Blame Tests/misc/bezierTools_test.py

rpm-build 6a2e4c
from __future__ import print_function, division, absolute_import
rpm-build 6a2e4c
from fontTools.misc.py23 import *
rpm-build 6a2e4c
from fontTools.misc.bezierTools import (
rpm-build 6a2e4c
    calcQuadraticBounds, calcCubicBounds, splitLine, splitQuadratic,
rpm-build 6a2e4c
    splitCubic, splitQuadraticAtT, splitCubicAtT, solveCubic)
rpm-build 6a2e4c
import pytest
rpm-build 6a2e4c
rpm-build 6a2e4c
rpm-build 6a2e4c
def test_calcQuadraticBounds():
rpm-build 6a2e4c
    assert calcQuadraticBounds(
rpm-build 6a2e4c
        (0, 0), (50, 100), (100, 0)) == (0, 0, 100, 50.0)
rpm-build 6a2e4c
    assert calcQuadraticBounds(
rpm-build 6a2e4c
        (0, 0), (100, 0), (100, 100)) == (0.0, 0.0, 100, 100)
rpm-build 6a2e4c
rpm-build 6a2e4c
rpm-build 6a2e4c
def test_calcCubicBounds():
rpm-build 6a2e4c
    assert calcCubicBounds(
rpm-build 6a2e4c
        (0, 0), (25, 100), (75, 100), (100, 0)) == ((0, 0, 100, 75.0))
rpm-build 6a2e4c
    assert calcCubicBounds(
rpm-build 6a2e4c
        (0, 0), (50, 0), (100, 50), (100, 100)) == (0.0, 0.0, 100, 100)
rpm-build 6a2e4c
    assert calcCubicBounds(
rpm-build 6a2e4c
        (50, 0), (0, 100), (100, 100), (50, 0)
rpm-build 6a2e4c
    ) == pytest.approx((35.566243, 0.000000, 64.433757, 75.000000))
rpm-build 6a2e4c
rpm-build 6a2e4c
rpm-build 6a2e4c
def test_splitLine():
rpm-build 6a2e4c
    assert splitLine(
rpm-build 6a2e4c
        (0, 0), (100, 100), where=50, isHorizontal=True
rpm-build 6a2e4c
    ) == [((0, 0), (50.0, 50.0)), ((50.0, 50.0), (100, 100))]
rpm-build 6a2e4c
    assert splitLine(
rpm-build 6a2e4c
        (0, 0), (100, 100), where=100, isHorizontal=True
rpm-build 6a2e4c
    ) == [((0, 0), (100, 100))]
rpm-build 6a2e4c
    assert splitLine(
rpm-build 6a2e4c
        (0, 0), (100, 100), where=0, isHorizontal=True
rpm-build 6a2e4c
    ) == [((0, 0), (0, 0)), ((0, 0), (100, 100))]
rpm-build 6a2e4c
    assert splitLine(
rpm-build 6a2e4c
        (0, 0), (100, 100), where=0, isHorizontal=False
rpm-build 6a2e4c
    ) == [((0, 0), (0, 0)), ((0, 0), (100, 100))]
rpm-build 6a2e4c
    assert splitLine(
rpm-build 6a2e4c
        (100, 0), (0, 0), where=50, isHorizontal=False
rpm-build 6a2e4c
    ) == [((100, 0), (50, 0)), ((50, 0), (0, 0))]
rpm-build 6a2e4c
    assert splitLine(
rpm-build 6a2e4c
        (0, 100), (0, 0), where=50, isHorizontal=True
rpm-build 6a2e4c
    ) == [((0, 100), (0, 50)), ((0, 50), (0, 0))]
rpm-build 6a2e4c
    assert splitLine(
rpm-build 6a2e4c
        (0, 100), (100, 100), where=50, isHorizontal=True
rpm-build 6a2e4c
    ) == [((0, 100), (100, 100))]
rpm-build 6a2e4c
rpm-build 6a2e4c
rpm-build 6a2e4c
def assert_curves_approx_equal(actual_curves, expected_curves):
rpm-build 6a2e4c
    assert len(actual_curves) == len(expected_curves)
rpm-build 6a2e4c
    for acurve, ecurve in zip(actual_curves, expected_curves):
rpm-build 6a2e4c
        assert len(acurve) == len(ecurve)
rpm-build 6a2e4c
        for apt, ept in zip(acurve, ecurve):
rpm-build 6a2e4c
            assert apt == pytest.approx(ept)
rpm-build 6a2e4c
rpm-build 6a2e4c
rpm-build 6a2e4c
def test_splitQuadratic():
rpm-build 6a2e4c
    assert splitQuadratic(
rpm-build 6a2e4c
        (0, 0), (50, 100), (100, 0), where=150, isHorizontal=False
rpm-build 6a2e4c
    ) == [((0, 0), (50, 100), (100, 0))]
rpm-build 6a2e4c
    assert splitQuadratic(
rpm-build 6a2e4c
        (0, 0), (50, 100), (100, 0), where=50, isHorizontal=False
rpm-build 6a2e4c
    ) == [((0, 0), (25, 50), (50, 50)),
rpm-build 6a2e4c
          ((50, 50), (75, 50), (100, 0))]
rpm-build 6a2e4c
    assert splitQuadratic(
rpm-build 6a2e4c
        (0, 0), (50, 100), (100, 0), where=25, isHorizontal=False
rpm-build 6a2e4c
    ) == [((0, 0), (12.5, 25), (25, 37.5)),
rpm-build 6a2e4c
          ((25, 37.5), (62.5, 75), (100, 0))]
