Module: Sevgi::Geometry::Affinity

Included in:
Point
Defined in:
lib/sevgi/geometry/point.rb

Overview

Affine transforms shared by immutable geometry tuples.

Instance Method Summary collapse

Instance Method Details

#reflect(x: true, y: true) ⇒ Sevgi::Geometry::Point

Reflects a point across the selected axes.

x: controls reflection across the x-axis, which negates y. y: controls reflection across the y-axis, which negates x.

Parameters:

  • x (Boolean) (defaults to: true)

    reflect across the x-axis

  • y (Boolean) (defaults to: true)

    reflect across the y-axis

Returns:



14
# File 'lib/sevgi/geometry/point.rb', line 14

def reflect(x: true, y: true) = with(x: (y ? -1 : 1) * self.x(), y: (x ? -1 : 1) * self.y())

#rotate(a) ⇒ Sevgi::Geometry::Point

Rotates a point around the origin using screen-space degrees.

Parameters:

  • a (Numeric)

    clockwise angle in degrees

Returns:



19
# File 'lib/sevgi/geometry/point.rb', line 19

def rotate(a) = with(x: (x * F.cos(a)) - (y * F.sin(a)), y: (x * F.sin(a)) + (y * F.cos(a)))

#scale(sx, sy = Undefined) ⇒ Sevgi::Geometry::Point

Scales a point from the origin.

Parameters:

  • sx (Numeric)

    x scale factor

  • sy (Numeric, Sevgi::Undefined) (defaults to: Undefined)

    y scale factor, defaulting to sx

Returns:



25
# File 'lib/sevgi/geometry/point.rb', line 25

def scale(sx, sy = Undefined) = with(x: sx * x, y: Undefined.default(sy, sx) * y)

#skew(ax, ay = Undefined) ⇒ Sevgi::Geometry::Point

Skews a point from the origin.

Parameters:

  • ax (Numeric)

    x-axis skew angle in degrees

  • ay (Numeric, Sevgi::Undefined) (defaults to: Undefined)

    y-axis skew angle in degrees, defaulting to ax

Returns:



31
# File 'lib/sevgi/geometry/point.rb', line 31

def skew(ax, ay = Undefined) = with(x: x + (y * F.tan(ax)), y: y + (x * F.tan(Undefined.default(ay, ax))))

#skew_x(a) ⇒ Sevgi::Geometry::Point

Skews a point along x.

Parameters:

  • a (Numeric)

    skew angle in degrees

Returns:



36
# File 'lib/sevgi/geometry/point.rb', line 36

def skew_x(a) = with(x: x + (y * F.tan(a)))

#skew_y(a) ⇒ Sevgi::Geometry::Point

Skews a point along y.

Parameters:

  • a (Numeric)

    skew angle in degrees

Returns:



41
# File 'lib/sevgi/geometry/point.rb', line 41

def skew_y(a) = with(y: y + (x * F.tan(a)))

#translate(dx, dy = Undefined) ⇒ Sevgi::Geometry::Point

Translates a point.

Parameters:

  • dx (Numeric)

    x offset

  • dy (Numeric, Sevgi::Undefined) (defaults to: Undefined)

    y offset, defaulting to dx

Returns:



47
# File 'lib/sevgi/geometry/point.rb', line 47

def translate(dx, dy = Undefined) = with(x: x + dx, y: y + Undefined.default(dy, dx))