Unable to round some fractional coordinates

Hi,

I am editing Kanji glyphs with lots of nodes and fractional coordinates, which are scanned and traced from brushed drawings. Some of the coordinates are very close to integers, say 100.001 or 329.994.

First, I tried to round them using my Python script but they remained unchanged. Next I put a rounded value into the Info Box in the Edit view, but it didn’t work. Paths > Round Coordinates neither.

After trying several times, I discovered that I can’t update values with delta less than 0.0099. That means the second line in the following code will be no-op:

node.position = NSMakePoint(100.001, 329.994)
node.position = NSMakePoint(100.000, 330.000)
print(node.position)
<NSPoint x=100.001 y=329.994>

If I’m not missing something, I find the behavior is counterintuitive. Is it a design decision or can it be fixed? What would be the best way to round all fractional coordinates to integers?

I’m on an M2 MacBook Air with Mac OS Ventura 13.0 running Glyphs 3.2 (3210).

Thanks for the report. I fixed it. For now, select all and move everything with the cursor keys one unit and back.

1 Like

Thank you Georg! Is the fix due for the next release?

Update is out (as cutting edge).

I can confirm that it works in 3.2.1.(3258).
Thank you for the quick fix!

Sorry for bumping the old thread, but is the issue still relevant when rounding coordinates? I found the following code didn’t work:

import traceback

def case1():
	# The change is applied as expected.
	node = GSNode()
	node.position = NSMakePoint(100.001, 200.0)
	x1, y1 = node.position.x, node.position.y
	node.position = NSMakePoint(100.000, 200.0)
	x2, y2 = node.position.x, node.position.y
	assert x1 != x2, (x1, x2)
	assert y1 == y2, (y1, y2)
	
def case2():
	# The change is not applied for this precision.
	node = GSNode()
	node.position = NSMakePoint(100.0001, 200.0)
	x1, y1 = node.position.x, node.position.y
	node.position = NSMakePoint(100.0000, 200.0)
	x2, y2 = node.position.x, node.position.y
	assert x1 != x2, (x1, x2)
	assert y1 == y2, (y1, y2)

def case3():
	# The method dedicated for rounding doesn't work either.
	node = GSNode()
	node.position = NSMakePoint(100.0001, 200.0)
	x1, y1 = node.position.x, node.position.y
	node.roundToGrid_(1.0)
	x2, y2 = node.position.x, node.position.y
	assert x1 != x2, (x1, x2)
	assert y1 == y2, (y1, y2)

if __name__ == '__main__':
	for case in (case1, case2, case3):
		try:
			case()
		except:
			print(traceback.format_exc())

The assertions for case2() and case3() fail as follows:

Traceback (most recent call last):
  File "<macro panel>", line 36
  File "<macro panel>", line 20, in case2
AssertionError: (100.0001, 100.0001)

Traceback (most recent call last):
  File "<macro panel>", line 36
  File "<macro panel>", line 30, in case3
AssertionError: (100.0001, 100.0001)

Is there a way to reliably update coordinates from a Python script regardless of delta? I suspect such fractional coordinates still occasionally remain after overlap removal.

I slightly decreased the threshold for rounding. So this particular test case would work. But the same with one more factional digit would fail again.
All fractional below 0.001 are ignored on export anyway (fraction coordinates are only written out for 1/100 of a unit) so those small values could be ignored.