@@ -2,9 +2,9 @@ import { vtkObject } from "../../../interfaces";
2
2
import { Bounds , Vector3 } from "../../../types" ;
3
3
4
4
export interface IPolygonInitialValues {
5
- firstPoint ?: Vector3 ,
6
- pointCount ?: number ,
7
- tris ?: Vector3 [ ] ,
5
+ firstPoint ?: Vector3 ,
6
+ pointCount ?: number ,
7
+ tris ?: Vector3 [ ] ,
8
8
}
9
9
10
10
/**
@@ -18,26 +18,46 @@ export enum POINT_IN_POLYGON {
18
18
ON_LINE ,
19
19
}
20
20
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
+
21
40
export interface vtkPolygon extends vtkObject {
22
41
23
42
/**
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 [ ] ;
27
46
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 ;
33
53
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 ;
41
61
42
62
/**
43
63
* Determine whether a point is inside a polygon. The function uses a winding
@@ -56,7 +76,57 @@ export interface vtkPolygon extends vtkObject {
56
76
vertices : Vector3 [ ] ,
57
77
bounds : Bounds ,
58
78
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
60
130
}
61
131
62
132
/**
@@ -97,15 +167,13 @@ export function newInstance(initialValues?: IPolygonInitialValues): vtkPolygon;
97
167
98
168
/**
99
169
* vtkPolygon represents a 2D n-sided polygon.
100
- *
170
+ *
101
171
* The polygons cannot have any internal holes, and cannot self-intersect.
102
172
* Define the polygon with n-points ordered in the counter-clockwise direction.
103
173
* Do not repeat the last point.
104
174
*/
105
175
export declare const vtkPolygon : {
106
- newInstance : typeof newInstance ,
107
- extend : typeof extend ;
108
- // static
109
-
176
+ newInstance : typeof newInstance ,
177
+ extend : typeof extend ;
110
178
} ;
111
179
export default vtkPolygon ;
0 commit comments