Skip to content

Commit 08de1f2

Browse files
implementation for line line intersection, polyline self intersection and two polyline intersections. Also implemented scaled to fit hex grid with extensons, wip for subidivison of faces to hexagon wires. Implemented sorting of points on xyz, stretch of points + stretch transform matrixes, transformations between line to segment, polyline to segments and vice versa. Unit tests for intersections, fixed and extended to use unit test helper.
1 parent fc04254 commit 08de1f2

File tree

26 files changed

+1948
-284
lines changed

26 files changed

+1948
-284
lines changed

packages/dev/babylonjs/lib/api/bitbybit-base.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ export class BitByBitBase {
8989
this.color = new Color(this.math);
9090
this.transforms = new Transforms(this.vector, this.math);
9191
this.point = new Point(geometryHelper, this.transforms, this.vector);
92-
this.line = new Line(this.point, geometryHelper);
93-
this.polyline = new Polyline(this.vector, this.point, geometryHelper);
92+
this.line = new Line(this.vector, this.point, geometryHelper);
93+
this.polyline = new Polyline(this.vector, this.point, this.line, geometryHelper);
9494
this.verb = new Verb(this.context, geometryHelper, this.math);
9595
this.time = new Time(this.context);
9696
this.occt = new OCCTW(this.context, this.occtWorkerManager);

packages/dev/base/lib/api/inputs/line-inputs.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,36 @@ export namespace Line {
190190
*/
191191
lines?: LinePointsDto[];
192192
}
193+
export class LineLineIntersectionDto {
194+
constructor(line1?: LinePointsDto, line2?: LinePointsDto, tolerance?: number) {
195+
if (line1 !== undefined) { this.line1 = line1; }
196+
if (line2 !== undefined) { this.line2 = line2; }
197+
if (tolerance !== undefined) { this.tolerance = tolerance; }
198+
}
199+
/**
200+
* First line
201+
* @default undefined
202+
*/
203+
line1?: LinePointsDto;
204+
/**
205+
* Second line
206+
* @default undefined
207+
*/
208+
line2?: LinePointsDto;
209+
/**
210+
* Set to false if you want to check for infinite lines
211+
* @default true
212+
*/
213+
checkSegmentsOnly? = true;
214+
/**
215+
* Tolerance for intersection
216+
* @default 0.01
217+
* @minimum 0
218+
* @maximum Infinity
219+
* @step 0.1
220+
*/
221+
tolerance?: number;
222+
}
193223
export class PointOnLineDto {
194224
constructor(line?: LinePointsDto, param?: number) {
195225
if (line !== undefined) { this.line = line; }

packages/dev/base/lib/api/inputs/point-inputs.ts

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,38 @@ export namespace Point {
304304
*/
305305
scaleXyz: Base.Vector3 = [1, 1, 1];
306306
}
307+
308+
export class StretchPointsDirFromCenterDto {
309+
constructor(points?: Base.Point3[], center?: Base.Point3, direction?: Base.Vector3, scale?: number) {
310+
if (points !== undefined) { this.points = points; }
311+
if (center !== undefined) { this.center = center; }
312+
if (direction !== undefined) { this.direction = direction; }
313+
if (scale !== undefined) { this.scale = scale; }
314+
}
315+
/**
316+
* Points to transform
317+
* @default undefined
318+
*/
319+
points?: Base.Point3[];
320+
/**
321+
* The center from which the scaling is applied
322+
* @default [0, 0, 0]
323+
*/
324+
center?: Base.Point3 = [0, 0, 0];
325+
/**
326+
* Stretch direction vector
327+
* @default [0, 0, 1]
328+
*/
329+
direction?: Base.Vector3 = [0, 0, 1];
330+
/**
331+
* The scale factor to apply along the direction vector. 1.0 means no change.
332+
* @default 2
333+
* @minimum -Infinity
334+
* @maximum Infinity
335+
* @step 0.1
336+
*/
337+
scale? = 2;
338+
}
307339
export class RotatePointsCenterAxisDto {
308340
constructor(points?: Base.Point3[], angle?: number, axis?: Base.Vector3, center?: Base.Point3) {
309341
if (points !== undefined) { this.points = points; }
@@ -543,7 +575,68 @@ export namespace Point {
543575
*/
544576
factor = 1;
545577
}
546-
578+
export class HexGridScaledToFitDto {
579+
constructor(wdith?: number, height?: number, nrHexagonsU?: number, nrHexagonsV?: number, centerGrid?: boolean, pointsOnGround?: boolean) {
580+
if (wdith !== undefined) { this.width = wdith; }
581+
if (height !== undefined) { this.height = height; }
582+
if (nrHexagonsU !== undefined) { this.nrHexagonsU = nrHexagonsU; }
583+
if (nrHexagonsV !== undefined) { this.nrHexagonsV = nrHexagonsV; }
584+
if (centerGrid !== undefined) { this.centerGrid = centerGrid; }
585+
if (pointsOnGround !== undefined) { this.pointsOnGround = pointsOnGround; }
586+
}
587+
/** Total desired width for the grid area. The hexagon size will be derived from this and nrHexagonsU.
588+
* @default 10
589+
* @minimum 0
590+
* @maximum Infinity
591+
* @step 0.1
592+
*/
593+
width? = 10;
594+
/** Total desired height for the grid area. Note: due to hexagon geometry, the actual grid height might differ slightly if maintaining regular hexagons based on width.
595+
* @default 10
596+
* @minimum 0
597+
* @maximum Infinity
598+
* @step 0.1
599+
*/
600+
height? = 10;
601+
/** Number of hexagons desired horizontally (U direction).
602+
* @default 10
603+
* @minimum 0
604+
* @maximum Infinity
605+
* @step 1
606+
*/
607+
nrHexagonsU? = 10;
608+
/** Number of hexagons desired vertically (V direction).
609+
* @default 10
610+
* @minimum 0
611+
* @maximum Infinity
612+
* @step 1
613+
*/
614+
nrHexagonsV? = 10;
615+
/** If true, shift the entire grid up by half hex height.
616+
* @default false
617+
*/
618+
extendTop? = false;
619+
/** If true, shift the entire grid down by half hex height.
620+
* @default false
621+
*/
622+
extendBottom? = false;
623+
/** If true, shift the entire grid left by half hex width.
624+
* @default false
625+
*/
626+
extendLeft? = false;
627+
/** If true, shift the entire grid right by half hex width.
628+
* @default false
629+
*/
630+
extendRight? = false;
631+
/** If true, the grid center (based on totalWidth/totalHeight) will be at [0,0,0].
632+
* @default false
633+
*/
634+
centerGrid? = false;
635+
/** If true, swaps Y and Z coordinates and sets Y to 0, placing points on the XZ ground plane.
636+
* @default false
637+
*/
638+
pointsOnGround? = false;
639+
}
547640
export class HexGridCentersDto {
548641
constructor(nrHexagonsX?: number, nrHexagonsY?: number, radiusHexagon?: number, orientOnCenter?: boolean, pointsOnGround?: boolean) {
549642
if (nrHexagonsX !== undefined) { this.nrHexagonsX = nrHexagonsX; }

packages/dev/base/lib/api/inputs/polyline-inputs.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,48 @@ export namespace Polyline {
197197
*/
198198
tolerance? = 1e-5;
199199
}
200+
export class PolylineToleranceDto {
201+
constructor(polyline?: PolylinePropertiesDto, tolerance?: number) {
202+
if (polyline !== undefined) { this.polyline = polyline; }
203+
if (tolerance !== undefined) { this.tolerance = tolerance; }
204+
}
205+
/**
206+
* Polyline to check
207+
* @default undefined
208+
*/
209+
polyline?: PolylinePropertiesDto;
210+
/**
211+
* Tolerance for the calculation
212+
* @default 1e-5
213+
* @minimum -Infinity
214+
* @maximum Infinity
215+
* @step 1e-5
216+
*/
217+
tolerance? = 1e-5;
218+
}
219+
export class TwoPolylinesToleranceDto {
220+
constructor(polyline1?: PolylinePropertiesDto, polyline2?: PolylinePropertiesDto, tolerance?: number) {
221+
if (polyline1 !== undefined) { this.polyline1 = polyline1; }
222+
if (polyline2 !== undefined) { this.polyline2 = polyline2; }
223+
if (tolerance !== undefined) { this.tolerance = tolerance; }
224+
}
225+
/**
226+
* First polyline to check
227+
* @default undefined
228+
*/
229+
polyline1?: PolylinePropertiesDto;
230+
/**
231+
* Second polyline to check
232+
* @default undefined
233+
*/
234+
polyline2?: PolylinePropertiesDto;
235+
/**
236+
* Tolerance for the calculation
237+
* @default 1e-5
238+
* @minimum -Infinity
239+
* @maximum Infinity
240+
* @step 1e-5
241+
*/
242+
tolerance? = 1e-5;
243+
}
200244
}

packages/dev/base/lib/api/inputs/transforms-inputs.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,28 @@ export namespace Transforms {
9494
*/
9595
scaleXyz: Base.Vector3 = [1, 1, 1];
9696
}
97+
export class StretchDirCenterDto {
98+
constructor(scale?: number, center?: Base.Point3, direction?: Base.Vector3) {
99+
if (scale !== undefined) { this.scale = scale; }
100+
if (center !== undefined) { this.center = center; }
101+
if (direction !== undefined) { this.direction = direction; }
102+
}
103+
/** The center point around which to stretch.
104+
* @default [0, 0, 0]
105+
*/
106+
center?: Base.Point3 = [0, 0, 0];
107+
/** The direction vector along which to stretch. Does not need to be normalized initially.
108+
* @default [0, 0, 1]
109+
*/
110+
direction?: Base.Vector3 = [0, 0, 1];
111+
/** The scale factor to apply along the direction vector. 1.0 means no change.
112+
* @default 2
113+
* @minimum -Infinity
114+
* @maximum Infinity
115+
* @step 0.1
116+
*/
117+
scale? = 2;
118+
}
97119
export class ScaleCenterXYZDto {
98120
constructor(center?: Base.Point3, scaleXyz?: Base.Vector3) {
99121
if (center !== undefined) { this.center = center; }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from "./text";
2+
export * from "./point";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./hex-grid-data";
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { Base } from "../../inputs/base-inputs";
2+
3+
export class HexGridData {
4+
points: Base.Point3[];
5+
hexagons: Base.Point3[][];
6+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * as Point from "./bucket";

0 commit comments

Comments
 (0)