示例#1
0
 def test_intersecting_points(self):
     self.assertRaises(ValueError, Circle.intersecting_points,
                       self.circle1, self.circle1)
     self.assertIsNone(self.circle1.intersecting_points(self.circle2))
     self.assertTupleEqual(self.circle1.intersecting_points(self.circle3),
                           (Point2D(10, 0),))
     self.assertTupleEqual(self.circle1.intersecting_points(self.circle4),
                           (Point2D(-10, 0),))
     self.assertIsNone(self.circle1.intersecting_points(self.circle5))
     self.assertTupleEqual(self.circle2.intersecting_points(self.circle3),
                           (Point2D(2.5, -4.33012702), Point2D(2.5, 4.33012702)))
示例#2
0
    def setUp(self):
        p1 = Point2D(0, 0)
        p2 = Point2D(1, 1)
        p3 = Point2D(1, 0)
        p4 = Point2D(0, 1)
        p5 = Point2D(-1, 1)
        p6 = Point2D(1, -1)
        p7 = Point2D(-1, -1)
        p8 = Point2D(-1, 0)
        p9 = Point2D(0, -1)

        self.corner1 = Corner(p1, p2, p3)
        self.corner2 = Corner(p1, p3, p4)
        self.corner3 = Corner(p1, p3, p9)
        self.corner4 = Corner(p7, p2, p6)
        self.corner5 = Corner(p5, p8, p3)
        self.corner6 = Corner(p1, p8, p3)
示例#3
0
    def setUp(self):
        p1 = Point2D(-10, 0)
        p2 = Point2D(10, 0)
        p3 = Point2D(0, 0)
        p4 = Point2D(0, 10)

        self.ellipse1 = Ellipse(p1, p2, Point2D(15, 0))
        self.ellipse2 = Ellipse(p1, p3, p2)
        self.ellipse3 = Ellipse(p3, p4, Point2D(0, -5))
        self.ellipse4 = Ellipse(p2, p4, Point2D(0, 11))
示例#4
0
 def test_in_bounds(self):
     self.assertTrue(
         self.p1.in_bounds(lower_bound=Point2D(0, 0),
                           upper_bound=Point2D(5, 5)))
     self.assertTrue(
         self.p2.in_bounds(lower_bound=Point2D(-1, -5),
                           upper_bound=Point2D(10, 10)))
     self.assertFalse(
         self.p3.in_bounds(lower_bound=Point2D(-10, -10),
                           upper_bound=Point2D(0, 0)))
     self.assertFalse(
         self.p4.in_bounds(lower_bound=Point2D(-5, -10),
                           upper_bound=self.p4))
示例#5
0
# Written by Cameron Haddock
# Written as a solution for Advent of Code 2021

# https://adventofcode.com/2021/day/17

from fishpy.pathfinding import Location
from fishpy.pathfinding.grid import Grid
from fishpy.geometry import Point2D, Vector2D, LatticePoint
from fishpy.physics import Object
from fishpy.structures import Bounds

with open('2021/17/input.txt') as f:
    x, y = [
        part.split('..') for part in f.readline().rstrip()[15:].split(', y=')
    ]
    low_p, high_p = Point2D(int(x[0]),
                            int(y[0])), Point2D(int(x[1]), int(y[1]))
    target_bounds = Bounds(low_p, high_p, upper_inclusive=True)

max_height = 0
highest_v = None
total_success = 0
for v_x in range(5, 51):
    for v_y in range(-267, 268):
        a_x = 1 if v_x < 0 else -1
        object = Object(Point2D(0, 0), Vector2D(v_x, v_y), Vector2D(a_x, -1))
        tent_max_height = max_height
        iterations = 0
        while object.position not in target_bounds and iterations < 270 * 2:
            object.step()
            if object.velocity.x == 0:
                object.acceleration.x = 0
示例#6
0
 def setUp(self):
     self.p1 = Point2D(1, 1)
