Skip to content

Commit

Permalink
fix: point_in_polygon
Browse files Browse the repository at this point in the history
fix: computation order
  • Loading branch information
BillHuang2001 committed Oct 13, 2023
1 parent a698f67 commit 415c723
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/evox/problems/numerical/maf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

@jit
def inside(x, a, b):
"""check if x is in [a, b) or (b, a]"""
return ((a <= x) & (x < b)) | ((b < x) & (x <= a))
"""check if x is in [a, b) or [b, a)"""
return (jnp.minimum(a, b) <= x) & (x < jnp.maximum(a, b))


@jit
Expand Down
10 changes: 6 additions & 4 deletions tests/test_maf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def test_inside():
assert inside(8.5, 0.0, 1.0) == False
assert inside(0.5, 0.0, 1.0) == True
assert inside(0.5, 1.0, 0.0) == True
assert inside(1.0, 1.0, 0.0) == True
assert inside(0.0, 1.0, 0.0) == False
assert inside(1.0, 1.0, 0.0) == False
assert inside(0.0, 1.0, 0.0) == True
assert inside(1.0, 0.0, 1.0) == False
assert inside(0.0, 0.0, 1.0) == True

Expand All @@ -27,9 +27,9 @@ def test_ray_intersect_segment():
assert ray_intersect_segment(point, jnp.array([1.0, 1.0]), jnp.array([1.0, 2.0])) == False
assert ray_intersect_segment(point, jnp.array([1.0, 1.0]), jnp.array([-1.0, -1.0])) == True
assert ray_intersect_segment(point, jnp.array([1.0, 1.0]), jnp.array([1.0, -1.0])) == True
assert ray_intersect_segment(point, jnp.array([1.0, 0.0]), jnp.array([1.0, -1.0])) == True
assert ray_intersect_segment(point, jnp.array([1.0, 0.0]), jnp.array([1.0, -1.0])) == False
assert ray_intersect_segment(point, jnp.array([1.0, 0.0]), jnp.array([1.0, 1.0])) == True
assert ray_intersect_segment(point, jnp.array([1.0, 1.0]), jnp.array([1.0, 0.0])) == False
assert ray_intersect_segment(point, jnp.array([1.0, 1.0]), jnp.array([1.0, 0.0])) == True

def test_point_in_polygon():
polygon = jnp.array([
Expand All @@ -43,6 +43,8 @@ def test_point_in_polygon():
assert point_in_polygon(polygon, point) == False
point = jnp.array([0, 1.0])
assert point_in_polygon(polygon, point) == True
point = jnp.array([-1, 1.0])
assert point_in_polygon(polygon, point) == False

def test_maf1():
prob = MaF1(d=d, m=m)
Expand Down

0 comments on commit 415c723

Please sign in to comment.