-
Notifications
You must be signed in to change notification settings - Fork 0
/
face.js
75 lines (58 loc) · 1.74 KB
/
face.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
var Point = require('./point');
var _faceCount = 0;
var Face = function(point1, point2, point3, register){
this.id = _faceCount++;
if(register == undefined){
register = true;
}
this.points = [
point1,
point2,
point3
];
if(register){
point1.registerFace(this);
point2.registerFace(this);
point3.registerFace(this);
}
};
Face.prototype.getOtherPoints = function(point1){
var other = [];
for(var i = 0; i < this.points.length; i++){
if(this.points[i].toString() !== point1.toString()){
other.push(this.points[i]);
}
}
return other;
}
Face.prototype.findThirdPoint = function(point1, point2){
for(var i = 0; i < this.points.length; i++){
if(this.points[i].toString() !== point1.toString() && this.points[i].toString() !== point2.toString()){
return this.points[i];
}
}
}
Face.prototype.isAdjacentTo = function(face2){
// adjacent if 2 of the points are the same
var count = 0;
for(var i = 0; i< this.points.length; i++){
for(var j =0 ; j< face2.points.length; j++){
if(this.points[i].toString() == face2.points[j].toString()){
count++;
}
}
}
return (count == 2);
}
Face.prototype.getCentroid = function(clear){
if(this.centroid && !clear){
return this.centroid;
}
var x = (this.points[0].x + this.points[1].x + this.points[2].x)/3;
var y = (this.points[0].y + this.points[1].y + this.points[2].y)/3;
var z = (this.points[0].z + this.points[1].z + this.points[2].z)/3;
var centroid = new Point(x,y,z);
this.centroid = centroid;
return centroid;
}
module.exports = Face;