示例#7
0
 def test_gt(self):
     self.assertFalse(Point2D(0, 0) > self.p1)
     self.assertFalse(Point2D(-3, 0) > self.p3)
     self.assertTrue(Point2D(0.5, 2.5) > self.p3)
     self.assertTrue(Point2D(-2, 6) > self.p4)
     self.assertFalse(self.p1 > self.p1)
示例#8
0
 def test_ne(self):
     self.assertTrue(self.p1 != self.p2)
     self.assertFalse(self.p1 != Point2D(1, 1))
     self.assertFalse(self.p2 != Point2D(1, -5))
     self.assertTrue(self.p3 != Point2D(1, 3))
     self.assertTrue(self.p4 != Point2D(-2, 6))
示例#9
0
 def test_neg(self):
     self.assertEqual(-self.p1, Point2D(-1, -1))
     self.assertEqual(-self.p2, Point2D(-1, 5))
     self.assertEqual(-self.p3, Point2D(0, -2))
     self.assertEqual(-self.p4, Point2D(3, -5))
示例#10
0
 def test_is_right(self):
     self.assertFalse(self.p1.is_right_of(self.p1))
     self.assertFalse(self.p2.is_right_of(self.p1))
     self.assertTrue(self.p3.is_right_of(self.p4))
     self.assertTrue(self.p4.is_right_of(Point2D(-10, 0)))
示例#11
0
 def test_mul(self):
     self.assertEqual(self.p1 * 3, Point2D(3, 3))
     self.assertEqual(self.p2 * -1, Point2D(-1, 5))
     self.assertEqual(self.p3 * 2, Point2D(0, 4))
     self.assertEqual(self.p4 * 0.5, Point2D(-1.5, 2.5))
示例#12
0
 def test_random(self):
     random_point = Point2D.random(lower_bound=self.p1,
                                   upper_bound=Point2D(5, 5))
     self.assertTrue(random_point.in_bounds(self.p1, Point2D(6, 6)))
示例#13
0
 def setUp(self):
     self.circle = Circle(Point2D(0, 0), 4)
示例#14
0
 def setUp(self):
     self.circle1 = Circle(Point2D(0, 0), 10)
     self.circle2 = Circle(Point2D(0, 0), 5)
     self.circle3 = Circle(Point2D(5, 0), 5)
     self.circle4 = Circle(Point2D(-15, 0), 5)
     self.circle5 = Circle(Point2D(20, 0), 5)
示例#15
0
 def test_contains(self):
     self.assertIn(Point2D(0, 0), self.circle)
     self.assertIn(Point2D(-10, 0), self.circle)
     self.assertIn(Point2D(7, 7), self.circle)
     self.assertNotIn(Point2D(15, 5), self.circle)
     self.assertNotIn(Point2D(9, 9), self.circle)
示例#16
0
 def setUp(self):
     self.p1 = Point2D(1, 1)
     self.p2 = Point2D(1, -5)
     self.p3 = Point2D(0, 2)
     self.p4 = Point2D(-3, 5)
示例#17
0
 def test_true_div(self):
     self.assertEqual(self.p1 / 2, Point2D(0.5, 0.5))
     self.assertEqual(self.p2 / 1, Point2D(1, -5))
     self.assertEqual(self.p3 / 4, Point2D(0, 0.5))
     self.assertEqual(self.p4 / -1, Point2D(3, -5))
     self.assertRaises(ZeroDivisionError, Point2D.__truediv__, self.p1, 0)
示例#18
0
 def test_add(self):
     self.assertEqual(self.p1 + self.p1, Point2D(2, 2))
     self.assertEqual(self.p2 + self.p3, Point2D(1, -3))
     self.assertEqual(self.p2 + self.p4, Point2D(-2, 0))
     self.assertEqual(self.p1 + self.p3, Point2D(1, 3))
