struct Point
- Point
- Struct
- Value
- Object
Included Modules
Extended Modules
Defined in:
point.crConstant Summary
-
Direction4 =
[Point.up, Point.left, Point.down, Point.right]
-
Direction8 =
Direction4 + [Point.ul, Point.ur, Point.dl, Point.dr]
Constructors
-
.[](y : Int, x : Int) : self
Alias for
.new(y : Int, x : Int)
-
.from(array : Array) : self
Creates point fomr given array.
- .new(y : Int, x : Int)
- .new(i : Int)
- .new
- .scan(scanner, io : IO) : self
Class Method Summary
-
.dl
Returns
Point.new(1, -1)
-
.down
Returns
Point.new(1, 0)
-
.dr
Returns
Point.new(1, 1)
- .each(y : Int, w : Int)
- .each(h : Int, w : Int, &)
- .height : Int32
- .height? : Int32?
-
.left
Returns
Point.new(0, -1)
- .reset_range
-
.right
Returns
Point.new(0, 1)
- .set_range(height : Int, width : Int)
- .size
-
.to_direction?(c : Char, lrud = "LRUD")
Convert
Char
representing direction intoPoint
. - .to_direction?(s : String, lrud = "LRUD")
-
.ul
Returns
Point.new(-1, -1)
- .unsafe_fetch(index : Int)
-
.up
Returns
Point.new(-1, 0)
-
.ur
Returns
Point.new(-1, 1)
- .width : Int32
- .width? : Int32?
-
.zero
Returns
Point.new(0, 0)
Instance Method Summary
- #%(other : Point)
- #%(other : Int)
- #*(other : Point)
- #*(other : Int)
- #+(other : Point)
- #+(other : Int)
- #-(other : Point)
- #-(other : Int)
- #//(other : Point)
- #//(other : Int)
-
#<=>(other : Point)
The comparison operator.
-
#==(other : Point)
Compares this object to other based on the receiver’s
#<=>
method, returningtrue
if it returns0
. - #[](i : Int)
- #adj4_in_range(&) : Nil
- #adj4_in_range
- #adj8_in_range
- #adj8_in_range(&) : Nil
- #adjacent4(&) : Nil
- #adjacent4
- #adjacent8
- #adjacent8(&) : Nil
- #chebyshev(other : Point)
- #cross(other : Point)
- #distance(other : Point)
- #distance_square(other : Point)
-
#dl
Returns
self + Point.new(1, -1)
-
#dl!
Adds
Point.new(1, -1)
- #dot(other : Point)
-
#down
Returns
self + Point.new(1, 0)
-
#down!
Adds
Point.new(1, 0)
-
#dr
Returns
self + Point.new(1, 1)
-
#dr!
Adds
Point.new(1, 1)
-
#flip_horizontally
Flips the grid horizontally.
-
#flip_horizontally!
Flips the grid horizontally.
-
#flip_vertically
Flips the grid vertically.
-
#flip_vertically!
Flips the grid vertically.
- #in_range?
-
#inspect(io : IO) : Nil
Writes a string representation of the point to io.
-
#left
Returns
self + Point.new(0, -1)
-
#left!
Adds
Point.new(0, -1)
- #manhattan(other : Point)
- #pred
-
#right
Returns
self + Point.new(0, 1)
-
#right!
Adds
Point.new(0, 1)
-
#rotate90
Rotates 90 degrees clockwise.
-
#rotate90!
Rotates 90 degrees clockwise.
- #succ
-
#to_direction_char?(lrud = "LRUD") : Char?
Convert
Point
intoChar
representing direction. - #to_i
-
#to_s(io : IO) : Nil
Writes a string representation of the point to io.
-
#ul
Returns
self + Point.new(-1, -1)
-
#ul!
Adds
Point.new(-1, -1)
-
#up
Returns
self + Point.new(-1, 0)
-
#up!
Adds
Point.new(-1, 0)
-
#ur
Returns
self + Point.new(-1, 1)
-
#ur!
Adds
Point.new(-1, 1)
- #x : Int32
- #x=(x : Int32)
-
#xy
Returns
Point.new(x, y)
- #y : Int32
- #y=(y : Int32)
-
#yx
Returns
Point.new(y, x)
-
#zero
Returns
self + Point.new(0, 0)
-
#zero!
Adds
Point.new(0, 0)
Constructor Detail
Class Method Detail
Convert Char
representing direction into Point
.
Point.to_direction?('R') # => Point.new(0, 1)
Instance Method Detail
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]
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.
Writes a string representation of the point to io.
Point.new(1, 2).inspect # => "(1, 2)"
Convert Point
into Char
representing direction.
Point.down.to_direction_char? # => 'D'
Point.left.to_direction_char? # => 'L'
Writes a string representation of the point to io.
Point.new(1, 2).to_s # => "(1, 2)"