Skip to content

Commit

Permalink
Black tests
Browse files Browse the repository at this point in the history
  • Loading branch information
simoncozens committed Jun 11, 2024
1 parent 784eec3 commit 7b4c571
Show file tree
Hide file tree
Showing 12 changed files with 482 additions and 486 deletions.
32 changes: 11 additions & 21 deletions test/test_arclength.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,17 @@
from beziers.cubicbezier import CubicBezier
from beziers.point import Point


class ArcLengthMethods(unittest.TestCase):
def test_quadraticLength(self):
b1 = QuadraticBezier(
Point(150,40),
Point(80,30),
Point(105,150)
)
self.assertAlmostEqual(b1.length, 144.79561403359523)
def test_quadraticLength(self):
b1 = QuadraticBezier(Point(150, 40), Point(80, 30), Point(105, 150))
self.assertAlmostEqual(b1.length, 144.79561403359523)

b2 = QuadraticBezier(
Point(707,596),
Point(645,596),
Point(592,623)
)
self.assertAlmostEqual(b2.length, 119.25113694489232)
b2 = QuadraticBezier(Point(707, 596), Point(645, 596), Point(592, 623))
self.assertAlmostEqual(b2.length, 119.25113694489232)

def test_cubicLength(self):
b1 = CubicBezier(
Point(100,25),
Point(10,90),
Point(110,100),
Point(132,192)
)
self.assertAlmostEqual(b1.length, 202.20118972656385)
def test_cubicLength(self):
b1 = CubicBezier(
Point(100, 25), Point(10, 90), Point(110, 100), Point(132, 192)
)
self.assertAlmostEqual(b1.length, 202.20118972656385)
28 changes: 15 additions & 13 deletions test/test_booleanshapeoperations.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@
from beziers.point import Point
from beziers.path.geometricshapes import Circle, Square


class BooleanShapeOperations(unittest.TestCase):
def drawIt(self, s,c,paths):
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
s.plot(ax,drawNodes=False)
c.plot(ax)
for p in paths:
p.plot(ax,drawNodes=False,color="red")
plt.show()
def drawIt(self, s, c, paths):
import matplotlib.pyplot as plt

fig, ax = plt.subplots()
s.plot(ax, drawNodes=False)
c.plot(ax)
for p in paths:
p.plot(ax, drawNodes=False, color="red")
plt.show()

def not_a_test_square_circle_union(self):
subject = Square(10, origin=Point(5,5))
clip = Circle(10, origin=Point(15,15))
paths = subject.union(clip)
self.drawIt(subject,clip,paths)
def not_a_test_square_circle_union(self):
subject = Square(10, origin=Point(5, 5))
clip = Circle(10, origin=Point(15, 15))
paths = subject.union(clip)
self.drawIt(subject, clip, paths)
38 changes: 19 additions & 19 deletions test/test_bounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
from beziers.point import Point
from beziers.boundingbox import BoundingBox


class BBoxMethods(unittest.TestCase):
def test_overlap(self):
b1 = BoundingBox()
b2 = BoundingBox()
b1.extend(Point(5,5))
b1.extend(Point(10,10))
b2.extend(Point(7,7))
b2.extend(Point(14,14))
print("%s v %s" % (b1,b2))
self.assertTrue(b1.overlaps(b2))
self.assertTrue(b2.overlaps(b1))
def test_overlap(self):
b1 = BoundingBox()
b2 = BoundingBox()
b1.extend(Point(5, 5))
b1.extend(Point(10, 10))
b2.extend(Point(7, 7))
b2.extend(Point(14, 14))
print("%s v %s" % (b1, b2))
self.assertTrue(b1.overlaps(b2))
self.assertTrue(b2.overlaps(b1))

def test_quadratic_bounds(self):
# console.log((new Bezier(150,40,80,30,105,150)).bbox())
q = QuadraticBezier(
Point(150,40), Point(80,30), Point(105,150))
b = q.bounds()
self.assertAlmostEqual(b.bl.x,98.42105263157895)
self.assertAlmostEqual(b.tr.x,150)
self.assertAlmostEqual(b.bl.y,39.23076923076923)
self.assertAlmostEqual(b.tr.y,150)
def test_quadratic_bounds(self):
# console.log((new Bezier(150,40,80,30,105,150)).bbox())
q = QuadraticBezier(Point(150, 40), Point(80, 30), Point(105, 150))
b = q.bounds()
self.assertAlmostEqual(b.bl.x, 98.42105263157895)
self.assertAlmostEqual(b.tr.x, 150)
self.assertAlmostEqual(b.bl.y, 39.23076923076923)
self.assertAlmostEqual(b.tr.y, 150)
31 changes: 16 additions & 15 deletions test/test_corners.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
from beziers.point import Point
from beziers.path.representations.Nodelist import NodelistRepresentation, Node


