import { rotatePoints } from './rotatePoints' ; import { _ } from '../constants' ; import { distance } from '../utilities/distance' ; import { FloatArray } from '../types' ; import { computeAbsoluteOrigin } from './computeAbsoluteOrigin' ; export function normalizePoints ( absolute , originX , originY , ns ) { let len = ns . length ; if ( ns [ len - 2 ] !== ns [ 0 ] || ns [ len - 1 ] !== ns [ 1 ] ) { return ; } if ( ! absolute ) { const relativeOrigin = computeAbsoluteOrigin ( originX , originY , ns ) ; originX = relativeOrigin . x ; originY = relativeOrigin . y ; } const buffer = ns . slice ( 2 ) ; len = buffer . length ; let index , minAmount ; for ( let i = 0 ; i < len ; i += 6 ) { const next = distance ( originX , originX , buffer [ i ] , buffer [ i + 1 ] ) ; if ( minAmount === _ || next < minAmount ) { minAmount = next ; index = i ; } } rotatePoints ( buffer , index ) ; ns [ 0 ] = buffer [ len - 2 ] ; ns [ 1 ] = buffer [ len - 1 ] ; for ( let i = 0 ; i < buffer . length ; i ++ ) { ns [ i + 2 ] = buffer [ i ] ; } }