From 24acddcc5afc72597201fe76e6c48dc3d2960025 Mon Sep 17 00:00:00 2001 From: "Val Erastov (xibyte)" Date: Sun, 19 Jul 2020 21:59:04 -0700 Subject: [PATCH] move out legacy bezier luts --- web/app/cad/sketch/sketchModel.js | 4 +-- web/app/math/bezier-cubic.js | 33 --------------------- web/app/sketcher/shapes/bezier-curve.js | 38 +++++++++++++++++++++++-- 3 files changed, 36 insertions(+), 39 deletions(-) delete mode 100644 web/app/math/bezier-cubic.js diff --git a/web/app/cad/sketch/sketchModel.js b/web/app/cad/sketch/sketchModel.js index 58251ae4..1534c9f0 100644 --- a/web/app/cad/sketch/sketchModel.js +++ b/web/app/cad/sketch/sketchModel.js @@ -1,11 +1,9 @@ import verb from 'verb-nurbs' import BrepCurve from '../../brep/geom/curves/brepCurve'; import NurbsCurve from '../../brep/geom/curves/nurbsCurve'; -import {Point} from '../../brep/geom/point' -import {LUT} from '../../math/bezier-cubic' import {makeAngle0_360} from '../../../../modules/math/commons' import {normalizeCurveEnds} from '../../brep/geom/impl/nurbs-ext'; -import Vector, {AXIS, ORIGIN} from '../../../../modules/math/vector'; +import Vector from '../../../../modules/math/vector'; import CSys from "../../../../modules/math/csys"; import {distanceAB} from "../../../../modules/math/distance"; import {isCCW} from "../../../../modules/math/euclidean"; diff --git a/web/app/math/bezier-cubic.js b/web/app/math/bezier-cubic.js deleted file mode 100644 index 04b080bf..00000000 --- a/web/app/math/bezier-cubic.js +++ /dev/null @@ -1,33 +0,0 @@ -import Vector from 'math/vector'; - -export function LUT(a, b, cp1, cp2, scale) { - scale = 1 / scale; - const lut = []; - for (let t = 0; t < 1; t += 0.1 * scale) { - const p = compute(t, a, b, cp1, cp2); - lut.push(p); - } - lut[0] = a; - lut[lut.length - 1] = b; - return lut; -} - -export function compute(t, from, to, controlPoint1, controlPoint2) { - const mt = 1 - t; - const mt2 = mt * mt; - const t2 = t * t; - - const a = mt2 * mt; - const b = mt2 * t * 3; - const c = mt * t2 * 3; - const d = t * t2; - const p0 = from; - const p3 = to; - const p1 = controlPoint1; - const p2 = controlPoint2; - return new Vector( - a * p0.x + b * p1.x + c * p2.x + d * p3.x, - a * p0.y + b * p1.y + c * p2.y + d * p3.y, - a * p0.z + b * p1.z + c * p2.z + d * p3.z - ); -} diff --git a/web/app/sketcher/shapes/bezier-curve.js b/web/app/sketcher/shapes/bezier-curve.js index c1d12dbf..a1ab06c9 100644 --- a/web/app/sketcher/shapes/bezier-curve.js +++ b/web/app/sketcher/shapes/bezier-curve.js @@ -1,10 +1,10 @@ import {SketchObject} from './sketch-object' import {Segment} from './segment' -import {LUT} from '../../math/bezier-cubic' import {ConvexHull2D} from '../../math/convex-hull' import * as draw_utils from '../shapes/draw-utils' -import {isPointInsidePolygon, polygonOffset} from "../../../../modules/math/euclidean"; +import {isPointInsidePolygon, polygonOffset} from "math/euclidean"; +import Vector from "math/vector"; export class BezierCurve extends SketchObject { @@ -123,4 +123,36 @@ BezierCurve.prototype.TYPE = 'BezierCurve'; BezierCurve.prototype._class = 'TCAD.TWO.BezierCurve'; -const RECOVER_LENGTH = 100; \ No newline at end of file +const RECOVER_LENGTH = 100; + +export function LUT(a, b, cp1, cp2, scale) { + scale = 1 / scale; + const lut = []; + for (let t = 0; t < 1; t += 0.1 * scale) { + const p = compute(t, a, b, cp1, cp2); + lut.push(p); + } + lut[0] = a; + lut[lut.length - 1] = b; + return lut; +} + +export function compute(t, from, to, controlPoint1, controlPoint2) { + const mt = 1 - t; + const mt2 = mt * mt; + const t2 = t * t; + + const a = mt2 * mt; + const b = mt2 * t * 3; + const c = mt * t2 * 3; + const d = t * t2; + const p0 = from; + const p3 = to; + const p1 = controlPoint1; + const p2 = controlPoint2; + return new Vector( + a * p0.x + b * p1.x + c * p2.x + d * p3.x, + a * p0.y + b * p1.y + c * p2.y + d * p3.y, + a * p0.z + b * p1.z + c * p2.z + d * p3.z + ); +}