Skip to content

Commit 3ee90fa

Browse files
committed
Remove remaining the implicit coordinates code
1 parent 5006a89 commit 3ee90fa

File tree

1 file changed

+11
-150
lines changed

1 file changed

+11
-150
lines changed

packages/geometry/src/spiro-control.mjs

Lines changed: 11 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -61,25 +61,15 @@ export class SpiroFlattener {
6161
}
6262
sink.push(c);
6363

64-
const cHasDependency =
65-
c.getDependency(RES_DEP_STAGE_COORDINATE_PROPOGATION_X) ||
66-
c.getDependency(RES_DEP_STAGE_COORDINATE_PROPOGATION_Y) ||
67-
c.getDependency(RES_DEP_STAGE_INTERPOLATION);
64+
const cHasDependency = c.getDependency(RES_DEP_STAGE_INTERPOLATION);
6865
return cHasDependency ? 1 : 0;
6966
}
7067
}
7168

7269
flattenImpl() {
73-
this.propagateCoordinates();
7470
return this.doInterpolate();
7571
}
7672

77-
propagateCoordinates() {
78-
const propagator = new CoordinatePropagator(this.controls);
79-
if (!propagator.nDependencies) return;
80-
propagator.solveAll();
81-
}
82-
8373
doInterpolate() {
8474
let nd = 0;
8575
let sink = [];
@@ -101,7 +91,7 @@ export class SpiroFlattener {
10191
return nd;
10292
}
10393

104-
getDependenciesForInterpolation(skipKind) {
94+
getDependenciesForInterpolation() {
10595
let nNonDependent = 0;
10696
let nDependent = 0;
10797
let deps = [];
@@ -156,70 +146,6 @@ export class SpiroFlattener {
156146
}
157147
}
158148

159-
/// Utility class to propagate coordinates
160-
class CoordinatePropagator {
161-
constructor(subjects) {
162-
this.nDependencies = 0;
163-
this.subjects = [];
164-
this.depX = [];
165-
this.stateX = [];
166-
this.depY = [];
167-
this.stateY = [];
168-
169-
for (const subject of subjects) {
170-
let dx = subject.getDependency(RES_DEP_STAGE_COORDINATE_PROPOGATION_X);
171-
let dy = subject.getDependency(RES_DEP_STAGE_COORDINATE_PROPOGATION_Y);
172-
if (dx === DEP_SKIP && dy === DEP_SKIP) continue;
173-
174-
this.subjects.push(subject);
175-
this.depX.push(dx), this.depY.push(dy);
176-
this.stateX.push(dx > DEP_SKIP ? CR_UNRESOLVED : CR_RESOLVED);
177-
this.stateY.push(dy > DEP_SKIP ? CR_UNRESOLVED : CR_RESOLVED);
178-
if (dx > DEP_SKIP) this.nDependencies += 1;
179-
if (dy > DEP_SKIP) this.nDependencies += 1;
180-
}
181-
}
182-
183-
solveAll() {
184-
for (let i = 0; i < this.subjects.length; i++) {
185-
this.solve(i, 0);
186-
this.solve(i, 1);
187-
}
188-
}
189-
solve(i, ic) {
190-
const depC = ic ? this.depY : this.depX;
191-
const stateC = ic ? this.stateY : this.stateX;
192-
193-
if (stateC[i] === CR_RESOLVED) return;
194-
if (stateC[i] === CR_RESOLVING) {
195-
console.log(this);
196-
throw new Error("Circular dependency detected");
197-
}
198-
199-
stateC[i] = CR_RESOLVING;
200-
201-
if (depC[i] & DEP_PRE_X) this.solve(this.cycI(i - 1), 0);
202-
if (depC[i] & DEP_PRE_Y) this.solve(this.cycI(i - 1), 1);
203-
if (depC[i] & DEP_SAME_X) this.solve(this.cycI(i), 0);
204-
if (depC[i] & DEP_SAME_Y) this.solve(this.cycI(i), 1);
205-
if (depC[i] & DEP_POST_X) this.solve(this.cycI(i + 1), 0);
206-
if (depC[i] & DEP_POST_Y) this.solve(this.cycI(i + 1), 1);
207-
208-
// console.log(i, ic, this);
209-
this.subjects[i].resolveCoordiantePropogation(
210-
ic,
211-
this.subjects[this.cycI(i - 1)].getKernelKnot(),
212-
this.subjects[this.cycI(i + 1)].getKernelKnot(),
213-
);
214-
215-
stateC[i] = CR_RESOLVED;
216-
}
217-
218-
cycI(i) {
219-
return (i + this.subjects.length) % this.subjects.length;
220-
}
221-
}
222-
223149
///////////////////////////////////////////////////////////////////////////////////////////////////
224150

225151
/** The "amendmend function" */
@@ -243,9 +169,7 @@ export class AfCombine extends AfBase {
243169

244170
///////////////////////////////////////////////////////////////////////////////////////////////////
245171

246-
const RES_DEP_STAGE_COORDINATE_PROPOGATION_X = 0;
247-
const RES_DEP_STAGE_COORDINATE_PROPOGATION_Y = 1;
248-
const RES_DEP_STAGE_INTERPOLATION = 2;
172+
const RES_DEP_STAGE_INTERPOLATION = 1;
249173

250174
export const DEP_SKIP = 0x1;
251175
export const DEP_PRE_X = 0x2;
@@ -258,10 +182,6 @@ export const DEP_POST_Y = 0x40;
258182
const DEP_PRE = DEP_PRE_X | DEP_PRE_Y;
259183
const DEP_POST = DEP_POST_X | DEP_POST_Y;
260184

261-
const CR_UNRESOLVED = 0;
262-
const CR_RESOLVING = 1;
263-
const CR_RESOLVED = 2;
264-
265185
export class UserControlKnot {
266186
constructor(type, x, y, af) {
267187
this.type = type;
@@ -273,17 +193,8 @@ export class UserControlKnot {
273193
if (this.af) this.af.applyTo(ctx);
274194
}
275195

276-
getDependency(stage) {
277-
switch (stage) {
278-
case RES_DEP_STAGE_COORDINATE_PROPOGATION_X:
279-
return typeof this.x === "number" ? 0 : this.x.getDependencyForX();
280-
case RES_DEP_STAGE_COORDINATE_PROPOGATION_Y:
281-
return typeof this.y === "number" ? 0 : this.y.getDependencyForY();
282-
case RES_DEP_STAGE_INTERPOLATION:
283-
return 0;
284-
default:
285-
return 0;
286-
}
196+
getDependency() {
197+
return 0;
287198
}
288199

289200
getKernelKnot() {
@@ -308,7 +219,7 @@ export class UserControlKnot {
308219
}
309220

310221
static isCoordinateValid(x) {
311-
return (typeof x === "number" && isFinite(x)) || x instanceof DerivedCoordinateBase;
222+
return isFinite(x);
312223
}
313224
}
314225

@@ -382,9 +293,6 @@ export class InterpolatorBase {
382293

383294
getDependency(stage) {
384295
switch (stage) {
385-
case RES_DEP_STAGE_COORDINATE_PROPOGATION_X:
386-
case RES_DEP_STAGE_COORDINATE_PROPOGATION_Y:
387-
return DEP_SKIP;
388296
case RES_DEP_STAGE_INTERPOLATION:
389297
return DEP_PRE | DEP_POST;
390298
default:
@@ -406,6 +314,11 @@ export class InterpolatorBase {
406314
}
407315
}
408316

317+
/**
318+
* Used in [decor@] (and thus operator (~~~)).
319+
* Make a list of control items "delayed" till resolution of interpolator.
320+
* Useful for specifying the decoration features of a path.
321+
*/
409322
export class DecorInterpolator extends InterpolatorBase {
410323
constructor(items) {
411324
super();
@@ -427,41 +340,6 @@ export class FunctionInterpolator extends InterpolatorBase {
427340
}
428341
}
429342

430-
/**
431-
* This class denotes an interpolator that has a proxy knot. The proxy could be used in the
432-
* coordinate propagation stage to resolve dependencies.
433-
*/
434-
export class KnotProxyInterpolator extends InterpolatorBase {
435-
constructor(proxy, actual) {
436-
super();
437-
this.knotProxy = proxy;
438-
this.actual = actual;
439-
}
440-
441-
getDependency(stage) {
442-
switch (stage) {
443-
case RES_DEP_STAGE_COORDINATE_PROPOGATION_X:
444-
case RES_DEP_STAGE_COORDINATE_PROPOGATION_Y:
445-
return this.knotProxy.getDependency(stage);
446-
default:
447-
return this.actual.getDependency(stage);
448-
}
449-
}
450-
451-
getKernelKnot() {
452-
return this.knotProxy.getKernelKnot();
453-
}
454-
resolveCoordiantePropogation(ic, pre, post) {
455-
this.knotProxy.resolveCoordiantePropogation(ic, pre, post);
456-
}
457-
resolveInterpolation(pre, post) {
458-
return this.actual.resolveInterpolation(pre, post);
459-
}
460-
}
461-
export function WithKnotProxy(proxy, actual) {
462-
return new KnotProxyInterpolator(proxy, actual);
463-
}
464-
465343
///////////////////////////////////////////////////////////////////////////////////////////////////
466344

467345
export class TerminateInstruction {
@@ -474,20 +352,3 @@ export class TerminateInstruction {
474352
if (this.af) throw new Error("Unreachable");
475353
}
476354
}
477-
478-
///////////////////////////////////////////////////////////////////////////////////////////////////
479-
480-
export class DerivedCoordinateBase {
481-
getDependencyForX() {
482-
throw new Error("Unimplemented");
483-
}
484-
getDependencyForY() {
485-
throw new Error("Unimplemented");
486-
}
487-
resolveX(pre, curr, post) {
488-
throw new Error("Unimplemented");
489-
}
490-
resolveY(pre, curr, post) {
491-
throw new Error("Unimplemented");
492-
}
493-
}

0 commit comments

Comments
 (0)