Skip to content

Commit 00256a9

Browse files
author
devbisme
committed
Merge branch 'centering' of https://github.com/dnschneid/KiPart into schneider
2 parents 6fc6670 + 7f28ae0 commit 00256a9

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

kipart/kipart.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,11 @@ def gridify(value, grid_spacing=GRID_SPACING, policy="round"):
122122
elif policy == "down":
123123
return math.floor(value / grid_spacing) * grid_spacing
124124
elif policy == "round":
125-
return round(value / grid_spacing) * grid_spacing
125+
# Round from zero (round() does round-to-even which looks bad)
126+
if value > 0:
127+
return math.floor(value / grid_spacing + 0.5) * grid_spacing
128+
else:
129+
return math.ceil(value / grid_spacing - 0.5) * grid_spacing
126130
else:
127131
raise ValueError(
128132
f"Invalid gridify policy '{policy}'. Use 'up', 'down', or 'round'."

0 commit comments

Comments
 (0)