import { sub , v2 , Vector2 , scale , normalize , add } from "./v2" ; import { segmentIntersection } from "./segment-intersection" ; import { Integratable } from "./common-types" ; const tunnelPoint = v2 ( ) ; const offset = v2 ( ) ; const v = v2 ( ) ; const direction = v2 ( ) ; const radiusSegment = v2 ( ) ; const cposIncludingRadius = v2 ( ) ; export function rewindToCollisionPoint ( point3 , radius3 , point1 , point2 ) { sub ( v , point3 . cpos , point3 . ppos ) ; normalize ( direction , v ) ; scale ( radiusSegment , direction , radius3 ) ; add ( cposIncludingRadius , radiusSegment , point3 . cpos ) ; const hasTunneled = segmentIntersection ( cposIncludingRadius , point3 . ppos , point1 , point2 , tunnelPoint ) ; if ( ! hasTunneled ) return false ; sub ( offset , cposIncludingRadius , tunnelPoint ) ; sub ( point3 . cpos , point3 . cpos , offset ) ; sub ( point3 . ppos , point3 . ppos , offset ) ; return true ; } function debuggerIfNaN ( point ) { if ( isNaN ( point . x ) || isNaN ( point . y ) ) { debugger ; } }