Skip to content

Commit 2bd06dd

Browse files
committed
fix(tp): tmp
tmp
1 parent e74e715 commit 2bd06dd

File tree

3 files changed

+72
-56
lines changed

3 files changed

+72
-56
lines changed

Sources/Common/DataModel/Polygon/Constants.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@ export const PolygonWithPointIntersectionState = {
66
FAILURE: -1,
77
OUTSIDE: 0,
88
INSIDE: 1,
9-
INTERSECTION: 2,
10-
ON_LINE: 3,
119
};
1210
export const VTK_DBL_EPSILON = 2.2204460492503131e-16;
1311

14-
export const INTERSECTION = {
15-
NO_INTERSECTION,
16-
POINT_INTERSECTION,
17-
LINE_INTERSECTION,
18-
}
12+
export const PolygonWithPolygonIntersectionState = {
13+
NO_INTERSECTION: 0,
14+
POINT_INTERSECTION: 1,
15+
LINE_INTERSECTION: 2,
16+
};
1917

20-
export default { INTERSECTION, PolygonWithPointIntersectionState };
18+
export default { PolygonWithPointIntersectionState };

Sources/Common/DataModel/Polygon/index.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@ import * as vtkMath from 'vtk.js/Sources/Common/Core/Math';
33
import vtkLine from 'vtk.js/Sources/Common/DataModel/Line';
44
import vtkPlane from 'vtk.js/Sources/Common/DataModel/Plane';
55
import vtkPriorityQueue from 'vtk.js/Sources/Common/Core/PriorityQueue';
6+
import { IntersectionState } from 'vtk.js/Sources/Common/DataModel/Line/Constants';
67
import vtkBoundingBox from 'vtk.js/Sources/Common/DataModel/BoundingBox';
78
import vtkCell from 'vtk.js/Sources/Common/DataModel/Cell';
89
import vtkPoints from 'vtk.js/Sources/Common/Core/Points';
910
import {
10-
INTERSECTION,
11-
PolygonWithPointIntersectionState,
11+
EPSILON,
1212
FLOAT_EPSILON,
13+
TOLERANCE,
14+
PolygonWithPointIntersectionState,
1315
VTK_DBL_EPSILON,
14-
POLYGON_TOLERANCE,
15-
EPSILON,
16+
PolygonWithPolygonIntersectionState,
1617
} from 'vtk.js/Sources/Common/DataModel/Polygon/Constants';
1718

1819
// ----------------------------------------------------------------------------
@@ -76,14 +77,14 @@ function pointInPolygon(point, vertices, bounds, normal) {
7677
p0[1] = vertices[i++];
7778
p0[2] = vertices[i++];
7879
if (vtkMath.distance2BetweenPoints(point, p0) <= tol2) {
79-
return PolygonWithPointIntersectionState.INSIDE;
80+
return PolygonWithPointIntersectionState.ON_LINE;
8081
}
8182

8283
// Check coincidence to polygon edges
8384
// double* p1 = pts + 3 * ((i + 1) % numPts);
8485
const { distance, t } = vtkLine.distanceToLine(point, p0, p1);
8586
if (distance <= tol2 && t > 0.0 && t < 1.0) {
86-
return PolygonWithPointIntersectionState.INSIDE;
87+
return PolygonWithPointIntersectionState.ON_LINE;
8788
}
8889
}
8990

@@ -149,7 +150,9 @@ function pointInPolygon(point, vertices, bounds, normal) {
149150
} // Over all polygon edges
150151

151152
// A winding number == 0 is outside the polygon
152-
return wn === 0 ? PolygonWithPointIntersectionState.OUTSIDE : PolygonWithPointIntersectionState.INSIDE;
153+
return wn === 0
154+
? PolygonWithPointIntersectionState.OUTSIDE
155+
: PolygonWithPointIntersectionState.INSIDE;
153156
}
154157

