Skip to content

Commit

Permalink
fix(network): Ensure negative coords less than tol read as 0 and not -0
Browse files Browse the repository at this point in the history
It seems like the "signed zero" issue is a little more complex than I thought given that you can have coordinate values like -0.002 and +0.002. Both of these should get a value of 0 in their coordinates hash if the tolerance is 0.01. But one will get a singed zero (-0) unless we do an extra check for this.
  • Loading branch information
chriswmackey committed Oct 3, 2024
1 parent 87c2c67 commit 6bedfb0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions ladybug_geometry/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ def coordinates_hash(point, tolerance):
else: # tolerance is not base 10 (eg. 0.003)
rtol += 1
# avoid cases of signed zeros messing with the hash
x_val = 0.0 if point.x == 0 else point.x
y_val = 0.0 if point.y == 0 else point.y
z_tol = tolerance / 2
x_val = 0.0 if abs(point.x) < z_tol else point.x
y_val = 0.0 if abs(point.y) < z_tol else point.y
# convert the coordinate values to a hash
return str((
base * round(x_val / base, rtol),
Expand Down Expand Up @@ -277,7 +278,7 @@ def from_shape_to_split(cls, boundary, holes, split_segments, tolerance):

# add the intersection segments to the graph
for seg in split_seg: # add a bidirectional edge to represent interior edges
dg.add_node(seg.p2, [seg.p1])
dg.add_node(seg.p2, [seg.p1], exterior=False)
dg.add_node(seg.p1, [seg.p2], exterior=False)
return dg

Expand Down

0 comments on commit 6bedfb0

Please sign in to comment.