MCPcopy Index your code
hub / github.com/OmkarPathak/pygorithm / contains_point

Method contains_point

pygorithm/geometry/rect2.py:179–210  ·  view source on GitHub ↗

Determine if the rect contains the point Distinguish between points that are on the edge of the rect and those that are not. .. tip:: This will never return ``True, True`` :param rect: the rect :type rec

(rect, point)

Source from the content-addressed store, hash-verified

177
178 @staticmethod
179 def contains_point(rect, point):
180 """
181 Determine if the rect contains the point
182
183 Distinguish between points that are on the edge of the
184 rect and those that are not.
185
186 .. tip::
187
188 This will never return ``True, True``
189
190 :param rect: the rect
191 :type rect: :class:`pygorithm.geometry.rect2.Rect2`
192 :param point: the point
193 :type point: :class:`pygorithm.geometry.vector2.Vector2`
194 :returns: point on edge, point inside
195 :rtype: bool, bool
196 """
197
198 edge_x = math.isclose(rect.mincorner.x, point.x, abs_tol=1e-07) or math.isclose(rect.mincorner.x + rect.width, point.x, abs_tol=1e-07)
199 edge_y = math.isclose(rect.mincorner.y, point.y, abs_tol=1e-07) or math.isclose(rect.mincorner.y + rect.height, point.y, abs_tol=1e-07)
200 if edge_x and edge_y:
201 return True, False
202
203 contains = (edge_x or (point.x > rect.mincorner.x and point.x < rect.mincorner.x + rect.width)) and \
204 (edge_y or (point.y > rect.mincorner.y and point.y < rect.mincorner.y + rect.height))
205 if not contains:
206 return False, False
207 elif edge_x or edge_y:
208 return True, False
209 else:
210 return False, True
211
212 @classmethod
213 def _find_intersection_rects(cls, rect1, rect2, find_mtv = True):

Calls

no outgoing calls