Skip to content

Commit

Permalink
Update Rect
Browse files Browse the repository at this point in the history
  • Loading branch information
krypciak committed Aug 18, 2024
1 parent 34f48c7 commit 4840417
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/util/geometry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@ export namespace Rect {
{ x: rect.width, y: rect.height },
]
}
export function mul(rect: Rect, mul: number): Rect {
rect.x *= mul
rect.y *= mul
rect.width *= mul
rect.height *= mul
return rect
}
export function div(rect: Rect, div: number): Rect {
rect.x *= div
rect.y *= div
rect.width *= div
rect.height *= div
return rect
}
export function x2(rect: Rect): number {
return rect.x + rect.width
}
Expand Down Expand Up @@ -148,12 +162,11 @@ export namespace Rect {
}
/** Extends the `rect` by `num` on all sides */
export function extend(rect: Rect, num: number): Rect {
return {
x: rect.x - num,
y: rect.y - num,
width: rect.width + num * 2,
height: rect.height + num * 2,
}
rect.x -= num
rect.y -= num
rect.width += num * 2
rect.height += num * 2
return rect
}
export function corner(
rect: Rect,
Expand Down

0 comments on commit 4840417

Please sign in to comment.