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
-
#reflect(x: true, y: true) ⇒ Sevgi::Geometry::Point
Reflects a point across the selected axes.
-
#rotate(a) ⇒ Sevgi::Geometry::Point
Rotates a point around the origin using screen-space degrees.
-
#scale(sx, sy = Undefined) ⇒ Sevgi::Geometry::Point
Scales a point from the origin.
-
#skew(ax, ay = Undefined) ⇒ Sevgi::Geometry::Point
Skews a point from the origin.
-
#skew_x(a) ⇒ Sevgi::Geometry::Point
Skews a point along x.
-
#skew_y(a) ⇒ Sevgi::Geometry::Point
Skews a point along y.
-
#translate(dx, dy = Undefined) ⇒ Sevgi::Geometry::Point
Translates a point.
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.
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.
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.
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.
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.
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.
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.
47 |
# File 'lib/sevgi/geometry/point.rb', line 47 def translate(dx, dy = Undefined) = with(x: x + dx, y: y + Undefined.default(dy, dx)) |