Skip to content

Commit

Permalink
fix(geom): update AABB/Rect.offset(), clamp size to zero
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jun 28, 2022
1 parent 3e1b340 commit 620121d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions packages/geom/src/api/aabb.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { AABBLike, Attribs } from "@thi.ng/geom-api";
import type { Vec } from "@thi.ng/vectors";
import { add3 } from "@thi.ng/vectors/add";
import { addN3 } from "@thi.ng/vectors/addn";
import { Vec, ZERO3 } from "@thi.ng/vectors/api";
import { max3 } from "@thi.ng/vectors/max";
import { set3 } from "@thi.ng/vectors/set";
import { subN3 } from "@thi.ng/vectors/subn";
import { __asVec } from "../internal/args.js";
Expand Down Expand Up @@ -40,7 +41,7 @@ export class AABB implements AABBLike {

offset(offset: number) {
subN3(null, this.pos, offset);
addN3(null, this.size, offset * 2);
max3(null, addN3(null, this.size, offset * 2), ZERO3);
return this;
}
}
5 changes: 3 additions & 2 deletions packages/geom/src/api/rect.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { AABBLike, Attribs, IHiccupShape } from "@thi.ng/geom-api";
import type { Vec } from "@thi.ng/vectors";
import { add2 } from "@thi.ng/vectors/add";
import { addN2 } from "@thi.ng/vectors/addn";
import { Vec, ZERO2 } from "@thi.ng/vectors/api";
import { max2 } from "@thi.ng/vectors/max";
import { set2 } from "@thi.ng/vectors/set";
import { subN2 } from "@thi.ng/vectors/subn";
import { __asVec } from "../internal/args.js";
Expand Down Expand Up @@ -40,7 +41,7 @@ export class Rect implements AABBLike, IHiccupShape {

offset(offset: number) {
subN2(null, this.pos, offset);
addN2(null, this.size, offset * 2);
max2(null, addN2(null, this.size, offset * 2), ZERO2);
return this;
}

Expand Down

0 comments on commit 620121d

Please sign in to comment.