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:
parent
4f1102ac6e
commit
b465dcff75
@ -34,7 +34,7 @@ from fontTools.ttLib.tables.otTables import (
|
||||
VariableInt,
|
||||
)
|
||||
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?
|
||||
@ -534,7 +534,7 @@ class LayerV1ListBuilder:
|
||||
r1 = _to_variable_value(r1)
|
||||
|
||||
# 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, y0 = x0._replace(value=c.centre[0]), y0._replace(value=c.centre[1])
|
||||
|
@ -78,8 +78,8 @@ class Circle:
|
||||
self.centre = _nudge_point(self.centre, direction)
|
||||
|
||||
|
||||
def nudge_start_circle_almost_inside(c0, r0, c1, r1):
|
||||
"""Nudge c0 so it continues to be inside/outside c1 after rounding.
|
||||
def round_start_circle_stable_containment(c0, r0, c1, r1):
|
||||
"""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
|
||||
if the start circle c0 is so close to the end circle c1's perimiter that
|
||||
|
@ -1,7 +1,7 @@
|
||||
from fontTools.ttLib import newTable
|
||||
from fontTools.ttLib.tables import otTables as ot
|
||||
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.errors import ColorLibError
|
||||
import pytest
|
||||
@ -1066,10 +1066,10 @@ class TrickyRadialGradientTest:
|
||||
else:
|
||||
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, 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 (
|
||||
self.circle_inside_circle(r.centre, r.radius, c1, r1, rounded=True)
|
||||
is inside
|
||||
@ -1082,8 +1082,7 @@ class TrickyRadialGradientTest:
|
||||
r0 = 0
|
||||
c1 = (642.99108, 104.70327999999995)
|
||||
r1 = 260.0072
|
||||
result = self.nudge_start_circle_position(c0, r0, c1, r1, inside=True)
|
||||
assert result == ((386, 71), 0)
|
||||
assert self.round_start_circle(c0, r0, c1, r1, inside=True) == ((386, 71), 0)
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"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):
|
||||
assert self.nudge_start_circle_position(c0, r0, c1, r1, inside) == expected
|
||||
assert self.round_start_circle(c0, r0, c1, r1, inside) == expected
|
||||
|
Loading…
x
Reference in New Issue
Block a user