public static Point2D findIntersection ( final int x , final int y , final MultiPath path ) { final Point2D pointerPosition = new Point2D ( x , y ) ; final BoundingBox box = path . getBoundingBox ( ) ; final Point2D center = findCenter ( box ) ; // length just needs to ensure the c to xy is outside of the path final double length = box . getWidth ( ) + box . getHeight ( ) ; final Point2D projectionPoint = getProjection ( center , pointerPosition , length ) ; final Point2DArray points = new Point2DArray ( ) ; points . push ( center ) ; points . push ( projectionPoint ) ; final Set < Point2D > [ ] intersects = Geometry . getCardinalIntersects ( path , points ) ; Point2D nearest = null ; for ( final Set < Point2D > set : intersects ) { double nearesstDistance = length ; if ( ( set != null ) && ! set . isEmpty ( ) ) { for ( final Point2D p : set ) { final double currentDistance = p . distance ( pointerPosition ) ; if ( currentDistance < nearesstDistance ) { nearesstDistance = currentDistance ; nearest = p ; } } } } return nearest ; }
Finds intersecting point from the center of a path