1
1
import { Point , pointInPolygon , Polygon , polygonBounds } from "geometric" ;
2
2
import { GPU } from "gpu.js" ;
3
- import Shape from "@doodle3d/clipper-js" ;
3
+ import { angleNormalize , Part , partMoveTo , partNestingBounds , partRotate , pointDistanceTo } from "./primitives" ;
4
+ import { origin } from "./nesting" ;
4
5
5
6
const gpu = new GPU ( {
6
7
mode : "gpu" ,
@@ -20,17 +21,13 @@ export function rasterize(bounds: [Point, Point]): Point[] {
20
21
return dots ;
21
22
}
22
23
23
- export function noFitRaster (
24
- boardDots : [ number , number ] [ ] ,
25
- stationaryDots : [ number , number ] [ ] ,
26
- orbitingDots : [ number , number ] [ ] ,
27
- ) : [ number , number ] [ ] {
24
+ export function noFitRaster ( boardDots : Point [ ] , stationaryDots : Point [ ] , orbitingDots : Point [ ] ) : Point [ ] {
28
25
const kernelFunc = gpu
29
26
. createKernel ( function (
30
- boardDots : [ number , number ] [ ] ,
31
- stationaryDots : [ number , number ] [ ] ,
32
- orbitingDots : [ number , number ] [ ] ,
33
- orbitingDotsMinimumPoint : [ number , number ] ,
27
+ boardDots : Point [ ] ,
28
+ stationaryDots : Point [ ] ,
29
+ orbitingDots : Point [ ] ,
30
+ orbitingDotsMinimumPoint : Point ,
34
31
) {
35
32
for ( let k = 0 ; k < this . constants . numOrbitingDots ; k ++ ) {
36
33
const x1 = orbitingDots [ k ] [ 0 ] + boardDots [ this . thread . y ] [ 0 ] ;
@@ -63,9 +60,9 @@ export function noFitRaster(
63
60
return boardDots . filter ( ( value , index ) => out [ index ] . some ( ( x : number ) => x == 1 ) ) ;
64
61
}
65
62
66
- export function rasterDifference ( a : [ number , number ] [ ] , b : [ number , number ] [ ] ) : [ number , number ] [ ] {
63
+ export function rasterDifference ( a : Point [ ] , b : Point [ ] ) : Point [ ] {
67
64
const kernelFunc = gpu
68
- . createKernel ( function ( a : [ number , number ] [ ] , b : [ number , number ] [ ] ) {
65
+ . createKernel ( function ( a : Point [ ] , b : Point [ ] ) {
69
66
for ( let k = 0 ; k < this . constants . numB ; k ++ ) {
70
67
const x1 = b [ k ] [ 0 ] ;
71
68
const x2 = a [ this . thread . x ] [ 0 ] ;
@@ -89,7 +86,7 @@ export function rasterDifference(a: [number, number][], b: [number, number][]):
89
86
return a . filter ( ( value , index ) => out [ index ] == 1 ) ;
90
87
}
91
88
92
- export function noFitPolygon ( stationaryPolygon : Polygon , orbitingPolygon : Polygon ) : [ number , number ] [ ] {
89
+ export function noFitPolygon ( stationaryPolygon : Polygon , orbitingPolygon : Polygon ) : Polygon {
93
90
const stationaryBounds = polygonBounds ( stationaryPolygon ) ;
94
91
const orbitingBounds = polygonBounds ( orbitingPolygon ) ;
95
92
@@ -120,28 +117,61 @@ export function noFitPolygon(stationaryPolygon: Polygon, orbitingPolygon: Polygo
120
117
return noFitRaster ( boardDots , stationaryDots , orbitingDots ) ;
121
118
}
122
119
123
- export function testClipper ( ) {
124
- const subjectPaths = [
125
- [
126
- { X : 30 , Y : 30 } ,
127
- { X : 10 , Y : 30 } ,
128
- { X : 10 , Y : 10 } ,
129
- { X : 30 , Y : 10 } ,
130
- ] ,
131
- ] ;
132
- const clipPaths = [
133
- [
134
- { X : 20 , Y : 20 } ,
135
- { X : 0 , Y : 20 } ,
136
- { X : 0 , Y : 0 } ,
137
- { X : 20 , Y : 0 } ,
138
- ] ,
139
- ] ;
120
+ export function noFitPolygons (
121
+ stationaryPartOutsideLoopExtentsPoints : Point [ ] ,
122
+ orbitingPartOutsideLoopExtentsPoints : Point [ ] ,
123
+ raster : boolean ,
124
+ ) : Polygon [ ] {
125
+ if ( ! raster ) {
126
+ throw new Error ( "not supported" ) ;
127
+ }
140
128
141
- const subject = new Shape ( subjectPaths , true ) ;
142
- const clip = new Shape ( clipPaths , true ) ;
129
+ // TODO
130
+ }
143
131
144
- const result = subject . intersect ( clip ) ;
132
+ export function innerFitPolygons (
133
+ stationaryPartInsideLoopExtentsPoints : Point [ ] ,
134
+ orbitingPartOutsideLoopExtentsPoints : Point [ ] ,
135
+ raseter : boolean ,
136
+ ) : Polygon [ ] {
137
+ // TODO
138
+ }
139
+
140
+ export function _noFitPolygonsAndInnerFitPolygons (
141
+ stationaryPart : Part ,
142
+ orbitingPart : Part ,
143
+ raster : boolean ,
144
+ ) : { noFitPolygons : Polygon [ ] ; innerFitPolygons : Polygon [ ] } {
145
+ if ( pointDistanceTo ( partNestingBounds ( stationaryPart ) [ 0 ] , origin ) > 0.1 ) {
146
+ throw new Error ( ) ;
147
+ }
148
+
149
+ if ( pointDistanceTo ( partNestingBounds ( orbitingPart ) [ 0 ] , origin ) > 0.1 ) {
150
+ throw new Error ( ) ;
151
+ }
152
+
153
+ const noFitPolygons : Polygon [ ] = [ ] ;
154
+ const innerFitPolygons : Polygon [ ] = [ ] ;
155
+
156
+ // TODO
157
+
158
+ // return {
159
+ // noFitPolygons: noFitPolygons,
160
+ // innerFitPolygons: innerFitPolygons,
161
+ // };
162
+ }
145
163
146
- console . log ( JSON . stringify ( result ) ) ;
164
+ export function noFitPolygonsAndInnerFitPolygons (
165
+ nestedPart : Part ,
166
+ notNestedPart : Part ,
167
+ nestingRotationInDegrees : number ,
168
+ raster : boolean ,
169
+ ) : { noFitPolygons : Polygon [ ] ; innerFitPolygons : Polygon [ ] } {
170
+ const rotation = angleNormalize ( nestingRotationInDegrees ) ;
171
+
172
+ return _noFitPolygonsAndInnerFitPolygons (
173
+ partMoveTo ( nestedPart , origin ) ,
174
+ partMoveTo ( partRotate ( partMoveTo ( notNestedPart , origin ) , rotation ) , origin ) ,
175
+ raster ,
176
+ ) ;
147
177
}
0 commit comments