@ -1,4 +1,5 @@
import {
clamp ,
pointDistance ,
pointFrom ,
pointScaleFromOrigin ,
@ -863,6 +864,8 @@ const handleEndpointDrag = (
) ;
} ;
const MAX_POS = 1 e6 ;
/ * *
*
* /
@ -883,6 +886,48 @@ export const updateElbowArrowPoints = (
return { points : updates.points ? ? arrow . points } ;
}
// NOTE (mtolmacs): This is a temporary check to ensure that the incoming elbow
// arrow size is valid. This check will be removed once the issue is identified
if (
arrow . x < - MAX_POS ||
arrow . x > MAX_POS ||
arrow . y < - MAX_POS ||
arrow . y > MAX_POS ||
arrow . x + ( updates ? . points ? . [ updates ? . points ? . length - 1 ] ? . [ 0 ] ? ? 0 ) <
- MAX_POS ||
arrow . x + ( updates ? . points ? . [ updates ? . points ? . length - 1 ] ? . [ 0 ] ? ? 0 ) >
MAX_POS ||
arrow . y + ( updates ? . points ? . [ updates ? . points ? . length - 1 ] ? . [ 1 ] ? ? 0 ) <
- MAX_POS ||
arrow . y + ( updates ? . points ? . [ updates ? . points ? . length - 1 ] ? . [ 1 ] ? ? 0 ) >
MAX_POS ||
arrow . x + ( arrow ? . points ? . [ arrow ? . points ? . length - 1 ] ? . [ 0 ] ? ? 0 ) <
- MAX_POS ||
arrow . x + ( arrow ? . points ? . [ arrow ? . points ? . length - 1 ] ? . [ 0 ] ? ? 0 ) >
MAX_POS ||
arrow . y + ( arrow ? . points ? . [ arrow ? . points ? . length - 1 ] ? . [ 1 ] ? ? 0 ) <
- MAX_POS ||
arrow . y + ( arrow ? . points ? . [ arrow ? . points ? . length - 1 ] ? . [ 1 ] ? ? 0 ) > MAX_POS
) {
console . error (
` Elbow arrow (or update) is outside reasonable bounds (> 1e6) arrow: ${ JSON . stringify (
arrow ,
) } updates : $ { JSON . stringify ( updates ) } ` ,
) ;
}
// @ts-ignore See above note
arrow . x = clamp ( arrow . x , - MAX_POS , MAX_POS ) ;
// @ts-ignore See above note
arrow . y = clamp ( arrow . y , - MAX_POS , MAX_POS ) ;
if ( updates . points ) {
updates . points = updates . points . map ( ( [ x , y ] ) = >
pointFrom < LocalPoint > (
clamp ( x , - MAX_POS , MAX_POS ) ,
clamp ( y , - MAX_POS , MAX_POS ) ,
) ,
) ;
}
if ( ! import . meta . env . PROD ) {
invariant (
! updates . points || updates . points . length >= 2 ,
@ -1981,17 +2026,45 @@ const normalizeArrowElementUpdate = (
const offsetX = global [ 0 ] [ 0 ] ;
const offsetY = global [ 0 ] [ 1 ] ;
cons t points = global . map ( ( p ) = >
le t points = global . map ( ( p ) = >
pointTranslate < GlobalPoint , LocalPoint > (
p ,
vectorScale ( vectorFromPoint ( global [ 0 ] ) , - 1 ) ,
) ,
) ;
return {
points ,
// NOTE (mtolmacs): This is a temporary check to see if the normalization
// creates an overly large arrow. This should be removed once we have an answer.
if (
offsetX < - MAX_POS ||
offsetX > MAX_POS ||
offsetY < - MAX_POS ||
offsetY > MAX_POS ||
offsetX + points [ points . length - 1 ] [ 0 ] < - MAX_POS ||
offsetY + points [ points . length - 1 ] [ 0 ] > MAX_POS ||
offsetX + points [ points . length - 1 ] [ 1 ] < - MAX_POS ||
offsetY + points [ points . length - 1 ] [ 1 ] > MAX_POS
) {
console . error (
` Elbow arrow normalization is outside reasonable bounds (> 1e6) arrow: ${ JSON . stringify (
{
x : offsetX ,
y : offsetY ,
points ,
. . . getSizeFromPoints ( points ) ,
} ,
) } ` ,
) ;
}
points = points . map ( ( [ x , y ] ) = >
pointFrom < LocalPoint > ( clamp ( x , - 1 e6 , 1 e6 ) , clamp ( y , - 1 e6 , 1 e6 ) ) ,
) ;
return {
points ,
x : clamp ( offsetX , - 1 e6 , 1 e6 ) ,
y : clamp ( offsetY , - 1 e6 , 1 e6 ) ,
fixedSegments :
( nextFixedSegments ? . length ? ? 0 ) > 0 ? nextFixedSegments : null ,
. . . getSizeFromPoints ( points ) ,