@@ -54,63 +54,21 @@ class SpiroSimplifier {
54
54
if ( arc . arcLength > 1e-6 ) this . combinedArcs . push ( arc ) ;
55
55
} else {
56
56
const combined = new SpiroSequenceArc ( this . m_ongoingArcs ) ;
57
- if ( combined . totalLength > 1e-6 ) this . combinedArcs . push ( combined ) ;
57
+ if ( ! combined . isEmpty ( ) && combined . totalLength > 1e-6 ) {
58
+ this . combinedArcs . push ( combined ) ;
59
+ }
58
60
}
59
61
this . m_ongoingArcs = [ ] ;
60
62
}
61
63
}
62
64
63
- class SpiroSequenceArc {
65
+ const SpiroMeasurer = {
66
+ measureLength ( a ) {
67
+ return a . arcLength ;
68
+ } ,
69
+ } ;
70
+ class SpiroSequenceArc extends TypoGeom . Arcs . CombinedArc {
64
71
constructor ( segments ) {
65
- // Filter out zero-length segments
66
- let rear = 0 ;
67
- for ( let j = 0 ; j < segments . length ; j ++ ) {
68
- if ( segments [ j ] . arcLength > 1e-6 ) {
69
- segments [ rear ++ ] = segments [ j ] ;
70
- }
71
- }
72
- segments . length = rear ;
73
-
74
- // Compute total length and stops
75
- let totalLength = 0 ;
76
- let stops = [ ] ;
77
- for ( let j = 0 ; j < segments . length ; j ++ ) {
78
- stops [ j ] = totalLength ;
79
- totalLength += segments [ j ] . arcLength ;
80
- }
81
- for ( let j = 0 ; j < segments . length ; j ++ ) {
82
- stops [ j ] = stops [ j ] / totalLength ;
83
- }
84
- this . totalLength = totalLength ;
85
- this . m_segments = segments ;
86
- this . m_stops = stops ;
87
- }
88
-
89
- eval ( t ) {
90
- const j = segTSearch ( this . m_stops , t ) ;
91
- const tBefore = this . m_stops [ j ] ;
92
- const tNext = j < this . m_stops . length - 1 ? this . m_stops [ j + 1 ] : 1 ;
93
- const tRelative = ( t - tBefore ) / ( tNext - tBefore ) ;
94
- return this . m_segments [ j ] . eval ( tRelative ) ;
95
- }
96
-
97
- derivative ( t ) {
98
- const j = segTSearch ( this . m_stops , t ) ;
99
- const tBefore = this . m_stops [ j ] ;
100
- const tNext = j < this . m_stops . length - 1 ? this . m_stops [ j + 1 ] : 1 ;
101
- const tRelative = ( t - tBefore ) / ( tNext - tBefore ) ;
102
- return Vec2 . scaleFrom ( 1 / ( tNext - tBefore ) , this . m_segments [ j ] . derivative ( tRelative ) ) ;
103
- }
104
- }
105
-
106
- function segTSearch ( stops , t ) {
107
- if ( t < 0 ) return 0 ;
108
- let l = 0 ,
109
- r = stops . length ;
110
- while ( l < r ) {
111
- let m = ( l + r ) >>> 1 ;
112
- if ( stops [ m ] > t ) r = m ;
113
- else l = m + 1 ;
72
+ super ( SpiroMeasurer , segments ) ;
114
73
}
115
- return r - 1 ;
116
74
}
0 commit comments