def checkIntersectionWithTexture(self, points, prim): global DEBUG global epsilon logging.debug( "Start method checkIntersectionWithTexture, class Texture") # First we check intersection with boundingBox if (self.get_prim() and self.get_absolute_points()): param_points_bounding_box = BoundingBox.BoundingBox2D(points, prim) texture_bounding_box = BoundingBox.BoundingBox2D( self.get_absolute_points(), self.get_prim()) intersections = ( texture_bounding_box.intersect_bounding_box_without_limits_3D( param_points_bounding_box)) if (not intersections): return None, None, [] else: if (not self.get_prim()): logging.debug( "Class Texture, not prim in method check intersection with texture" ) else: logging.debug("No object points") logging.debug(str(self)) logging.debug(str(self.get_is_default_texture())) logging.debug(str(self.get_absolute_points())) logging.debug(str(self.get_absolute_points_not_erasable())) logging.debug(str(self.get_delimited_proportions())) logging.debug(str(self.get_obj())) pointsIntersect = [] for n in range(len(points) - 1): edge = [points[n], points[n + 1]] for texIndex in range(len(self.absolutePoints)): nextTexIndex = (texIndex + 1) % len(self.absolutePoints) texEdge = [ self.absolutePoints[texIndex], self.absolutePoints[nextTexIndex] ] pointIntersect = GeoMath.getFalseIntersectionBetweenTwoEdges3D( edge, texEdge, prim) # We have to avoid first point, that surely intersect with some texture. # Also avoid the case where two texture are together and pattern intersect with # the first texture, but when 'exit' from this texture, it intersect with the # other texture anda pattern of length 0 is used; with this method we avoid this if (pointIntersect): distacenToLastPoint = GeoMath.vecModul( GeoMath.vecSub(points[len(points) - 1], pointIntersect)) if (GeoMath.vecModul( GeoMath.vecSub(pointIntersect, points[0])) > epsilon and distacenToLastPoint > epsilon): pointsIntersect.append(pointIntersect) if (pointsIntersect): nearestPointIntersect = None # Big number minDistance = 999999 # For each point we look if intersection is the minimum distance intersection for pointIntersect in pointsIntersect: distance, achieved = GeoMath.takeDistanceInTrackToPoint( points, pointIntersect, points[0]) if (achieved and distance < minDistance and distance > epsilon): # We need the minimun distance, but to avoid errors, we have # to discard the first point and the last minDistance = distance nearestPointIntersect = pointIntersect if (not nearestPointIntersect): minDistance = None else: nearestPointIntersect = None minDistance = None if (nearestPointIntersect): logging.debug('End method checkIntersectionWithTexture,' 'class Texture. State: Intersection') else: logging.debug('End method checkIntersectionWithTexture,' 'class Texture. State: No intersection') return minDistance, nearestPointIntersect, pointsIntersect
def checkIntersectionWithTexture(self, points, prim): global DEBUG global epsilon logging.debug("Start method checkIntersectionWithTexture, class Texture") # First we check intersection with boundingBox if(self.get_prim() and self.get_absolute_points()): param_points_bounding_box = BoundingBox.BoundingBox2D(points, prim) texture_bounding_box = BoundingBox.BoundingBox2D( self.get_absolute_points(), self.get_prim()) intersections = ( texture_bounding_box.intersect_bounding_box_without_limits_3D( param_points_bounding_box)) if (not intersections): return None, None, [] else: if(not self.get_prim()): logging.debug("Class Texture, not prim in method check intersection with texture") else: logging.debug("No object points") logging.debug(str(self)) logging.debug(str(self.get_is_default_texture())) logging.debug(str(self.get_absolute_points())) logging.debug(str(self.get_absolute_points_not_erasable())) logging.debug(str(self.get_delimited_proportions())) logging.debug(str(self.get_obj())) pointsIntersect = [] for n in range(len(points) - 1): edge = [points[n], points[n + 1]] for texIndex in range(len(self.absolutePoints)): nextTexIndex = (texIndex + 1) % len(self.absolutePoints) texEdge = [self.absolutePoints[texIndex], self.absolutePoints[nextTexIndex]] pointIntersect = GeoMath.getFalseIntersectionBetweenTwoEdges3D(edge, texEdge, prim) # We have to avoid first point, that surely intersect with some texture. # Also avoid the case where two texture are together and pattern intersect with # the first texture, but when 'exit' from this texture, it intersect with the # other texture anda pattern of length 0 is used; with this method we avoid this if(pointIntersect): distacenToLastPoint = GeoMath.vecModul(GeoMath.vecSub( points[len(points) - 1], pointIntersect)) if(GeoMath.vecModul(GeoMath.vecSub(pointIntersect, points[0])) > epsilon and distacenToLastPoint > epsilon): pointsIntersect.append(pointIntersect) if(pointsIntersect): nearestPointIntersect = None # Big number minDistance = 999999 # For each point we look if intersection is the minimum distance intersection for pointIntersect in pointsIntersect: distance, achieved = GeoMath.takeDistanceInTrackToPoint(points, pointIntersect, points[0]) if(achieved and distance < minDistance and distance > epsilon): # We need the minimun distance, but to avoid errors, we have # to discard the first point and the last minDistance = distance nearestPointIntersect = pointIntersect if(not nearestPointIntersect): minDistance = None else: nearestPointIntersect = None minDistance = None if(nearestPointIntersect): logging.debug('End method checkIntersectionWithTexture,' 'class Texture. State: Intersection') else: logging.debug('End method checkIntersectionWithTexture,' 'class Texture. State: No intersection') return minDistance, nearestPointIntersect, pointsIntersect