155158
// ---------------------------------------------------
@@ -205,7 +208,7 @@ export function getNormal(poly, points, normal) {
205208
const v2 = [];
206209
for (let j = 2; j < n; j++) {
207210
points.getPoint(poly[j], p2);
208-
vtkMath.subtract(p2, p1, v2);
211+
vtkMath.subtract(p2, p1, v1);
209212
vtkMath.subtract(p0, p1, v2);
210213

211214
nn[0] += v1[1] * v2[2] - v1[2] * v2[1];
@@ -533,8 +536,6 @@ function interpolateFunctionsUsingMVC(point, points) {
533536
// distance
534537
dist[i] = vtkMath.norm([uVec[3 * i], uVec[3 * i + 1], uVec[3 * i + 2]]);
535538

536-
// eslint-disable-next-line no-debugger
537-
debugger;
538539
// handle special case when the point is really close to a vertex
539540
if (dist[i] <= EPSILON) {
540541
weights[i] = 1.0;
@@ -709,7 +710,7 @@ function intersectWithLine(p1, p2, points, normal) {
709710
t: Number.MAX_VALUE,
710711
x: [],
711712
};
712-
const tol2 = POLYGON_TOLERANCE * POLYGON_TOLERANCE;
713+
const tol2 = TOLERANCE * TOLERANCE;
713714

714715
// Intersect plane of the polygon with line
715716
//
@@ -742,7 +743,7 @@ function intersectConvex2DCells(polygon, points, normal) {
742743
const x1 = [];
743744
let lineIntersection;
744745
const outObj = {
745-
intersection: INTERSECTION.NO_INTERSECTION,
746+
intersection: PolygonWithPolygonIntersectionState.NO_INTERSECTION,
746747
x0: [],
747748
x1: [],
748749
};
@@ -768,7 +769,8 @@ function intersectConvex2DCells(polygon, points, normal) {
768769
t2 &&
769770
!vtkMath.areEquals(lineIntersection.x, outObj.x0)
770771
) {
771-
outObj.intersection = INTERSECTION.LINE_INTERSECTION;
772+
outObj.intersection =
773+
PolygonWithPolygonIntersectionState.LINE_INTERSECTION;
772774
outObj.x1 = lineIntersection.x;
773775
return outObj;
774776
}
@@ -792,7 +794,8 @@ function intersectConvex2DCells(polygon, points, normal) {
792794
t2 &&
793795
!vtkMath.areEquals(lineIntersection.x, outObj.x0)
794796
) {
795-
outObj.intersection = INTERSECTION.LINE_INTERSECTION;
797+
outObj.intersection =
798+
PolygonWithPolygonIntersectionState.LINE_INTERSECTION;
796799
outObj.x1 = lineIntersection.x;
797800
return outObj;
798801
}
@@ -801,10 +804,11 @@ function intersectConvex2DCells(polygon, points, normal) {
801804

802805
// Evaluate what we got
803806
if (idx === 1) {
804-
outObj.intersection = INTERSECTION.POINT_INTERSECTION; // everything intersecting at single point
807+
outObj.intersection =
808+
PolygonWithPolygonIntersectionState.POINT_INTERSECTION; // everything intersecting at single point
805809
return outObj;
806810
}
807-
outObj.intersection = INTERSECTION.NO_INTERSECTION;
811+
outObj.intersection = PolygonWithPolygonIntersectionState.NO_INTERSECTION;
808812
return outObj;
809813
}
810814

@@ -963,12 +967,10 @@ function vtkPolygon(publicAPI, model) {
963967
if (model.pointCount === vertexQueue.length()) {
964968
// convex
965969
const idPointToRemove = vertexQueue.pop();
966-
console.log(idPointToRemove);
967970
removePoint(idPointToRemove, vertexQueue);
968971
} else {
969972
// concave
970973
const idPointToRemove = vertexQueue.pop();
971-
console.log(idPointToRemove);
972974
if (canRemoveVertex(idPointToRemove)) {
973975
removePoint(idPointToRemove, vertexQueue);
974976
}
@@ -982,7 +984,6 @@ function vtkPolygon(publicAPI, model) {
982984
const ids = [];
983985
for (let i = 0; i < model.pointCount; i++) ids.push(i);
984986
model.normal = [];
985-
console.log(ids);
986987
return getNormal(ids, model.points, model.normal);
987988
};
988989

Sources/Common/DataModel/Polygon/test/testPolygon.js

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import test from 'tape-catch';
22
import vtkMath from 'vtk.js/Sources/Common/Core/Math';
33
import vtkPolygon from 'vtk.js/Sources/Common/DataModel/Polygon';
44
import {
5-
INTERSECTION,
5+
PolygonWithPointIntersectionState,
6+
PolygonWithPolygonIntersectionState,
67
EPSILON,
78
} from 'vtk.js/Sources/Common/DataModel/Polygon/Constants';
89

@@ -13,6 +14,28 @@ test('Test vtkPolygon instance', (t) => {
1314
t.end();
1415
});
1516

17+
test('Test vtkPolygon computeNormal', (t) => {
18+
const polygon = vtkPolygon.newInstance();
19+
20+
const poly = [
21+
[0, 0, 0],
22+
[3, 0, 0],
23+
[3, 3, 3],
24+
[0, 3, 3],
25+
];
26+
polygon.setPoints(poly);
27+
28+
t.ok(
29+
polygon.computeNormal() === 648 &&
30+
vtkMath.areEquals(
31+
polygon.get().normal,
32+
[0, -0.7071067811865476, 0.7071067811865476]
33+
)
34+
);
35+
36+
t.end();
37+
});
38+
1639
test('Test vtkPolygon computeCentroid', (t) => {
1740
const polygon = vtkPolygon.newInstance();
1841

@@ -85,37 +108,18 @@ test('Test vtkPolygon computeArea', (t) => {
85108
t.end();
86109
});
87110

88-
test('Test vtkPolygon computeNormal', (t) => {
89-
const polygon = vtkPolygon.newInstance();
90-
91-
let poly = [
92-
[0, 0, 0],
93-
[3, 0, 0],
94-
[3, 3, 3],
95-
[0, 3, 3],
96-
];
97-
polygon.setPoints(poly);
98-
99-
t.ok(
100-
polygon.computeNormal() === 2 &&
101-
vtkMath.areEquals(polygon.get().normal, [0.57, 0.57, 0.57])
102-
);
103-
104-
t.end();
105-
});
106-
107111
test('Test vtkPolygon triangulate', (t) => {
108112
const polygon = vtkPolygon.newInstance();
109113

110-
let poly = [
114+
const poly = [
111115
[0, 0, 0],
112116
[3, 0, 0],
113117
[3, 3, 3],
114118
[0, 3, 3],
115119
];
116120
polygon.setPoints(poly);
117121

118-
t.ok(polygon.triangulate(), 'Triangulate');
122+
t.ok(polygon.triangulate(), 'Can triangulate');
119123

120124
t.end();
121125
});
@@ -130,10 +134,19 @@ test('Test vtkPolygon pointInPolygon', (t) => {
130134
];
131135
polygon.setPoints(poly);
132136

133-
t.ok(polygon.pointInPolygon([1.5, 1.5, 1.5]), '[1.5,1.5,1.5] is in polygon');
134-
t.ok(!polygon.pointInPolygon([5, 5, 5]), '[5,5,5] is not in polygon');
135137
t.ok(
136-
polygon.pointInPolygon([1.5, 0, 0]),
138+
polygon.pointInPolygon([1.5, 1.5, 1.5]) ===
139+
PolygonWithPointIntersectionState.INSIDE,
140+
'[1.5,1.5,1.5] is in polygon'
141+
);
142+
t.ok(
143+
polygon.pointInPolygon([5, 5, 5]) ===
144+
PolygonWithPointIntersectionState.OUTSIDE,
145+
'[5,5,5] is not in polygon'
146+
);
147+
t.ok(
148+
polygon.pointInPolygon([1.5, 0, 0]) ===
149+
PolygonWithPointIntersectionState.INSIDE,
137150
'[1.5,0,0] is on edge of polygon (considered inside)'
138151
);
139152
// Same points but in a different order to test degenerate polygon
@@ -325,7 +338,8 @@ test('Test vtkPolygon intersectConvex2DCells', (t) => {
325338

326339
let intersection = polygon.intersectConvex2DCells(polygonToIntersect);
327340
t.ok(
328-
intersection.intersection === INTERSECTION.LINE_INTERSECTION &&
341+
intersection.intersection ===
342+
PolygonWithPolygonIntersectionState.LINE_INTERSECTION &&
329343
((vtkMath.areEquals(intersection.x0, [0, 1.5, 1.5]) &&
330344
vtkMath.areEquals(intersection.x1, [3, 1.5, 1.5])) ||
331345
(vtkMath.areEquals(intersection.x0, [3, 1.5, 1.5]) &&
@@ -343,7 +357,8 @@ test('Test vtkPolygon intersectConvex2DCells', (t) => {
343357

344358
intersection = polygon.intersectConvex2DCells(polygonToIntersect);
345359
t.ok(
346-
intersection.intersection === INTERSECTION.LINE_INTERSECTION &&
360+
intersection.intersection ===
361+
PolygonWithPolygonIntersectionState.LINE_INTERSECTION &&
347362
((vtkMath.areEquals(intersection.x0, [0, 1.5, 1.5]) &&
348363
vtkMath.areEquals(intersection.x1, [3, 1.5, 1.5])) ||
349364
(vtkMath.areEquals(intersection.x0, [3, 1.5, 1.5]) &&
@@ -360,7 +375,8 @@ test('Test vtkPolygon intersectConvex2DCells', (t) => {
360375

361376
intersection = polygon.intersectConvex2DCells(polygonToIntersect);
362377
t.ok(
363-
intersection.intersection === INTERSECTION.POINT_INTERSECTION &&
378+
intersection.intersection ===
379+
PolygonWithPolygonIntersectionState.POINT_INTERSECTION &&
364380
vtkMath.areEquals(intersection.x0, [1, 1.5, 1.5]) &&
365381
vtkMath.areEquals(intersection.x1, []),
366382
'point intersection'
@@ -375,7 +391,8 @@ test('Test vtkPolygon intersectConvex2DCells', (t) => {
375391

376392
intersection = polygon.intersectConvex2DCells(polygonToIntersect);
377393
t.ok(
378-
intersection.intersection === INTERSECTION.NO_INTERSECTION &&
394+
intersection.intersection ===
395+
PolygonWithPolygonIntersectionState.NO_INTERSECTION &&
379396
vtkMath.areEquals(intersection.x0, []) &&
380397
vtkMath.areEquals(intersection.x1, []),
381398
'no intersection'

0 commit comments

Comments
 (0)