@@ -108,13 +108,20 @@ def pacman(h=0.1, **kwargs):
108
108
return mesh
109
109
110
110
111
- def uniformSquare (N , M = None , ax = 0 , ay = 0 , bx = 1 , by = 1 , crossed = False , preserveLinesHorizontal = [], preserveLinesVertical = []):
112
- if M is None :
113
- M = max (int (np .around ((by - ay )/ (bx - ax )))* N , 2 )
114
- assert N >= 2
115
- assert M >= 2
116
- xVals = np .linspace (ax , bx , N )
117
- yVals = np .linspace (ay , by , M )
111
+ def uniformSquare (N = 2 , M = None , ax = 0 , ay = 0 , bx = 1 , by = 1 , crossed = False , preserveLinesHorizontal = [], preserveLinesVertical = [], xVals = None , yVals = None ):
112
+ if xVals is None :
113
+ assert N is not None
114
+ assert N >= 2
115
+ xVals = np .linspace (ax , bx , N )
116
+ else :
117
+ N = xVals .shape [0 ]
118
+ if yVals is None :
119
+ if M is None :
120
+ M = max (int (np .around ((by - ay )/ (bx - ax )))* N , 2 )
121
+ assert M >= 2
122
+ yVals = np .linspace (ay , by , M )
123
+ else :
124
+ M = yVals .shape [0 ]
118
125
x , y = np .meshgrid (xVals , yVals )
119
126
for yVal in preserveLinesHorizontal :
120
127
assert (yVals - yVal ).min () < 1e-10
@@ -310,96 +317,85 @@ def squareWithInteractions(ax, ay, bx, by,
310
317
if not uniform :
311
318
from . meshConstruction import (circularSegment ,
312
319
line ,
320
+ polygon ,
313
321
transformationRestriction )
314
322
if h is None :
315
323
h = horizon
316
324
bottomLeft = np .array ([ax , ay ])
325
+ bottomRight = np .array ([bx , ay ])
326
+ topRight = np .array ([bx , by ])
327
+ topLeft = np .array ([ax , by ])
328
+
329
+ horizontalOffset = np .array ([horizon , 0. ])
330
+ verticalOffset = np .array ([0. , horizon ])
331
+
317
332
center = np .array ([(ax + bx )/ 2 , (ay + by )/ 2 ])
318
333
319
334
numPointsPerUnitLength = int (np .ceil (1 / h ))
320
335
321
336
assert len (preserveLinesVertical ) == 0 or len (preserveLinesHorizontal ) == 0
322
- if len (preserveLinesVertical )+ len (preserveLinesHorizontal ) > 0 :
323
- preserve = preserveLinesVertical + preserveLinesHorizontal
324
-
325
- c1 = circularSegment (bottomLeft , horizon , np .pi , 3 / 2 * np .pi , numPointsPerUnitLength )
326
-
327
- x1 = preserve [0 ]
328
- c2 = line ((ax , ay ), (x1 , ay ))
329
- for k in range (len (preserve )- 1 ):
330
- x1 = preserve [k ]
331
- x2 = preserve [k + 1 ]
332
- c2 = c2 + line ((x1 , ay ), (x2 , ay ))
333
- x2 = preserve [- 1 ]
334
- c2 = c2 + line ((x2 , ay ), (bx , ay ))
335
- c1 = c1 + (c2 + (0. , - horizon ))
336
- else :
337
- c1 = circularSegment (bottomLeft , horizon , np .pi , 3 / 2 * np .pi , numPointsPerUnitLength )
338
- c2 = line ((ax , ay ), (bx , ay ))
339
- c1 = c1 + (c2 + (0. , - horizon ))
340
- c3 = line ((ax , ay ), (ax , ay - horizon ))
341
- c4 = line ((ax , ay ), (ax - horizon , ay ))
342
- c = c1 + c2 + c3 + c4
343
-
344
- frame = (c + (c * (center , np .pi / 2 )) + (c * (center , np .pi )) + (c * (center , - np .pi / 2 )))
345
-
346
- if len (preserveLinesVertical ) > 0 :
347
- d = line ((0 , ay - horizon ), (0 , ay ))
348
- x1 = preserve [0 ]
349
- d = d + line ((0 , ay ), (0 , x1 ))
350
- for k in range (len (preserve )- 1 ):
351
- x1 = preserve [k ]
352
- x2 = preserve [k + 1 ]
353
- d += line ((0 , x1 ), (0 , x2 ))
354
- x2 = preserve [- 1 ]
355
- d = d + line ((0 , x2 ), (0 , by ))
356
- d = d + line ((0 , by ), (0 , by + horizon ))
357
- for x in preserveLinesVertical :
358
- assert ax <= x <= bx
359
- frame += (d + (x , 0. ))
360
- if len (preserveLinesHorizontal ) > 0 :
361
- d = line ((ax - horizon , 0 ), (ax , 0 ))+ line ((ax , 0 ), (bx , 0 ))+ line ((bx , 0 ), (bx + horizon , 0 ))
362
-
363
- d = line ((ax - horizon , 0 ), (ax , 0 ))
364
- x1 = preserve [0 ]
365
- d = d + line ((ax , 0 ), (x1 , 0 ))
366
- for k in range (len (preserve )- 1 ):
367
- x1 = preserve [k ]
368
- x2 = preserve [k + 1 ]
369
- d += line ((x1 , 0 ), (x2 , 0 ))
370
- x2 = preserve [- 1 ]
371
- d = d + line ((x2 , 0 ), (bx , 0 ))
372
- d = d + line ((bx , 0 ), (bx + horizon , 0 ))
373
-
374
- for y in preserveLinesHorizontal :
375
- assert ay <= y <= by
376
- frame += (d + (0 , y ))
337
+
338
+ lineHorizontal = polygon ([(0. , 0. )] + [(p - ax , 0. ) for p in preserveLinesVertical ] + [(bx - ax , 0. )], doClose = False )
339
+ lineVertical = polygon ([(0. , 0. )] + [(0. , p - ay ) for p in preserveLinesHorizontal ] + [(0. , by - ay )], doClose = False )
340
+
341
+ d1 = (circularSegment (bottomLeft , horizon , np .pi , 1.5 * np .pi , numPointsPerUnitLength ) +
342
+ line (bottomLeft , bottomLeft - horizontalOffset ) +
343
+ line (bottomLeft , bottomLeft - verticalOffset ) +
344
+ (lineHorizontal + bottomLeft )+
345
+ (lineHorizontal + (bottomLeft - verticalOffset )))
346
+
347
+ d2 = (circularSegment (bottomRight , horizon , - 0.5 * np .pi , 0. , numPointsPerUnitLength ) +
348
+ line (bottomRight , bottomRight + horizontalOffset ) +
349
+ line (bottomRight , bottomRight - verticalOffset ) +
350
+ (lineVertical + (bottomRight + horizontalOffset )) +
351
+ (lineVertical + bottomRight ))
352
+
353
+ d3 = (circularSegment (topRight , horizon , 0 , 0.5 * np .pi , numPointsPerUnitLength ) +
354
+ line (topRight , topRight + horizontalOffset ) +
355
+ line (topRight , topRight + verticalOffset ) +
356
+ (lineHorizontal + topLeft ) +
357
+ (lineHorizontal + (topLeft + verticalOffset )))
358
+
359
+ d4 = (circularSegment (topLeft , horizon , 0.5 * np .pi , np .pi , numPointsPerUnitLength ) +
360
+ line (topLeft , topLeft - horizontalOffset ) +
361
+ line (topLeft , topLeft + verticalOffset ) +
362
+ (lineVertical + bottomLeft ) +
363
+ (lineVertical + (bottomLeft - horizontalOffset )))
364
+
365
+ frame = d1 + d2 + d3 + d4
366
+
367
+ frame .holes .append (center )
377
368
378
369
if innerRadius > 0 :
379
370
frame += transformationRestriction (circularSegment (center , innerRadius , 0 , 2 * np .pi , numPointsPerUnitLength ),
380
371
center - (innerRadius , innerRadius ),
381
372
center + (innerRadius , innerRadius ))
382
373
mesh = frame .mesh (max_volume = h ** 2 , min_angle = 30 , ** kwargs )
383
374
else :
384
- frame .holes .append (center )
385
375
mesh = frame .mesh (max_volume = h ** 2 , min_angle = 30 , ** kwargs )
386
376
387
377
eps = 1e-10
388
- N1 = np .logical_and (np .absolute (mesh .vertices_as_array [:, 0 ]- ax ) < eps ,
389
- np .logical_and (mesh .vertices_as_array [:, 1 ] >= ay - eps ,
390
- mesh .vertices_as_array [:, 1 ] <= by + eps )).sum ()
391
- N2 = np .logical_and (np .absolute (mesh .vertices_as_array [:, 0 ]- bx ) < eps ,
392
- np .logical_and (mesh .vertices_as_array [:, 1 ] >= ay - eps ,
393
- mesh .vertices_as_array [:, 1 ] <= by + eps )).sum ()
394
- M1 = np .logical_and (np .absolute (mesh .vertices_as_array [:, 1 ]- ay ) < eps ,
378
+ idx1 = np .logical_and (np .absolute (mesh .vertices_as_array [:, 0 ]- ax ) < eps ,
379
+ np .logical_and (mesh .vertices_as_array [:, 1 ] >= ay - eps ,
380
+ mesh .vertices_as_array [:, 1 ] <= by + eps ))
381
+ idx2 = np .logical_and (np .absolute (mesh .vertices_as_array [:, 0 ]- bx ) < eps ,
382
+ np .logical_and (mesh .vertices_as_array [:, 1 ] >= ay - eps ,
383
+ mesh .vertices_as_array [:, 1 ] <= by + eps ))
384
+ yVals1 = np .sort (mesh .vertices_as_array [idx1 , 1 ])
385
+ yVals2 = np .sort (mesh .vertices_as_array [idx2 , 1 ])
386
+ assert np .allclose (yVals1 , yVals2 ), (yVals1 , yVals2 )
387
+
388
+ idx3 = np .logical_and (np .absolute (mesh .vertices_as_array [:, 1 ]- ay ) < eps ,
395
389
np .logical_and (mesh .vertices_as_array [:, 0 ] >= ax - eps ,
396
- mesh .vertices_as_array [:, 0 ] <= bx + eps )). sum ()
397
- M2 = np .logical_and (np .absolute (mesh .vertices_as_array [:, 1 ]- by ) < eps ,
390
+ mesh .vertices_as_array [:, 0 ] <= bx + eps ))
391
+ idx4 = np .logical_and (np .absolute (mesh .vertices_as_array [:, 1 ]- by ) < eps ,
398
392
np .logical_and (mesh .vertices_as_array [:, 0 ] >= ax - eps ,
399
- mesh .vertices_as_array [:, 0 ] <= bx + eps )).sum ()
400
- assert N1 == N2 , (N1 , N2 )
401
- assert M1 == M2 , (M1 , M2 )
402
- mesh2 = uniformSquare (N = N1 , M = M1 , ax = ax , ay = ay , bx = bx , by = by )
393
+ mesh .vertices_as_array [:, 0 ] <= bx + eps ))
394
+ xVals3 = np .sort (mesh .vertices_as_array [idx3 , 0 ])
395
+ xVals4 = np .sort (mesh .vertices_as_array [idx4 , 0 ])
396
+ assert np .allclose (xVals3 , xVals4 ), (xVals3 , xVals4 )
397
+ mesh2 = uniformSquare (ax = ax , ay = ay , bx = bx , by = by , xVals = xVals3 , yVals = yVals1 )
398
+ mesh2 .plot ()
403
399
mesh = snapMeshes (mesh , mesh2 )
404
400
405
401
location = uninitialized ((mesh .num_vertices ), dtype = INDEX )
0 commit comments