Skip to content

Commit e74e715

Browse files
committed
feat(polygon, testPolygon): add functions to polygon
Translation from cpp implementation and add test to those functions Create functions as static functions and in publicAPI Updated ts definition
1 parent 47d8ca9 commit e74e715

File tree

5 files changed

+1191
-330
lines changed

5 files changed

+1191
-330
lines changed

Sources/Common/DataModel/Cell/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,12 @@ function vtkCell(publicAPI, model) {
104104
cell.initialize(model.points, model.pointsIds);
105105
};
106106

107-
publicAPI.getCellDimension = () => {}; // virtual
108-
publicAPI.intersectWithLine = (p1, p2, tol, t, x, pcoords, subId) => {}; // virtual
107+
publicAPI.getCellDimension = () => {
108+
macro.vtkErrorMacro('vtkCell.getCellDimension is not implemented.');
109+
}; // virtual
110+
publicAPI.intersectWithLine = (p1, p2, tol, t, x, pcoords, subId) => {
111+
macro.vtkErrorMacro('vtkCell.intersectWithLine is not implemented.');
112+
}; // virtual
109113
publicAPI.evaluatePosition = (
110114
x,
111115
closestPoint,

Sources/Common/DataModel/Polygon/Constants.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,12 @@ export const PolygonWithPointIntersectionState = {
99
INTERSECTION: 2,
1010
ON_LINE: 3,
1111
};
12+
export const VTK_DBL_EPSILON = 2.2204460492503131e-16;
13+
14+
export const INTERSECTION = {
15+
NO_INTERSECTION,
16+
POINT_INTERSECTION,
17+
LINE_INTERSECTION,
18+
}
19+
20+
export default { INTERSECTION, PolygonWithPointIntersectionState };

Sources/Common/DataModel/Polygon/index.d.ts

Lines changed: 92 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { vtkObject } from "../../../interfaces";
22
import { Bounds, Vector3 } from "../../../types";
33

44
export interface IPolygonInitialValues {
5-
firstPoint?: Vector3,
6-
pointCount?: number,
7-
tris?: Vector3[],
5+
firstPoint?: Vector3,
6+
pointCount?: number,
7+
tris?: Vector3[],
88
}
99

1010
/**
@@ -18,26 +18,46 @@ export enum POINT_IN_POLYGON {
1818
ON_LINE,
1919
}
2020

21+
export enum INTERSECTION {
22+
NO_INTERSECTION,
23+
LINE_INTERSECTION,
24+
POINT_INTERSECTION,
25+
};
26+
27+
interface IIntersectWithLine {
28+
intersection: boolean;
29+
betweenPoints: boolean;
30+
t: number;
31+
x: Vector3;
32+
}
33+
34+
export const INTERSECTION = {
35+
NO_INTERSECTION: 0,
36+
LINE_INTERSECTION: 1,
37+
POINT_INTERSECTION: 2,
38+
}
39+
2140
export interface vtkPolygon extends vtkObject {
2241

2342
/**
24-
* Get the array of triangles that triangulate the polygon.
25-
*/
26-
getPointArray(): Vector3[];
43+
* Get the array of triangles that triangulate the polygon.
44+
*/
45+
getPointArray(): Vector3[];
2746

28-
/**
29-
* Set the polygon's points.
30-
* @param {Vector3[]} points The polygon's points.
31-
*/
32-
setPoints(points: Vector3[]): void;
47+
/**
48+
* Set the polygon's points
49+
* Points must be ordered in counterclockwise order
50+
* @param {Vector3[]} points The polygon's points.
51+
*/
52+
setPoints(points: Vector3[]): void;
3353

34-
/**
35-
* Triangulate this polygon.
36-
* The output data must be accessed through `getPointArray`.
37-
* The output data contains points by group of three: each three-group
38-
* defines one triangle.
39-
*/
40-
triangulate(): void;
54+
/**
55+
* Triangulate this polygon.
56+
* The output data must be accessed through `getPointArray`.
57+
* The output data contains points by group of three: each three-group
58+
* defines one triangle.
59+
*/
60+
triangulate(): void;
4161

4262
/**
4363
* Determine whether a point is inside a polygon. The function uses a winding
@@ -56,7 +76,57 @@ export interface vtkPolygon extends vtkObject {
5676
vertices: Vector3[],
5777
bounds: Bounds,
5878
normal: Vector3
59-
): number;
79+
): number;
80+
81+
/**
82+
* Compute ear triangulation of current polygon
83+
* The polygon must be convex and have at least 3 points
84+
* @return {boolean} whether triangulation failed or not
85+
*/
86+
triangulate(): boolean;
87+
88+
/**
89+
* Returns the centroid of this polygon
90+
* @return {Vector3} centroid
91+
*/
92+
computeCentroid(): Vector3;
93+
94+
/**
95+
* Returns the area of the polygon
96+
* @return {number} area
97+
*/
98+
computeArea(): number;
99+
100+
/**
101+
* Returns whether the polygon is convex or not
102+
* Returns false for degenerate polygon
103+
* @return {boolean} is convex or not
104+
*/
105+
isConvex(): boolean;
106+
107+
/**
108+
* Interpolates functions with polygon points
109+
* @param point point to compute the interpolation on
110+
* @param useMVCInterpolation
111+
* @return weights corresponding to each point of polygon parametrizing the given point
112+
*/
113+
interpolateFunctions(point: Vector3, useMVCInterpolation: boolean): Number[]
114+
115+
/**
116+
* Computes intersection of polygon with a line defined by two points
117+
* @param p1 first point of line
118+
* @param p2 second point of line
119+
* @return intersection point coordinates
120+
*/
121+
intersectWithLine(p1: Vector3, p2: Vector3): IIntersectWithLine
122+
123+
/**
124+
* Computes the intersection between two polygons
125+
* The two points p0 and p1 describe the intersection. If no intersection is found, p0 and p1 are left null.
126+
* If the intersection is only one point, p1 is left null
127+
* @return {INTERSECTION} type of intersection (no, one point or line)
128+
*/
129+
intersectConvex2DCells(polygon: vtkPolygon, tol: number, p0: Vector3, p1: Vector3): INTERSECTION
60130
}
61131

62132
/**
@@ -97,15 +167,13 @@ export function newInstance(initialValues?: IPolygonInitialValues): vtkPolygon;
97167

98168
/**
99169
* vtkPolygon represents a 2D n-sided polygon.
100-
*
170+
*
101171
* The polygons cannot have any internal holes, and cannot self-intersect.
102172
* Define the polygon with n-points ordered in the counter-clockwise direction.
103173
* Do not repeat the last point.
104174
*/
105175
export declare const vtkPolygon: {
106-
newInstance: typeof newInstance,
107-
extend: typeof extend;
108-
// static
109-
176+
newInstance: typeof newInstance,
177+
extend: typeof extend;
110178
};
111179
export default vtkPolygon;

0 commit comments

Comments
 (0)