summaryrefslogtreecommitdiff
path: root/gerber/tests/test_primitives.py
diff options
context:
space:
mode:
authorHamilton Kibbe <hamilton.kibbe@gmail.com>2014-10-28 22:11:43 -0400
committerHamilton Kibbe <hamilton.kibbe@gmail.com>2014-10-28 22:11:43 -0400
commitf5abd5b0bdc0b9f524456dc9216bd0f3732e82a0 (patch)
tree896c4398f4ee680a63bd8a29b86cee21b95ec836 /gerber/tests/test_primitives.py
parentb488ab6af9d7925263b2d0712abfd2ba55dc96d2 (diff)
downloadgerbonara-f5abd5b0bdc0b9f524456dc9216bd0f3732e82a0.tar.gz
gerbonara-f5abd5b0bdc0b9f524456dc9216bd0f3732e82a0.tar.bz2
gerbonara-f5abd5b0bdc0b9f524456dc9216bd0f3732e82a0.zip
Add arc rendering and tests
Diffstat (limited to 'gerber/tests/test_primitives.py')
-rw-r--r--gerber/tests/test_primitives.py85
1 files changed, 85 insertions, 0 deletions
diff --git a/gerber/tests/test_primitives.py b/gerber/tests/test_primitives.py
new file mode 100644
index 0000000..29036b4
--- /dev/null
+++ b/gerber/tests/test_primitives.py
@@ -0,0 +1,85 @@
+#! /usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# Author: Hamilton Kibbe <ham@hamiltonkib.be>
+from ..primitives import *
+from tests import *
+
+
+
+def test_line_angle():
+ """ Test Line primitive angle calculation
+ """
+ cases = [((0, 0), (1, 0), math.radians(0)),
+ ((0, 0), (1, 1), math.radians(45)),
+ ((0, 0), (0, 1), math.radians(90)),
+ ((0, 0), (-1, 1), math.radians(135)),
+ ((0, 0), (-1, 0), math.radians(180)),
+ ((0, 0), (-1, -1), math.radians(225)),
+ ((0, 0), (0, -1), math.radians(270)),
+ ((0, 0), (1, -1), math.radians(315)),]
+ for start, end, expected in cases:
+ l = Line(start, end, 0)
+ line_angle = (l.angle + 2 * math.pi) % (2 * math.pi)
+ assert_almost_equal(line_angle, expected)
+
+def test_line_bounds():
+ """ Test Line primitive bounding box calculation
+ """
+ cases = [((0, 0), (1, 1), ((0, 1), (0, 1))),
+ ((-1, -1), (1, 1), ((-1, 1), (-1, 1))),
+ ((1, 1), (-1, -1), ((-1, 1), (-1, 1))),
+ ((-1, 1), (1, -1), ((-1, 1), (-1, 1))),]
+ for start, end, expected in cases:
+ l = Line(start, end, 0)
+ assert_equal(l.bounding_box, expected)
+
+def test_arc_radius():
+ """ Test Arc primitive radius calculation
+ """
+ cases = [((-3, 4), (5, 0), (0, 0), 5),
+ ((0, 1), (1, 0), (0, 0), 1),]
+
+ for start, end, center, radius in cases:
+ a = Arc(start, end, center, 'clockwise', 0)
+ assert_equal(a.radius, radius)
+
+
+def test_arc_sweep_angle():
+ """ Test Arc primitive sweep angle calculation
+ """
+ cases = [((1, 0), (0, 1), (0, 0), 'counterclockwise', math.radians(90)),
+ ((1, 0), (0, 1), (0, 0), 'clockwise', math.radians(270)),
+ ((1, 0), (-1, 0), (0, 0), 'clockwise', math.radians(180)),
+ ((1, 0), (-1, 0), (0, 0), 'counterclockwise', math.radians(180)),]
+
+ for start, end, center, direction, sweep in cases:
+ a = Arc(start, end, center, direction, 0)
+ assert_equal(a.sweep_angle, sweep)
+
+
+def test_arc_bounds():
+ """ Test Arc primitive bounding box calculation
+ """
+ cases = [((1, 0), (0, 1), (0, 0), 'clockwise', ((-1, 1), (-1, 1))),
+ ((1, 0), (0, 1), (0, 0), 'counterclockwise', ((0, 1), (0, 1))),
+ #TODO: ADD MORE TEST CASES HERE
+ ]
+
+ for start, end, center, direction, bounds in cases:
+ a = Arc(start, end, center, direction, 0)
+ assert_equal(a.bounding_box, bounds)
+
+def test_circle_radius():
+ """ Test Circle primitive radius calculation
+ """
+ c = Circle((1, 1), 2)
+ assert_equal(c.radius, 1)
+
+def test_circle_bounds():
+ """ Test Circle bounding box calculation
+ """
+ c = Circle((1, 1), 2)
+ assert_equal(c.bounding_box, ((0, 2), (0, 2)))
+
+