def test_Line_length(self): a = xyz.Line(xyz.XY(0, 0), xyz.XY(1, 1)) self.assertEqual(a.length, Decimal('1.414')) a = xyz.Line(xyz.XY(1, -3), xyz.XY(-5, -7)) self.assertEqual(a.length, Decimal('7.211')) self.assertEqual(list(a.points), [xyz.XY(1, -3), xyz.XY(-5, -7)])
def test_Line_bisections(self): a = xyz.Line(xyz.XY(0, 0), xyz.XY(4, 5)) self.assertEqual(a.middle, xyz.XY(2, 2.5)) self.assertEqual(a.top, xyz.Line(xyz.XY(2, 2.5), xyz.XY(4, 5))) self.assertEqual(a.bottom, xyz.Line(xyz.XY(0, 0), xyz.XY(2, 2.5))) self.assertEqual(a.xybisector, xyz.Line(xyz.XY(-0.499, 4.499), xyz.XY(4.5, 0.5)))
def test_Line_sort(self): a = xyz.XY(0, 0) b = xyz.XY(3, 0) c = xyz.XY(3, 4) AB = xyz.Line(a, b) BC = xyz.Line(b, c) AC = xyz.Line(a, c) good = [AB, BC, AC] for abc in ([AB, BC, AC], [AB, AC, BC], [BC, AB, AC], [BC, AC, AB], [AC, AB, BC], [AC, BC, AB]): abc.sort() self.assertEqual(good, abc)
def test_RightTriangle_angles(self): a = xyz.XY(0,0) b = xyz.XY(3,0) c = xyz.XY(3,3) for abc in ((a,b,c), (a,c,b), (b,a,c), (b,c,a), (c,a,b), (c,b,a)): t = shapes.RightTriangle(abc[0], abc[1], abc[2]) self.assertTrue(t.a in [xyz.Line(xyz.XY(0,0), xyz.XY(3,0)), xyz.Line(xyz.XY(3,0), xyz.XY(3,3))]) self.assertEqual(t.b, xyz.Line(xyz.XY(0,0), xyz.XY(3,3))) self.assertTrue(t.c in [xyz.Line(xyz.XY(0,0), xyz.XY(3,0)), xyz.Line(xyz.XY(3,0), xyz.XY(3,3))]) self.assertTrue(t.b.length >= t.a.length) self.assertTrue(t.b.length >= t.c.length) self.assertTrue(t.a.length >= t.c.length) self.assertEqual(t.a.length, 3) self.assertEqual(t.b.length, Decimal('4.243')) self.assertEqual(t.c.length, 3) self.assertEqual(t.BAC, 45) self.assertEqual(t.ABC, 90) self.assertEqual(t.ACB, 45) self.assertEqual(t.Bmid, xyz.XY(1.5, 1.5)) a = xyz.XY(0,0) b = xyz.XY(3,0) c = xyz.XY(3,4) AB = xyz.Line(a,b) AC = xyz.Line(a,c) BC = xyz.Line(b,c) for abc in ((a,b,c), (a,c,b), (b,a,c), (b,c,a), (c,a,b), (c,b,a)): t = shapes.RightTriangle(abc[0], abc[1], abc[2]) self.assertTrue(t.a in [BC, BC.reverse]) self.assertEqual(t.b, AC) self.assertTrue(t.c in [AB, AB.reverse]) self.assertTrue(t.b.length >= t.a.length) self.assertTrue(t.b.length >= t.c.length) self.assertTrue(t.a.length >= t.c.length) self.assertEqual(t.a.length, 4) self.assertEqual(t.b.length, 5) self.assertEqual(t.c.length, 3) self.assertEqual(t.BAC, Decimal('36.87')) self.assertEqual(t.ABC, 90) self.assertEqual(t.ACB, Decimal('53.13000')) self.assertEqual(t.Bmid, xyz.XY(1.5, 2))
def test_Line_atD(self): a = xyz.Line(xyz.XY(0, 0), xyz.XY(4, 5)) d = a.length * 2 self.assertNotEqual(a.atD(d), xyz.XY(7, 10)) self.assertEqual(a.atD(d), xyz.XY(8, 10)) self.assertNotEqual(a.atD(d), xyz.XY(9, 10)) d = 0 - d self.assertNotEqual(a.atD(d), xyz.XY(-7, -10)) self.assertEqual(a.atD(d), xyz.XY(-8, -10)) self.assertNotEqual(a.atD(d), xyz.XY(-9, -10))
def test_Line_xyBLAH(self): a = xyz.Line(xyz.XY(0, 0), xyz.XY(4, 5)) self.assertEqual(a.xyb, 0) self.assertEqual(a.xym, 1.25) self.assertEqual(a.xybisector.xyb, Decimal("4.1")) self.assertEqual(a.xybisector.xym, Decimal("-0.8")) self.assertEqual(a.xyYAtX(-4), -5) self.assertEqual(a.xyYAtX(0), 0) self.assertEqual(a.xyYAtX(2), 2.5) self.assertEqual(a.xyYAtX(4), 5) self.assertEqual(a.xyYAtX(8), 10) self.assertEqual(a.xyXAtY(-5), -4) self.assertEqual(a.xyXAtY(0), 0) self.assertEqual(a.xyXAtY(2.5), 2) self.assertEqual(a.xyXAtY(5), 4) self.assertEqual(a.xyXAtY(10), 8) self.assertEqual(a.atX(4), xyz.XY(4, 5))
def test_Line(self): a = xyz.XY(0,0) b = xyz.XY(0.5, 0.86603) l = xyz.Line(a, b) self.assertEqual(l.xy_min.x, Decimal('0')) self.assertEqual(l.xy_min.y, Decimal('0')) self.assertEqual(l.xy_max.x, Decimal('0.5')) self.assertEqual(l.xy_max.y, Decimal('0.866')) self.assertEqual(l.xym, Decimal('1.732')) self.assertEqual(l.xyb, Decimal('0')) l = xyz.Line(b, a) self.assertEqual(l.xym, Decimal('1.732')) self.assertEqual(l.xyb, Decimal('0')) a = xyz.XY(0,0) b = xyz.XY(0.5, -0.86603) l = xyz.Line(a, b) self.assertEqual(l.xym, Decimal('-1.732')) self.assertEqual(l.xyb, Decimal('0')) l = xyz.Line(b, a) self.assertEqual(l.xym, Decimal('-1.732')) self.assertEqual(l.xyb, Decimal('0')) a = xyz.XY(1,0) b = xyz.XY(1.5, 0.86603) l = xyz.Line(a, b) self.assertEqual(l.xym, Decimal('1.732')) self.assertEqual(l.xyb, Decimal('-1.732')) a = xyz.XY(3,0) b = xyz.XY(4,5) l = xyz.Line(a, b) self.assertEqual(l.xym, Decimal('5')) self.assertEqual(l.xyb, Decimal('-15'))
def test_Triangle_subsets(self): a = xyz.XY(0,0) b = xyz.XY(1,0) c = xyz.XY(0.5, math.sqrt(Decimal("0.75"))) for abc in ((a,b,c), (a,c,b), (b,a,c), (b,c,a), (c,a,b), (c,b,a)): t = shapes.Triangle(abc[0], abc[1], abc[2]) self.assertEqual(t.A, a) self.assertEqual(t.B, b) self.assertEqual(t.C, c) self.assertFalse(isinstance(t, shapes.RightTriangle)) self.assertTrue(t.b.length >= t.a.length) self.assertTrue(t.b.length >= t.c.length) self.assertTrue(t.a.length >= t.c.length) l = t.a.length + t.c.length l = t.a.length / l l = t.b.length * l self.assertEqual(t.a, xyz.Line(a, c)) self.assertEqual(t.b, xyz.Line(b, c)) self.assertEqual(t.c, xyz.Line(a, b)) self.assertEqual(t.a.length, 1) self.assertEqual(t.b.length, 1) self.assertEqual(t.c.length, 1) mids = [xyz.XY(Decimal("0.25000"), Decimal("0.43301")), xyz.XY(0.5, 0), xyz.XY(Decimal("0.75000"), Decimal("0.43301"))] self.assertTrue(t.Bmid in mids) self.assertTrue(t.ABC > Decimal('59.001') and \ t.ABC < Decimal('60.001')) self.assertTrue(t.BAC > Decimal('59.001') and \ t.ABC < Decimal('60.001')) self.assertTrue(t.ACB > Decimal('59.001') and \ t.ABC < Decimal('60.001')) a = xyz.XY(0,0) b = xyz.XY(3,0) c = xyz.XY(4,5) for abc in ((a,b,c), (a,c,b), (b,a,c), (b,c,a), (c,a,b), (c,b,a)): t = shapes.Triangle(abc[0], abc[1], abc[2]) self.assertFalse(isinstance(t, shapes.RightTriangle)) self.assertTrue(t.b.length >= t.a.length) self.assertTrue(t.b.length >= t.c.length) self.assertTrue(t.a.length >= t.c.length) self.assertEqual(t.Bmid, xyz.XY(1.170, 1.464)) l = t.a.length + t.c.length l = t.a.length / l l = t.b.length * l self.assertEqual(t.a, xyz.Line(xyz.XY(3,0), xyz.XY(4,5))) self.assertEqual(t.b, xyz.Line(xyz.XY(0,0), xyz.XY(4,5))) self.assertEqual(t.c, xyz.Line(xyz.XY(0,0), xyz.XY(3,0))) self.assertEqual(t.a.length, Decimal('5.099')) self.assertEqual(t.b.length, Decimal('6.403')) self.assertEqual(t.c.length, 3) self.assertEqual(t.thetaA, Decimal('51.340')) self.assertEqual(t.thetaC, Decimal('-27.350')) self.assertEqual(t.ABC, Decimal('101.31')) self.assertEqual(t.BAC, Decimal('51.340')) self.assertEqual(t.ACB, Decimal('27.35'))
def test_Line_distance(self): a = xyz.Line(xyz.XY(0, 0), xyz.XY(4, 5)) A = xyz.XY(0, 4) self.assertEqual(a.distance(A), Decimal('4.0615'))
def test_Line_reverse(self): a = xyz.Line(xyz.XY(0, 0), xyz.XY(4, 5)) b = xyz.Line(xyz.XY(4, 5), xyz.XY(0, 0)) self.assertEqual(a.reverse, b)
def test_Line_str(self): a = xyz.Line(xyz.XY(0, 0), xyz.XY(1, 1)) self.assertEqual(str(a), "Line(XY(0,0),XY(1,1))")