diff --git a/bezier-js/bezier-js-tests.ts b/bezier-js/bezier-js-tests.ts index 54c629d11b..2f9f2685a2 100644 --- a/bezier-js/bezier-js-tests.ts +++ b/bezier-js/bezier-js-tests.ts @@ -1,27 +1,29 @@ /// function test() { - + var bezierjs: typeof BezierJs; - - var bezier = new bezierjs.Bezier([1,2,3,4]); + + var bezier = new bezierjs.Bezier([1, 2, 3, 4]); var cap = new bezierjs.BezierCap([]); var point: BezierJs.Point = { x: 0, y: 0 }; var utils = bezier.getUtils(); - var line: BezierJs.Line = { p1: { x:0, y: 0}, p2: {x:1, y: 1}}; + var line: BezierJs.Line = { p1: { x: 0, y: 0 }, p2: { x: 1, y: 1 } }; var abc: BezierJs.ABC = { A: null, B: null, C: null }; var arc: BezierJs.Arc = { e: 0, s: 0, x: 0, y: 0, r: 1 }; var bbox: BezierJs.BBox = bezier.bbox(); - var closest: BezierJs.Closest = { mdist: 1, mpos: 0 }; - var inflection: BezierJs.Inflection = { values: null, x: [0], y: [0], z:[0] }; + var closest: BezierJs.Closest = { mdist: 1, mpos: 0 }; + var inflection: BezierJs.Inflection = { values: null, x: [0], y: [0], z: [0] }; var minmax: BezierJs.MinMax = { min: 0, max: 0 }; var offset: BezierJs.Offset = { x: 0, y: 0, c: point, n: point }; var pair: BezierJs.Pair = { left: bezier, right: bezier }; var poly: BezierJs.PolyBezier = bezier.outline(1); var projection: BezierJs.Projection = { x: 0, y: 0, t: 9, d: 4 }; - var shape: BezierJs.Shape = { startcap: cap, endcap: cap, forward: bezier, back: bezier, bbox: bbox }; + var shape: BezierJs.Shape = { + startcap: cap, endcap: cap, forward: bezier, back: bezier, bbox: bbox, intersections: function (shape) { return [[0]]; } + }; var split: BezierJs.Split = { left: bezier, right: bezier, span: [point] }; - + bezier.arcs(); bezier.clockwise; bezier.compute(.5); @@ -36,10 +38,10 @@ function test() { bezier.length(); bezier.lineIntersects(line); bezier.normal(0); - bezier.offset(1,2); + bezier.offset(1, 2); bezier.on(point, 0); bezier.order = 5; - bezier.outlineshapes(1,3); + bezier.outlineshapes(1, 3); bezier.overlaps(bezier); bezier.point(9); bezier.project(point); @@ -52,9 +54,9 @@ function test() { bezier.split(0.5).left; bezier.toSVG(); bezier.update(); - + cap.virtual = true; - + poly.addCurve(bezier); poly.bbox(); poly.curve(7); @@ -62,12 +64,12 @@ function test() { poly.length(); poly.offset(9).points[0].y; poly.points[0]; - + utils.abcratio(0, 1); utils.align([point], line); utils.angle(point, point, point); utils.approximately(5, 7, .001); - utils.arcfn(1, function(){}); + utils.arcfn(1, function () { }); utils.bboxoverlap(bbox, bbox); utils.between(0, 0, 1); utils.closest([point], point); @@ -78,7 +80,7 @@ function test() { utils.findbbox([bezier]); utils.getccenter(point, point, point); utils.getminmax(bezier, 'x', [0]); - utils.length(function(){}); + utils.length(function () { }); utils.lerp(1, point, point); utils.lli(offset, offset); utils.lli4(point, point, point, point); @@ -92,5 +94,5 @@ function test() { utils.roots([point], line); utils.round(.999, .001); utils.shapeintersections(shape, bbox, shape, bbox); - + } \ No newline at end of file diff --git a/bezier-js/bezier-js.d.ts b/bezier-js/bezier-js.d.ts index 8256f4ce99..dfc699bc15 100644 --- a/bezier-js/bezier-js.d.ts +++ b/bezier-js/bezier-js.d.ts @@ -57,6 +57,7 @@ declare module BezierJs { back: Bezier; endcap: BezierCap; bbox: BBox; + intersections: (shape: Shape) => string[][] | number[][]; } interface ABC { A: Point; @@ -76,8 +77,8 @@ declare module BezierJs { * */ class Bezier { - clockwise: boolean; private _linear; + clockwise: boolean; _3d: boolean; _t1: number; _t2: number; @@ -128,12 +129,12 @@ declare module BezierJs { scale(d: Function): Bezier; scale(d: number): Bezier; outline(d1: number, d2?: number, d3?: number, d4?: number): PolyBezier; - outlineshapes(d1: number, d2: number): Shape[]; - intersects(curve: Bezier): string[] | number[]; + outlineshapes(d1: number, d2: number, curveIntersectionThreshold?: number): Shape[]; + intersects(curve: Bezier, curveIntersectionThreshold?: number): string[] | number[]; intersects(curve: Line): string[] | number[]; lineIntersects(line: Line): number[]; - selfintersects(): string[]; - curveintersects(c1: Bezier[], c2: Bezier[]): string[]; + selfintersects(curveIntersectionThreshold?: number): string[]; + curveintersects(c1: Bezier[], c2: Bezier[], curveIntersectionThreshold?: number): string[]; arcs(errorThreshold?: number): Arc[]; private _error(pc, np1, s, e); private _iterate(errorThreshold, circles); @@ -165,8 +166,8 @@ declare module BezierJs.utils { function lli(v1: Offset, v2: Offset): Point; function makeline(p1: Point, p2: Point): Bezier; function findbbox(sections: Bezier[]): BBox; - function shapeintersections(s1: Shape, bbox1: BBox, s2: Shape, bbox2: BBox): string[][] | number[][]; - function makeshape(forward: Bezier, back: Bezier): Shape; + function shapeintersections(s1: Shape, bbox1: BBox, s2: Shape, bbox2: BBox, curveIntersectionThreshold?: number): string[][] | number[][]; + function makeshape(forward: Bezier, back: Bezier, curveIntersectionThreshold?: number): Shape; function getminmax(curve: Bezier, d: string, list: number[]): MinMax; function align(points: Point[], line: Line): Point[]; function roots(points: Point[], line: Line): number[]; @@ -174,7 +175,7 @@ declare module BezierJs.utils { function inflections(points: Point[]): number[]; function bboxoverlap(b1: BBox, b2: BBox): boolean; function expandbox(bbox: BBox, _bbox: BBox): void; - function pairiteration(c1: Bezier, c2: Bezier): string[]; + function pairiteration(c1: Bezier, c2: Bezier, curveIntersectionThreshold?: number): string[]; function getccenter(p1: Point, p2: Point, p3: Point): Arc; } declare module BezierJs {