示例#19
0
 def test_floor_div(self):
     self.assertEqual(self.p1 // 2, Point2D(0, 0))
     self.assertEqual(self.p2 // 1, Point2D(1, -5))
     self.assertEqual(self.p3 // 4, Point2D(0, 0))
     self.assertEqual(self.p4 // -1, Point2D(3, -5))
示例#20
0
 def test_eq(self):
     self.assertFalse(self.p1 == self.p2)
     self.assertTrue(self.p1 == Point2D(1, 1))
     self.assertTrue(self.p2 == Point2D(1, -5))
     self.assertTrue(self.p3 == Point2D(0, 2))
     self.assertTrue(self.p4 == Point2D(-3, 5))
示例#21
0
 def test_mod(self):
     self.assertEqual(self.p1 % Point2D(5, 5), self.p1)
     self.assertEqual(self.p2 % Point2D(2, 2), Point2D(1, 1))
     self.assertEqual(self.p3 % Point2D(1, 1), Point2D(0, 0))
     self.assertEqual(self.p4 % Point2D(4, 3), Point2D(1, 2))
示例#22
0
 def test_lt(self):
     self.assertTrue(Point2D(0, 0) < self.p1)
     self.assertTrue(Point2D(-3, 0) < self.p3)
     self.assertFalse(Point2D(0, 1) < self.p3)
     self.assertFalse(Point2D(-3, 5) < self.p4)
示例#23
0
 def test_abs(self):
     self.assertEqual(abs(-self.p1), Point2D(1, 1))
     self.assertEqual(abs(self.p2), Point2D(1, 5))
     self.assertEqual(abs(-self.p3), Point2D(0, 2))
     self.assertEqual(abs(self.p4), Point2D(3, 5))
示例#24
0
 def test_le(self):
     self.assertTrue(Point2D(1, 0) <= self.p1)
     self.assertTrue(Point2D(-3, 5) <= self.p4)
     self.assertTrue(Point2D(0, 1) <= self.p3)
     self.assertFalse(Point2D(6, 6) <= self.p4)
示例#25
0
 def test_floor(self):
     self.assertEqual(math.floor(Point2D(0.57, 7.13)), Point2D(0, 7))
     self.assertEqual(math.floor(Point2D(3.14, 2.81)), Point2D(3, 2))
     self.assertEqual(math.floor(Point2D(0.01, 0.99)), Point2D(0, 0))
     self.assertEqual(math.floor(Point2D(9.12, -1.1)), Point2D(9, -2))
示例#26
0
 def test_ge(self):
     self.assertFalse(Point2D(0, 0) >= self.p1)
     self.assertTrue(Point2D(8, 1) >= self.p3)
     self.assertTrue(Point2D(-1, 2) >= self.p3)
     self.assertTrue(Point2D(-3, 5) >= self.p4)
     self.assertFalse(self.p1 > self.p1)
示例#27
0
 def test_ceil(self):
     self.assertEqual(math.ceil(Point2D(0.57, 7.13)), Point2D(1, 8))
     self.assertEqual(math.ceil(Point2D(3.14, 2.81)), Point2D(4, 3))
     self.assertEqual(math.ceil(Point2D(0.01, 0.99)), Point2D(1, 1))
     self.assertEqual(math.ceil(Point2D(9.12, -1.1)), Point2D(10, -1))
示例#28
0
 def test_midpoint(self):
     self.assertEqual(self.p1.midpoint(self.p2), Point2D(1, -2))
     self.assertEqual(self.p2.midpoint(self.p3), Point2D(0.5, -1.5))
     self.assertEqual(self.p3.midpoint(self.p4), Point2D(-1.5, 3.5))
     self.assertEqual(self.p4.midpoint(self.p1), Point2D(-1, 3))
示例#29
0
 def test_center(self):
     self.assertEqual(self.ellipse1.center, Point2D(0, 0))
     self.assertEqual(self.ellipse2.center, Point2D(-5, 0))
     self.assertEqual(self.ellipse3.center, Point2D(0, 5))
     self.assertEqual(self.ellipse4.center, Point2D(5, 5))