Skip to content

Commit

Permalink
feat(geom): add ray-rect/aabb impls for intersects()
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jan 30, 2019
1 parent 93e2ea6 commit 5f7dd63
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions packages/geom/src/ops/intersects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,22 @@ import {
import {
intersectCircleCircle,
intersectLineLine,
intersectRayAABB,
intersectRayCircle,
intersectRayPolyline,
intersectRayRect,
testRectCircle,
testRectRect
} from "@thi.ng/geom-isec";
import { dispatch2 } from "../internal/dispatch";
import {
AABB,
Circle,
Line,
Ray,
Rect,
Sphere,
Sphere
} from "../api";
import { dispatch2 } from "../internal/dispatch";

export const intersects: MultiFn2O<IShape, IShape, any, IntersectionResult> = defmulti(dispatch2);

Expand All @@ -35,6 +38,10 @@ intersects.addAll({
({ points: a }: Line, { points: b }: Line) =>
intersectLineLine(a[0], a[1], b[0], b[1]),

[`${Type.RAY}-${Type.AABB}`]:
(ray: Ray, box: AABB) =>
intersectRayAABB(ray.pos, ray.dir, box.pos, box.max()),

[`${Type.RAY}-${Type.CIRCLE}`]:
(ray: Ray, sphere: Sphere) =>
intersectRayCircle(ray.pos, ray.dir, sphere.pos, sphere.r),
Expand All @@ -47,6 +54,10 @@ intersects.addAll({
(ray: Ray, poly: PCLike) =>
intersectRayPolyline(ray.pos, ray.dir, poly.points, false),

[`${Type.RAY}-${Type.RECT}`]:
(ray: Ray, rect: Rect) =>
intersectRayRect(ray.pos, ray.dir, rect.pos, rect.max()),

[`${Type.RECT}-${Type.CIRCLE}`]:
({ pos: rp, size }: Rect, { pos: cp, r }: Circle) => ({
type: testRectCircle(rp, size, cp, r) ?
Expand Down

0 comments on commit 5f7dd63

Please sign in to comment.