class CornerMethods(unittest.TestCase):
def test_corners(self):
nl = [
Node(302.0,492.0,"line"),
Node(176.0,432.0,"line"),
Node(-51.0,325.0,"offcurve"),
Node(-74.0,484.0,"offcurve"),
Node(73.0,570.0,"curve"),
Node(85.0,764.0,"offcurve"),
Node(290.0,748.0,"offcurve"),
Node(418.0,688.0,"curve"),
]
path = BezierPath.fromNodelist(nl)
path.closed = False
for seg1, seg2 in path.segpairs():
print(seg1.endAngle * 57.2958, seg2.startAngle * 57.2958)
def test_corners(self):
nl = [
Node(302.0, 492.0, "line"),
Node(176.0, 432.0, "line"),
Node(-51.0, 325.0, "offcurve"),
Node(-74.0, 484.0, "offcurve"),
Node(73.0, 570.0, "curve"),
Node(85.0, 764.0, "offcurve"),
Node(290.0, 748.0, "offcurve"),
Node(418.0, 688.0, "curve"),
]
path = BezierPath.fromNodelist(nl)
path.closed = False
for seg1, seg2 in path.segpairs():
print(seg1.endAngle * 57.2958, seg2.startAngle * 57.2958)
96 changes: 47 additions & 49 deletions test/test_cubic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,56 @@
from beziers.point import Point
from beziers.path import BezierPath

class CubicMethods(unittest.TestCase):
def test_extremes(self):
q = CubicBezier(
Point(65,59), Point(194,90), Point(220,260), Point(70,261)
)
# console.log(Bezier(65,59, 194,90, 220,260, 70,261).extrema())
r = q.findExtremes()
self.assertEqual(len(r), 1)
self.assertAlmostEqual(r[0], 0.5275787707261016)
r = q.findExtremes(inflections = True)
self.assertEqual(len(r), 2)
self.assertAlmostEqual(r[0], 0.4512987012987013)
self.assertAlmostEqual(r[1], 0.5275787707261016)

class CubicMethods(unittest.TestCase):
def test_extremes(self):
q = CubicBezier(Point(65, 59), Point(194, 90), Point(220, 260), Point(70, 261))
# console.log(Bezier(65,59, 194,90, 220,260, 70,261).extrema())
r = q.findExtremes()
self.assertEqual(len(r), 1)
self.assertAlmostEqual(r[0], 0.5275787707261016)
r = q.findExtremes(inflections=True)
self.assertEqual(len(r), 2)
self.assertAlmostEqual(r[0], 0.4512987012987013)
self.assertAlmostEqual(r[1], 0.5275787707261016)

def test_length(self):
q = CubicBezier(
Point(120,160), Point(35,200), Point(220,260), Point(220,40)
)
self.assertAlmostEqual(q.length,272.87003168)
def test_length(self):
q = CubicBezier(
Point(120, 160), Point(35, 200), Point(220, 260), Point(220, 40)
)
self.assertAlmostEqual(q.length, 272.87003168)

def test_align(self):
q = CubicBezier(
Point(120,160), Point(35,200), Point(220,260), Point(220,40)
)
s = q.aligned()
self.assertAlmostEqual(s[0].x,0.0)
self.assertAlmostEqual(s[0].y,0.0)
self.assertAlmostEqual(s[1].x,-85.14452515537582)
self.assertAlmostEqual(s[1].y,-39.69143277919774)
self.assertAlmostEqual(s[2].x,-12.803687993289572)
self.assertAlmostEqual(s[2].y,140.84056792618557)
self.assertAlmostEqual(s[3].x,156.2049935181331)
self.assertAlmostEqual(s[3].y,0.0)
def test_align(self):
q = CubicBezier(
Point(120, 160), Point(35, 200), Point(220, 260), Point(220, 40)
)
s = q.aligned()
self.assertAlmostEqual(s[0].x, 0.0)
self.assertAlmostEqual(s[0].y, 0.0)
self.assertAlmostEqual(s[1].x, -85.14452515537582)
self.assertAlmostEqual(s[1].y, -39.69143277919774)
self.assertAlmostEqual(s[2].x, -12.803687993289572)
self.assertAlmostEqual(s[2].y, 140.84056792618557)
self.assertAlmostEqual(s[3].x, 156.2049935181331)
self.assertAlmostEqual(s[3].y, 0.0)

def test_curvature(self):
q = CubicBezier(
Point(122,102), Point(35,200), Point(228,145), Point(190,46)
)
self.assertAlmostEqual(q.curvatureAtTime(0.5),-103450.5)
def test_curvature(self):
q = CubicBezier(
Point(122, 102), Point(35, 200), Point(228, 145), Point(190, 46)
)
self.assertAlmostEqual(q.curvatureAtTime(0.5), -103450.5)

