forked from mvasilkov/roads2017
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvec2.js
34 lines (34 loc) · 888 Bytes
/
vec2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"use strict";
/// <reference path="roads.d.ts" />
var Vec2 = /** @class */ (function () {
function Vec2(x, y) {
if (x === void 0) { x = 0; }
if (y === void 0) { y = 0; }
this.x = x;
this.y = y;
}
Vec2.prototype.set = function (x, y) {
this.x = x;
this.y = y;
};
Vec2.prototype.setTo = function (other) {
this.x = other.x;
this.y = other.y;
};
Vec2.prototype.setNormal = function (a, b) {
// perpendicular
var x = a.y - b.y;
var y = b.x - a.x;
// normalize
var length = Math.sqrt(x * x + y * y);
if (length < Number.MIN_VALUE) {
this.x = x;
this.y = y;
return;
}
var inverseLength = 1 / length;
this.x = x * inverseLength;
this.y = y * inverseLength;
};
return Vec2;
}());