MCPcopy Index your code
hub / github.com/Layout-Parser/layout-parser / Rectangle

Class Rectangle

src/layoutparser/elements/layout_elements.py:467–777  ·  view source on GitHub ↗

This class describes the coordinate system of an axial rectangle box using two points as indicated below:: (x_1, y_1) ---- | | | | | | ---- (x_2, y_2) Args: x_1 (:obj:`numeric`):

Source from the content-addressed store, hash-verified

465
466@inherit_docstrings
467class Rectangle(BaseCoordElement):
468 """
469 This class describes the coordinate system of an axial rectangle box using two points as indicated below::
470
471 (x_1, y_1) ----
472 | |
473 | |
474 | |
475 ---- (x_2, y_2)
476
477 Args:
478 x_1 (:obj:`numeric`):
479 x coordinate on the horizontal axis of the upper left corner of the rectangle.
480 y_1 (:obj:`numeric`):
481 y coordinate on the vertical axis of the upper left corner of the rectangle.
482 x_2 (:obj:`numeric`):
483 x coordinate on the horizontal axis of the lower right corner of the rectangle.
484 y_2 (:obj:`numeric`):
485 y coordinate on the vertical axis of the lower right corner of the rectangle.
486 """
487
488 _name = "rectangle"
489 _features = ["x_1", "y_1", "x_2", "y_2"]
490
491 def __init__(self, x_1, y_1, x_2, y_2):
492
493 self.x_1 = x_1
494 self.y_1 = y_1
495 self.x_2 = x_2
496 self.y_2 = y_2
497
498 @property
499 def height(self):
500 """
501 Calculate the height of the rectangle.
502
503 Returns:
504 :obj:`numeric`: Output the numeric value of the height.
505 """
506
507 return self.y_2 - self.y_1
508
509 @property
510 def width(self):
511 """
512 Calculate the width of the rectangle.
513
514 Returns:
515 :obj:`numeric`: Output the numeric value of the width.
516 """
517
518 return self.x_2 - self.x_1
519
520 @property
521 def coordinates(self):
522 """
523 Return the coordinates of the two points that define the rectangle.
524

Callers 15

test_rectangleFunction · 0.90
test_interval_relationsFunction · 0.90
test_rectangle_relationsFunction · 0.90
test_textblockFunction · 0.90
test_layoutFunction · 0.90
test_layout_compFunction · 0.90
test_shape_operationsFunction · 0.90
test_dictFunction · 0.90
test_jsonFunction · 0.90
test_csvFunction · 0.90

Calls

no outgoing calls

Tested by 12

test_rectangleFunction · 0.72
test_interval_relationsFunction · 0.72
test_rectangle_relationsFunction · 0.72
test_textblockFunction · 0.72
test_layoutFunction · 0.72
test_layout_compFunction · 0.72
test_shape_operationsFunction · 0.72
test_dictFunction · 0.72
test_jsonFunction · 0.72
test_csvFunction · 0.72
test_vizFunction · 0.68