Returns the distance from point a to the exterior of shape.
a
shape
const distance = distanceToExterior( {x: 50, y: 50}, {x: 100, y: 100, width: 20, height: 20}); Copy
const distance = distanceToExterior( {x: 50, y: 50}, {x: 100, y: 100, width: 20, height: 20});
import {minIndex} from '../data/arrays.js';const shapes = [ some shapes... ]; // Shapes to compare againstconst pt = { x: 10, y: 10 }; // Comparison pointconst distances = shapes.map(v => distanceToExterior(pt, v));const closest = shapes[minIndex(...distances)]; Copy
import {minIndex} from '../data/arrays.js';const shapes = [ some shapes... ]; // Shapes to compare againstconst pt = { x: 10, y: 10 }; // Comparison pointconst distances = shapes.map(v => distanceToExterior(pt, v));const closest = shapes[minIndex(...distances)];
Point
Point, or a positioned Rect or Circle.
Returns the distance from point
a
to the exterior ofshape
.Example: Distance from point to rectangle
Example: Find closest shape to point