def test_normalize(self): for i in range(100): a = random.random() + i b = random.random() + i c = random.random() + i self.assertTrue( BaseUtils.equal(P3(a, b, c).normalize().length(), 1.0))
def test_tr_01(self): t = (Trajectory(StraightLine2(2.0, P2(1, 0), P2(0, 0))).add_arc_line( 0.95, False, 22.5).add_strait_line(1.5).add_arc_line( 0.95, False, 22.5).add_strait_line(2.0 + 2.2).add_arc_line( 0.95, True, 67.5).add_strait_line(1.5).add_arc_line( 0.95, True, 67.5).add_strait_line(2.2)) self.assertTrue(BaseUtils.equal(t.direct_at_end(), P2(0, -1)))
def test_change_length(self): for i in range(100): a = random.random() + i b = random.random() + i c = random.random() + i d = random.random() + i self.assertTrue( BaseUtils.equal(P3(a, b, c).change_length(d).length(), d))
def test_length(self): for i in range(100): a = random.random() + i b = random.random() + i c = random.random() + i self.assertTrue( BaseUtils.equal( P3(a, b, c).length(), float(np.sqrt(a**2 + b**2 + c**2))))
def test_mul2(self): for i in range(100): a = random.random() + i + 1 b = random.random() + i + 1 c = random.random() + i + 1 d = random.random() + i + 1 self.assertTrue( BaseUtils.equal(P2(a, b) * P2(c, d), a * c + b * d, msg="error"))
def test_mul2(self): for i in range(100): a = random.random() + i + 1 b = random.random() + i + 1 c = random.random() + i + 1 d = random.random() + i + 1 e = random.random() + i + 1 f = random.random() + i + 1 self.assertTrue( BaseUtils.equal(P3(a, b, e) * P3(c, d, f), a * c + b * d + e * f, msg="error"))
def test_angle_to(self): for i in range(100): a0 = random.random() * np.pi * 1.9 + 1e-6 b0 = random.random() * np.pi * 1.9 + 1e-6 a = max(a0, b0) b = min(a0, b0) p1 = P2(1.0) p2 = P2(1.0) p1 = p1.rotate(a) p2 = p2.rotate(b) diff = a - b # print(p1.angle_to(p2),diff) self.assertTrue( BaseUtils.equal( p2.angle_to(p1), diff #if diff >0 else 2 * np.pi - diff ))
def test_p2_copy(self): for i in range(100): p = P2(random.random() + i, random.random() + i) self.assertTrue(BaseUtils.equal(p, p.copy())) self.assertFalse(p is p.copy())
def test_p2_norm(self): p = P2(1, 1) self.assertTrue( BaseUtils.equal(p.normalize(), P2(np.sqrt(2) / 2, np.sqrt(2) / 2)))
def test_p2_len(self): p = P2(1, 1) self.assertTrue(BaseUtils.equal(p.length(), np.sqrt(2)))
def test_straight(self): s = StraightLine2(1, np.array([1.0, 1.0]), np.array([0.0, 0.0])) self.assertTrue(BaseUtils.equal(s.get_length(), 1))
def test_equal2(self): BaseUtils.equal(P2(), P2(1e-10), msg="不相等") with self.assertRaises(AssertionError): BaseUtils.equal(P2(), P2(1e-5), msg="不相等")
def test_equal(self): BaseUtils.equal(1, 1, msg="不相等") with self.assertRaises(AssertionError): BaseUtils.equal(1, 2, msg="不相等")
def test_angle_to_x_axis(self): for i in range(100): phi = random.random() * np.pi * 1.9 + 1e-6 p = P2(1.0) p = p.rotate(phi) self.assertTrue(BaseUtils.equal(p.angle_to_x_axis(), phi))
def test_p2_rotate(self): for phi in np.linspace(0.1, 2 * np.pi * 0.99, 100): p = P2(1.0) p = p.rotate(phi) self.assertTrue(BaseUtils.equal(p.angle_to_x_axis(), phi))