-
Notifications
You must be signed in to change notification settings - Fork 0
/
point3.js
142 lines (117 loc) · 3.1 KB
/
point3.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
"use strict";
var Point = require("./point");
module.exports = Point3;
function Point3(x, y, z) {
this.x = x;
this.y = y;
this.z = z;
}
Point3.prototype = Object.create(Point.prototype);
Point3.prototype.constructor = Point3;
Point3.zero = new Point3();
Point3.one = new Point3(1, 1, 1);
Point3.prototype.addThis = function (that) {
this.x = this.x + that.x;
this.y = this.y + that.y;
this.z = this.z + that.z;
return this;
};
Point3.prototype.subThis = function (that) {
this.x = this.x - that.x;
this.y = this.y - that.y;
this.z = this.z - that.z;
return this;
};
Point3.prototype.mulThis = function (that) {
this.x = this.x * that.x;
this.y = this.y * that.y;
this.z = this.z * that.z;
return this;
};
Point3.prototype.scaleThis = function (n) {
this.x = this.x * n;
this.y = this.y * n;
this.z = this.z * n;
return this;
};
Point3.prototype.bitwiseAndThis = function (n) {
this.x = this.x & n;
this.y = this.y & n;
this.z = this.z & n;
return this;
};
Point3.prototype.bitwiseOrThis = function (n) {
this.x = this.x | n;
this.y = this.y | n;
this.z = this.z | n;
return this;
};
Point3.prototype.roundThis = function () {
this.x = Math.round(this.x);
this.y = Math.round(this.y);
this.z = Math.round(this.z);
};
Point3.prototype.floorThis = function () {
this.x = Math.floor(this.x);
this.y = Math.floor(this.y);
this.z = Math.floor(this.z);
};
Point3.prototype.ceilThis = function () {
this.x = Math.ceil(this.x);
this.y = Math.ceil(this.y);
this.z = Math.ceil(this.z);
};
Point3.prototype.absThis = function () {
this.x = Math.abs(this.x);
this.y = Math.abs(this.y);
this.z = Math.abs(this.z);
};
Point3.prototype.minThis = function (that) {
this.x = Math.min(this.x, that.x);
this.y = Math.min(this.y, that.y);
this.z = Math.min(this.z, that.z);
};
Point3.prototype.maxThis = function (that) {
this.x = Math.max(this.x, that.x);
this.y = Math.max(this.y, that.y);
this.z = Math.max(this.z, that.z);
};
Point3.prototype.clone = function () {
return new Point3(this.x, this.y, this.z);
};
Point3.prototype.copyFrom = function (that) {
this.x = that.x;
this.y = that.y;
this.z = that.z;
return this;
};
// TODO deprecated for copyFrom
Point3.prototype.become = function (that) {
this.x = that.x;
this.y = that.y;
this.z = that.z;
return this;
};
Point3.prototype.copyFromXY = function (that) {
this.x = that.x;
this.y = that.y;
return this;
};
// TODO deprecated for copyFromXY
Point3.prototype.becomeXY = function (that) {
this.x = that.x;
this.y = that.y;
return this;
};
Point3.prototype.toString = function () {
return "[x=" + this.x + " y=" + this.y + " z=" + this.z + "]";
};
Point3.prototype.hash = function () {
return this.x + "," + this.y + "," + this.z;
};
Point3.prototype.equals = function (that) {
return this.x === that.x && this.y === that.y && this.z === that.z;
};
Point3.prototype.lessThan = function (that) {
return this.x < that.x && this.y < that.y && this.z < that.z;
};