import { InterpolateOptions , FloatArray , Matrix } from '../types' ; import { fillSegments } from './fillSegments' ; import { normalizePoints } from './normalizePoints' ; import { fillPoints } from './fillPoints' ; import { FILL } from '../constants' ; import { raiseError } from '../utilities/errors' ; import { getSortedSegments } from './getSortedSegments' ; export function normalizePaths ( left , right , options ) { if ( options . optimize === FILL ) { left = getSortedSegments ( left ) ; right = getSortedSegments ( right ) ; } if ( left . length !== right . length ) { if ( options . optimize === FILL ) { fillSegments ( left , right , options . origin ) ; } else { raiseError ( 'optimize:none requires equal lengths' ) ; } } const matrix = Array ( 2 ) as Matrix ; matrix [ 0 ] = left ; matrix [ 1 ] = right ; if ( options . optimize === FILL ) { const { x , y , absolute } = options . origin ; for ( let i = 0 ; i < left . length ; i ++ ) { normalizePoints ( absolute , x , y , matrix [ 0 ] [ i ] ) ; normalizePoints ( absolute , x , y , matrix [ 1 ] [ i ] ) ; } fillPoints ( matrix , options . addPoints * 6 ) ; } return matrix ; }