Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions docs/demos/index.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/index.html

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions docs/target/js/browser.maker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2674,7 +2674,7 @@ var MakerJs;
}
if (modelToDistort.type === MakerJs.models.BezierCurve.typeName) {
var b = modelToDistort;
var bezierPartsByLayer = MakerJs.models.BezierCurve.getBezierSeeds(b, { byLayers: true });
var bezierPartsByLayer = MakerJs.models.BezierCurve.getBezierSeeds(b, { byLayers: true, pointMatchingDistance: bezierAccuracy });
var _loop_1 = function (layer_1) {
var pathArray = bezierPartsByLayer[layer_1];
pathArray.forEach(function (p, i) {
Expand Down Expand Up @@ -6437,7 +6437,7 @@ var MakerJs;
var beziers;
if (opts.unifyBeziers) {
beziers = getBezierModels(modelContext);
swapBezierPathsWithSeeds(beziers, true);
swapBezierPathsWithSeeds(beziers, true, opts.pointMatchingDistance);
}
model.walk(modelContext, walkOptions);
var _loop_3 = function (layer_2) {
Expand Down Expand Up @@ -6474,7 +6474,7 @@ var MakerJs;
_loop_3(layer_2);
}
if (beziers) {
swapBezierPathsWithSeeds(beziers, false);
swapBezierPathsWithSeeds(beziers, false, opts.pointMatchingDistance);
}
if (opts.byLayers) {
return chainsByLayer;
Expand Down Expand Up @@ -6571,7 +6571,7 @@ var MakerJs;
/**
* @private
*/
function swapBezierPathsWithSeeds(beziers, swap) {
function swapBezierPathsWithSeeds(beziers, swap, pointMatchingDistance) {
var tempKey = 'tempPaths';
var tempLayerKey = 'tempLayer';
beziers.forEach(function (wm) {
Expand All @@ -6583,7 +6583,7 @@ var MakerJs;
b.layer = wm.layer;
}
//use seeds as path, hide the arc paths from findChains()
var bezierPartsByLayer = MakerJs.models.BezierCurve.getBezierSeeds(b, { byLayers: true });
var bezierPartsByLayer = MakerJs.models.BezierCurve.getBezierSeeds(b, { byLayers: true, pointMatchingDistance: pointMatchingDistance });
for (var layer in bezierPartsByLayer) {
var bezierSeeds = bezierPartsByLayer[layer];
if (bezierSeeds.length > 0) {
Expand Down Expand Up @@ -9002,7 +9002,7 @@ var MakerJs;
/**
* @private
*/
function getActualBezierRange(curve, arc, endpoints, offset) {
function getActualBezierRange(curve, arc, endpoints, offset, pointMatchingDistance) {
var b = getScratch(curve.seed);
var tPoints = [arc.bezierData.startT, arc.bezierData.endT].map(function (t) { return new TPoint(b, t, offset); });
var ends = endpoints.slice();
Expand All @@ -9011,7 +9011,7 @@ var MakerJs;
if (endpointDistancetoStart[0] > endpointDistancetoStart[1])
ends.reverse();
for (var i = 2; i--;) {
if (!MakerJs.measure.isPointEqual(ends[i], tPoints[i].point)) {
if (!MakerJs.measure.isPointEqual(ends[i], tPoints[i].point, pointMatchingDistance)) {
return null;
}
}
Expand All @@ -9020,13 +9020,13 @@ var MakerJs;
/**
* @private
*/
function getChainBezierRange(curve, c, layer, addToLayer) {
function getChainBezierRange(curve, c, layer, addToLayer, pointMatchingDistance) {
var endLinks = [c.links[0], c.links[c.links.length - 1]];
if (endLinks[0].walkedPath.pathContext.bezierData.startT > endLinks[1].walkedPath.pathContext.bezierData.startT) {
MakerJs.chain.reverse(c);
endLinks.reverse();
}
var actualBezierRanges = endLinks.map(function (endLink) { return getActualBezierRange(curve, endLink.walkedPath.pathContext, endLink.endPoints, endLink.walkedPath.offset); });
var actualBezierRanges = endLinks.map(function (endLink) { return getActualBezierRange(curve, endLink.walkedPath.pathContext, endLink.endPoints, endLink.walkedPath.offset, pointMatchingDistance); });
var result = {
startT: actualBezierRanges[0] ? actualBezierRanges[0].startT : null,
endT: actualBezierRanges[1] ? actualBezierRanges[1].endT : null
Expand Down Expand Up @@ -9188,7 +9188,7 @@ var MakerJs;
};
MakerJs.model.findChains(curve, function (chains, loose, layer) {
chains.forEach(function (c) {
var range = getChainBezierRange(curve, c, layer, addToLayer);
var range = getChainBezierRange(curve, c, layer, addToLayer, options.pointMatchingDistance);
if (range) {
var b = getScratch(curve.seed);
var piece = b.split(range.startT, range.endT);
Expand All @@ -9203,7 +9203,7 @@ var MakerJs;
//bezier is linear
return addToLayer(wp.pathContext, layer, true);
}
var range = getActualBezierRange(curve, wp.pathContext, MakerJs.point.fromPathEnds(wp.pathContext), wp.offset);
var range = getActualBezierRange(curve, wp.pathContext, MakerJs.point.fromPathEnds(wp.pathContext), wp.offset, options.pointMatchingDistance);
if (range) {
var b = getScratch(curve.seed);
var piece = b.split(range.startT, range.endT);
Expand Down
12 changes: 6 additions & 6 deletions packages/maker.js/src/core/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@
var beziers: IWalkModel[];
if (opts.unifyBeziers) {
beziers = getBezierModels(modelContext);
swapBezierPathsWithSeeds(beziers, true);
swapBezierPathsWithSeeds(beziers, true, opts.pointMatchingDistance);
}

walk(modelContext, walkOptions);
Expand Down Expand Up @@ -280,7 +280,7 @@
}

if (beziers) {
swapBezierPathsWithSeeds(beziers, false);
swapBezierPathsWithSeeds(beziers, false, opts.pointMatchingDistance);
}

if (opts.byLayers) {
Expand Down Expand Up @@ -398,7 +398,7 @@
/**
* @private
*/
function swapBezierPathsWithSeeds(beziers: IWalkModel[], swap: boolean) {
function swapBezierPathsWithSeeds(beziers: IWalkModel[], swap: boolean, pointMatchingDistance: number) {
const tempKey = 'tempPaths';
const tempLayerKey = 'tempLayer';

Expand All @@ -414,7 +414,7 @@
}

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

for (var layer in bezierPartsByLayer) {
var bezierSeeds = bezierPartsByLayer[layer];
Expand All @@ -436,15 +436,15 @@
//revert the above

if (tempKey in b) {
b.paths = b[tempKey];
b.paths = b[tempKey] as IPathMap;
delete b[tempKey];
}

if (tempLayerKey in b) {
if (b[tempLayerKey] == undefined) {
delete (b as IModel).layer;
} else {
(b as IModel).layer = b[tempLayerKey];
(b as IModel).layer = b[tempLayerKey] as string;
}
delete b[tempLayerKey];
}
Expand Down
2 changes: 1 addition & 1 deletion packages/maker.js/src/core/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ namespace MakerJs.model {

if (modelToDistort.type === models.BezierCurve.typeName) {
const b = modelToDistort as models.BezierCurve;
const bezierPartsByLayer = models.BezierCurve.getBezierSeeds(b, { byLayers: true });
const bezierPartsByLayer = models.BezierCurve.getBezierSeeds(b, { byLayers: true, pointMatchingDistance: bezierAccuracy });
for (let layer in bezierPartsByLayer) {
let pathArray = bezierPartsByLayer[layer]
pathArray.forEach((p, i) => {
Expand Down
12 changes: 6 additions & 6 deletions packages/maker.js/src/models/BezierCurve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@
/**
* @private
*/
function getActualBezierRange(curve: BezierCurve, arc: IPathArcInBezierCurve, endpoints: IPoint[], offset: IPoint): IBezierRange {
function getActualBezierRange(curve: BezierCurve, arc: IPathArcInBezierCurve, endpoints: IPoint[], offset: IPoint, pointMatchingDistance: number): IBezierRange {
var b = getScratch(curve.seed);
var tPoints = [arc.bezierData.startT, arc.bezierData.endT].map(t => new TPoint(b, t, offset));
var ends = endpoints.slice();
Expand All @@ -255,7 +255,7 @@
if (endpointDistancetoStart[0] > endpointDistancetoStart[1]) ends.reverse();

for (var i = 2; i--;) {
if (!measure.isPointEqual(ends[i], tPoints[i].point)) {
if (!measure.isPointEqual(ends[i], tPoints[i].point, pointMatchingDistance)) {
return null;
}
}
Expand All @@ -273,15 +273,15 @@
/**
* @private
*/
function getChainBezierRange(curve: BezierCurve, c: IChain, layer: string, addToLayer: IAddToLayer): IBezierRange {
function getChainBezierRange(curve: BezierCurve, c: IChain, layer: string, addToLayer: IAddToLayer, pointMatchingDistance: number): IBezierRange {

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

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

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

chains.forEach(c => {
var range = getChainBezierRange(curve, c, layer, addToLayer);
var range = getChainBezierRange(curve, c, layer, addToLayer, options.pointMatchingDistance);
if (range) {
var b = getScratch(curve.seed);
var piece = b.split(range.startT, range.endT);
Expand All @@ -538,7 +538,7 @@
//bezier is linear
return addToLayer(wp.pathContext, layer, true);
}
var range = getActualBezierRange(curve, wp.pathContext as IPathArcInBezierCurve, point.fromPathEnds(wp.pathContext), wp.offset);
var range = getActualBezierRange(curve, wp.pathContext as IPathArcInBezierCurve, point.fromPathEnds(wp.pathContext), wp.offset, options.pointMatchingDistance);
if (range) {
var b = getScratch(curve.seed);
var piece = b.split(range.startT, range.endT);
Expand Down
20 changes: 10 additions & 10 deletions packages/maker.js/test/data/newrocker-NewRocker-Regular.json
Original file line number Diff line number Diff line change
Expand Up @@ -978,12 +978,12 @@
"arc_1": {
"type": "arc",
"origin": [
34.21829549156312,
20.29048503372315
34.21829499017781,
20.290491976000105
],
"radius": 24.489835405737637,
"startAngle": 245.1291957434888,
"endAngle": 248.37085975705295,
"radius": 24.489841674393777,
"startAngle": 245.12920363866954,
"endAngle": 248.37086683423286,
"bezierData": {
"startT": 0.375,
"endT": 0.765625
Expand All @@ -992,12 +992,12 @@
"arc_2": {
"type": "arc",
"origin": [
31.345750652972885,
14.049104010594398
31.345837857608277,
14.049286424965011
],
"radius": 17.619183600608075,
"startAngle": 242.64611943578197,
"endAngle": 245.06799726651286,
"radius": 17.61938577599639,
"startAngle": 242.6461401266273,
"endAngle": 245.0679901692163,
"bezierData": {
"startT": 0.765625,
"endT": 1
Expand Down