-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(math): add negate operation to Vec2
- Loading branch information
1 parent
893de02
commit 4134e81
Showing
2 changed files
with
47 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,17 @@ | ||
export class Vec2 { | ||
constructor( | ||
public readonly x: number = 0, | ||
public readonly y: number = 0 | ||
public constructor( | ||
public x: number = 0, | ||
public y: number = 0 | ||
) { | ||
} | ||
|
||
public negate(): void { | ||
this.x = -this.x; | ||
this.y = -this.y; | ||
} | ||
|
||
public getNegated(): Vec2 { | ||
// avoid reusing negate for better performance | ||
return new Vec2(-this.x, -this.y); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters