def setUp(self):
      # 10x10 square beginning on origin
      self.polygon1 = Polygon.from_relative_coordinates((0, 0), [(0,0),(10,0),(10,10),(0,10)])

      # 10x10 diamond shape centered at origin
      self.polygon2 = Polygon.from_relative_coordinates((0, 0), [(10,0), (0, 10), (-10, 0), (0, -10)])

      # L-shaped polygon
      self.polygon3 = Polygon.from_relative_coordinates((0, 0), [(0,0),(10,0),(10,5),(5,5),(5,10),(0,10)])

      self.polygon4 = Polygon.from_absolute_coordinates([(0,0),(5,0),(5,5),(10,5),(10,10),(0,10)])
Пример #2
0
    def setUp(self):
        self.polygon1 = Polygon.from_relative_coordinates((100, 200),
                                                          [(0, 0), (10, 0),
                                                           (10, 10), (0, 10)])

        self.polygon2 = Polygon.from_absolute_coordinates([(-20, 30), (0, -10),
                                                           (20, -30),
                                                           (40, -10)])
Пример #3
0
   def setUp(self):
      self.polygon1 = Polygon.from_relative_coordinates(
         (100, 200),
         [ (0, 0), (10, 0), (10, 10), (0, 10) ]
      )

      self.polygon2 = Polygon.from_absolute_coordinates(
         [ (-20, 30), (0, -10), (20, -30), (40, -10) ]
      )
Пример #4
0
   def test_simplify_close_points(self):
      p1 = Polygon.from_relative_coordinates( Point(0,0),
         [ (-20, 30), (-20.35, 30.25), (0, -10), (-0.3, -10.36), (40, -10) ]
      ).simplify_close_points()

      self.assertEqual(p1.points, [ (-20, 30), (0, -10), (40, -10) ])

      p2 = Polygon.from_relative_coordinates( Point(0,0),
         [ (-20, 30), (-20.25, 30.15), (0, -10), (-0.13, -10.16), (15, 15), (-20, 30) ]
      ).simplify_close_points()

      self.assertEqual(p2.points, [ (0, -10), (15, 15), (-20, 30), (0, -10) ])

      p3 = Polygon.from_relative_coordinates( Point(0,0),
         [ (0, 0), (0, 0.49), (0, 0.495), (0, 0.396), (0, 0.9), (0, 1.3), (0, 1.41) ]
      ).simplify_close_points()

      self.assertEqual(p3.points, [ (0, 0), (0, 0.9), (0, 1.41) ])
Пример #5
0
    def test_simplify_close_points(self):
        p1 = Polygon.from_relative_coordinates(Point(
            0, 0), [(-20, 30), (-20.35, 30.25), (0, -10), (-0.3, -10.36),
                    (40, -10)]).simplify_close_points()

        self.assertEqual(p1.points, [(-20, 30), (0, -10), (40, -10)])

        p2 = Polygon.from_relative_coordinates(Point(
            0, 0), [(-20, 30), (-20.25, 30.15), (0, -10), (-0.13, -10.16),
                    (15, 15), (-20, 30)]).simplify_close_points()

        self.assertEqual(p2.points, [(0, -10), (15, 15), (-20, 30), (0, -10)])

        p3 = Polygon.from_relative_coordinates(Point(
            0, 0), [(0, 0), (0, 0.49), (0, 0.495), (0, 0.396), (0, 0.9),
                    (0, 1.3), (0, 1.41)]).simplify_close_points()

        self.assertEqual(p3.points, [(0, 0), (0, 0.9), (0, 1.41)])
