struct Point

Included Modules

Extended Modules

Defined in:

point.cr

Constant Summary

Direction4 = [Point.up, Point.left, Point.down, Point.right]
Direction8 = Direction4 + [Point.ul, Point.ur, Point.dl, Point.dr]

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from module Comparable(Point)

max(x : T) max, min(x : T) min

Constructor Detail

def self.[](y : Int, x : Int) : self #

[View source]
def self.from(array : Array) : self #

Creates point fomr given array.


[View source]
def self.new(y : Int, x : Int) #

[View source]
def self.new(i : Int) #

[View source]
def self.new #

[View source]
def self.scan(scanner, io : IO) : self #

[View source]

Class Method Detail

def self.dl #

[View source]
def self.down #

Returns Point.new(1, 0)


[View source]
def self.dr #

Returns Point.new(1, 1)


[View source]
def self.each(y : Int, w : Int) #

[View source]
def self.each(h : Int, w : Int, &) #

[View source]
def self.height : Int32 #

[View source]
def self.height? : Int32? #

[View source]
def self.left #

[View source]
def self.reset_range #

[View source]
def self.right #

Returns Point.new(0, 1)


[View source]
def self.set_range(height : Int, width : Int) #

[View source]
def self.size #

[View source]
def self.to_direction?(c : Char, lrud = "LRUD") #

Convert Char representing direction into Point.

Point.to_direction?('R') # => Point.new(0, 1)

[View source]
def self.to_direction?(s : String, lrud = "LRUD") #

Convert String representing direction into Point.

Point.to_direction?("DR") # => Point.new(1, 1)

[View source]
def self.ul #

[View source]
def self.unsafe_fetch(index : Int) #

[View source]
def self.up #

[View source]
def self.ur #

[View source]
def self.width : Int32 #

[View source]
def self.width? : Int32? #

[View source]
def self.zero #

Returns Point.new(0, 0)


[View source]

Instance Method Detail

def %(other : Point) #

[View source]
def %(other : Int) #

[View source]
def *(other : Point) #

[View source]
def *(other : Int) #

[View source]
def +(other : Point) #

[View source]
def +(other : Int) #

[View source]
def -(other : Point) #

[View source]
def -(other : Int) #

[View source]
def //(other : Point) #

[View source]
def //(other : Int) #

[View source]
def <=>(other : Point) #
Description copied from module Comparable(Point)

The comparison operator. Returns 0 if the two objects are equal, a negative number if this object is considered less than other, a positive number if this object is considered greter than other, or nil if the two objects are not comparable.

Subclasses define this method to provide class-specific ordering.

The comparison operator is usually used to sort values:

# Sort in a descending way:
[3, 1, 2].sort { |x, y| y <=> x } # => [3, 2, 1]

# Sort in an ascending way:
[3, 1, 2].sort { |x, y| x <=> y } # => [1, 2, 3]

[View source]
def ==(other : Point) #
Description copied from module Comparable(Point)

Compares this object to other based on the receiver’s #<=> method, returning true if it returns 0.

Also returns true if this and other are the same object.


[View source]
def [](i : Int) #

[View source]
def adj4_in_range(&) : Nil #

[View source]
def adj4_in_range #

[View source]
def adj8_in_range #

[View source]
def adj8_in_range(&) : Nil #

[View source]
def adjacent4(&) : Nil #

[View source]
def adjacent4 #

[View source]
def adjacent8 #

[View source]
def adjacent8(&) : Nil #

[View source]
def chebyshev(other : Point) #

[View source]
def cross(other : Point) #

[View source]
def distance(other : Point) #

[View source]
def distance_square(other : Point) #

[View source]
def dl #

Returns self + Point.new(1, -1)


[View source]
def dl! #

[View source]
def dot(other : Point) #

[View source]
def down #

Returns self + Point.new(1, 0)


[View source]
def down! #

[View source]
def dr #

Returns self + Point.new(1, 1)


[View source]
def dr! #

[View source]
def flip_horizontally #

Flips the grid horizontally.

.x.... ....x. ...... -> ...... .....y y.....


[View source]
def flip_horizontally! #

Flips the grid horizontally.

.x.... ....x. ...... -> ...... .....y y.....


[View source]
def flip_vertically #

Flips the grid vertically.

.x.... .....y ...... -> ...... .....y .x....


[View source]
def flip_vertically! #

Flips the grid vertically.

.x.... .....y ...... -> ...... .....y .x....


[View source]
def in_range? #

[View source]
def inspect(io : IO) : Nil #

Writes a string representation of the point to io.

Point.new(1, 2).inspect # => "(1, 2)"

[View source]
def left #

Returns self + Point.new(0, -1)


[View source]
def left! #

[View source]
def manhattan(other : Point) #

[View source]
def pred #

[View source]
def right #

Returns self + Point.new(0, 1)


[View source]
def right! #

[View source]
def rotate90 #

Rotates 90 degrees clockwise.

x.... ..x ..... -> ... ....y ...

       ...
       y..

[View source]
def rotate90! #

Rotates 90 degrees clockwise.

x.... ..x ..... -> ... ....y ...

       ...
       y..

[View source]
def succ #

[View source]
def to_direction_char?(lrud = "LRUD") : Char? #

Convert Point into Char representing direction.

Point.down.to_direction_char? # => 'D'
Point.left.to_direction_char? # => 'L'

[View source]
def to_i #

[View source]
def to_s(io : IO) : Nil #

Writes a string representation of the point to io.

Point.new(1, 2).to_s # => "(1, 2)"

[View source]
def ul #

Returns self + Point.new(-1, -1)


[View source]
def ul! #

[View source]
def up #

Returns self + Point.new(-1, 0)


[View source]
def up! #

[View source]
def ur #

Returns self + Point.new(-1, 1)


[View source]
def ur! #

[View source]
def x : Int32 #

[View source]
def x=(x : Int32) #

[View source]
def xy #

Returns Point.new(x, y)


[View source]
def y : Int32 #

[View source]
def y=(y : Int32) #

[View source]
def yx #

Returns Point.new(y, x)


[View source]
def zero #

Returns self + Point.new(0, 0)


[View source]
def zero! #

[View source]