Class: GD2::Canvas::Point

Inherits:
Object
  • Object
show all
Defined in:
lib/gd2/canvas.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y) ⇒ Point

Returns a new instance of Point


15
16
17
# File 'lib/gd2/canvas.rb', line 15

def initialize(x, y)
  @x, @y = x, y
end

Instance Attribute Details

#xObject (readonly)

Returns the value of attribute x


13
14
15
# File 'lib/gd2/canvas.rb', line 13

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y


13
14
15
# File 'lib/gd2/canvas.rb', line 13

def y
  @y
end

Instance Method Details

#coordinatesObject


19
20
21
# File 'lib/gd2/canvas.rb', line 19

def coordinates
  [@x, @y]
end

#draw(image, mode) ⇒ Object


32
33
34
# File 'lib/gd2/canvas.rb', line 32

def draw(image, mode)
  image.set_pixel(@x, @y, mode)
end

#transform(matrix) ⇒ Object


28
29
30
# File 'lib/gd2/canvas.rb', line 28

def transform(matrix)
  dup.transform!(matrix)
end

#transform!(matrix) ⇒ Object


23
24
25
26
# File 'lib/gd2/canvas.rb', line 23

def transform!(matrix)
  @x, @y = (Matrix.row_vector([@x, @y, 1]) * matrix)[0, 0..1]
  self
end