Skip to content

Commit

Permalink
fix(geom-isec): update madd & perpendicular call sites (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jul 6, 2019
1 parent 3250c82 commit d2e9969
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions packages/geom-isec/src/circle-circle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
maddN,
mag,
mulN,
perpendicularLeft2,
perpendicularCCW,
ReadonlyVec,
sub
} from "@thi.ng/vectors";
Expand All @@ -27,8 +27,8 @@ export const intersectCircleCircle = (
ar *= ar;
const alpha = (ar - br * br + d * d) / (2 * d);
const h = Math.sqrt(ar - alpha * alpha);
const p = maddN([], a, delta, alpha / d);
const t = mulN(null, perpendicularLeft2(null, delta), h / d);
const p = maddN([], delta, alpha / d, a);
const t = mulN(null, perpendicularCCW(null, delta), h / d);
return {
type: IntersectionType.INTERSECT,
isec: [add([], p, t), sub([], p, t)]
Expand Down
8 changes: 4 additions & 4 deletions packages/geom-isec/src/ray-circle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ export const intersectRayCircle = (
a >= 0
? b >= 0
? a > b
? [maddN(delta, rpos, dir, b), maddN([], rpos, dir, a)]
: [maddN(delta, rpos, dir, a), maddN([], rpos, dir, b)]
: [maddN(delta, rpos, dir, a)]
? [maddN(delta, dir, b, rpos), maddN([], dir, a, rpos)]
: [maddN(delta, dir, a, rpos), maddN([], dir, b, rpos)]
: [maddN(delta, dir, a, rpos)]
: b >= 0
? [maddN(delta, rpos, dir, b)]
? [maddN(delta, dir, b, rpos)]
: undefined;
return isec ? { type: IntersectionType.INTERSECT, isec } : NONE;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/geom-isec/src/ray-line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const intersectRayLine = (
return t >= 0 && s >= 0 && s <= 1
? {
type: IntersectionType.INTERSECT,
isec: maddN([], rpos, dir, t),
isec: maddN([], dir, t, rpos),
alpha: t
}
: NONE;
Expand Down
2 changes: 1 addition & 1 deletion packages/geom-isec/src/ray-plane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const intersectRayPlane = (
const alpha = dot(normal, isec) / d;
return {
type: IntersectionType.INTERSECT,
isec: maddN(isec, rpos, dir, alpha),
isec: maddN(isec, dir, alpha, rpos),
alpha
};
}
Expand Down
4 changes: 2 additions & 2 deletions packages/geom-isec/src/ray-poly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const intersectRayPolyline = (
return cross > 0
? {
type: IntersectionType.INTERSECT,
isec: maddN2([], rpos, dir, minD),
isec: maddN2([], dir, minD, rpos),
inside: !(cross & 1),
alpha: minD
}
Expand All @@ -56,7 +56,7 @@ export const intersectRayPolylineAll = (
for (let k = 0; k <= n; i = j, j = pts[++k]) {
const d = intersectRayLine(rpos, dir, i, j).alpha;
if (d !== undefined) {
res.push([d, maddN2([], rpos, dir, d)]);
res.push([d, maddN2([], dir, d, rpos)]);
}
}
return res.length
Expand Down
6 changes: 3 additions & 3 deletions packages/geom-isec/src/ray-rect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ const intersectWith = (
? {
type: IntersectionType.INTERSECT,
inside,
isec: [maddN([], rpos, dir, tmax)],
isec: [maddN([], dir, tmax, rpos)],
alpha: tmax
}
: {
type: IntersectionType.INTERSECT,
isec: [
maddN([], rpos, dir, tmin),
maddN([], rpos, dir, tmax)
maddN([], dir, tmin, rpos),
maddN([], dir, tmax, rpos)
],
alpha: tmin,
beta: tmax
Expand Down

0 comments on commit d2e9969

Please sign in to comment.