2.1.1. Positions and Sizes (layout.datatypes.position)

class layout.datatypes.position.Point

Bases: layout.datatypes.position.Point

A single point in space, or a vector in 2D.

get_angle()

Returns the CCW angle from the positive X-axis (i.e. that returned from atan2.

get_angle_between(other)

Returns the smallest angle between this vector and the given other vector.

get_component_product(other)

Returns the component product of this vector and the given other vector.

get_copy()

Returns a copy of this vector.

get_left_normal()

Returns the left hand normal of this vector: the vector produced by rotating this vector about ninety degrees anti-clockwise.

get_magnitude()

Returns the magnitude of this vector.

get_magnitude_squared()

Returns the square of the magnitude of this vector.

get_maximum(other)

Updates this vector so its components are the higher of its current components and those of the given other value.

get_minimum(other)

Updates this vector so its components are the lower of its current components and those of the given other value.

get_normalized()

Returns a vector of unit length, unless it is the zero vector, in which case it is left as is.

static get_random(min_pt, max_pt)

Returns a random vector in the given range.

get_right_normal()

Returns the right hand normal of this vector: the vector produced by rotating this vector about ninety degrees clockwise.

get_rotated(angle)

Rotates this vector through the given anti-clockwise angle in radians.

get_scalar_product(other)

Returns the scalar product of this vector with the given other vector.

get_x_mirror()

Returns a copy of this vector reflected in the x=0 axis.

get_y_mirror()

Returns a copy of this vector reflected in the y=0 axis.

class layout.datatypes.position.Rectangle(x, y, w, h)

Bases: object

A rectangle in two dimensional space.

The data in this rectangle can be accessed in many different ways. It has data members of x, y, w, and h, and properties corresponding to all combinations of left (which equals x), right, top, bottom (which equals y), center (horizontal) and middle (vertical). Pair combinations (such as top_right) return a Point, while single values (such as center) return a number. You can also abbreviate each of the properties using its initial letter.

So to access the center point of the rectangle, for example, you use any of the properties:

  • Rectangle.cm
  • Rectangle.mc
  • Rectangle.center_middle
  • Rectangle.middle_center

And to access just the right-hand coordinate, you can use:

  • Rectangle.right
  • Rectangle.r
get_data()

Returns the x, y, w, h, data as a tuple.