Skip to content

Commit

Permalink
Polyslab plotting for vertices splitting during erosion/dilation
Browse files Browse the repository at this point in the history
  • Loading branch information
weiliangjin2021 authored and momchil-flex committed Apr 23, 2022
1 parent 72f2f84 commit be978ab
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
20 changes: 10 additions & 10 deletions tests/test_sidewall.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def test_max_erosion_polygon():
s = setup_polyslab(vertices, dilation, angle, bounds)
except:
continue
assert np.isclose(minimal_edge_length(s.base_polygon), 0, atol=1e-5)
assert np.isclose(minimal_edge_length(s.base_polygon), 0, atol=1e-4)

# verify it is indeed maximal allowed
dilation = 0.0
Expand All @@ -141,7 +141,7 @@ def test_max_erosion_polygon():
s = setup_polyslab(vertices, dilation, angle, bounds)
except:
continue
assert np.isclose(minimal_edge_length(s.top_polygon), 0, atol=1e-5)
assert np.isclose(minimal_edge_length(s.top_polygon), 0, atol=1e-4)


def test_shift_height():
Expand Down Expand Up @@ -184,7 +184,7 @@ def test_intersection_with_inside():
Lx = 10 # maximal length in x,y direction
for i in range(50):
vertices = convert_valid_polygon(np.random.random((N, 2)) * Lx)
vertices = np.array(vertices).astype("float32")
vertices = np.array(vertices) # .astype("float32")
dilation = 0
angle = 0
bounds = (0, 1)
Expand All @@ -193,7 +193,7 @@ def test_intersection_with_inside():
# set up proper thickness
_, max_dist = s._crossing_detection(s.base_polygon, -100)
dilation = 0.0
bounds = (0, np.float32(max_dist * 0.95))
bounds = (0, (max_dist * 0.95))
angle = np.pi / 4
# avoid vertex-edge crossing case
try:
Expand All @@ -205,9 +205,9 @@ def test_intersection_with_inside():
xp = np.random.random(1)[0] * 2 * Lx - Lx
yp = np.random.random(10) * 2 * Lx - Lx
zp = np.random.random(10) * (bounds[1] - bounds[0]) + bounds[0]
xp = np.float32(xp)
yp = np.float32(yp)
zp = np.float32(zp)
# xp = np.float32(xp)
# yp = np.float32(yp)
# zp = np.float32(zp)
shape_intersect = s.intersections(x=xp)

for i in range(len(yp)):
Expand All @@ -230,9 +230,9 @@ def test_intersection_with_inside():
xp = np.random.random(10) * 2 * Lx - Lx
yp = np.random.random(1)[0] * 2 * Lx - Lx
zp = np.random.random(10) * (bounds[1] - bounds[0]) + bounds[0]
xp = np.float32(xp)
yp = np.float32(yp)
zp = np.float32(zp)
# xp = np.float32(xp)
# yp = np.float32(yp)
# zp = np.float32(zp)
shape_intersect = s.intersections(y=yp)

for i in range(len(xp)):
Expand Down
14 changes: 10 additions & 4 deletions tidy3d/components/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1808,10 +1808,16 @@ def _find_intersecting_ys_angle_slant( # pylint:disable=too-many-locals, too-ma
# the vertex will split into two
ints_y.append(y_on)
ints_y.append(y_on)
slope = (y_on - y_b) / (x_on - x_b)
ints_angle.append(np.pi / 2 - np.arctan(np.abs(slope)))
slope = (y_on - y_f) / (x_on - x_f)
ints_angle.append(np.pi / 2 - np.arctan(np.abs(slope)))

# the order of the two new vertices needs to handled correctly;
# it should be sorted according to the -slope * moving direction
slope = [(y_on - y_b) / (x_on - x_b), (y_on - y_f) / (x_on - x_f)]
dressed_slope = [-s_i * shift_local for s_i in slope]
sort_index = np.argsort(np.array(dressed_slope))
sorted_slope = np.array(slope)[sort_index]

ints_angle.append(np.pi / 2 - np.arctan(np.abs(sorted_slope[0])))
ints_angle.append(np.pi / 2 - np.arctan(np.abs(sorted_slope[1])))
# case 3, one of neightbouring vertices on the plane too:
else:
# now only for angle<np.pi/2, so it's not relevant
Expand Down

0 comments on commit be978ab

Please sign in to comment.