UNPKG

agentscape

Version:

Agentscape is a library for creating agent-based simulations. It provides a simple API for defining agents and their behavior, and for defining the environment in which the agents interact. Agentscape is designed to be flexible and extensible, allowing

43 lines 1.58 kB
import concaveman from 'concaveman'; export class Intersections { static circleCircle(circle1, circle2) { const dx = circle1.x - circle2.x; const dy = circle1.y - circle2.y; const distance = Math.sqrt(dx * dx + dy * dy); return distance < (circle1.r + circle2.r); } } class Geometry { static concaveHull(points, concavity, lengthThreshold) { if (points.length < 3) return points; const hull = concaveman(points, concavity, lengthThreshold); return hull; } static convexHull(points) { if (points.length < 3) return points; // Sort points by x, then by y const sorted = points.slice().sort((a, b) => (a[0] === b[0] ? a[1] - b[1] : a[0] - b[0])); const crossProduct = (o, a, b) => (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]); const buildHull = (pts) => { const hull = []; for (const p of pts) { while (hull.length >= 2 && crossProduct(hull[hull.length - 2], hull[hull.length - 1], p) <= 0) { hull.pop(); } hull.push(p); } return hull; }; const lowerHull = buildHull(sorted); const upperHull = buildHull(sorted.reverse()); // Remove last point from each hull to avoid duplication lowerHull.pop(); upperHull.pop(); return lowerHull.concat(upperHull); } } Geometry.Intersections = Intersections; export default Geometry; //# sourceMappingURL=Geometry.js.map