Simple class that represents a point on a canvas using an x and y coordinate.
This class implements some basic methods to handle comparison, the splat operator and bounds checking that make it easier to work with coordinates.
@return [Regexp] The regexp to parse points from a string. @private
Compares 2 points.
It will first compare the y coordinate, and it only takes the x-coordinate into account if the y-coordinates of the points are identical. This way, an array of points will be sorted into the order in which they would occur in the pixels array returned by {ChunkyPNG::Canvas#pixels}.
@param [ChunkyPNG::Point] other The point to compare this point with. @return [-1, 0, 1] -1 If this point comes before the other one, 1
if after, and <tt>0</tt> if the points are identical.
# File lib/chunky_png/point.rb, line 94 def <=>(other) ((y <=> other.y) == 0) ? x <=> other.x : y <=> other.y end
Checks whether 2 points are identical. @return [true, false] true iff the x and y coordinates match
# File lib/chunky_png/point.rb, line 78 def eql?(other) other.x == x && other.y == y end
Converts the point instance to an array. @return [Array] A 2-element array, i.e. [x, y].
# File lib/chunky_png/point.rb, line 100 def to_a [x, y] end
Checks whether the point falls into a dimension @param [ChunkyPNG::Dimension, ...] dimension_like The dimension of which the bounds
should be taken for the check.
@return [true, false] true iff the x and y coordinate fall width the width
and height of the dimension.
# File lib/chunky_png/point.rb, line 111 def within_bounds?(*dimension_like) ChunkyPNG::Dimension(*dimension_like).include?(self) end
Generated with the Darkfish Rdoc Generator 2.