Skip to content

Commit b9ec532

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

File tree

2 files changed

+148
-65
lines changed

2 files changed

+148
-65
lines changed
Lines changed: 142 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,39 @@
1-
import { vtkObject } from "../../../interfaces";
2-
import { Bounds, Vector3 } from "../../../types";
1+
import { vtkObject } from '../../../interfaces';
2+
import { Bounds, Vector3 } from '../../../types';
3+
import vtkPoints from '../../Core/Points';
34

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

1010
/**
1111
* Different states which pointInPolygon could return.
1212
*/
13-
export enum POINT_IN_POLYGON {
14-
FAILURE,
15-
OUTSIDE,
16-
INSIDE,
17-
INTERSECTION,
18-
ON_LINE,
13+
export enum PolygonWithPointIntersectionState {
14+
FAILURE,
15+
OUTSIDE,
16+
INSIDE,
1917
}
2018

21-
export enum INTERSECTION {
19+
/**
20+
* Different states which intersectWith2DConvexCell could return.
21+
*/
22+
export enum PolygonWithPolygonIntersectionState {
2223
NO_INTERSECTION,
2324
LINE_INTERSECTION,
2425
POINT_INTERSECTION,
25-
};
26-
27-
interface IIntersectWithLine {
28-
intersection: boolean;
29-
betweenPoints: boolean;
30-
t: number;
31-
x: Vector3;
3226
}
3327

34-
export const INTERSECTION = {
35-
NO_INTERSECTION: 0,
36-
LINE_INTERSECTION: 1,
37-
POINT_INTERSECTION: 2,
28+
interface IIntersectWithLine {
29+
intersection: boolean;
30+
betweenPoints: boolean;
31+
t: number;
32+
x: Vector3;
3833
}
3934

4035
export interface vtkPolygon extends vtkObject {
41-
42-
/**
36+
/**
4337
* Get the array of triangles that triangulate the polygon.
4438
*/
4539
getPointArray(): Vector3[];
@@ -51,6 +45,12 @@ export interface vtkPolygon extends vtkObject {
5145
*/
5246
setPoints(points: Vector3[]): void;
5347

48+
/**
49+
* Computes the polygon normal
50+
* @return {number} squared norm before normalization
51+
*/
52+
computeNormal(): number;
53+
5454
/**
5555
* Triangulate this polygon.
5656
* The output data must be accessed through `getPointArray`.
@@ -59,25 +59,18 @@ export interface vtkPolygon extends vtkObject {
5959
*/
6060
triangulate(): void;
6161

62-
/**
63-
* Determine whether a point is inside a polygon. The function uses a winding
64-
* number calculation generalized to the 3D plane one which the polygon
65-
* resides. Returns 0 if point is not in the polygon; 1 if it is inside. Can
66-
* also return -1 to indicate a degenerate polygon. This implementation is
67-
* inspired by Dan Sunday's algorithm found in the book Practical Geometry
68-
* Algorithms.
69-
* @param {Vector3} point Point to check
70-
* @param {Vector3[]} vertices Vertices of the polygon
71-
* @param {Bounds} bounds Bounds of the vertices
72-
* @param {Vector3} normal normal vector of the polygon
73-
*/
74-
pointInPolygon(
75-
point: Vector3,
76-
vertices: Vector3[],
77-
bounds: Bounds,
78-
normal: Vector3
79-
): number;
80-
62+
/**
63+
* Determine whether a point is inside a polygon. The function uses a winding
64+
* number calculation generalized to the 3D plane one which the polygon
65+
* resides. Returns OUTSIDE if point is not in the polygon; INSIDE if it is inside. Can
66+
* also return FAILURE to indicate a degenerate polygon. This implementation is
67+
* inspired by Dan Sunday's algorithm found in the book Practical Geometry
68+
* Algorithms.
69+
* @param {Vector3} point Point to check
70+
* @return {PolygonWithPointIntersectionState} type of intersection
71+
*/
72+
pointInPolygon(point: Vector3): PolygonWithPointIntersectionState;
73+
8174
/**
8275
* Compute ear triangulation of current polygon
8376
* The polygon must be convex and have at least 3 points
@@ -107,33 +100,73 @@ export interface vtkPolygon extends vtkObject {
107100
/**
108101
* Interpolates functions with polygon points
109102
* @param point point to compute the interpolation on
110-
* @param useMVCInterpolation
103+
* @param useMVCInterpolation
111104
* @return weights corresponding to each point of polygon parametrizing the given point
112105
*/
113-
interpolateFunctions(point: Vector3, useMVCInterpolation: boolean): Number[]
106+
interpolateFunctions(point: Vector3, useMVCInterpolation: boolean): Number[];
114107

115108
/**
116109
* 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
110+
* @param x1 first point of line
111+
* @param x2 second point of line
119112
* @return intersection point coordinates
120113
*/
121-
intersectWithLine(p1: Vector3, p2: Vector3): IIntersectWithLine
114+
intersectWithLine(x1: Vector3, x2: Vector3): IIntersectWithLine;
122115

123116
/**
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)
117+
* Computes intersection of polygon with another polygon.
118+
* It can be a line, a point or no intersection.
119+
* Note: Expects both polygons to be convex
120+
* @param polygon vtkPolygon with which to compute intersection
121+
* @return {PolygonWithPolygonIntersectionState} type of intersection
128122
*/
129-
intersectConvex2DCells(polygon: vtkPolygon, tol: number, p0: Vector3, p1: Vector3): INTERSECTION
123+
intersectConvex2DCells(
124+
polygon: vtkPolygon
125+
): PolygonWithPolygonIntersectionState;
130126
}
131127

128+
// ---------------------------------------------------
129+
/**
130+
* Compute the normal of a polygon and return its squared norm.
131+
* @param {Array<number>|TypedArray<number>} poly
132+
* @param {vtkPoints} points
133+
* @param {Vector3} normal
134+
* @returns {number}
135+
*/
136+
export function getNormal(
137+
poly: Vector3[],
138+
points: vtkPoints,
139+
normal: Vector3
140+
): number;
141+
142+
/**
143+
* Determines whether a polygon is convex
144+
* @param points vtkPoints defining the polygon
145+
* @return {boolean} whether the polygon is convex or not
146+
*/
147+
export function isConvex(points: vtkPoints): boolean;
148+
149+
/**
150+
* Given a set of points, computes the centroid of the corresponding polygon
151+
* @param points vtkPoints defining the polygon
152+
* @param normal normal to the polygon of which the centroid is computed
153+
* @return {Vector3} centroid. Returns null for degenerate polygon
154+
*/
155+
export function computeCentroid(points: vtkPoints, normal: Vector3): Vector3;
156+
157+
/**
158+
* Given a set of points, computes the area of the corresponding polygon
159+
* @param points vtkPoints defining the polygon
160+
* @param normal normal to the polygon of which the centroid is computed
161+
* @return {number} area of polygon
162+
*/
163+
export function computeArea(points: vtkPoints, normal: Vector3): number;
164+
132165
/**
133166
* Determine whether a point is inside a polygon. The function uses a winding
134167
* number calculation generalized to the 3D plane one which the polygon
135-
* resides. Returns 0 if point is not in the polygon; 1 if it is inside. Can
136-
* also return -1 to indicate a degenerate polygon. This implementation is
168+
* resides. Returns OUTSIDE if point is not in the polygon; INSIDE if it is inside. Can
169+
* also return FAILURE to indicate a degenerate polygon. This implementation is
137170
* inspired by Dan Sunday's algorithm found in the book Practical Geometry
138171
* Algorithms.
139172
*
@@ -145,19 +178,69 @@ export interface vtkPolygon extends vtkObject {
145178
*/
146179
export function pointInPolygon(
147180
point: Vector3,
148-
vertices: Array|TypedArray,
181+
vertices: Array | TypedArray,
149182
bounds: Bounds,
150183
normal: Vector3
151184
): PolygonIntersectionState;
152185

186+
/**
187+
* Given a set of points that define a polygon, determines whether a line defined
188+
* by two points intersect with the polygon. There can be no intersection, a point
189+
* intersection or a line intersection.
190+
* @param p1 first point of the line
191+
* @param p2 second point of the line
192+
* @param points points defining the polygon
193+
* @param normal normal to the polygon
194+
* @return {IIntersectWithLine} type of intersection
195+
*/
196+
export function intersectWithLine(
197+
p1: Vector3,
198+
p2: Vector3,
199+
points: vtkPoints,
200+
normal: Vector3
201+
): IIntersectWithLine;
202+
203+
/**
204+
* Given a set of points that define a polygon and another polygon, computes their
205+
* intersection. It can be a line, a point or no intersection.
206+
* Note: Expects both polygons to be convex
207+
* @param polygon vtkPolygon with which to compute intersection
208+
* @param points points defining the polygon
209+
* @param normal normal to the polygon
210+
* @return {PolygonWithPolygonIntersectionState} type of intersection
211+
*/
212+
export function intersectConvex2DCells(
213+
polygon: vtkPolygon,
214+
points: vtkPoints,
215+
normal: Vector3
216+
): PolygonWithPolygonIntersectionState;
217+
218+
/**
219+
* Given a set of points, computes the weights corresponding to the interpolation of the
220+
* given point with regard to the points of the polygon. The returned array corresponds to
221+
* the weights and therefore its size is the number of points in the polygon
222+
* @param point point we want the interpolation of
223+
* @param points points defining the polygon
224+
* @param useMVCInterpolation whether to use MVC interpolation
225+
*/
226+
export function interpolateFunctions(
227+
point: Vector3,
228+
points: vtkPoints,
229+
useMVCInterpolation: boolean
230+
): Array<number>;
231+
153232
/**
154233
* Method used to decorate a given object (publicAPI+model) with vtkPolygon characteristics.
155234
*
156235
* @param publicAPI object on which methods will be bounds (public)
157236
* @param model object on which data structure will be bounds (protected)
158237
* @param {IPolygonInitialValues} [initialValues] (default: {})
159238
*/
160-
export function extend(publicAPI: object, model: object, initialValues?: IPolygonInitialValues): void;
239+
export function extend(
240+
publicAPI: object,
241+
model: object,
242+
initialValues?: IPolygonInitialValues
243+
): void;
161244

162245
/**
163246
* Method used to create a new instance of vtkPolygon.
@@ -173,7 +256,7 @@ export function newInstance(initialValues?: IPolygonInitialValues): vtkPolygon;
173256
* Do not repeat the last point.
174257
*/
175258
export declare const vtkPolygon: {
176-
newInstance: typeof newInstance,
259+
newInstance: typeof newInstance;
177260
extend: typeof extend;
178261
};
179262
export default vtkPolygon;

Sources/Common/DataModel/Polygon/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ export function getNormal(poly, points, normal) {
229229
return norm2;
230230
}
231231

232-
function isConvex(points) {
232+
export function isConvex(points) {
233233
let i;
234234
const v = [
235235
[0, 0, 0],
@@ -292,7 +292,7 @@ function isConvex(points) {
292292
return true;
293293
}
294294

295-
function computeCentroid(points, normal) {
295+
export function computeCentroid(points, normal) {
296296
const numPts = points.getNumberOfPoints();
297297
// Strategy:
298298
// - Compute centroid of projected polygon on (x,y) if polygon is projectible, (x,z) otherwise
@@ -357,7 +357,7 @@ function computeCentroid(points, normal) {
357357
return c;
358358
}
359359

360-
function computeArea(points, normal) {
360+
export function computeArea(points, normal) {
361361
const numPts = points.getNumberOfPoints();
362362
if (numPts < 3) {
363363
return 0.0;
@@ -601,7 +601,7 @@ function interpolateFunctionsUsingMVC(point, points) {
601601
return weights;
602602
}
603603

604-
function interpolateFunctions(point, points, useMVCInterpolation) {
604+
export function interpolateFunctions(point, points, useMVCInterpolation) {
605605
// Compute interpolation weights using mean value coordinate.
606606
if (useMVCInterpolation) {
607607
return interpolateFunctionsUsingMVC(point, points);
@@ -703,7 +703,7 @@ function evaluatePosition(point, points, normal) {
703703
return res;
704704
}
705705

706-
function intersectWithLine(p1, p2, points, normal) {
706+
export function intersectWithLine(p1, p2, points, normal) {
707707
let outObj = {
708708
intersection: false,
709709
betweenPoints: false,
@@ -735,7 +735,7 @@ function intersectWithLine(p1, p2, points, normal) {
735735
}
736736

737737
//------------------------------------------------------------------------------
738-
function intersectConvex2DCells(polygon, points, normal) {
738+
export function intersectConvex2DCells(polygon, points, normal) {
739739
// Intersect the six total edges of the two triangles against each other. Two points are
740740
// all that are required.
741741
const numPts = points.getNumberOfPoints();

0 commit comments

Comments
 (0)