def test_distance_three_axis(self): """ Distance returns value equal to diagonal distance between point (0,0,0) and (1,1,1) in 3-D """ p1 = Point(0, 0, 0) p2 = Point(1, 1, 1) self.assertEqual(p1.distance(p2), 3**0.5) self.assertEqual(p2.distance(p1), 3**0.5)
def test_distance_two_axis(self): """ Distance returns value equal to diagonal distance between point (0,0) and (1,1) in x-y plane """ p1 = Point(0, 0, 0) p2 = Point(1, 1, 0) self.assertEqual(p1.distance(p2), 2**0.5) self.assertEqual(p2.distance(p1), 2**0.5)
def test_distance_non_zero_point(self): """ Distance returns value equal to diagonal distance between two points, neither of which has a zero value component i.e. check all components included in calcs """ p1 = Point(-1, -1, -1) p2 = Point(1, 1, 1) self.assertEqual(p1.distance(p2), 2 * 3**0.5) self.assertEqual(p2.distance(p1), 2 * 3**0.5)
def bulge2arc(self, Ps, Pe, bulge): """ bulge2arc() """ c = (1 / bulge - bulge) / 2 # Berechnung des Mittelpunkts (Formel von Mickes!) # Calculation of the center (Micke's formula) O = Point((Ps.x + Pe.x - (Pe.y - Ps.y) * c) / 2, (Ps.y + Pe.y + (Pe.x - Ps.x) * c) / 2) # Radius = Distance between the centre and Ps r = O.distance(Ps) # Kontrolle ob beide gleich sind (passt ...) # Check if they are equal (fits ...) # r=O.distance(Pe) # Unterscheidung f�r den �ffnungswinkel. # Distinction for the opening angle. ??? if bulge > 0: return ArcGeo(Ps=Ps, Pe=Pe, O=O, r=r) else: arc = ArcGeo(Ps=Pe, Pe=Ps, O=O, r=r) arc.reverse() return arc
def contains_point(self, point): """ Method to determine the minimal distance from the point to the shape @param point: a QPointF @return: minimal distance """ min_distance = float(0x7fffffff) ref_point = Point(point.x(), point.y()) t = 0.0 while t < 1.0: per_point = self.path.pointAtPercent(t) spline_point = Point(per_point.x(), per_point.y()) distance = ref_point.distance(spline_point) if distance < min_distance: min_distance = distance t += 0.01 return min_distance
def bulge2arc(self, Ps, Pe, bulge): """ bulge2arc() """ c = (1 / bulge - bulge) / 2 # Calculate the centre point (Micke's formula!) O = Point((Ps.x + Pe.x - (Pe.y - Ps.y) * c) / 2, (Ps.y + Pe.y + (Pe.x - Ps.x) * c) / 2) # Radius = Distance between the centre and Ps r = O.distance(Ps) # Check if they are equal (fits ...) # r=O.distance(Pe) # Unterscheidung f�r den �ffnungswinkel. # Distinction for the opening angle. ??? if bulge > 0: return ArcGeo(Ps=Ps, Pe=Pe, O=O, r=r) else: arc = ArcGeo(Ps=Pe, Pe=Ps, O=O, r=r) arc.reverse() return arc
def test_distance_one_axis(self): """Distance returns value equal to difference between x-values""" p1 = Point(0, 0, 0) p2 = Point(1, 0, 0) self.assertEqual(p1.distance(p2), 1) self.assertEqual(p2.distance(p1), 1)