export { point_in_lasso } from './lasso_test' ; export function point_in_rectangle ( point , x , y ) { if ( x . length == 0 && y . length == 0 ) { return false ; } let is_inside = true ; if ( x . length != 0 ) { is_inside = is_inside && x [ 0 ] <= point [ 0 ] && point [ 0 ] <= x [ 1 ] ; } if ( y . length != 0 ) { is_inside = is_inside && y [ 0 ] <= point [ 1 ] && point [ 1 ] <= y [ 1 ] ; } return is_inside ; } export function rect_inter_rect ( x0 , y0 , x1 , y1 ) { return seg_inter_seg ( x0 , x1 ) && seg_inter_seg ( y0 , y1 ) ; } export function lasso_inter_rect ( x , y , vertices ) { for ( let i = 0 ; i < vertices . length ; i ++ ) { if ( point_in_rectangle ( vertices [ i ] , x , y ) ) { return true ; } } return false ; } function seg_inter_seg ( p , q ) { if ( p . length == 0 || q . length == 0 ) { return p . length != 0 || q . length != 0 ; } p . sort ( ( a , b ) => { return a - b ; } ) ; q . sort ( ( a , b ) => { return a - b ; } ) ; return ( p [ 0 ] < q [ 0 ] != p [ 0 ] < q [ 1 ] || p [ 1 ] < q [ 0 ] != p [ 1 ] < q [ 1 ] || q [ 0 ] < p [ 0 ] != q [ 0 ] < p [ 1 ] || q [ 1 ] < p [ 0 ] != q [ 1 ] < p [ 1 ] ) ; }