-
-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathtest_edge.js
More file actions
147 lines (131 loc) · 5.66 KB
/
test_edge.js
File metadata and controls
147 lines (131 loc) · 5.66 KB
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
143
144
145
146
147
const should = require("should");
const occ = require("../lib/occ");
describe("testing Edges ",function(){
describe("EDGE0 - constructing an empty Edge",function(){
let edge;
before(function(){
edge = new occ.Edge()
should.exist(edge);
});
it("should be valid", function(){
edge.isNull.should.equal(true);
});
it("should have a zero length", function(){
edge.length.should.equal(0);
});
it("should have a zero vertices", function(){
edge.numVertices.should.equal(0);
});
it("should be degenerated", function(){
edge.isDegenerated.should.equal(true);
});
it("shouldn't be closed", function(){
edge.isClosed.should.equal(false);
});
it("should provide a bounding box", function () {
edge.getBoundingBox().should.be.instanceOf(occ.BoundingBox);
edge.getBoundingBox().isVoid.should.eql(true);
});
});
describe("EDGE1 - an Edge constructed as as a linear Segment between (10,20,30) and (-30,20,30) ",function(){
let edge;
before(function(){
let v1 = new occ.Vertex(10,20,30);
let v2 = new occ.Vertex(-30,20,30);
edge = occ.makeLine(v1, v2);
edge.should.be.instanceOf(occ.Edge);
});
it("should have a length of 40.0 ", function() {
edge.length.should.equal(40.0);
});
it("should have two vertices ", function() {
edge.numVertices.should.equal(2.0);
});
it("shouldn't be closed", function() {
edge.isClosed.should.equal(false);
});
it("shouldn't be degenerated", function() {
edge.isDegenerated.should.equal(false);
});
it("should provide a bounding box", function () {
edge.getBoundingBox().should.be.instanceOf(occ.BoundingBox);
edge.getBoundingBox().isVoid.should.eql(false);
edge.getBoundingBox().nearPt.equals(new occ.Point3D(-30, 20, 30)).should.eql(true);
edge.getBoundingBox().nearPt.equals([-30, 20, 30]).should.eql(true);
edge.getBoundingBox().farPt.equals([10, 20, 30]).should.eql(true);
let extra = 0.000000000001;
edge.getBoundingBox().farPt.asArray().should.eql([10 + extra, 20 + extra, 30 + extra]);
});
it("should polygonize a segment with two points", function () {
console.log("polyligonize");
let polyline = edge.polygonize();
console.log("polyligonize2");
polyline.length.should.eql(3 * 2);
[polyline[0], polyline[1], polyline[2]].should.eql([10, 20, 30]);
let l = polyline.length;
(l % 3).should.eql(0);
[polyline[l - 3], polyline[l - 2], polyline[l - 1]].should.eql([-30, 20, 30]);
});
});
describe("EDGE2 - an Edge constructed as as a linear Segment between (10,20,30) and (-30,20,30) and translated by [1,2,3]", function () {
let edge;
before(function () {
let v1 = new occ.Vertex(10, 20, 30);
let v2 = new occ.Vertex(-30, 20, 30);
edge = occ.makeLine(v1, v2);
edge = edge.translate([1, 2, 3]);
});
it("should have a length of 40.0 ", function () {
edge.length.should.equal(40.0);
});
it("should provide a bounding box", function () {
edge.getBoundingBox().nearPt.equals([-29, 22, 33]).should.eql(true);
edge.getBoundingBox().farPt.equals([11, 22, 33]).should.eql(true);
});
it("should polygonize a segment with two points", function () {
let polyline = edge.polygonize();
polyline.length.should.eql(3 * 2);
[polyline[0], polyline[1], polyline[2]].should.eql([11, 22, 33]);
let l = polyline.length;
(l % 3).should.eql(0);
[polyline[l - 3], polyline[l - 2], polyline[l - 1]].should.eql([-29, 22, 33]);
});
});
describe("EDGE3 - an Edge constructed as a Circle on the Z+ plan with a radius of 20", function () {
let edge;
before(function(){
edge = occ.makeCircle([10, 10, 10], [0, 0, 1], 20);
});
it("should have a length of 2*PI*20.0 ", function(){
let epsilon = 1E-2;
let PI = 3.1415;
edge.length.should.be.within(2*PI*20.0-epsilon,2*PI*20.0+epsilon);
});
it("should have a unique vertex ", function(){
edge.numVertices.should.equal(1);
});
it("should be closed", function(){
edge.isClosed.should.equal(true);
});
it("shouldn't be degenerated", function(){
edge.isDegenerated.should.equal(false);
});
it("should provide a bounding box", function () {
edge.getBoundingBox().should.be.instanceOf(occ.BoundingBox);
edge.getBoundingBox().isVoid.should.eql(false);
//xx console.log(JSON.stringify(edge.getBoundingBox()));//.toString());
edge.getBoundingBox().nearPt.equals([-11.647844, -11.647844, 10]);
edge.getBoundingBox().farPt.equals([31.647844, 31.647844, 10]);
});
it("should polygonize a edge", function () {
let a = edge.polygonize();
[a[0], a[1], a[2]].should.eql([30, 10, 10]);
let l = a.length;
(l % 3).should.eql(0);
[a[l - 3], a[l - 2], a[l - 1]].should.eql([30, 10, 10]);
//xx console.log(a);
});
});
describe("EDGE4 - an Edge constructed as as a linear Segment between (10,20,30) and (-30,20,30) ", function () {
});
});