rpm-build 6a2e4c
    assert_curves_approx_equal(
rpm-build 6a2e4c
        splitQuadratic(
rpm-build 6a2e4c
            (0, 0), (50, 100), (100, 0), where=25, isHorizontal=True),
rpm-build 6a2e4c
        [((0, 0), (7.32233, 14.64466), (14.64466, 25)),
rpm-build 6a2e4c
         ((14.64466, 25), (50, 75), (85.3553, 25)),
rpm-build 6a2e4c
         ((85.3553, 25), (92.6777, 14.64466), (100, -7.10543e-15))])
rpm-build 6a2e4c
    # XXX I'm not at all sure if the following behavior is desirable
rpm-build 6a2e4c
    assert splitQuadratic(
rpm-build 6a2e4c
        (0, 0), (50, 100), (100, 0), where=50, isHorizontal=True
rpm-build 6a2e4c
    ) == [((0, 0), (25, 50), (50, 50)),
rpm-build 6a2e4c
          ((50, 50), (50, 50), (50, 50)),
rpm-build 6a2e4c
          ((50, 50), (75, 50), (100, 0))]
rpm-build 6a2e4c
rpm-build 6a2e4c
rpm-build 6a2e4c
def test_splitCubic():
rpm-build 6a2e4c
    assert splitCubic(
rpm-build 6a2e4c
        (0, 0), (25, 100), (75, 100), (100, 0), where=150, isHorizontal=False
rpm-build 6a2e4c
    ) == [((0, 0), (25, 100), (75, 100), (100, 0))]
rpm-build 6a2e4c
    assert splitCubic(
rpm-build 6a2e4c
        (0, 0), (25, 100), (75, 100), (100, 0), where=50, isHorizontal=False
rpm-build 6a2e4c
    ) == [((0, 0), (12.5, 50), (31.25, 75), (50, 75)),
rpm-build 6a2e4c
          ((50, 75), (68.75, 75), (87.5, 50), (100, 0))]
rpm-build 6a2e4c
    assert_curves_approx_equal(
rpm-build 6a2e4c
        splitCubic(
rpm-build 6a2e4c
            (0, 0), (25, 100), (75, 100), (100, 0), where=25,
rpm-build 6a2e4c
            isHorizontal=True),
rpm-build 6a2e4c
        [((0, 0), (2.293792, 9.17517), (4.798045, 17.5085), (7.47414, 25)),
rpm-build 6a2e4c
         ((7.47414, 25), (31.2886, 91.6667), (68.7114, 91.6667),
rpm-build 6a2e4c
          (92.5259, 25)),
rpm-build 6a2e4c
         ((92.5259, 25), (95.202, 17.5085), (97.7062, 9.17517),
rpm-build 6a2e4c
          (100, 1.77636e-15))])
rpm-build 6a2e4c
rpm-build 6a2e4c
rpm-build 6a2e4c
def test_splitQuadraticAtT():
rpm-build 6a2e4c
    assert splitQuadraticAtT(
rpm-build 6a2e4c
        (0, 0), (50, 100), (100, 0), 0.5
rpm-build 6a2e4c
    ) == [((0, 0), (25, 50), (50, 50)),
rpm-build 6a2e4c
          ((50, 50), (75, 50), (100, 0))]
rpm-build 6a2e4c
    assert splitQuadraticAtT(
rpm-build 6a2e4c
        (0, 0), (50, 100), (100, 0), 0.5, 0.75
rpm-build 6a2e4c
    ) == [((0, 0), (25, 50), (50, 50)),
rpm-build 6a2e4c
          ((50, 50), (62.5, 50), (75, 37.5)),
rpm-build 6a2e4c
          ((75, 37.5), (87.5, 25), (100, 0))]
rpm-build 6a2e4c
rpm-build 6a2e4c
rpm-build 6a2e4c
def test_splitCubicAtT():
rpm-build 6a2e4c
    assert splitCubicAtT(
rpm-build 6a2e4c
        (0, 0), (25, 100), (75, 100), (100, 0), 0.5
rpm-build 6a2e4c
    ) == [((0, 0), (12.5, 50), (31.25, 75), (50, 75)),
rpm-build 6a2e4c
          ((50, 75), (68.75, 75), (87.5, 50), (100, 0))]
rpm-build 6a2e4c
    assert splitCubicAtT(
rpm-build 6a2e4c
        (0, 0), (25, 100), (75, 100), (100, 0), 0.5, 0.75
rpm-build 6a2e4c
    ) == [((0, 0), (12.5, 50), (31.25, 75), (50, 75)),
rpm-build 6a2e4c
          ((50, 75), (59.375, 75), (68.75, 68.75), (77.34375, 56.25)),
rpm-build 6a2e4c
          ((77.34375, 56.25), (85.9375, 43.75), (93.75, 25), (100, 0))]
rpm-build 6a2e4c
rpm-build 6a2e4c
rpm-build 6a2e4c
def test_solveCubic():
rpm-build 6a2e4c
    assert solveCubic(1, 1, -6, 0) == [-3.0, -0.0, 2.0]
rpm-build 6a2e4c
    assert solveCubic(-10.0, -9.0, 48.0, -29.0) == [-2.9, 1.0, 1.0]
rpm-build 6a2e4c
    assert solveCubic(-9.875, -9.0, 47.625, -28.75) == [-2.911392, 1.0, 1.0]
rpm-build 6a2e4c
    assert solveCubic(1.0, -4.5, 6.75, -3.375) == [1.5, 1.5, 1.5]
rpm-build 6a2e4c
    assert solveCubic(-12.0, 18.0, -9.0, 1.50023651123) == [0.5, 0.5, 0.5]
rpm-build 6a2e4c
    assert solveCubic(9.0, 0.0, 0.0, -7.62939453125e-05) == [-0.0, -0.0, -0.0]