Skip to content

Commit 48831eb

Browse files
committed
o intersections: collapse pos/neg-valid branches via XOR in gca_const_lat_intersection
1 parent 9d88f83 commit 48831eb

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

uxarray/grid/intersections.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -676,18 +676,20 @@ def gca_const_lat_intersection(gca_cart, const_z):
676676

677677
px, py, nx, ny = _accux_constlat_scalar(a0, a1, a2, b0, b1, b2, const_z)
678678

679-
pos_fin = math.isfinite(px) and math.isfinite(py)
680-
neg_fin = math.isfinite(nx) and math.isfinite(ny)
681-
pos_valid = pos_fin and _on_minor_arc_xyz(px, py, const_z, a0, a1, a2, b0, b1, b2)
682-
neg_valid = neg_fin and _on_minor_arc_xyz(nx, ny, const_z, a0, a1, a2, b0, b1, b2)
683-
684-
if pos_valid and not neg_valid:
685-
sx, sy = _snap_const_lat_endpoint_xy(px, py, a0, a1, a2, b0, b1, b2, const_z)
686-
res[0, 0] = sx
687-
res[0, 1] = sy
688-
res[0, 2] = const_z
689-
elif neg_valid and not pos_valid:
690-
sx, sy = _snap_const_lat_endpoint_xy(nx, ny, a0, a1, a2, b0, b1, b2, const_z)
679+
pos_fin = int(math.isfinite(px)) * int(math.isfinite(py))
680+
neg_fin = int(math.isfinite(nx)) * int(math.isfinite(ny))
681+
pos_valid = pos_fin * _on_minor_arc_xyz(px, py, const_z, a0, a1, a2, b0, b1, b2)
682+
neg_valid = neg_fin * _on_minor_arc_xyz(nx, ny, const_z, a0, a1, a2, b0, b1, b2)
683+
684+
if pos_valid ^ neg_valid:
685+
if pos_valid:
686+
sx, sy = _snap_const_lat_endpoint_xy(
687+
px, py, a0, a1, a2, b0, b1, b2, const_z
688+
)
689+
else:
690+
sx, sy = _snap_const_lat_endpoint_xy(
691+
nx, ny, a0, a1, a2, b0, b1, b2, const_z
692+
)
691693
res[0, 0] = sx
692694
res[0, 1] = sy
693695
res[0, 2] = const_z

0 commit comments

Comments
 (0)