Skip to content

Commit

Permalink
fix(geom): update madd/maddN call sites (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jul 6, 2019
1 parent d2e9969 commit a96e028
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 25 deletions.
2 changes: 1 addition & 1 deletion packages/geom/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ export class Ray implements IHiccupShape {
"line",
this.attribs,
this.pos,
maddN2([], this.pos, this.dir, 1e6)
maddN2([], this.dir, 1e6, this.pos)
];
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/geom/src/ctors/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const roundedRect = (
attribs?: Attribs
) => {
r = isNumber(r) ? [r, r] : r;
const [w, h] = maddN2([], size, r, -2);
const [w, h] = maddN2([], r, -2, size);
return new PathBuilder(attribs)
.moveTo([pos[0] + r[0], pos[1]])
.hlineTo(w, true)
Expand Down
22 changes: 4 additions & 18 deletions packages/geom/src/ctors/triangle.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import { Attribs } from "@thi.ng/geom-api";
import { THIRD_PI } from "@thi.ng/math";
import {
maddN2,
mag,
normalize,
perpendicularLeft2,
sub2,
Vec
} from "@thi.ng/vectors";
import { equilateralTriangle2 } from "@thi.ng/geom-poly-utils";
import { Vec } from "@thi.ng/vectors";
import { Triangle } from "../api";
import { argAttribs } from "../internal/args";

Expand All @@ -18,12 +11,5 @@ export function triangle(...args: any[]) {
return new Triangle(args.length === 1 ? args[0] : args, attr);
}

export const equilateralTriangle = (a: Vec, b: Vec, attribs?: Attribs) => {
const dir = sub2([], b, a);
const c = normalize(
null,
perpendicularLeft2([], dir),
mag(dir) * Math.sin(THIRD_PI)
);
return new Triangle([a, b, maddN2(null, c, dir, 0.5)], attribs);
};
export const equilateralTriangle = (a: Vec, b: Vec, attribs?: Attribs) =>
new Triangle(equilateralTriangle2(a, b), attribs);
2 changes: 1 addition & 1 deletion packages/geom/src/ops/centroid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ centroid.addAll(<IObjectOf<Implementation1O<unknown, Vec, Vec>>>{

[Type.POLYGON]: ($: Polygon, out?) => centerOfWeight2($.points, out),

[Type.RECT]: ($: AABBLike, out?) => maddN(out || [], $.pos, $.size, 0.5),
[Type.RECT]: ($: AABBLike, out?) => maddN(out || [], $.size, 0.5, $.pos),

[Type.TRIANGLE]: ({ points }: Triangle, out?) =>
divN(
Expand Down
4 changes: 2 additions & 2 deletions packages/geom/src/ops/point-at.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pointAt.addAll(<IObjectOf<Implementation2<unknown, number, Vec>>>{
[Type.CUBIC]: ({ points }: Cubic, t) =>
mixCubic([], points[0], points[1], points[2], points[3], t),

[Type.ELLIPSE]: ($: Ellipse, t) => madd2([], $.pos, cossin(TAU * t), $.r),
[Type.ELLIPSE]: ($: Ellipse, t) => madd2([], cossin(TAU * t), $.r, $.pos),

[Type.LINE]: ({ points }: Line, t) => mixN2([], points[0], points[1], t),

Expand All @@ -47,7 +47,7 @@ pointAt.addAll(<IObjectOf<Implementation2<unknown, number, Vec>>>{
[Type.QUADRATIC]: ({ points }: Quadratic, t) =>
mixQuadratic([], points[0], points[1], points[2], t),

[Type.RAY]: ($: Ray, t) => maddN([], $.pos, $.dir, t),
[Type.RAY]: ($: Ray, t) => maddN([], $.dir, t, $.pos),

[Type.RECT]: ($: Rect, t) => new Sampler(vertices($), true).pointAt(t)
});
Expand Down
2 changes: 1 addition & 1 deletion packages/geom/src/ops/unmap-point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ unmapPoint.addAll(<IObjectOf<Implementation2O<unknown, ReadonlyVec, Vec, Vec>>>{
),

[Type.RECT]: ($: Rect, uvw: ReadonlyVec, out = []) =>
madd(out, $.pos, $.size, uvw)
madd(out, $.size, uvw, $.pos)
});

unmapPoint.isa(Type.AABB, Type.RECT);
Expand Down
2 changes: 1 addition & 1 deletion packages/geom/src/ops/vertices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ vertices.addAll(<
const delta = TAU / num;
last && num++;
for (let i = 0; i < num; i++) {
buf[i] = madd2([], pos, cossin(i * delta), r);
buf[i] = madd2([], cossin(i * delta), r, pos);
}
return buf;
},
Expand Down

0 comments on commit a96e028

Please sign in to comment.