@@ -22,6 +22,9 @@ export class GeometryBase {
22
22
toReferences ( ) {
23
23
throw new Error ( "Unimplemented" ) ;
24
24
}
25
+ toIndependent ( ) {
26
+ throw new Error ( "Unimplemented" ) ;
27
+ }
25
28
getDependencies ( ) {
26
29
throw new Error ( "Unimplemented" ) ;
27
30
}
@@ -50,6 +53,9 @@ export class ContourSetGeometry extends GeometryBase {
50
53
toReferences ( ) {
51
54
return null ;
52
55
}
56
+ toIndependent ( ) {
57
+ return this ;
58
+ }
53
59
getDependencies ( ) {
54
60
return null ;
55
61
}
@@ -102,25 +108,32 @@ export class CachedGeometry extends GeometryBase {
102
108
}
103
109
}
104
110
105
- export class SpiroGeometry extends CachedGeometry {
106
- constructor ( gizmo , closed , knots ) {
107
- super ( ) ;
108
- this . m_knots = knots ;
109
- this . m_closed = closed ;
110
- this . m_gizmo = gizmo ;
111
- }
112
- toContoursImpl ( ) {
113
- return spiroToOutlineWithSimplification ( this . m_knots , this . m_closed , this . m_gizmo ) ;
114
- }
111
+ class SimpleGeometry extends CachedGeometry {
115
112
toReferences ( ) {
116
113
return null ;
117
114
}
115
+ toIndependent ( ) {
116
+ return this ;
117
+ }
118
118
getDependencies ( ) {
119
119
return null ;
120
120
}
121
121
filterTag ( fn ) {
122
122
return this ;
123
123
}
124
+ }
125
+
126
+ export class SpiroGeometry extends SimpleGeometry {
127
+ constructor ( gizmo , closed , knots ) {
128
+ super ( ) ;
129
+ this . m_knots = knots ;
130
+ this . m_closed = closed ;
131
+ this . m_gizmo = gizmo ;
132
+ }
133
+ toContoursImpl ( ) {
134
+ return spiroToOutlineWithSimplification ( this . m_knots , this . m_closed , this . m_gizmo ) ;
135
+ }
136
+
124
137
measureComplexity ( ) {
125
138
let cplx = CPLX_NON_EMPTY | CPLX_NON_SIMPLE ;
126
139
for ( const z of this . m_knots ) {
@@ -140,7 +153,7 @@ export class SpiroGeometry extends CachedGeometry {
140
153
}
141
154
}
142
155
143
- export class SpiroPenGeometry extends CachedGeometry {
156
+ export class SpiroPenGeometry extends SimpleGeometry {
144
157
constructor ( gizmo , penProfile , closed , knots ) {
145
158
super ( ) ;
146
159
this . m_gizmo = gizmo ;
@@ -177,16 +190,6 @@ export class SpiroPenGeometry extends CachedGeometry {
177
190
return ctx . contours ;
178
191
}
179
192
180
- toReferences ( ) {
181
- return null ;
182
- }
183
- getDependencies ( ) {
184
- return null ;
185
- }
186
- filterTag ( fn ) {
187
- return this ;
188
- }
189
-
190
193
measureComplexity ( ) {
191
194
let cplx = CPLX_NON_EMPTY | CPLX_NON_SIMPLE ;
192
195
for ( const z of this . m_penProfile ) {
@@ -217,7 +220,7 @@ export class SpiroPenGeometry extends CachedGeometry {
217
220
}
218
221
}
219
222
220
- export class DiSpiroGeometry extends CachedGeometry {
223
+ export class DiSpiroGeometry extends SimpleGeometry {
221
224
constructor ( gizmo , contrast , closed , biKnots ) {
222
225
super ( ) ;
223
226
this . m_biKnots = biKnots ; // untransformed
@@ -261,15 +264,7 @@ export class DiSpiroGeometry extends CachedGeometry {
261
264
}
262
265
return expander . expand ( ) ;
263
266
}
264
- toReferences ( ) {
265
- return null ;
266
- }
267
- getDependencies ( ) {
268
- return null ;
269
- }
270
- filterTag ( fn ) {
271
- return this ;
272
- }
267
+
273
268
measureComplexity ( ) {
274
269
let cplx = CPLX_NON_EMPTY | CPLX_NON_SIMPLE ;
275
270
for ( const z of this . m_biKnots ) {
@@ -298,14 +293,24 @@ export class ReferenceGeometry extends GeometryBase {
298
293
this . m_x = x || 0 ;
299
294
this . m_y = y || 0 ;
300
295
}
301
- unwrap ( ) {
296
+
297
+ toIndependent ( ) {
298
+ // Do unlinking *recursively*
299
+ return TransformedGeometry . create (
300
+ Transform . Translate ( this . m_x , this . m_y ) ,
301
+ this . m_glyph . geometry . toIndependent ( ) ,
302
+ ) ;
303
+ }
304
+ unwrapSimple ( ) {
305
+ // Do unlinking *for only one level*
302
306
return TransformedGeometry . create (
303
307
Transform . Translate ( this . m_x , this . m_y ) ,
304
308
this . m_glyph . geometry ,
305
309
) ;
306
310
}
311
+
307
312
toContours ( ctx ) {
308
- return this . unwrap ( ) . toContours ( ctx ) ;
313
+ return this . unwrapSimple ( ) . toContours ( ctx ) ;
309
314
}
310
315
toReferences ( ) {
311
316
if ( this . m_glyph . geometry . measureComplexity ( ) & CPLX_NON_EMPTY ) {
@@ -319,13 +324,13 @@ export class ReferenceGeometry extends GeometryBase {
319
324
return [ this . m_glyph ] ;
320
325
}
321
326
filterTag ( fn ) {
322
- return this . unwrap ( ) . filterTag ( fn ) ;
327
+ return this . unwrapSimple ( ) . filterTag ( fn ) ;
323
328
}
324
329
measureComplexity ( ) {
325
330
return this . m_glyph . geometry . measureComplexity ( ) ;
326
331
}
327
332
hash ( h ) {
328
- this . unwrap ( ) . hash ( h ) ;
333
+ this . unwrapSimple ( ) . hash ( h ) ;
329
334
}
330
335
}
331
336
@@ -341,6 +346,9 @@ export class TaggedGeometry extends GeometryBase {
341
346
toReferences ( ) {
342
347
return this . m_geom . toReferences ( ) ;
343
348
}
349
+ toIndependent ( ) {
350
+ return new TaggedGeometry ( this . m_geom . toIndependent ( ) , this . m_tag ) ;
351
+ }
344
352
getDependencies ( ) {
345
353
return this . m_geom . getDependencies ( ) ;
346
354
}
@@ -395,6 +403,9 @@ export class TransformedGeometry extends GeometryBase {
395
403
result . push ( { glyph, x : x + this . m_transform . tx , y : y + this . m_transform . ty } ) ;
396
404
return result ;
397
405
}
406
+ toIndependent ( ) {
407
+ return TransformedGeometry . create ( this . m_transform , this . m_geom . toIndependent ( ) ) ;
408
+ }
398
409
getDependencies ( ) {
399
410
return this . m_geom . getDependencies ( ) ;
400
411
}
@@ -429,6 +440,9 @@ export class RadicalGeometry extends GeometryBase {
429
440
toReferences ( ) {
430
441
return null ;
431
442
}
443
+ toIndependent ( ) {
444
+ return new RadicalGeometry ( this . m_geom . toIndependent ( ) ) ;
445
+ }
432
446
getDependencies ( ) {
433
447
return this . m_geom . getDependencies ( ) ;
434
448
}
@@ -480,6 +494,9 @@ export class CombineGeometry extends GeometryBase {
480
494
}
481
495
return results ;
482
496
}
497
+ toIndependent ( ) {
498
+ return new CombineGeometry ( this . m_parts . map ( x => x . toIndependent ( ) ) ) ;
499
+ }
483
500
getDependencies ( ) {
484
501
let results = [ ] ;
485
502
for ( const part of this . m_parts ) {
@@ -557,9 +574,16 @@ export class BooleanGeometry extends CachedGeometry {
557
574
if ( i > 0 ) sink . push ( { type : "operator" , operator : this . m_operator } ) ;
558
575
}
559
576
}
577
+
560
578
toReferences ( ) {
561
579
return null ;
562
580
}
581
+ toIndependent ( ) {
582
+ return new BooleanGeometry (
583
+ this . m_operator ,
584
+ this . m_operands . map ( x => x . toIndependent ( ) ) ,
585
+ ) ;
586
+ }
563
587
getDependencies ( ) {
564
588
let results = [ ] ;
565
589
for ( const part of this . m_operands ) {
@@ -634,6 +658,15 @@ export class StrokeGeometry extends CachedGeometry {
634
658
toReferences ( ) {
635
659
return null ;
636
660
}
661
+ toIndependent ( ) {
662
+ return new StrokeGeometry (
663
+ this . m_geom . toIndependent ( ) ,
664
+ this . m_gizmo ,
665
+ this . m_radius ,
666
+ this . m_contrast ,
667
+ this . m_fInside ,
668
+ ) ;
669
+ }
637
670
getDependencies ( ) {
638
671
return this . m_geom . getDependencies ( ) ;
639
672
}
@@ -709,6 +742,9 @@ export class RemoveHolesGeometry extends CachedGeometry {
709
742
toReferences ( ) {
710
743
return null ;
711
744
}
745
+ toIndependent ( ) {
746
+ return new RemoveHolesGeometry ( this . m_geom . toIndependent ( ) , this . m_gizmo ) ;
747
+ }
712
748
getDependencies ( ) {
713
749
return this . m_geom . getDependencies ( ) ;
714
750
}
@@ -756,6 +792,9 @@ export class SimplifyGeometry extends CachedGeometry {
756
792
toReferences ( ) {
757
793
return null ;
758
794
}
795
+ toIndependent ( ) {
796
+ return new SimplifyGeometry ( this . m_geom . toIndependent ( ) ) ;
797
+ }
759
798
getDependencies ( ) {
760
799
return this . m_geom . getDependencies ( ) ;
761
800
}
0 commit comments