Esempio n. 1
0
	def contains_point(self, p, include_ends=True):
		""" Check if a point is on the segment """

		# Format point correctly
		p = tuple([tls.list_to_number(x) for x in p])

		# Now check if the line contains the point
		# If not, return False
		if not self.line.contains_point(p):
			return False

		# Now check that the point falls in the rectangle where seg is the 
		# diagonal
		xp, yp = p
		a, b = self.a, self.b

		# Note: if the segment is vertical, include_ends = True
		include_ends = include_ends or self.vertical or self.horizontal

		if include_ends:
			inx = (a[0] <= xp <= b[0]) | (a[0] >= xp >= b[0])
			iny = (a[1] <= yp <= b[1]) | (a[1] >= yp >= b[1])
		else:
			inx = (a[0] < xp < b[0]) | (a[0] > xp > b[0])
			iny = (a[1] < yp < b[1]) | (a[1] > yp > b[1])

		if inx and iny:
			return True
		else:
			return False
Esempio n. 2
0
	def contains_point(self, p):
		"""
		Check if a point p is on this line
		"""
		xp, yp = [tls.list_to_number(x) for x in p]
		if self.vertical:
			return nearly_equal(xp, self.point[0], tolerance=1.e-9)
		return nearly_equal(yp, self.equation(xp), tolerance=1.e-9)
Esempio n. 3
0
	def change_point(self, index, point):
		""" Change one point of the segment; hence change it """
		# Clean the point
		point = tuple([tls.list_to_number(x) for x in point])
		# Add it to the list
		self.points_list[index] = point
		# Update the segment
		self.update(self.points_list)
Esempio n. 4
0
    def __init__(self, points):

        # Validation
        if len(points) != 2:
            msg = 'WARNING: Defined a segment with %i points:\n%s\nSegment not created. Returned None' % (
                len(points), str(points))
            try:
                ws.log(msg)
            except AttributeError:
                print(msg)
            return None

        # Clean the points. Give them a nice and clean format
        points = (tuple([tls.list_to_number(x) for x in points[0]]),
                  tuple([tls.list_to_number(x) for x in points[1]]))
        self.points_list = list(points)
        # Add attributes
        self.update(points)