Package pytilities :: Package geometry :: Module rectangle :: Class Rectangle
[hide private]
[frames] | no frames]

Class Rectangle

source code

object --+
         |
        Rectangle


A rectangle identified by two points.

The rectangle stores left, top, right, and bottom values.

Coordinates are based on screen coordinates.

origin                               top
   +-----> x increases                |
   |                           left  -+-  right
   v                                  |
y increases                         bottom

Instance methods:

    - `copy`: Make a shallow copy
    - `contains`: Is a vector inside?
    - `overlaps`: Does a rectangle overlap?
    - `inflate`: grow (or shrink)
    - `move_to`: move entire rectangle to a spot
    - `move_by`: move entire rectangle by an amount

Instance properties:

    - `bounds`: Read-write, all rectangle coordinates
    - `center`: Read-write, center of the rectangle
    - `width`: Read-write, width of the rectangle
    - `height`: Read-write, height of the rectangle
    - `size`: Read-write, size of the rectangle
    - `left`: Read-write, left edge of rectangle
    - `top`: Read-write, top edge of rectangle
    - `right`: Read-write, right edge of rectangle
    - `bottom`: Read-write, bottom edge of rectangle
    - `top_left`: Read-write, top-left corner
    - `top_right`: Read-write, top-right corner
    - `bottom_left`: Read-write, bottom-left corner
    - `bottom_right`: Read-write, bottom-right corner

Operators:

    str(s)
    repr(s)

Instance Methods [hide private]
 
__init__(self, *args)
Construct a rectangle.
source code
 
__copy__(self) source code
 
copy(self)
Returns shallow copy
source code
 
__set_bounds_numbers(self, left, top, right, bottom) source code
 
__set_bounds_points(self, top_left, bottom_right) source code
 
contains(self, v)
Returns `True` if `v` is inside the rectangle.
source code
 
overlaps(self, rect)
Returns `True` if `rect` overlaps with this rectangle.
source code
 
__inflate_number(self, n) source code
 
__inflate_vector(self, v) source code
 
inflate(*args, **kwargs)
Inflate the rectangle
source code
 
move_to(self, v)
Move the top_left corner to `v`, without changing size
source code
 
move_by(self, v)
Move the top_left corner by `v`, without changing size
source code
 
__str__(self)
str(x)
source code
 
__repr__(self)
repr(x)
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __subclasshook__

Properties [hide private]
  bounds
Read-write, all rectangle coordinates
  __center_x
  __center_y
  center
Read-write, center of the rectangle :: bound Vector
  width
Read-write, width of the rectangle :: float | int
  height
Read-write, height of the rectangle :: float | int
  size
Read-write, size of the rectangle :: bound Vector
  left
Read-write, left edge of rectangle :: float | int
  top
Read-write, top edge of rectangle :: float | int
  right
Read-write, right edge of rectangle :: float | int
  bottom
Read-write, bottom edge of rectangle :: float | int
  top_left
Read-write, top-left corner :: bound Vector
  top_right
Read-write, top-right corner :: bound Vector
  bottom_left
Read-write, bottom-left corner :: bound Vector
  bottom_right
Read-write, bottom-right corner :: bound Vector

Inherited from object: __class__

Method Details [hide private]

__init__(self, *args)
(Constructor)

source code 

Construct a rectangle.

Overloaded, parameters:

:a:
    `left` :: float | int
    `top` :: float | int
    `right` :: float | int
    `bottom` :: float | int

:b:
    `top_left` :: Vector
    `bottom_right` :: Vector

Overrides: object.__init__

contains(self, v)

source code 

Returns `True` if `v` is inside the rectangle.

Parameters:

    `v` :: Vector

overlaps(self, rect)

source code 

Returns `True` if `rect` overlaps with this rectangle.

Parameters:

    `rect` :: Rectangle

inflate(*args, **kwargs)

source code 

Inflate the rectangle

Overloaded, parameters:

