1- // http://www.cad.zju.edu.cn/home/zhx/papers/PoissonMorphing.pdf
2- // https://medium.com/@adrian_cooney /bezier-interpolation-13b68563313a
3- // http://www.iscriptdesign.com/?sketch=tutorial/splitbezier
4- // http://www.wikiwand.com/en/Hungarian_algorithm
5-
61import blobs from ".." ;
72
83let ctx : CanvasRenderingContext2D ;
@@ -241,6 +236,21 @@ const divideShape = (count: number, points: Point[]): Point[] => {
241236 return out ;
242237} ;
243238
239+ const fixAngles = ( a : Point [ ] , b : Point [ ] ) : Point [ ] => {
240+ const out : Point [ ] = [ ] ;
241+ for ( let i = 0 ; i < a . length ; i ++ ) {
242+ const point = copyPoint ( b [ i ] ) ;
243+ if ( point . handleIn . length === 0 ) {
244+ point . handleIn . angle = a [ i ] . handleIn . angle ;
245+ }
246+ if ( point . handleOut . length === 0 ) {
247+ point . handleOut . angle = a [ i ] . handleOut . angle ;
248+ }
249+ out . push ( point ) ;
250+ }
251+ return out ;
252+ } ;
253+
244254const divideLengths = ( lengths : number [ ] , add : number ) : number [ ] => {
245255 const divisors = lengths . map ( ( ) => 1 ) ;
246256 const sizes = lengths . slice ( ) ;
@@ -346,7 +356,6 @@ const renderShape = (points: Point[]) => {
346356} ;
347357
348358const interpolateBetween = ( percentage : number , a : Point [ ] , b : Point [ ] ) : Point [ ] => {
349- // TODO when handle length === 0, ignore/modify angle to look nice
350359 if ( a . length !== b . length ) throw new Error ( "shapes have different number of points" ) ;
351360 const points : Point [ ] = [ ] ;
352361 for ( let i = 0 ; i < a . length ; i ++ ) {
@@ -451,8 +460,9 @@ const testBlobMorph = (percentage: number) => {
451460 const aNorm = divideShape ( points , a ) ;
452461 const bNorm = divideShape ( points , b ) ;
453462 const bOpt = optimizeOrder ( aNorm , bNorm ) ;
463+ const bFix = fixAngles ( aNorm , bOpt ) ;
454464
455- renderShape ( interpolateBetweenLoop ( percentage , aNorm , bOpt ) ) ;
465+ renderShape ( interpolateBetweenLoop ( percentage , aNorm , bFix ) ) ;
456466} ;
457467
458468const testShapeMorph = ( percentage : number ) => {
@@ -468,8 +478,9 @@ const testShapeMorph = (percentage: number) => {
468478 const aNorm = divideShape ( points , a ) ;
469479 const bNorm = divideShape ( points , b ) ;
470480 const bOpt = optimizeOrder ( aNorm , bNorm ) ;
481+ const bFix = fixAngles ( aNorm , bOpt ) ;
471482
472- renderShape ( interpolateBetweenLoop ( percentage , aNorm , bOpt ) ) ;
483+ renderShape ( interpolateBetweenLoop ( percentage , aNorm , bFix ) ) ;
473484} ;
474485
475486const genBlob = (
0 commit comments