From 1ba9d45b35b63c5d378478606692468f6064c066 Mon Sep 17 00:00:00 2001 From: Orion Elenzil Date: Tue, 22 May 2018 15:48:45 -0700 Subject: [PATCH] unit test for new scale() and scaled() path transformation. tests all current segment types, composite paths, etc --- test/test_path.py | 67 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/test/test_path.py b/test/test_path.py index 8474b26..e9e1914 100644 --- a/test/test_path.py +++ b/test/test_path.py @@ -4,6 +4,7 @@ import unittest from math import sqrt, pi from operator import itemgetter from numpy import poly1d +from numpy import linspace # Internal dependencies from svgpathtools import * @@ -701,6 +702,72 @@ class TestPath(unittest.TestCase): with self.assertRaises(AssertionError): p_open.cropped(1, 0) + def test_transform_scale(self): + line1 = Line(600 + 350j, 650 + 325j) + arc1 = Arc(650 + 325j, 25 + 25j, -30, 0, 1, 700 + 300j) + cub1 = CubicBezier(650 + 325j, 25 + 25j, -30, 700 + 300j) + cub2 = CubicBezier(700 + 300j, 800 + 400j, 750 + 200j, 600 + 100j) + quad3 = QuadraticBezier(600 + 100j, 600, 600 + 300j) + linez = Line(600 + 300j, 600 + 350j) + + bezpath = Path(line1, cub1, cub2, quad3) + bezpathz = Path(line1, cub1, cub2, quad3, linez) + path = Path(line1, arc1, cub2, quad3) + pathz = Path(line1, arc1, cub2, quad3, linez) + lpath = Path(linez) + qpath = Path(quad3) + cpath = Path(cub1) + apath = Path(arc1) + + test_paths = [ + bezpath, + bezpathz, + path, + pathz, + lpath, + qpath, + cpath, + apath, + ] + + for path_orig in test_paths: + + # scale by 2 around (100, 100) + path_trns = path_orig.scaled(2.0, complex(100, 100)) + + # expected length + len_orig = path_orig.length() + len_trns = path_trns.length() + self.assertAlmostEqual(len_orig * 2.0, len_trns) + + # expected positions + for T in linspace(0.0, 1.0, num=100): + pt_orig = path_orig.point(T) + pt_trns = path_trns.point(T) + pt_xpct = (pt_orig - complex(100, 100)) * 2.0 + complex(100, 100) + self.assertAlmostEqual(pt_xpct, pt_trns) + + for path_orig in test_paths: + + # scale by 0.3 around (0, -100) + # the 'almost equal' test fails at the 7th decimal place for some length and position tests here. + path_trns = path_orig.scaled(0.3, complex(0, -100)) + + # expected length + len_orig = path_orig.length() + len_trns = path_trns.length() + self.assertAlmostEqual(len_orig * 0.3, len_trns, delta = 0.000001) + + # expected positions + for T in linspace(0.0, 1.0, num=100): + pt_orig = path_orig.point(T) + pt_trns = path_trns.point(T) + pt_xpct = (pt_orig - complex(0, -100)) * 0.3 + complex(0, -100) + self.assertAlmostEqual(pt_xpct, pt_trns, delta = 0.000001) + + + + class Test_ilength(unittest.TestCase): # See svgpathtools.notes.inv_arclength.py for information on how these