Пример #6
0
    def setUp(self):
        # 10x10 square beginning on origin
        self.polygon1 = Polygon.from_relative_coordinates((0, 0), [(0, 0),
                                                                   (10, 0),
                                                                   (10, 10),
                                                                   (0, 10)])

        # 10x10 diamond shape centered at origin
        self.polygon2 = Polygon.from_relative_coordinates((0, 0), [(10, 0),
                                                                   (0, 10),
                                                                   (-10, 0),
                                                                   (0, -10)])

        # L-shaped polygon
        self.polygon3 = Polygon.from_relative_coordinates((0, 0), [(0, 0),
                                                                   (10, 0),
                                                                   (10, 5),
                                                                   (5, 5),
                                                                   (5, 10),
                                                                   (0, 10)])

        self.polygon4 = Polygon.from_absolute_coordinates([(0, 0), (5, 0),
                                                           (5, 5), (10, 5),
                                                           (10, 10), (0, 10)])
Пример #7
0
   def _extract_entities(self):
      self._rooms          = []
      self._texts          = []
      self._wall_lines     = []
      self._window_lines   = []

      for ent in self._grabber.entities:
         if self._is_valid_room(ent):
            points = [(p[0], -p[1]) for p in ent.points]

            polygon = Polygon.from_absolute_coordinates(points)
            polygon.ensure_is_closed(tollerance = 0.8)
            polygon.simplify_close_points(tollerance = 0.8)

            if polygon.is_self_crossing():
               Logger.warning("Self crossing room is not valid: "+str(polygon))
               continue

            self._rooms.append(
               Room(
                  polygon
               )
            )
         elif self._is_valid_text(ent):
            self._texts.append(
               Text(
                  ent.plain_text().strip(), Point(ent.insert[0], -ent.insert[1])
               )
            )
         elif self._is_valid_wall_line(ent):
            start = Point(ent.start[0], -ent.start[1])
            end   = Point(ent.end[0], -ent.end[1])
            line  = Segment(start, end)
            self._wall_lines.append( line )

         elif self._is_valid_wall_polyline(ent):
            points = [(p[0], -p[1]) for p in ent.points]
            polygon = Polygon.from_relative_coordinates((0,0), points)
            polygon.ensure_is_closed(tollerance = 1)
            polygon.simplify_close_points(tollerance = 1)

            self._wall_lines.extend( polygon.as_segment_list() )

         elif self._is_valid_window_line(ent):
            start = Point(ent.start[0], -ent.start[1])
            end   = Point(ent.end[0], -ent.end[1])
            line  = Segment(start, end)
            self._window_lines.append( line )
Пример #8
0
    def _extract_entities(self):
        self._rooms = []
        self._texts = []
        self._wall_lines = []
        self._window_lines = []

        for ent in self._grabber.entities:
            if self._is_valid_room(ent):
                points = [(p[0], -p[1]) for p in ent.points]

                polygon = Polygon.from_absolute_coordinates(points)
                polygon.ensure_is_closed(tollerance=0.8)
                polygon.simplify_close_points(tollerance=0.8)

                if polygon.is_self_crossing():
                    Logger.warning("Self crossing room is not valid: " +
                                   str(polygon))
                    continue

                self._rooms.append(Room(polygon))
            elif self._is_valid_text(ent):
                self._texts.append(
                    Text(ent.plain_text().strip(),
                         Point(ent.insert[0], -ent.insert[1])))
            elif self._is_valid_wall_line(ent):
                start = Point(ent.start[0], -ent.start[1])
                end = Point(ent.end[0], -ent.end[1])
                line = Segment(start, end)
                self._wall_lines.append(line)

            elif self._is_valid_wall_polyline(ent):
                points = [(p[0], -p[1]) for p in ent.points]
                polygon = Polygon.from_relative_coordinates((0, 0), points)
                polygon.ensure_is_closed(tollerance=1)
                polygon.simplify_close_points(tollerance=1)

                self._wall_lines.extend(polygon.as_segment_list())

            elif self._is_valid_window_line(ent):
                start = Point(ent.start[0], -ent.start[1])
                end = Point(ent.end[0], -ent.end[1])
                line = Segment(start, end)
                self._window_lines.append(line)