def test_loop(self):
q = CubicBezier(
Point(171,272), Point(388,249), Point(167,444), Point(388,176)
)
self.assertTrue(not q.hasLoop)
def test_loop(self):
q = CubicBezier(
Point(171, 272), Point(388, 249), Point(167, 444), Point(388, 176)
)
self.assertTrue(not q.hasLoop)

q = CubicBezier(
Point(171,272), Point(595,249), Point(167,444), Point(388,176)
)
roots = q.hasLoop
p1 = q.pointAtTime(roots[0])
p2 = q.pointAtTime(roots[1])
self.assertTrue(q.hasLoop)
self.assertEqual(p1,p2)
q = CubicBezier(
Point(171, 272), Point(595, 249), Point(167, 444), Point(388, 176)
)
roots = q.hasLoop
p1 = q.pointAtTime(roots[0])
p2 = q.pointAtTime(roots[1])
self.assertTrue(q.hasLoop)
self.assertEqual(p1, p2)
96 changes: 48 additions & 48 deletions test/test_curvefit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,54 @@
from beziers.path import BezierPath
from beziers.point import Point


class CurveFitterMethods(unittest.TestCase):
def test_cf1(self):
nodes = [
Point(122,102), Point(35,200), Point(228,145), Point(190,46)
]
t = CurveFit._leftTangent(nodes)
self.assertAlmostEqual(t.x, -0.663890062102)
self.assertAlmostEqual(t.y,0.747830184896)
t = CurveFit._rightTangent(nodes)
self.assertAlmostEqual(t.x,-0.3583470773350791)
self.assertAlmostEqual(t.y, -0.9335884383203376)
def test_cf1(self):
nodes = [Point(122, 102), Point(35, 200), Point(228, 145), Point(190, 46)]
t = CurveFit._leftTangent(nodes)
self.assertAlmostEqual(t.x, -0.663890062102)
self.assertAlmostEqual(t.y, 0.747830184896)
t = CurveFit._rightTangent(nodes)
self.assertAlmostEqual(t.x, -0.3583470773350791)
self.assertAlmostEqual(t.y, -0.9335884383203376)

def test_cf2(self):
nodes = [
Point(100, 50),
Point(50, 150),
Point(100, 220),
Point(200, 200),
Point(250, 80),
Point(220, 50),
]
path = BezierPath.fromPoints(nodes)
segs = path.asSegments()
self.assertEqual(len(segs), 2)
self.assertEqual(segs[0].start, Point(100.0, 50.0))
self.assertAlmostEqual(segs[0][1].x, 83.333333333)
self.assertAlmostEqual(segs[0][1].y, 83.333333333)
self.assertEqual(segs[0].end, Point(50.0, 150.0))
self.assertAlmostEqual(segs[1][1].x, 50)
self.assertEqual(segs[1].end, Point(220.0, 50.0))

def test_cf2(self):
nodes = [
Point(100,50),
Point(50,150),
Point(100,220),
Point(200,200),
Point(250,80),
Point(220,50)
]
path = BezierPath.fromPoints(nodes)
segs = path.asSegments()
self.assertEqual(len(segs),2)
self.assertEqual(segs[0].start, Point(100.0, 50.0))
self.assertAlmostEqual(segs[0][1].x, 83.333333333)
self.assertAlmostEqual(segs[0][1].y, 83.333333333)
self.assertEqual(segs[0].end, Point(50.0, 150.0))
self.assertAlmostEqual(segs[1][1].x, 50)
self.assertEqual(segs[1].end, Point(220.0, 50.0))
def not_a_test_cf3(self):
import matplotlib.pyplot as plt
import math

def not_a_test_cf3(self):
import matplotlib.pyplot as plt
import math
fig, ax = plt.subplots()
points = [
Point(100,50),
Point(50,150),
Point(150,250),
Point(200,220),
Point(250,80),
Point(220,50)
]
path = BezierPath.fromPoints(points)
centroid = path.bounds().centroid
path.rotate(centroid, math.pi/2)
path.balance()
path.plot(ax)
path.offset(Point(5,5)).plot(ax, color="red")
path.offset(Point(-5,-5)).plot(ax, color="green")
plt.show()
fig, ax = plt.subplots()
points = [
Point(100, 50),
Point(50, 150),
Point(150, 250),
Point(200, 220),
Point(250, 80),
Point(220, 50),
]
path = BezierPath.fromPoints(points)
centroid = path.bounds().centroid
path.rotate(centroid, math.pi / 2)
path.balance()
path.plot(ax)
path.offset(Point(5, 5)).plot(ax, color="red")
path.offset(Point(-5, -5)).plot(ax, color="green")
plt.show()
Loading

0 comments on commit 7b4c571

Please sign in to comment.