From d502c417cd4962fe1d52bc426161b4b62f17b92c Mon Sep 17 00:00:00 2001 From: winetree94 Date: Sun, 27 Feb 2022 19:22:27 +0900 Subject: [PATCH] chore: include build files --- .gitignore | 2 - build/main-browser.d.ts | 3 + build/main-browser.d.ts.map | 1 + build/main-browser.js | 5 + build/main-browser.js.map | 1 + build/main.d.ts | 6 + build/main.d.ts.map | 1 + build/main.js | 9 + build/main.js.map | 1 + build/vertor-optimizer/cubic-bezier.d.ts | 16 + build/vertor-optimizer/cubic-bezier.d.ts.map | 1 + build/vertor-optimizer/cubic-bezier.js | 29 ++ build/vertor-optimizer/cubic-bezier.js.map | 1 + build/vertor-optimizer/curve-fit-base.d.ts | 24 ++ .../vertor-optimizer/curve-fit-base.d.ts.map | 1 + build/vertor-optimizer/curve-fit-base.js | 289 ++++++++++++++++++ build/vertor-optimizer/curve-fit-base.js.map | 1 + build/vertor-optimizer/curve-fit.d.ts | 13 + build/vertor-optimizer/curve-fit.d.ts.map | 1 + build/vertor-optimizer/curve-fit.js | 104 +++++++ build/vertor-optimizer/curve-fit.js.map | 1 + build/vertor-optimizer/curve-preprocess.d.ts | 7 + .../curve-preprocess.d.ts.map | 1 + build/vertor-optimizer/curve-preprocess.js | 171 +++++++++++ .../vertor-optimizer/curve-preprocess.js.map | 1 + build/vertor-optimizer/math.d.ts | 2 + build/vertor-optimizer/math.d.ts.map | 1 + build/vertor-optimizer/math.js | 8 + build/vertor-optimizer/math.js.map | 1 + build/vertor-optimizer/vector.d.ts | 23 ++ build/vertor-optimizer/vector.d.ts.map | 1 + build/vertor-optimizer/vector.js | 52 ++++ build/vertor-optimizer/vector.js.map | 1 + dist/vector-optimizer.min.js | 2 + dist/vector-optimizer.min.js.LICENSE.txt | 14 + package.json | 2 +- 36 files changed, 794 insertions(+), 3 deletions(-) create mode 100644 build/main-browser.d.ts create mode 100644 build/main-browser.d.ts.map create mode 100644 build/main-browser.js create mode 100644 build/main-browser.js.map create mode 100644 build/main.d.ts create mode 100644 build/main.d.ts.map create mode 100644 build/main.js create mode 100644 build/main.js.map create mode 100644 build/vertor-optimizer/cubic-bezier.d.ts create mode 100644 build/vertor-optimizer/cubic-bezier.d.ts.map create mode 100644 build/vertor-optimizer/cubic-bezier.js create mode 100644 build/vertor-optimizer/cubic-bezier.js.map create mode 100644 build/vertor-optimizer/curve-fit-base.d.ts create mode 100644 build/vertor-optimizer/curve-fit-base.d.ts.map create mode 100644 build/vertor-optimizer/curve-fit-base.js create mode 100644 build/vertor-optimizer/curve-fit-base.js.map create mode 100644 build/vertor-optimizer/curve-fit.d.ts create mode 100644 build/vertor-optimizer/curve-fit.d.ts.map create mode 100644 build/vertor-optimizer/curve-fit.js create mode 100644 build/vertor-optimizer/curve-fit.js.map create mode 100644 build/vertor-optimizer/curve-preprocess.d.ts create mode 100644 build/vertor-optimizer/curve-preprocess.d.ts.map create mode 100644 build/vertor-optimizer/curve-preprocess.js create mode 100644 build/vertor-optimizer/curve-preprocess.js.map create mode 100644 build/vertor-optimizer/math.d.ts create mode 100644 build/vertor-optimizer/math.d.ts.map create mode 100644 build/vertor-optimizer/math.js create mode 100644 build/vertor-optimizer/math.js.map create mode 100644 build/vertor-optimizer/vector.d.ts create mode 100644 build/vertor-optimizer/vector.d.ts.map create mode 100644 build/vertor-optimizer/vector.js create mode 100644 build/vertor-optimizer/vector.js.map create mode 100644 dist/vector-optimizer.min.js create mode 100644 dist/vector-optimizer.min.js.LICENSE.txt diff --git a/.gitignore b/.gitignore index ef22995..0e76ed1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,3 @@ node_modules -dist -build .DS_Store temp \ No newline at end of file diff --git a/build/main-browser.d.ts b/build/main-browser.d.ts new file mode 100644 index 0000000..8b5cfa6 --- /dev/null +++ b/build/main-browser.d.ts @@ -0,0 +1,3 @@ +import * as VectorOptimizer from './main'; +export = VectorOptimizer; +//# sourceMappingURL=main-browser.d.ts.map \ No newline at end of file diff --git a/build/main-browser.d.ts.map b/build/main-browser.d.ts.map new file mode 100644 index 0000000..d09fef9 --- /dev/null +++ b/build/main-browser.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"main-browser.d.ts","sourceRoot":"","sources":["../src/main-browser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,eAAe,MAAM,QAAQ,CAAC;AAC1C,SAAS,eAAe,CAAC"} \ No newline at end of file diff --git a/build/main-browser.js b/build/main-browser.js new file mode 100644 index 0000000..78344cb --- /dev/null +++ b/build/main-browser.js @@ -0,0 +1,5 @@ +"use strict"; +const tslib_1 = require("tslib"); +const VectorOptimizer = tslib_1.__importStar(require("./main")); +module.exports = VectorOptimizer; +//# sourceMappingURL=main-browser.js.map \ No newline at end of file diff --git a/build/main-browser.js.map b/build/main-browser.js.map new file mode 100644 index 0000000..0d7fac3 --- /dev/null +++ b/build/main-browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"main-browser.js","sourceRoot":"","sources":["../src/main-browser.ts"],"names":[],"mappings":";;AAAA,gEAA0C;AAC1C,iBAAS,eAAe,CAAC"} \ No newline at end of file diff --git a/build/main.d.ts b/build/main.d.ts new file mode 100644 index 0000000..9c70979 --- /dev/null +++ b/build/main.d.ts @@ -0,0 +1,6 @@ +export * from './vertor-optimizer/cubic-bezier'; +export * from './vertor-optimizer/curve-fit-base'; +export * from './vertor-optimizer/curve-fit'; +export * from './vertor-optimizer/curve-preprocess'; +export * from './vertor-optimizer/vector'; +//# sourceMappingURL=main.d.ts.map \ No newline at end of file diff --git a/build/main.d.ts.map b/build/main.d.ts.map new file mode 100644 index 0000000..87062e3 --- /dev/null +++ b/build/main.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC;AAChD,cAAc,mCAAmC,CAAC;AAClD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qCAAqC,CAAC;AACpD,cAAc,2BAA2B,CAAC"} \ No newline at end of file diff --git a/build/main.js b/build/main.js new file mode 100644 index 0000000..7f47be7 --- /dev/null +++ b/build/main.js @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const tslib_1 = require("tslib"); +tslib_1.__exportStar(require("./vertor-optimizer/cubic-bezier"), exports); +tslib_1.__exportStar(require("./vertor-optimizer/curve-fit-base"), exports); +tslib_1.__exportStar(require("./vertor-optimizer/curve-fit"), exports); +tslib_1.__exportStar(require("./vertor-optimizer/curve-preprocess"), exports); +tslib_1.__exportStar(require("./vertor-optimizer/vector"), exports); +//# sourceMappingURL=main.js.map \ No newline at end of file diff --git a/build/main.js.map b/build/main.js.map new file mode 100644 index 0000000..d9de5e2 --- /dev/null +++ b/build/main.js.map @@ -0,0 +1 @@ +{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;;AAAA,0EAAgD;AAChD,4EAAkD;AAClD,uEAA6C;AAC7C,8EAAoD;AACpD,oEAA0C"} \ No newline at end of file diff --git a/build/vertor-optimizer/cubic-bezier.d.ts b/build/vertor-optimizer/cubic-bezier.d.ts new file mode 100644 index 0000000..607b296 --- /dev/null +++ b/build/vertor-optimizer/cubic-bezier.d.ts @@ -0,0 +1,16 @@ +import { Point, Vector } from './vector'; +export declare class CubicBezier { + readonly p0: Vector; + readonly p1: Vector; + readonly p2: Vector; + readonly p3: Vector; + static from(cubicBezierLike: { + p0: Point; + p1: Point; + p2: Point; + p3: Point; + }): CubicBezier; + constructor(p0: Vector, p1: Vector, p2: Vector, p3: Vector); + sample(t: number): Vector; +} +//# sourceMappingURL=cubic-bezier.d.ts.map \ No newline at end of file diff --git a/build/vertor-optimizer/cubic-bezier.d.ts.map b/build/vertor-optimizer/cubic-bezier.d.ts.map new file mode 100644 index 0000000..2b0969f --- /dev/null +++ b/build/vertor-optimizer/cubic-bezier.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"cubic-bezier.d.ts","sourceRoot":"","sources":["../../src/vertor-optimizer/cubic-bezier.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEzC,qBAAa,WAAW;aAgBJ,EAAE,EAAE,MAAM;aACV,EAAE,EAAE,MAAM;aACV,EAAE,EAAE,MAAM;aACV,EAAE,EAAE,MAAM;WAlBd,IAAI,CAAC,eAAe,EAAE;QAClC,EAAE,EAAE,KAAK,CAAC;QACV,EAAE,EAAE,KAAK,CAAC;QACV,EAAE,EAAE,KAAK,CAAC;QACV,EAAE,EAAE,KAAK,CAAC;KACX,GAAG,WAAW;gBAUG,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM;IAGrB,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM;CAYjC"} \ No newline at end of file diff --git a/build/vertor-optimizer/cubic-bezier.js b/build/vertor-optimizer/cubic-bezier.js new file mode 100644 index 0000000..33db806 --- /dev/null +++ b/build/vertor-optimizer/cubic-bezier.js @@ -0,0 +1,29 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.CubicBezier = void 0; +const vector_1 = require("./vector"); +class CubicBezier { + constructor(p0, p1, p2, p3) { + this.p0 = p0; + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + } + static from(cubicBezierLike) { + return new CubicBezier(vector_1.Vector.from(cubicBezierLike.p0), vector_1.Vector.from(cubicBezierLike.p1), vector_1.Vector.from(cubicBezierLike.p2), vector_1.Vector.from(cubicBezierLike.p3)); + } + sample(t) { + const ti = 1 - t; + const t0 = ti * ti * ti; + const t1 = 3 * ti * ti * t; + const t2 = 3 * ti * t * t; + const t3 = t * t * t; + return this.p0 + .multiply(t0) + .add(this.p1.multiply(t1)) + .add(this.p2.multiply(t2)) + .add(this.p3.multiply(t3)); + } +} +exports.CubicBezier = CubicBezier; +//# sourceMappingURL=cubic-bezier.js.map \ No newline at end of file diff --git a/build/vertor-optimizer/cubic-bezier.js.map b/build/vertor-optimizer/cubic-bezier.js.map new file mode 100644 index 0000000..0f064ef --- /dev/null +++ b/build/vertor-optimizer/cubic-bezier.js.map @@ -0,0 +1 @@ +{"version":3,"file":"cubic-bezier.js","sourceRoot":"","sources":["../../src/vertor-optimizer/cubic-bezier.ts"],"names":[],"mappings":";;;AAAA,qCAAyC;AAEzC,MAAa,WAAW;IAetB,YACkB,EAAU,EACV,EAAU,EACV,EAAU,EACV,EAAU;QAHV,OAAE,GAAF,EAAE,CAAQ;QACV,OAAE,GAAF,EAAE,CAAQ;QACV,OAAE,GAAF,EAAE,CAAQ;QACV,OAAE,GAAF,EAAE,CAAQ;IACzB,CAAC;IAnBG,MAAM,CAAC,IAAI,CAAC,eAKlB;QACC,OAAO,IAAI,WAAW,CACpB,eAAM,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC,EAC/B,eAAM,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC,EAC/B,eAAM,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC,EAC/B,eAAM,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC,CAChC,CAAC;IACJ,CAAC;IASM,MAAM,CAAC,CAAS;QACrB,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;QACjB,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;QACxB,MAAM,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;QAC3B,MAAM,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;QAC1B,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACrB,OAAO,IAAI,CAAC,EAAE;aACX,QAAQ,CAAC,EAAE,CAAC;aACZ,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;aACzB,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;aACzB,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;IAC/B,CAAC;CACF;AAlCD,kCAkCC"} \ No newline at end of file diff --git a/build/vertor-optimizer/curve-fit-base.d.ts b/build/vertor-optimizer/curve-fit-base.d.ts new file mode 100644 index 0000000..3153d2c --- /dev/null +++ b/build/vertor-optimizer/curve-fit-base.d.ts @@ -0,0 +1,24 @@ +import { CubicBezier } from './cubic-bezier'; +import { Vector } from './vector'; +export declare class CurveFitBase { + _pts: ReadonlyArray; + _arclen: ReadonlyArray; + protected _u: number[]; + protected _squaredError: number; + protected fitCurve(first: number, last: number, tanL: Vector, tanR: Vector, curve: CubicBezier, split: number): { + response: boolean; + split: number; + curve: CubicBezier; + }; + protected findMaxSquaredError(first: number, last: number, curve?: CubicBezier, split?: number): { + response: number; + split: number; + }; + protected generateBezier(first: number, last: number, tanL: Vector, tanR: Vector): CubicBezier; + protected reparameterize(first: number, last: number, curve: CubicBezier): void; + protected arcLengthParamaterize(first: number, last: number): void; + protected getLeftTangent(last: number): Vector; + protected getRightTangent(first: number): Vector; + protected getCenterTangent(first: number, last: number, split: number): Vector; +} +//# sourceMappingURL=curve-fit-base.d.ts.map \ No newline at end of file diff --git a/build/vertor-optimizer/curve-fit-base.d.ts.map b/build/vertor-optimizer/curve-fit-base.d.ts.map new file mode 100644 index 0000000..f1bb379 --- /dev/null +++ b/build/vertor-optimizer/curve-fit-base.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"curve-fit-base.d.ts","sourceRoot":"","sources":["../../src/vertor-optimizer/curve-fit-base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAwBlC,qBAAa,YAAY;IAChB,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAC5B,OAAO,EAA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 index 0000000..f6c805f --- /dev/null +++ b/build/vertor-optimizer/curve-fit-base.js @@ -0,0 +1,289 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.CurveFitBase = void 0; +const cubic_bezier_1 = require("./cubic-bezier"); +const vector_1 = require("./vector"); +// Copyright (c) 2015 burningmime +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgement in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. +const MAX_ITERS = 4; +const END_TANGENT_N_PTS = 8; +const MID_TANGENT_N_PTS = 4; +class CurveFitBase { + constructor() { + this._u = []; + this._squaredError = 0; + } + fitCurve(first, last, tanL, tanR, curve, split) { + const result = { + response: false, + split: split, + curve: curve, + }; + const pts = this._pts; + const nPts = last - first + 1; + if (nPts < 2) { + throw new Error('INTERNAL ERROR: Should always have at least 2 points here'); + } + else if (nPts == 2) { + const p0 = pts[first]; + const p3 = pts[last]; + const alpha = p0.distance(p3) / 3; + const p1 = tanL.multiply(alpha).add(p0); + const p2 = tanR.multiply(alpha).add(p3); + curve = new cubic_bezier_1.CubicBezier(p0, p1, p2, p3); + result.curve = curve; + split = 0; + result.split = split; + result.response = true; + return result; + } + else { + split = 0; + result.split = split; + this.arcLengthParamaterize(first, last); + curve = null; + result.curve = curve; + for (let i = 0; i < MAX_ITERS + 1; i++) { + if (i != 0) { + this.reparameterize(first, last, curve); + } + curve = this.generateBezier(first, last, tanL, tanR); + result.curve = curve; + const res = this.findMaxSquaredError(first, last, curve, result.split); + result.split = res.split; + if (res.response < this._squaredError) { + result.response = true; + return result; + } + } + result.response = false; + return result; + } + } + findMaxSquaredError(first, last, curve = null, split = 0) { + const result = { + response: 0, + split: split, + }; + const pts = this._pts; + const u = this._u; + let s = (last - first + 1) / 2; + const nPts = last - first + 1; + let max = 0; + for (let i = 1; i < nPts; i++) { + const v0 = pts[first + i]; + const v1 = curve.sample(u[i]); + const d = v0.distanceSquared(v1); + if (d > max) { + max = d; + s = i; + } + } + split = s + first; + if (split <= first) + split = first + 1; + if (split >= last) + split = last - 1; + result.split = split; + result.response = max; + return result; + } + generateBezier(first, last, tanL, tanR) { + const pts = this._pts; + const u = this._u; + const nPts = last - first + 1; + const p0 = pts[first]; + const p3 = pts[last]; + let c00 = 0; + let c01 = 0; + let c11 = 0; + let x0 = 0; + let x1 = 0; + for (let i = 1; i < nPts; i++) { + const t = u[i]; + const ti = 1 - t; + const t0 = ti * ti * ti; + const t1 = 3 * ti * ti * t; + const t2 = 3 * ti * t * t; + const t3 = t * t * t; + const s = p0 + .multiply(t0) + .add(p0.multiply(t1)) + .add(p3.multiply(t2)) + .add(p3.multiply(t3)); + const v = pts[first + i].subtract(s); + const a0 = tanL.multiply(t1); + const a1 = tanR.multiply(t2); + c00 += a0.dot(a0); + c01 += a0.dot(a1); + c11 += a1.dot(a1); + x0 += a0.dot(v); + x1 += a1.dot(v); + } + const det_C0_C1 = c00 * c11 - c01 * c01; + const det_C0_X = c00 * x1 - c01 * x0; + const det_X_C1 = x0 * c11 - x1 * c01; + const alphaL = det_X_C1 / det_C0_C1; + const alphaR = det_C0_X / det_C0_C1; + const linDist = p0.distance(p3); + const epsilon2 = Number.EPSILON * linDist; + if (Math.abs(det_C0_C1) < Number.EPSILON || + alphaL < epsilon2 || + alphaR < epsilon2) { + const alpha = linDist / 3; + const p1 = tanL.multiply(alpha).add(p0); + const p2 = tanR.multiply(alpha).add(p3); + return new cubic_bezier_1.CubicBezier(p0, p1, p2, p3); + } + else { + const p1 = tanL.multiply(alphaL).add(p0); + const p2 = tanR.multiply(alphaR).add(p3); + return new cubic_bezier_1.CubicBezier(p0, p1, p2, p3); + } + } + reparameterize(first, last, curve) { + const pts = this._pts; + const u = this._u; + const nPts = last - first; + for (let i = 1; i < nPts; i++) { + const p = pts[first + i]; + const t = u[i]; + const ti = 1 - t; + const qp0 = curve.p1.subtract(curve.p0).multiply(3); + const qp1 = curve.p2.subtract(curve.p1).multiply(3); + const qp2 = curve.p3.subtract(curve.p2).multiply(3); + const qpp0 = qp1.subtract(qp0).multiply(2); + const qpp1 = qp2.subtract(qp1).multiply(2); + const p0 = curve.sample(t); + const p1 = qp0 + .multiply(ti * ti) + .add(qp1.multiply(2 * ti * t)) + .add(qp2.multiply(t * t)); + const p2 = qpp0.multiply(ti).add(qpp1.multiply(t)); + const num = (p0.x - p.x) * p1.x + (p0.y - p.y) * p1.y; + const den = p1.x * p1.x + p1.y * p1.y + (p0.x - p.x) * p2.x + (p0.y - p.y) * p2.y; + const newU = t - num / den; + if (Math.abs(den) > Number.EPSILON && newU >= 0 && newU <= 1) { + u[i] = newU; + } + } + } + arcLengthParamaterize(first, last) { + const arclen = this._arclen; + const u = this._u; + u.splice(0); + const diff = arclen[last] - arclen[first]; + const start = arclen[first]; + const nPts = last - first; + u.push(0); + for (let i = 1; i < nPts; i++) { + u.push((arclen[first + i] - start) / diff); + } + u.push(1); + } + getLeftTangent(last) { + const pts = this._pts; + const arclen = this._arclen; + const totalLen = arclen[arclen.length - 1]; + const p0 = pts[0]; + let tanL = pts[1].subtract(p0).normalize(); + let total = tanL; + let weightTotal = 1; + last = Math.min(END_TANGENT_N_PTS, last - 1); + for (let i = 2; i <= last; i++) { + const ti = 1 - arclen[i] / totalLen; + const weight = ti * ti * ti; + const v = pts[i].subtract(p0).normalize(); + total = total.add(v.multiply(weight)); + weightTotal += weight; + } + if (total.length() > Number.EPSILON) { + tanL = total.divide(weightTotal).normalize(); + } + return tanL; + } + getRightTangent(first) { + const pts = this._pts; + const arclen = this._arclen; + const totalLen = arclen[arclen.length - 1]; + const p3 = pts[pts.length - 1]; + let tanR = pts[pts.length - 2].subtract(p3).normalize(); + let total = tanR; + let weightTotal = 1; + first = Math.max(pts.length - (END_TANGENT_N_PTS + 1), first + 1); + for (let i = pts.length - 3; i >= first; i--) { + const t = arclen[i] / totalLen; + const weight = t * t * t; + const v = pts[i].subtract(p3).normalize(); + total = total.add(v.multiply(weight)); + weightTotal += weight; + } + if (total.length() > Number.EPSILON) { + tanR = total.divide(weightTotal).normalize(); + } + return tanR; + } + getCenterTangent(first, last, split) { + const pts = this._pts; + const arclen = this._arclen; + const splitLen = arclen[split]; + const pSplit = pts[split]; + const firstLen = arclen[first]; + let partLen = splitLen - firstLen; + let total = new vector_1.Vector(0, 0); + let weightTotal = 0; + for (let i = Math.max(first, split - MID_TANGENT_N_PTS); i < split; i++) { + const t = (arclen[i] - firstLen) / partLen; + const weight = t * t * t; + const v = pts[i].subtract(pSplit).normalize(); + total = total.add(v.multiply(weight)); + weightTotal += weight; + } + let tanL = total.length() > Number.EPSILON && weightTotal > Number.EPSILON + ? total.divide(weightTotal).normalize() + : pts[split - 1].subtract(pSplit).normalize(); + partLen = arclen[last] - splitLen; + const rMax = Math.min(last, split + MID_TANGENT_N_PTS); + total = new vector_1.Vector(0, 0); + weightTotal = 0; + for (let i = split + 1; i <= rMax; i++) { + const ti = 1 - (arclen[i] - splitLen) / partLen; + const weight = ti * ti * ti; + const v = pSplit.subtract(pts[i]).normalize(); + total = total.add(v.multiply(weight)); + weightTotal += weight; + } + let tanR = total.length() > Number.EPSILON && weightTotal > Number.EPSILON + ? total.divide(weightTotal).normalize() + : pSplit.subtract(pts[split + 1]).normalize(); + total = tanL.add(tanR); + if (total.lengthSquared() < Number.EPSILON) { + tanL = pts[split - 1].subtract(pSplit).normalize(); + tanR = pSplit.subtract(pts[split + 1]).normalize(); + total = tanL.add(tanR); + return total.lengthSquared() < Number.EPSILON + ? tanL + : total.divide(2).normalize(); + } + else { + return total.divide(2).normalize(); + } + } +} +exports.CurveFitBase = CurveFitBase; +//# sourceMappingURL=curve-fit-base.js.map \ No newline at end of file diff --git a/build/vertor-optimizer/curve-fit-base.js.map b/build/vertor-optimizer/curve-fit-base.js.map new file mode 100644 index 0000000..b2cee9e --- /dev/null +++ b/build/vertor-optimizer/curve-fit-base.js.map @@ -0,0 +1 @@ +{"version":3,"file":"curve-fit-base.js","sourceRoot":"","sources":["../../src/vertor-optimizer/curve-fit-base.ts"],"names":[],"mappings":";;;AAAA,iDAA6C;AAC7C,qCAAkC;AAElC,iCAAiC;AACjC,EAAE;AACF,oEAAoE;AACpE,wEAAwE;AACxE,yCAAyC;AACzC,EAAE;AACF,wEAAwE;AACxE,yEAAyE;AACzE,iDAAiD;AACjD,EAAE;AACF,0EAA0E;AAC1E,0EAA0E;AAC1E,4EAA4E;AAC5E,sCAAsC;AACtC,6EAA6E;AAC7E,oDAAoD;AACpD,6EAA6E;AAE7E,MAAM,SAAS,GAAG,CAAC,CAAC;AACpB,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAC5B,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAE5B,MAAa,YAAY;IAAzB;QAGY,OAAE,GAAa,EAAE,CAAC;QAClB,kBAAa,GAAW,CAAC,CAAC;IAiUtC,CAAC;IA/TW,QAAQ,CAChB,KAAa,EACb,IAAY,EACZ,IAAY,EACZ,IAAY,EACZ,KAAkB,EAClB,KAAa;QAMb,MAAM,MAAM,GAIR;YACF,QAAQ,EAAE,KAAK;YACf,KAAK,EAAE,KAAK;YACZ,KAAK,EAAE,KAAK;SACb,CAAC;QAEF,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,MAAM,IAAI,GAAG,IAAI,GAAG,KAAK,GAAG,CAAC,CAAC;QAC9B,IAAI,IAAI,GAAG,CAAC,EAAE;YACZ,MAAM,IAAI,KAAK,CACb,2DAA2D,CAC5D,CAAC;SACH;aAAM,IAAI,IAAI,IAAI,CAAC,EAAE;YACpB,MAAM,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC;YACtB,MAAM,EAAE,GAAG,GAAG,CAAC,IAA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AAQ,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;YACnD,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACvB,OAAO,KAAK,CAAC,aAAa,EAAE,GAAG,MAAM,CAAC,OAAO;gBAC3C,CAAC,CAAC,IAAI;gBACN,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;SACjC;aAAM;YACL,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;SACpC;IACH,CAAC;CACF;AArUD,oCAqUC"} \ No newline at end of file diff --git a/build/vertor-optimizer/curve-fit.d.ts b/build/vertor-optimizer/curve-fit.d.ts new file mode 100644 index 0000000..99b3557 --- /dev/null +++ b/build/vertor-optimizer/curve-fit.d.ts @@ -0,0 +1,13 @@ +import { CubicBezier } from './cubic-bezier'; +import { CurveFitBase } from './curve-fit-base'; +import { Vector } from './vector'; +export declare function fit(points: readonly Vector[]): CubicBezier[]; +export declare function generateArcLengths(points: ReadonlyArray): number[]; +export declare class CurveFit extends CurveFitBase { + readonly _pts: ReadonlyArray; + private _result; + constructor(_pts: ReadonlyArray); + fit(maxError: number): CubicBezier[]; + private fitRecursive; +} +//# sourceMappingURL=curve-fit.d.ts.map \ No newline at end of file diff --git a/build/vertor-optimizer/curve-fit.d.ts.map b/build/vertor-optimizer/curve-fit.d.ts.map new file mode 100644 index 0000000..0adde68 --- /dev/null +++ b/build/vertor-optimizer/curve-fit.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"curve-fit.d.ts","sourceRoot":"","sources":["../../src/vertor-optimizer/curve-fit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAuBlC,wBAAgB,GAAG,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,WAAW,EAAE,CAG5D;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,MAAM,EAAE,CAY1E;AAED,qBAAa,QAAS,SAAQ,YAAY;aAGL,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC;IAF9D,OAAO,CAAC,OAAO,CAAqB;gBAED,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC;IAevD,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,WAAW,EAAE;IAuB3C,OAAO,CAAC,YAAY;CA6BrB"} \ No newline at end of file diff --git a/build/vertor-optimizer/curve-fit.js b/build/vertor-optimizer/curve-fit.js new file mode 100644 index 0000000..0457c4a --- /dev/null +++ b/build/vertor-optimizer/curve-fit.js @@ -0,0 +1,104 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.CurveFit = exports.generateArcLengths = exports.fit = void 0; +const curve_fit_base_1 = require("./curve-fit-base"); +const vector_1 = require("./vector"); +// Copyright (c) 2015 burningmime +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgement in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. +const END_TANGENT_N_PTS = 8; +const NO_CURVES = []; +function fit(points) { + const arcLen = generateArcLengths(points); + return []; +} +exports.fit = fit; +function generateArcLengths(points) { + const results = []; + results.push(0); + let clen = 0; + let pp = points[0]; + for (let i = 1; i < points.length; i++) { + const np = points[i]; + clen += vector_1.Vector.from(pp).distance(vector_1.Vector.from(np)); + results.push(clen); + pp = np; + } + return results; +} +exports.generateArcLengths = generateArcLengths; +class CurveFit extends curve_fit_base_1.CurveFitBase { + constructor(_pts) { + super(); + this._pts = _pts; + this._result = []; + const arclen = []; + arclen.push(0); + let clen = 0; + let pp = this._pts[0]; + for (let i = 1; i < this._pts.length; i++) { + const np = this._pts[i]; + clen += vector_1.Vector.from(pp).distance(vector_1.Vector.from(np)); + arclen.push(clen); + pp = np; + } + this._arclen = arclen; + } + fit(maxError) { + if (maxError < Number.EPSILON) { + throw new Error('maxError cannot be negative/zero/less than epsilon value'); + } + if (!this._pts) { + throw new Error('points'); + } + if (this._pts.length < 2) { + return NO_CURVES; + } + this._squaredError = maxError * maxError; + const last = this._pts.length - 1; + const tanL = this.getLeftTangent(last); + const tanR = this.getRightTangent(0); + this.fitRecursive(0, last, tanL, tanR); + return this._result; + } + fitRecursive(first = 0, last = 0, tanL, tanR) { + let split = 0; + let curve = null; + const fitCurveResult = this.fitCurve(first, last, tanL, tanR, curve, split); + split = fitCurveResult.split; + curve = fitCurveResult.curve; + if (fitCurveResult.response) { + this._result.push(curve); + } + else { + const tanM1 = this.getCenterTangent(first, last, split); + const tanM2 = new vector_1.Vector(-tanM1.x, -tanM1.y); + if (first == 0 && split < END_TANGENT_N_PTS) { + tanL = this.getLeftTangent(split); + } + if (last == this._pts.length - 1 && + split > this._pts.length - (END_TANGENT_N_PTS + 1)) { + tanR = this.getRightTangent(split); + } + // do actual recursion + this.fitRecursive(first, split, tanL, tanM1); + this.fitRecursive(split, last, tanM2, tanR); + } + } +} +exports.CurveFit = CurveFit; +//# sourceMappingURL=curve-fit.js.map \ No newline at end of file diff --git a/build/vertor-optimizer/curve-fit.js.map b/build/vertor-optimizer/curve-fit.js.map new file mode 100644 index 0000000..079d26c --- /dev/null +++ b/build/vertor-optimizer/curve-fit.js.map @@ -0,0 +1 @@ +{"version":3,"file":"curve-fit.js","sourceRoot":"","sources":["../../src/vertor-optimizer/curve-fit.ts"],"names":[],"mappings":";;;AACA,qDAAgD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;YAC7C,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;SAC7C;IACH,CAAC;CACF;AAtED,4BAsEC"} \ No newline at end of file diff --git a/build/vertor-optimizer/curve-preprocess.d.ts b/build/vertor-optimizer/curve-preprocess.d.ts new file mode 100644 index 0000000..90fd902 --- /dev/null +++ b/build/vertor-optimizer/curve-preprocess.d.ts @@ -0,0 +1,7 @@ +import { Vector } from './vector'; +export declare function linearize(src: Vector[], minDistance: number, alwaysKeepLastVertex?: boolean, alwaysLinearizeAllVertexes?: boolean): Vector[]; +export declare function removeDuplicates(pts: Vector[]): Vector[]; +export declare function rdpReduce(pts: Vector[], error: number): Vector[]; +export declare function rdpRecursive(pts: Vector[], error: number, first: number, last: number, keepIndex: number[]): void; +export declare function perpendicularDistance(a: Vector, b: Vector, abDist: number, aCrossB: number, p: Vector): number; +//# sourceMappingURL=curve-preprocess.d.ts.map \ No newline at end of file diff --git a/build/vertor-optimizer/curve-preprocess.d.ts.map b/build/vertor-optimizer/curve-preprocess.d.ts.map new file mode 100644 index 0000000..b6cbd9d --- /dev/null +++ b/build/vertor-optimizer/curve-preprocess.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"curve-preprocess.d.ts","sourceRoot":"","sources":["../../src/vertor-optimizer/curve-preprocess.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAoBlC,wBAAgB,SAAS,CACvB,GAAG,EAAE,MAAM,EAAE,EACb,WAAW,EAAE,MAAM,EACnB,oBAAoB,GAAE,OAAe,EACrC,0BAA0B,GAAE,OAAc,GACzC,MAAM,EAAE,CA4CV;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CA6BxD;AAYD,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAehE;AAED,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,EAAE,EACb,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,EAAE,GAClB,IAAI,CAyBN;AAWD,wBAAgB,qBAAqB,CACnC,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,CAAC,EAAE,MAAM,GACR,MAAM,CAWR"} \ No newline at end of file diff --git a/build/vertor-optimizer/curve-preprocess.js b/build/vertor-optimizer/curve-preprocess.js new file mode 100644 index 0000000..0eab48a --- /dev/null +++ b/build/vertor-optimizer/curve-preprocess.js @@ -0,0 +1,171 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.perpendicularDistance = exports.rdpRecursive = exports.rdpReduce = exports.removeDuplicates = exports.linearize = void 0; +// Copyright (c) 2015 burningmime +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgement in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. +function linearize(src, minDistance, alwaysKeepLastVertex = false, alwaysLinearizeAllVertexes = true) { + const dist = []; + if (src === null) { + throw new Error('Source vector array is null'); + } + if (minDistance <= Number.EPSILON) { + throw new Error(`md ${minDistance}' is be less than epsilon ${Number.EPSILON}`); + } + if (src.length > 0) { + let pp = src[0]; + dist.push(pp); + let cd = 0; + for (let ip = 1; ip < src.length; ip++) { + const p0 = src[ip - 1]; + const p1 = src[ip]; + const td = p0.distance(p1); + if (cd + td > minDistance) { + const pd = minDistance - cd; + dist.push(p0.lerp(p1, pd / td)); + let rd = td - pd; + while (rd > minDistance) { + rd -= minDistance; + if (alwaysLinearizeAllVertexes) { + const np = p0.lerp(p1, (td - rd) / td); + if (!np.equalsOrClose(pp)) { + dist.push(np); + pp = np; + } + } + } + cd = rd; + } + else { + cd += td; + } + } + const lp = src[src.length - 1]; + if (alwaysKeepLastVertex || !pp.equalsOrClose(lp)) { + dist.push(lp); + } + } + return dist; +} +exports.linearize = linearize; +function removeDuplicates(pts) { + if (pts.length < 2) { + return pts; + } + let prev = pts[0]; + const len = pts.length; + let nDup = 0; + for (let i = 1; i < len; i++) { + const cur = pts[i]; + if (prev.equalsOrClose(cur)) + nDup++; + else + prev = cur; + } + if (nDup == 0) { + return pts; + } + else { + const dst = []; + prev = pts[0]; + dst.push(prev); + for (let i = 1; i < len; i++) { + const cur = pts[i]; + if (!prev.equalsOrClose(cur)) { + dst.push(cur); + prev = cur; + } + } + return dst; + } +} +exports.removeDuplicates = removeDuplicates; +/// +/// "Reduces" a set of line segments by removing points that are too far away. Does not modify the input list; returns +/// a new list with the points removed. +/// The image says it better than I could ever describe: http://upload.wikimedia.org/wikipedia/commons/3/30/Douglas-Peucker_animated.gif +/// The wiki article: http://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm +/// Based on: http://www.codeproject.com/Articles/18936/A-Csharp-Implementation-of-Douglas-Peucker-Line-Ap +/// +/// Points to reduce +/// Maximum distance of a point to a line. Low values (~2-4) work well for mouse/touchscreen data. +/// A new list containing only the points needed to approximate the curve. +function rdpReduce(pts, error) { + if (pts == null) + throw new Error('pts'); + pts = removeDuplicates(pts); + if (pts.length < 3) { + return [...pts]; + } + const keepIndex = []; + keepIndex.push(0); + keepIndex.push(pts.length - 1); + rdpRecursive(pts, error, 0, pts.length - 1, keepIndex); + keepIndex.sort(); + const res = []; + // ReSharper disable once LoopCanBeConvertedToQuery + keepIndex.forEach((i) => res.push(pts[i])); + return res; +} +exports.rdpReduce = rdpReduce; +function rdpRecursive(pts, error, first, last, keepIndex) { + const nPts = last - first + 1; + if (nPts < 3) { + return; + } + const a = pts[first]; + const b = pts[last]; + const abDist = a.distance(b); + const aCrossB = a.x * b.y - b.x * a.y; + let maxDist = error; + let split = 0; + for (let i = first + 1; i < last - 1; i++) { + const p = pts[i]; + const pDist = perpendicularDistance(a, b, abDist, aCrossB, p); + if (pDist > maxDist) { + maxDist = pDist; + split = i; + } + } + if (split != 0) { + keepIndex.push(split); + rdpRecursive(pts, error, first, split, keepIndex); + rdpRecursive(pts, error, split, last, keepIndex); + } +} +exports.rdpRecursive = rdpRecursive; +/// +/// Finds the shortest distance between a point and a line. See: http://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line +/// +/// First point of the line. +/// Last point of the line. +/// Distance between a and b (length of the line). +/// "a.X*b.Y - b.X*a.Y" This would be the Z-component of (⟪a.X, a.Y, 0⟫ ⨯ ⟪b.X, b.Y, 0⟫) in 3-space. +/// The point to test. +/// The perpendicular distance to the line. +function perpendicularDistance(a, b, abDist, aCrossB, p) { + // a profile with the test data showed that originally this was eating up ~44% of the runtime. So, this went through + // several iterations of optimization and staring at the disassembly. I tried different methods of using cross + // products, doing the computation with larger vector types, etc... this is the best I could do in ~45 minutes + // running on 3 hours of sleep, which is all scalar math, but RyuJIT puts it into XMM registers and does + // ADDSS/SUBSS/MULSS/DIVSS because that's what it likes to do whenever it sees a vector in a function. + const area = Math.abs(aCrossB + b.x * p.y + p.x * a.y - p.x * b.y - a.x * p.y); + const height = area / abDist; + return height; +} +exports.perpendicularDistance = perpendicularDistance; +//# sourceMappingURL=curve-preprocess.js.map \ No newline at end of file diff --git a/build/vertor-optimizer/curve-preprocess.js.map b/build/vertor-optimizer/curve-preprocess.js.map new file mode 100644 index 0000000..5c81f07 --- /dev/null +++ b/build/vertor-optimizer/curve-preprocess.js.map @@ -0,0 +1 @@ +{"version":3,"file":"curve-preprocess.js","sourceRoot":"","sources":["../../src/vertor-optimizer/curve-preprocess.ts"],"names":[],"mappings":";;;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AC,CAAC;SACX;KACF;IACD,IAAI,KAAK,IAAI,CAAC,EAAE;QACd,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACtB,YAAY,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;QAClD,YAAY,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;KAClD;AACH,CAAC;AA/BD,oCA+BC;AAED,aAAa;AACb,6HAA6H;AAC7H,cAAc;AACd,oDAAoD;AACpD,mDAAmD;AACnD,+EAA+E;AAC/E,kIAAkI;AAClI,8CAA8C;AAC9C,8DAA8D;AAC9D,SAAgB,qBAAqB,CACnC,CAAS,EACT,CAAS,EACT,MAAc,EACd,OAAe,EACf,CAAS;IAET,oHAAoH;IACpH,8GAA8G;IAC9G,8GAA8G;IAC9G,wGAAwG;IACxG,sGAAsG;IACtG,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CACnB,OAAO,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CACxD,CAAC;IACF,MAAM,MAAM,GAAG,IAAI,GAAG,MAAM,CAAC;IAC7B,OAAO,MAAM,CAAC;AAChB,CAAC;AAjBD,sDAiBC"} \ No newline at end of file diff --git a/build/vertor-optimizer/math.d.ts b/build/vertor-optimizer/math.d.ts new file mode 100644 index 0000000..06c47d7 --- /dev/null +++ b/build/vertor-optimizer/math.d.ts @@ -0,0 +1,2 @@ +export declare function approximate(v: number, precision?: number): number; +//# sourceMappingURL=math.d.ts.map \ No newline at end of file diff --git a/build/vertor-optimizer/math.d.ts.map b/build/vertor-optimizer/math.d.ts.map new file mode 100644 index 0000000..dc646cd --- /dev/null +++ b/build/vertor-optimizer/math.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"math.d.ts","sourceRoot":"","sources":["../../src/vertor-optimizer/math.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,SAAS,SAAK,GAAG,MAAM,CAE7D"} \ No newline at end of file diff --git a/build/vertor-optimizer/math.js b/build/vertor-optimizer/math.js new file mode 100644 index 0000000..0e37407 --- /dev/null +++ b/build/vertor-optimizer/math.js @@ -0,0 +1,8 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.approximate = void 0; +function approximate(v, precision = 10) { + return Math.floor(v * precision) / precision; +} +exports.approximate = approximate; +//# sourceMappingURL=math.js.map \ No newline at end of file diff --git a/build/vertor-optimizer/math.js.map b/build/vertor-optimizer/math.js.map new file mode 100644 index 0000000..806e573 --- /dev/null +++ b/build/vertor-optimizer/math.js.map @@ -0,0 +1 @@ +{"version":3,"file":"math.js","sourceRoot":"","sources":["../../src/vertor-optimizer/math.ts"],"names":[],"mappings":";;;AAAA,SAAgB,WAAW,CAAC,CAAS,EAAE,SAAS,GAAG,EAAE;IACnD,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,SAAS,CAAC,GAAG,SAAS,CAAC;AAC/C,CAAC;AAFD,kCAEC"} \ No newline at end of file diff --git a/build/vertor-optimizer/vector.d.ts b/build/vertor-optimizer/vector.d.ts new file mode 100644 index 0000000..de56ac6 --- /dev/null +++ b/build/vertor-optimizer/vector.d.ts @@ -0,0 +1,23 @@ +export interface Point { + x: number; + y: number; +} +export declare class Vector { + x: number; + y: number; + static from(point: Point): Vector; + constructor(x: number, y: number); + add(a: Vector | number): Vector; + subtract(a: Vector | number): Vector; + multiply(a: Vector | number): Vector; + divide(a: Vector | number): Vector; + distance(a: Vector): number; + distanceSquared(a: Vector): number; + lerp(v: Vector, fraction: number): Vector; + equalsOrClose(a: Vector): boolean; + dot(a: Vector): number; + lengthSquared(): number; + length(): number; + normalize(): Vector; +} +//# sourceMappingURL=vector.d.ts.map \ No newline at end of file diff --git a/build/vertor-optimizer/vector.d.ts.map b/build/vertor-optimizer/vector.d.ts.map new file mode 100644 index 0000000..13b1e54 --- /dev/null +++ b/build/vertor-optimizer/vector.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"vector.d.ts","sourceRoot":"","sources":["../../src/vertor-optimizer/vector.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,KAAK;IACpB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED,qBAAa,MAAM;IAKS,CAAC,EAAE,MAAM;IAAS,CAAC,EAAE,MAAM;WAJvC,IAAI,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM;gBAId,CAAC,EAAE,MAAM,EAAS,CAAC,EAAE,MAAM;IAE9C,GAAG,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM;IAO/B,QAAQ,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM;IAOpC,QAAQ,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM;IAOpC,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM;IAOlC,QAAQ,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM;IAI3B,eAAe,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM;IAMlC,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM;IAOzC,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO;IAIjC,GAAG,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM;IAItB,aAAa,IAAI,MAAM;IAIvB,MAAM,IAAI,MAAM;IAIhB,SAAS,IAAI,MAAM;CAG3B"} \ No newline at end of file diff --git a/build/vertor-optimizer/vector.js b/build/vertor-optimizer/vector.js new file mode 100644 index 0000000..e7c6c2f --- /dev/null +++ b/build/vertor-optimizer/vector.js @@ -0,0 +1,52 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Vector = void 0; +class Vector { + constructor(x, y) { + this.x = x; + this.y = y; + } + static from(point) { + return new Vector(point.x, point.y); + } + add(a) { + return new Vector(this.x + (a instanceof Vector ? a.x : a), this.y + (a instanceof Vector ? a.y : a)); + } + subtract(a) { + return new Vector(this.x - (a instanceof Vector ? a.x : a), this.y - (a instanceof Vector ? a.y : a)); + } + multiply(a) { + return new Vector(this.x * (a instanceof Vector ? a.x : a), this.y * (a instanceof Vector ? a.y : a)); + } + divide(a) { + return new Vector(this.x / (a instanceof Vector ? a.x : a), this.y / (a instanceof Vector ? a.y : a)); + } + distance(a) { + return Math.sqrt(this.distanceSquared(a)); + } + distanceSquared(a) { + const x = this.x - a.x; + const y = this.y - a.y; + return x * x + y * y; + } + lerp(v, fraction) { + return new Vector(this.x + (v.x - this.x) * fraction, this.y + (v.y - this.y) * fraction); + } + equalsOrClose(a) { + return this.distanceSquared(a) < Number.EPSILON; + } + dot(a) { + return this.x * a.x + this.y * a.y; + } + lengthSquared() { + return this.x * this.x + this.y * this.y; + } + length() { + return Math.sqrt(this.x * this.x + this.y * this.y); + } + normalize() { + return this.divide(this.length()); + } +} +exports.Vector = Vector; +//# sourceMappingURL=vector.js.map \ No newline at end of file diff --git a/build/vertor-optimizer/vector.js.map b/build/vertor-optimizer/vector.js.map new file mode 100644 index 0000000..22d9b6d --- /dev/null +++ b/build/vertor-optimizer/vector.js.map @@ -0,0 +1 @@ +{"version":3,"file":"vector.js","sourceRoot":"","sources":["../../src/vertor-optimizer/vector.ts"],"names":[],"mappings":";;;AAKA,MAAa,MAAM;IAKjB,YAA0B,CAAS,EAAS,CAAS;QAA3B,MAAC,GAAD,CAAC,CAAQ;QAAS,MAAC,GAAD,CAAC,CAAQ;IAAG,CAAC;IAJlD,MAAM,CAAC,IAAI,CAAC,KAAY;QAC7B,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,K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,CAAC,CAAC,CAAC;IACtD,CAAC;IAEM,SAAS;QACd,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IACpC,CAAC;CACF;AAvED,wBAuEC"} \ No newline at end of file diff --git a/dist/vector-optimizer.min.js b/dist/vector-optimizer.min.js new file mode 100644 index 0000000..360a8ab --- /dev/null +++ b/dist/vector-optimizer.min.js @@ -0,0 +1,2 @@ +/*! For license information please see vector-optimizer.min.js.LICENSE.txt */ +!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.VectorOptimizer=e():t.VectorOptimizer=e()}(self,(function(){return function(){"use strict";var t={541:function(t,e,r){const n=r(655).__importStar(r(519));t.exports=n},519:function(t,e,r){Object.defineProperty(e,"__esModule",{value:!0});const n=r(655);n.__exportStar(r(564),e),n.__exportStar(r(664),e),n.__exportStar(r(269),e),n.__exportStar(r(738),e),n.__exportStar(r(80),e)},564:function(t,e,r){Object.defineProperty(e,"__esModule",{value:!0}),e.CubicBezier=void 0;const n=r(80);class o{constructor(t,e,r,n){this.p0=t,this.p1=e,this.p2=r,this.p3=n}static from(t){return new o(n.Vector.from(t.p0),n.Vector.from(t.p1),n.Vector.from(t.p2),n.Vector.from(t.p3))}sample(t){const e=1-t,r=e*e*e,n=3*e*e*t,o=3*e*t*t,i=t*t*t;return this.p0.multiply(r).add(this.p1.multiply(n)).add(this.p2.multiply(o)).add(this.p3.multiply(i))}}e.CubicBezier=o},664:function(t,e,r){Object.defineProperty(e,"__esModule",{value:!0}),e.CurveFitBase=void 0;const n=r(564),o=r(80);e.CurveFitBase=class{constructor(){this._u=[],this._squaredError=0}fitCurve(t,e,r,o,i,u){const s={response:!1,split:u,curve:i},a=this._pts,c=e-t+1;if(c<2)throw new Error("INTERNAL ERROR: Should always have at least 2 points here");if(2==c){const c=a[t],l=a[e],f=c.distance(l)/3,p=r.multiply(f).add(c),h=o.multiply(f).add(l);return i=new n.CubicBezier(c,p,h,l),s.curve=i,u=0,s.split=u,s.response=!0,s}u=0,s.split=u,this.arcLengthParamaterize(t,e),i=null,s.curve=i;for(let n=0;n<5;n++){0!=n&&this.reparameterize(t,e,i),i=this.generateBezier(t,e,r,o),s.curve=i;const u=this.findMaxSquaredError(t,e,i,s.split);if(s.split=u.split,u.responsec&&(c=a,s=e)}return(n=s+t)<=t&&(n=t+1),n>=e&&(n=e-1),o.split=n,o.response=c,o}generateBezier(t,e,r,o){const i=this._pts,u=this._u,s=e-t+1,a=i[t],c=i[e];let l=0,f=0,p=0,h=0,d=0;for(let e=1;eNumber.EPSILON&&b>=0&&b<=1&&(o[e]=b)}}arcLengthParamaterize(t,e){const r=this._arclen,n=this._u;n.splice(0);const o=r[e]-r[t],i=r[t],u=e-t;n.push(0);for(let e=1;eNumber.EPSILON&&(i=u.divide(s).normalize()),i}getRightTangent(t){const e=this._pts,r=this._arclen,n=r[r.length-1],o=e[e.length-1];let i=e[e.length-2].subtract(o).normalize(),u=i,s=1;t=Math.max(e.length-9,t+1);for(let i=e.length-3;i>=t;i--){const t=r[i]/n,a=t*t*t,c=e[i].subtract(o).normalize();u=u.add(c.multiply(a)),s+=a}return u.length()>Number.EPSILON&&(i=u.divide(s).normalize()),i}getCenterTangent(t,e,r){const n=this._pts,i=this._arclen,u=i[r],s=n[r],a=i[t];let c=u-a,l=new o.Vector(0,0),f=0;for(let e=Math.max(t,r-4);eNumber.EPSILON&&f>Number.EPSILON?l.divide(f).normalize():n[r-1].subtract(s).normalize();c=i[e]-u;const h=Math.min(e,r+4);l=new o.Vector(0,0),f=0;for(let t=r+1;t<=h;t++){const e=1-(i[t]-u)/c,r=e*e*e,o=s.subtract(n[t]).normalize();l=l.add(o.multiply(r)),f+=r}let d=l.length()>Number.EPSILON&&f>Number.EPSILON?l.divide(f).normalize():s.subtract(n[r+1]).normalize();return l=p.add(d),l.lengthSquared()this._pts.length-9&&(n=this.getRightTangent(i)),this.fitRecursive(t,i,r,u),this.fitRecursive(i,e,s,n)}}}e.CurveFit=s},738:function(t,e){function r(t){if(t.length<2)return t;let e=t[0];const r=t.length;let n=0;for(let o=1;of&&(f=r,p=e)}0!=p&&(u.push(p),n(t,e,r,p,u),n(t,e,p,i,u))}function o(t,e,r,n,o){return Math.abs(n+e.x*o.y+o.x*t.y-o.x*e.y-t.x*o.y)/r}Object.defineProperty(e,"__esModule",{value:!0}),e.perpendicularDistance=e.rdpRecursive=e.rdpReduce=e.removeDuplicates=e.linearize=void 0,e.linearize=function(t,e,r=!1,n=!0){const o=[];if(null===t)throw new Error("Source vector array is null");if(e<=Number.EPSILON)throw new Error(`md ${e}' is be less than epsilon ${Number.EPSILON}`);if(t.length>0){let i=t[0];o.push(i);let u=0;for(let r=1;re){const t=e-u;o.push(s.lerp(a,t/c));let r=c-t;for(;r>e;)if(r-=e,n){const t=s.lerp(a,(c-r)/c);t.equalsOrClose(i)||(o.push(t),i=t)}u=r}else u+=c}const s=t[t.length-1];!r&&i.equalsOrClose(s)||o.push(s)}return o},e.removeDuplicates=r,e.rdpReduce=function(t,e){if(null==t)throw new Error("pts");if((t=r(t)).length<3)return[...t];const o=[];o.push(0),o.push(t.length-1),n(t,e,0,t.length-1,o),o.sort();const i=[];return o.forEach((e=>i.push(t[e]))),i},e.rdpRecursive=n,e.perpendicularDistance=o},80:function(t,e){Object.defineProperty(e,"__esModule",{value:!0}),e.Vector=void 0;class r{constructor(t,e){this.x=t,this.y=e}static from(t){return new r(t.x,t.y)}add(t){return new r(this.x+(t instanceof r?t.x:t),this.y+(t instanceof r?t.y:t))}subtract(t){return new r(this.x-(t instanceof r?t.x:t),this.y-(t instanceof r?t.y:t))}multiply(t){return new r(this.x*(t instanceof r?t.x:t),this.y*(t instanceof r?t.y:t))}divide(t){return new r(this.x/(t instanceof r?t.x:t),this.y/(t instanceof r?t.y:t))}distance(t){return Math.sqrt(this.distanceSquared(t))}distanceSquared(t){const e=this.x-t.x,r=this.y-t.y;return e*e+r*r}lerp(t,e){return new r(this.x+(t.x-this.x)*e,this.y+(t.y-this.y)*e)}equalsOrClose(t){return this.distanceSquared(t)=0;s--)(o=t[s])&&(u=(i<3?o(u):i>3?o(e,r,u):o(e,r))||u);return i>3&&u&&Object.defineProperty(e,r,u),u}function a(t,e){return function(r,n){e(r,n,t)}}function c(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}function l(t,e,r,n){return new(r||(r=Promise))((function(o,i){function u(t){try{a(n.next(t))}catch(t){i(t)}}function s(t){try{a(n.throw(t))}catch(t){i(t)}}function a(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(u,s)}a((n=n.apply(t,e||[])).next())}))}function f(t,e){var r,n,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;u;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,n=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function y(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,o,i=r.call(t),u=[];try{for(;(void 0===e||e-- >0)&&!(n=i.next()).done;)u.push(n.value)}catch(t){o={error:t}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return u}function m(){for(var t=[],e=0;e1||s(t,e)}))})}function s(t,e){try{(r=o[t](e)).value instanceof b?Promise.resolve(r.value.v).then(a,c):l(i[0][2],r)}catch(t){l(i[0][3],t)}var r}function a(t){s("next",t)}function c(t){s("throw",t)}function l(t,e){t(e),i.shift(),i.length&&s(i[0][0],i[0][1])}}function g(t){var e,r;return e={},n("next"),n("throw",(function(t){throw t})),n("return"),e[Symbol.iterator]=function(){return this},e;function n(n,o){e[n]=t[n]?function(e){return(r=!r)?{value:b(t[n](e)),done:"return"===n}:o?o(e):e}:o}}function x(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,r=t[Symbol.asyncIterator];return r?r.call(t):(t=d(t),e={},n("next"),n("throw"),n("return"),e[Symbol.asyncIterator]=function(){return this},e);function n(r){e[r]=t[r]&&function(e){return new Promise((function(n,o){!function(t,e,r,n){Promise.resolve(n).then((function(e){t({value:e,done:r})}),e)}(n,o,(e=t[r](e)).done,e.value)}))}}}function w(t,e){return Object.defineProperty?Object.defineProperty(t,"raw",{value:e}):t.raw=e,t}function O(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r in t)Object.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e.default=t,e}function S(t){return t&&t.__esModule?t:{default:t}}function P(t,e){if(!e.has(t))throw new TypeError("attempted to get private field on non-instance");return e.get(t)}function E(t,e,r){if(!e.has(t))throw new TypeError("attempted to set private field on non-instance");return e.set(t,r),r}}},e={};function r(n){var o=e[n];if(void 0!==o)return o.exports;var i=e[n]={exports:{}};return t[n](i,i.exports,r),i.exports}return r.d=function(t,e){for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r(541)}()})); \ No newline at end of file diff --git a/dist/vector-optimizer.min.js.LICENSE.txt b/dist/vector-optimizer.min.js.LICENSE.txt new file mode 100644 index 0000000..c18ab1d --- /dev/null +++ b/dist/vector-optimizer.min.js.LICENSE.txt @@ -0,0 +1,14 @@ +/*! ***************************************************************************** +Copyright (c) Microsoft Corporation. + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. +***************************************************************************** */ diff --git a/package.json b/package.json index e3c926a..997062c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vector-optimizer", - "version": "1.0.0", + "version": "1.0.1", "description": "curves for javascript", "main": "build/main.js", "types": "build/main.d.ts",