struct

CrImage::Point

Inherits Struct / Value / Object

A Point represents an (x, y) coordinate on the integer grid.

Coordinate system:

  • X-axis increases to the right
  • Y-axis increases downward
  • A Point is neither a pixel nor a grid square
  • A Point has no intrinsic width, height, or color

Example:

p1 = CrImage::Point.new(10, 20)
p2 = CrImage.point(30, 40) # Factory method
p3 = p1 + p2               # Point arithmetic

Constructors

from(tuple : Tuple(Int32, Int32)) : Point

Create Point from tuple

Source
new(x : Int32, y : Int32)
Source
new(tuple : Tuple(Int32, Int32)) : Point

Allow implicit conversion from tuple

Source

Class methods

zero
Source

Instance methods

*(o : Point)
Source
+(o : Point)
Source
-(o : Point)
Source
/(o : Point)
Source
eq(o : Point)
Source
in(r : Rectangle) : Bool

Reports whether this point is inside the given rectangle.

A point is considered inside if it satisfies:

  • r.min.x <= x < r.max.x
  • r.min.y <= y < r.max.y

Note: The max bounds are exclusive.

Source
mod(r : Rectangle) : Point

Returns the point q in Rectangle r such that p.x - q.x is a multiple of r's width and p.y - q.y is a multiple of r's height.

This is useful for wrapping coordinates within a rectangular region, similar to modulo arithmetic but for 2D coordinates.

Source
to_s(io : IO) : Nil

Same as #inspect(io).

Source
x=(x : Int32)
Source
y=(y : Int32)
Source