Skip to content

Commit 217a17c

Browse files
committed
Add pointMatchingDistance parameter to bezier seed functions
1 parent 4a3bf9d commit 217a17c

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

packages/maker.js/src/core/chain.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@
235235
var beziers: IWalkModel[];
236236
if (opts.unifyBeziers) {
237237
beziers = getBezierModels(modelContext);
238-
swapBezierPathsWithSeeds(beziers, true);
238+
swapBezierPathsWithSeeds(beziers, true, opts.pointMatchingDistance);
239239
}
240240

241241
walk(modelContext, walkOptions);
@@ -280,7 +280,7 @@
280280
}
281281

282282
if (beziers) {
283-
swapBezierPathsWithSeeds(beziers, false);
283+
swapBezierPathsWithSeeds(beziers, false, opts.pointMatchingDistance);
284284
}
285285

286286
if (opts.byLayers) {
@@ -398,7 +398,7 @@
398398
/**
399399
* @private
400400
*/
401-
function swapBezierPathsWithSeeds(beziers: IWalkModel[], swap: boolean) {
401+
function swapBezierPathsWithSeeds(beziers: IWalkModel[], swap: boolean, pointMatchingDistance: number) {
402402
const tempKey = 'tempPaths';
403403
const tempLayerKey = 'tempLayer';
404404

@@ -414,7 +414,7 @@
414414
}
415415

416416
//use seeds as path, hide the arc paths from findChains()
417-
var bezierPartsByLayer = models.BezierCurve.getBezierSeeds(b, { byLayers: true });
417+
var bezierPartsByLayer = models.BezierCurve.getBezierSeeds(b, { byLayers: true, pointMatchingDistance });
418418

419419
for (var layer in bezierPartsByLayer) {
420420
var bezierSeeds = bezierPartsByLayer[layer];
@@ -436,15 +436,15 @@
436436
//revert the above
437437

438438
if (tempKey in b) {
439-
b.paths = b[tempKey];
439+
b.paths = b[tempKey] as IPathMap;
440440
delete b[tempKey];
441441
}
442442

443443
if (tempLayerKey in b) {
444444
if (b[tempLayerKey] == undefined) {
445445
delete (b as IModel).layer;
446446
} else {
447-
(b as IModel).layer = b[tempLayerKey];
447+
(b as IModel).layer = b[tempLayerKey] as string;
448448
}
449449
delete b[tempLayerKey];
450450
}

packages/maker.js/src/core/model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ namespace MakerJs.model {
475475

476476
if (modelToDistort.type === models.BezierCurve.typeName) {
477477
const b = modelToDistort as models.BezierCurve;
478-
const bezierPartsByLayer = models.BezierCurve.getBezierSeeds(b, { byLayers: true });
478+
const bezierPartsByLayer = models.BezierCurve.getBezierSeeds(b, { byLayers: true, pointMatchingDistance: bezierAccuracy });
479479
for (let layer in bezierPartsByLayer) {
480480
let pathArray = bezierPartsByLayer[layer]
481481
pathArray.forEach((p, i) => {

packages/maker.js/src/models/BezierCurve.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@
245245
/**
246246
* @private
247247
*/
248-
function getActualBezierRange(curve: BezierCurve, arc: IPathArcInBezierCurve, endpoints: IPoint[], offset: IPoint): IBezierRange {
248+
function getActualBezierRange(curve: BezierCurve, arc: IPathArcInBezierCurve, endpoints: IPoint[], offset: IPoint, pointMatchingDistance: number): IBezierRange {
249249
var b = getScratch(curve.seed);
250250
var tPoints = [arc.bezierData.startT, arc.bezierData.endT].map(t => new TPoint(b, t, offset));
251251
var ends = endpoints.slice();
@@ -255,7 +255,7 @@
255255
if (endpointDistancetoStart[0] > endpointDistancetoStart[1]) ends.reverse();
256256

257257
for (var i = 2; i--;) {
258-
if (!measure.isPointEqual(ends[i], tPoints[i].point)) {
258+
if (!measure.isPointEqual(ends[i], tPoints[i].point, pointMatchingDistance)) {
259259
return null;
260260
}
261261
}
@@ -273,15 +273,15 @@
273273
/**
274274
* @private
275275
*/
276-
function getChainBezierRange(curve: BezierCurve, c: IChain, layer: string, addToLayer: IAddToLayer): IBezierRange {
276+
function getChainBezierRange(curve: BezierCurve, c: IChain, layer: string, addToLayer: IAddToLayer, pointMatchingDistance: number): IBezierRange {
277277

278278
var endLinks = [c.links[0], c.links[c.links.length - 1]];
279279
if ((endLinks[0].walkedPath.pathContext as IPathArcInBezierCurve).bezierData.startT > (endLinks[1].walkedPath.pathContext as IPathArcInBezierCurve).bezierData.startT) {
280280
chain.reverse(c);
281281
endLinks.reverse();
282282
}
283283

284-
var actualBezierRanges = endLinks.map(endLink => getActualBezierRange(curve, endLink.walkedPath.pathContext as IPathArcInBezierCurve, endLink.endPoints, endLink.walkedPath.offset));
284+
var actualBezierRanges = endLinks.map(endLink => getActualBezierRange(curve, endLink.walkedPath.pathContext as IPathArcInBezierCurve, endLink.endPoints, endLink.walkedPath.offset, pointMatchingDistance));
285285

286286
var result: IBezierRange = {
287287
startT: actualBezierRanges[0] ? actualBezierRanges[0].startT : null,
@@ -523,7 +523,7 @@
523523
model.findChains(curve, function (chains: IChain[], loose: IWalkPath[], layer: string) {
524524

525525
chains.forEach(c => {
526-
var range = getChainBezierRange(curve, c, layer, addToLayer);
526+
var range = getChainBezierRange(curve, c, layer, addToLayer, options.pointMatchingDistance);
527527
if (range) {
528528
var b = getScratch(curve.seed);
529529
var piece = b.split(range.startT, range.endT);
@@ -538,7 +538,7 @@
538538
//bezier is linear
539539
return addToLayer(wp.pathContext, layer, true);
540540
}
541-
var range = getActualBezierRange(curve, wp.pathContext as IPathArcInBezierCurve, point.fromPathEnds(wp.pathContext), wp.offset);
541+
var range = getActualBezierRange(curve, wp.pathContext as IPathArcInBezierCurve, point.fromPathEnds(wp.pathContext), wp.offset, options.pointMatchingDistance);
542542
if (range) {
543543
var b = getScratch(curve.seed);
544544
var piece = b.split(range.startT, range.endT);

0 commit comments

Comments
 (0)