Esempio n. 1
0
    def test_315(self):
        """ Test for the closest point when the line is 90 degrees """

        angle = 1.75*numpy.pi
        line = Line(self.xa, self.length, angle)

        pnt = Point(2, 1)
        p = line.find_closest_point(pnt)
        self.assertAlmostEqual(p.x, self.xa.x+0.5, 10)
        self.assertAlmostEqual(p.y, self.xa.y-0.5, 10)

        pnt = Point(1, 0)
        p = line.find_closest_point(pnt)
        self.assertAlmostEqual(p.x, self.xa.x+0.5, 10)
        self.assertAlmostEqual(p.y, self.xa.y-0.5, 10)

        pnt = Point(1, 2)
        p = line.find_closest_point(pnt)
        self.assertAlmostEqual(p.x, self.xa.x, 10)
        self.assertAlmostEqual(p.y, self.xa.y, 10)

        pnt = Point(3, 0)
        p = line.find_closest_point(pnt)
        self.assertAlmostEqual(p.x, line.xb.x, 10)
        self.assertAlmostEqual(p.y, line.xb.y, 10)
Esempio n. 2
0
    def test_90(self):
        """ Test for the closest point when the line is 90 degrees """

        angle = 0.5*numpy.pi
        line = Line(self.xa, self.length, angle)

        pnt = Point(0, 1.5)
        p = line.find_closest_point(pnt)
        self.assertAlmostEqual(p.x, self.xa.x, 10)
        self.assertAlmostEqual(p.y, self.xa.y+0.5, 10)

        pnt = Point(0, 0)
        p = line.find_closest_point(pnt)
        self.assertAlmostEqual(p.x, self.xa.x, 10)
        self.assertAlmostEqual(p.y, self.xa.y, 10)

        pnt = Point(1.5, 1.5)
        p = line.find_closest_point(pnt)
        self.assertAlmostEqual(p.x, self.xa.x, 10)
        self.assertAlmostEqual(p.y, self.xa.y+0.5, 10)
Esempio n. 3
0
    def test_zero(self):
        """ Test when the angle is 0 """
        angle = 0.0
        line = Line(self.xa, self.length, angle)

        pnt = Point(1, 2)
        p = line.find_closest_point(pnt)
        self.assertAlmostEqual(p.x, 1.0, 10)
        self.assertAlmostEqual(p.y, 1.0, 10)

        pnt = Point(2, 2)
        p = line.find_closest_point(pnt)
        self.assertAlmostEqual(p.x, 2.0, 10)
        self.assertAlmostEqual(p.y, 1.0, 10)

        pnt = Point(1.5, 2)
        p = line.find_closest_point(pnt)
        self.assertAlmostEqual(p.x, 1.5, 10)
        self.assertAlmostEqual(p.y, 1.0, 10)

        pnt = Point(2.5, 2)
        p = line.find_closest_point(pnt)
        self.assertAlmostEqual(p.x, line.xb.x, 10)
        self.assertAlmostEqual(p.y, 1.0, 10)

        pnt = Point(0.5, 2)
        p = line.find_closest_point(pnt)
        self.assertAlmostEqual(p.x, line.xa.x, 10)
        self.assertAlmostEqual(p.y, 1.0, 10)
Esempio n. 4
0
    def test_45(self):
        """ Test for the closest point when the line is at 45 degrees """
        angle = 0.25*numpy.pi
        line = Line(self.xa, self.length, angle)

        pnt = Point(1, 2)
        p = line.find_closest_point(pnt)
        self.assertAlmostEqual(p.x, self.xa.x+0.5, 10)
        self.assertAlmostEqual(p.y, self.xa.y+0.5, 10)

        pnt = Point(0, 2)
        p = line.find_closest_point(pnt)
        self.assertAlmostEqual(p.x, self.xa.x, 10)
        self.assertAlmostEqual(p.y, self.xa.y, 10)

        pnt = Point(2, 0)
        p = line.find_closest_point(pnt)
        self.assertAlmostEqual(p.x, self.xa.x, 10)
        self.assertAlmostEqual(p.y, self.xa.y, 10)

        pnt = Point(2, 1)
        p = line.find_closest_point(pnt)
        self.assertAlmostEqual(p.x, self.xa.x+0.5, 10)
        self.assertAlmostEqual(p.y, self.xa.y+0.5, 10)