File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -167,6 +167,24 @@ const approxCurveLength = (a: Point, b: Point): number => {
167167 return ( ab + abHandle + a . handleOut . length + b . handleIn . length ) / 2 ;
168168} ;
169169
170+ const calcOptimalOffset = ( a : Coord [ ] , b : Coord [ ] ) : number => {
171+ const count = a . length ;
172+ let min = Infinity ;
173+ let minIndex = 0 ;
174+ for ( let i = 0 ; i < count ; i ++ ) {
175+ let sum = 0 ;
176+ for ( let j = 0 ; j < count ; j ++ ) {
177+ sum += distance ( a [ j ] , b [ ( j + i ) % count ] ) ;
178+ if ( sum > min ) break ;
179+ }
180+ if ( sum < min ) {
181+ min = sum ;
182+ minIndex = i ;
183+ }
184+ }
185+ return minIndex ;
186+ } ;
187+
170188const divideShape = ( count : number , points : Point [ ] ) : Point [ ] => {
171189 if ( points . length < 3 ) throw new Error ( "not enough points" ) ;
172190 if ( count < points . length ) throw new Error ( "cannot remove points" ) ;
You can’t perform that action at this time.
0 commit comments