rename function to round_start_circle_stable_containment

as suggested in https://github.com/fonttools/fonttools/pull/2148#discussion_r557656073
This commit is contained in:
Cosimo Lupo 2021-01-15 17:37:11 +00:00
parent 4f1102ac6e
commit b465dcff75
No known key found for this signature in database
GPG Key ID: 179A8F0895A02F4F
3 changed files with 9 additions and 10 deletions

View File

@ -34,7 +34,7 @@ from fontTools.ttLib.tables.otTables import (
VariableInt, VariableInt,
) )
from .errors import ColorLibError from .errors import ColorLibError
from .geometry import nudge_start_circle_almost_inside from .geometry import round_start_circle_stable_containment
# TODO move type aliases to colorLib.types? # TODO move type aliases to colorLib.types?
@ -534,7 +534,7 @@ class LayerV1ListBuilder:
r1 = _to_variable_value(r1) r1 = _to_variable_value(r1)
# avoid abrupt change after rounding when c0 is near c1's perimeter # avoid abrupt change after rounding when c0 is near c1's perimeter
c = nudge_start_circle_almost_inside( c = round_start_circle_stable_containment(
(x0.value, y0.value), r0.value, (x1.value, y1.value), r1.value (x0.value, y0.value), r0.value, (x1.value, y1.value), r1.value
) )
x0, y0 = x0._replace(value=c.centre[0]), y0._replace(value=c.centre[1]) x0, y0 = x0._replace(value=c.centre[0]), y0._replace(value=c.centre[1])

View File

@ -78,8 +78,8 @@ class Circle:
self.centre = _nudge_point(self.centre, direction) self.centre = _nudge_point(self.centre, direction)
def nudge_start_circle_almost_inside(c0, r0, c1, r1): def round_start_circle_stable_containment(c0, r0, c1, r1):
"""Nudge c0 so it continues to be inside/outside c1 after rounding. """Round start circle so that it stays inside/outside end circle after rounding.
The rounding of circle coordinates to integers may cause an abrupt change The rounding of circle coordinates to integers may cause an abrupt change
if the start circle c0 is so close to the end circle c1's perimiter that if the start circle c0 is so close to the end circle c1's perimiter that

View File

@ -1,7 +1,7 @@
from fontTools.ttLib import newTable from fontTools.ttLib import newTable
from fontTools.ttLib.tables import otTables as ot from fontTools.ttLib.tables import otTables as ot
from fontTools.colorLib import builder from fontTools.colorLib import builder
from fontTools.colorLib.geometry import nudge_start_circle_almost_inside, Circle from fontTools.colorLib.geometry import round_start_circle_stable_containment, Circle
from fontTools.colorLib.builder import LayerV1ListBuilder from fontTools.colorLib.builder import LayerV1ListBuilder
from fontTools.colorLib.errors import ColorLibError from fontTools.colorLib.errors import ColorLibError
import pytest import pytest
@ -1066,10 +1066,10 @@ class TrickyRadialGradientTest:
else: else:
return Circle(c0, r0).inside(Circle(c1, r1)) return Circle(c0, r0).inside(Circle(c1, r1))
def nudge_start_circle_position(self, c0, r0, c1, r1, inside=True): def round_start_circle(self, c0, r0, c1, r1, inside=True):
assert self.circle_inside_circle(c0, r0, c1, r1) is inside assert self.circle_inside_circle(c0, r0, c1, r1) is inside
assert self.circle_inside_circle(c0, r0, c1, r1, rounded=True) is not inside assert self.circle_inside_circle(c0, r0, c1, r1, rounded=True) is not inside
r = nudge_start_circle_almost_inside(c0, r0, c1, r1) r = round_start_circle_stable_containment(c0, r0, c1, r1)
assert ( assert (
self.circle_inside_circle(r.centre, r.radius, c1, r1, rounded=True) self.circle_inside_circle(r.centre, r.radius, c1, r1, rounded=True)
is inside is inside
@ -1082,8 +1082,7 @@ class TrickyRadialGradientTest:
r0 = 0 r0 = 0
c1 = (642.99108, 104.70327999999995) c1 = (642.99108, 104.70327999999995)
r1 = 260.0072 r1 = 260.0072
result = self.nudge_start_circle_position(c0, r0, c1, r1, inside=True) assert self.round_start_circle(c0, r0, c1, r1, inside=True) == ((386, 71), 0)
assert result == ((386, 71), 0)
@pytest.mark.parametrize( @pytest.mark.parametrize(
"c0, r0, c1, r1, inside, expected", "c0, r0, c1, r1, inside, expected",
@ -1105,4 +1104,4 @@ class TrickyRadialGradientTest:
], ],
) )
def test_nudge_start_circle_position(self, c0, r0, c1, r1, inside, expected): def test_nudge_start_circle_position(self, c0, r0, c1, r1, inside, expected):
assert self.nudge_start_circle_position(c0, r0, c1, r1, inside) == expected assert self.round_start_circle(c0, r0, c1, r1, inside) == expected