Comparing version 1.11.2 to 1.12.0
@@ -18,2 +18,3 @@ import { Vec2, Rect2 } from '@js-draw/math'; | ||
private buffer; | ||
private centerOfMass; | ||
private lastPoint; | ||
@@ -20,0 +21,0 @@ private lastExitingVec; |
@@ -18,2 +18,3 @@ "use strict"; | ||
this.isFirstSegment = true; | ||
this.centerOfMass = null; | ||
this.lastExitingVec = null; | ||
@@ -64,2 +65,3 @@ this.currentCurve = null; | ||
this.currentCurve = null; | ||
this.centerOfMass = null; | ||
this.isFirstSegment = false; | ||
@@ -112,6 +114,16 @@ } | ||
} | ||
if (!this.centerOfMass) { | ||
this.centerOfMass = newPoint.pos; | ||
} | ||
else { | ||
this.centerOfMass = this.centerOfMass | ||
.times(this.buffer.length) | ||
.plus(newPoint.pos).times(1 / (this.buffer.length + 1)); | ||
} | ||
const toCenterOfMass = this.centerOfMass.minus(newPoint.pos); | ||
const deltaTimeSeconds = deltaTime / 1000; | ||
const velocity = newPoint.pos.minus(this.lastPoint.pos).times(1 / deltaTimeSeconds); | ||
// TODO: Do we need momentum smoothing? (this.momentum.lerp(velocity, 0.9);) | ||
this.momentum = velocity; | ||
const k = 1; | ||
this.momentum = velocity.plus(toCenterOfMass.times(k)); | ||
} | ||
@@ -153,3 +165,3 @@ const lastPoint = this.lastPoint ?? newPoint; | ||
// Find the intersection between the entering vector and the exiting vector | ||
const maxRelativeLength = 2.4; | ||
const maxRelativeLength = 1.6; | ||
const segmentStart = this.buffer[0]; | ||
@@ -175,8 +187,14 @@ const segmentEnd = newPoint.pos; | ||
} | ||
// No intersection or the intersection is one of the end points? | ||
if (!controlPoint || segmentStart.eq(controlPoint) || segmentEnd.eq(controlPoint)) { | ||
// Position the control point closer to the first -- the connecting | ||
// segment will be roughly a line. | ||
controlPoint = segmentStart.plus(enteringVec.times(startEndDist / 4)); | ||
// No intersection? | ||
if (!controlPoint) { | ||
// Estimate the control point position based on the entering tangent line | ||
controlPoint = segmentStart | ||
.lerp(segmentEnd, 0.5) | ||
.lerp(segmentStart.plus(enteringVec.times(startEndDist)), 0.25); | ||
} | ||
// Equal to an endpoint? | ||
if (segmentStart.eq(controlPoint) || segmentEnd.eq(controlPoint)) { | ||
// Position the control point between the two end points | ||
controlPoint = segmentStart.lerp(segmentEnd, 0.5); | ||
} | ||
console.assert(!segmentStart.eq(controlPoint, 1e-11), 'Start and control points are equal!'); | ||
@@ -183,0 +201,0 @@ console.assert(!controlPoint.eq(segmentEnd, 1e-11), 'Control and end points are equal!'); |
@@ -60,2 +60,3 @@ "use strict"; | ||
const listenForKeyboardEventsFrom_1 = __importDefault(require("./util/listenForKeyboardEventsFrom")); | ||
const mitLicenseAttribution_1 = __importDefault(require("./util/mitLicenseAttribution")); | ||
/** | ||
@@ -1206,5 +1207,15 @@ * The main entrypoint for the full editor. | ||
'', | ||
'js-draw uses several libraries at runtime. Particularly noteworthy are:', | ||
'At runtime, js-draw uses', | ||
' - The Coloris color picker: https://github.com/mdbassit/Coloris', | ||
' - The bezier.js Bézier curve library: https://github.com/Pomax/bezierjs' | ||
' - The bezier.js Bézier curve library: https://github.com/Pomax/bezierjs', | ||
'', | ||
'Both are licensed under the MIT license:', | ||
'', | ||
'', | ||
'== Coloris ==', | ||
(0, mitLicenseAttribution_1.default)('2021 Mohammed Bassit'), | ||
'', | ||
'', | ||
'== Bezier.js ==', | ||
(0, mitLicenseAttribution_1.default)('2023 Mike "Pomax" Kamermans'), | ||
].join('\n'), | ||
@@ -1211,0 +1222,0 @@ minimized: true, |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = { | ||
number: '1.11.2', | ||
number: '1.12.0', | ||
}; |
@@ -18,2 +18,3 @@ import { Vec2, Rect2 } from '@js-draw/math'; | ||
private buffer; | ||
private centerOfMass; | ||
private lastPoint; | ||
@@ -20,0 +21,0 @@ private lastExitingVec; |
{ | ||
"name": "js-draw", | ||
"version": "1.11.2", | ||
"version": "1.12.0", | ||
"description": "Draw pictures using a pen, touchscreen, or mouse! JS-draw is a drawing library for JavaScript and TypeScript. ", | ||
@@ -89,3 +89,3 @@ "types": "./dist/mjs/lib.d.ts", | ||
], | ||
"gitHead": "e1d593def957ec85633ff89166f9af25ae03f862" | ||
"gitHead": "c179c5b3ebca482dfb156527ec6631c8f5159033" | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3876455
735
52999