Class: ChunkyPNG::Point

### Home Classes Methods

### In Files

- lib/chunky_png/point.rb

### Parent

Object

### Methods

- ::new
- #<=>
- #==
- #eql?
- #to_a
- #to_ary
- #within_bounds?

### Files

- BENCHMARKING.rdoc
- CHANGELOG.rdoc
- CONTRIBUTING.rdoc
- README.rdoc

### Class/Module Index

Quicksearch

- ChunkyPNG
- ChunkyPNG::CRCMismatch
- ChunkyPNG::Canvas
- ChunkyPNG::Canvas::Adam7Interlacing
- ChunkyPNG::Canvas::DataUrlExporting
- ChunkyPNG::Canvas::DataUrlImporting
- ChunkyPNG::Canvas::Drawing
- ChunkyPNG::Canvas::Masking
- ChunkyPNG::Canvas::Operations
- ChunkyPNG::Canvas::PNGDecoding
- ChunkyPNG::Canvas::PNGEncoding
- ChunkyPNG::Canvas::Resampling
- ChunkyPNG::Canvas::StreamExporting
- ChunkyPNG::Canvas::StreamImporting
- ChunkyPNG::Chunk
- ChunkyPNG::Chunk::Base
- ChunkyPNG::Chunk::CompressedText
- ChunkyPNG::Chunk::End
- ChunkyPNG::Chunk::Generic
- ChunkyPNG::Chunk::Header
- ChunkyPNG::Chunk::ImageData
- ChunkyPNG::Chunk::InternationalText
- ChunkyPNG::Chunk::Palette
- ChunkyPNG::Chunk::Text
- ChunkyPNG::Chunk::Transparency
- ChunkyPNG::Color
- ChunkyPNG::Datastream
- ChunkyPNG::Dimension
- ChunkyPNG::Exception
- ChunkyPNG::ExpectationFailed
- ChunkyPNG::Image
- ChunkyPNG::NotSupported
- ChunkyPNG::OutOfBounds
- ChunkyPNG::Palette
- ChunkyPNG::Point
- ChunkyPNG::RMagick
- ChunkyPNG::SignatureMismatch
- ChunkyPNG::Vector
- Enumerable
- String

No matching classes.

# ChunkyPNG::Point

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.

@see ChunkyPNG.Point

### Constants

POINT_REGEXP

  @return [Regexp] The regexp to parse points from a string. @private

### Attributes

x[RW]

@return [Integer] The x-coordinate of the point.

y[RW]

@return [Integer] The y-coordinate of the point.

### Public Class Methods

new(x, y) click to toggle source

Initializes a new point instance. @param [Integer, :to_i] x The x-coordinate. @param [Integer, :to_i] y The y-coordinate.

    # File lib/chunky_png/point.rb, line 86
    def initialize(x, y)
      @x, @y = x.to_i, y.to_i
    end

### Public Instance Methods

<=>(other) click to toggle source

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 108
    def <=>(other)
      ((y <=> other.y) == 0) ? x <=> other.x : y <=> other.y
    end

==(other) click to toggle source
Alias for: eql?
eql?(other) click to toggle source

Checks whether 2 points are identical. @return [true, false] `true` iff the x and y coordinates match

    # File lib/chunky_png/point.rb, line 92
    def eql?(other)
      other.x == x && other.y == y
    end

Also aliased as: ==
to_a() click to toggle source

Converts the point instance to an array. @return [Array] A 2-element array, i.e. `[x, y]`.

    # File lib/chunky_png/point.rb, line 114
    def to_a
      [x, y]
    end

Also aliased as: to_ary
to_ary() click to toggle source
Alias for: to_a
within_bounds?(*dimension_like) click to toggle source

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 125
    def within_bounds?(*dimension_like)
      ChunkyPNG::Dimension(*dimension_like).include?(self)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.