ordec.core.geoprim — Geometric primitives

Geometric primitive types: vectors, matrices, orientations and rotations (D4)

2D vectors

class ordec.core.geoprim.Vec2Generic(x, y)

2D vector, typically representing a point / vertex in 2D space.

property x

x scalar component.

property y

y scalar component.

tofloat() tuple[float, float]

Returns (x, y) tuple of floats.

class ordec.core.geoprim.Vec2R(x, y)

2D vector with rational (ordec.core.rational.R) components.

transl() TD4R

Returns translation by vector.

class ordec.core.geoprim.Vec2I(x, y)

2D vector with integer components.

transl() TD4

Returns translation by vector.

Rectangle types

class ordec.core.geoprim.Rect4Generic(lx, ly, ux, uy)

Rectangle in 2D space.

../_images/geoprim_rect.svg

“Geographic” helper methods, each returning a 2D vector.

property lx

lower x coordinate.

property ly

lower y coordinate.

property ux

upper x coordinate.

property uy

upper y coordinate.

property cx

x coodinate centered between lx and ux.

property cy

y coodinate centered between ly and uy.

property height

height scalar (uy - ly).

property width

height scalar (ux - lx).

tofloat() tuple[float, float, float, float]

Returns (lx, ly, ux, uy) tuple of floats.

property northwest

(lx, uy) vector.

property north

(cx, uy) vector.

property northeast

(ux, uy) vector.

property west

(lx, cy) vector.

property center

(cx, cy) vector.

property east

(ux, cy) vector.

property southwest

(lx, ly) vector.

property south

(cx, ly) vector.

property southeast

(ux, ly) vector.

property x_extent

(lx, ux) vector.

property y_extent

(ly, uy) vector.

property size

(width, height) vector.

extend(vertex)

Returns the smallest rectangle that contains both the original rectangle and the provided vertex.

class ordec.core.geoprim.Rect4R(lx: Rational, ly: Rational, ux: Rational, uy: Rational)

2D rectangle with rational (ordec.core.rational.R) components.

class ordec.core.geoprim.Rect4I(lx: int, ly: int, ux: int, uy: int)

2D rectangle with integer components.

2D Translation, X/Y mirroring and 90° rotation

class ordec.core.geoprim.TD4(transl=None, d4=None)

Transformation group supporting 2D translation, X/Y mirroring and 90° rotations. Multiply instances of this class with a Vec2R, Rect4R or TD4 to apply the transformation.

property transl

Translation vector.

property d4: D4

Rotation / flip setting.

det() int

Returns determinant: 1 if handedness is preserved, -1 if flipped.

arc(angle_start: Rational, angle_end: Rational'>, <class 'ordec.core.rational.Rational'>)

Rotates an arc / pair of angles (angle_start, angle_end). R(1) = 360° = 2pi

svg_transform(x_scale=1, y_scale=1) str

Returns a string representation of the transformation suitable for the SVG attribute “transform”.

class ordec.core.geoprim.D4(value)

Dihedral group D4, supporting X/Y mirroring and 90° rotations.

../_images/geoprim_D4.svg

Elements of the dihedral group D4 applied to a half arrow.

R0 = (False, False, False)

rotation by 0° (identity element)

R90 = (True, True, False)

rotation by 90°

R180 = (False, True, True)

rotation by 180°

R270 = (True, False, True)

rotation by 270°

MX = (False, False, True)

mirror along X axis (flipping Y coordinate)

MY = (False, True, False)

mirror along Y axis (flipping X coordinate)

MX90 = (True, False, False)

mirror along X axis, followed by 90° rotation

MY90 = (True, True, True)

mirror along Y axis, followed by 90° rotation

unflip() D4

Return D4 element with non-flipped handedness (det=1), preserving the vertex (x=0, y=1).

det() int

Returns determinant: 1 if handedness is preserved, -1 if flipped.

inv() D4

Returns D4 such that x.inv()*x == x*x.inv() == D4.R0.

flip() Self

Returns TD4 with flipped handedness, preserving the vertex (0, 1).

ordec.core.geoprim.Orientation

alias of D4