python-igraph manual

For using igraph from Python

   Home       Trees       Indices       Help   
Package igraph :: Package drawing :: Module utils :: Class Rectangle
[hide private]

Class Rectangle

source code

object --+
         |
        Rectangle
Known Subclasses:

Class representing a rectangle.

Instance Methods [hide private]
 
__init__(self, *args)
Creates a rectangle.
source code
 
contract(self, margins)
Contracts the rectangle by the given margins.
source code
 
expand(self, margins)
Expands the rectangle by the given margins.
source code
 
isdisjoint(self, other)
Returns ``True`` if the two rectangles have no intersection.
source code
 
isempty(self)
Returns ``True`` if the rectangle is empty (i.e.
source code
 
intersection(self, other)
Returns the intersection of this rectangle with another.
source code
 
__and__(self, other)
Returns the intersection of this rectangle with another.
source code
 
translate(self, dx, dy)
Translates the rectangle in-place.
source code
 
union(self, other)
Returns the union of this rectangle with another.
source code
 
__or__(self, other)
Returns the union of this rectangle with another.
source code
 
__ior__(self, other)
Expands this rectangle to include itself and another completely while still being as small as possible.
source code
 
__repr__(self)
repr(x)
source code
 
__eq__(self, other) source code
 
__ne__(self, other) source code
 
__bool__(self) source code
 
__nonzero__(self) source code
 
__hash__(self)
hash(x)
source code

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

Properties [hide private]
  coords
The coordinates of the corners.
  width
The width of the rectangle
  height
The height of the rectangle
  left
The X coordinate of the left side of the box
  right
The X coordinate of the right side of the box
  top
The Y coordinate of the top edge of the box
  bottom
The Y coordinate of the bottom edge of the box
  midx
The X coordinate of the center of the box
  midy
The Y coordinate of the center of the box
  shape
The shape of the rectangle (width, height)
  _bottom
  _left
  _right
  _top

Inherited from object: __class__

Method Details [hide private]

__init__(self, *args)
(Constructor)

source code 

Creates a rectangle.

The corners of the rectangle can be specified by either a tuple (four items, two for each corner, respectively), four separate numbers (X and Y coordinates for each corner) or two separate numbers (width and height, the upper left corner is assumed to be at (0,0))

Overrides: object.__init__

contract(self, margins)

source code 

Contracts the rectangle by the given margins.

Returns:
a new Rectangle object.

expand(self, margins)

source code 

Expands the rectangle by the given margins.

Returns:
a new Rectangle object.

isdisjoint(self, other)

source code 

Returns ``True`` if the two rectangles have no intersection.

Example:

   >>> r1 = Rectangle(10, 10, 30, 30)
   >>> r2 = Rectangle(20, 20, 50, 50)
   >>> r3 = Rectangle(70, 70, 90, 90)
   >>> r1.isdisjoint(r2)
   False
   >>> r2.isdisjoint(r1)
   False
   >>> r1.isdisjoint(r3)
   True
   >>> r3.isdisjoint(r1)
   True

isempty(self)

source code 

Returns ``True`` if the rectangle is empty (i.e. it has zero width and height).

Example:

   >>> r1 = Rectangle(10, 10, 30, 30)
   >>> r2 = Rectangle(70, 70, 90, 90)
   >>> r1.isempty()
   False
   >>> r2.isempty()
   False
   >>> r1.intersection(r2).isempty()
   True

intersection(self, other)

source code 

Returns the intersection of this rectangle with another.

Example:

   >>> r1 = Rectangle(10, 10, 30, 30)
   >>> r2 = Rectangle(20, 20, 50, 50)
   >>> r3 = Rectangle(70, 70, 90, 90)
   >>> r1.intersection(r2)
   Rectangle(20.0, 20.0, 30.0, 30.0)
   >>> r2 & r1
   Rectangle(20.0, 20.0, 30.0, 30.0)
   >>> r2.intersection(r1) == r1.intersection(r2)
   True
   >>> r1.intersection(r3)
   Rectangle(0.0, 0.0, 0.0, 0.0)

__and__(self, other)
(And operator)

source code 

Returns the intersection of this rectangle with another.

Example:

   >>> r1 = Rectangle(10, 10, 30, 30)
   >>> r2 = Rectangle(20, 20, 50, 50)
   >>> r3 = Rectangle(70, 70, 90, 90)
   >>> r1.intersection(r2)
   Rectangle(20.0, 20.0, 30.0, 30.0)
   >>> r2 & r1
   Rectangle(20.0, 20.0, 30.0, 30.0)
   >>> r2.intersection(r1) == r1.intersection(r2)
   True
   >>> r1.intersection(r3)
   Rectangle(0.0, 0.0, 0.0, 0.0)

translate(self, dx, dy)

source code 

Translates the rectangle in-place.

Example:

>>> r = Rectangle(10, 20, 50, 70)
>>> r.translate(30, -10)
>>> r
Rectangle(40.0, 10.0, 80.0, 60.0)
Parameters:
  • dx - the X coordinate of the translation vector
  • dy - the Y coordinate of the translation vector

union(self, other)

source code 

Returns the union of this rectangle with another.

The resulting rectangle is the smallest rectangle that contains both rectangles.

Example:

   >>> r1 = Rectangle(10, 10, 30, 30)
   >>> r2 = Rectangle(20, 20, 50, 50)
   >>> r3 = Rectangle(70, 70, 90, 90)
   >>> r1.union(r2)
   Rectangle(10.0, 10.0, 50.0, 50.0)
   >>> r2 | r1
   Rectangle(10.0, 10.0, 50.0, 50.0)
   >>> r2.union(r1) == r1.union(r2)
   True
   >>> r1.union(r3)
   Rectangle(10.0, 10.0, 90.0, 90.0)

__or__(self, other)
(Or operator)

source code 

Returns the union of this rectangle with another.

The resulting rectangle is the smallest rectangle that contains both rectangles.

Example:

   >>> r1 = Rectangle(10, 10, 30, 30)
   >>> r2 = Rectangle(20, 20, 50, 50)
   >>> r3 = Rectangle(70, 70, 90, 90)
   >>> r1.union(r2)
   Rectangle(10.0, 10.0, 50.0, 50.0)
   >>> r2 | r1
   Rectangle(10.0, 10.0, 50.0, 50.0)
   >>> r2.union(r1) == r1.union(r2)
   True
   >>> r1.union(r3)
   Rectangle(10.0, 10.0, 90.0, 90.0)

__ior__(self, other)

source code 

Expands this rectangle to include itself and another completely while still being as small as possible.

Example:

   >>> r1 = Rectangle(10, 10, 30, 30)
   >>> r2 = Rectangle(20, 20, 50, 50)
   >>> r3 = Rectangle(70, 70, 90, 90)
   >>> r1 |= r2
   >>> r1
   Rectangle(10.0, 10.0, 50.0, 50.0)
   >>> r1 |= r3
   >>> r1
   Rectangle(10.0, 10.0, 90.0, 90.0)

__repr__(self)
(Representation operator)

source code 

repr(x)

Overrides: object.__repr__
(inherited documentation)

__hash__(self)
(Hashing function)

source code 

hash(x)

Overrides: object.__hash__
(inherited documentation)

Property Details [hide private]

coords

The coordinates of the corners.

The coordinates are returned as a 4-tuple in the following order: left edge, top edge, right edge, bottom edge.

Get Method:
unreachable.coords(self) - The coordinates of the corners.
Set Method:
unreachable.coords(self, coords) - Sets the coordinates of the corners.

width

The width of the rectangle

Get Method:
unreachable.width(self) - The width of the rectangle
Set Method:
unreachable.width(self, value) - Sets the width of the rectangle by adjusting the right edge.

height

The height of the rectangle

Get Method:
unreachable.height(self) - The height of the rectangle
Set Method:
unreachable.height(self, value) - Sets the height of the rectangle by adjusting the bottom edge.

left

The X coordinate of the left side of the box

Get Method:
unreachable.left(self) - The X coordinate of the left side of the box
Set Method:
unreachable.left(self, value) - Sets the X coordinate of the left side of the box

right

The X coordinate of the right side of the box

Get Method:
unreachable.right(self) - The X coordinate of the right side of the box
Set Method:
unreachable.right(self, value) - Sets the X coordinate of the right side of the box

top

The Y coordinate of the top edge of the box

Get Method:
unreachable.top(self) - The Y coordinate of the top edge of the box
Set Method:
unreachable.top(self, value) - Sets the Y coordinate of the top edge of the box

bottom

The Y coordinate of the bottom edge of the box

Get Method:
unreachable.bottom(self) - The Y coordinate of the bottom edge of the box
Set Method:
unreachable.bottom(self, value) - Sets the Y coordinate of the bottom edge of the box

midx

The X coordinate of the center of the box

Get Method:
unreachable.midx(self) - The X coordinate of the center of the box
Set Method:
unreachable.midx(self, value) - Moves the center of the box to the given X coordinate

midy

The Y coordinate of the center of the box

Get Method:
unreachable.midy(self) - The Y coordinate of the center of the box
Set Method:
unreachable.midy(self, value) - Moves the center of the box to the given Y coordinate

shape

The shape of the rectangle (width, height)

Get Method:
unreachable.shape(self) - The shape of the rectangle (width, height)
Set Method:
unreachable.shape(self, shape) - Sets the shape of the rectangle (width, height).

   Home       Trees       Indices       Help