| 1 |
import unittest |
| 2 |
import math |
| 3 |
from random import random |
| 4 |
from fontMath.mathFunctions import _roundNumber |
| 5 |
from fontMath.mathTransform import ( |
| 6 |
Transform, FontMathWarning, matrixToMathTransform, mathTransformToMatrix, |
| 7 |
_polarDecomposeInterpolationTransformation, |
| 8 |
_mathPolarDecomposeInterpolationTransformation, |
| 9 |
_linearInterpolationTransformMatrix |
| 10 |
) |
| 11 |
|
| 12 |
|
| 13 |
class MathTransformToFunctionsTest(unittest.TestCase): |
| 14 |
def __init__(self, methodName): |
| 15 |
unittest.TestCase.__init__(self, methodName) |
| 16 |
|
| 17 |
def test_matrixToTransform(self): |
| 18 |
pass |
| 19 |
|
| 20 |
def test_TransformToMatrix(self): |
| 21 |
pass |
| 22 |
|
| 23 |
|
| 24 |
class ShallowTransformTest(unittest.TestCase): |
| 25 |
def __init__(self, methodName): |
| 26 |
unittest.TestCase.__init__(self, methodName) |
| 27 |
|
| 28 |
|
| 29 |
_testData = [ |
| 30 |
( |
| 31 |
Transform().rotate(math.radians(0)), |
| 32 |
Transform().rotate(math.radians(90)) |
| 33 |
), |
| 34 |
|
| 35 |
( |
| 36 |
Transform().skew(math.radians(60), math.radians(10)), |
| 37 |
Transform().rotate(math.radians(90)) |
| 38 |
), |
| 39 |
|
| 40 |
( |
| 41 |
Transform().scale(.3, 1.3), |
| 42 |
Transform().rotate(math.radians(90)) |
| 43 |
), |
| 44 |
|
| 45 |
( |
| 46 |
Transform().scale(.3, 1.3).rotate(math.radians(-15)), |
| 47 |
Transform().rotate(math.radians(90)).scale(.7, .3) |
| 48 |
), |
| 49 |
|
| 50 |
( |
| 51 |
Transform().translate(250, 250).rotate(math.radians(-15)) |
| 52 |
.translate(-250, -250), |
| 53 |
Transform().translate(0, 400).rotate(math.radians(80)) |
| 54 |
.translate(-100, 0).rotate(math.radians(80)), |
| 55 |
), |
| 56 |
|
| 57 |
( |
| 58 |
Transform().skew(math.radians(50)).scale(1.5).rotate(math.radians(60)), |
| 59 |
Transform().rotate(math.radians(90)) |
| 60 |
), |
| 61 |
] |
| 62 |
|
| 63 |
|
| 64 |
class MathTransformTest(unittest.TestCase): |
| 65 |
def __init__(self, methodName): |
| 66 |
unittest.TestCase.__init__(self, methodName) |
| 67 |
|
| 68 |
|
| 69 |
if not hasattr(self, "assertRaisesRegex"): |
| 70 |
self.assertRaisesRegex = self.assertRaisesRegexp |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
def _wrapUnWrap(self, precision=12): |
| 106 |
""" |
| 107 |
Wrap and unwrap a matrix with random values to establish rounding error |
| 108 |
""" |
| 109 |
t1 = [] |
| 110 |
for i in range(6): |
| 111 |
t1.append(random()) |
| 112 |
m = matrixToMathTransform(t1) |
| 113 |
t2 = mathTransformToMatrix(m) |
| 114 |
|
| 115 |
if not sum([_roundNumber(t1[i] - t2[i], precision) |
| 116 |
for i in range(len(t1))]) == 0: |
| 117 |
raise FontMathWarning( |
| 118 |
"Matrix round-tripping failed for precision value %s." |
| 119 |
% (precision)) |
| 120 |
|
| 121 |
def test_wrapUnWrap(self): |
| 122 |
self._wrapUnWrap() |
| 123 |
|
| 124 |
def test_wrapUnWrapPrecision(self): |
| 125 |
""" |
| 126 |
Wrap and unwrap should have no rounding errors at least up to |
| 127 |
a precision value of 12. |
| 128 |
Rounding errors seem to start occuring at a precision value of 14. |
| 129 |
""" |
| 130 |
for p in range(5, 13): |
| 131 |
for i in range(1000): |
| 132 |
self._wrapUnWrap(p) |
| 133 |
with self.assertRaisesRegex( |
| 134 |
FontMathWarning, |
| 135 |
"Matrix round-tripping failed for precision value"): |
| 136 |
for p in range(14, 16): |
| 137 |
for i in range(1000): |
| 138 |
self._wrapUnWrap(p) |