Skip to content

Commit

Permalink
Update Vec2
Browse files Browse the repository at this point in the history
  • Loading branch information
krypciak committed Aug 18, 2024
1 parent 7ea8bef commit acc3c26
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/util/vec2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,16 @@ export interface Vec2 {
}

export namespace Vec2 {
export function copy(v: Vec2): Vec2 {
return { x: v.x, y: v.y }
export function assign(v1: Vec2, v2: Vec2) {
v1.x = v2.x || 0
v1.y = v2.y || 0
return v1
}

export function assignC(v: Vec2, x?: number, y?: number) {
v.x = x || 0
v.y = y || 0
return v
}

export function add(v1: Vec2, v2: Vec2, copy?: boolean) {
Expand Down Expand Up @@ -191,4 +199,12 @@ export namespace Vec2 {
export function flipSides(v: Vec2, doFlip: boolean): Vec2 {
return doFlip ? { x: v.y, y: v.x } : Vec2.copy(v)
}
export function copy(v: Vec2): Vec2 {
return { x: v.x, y: v.y }
}
export function floor(v: Vec2): Vec2 {
v.x = v.x.floor()
v.y = v.y.floor()
return v
}
}

0 comments on commit acc3c26

Please sign in to comment.