-
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.
- Loading branch information
1 parent
d08434d
commit 9749fd6
Showing
1 changed file
with
24 additions
and
1 deletion.
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,32 +1,55 @@ | ||
class Vertex { | ||
public x : number; | ||
public y : number; | ||
|
||
public constructor (x:number, y:number) { | ||
this.x = x; | ||
this.y = y; | ||
} | ||
|
||
public equals(point:Vertex):boolean { | ||
return this.x == point.x && this.y == point.y; | ||
} | ||
|
||
public clone():Vertex { | ||
return new Vertex(this.x, this.y); | ||
} | ||
|
||
public static Add(a:Vertex, b:Vertex) { | ||
return new Vertex(a.x + b.x, a.y + b.y); | ||
} | ||
|
||
public static Subtract(a:Vertex, b:Vertex) { | ||
return new Vertex(a.x - b.x, a.y - b.y); | ||
} | ||
|
||
public setCoords(x:number, y:number):void { | ||
this.x = x; | ||
this.y = y; | ||
} | ||
|
||
public setTo(v:Vertex):void { | ||
this.x = v.x; | ||
this.y = v.y; | ||
} | ||
public translate(offset:Vertex) { | ||
|
||
public translate(offset:Vertex):void { | ||
this.x += offset.x; | ||
this.y += offset.y; | ||
} | ||
|
||
public normalise():void { | ||
let mod = 1.0 / Util.distance(Vertex.Zero, this); | ||
this.x *= mod; | ||
this.y *= mod; | ||
} | ||
|
||
public normalised():Vertex { | ||
let output:Vertex = this.clone(); | ||
output.normalise(); | ||
return output; | ||
} | ||
|
||
|
||
public static Zero:Vertex = new Vertex(0, 0); | ||
} |