File: test_transformation.py

package info (click to toggle)
python-beziers 0.6.0%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 672 kB
  • sloc: python: 3,160; makefile: 20
file content (46 lines) | stat: -rw-r--r-- 1,269 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import unittest
from beziers.point import Point
from beziers.cubicbezier import CubicBezier
from beziers.affinetransformation import AffineTransformation
import math

class AffineTransformationMethods(unittest.TestCase):
  def test_translate(self):
    p = Point(30,70)
    p.rotate(Point(0,0), math.pi/4)
    self.assertEqual(p.x, -28.284271247461906)
    self.assertEqual(p.y, 70.71067811865476)

    p = Point(30,70)
    m = AffineTransformation.rotation(math.pi/4)
    p.transform(m)
    self.assertAlmostEqual(p.x, -28.284271247461906)
    self.assertAlmostEqual(p.y, 70.71067811865476)

    p = Point(0,10)
    m = AffineTransformation.translation(Point(5,-2))
    p.transform(m)
    self.assertEqual(p.x, 5)
    self.assertEqual(p.y, 8)

  def test_scale(self):
    p = Point(4,5)
    m = AffineTransformation.scaling(2)
    p.transform(m)
    self.assertEqual(p.x, 8)
    self.assertEqual(p.y, 10)

    p = Point(4,5)
    m = AffineTransformation.scaling(1.5, -2)
    p.transform(m)
    self.assertEqual(p.x, 6)
    self.assertEqual(p.y, -10)

  def test_multiple_application(self):
    p = Point(10,10)
    m = AffineTransformation()
    m.translate(Point(6,5))
    m.scale(1.5,2)
    p.transform(m)
    self.assertEqual(p.x, 24)
    self.assertEqual(p.y, 30)