def make_coordinates(self): self.lTop_ = self.pos_ self.lBot_ = self.pos_ + gm.Point(0, self.sz_.y()) self.rTop_ = self.pos_ + gm.Point(self.sz_.x(), 0) self.rBot_ = self.pos_ + gm.Point(self.sz_.x(), self.sz_.y()) self.l1_ = gm.Line(self.lTop_, self.lBot_) # Left line self.l2_ = gm.Line(self.lBot_, self.rBot_) self.l3_ = gm.Line(self.rBot_, self.rTop_) self.l4_ = gm.Line(self.rTop_, self.lTop_) self.bbox_ = gm.Bbox(self.lTop_, self.lBot_, self.rBot_, self.rTop_)
def test_line_bbox_intersection(): bbox = gm.Bbox(gm.Point(1, 2), gm.Point(1, 1), gm.Point(2, 1), gm.Point(2, 2)) l1 = gm.Line(gm.Point(0, 0), gm.Point(1.5, 1.9)) l2 = gm.Line(gm.Point(0, 0), gm.Point(1, 10)) l3 = gm.Line(gm.Point(0, 1), gm.Point(5, 1)) print "GT: True, Predict:", bbox.is_intersect_line(l1) print "GT: False, Predict:", bbox.is_intersect_line(l2) print "GT: True, Predict:", bbox.is_intersect_line(l3) pt1, s1 = bbox.get_intersection_with_line(l1) pt2, s2 = bbox.get_intersection_with_line(l2) pt3, s3 = bbox.get_intersection_with_line(l3) print pt1, s1 print pt2, s2 print pt3, s3
def test_line_ray_bbox_intersection(): bbox = gm.Bbox(gm.Point(1, 2), gm.Point(1, 1), gm.Point(2, 1), gm.Point(2, 2)) l1 = gm.Line(gm.Point(0, 0), gm.Point(1.5, 1.9)) l2 = gm.Line(gm.Point(0, 0), gm.Point(1, 10)) l3 = gm.Line(gm.Point(0, 1), gm.Point(5, 1)) print "GT: True, Predict:", bbox.is_intersect_line(l1) print "GT: False, Predict:", bbox.is_intersect_line(l2) print "GT: True, Predict:", bbox.is_intersect_line(l3) l4 = gm.Line(gm.Point(1.5, 0.5), gm.Point(1.5, -0.5)) l6 = gm.Line(gm.Point(1.5, -0.5), gm.Point(1.5, 0.5)) l5 = gm.Line(gm.Point(1.5, 1.9), gm.Point(0, 0)) print "GT: False, Predict:", bbox.is_intersect_line_ray(l4) print "GT: True, Predict:", bbox.is_intersect_line(l4) print "GT: True, Predict:", bbox.is_intersect_line_ray(l6) print "GT: True, Predict:", bbox.is_intersect_line_ray(l5)