:a:
    n :: number
        Extend all sides by n points
:b:
    v :: Vector
        extend left and right sides by v.x and top and bottom sides by
        v.y

Decorators:
  • @overloaded((Overload(__inflate_number, Param("n", NumberType)), Overload(__inflate_vector, Param("v"))))

move_to(self, v)

source code 

Move the top_left corner to `v`, without changing size

Parameters:

    `v` :: Vector
        the spot to move to

move_by(self, v)

source code 

Move the top_left corner by `v`, without changing size

Parameters:

    `v` :: Vector
        the amount to move by

__str__(self)
(Informal representation operator)

source code 

str(x)

Overrides: object.__str__
(inherited documentation)

__repr__(self)
(Representation operator)

source code 

repr(x)

Overrides: object.__repr__
(inherited documentation)

Property Details [hide private]

bounds

Read-write, all rectangle coordinates

Returns (left, top, right, bottom)

Overloaded, set parameters:

:a:
    `left` :: float | int
    `top` :: float | int
    `right` :: float | int
    `bottom` :: float | int

:b:
    `top_left` :: Vector
    `bottom_right` :: Vector

Get Method:
unreachable.bounds(self) - Read-write, all rectangle coordinates
Set Method:
unreachable.__overloaded(*args, **kwargs)

__center_x

Get Method:
unreachable.__center_x(self)
Set Method:
unreachable.__center_x(self, value)

__center_y

Get Method:
unreachable.__center_y(self)
Set Method:
unreachable.__center_y(self, value)

center


Read-write, center of the rectangle :: bound Vector

Changing the center does not change the size.

Get Method:
unreachable.center(self) - Read-write, center of the rectangle :: bound Vector
Set Method:
unreachable.center(self, v)

width

Read-write, width of the rectangle :: float | int

Get Method:
unreachable.width(self) - Read-write, width of the rectangle :: float | int
Set Method:
unreachable.width(self, value)

height

Read-write, height of the rectangle :: float | int

Get Method:
unreachable.height(self) - Read-write, height of the rectangle :: float | int
Set Method:
unreachable.height(self, value)

size

Read-write, size of the rectangle :: bound Vector

Get Method:
unreachable.size(self) - Read-write, size of the rectangle :: bound Vector
Set Method:
unreachable.size(self, value)

left

Read-write, left edge of rectangle :: float | int

Get Method:
unreachable.left(self) - Read-write, left edge of rectangle :: float | int
Set Method:
unreachable.left(self, value)

top

Read-write, top edge of rectangle :: float | int

Get Method:
unreachable.top(self) - Read-write, top edge of rectangle :: float | int
Set Method:
unreachable.top(self, value)

right

Read-write, right edge of rectangle :: float | int

Get Method:
unreachable.right(self) - Read-write, right edge of rectangle :: float | int
Set Method:
unreachable.right(self, value)

bottom

Read-write, bottom edge of rectangle :: float | int

Get Method:
unreachable.bottom(self) - Read-write, bottom edge of rectangle :: float | int
Set Method:
unreachable.bottom(self, value)

top_left

Read-write, top-left corner :: bound Vector

Get Method:
unreachable.top_left(self) - Read-write, top-left corner :: bound Vector
Set Method:
unreachable.top_left(self, value)

top_right

Read-write, top-right corner :: bound Vector

Get Method:
unreachable.top_right(self) - Read-write, top-right corner :: bound Vector
Set Method:
unreachable.top_right(self, value)

bottom_left

Read-write, bottom-left corner :: bound Vector

Get Method:
unreachable.bottom_left(self) - Read-write, bottom-left corner :: bound Vector
Set Method:
unreachable.bottom_left(self, value)

bottom_right

Read-write, bottom-right corner :: bound Vector

Get Method:
unreachable.bottom_right(self) - Read-write, bottom-right corner :: bound Vector
Set Method:
unreachable.bottom_right(self, value)