Class: Wx::Point

Inherits:
Object
  • Object
show all
Defined in:
lib/wx/classes/point.rb

Instance Method Summary collapse

Instance Method Details

#*(mul) ⇒ Object

Return a new Wx::Point with the x and y values both multiplied by parameter mul, which should be a Numeric



23
24
25
# File 'lib/wx/classes/point.rb', line 23

def *(mul)
  self.class.new( (get_x * mul).to_i, (get_y * mul).to_i )
end

#+(arg) ⇒ Object

Return a new Wx::Point with the x and y values both increased by parameter arg. If arg is another Wx::Point, increase x by the other’s x and y by the other’s y; if arg is a numeric value, increase both x and y by that value.



46
47
48
49
50
51
52
53
54
55
# File 'lib/wx/classes/point.rb', line 46

def +(arg)
  case arg
  when self.class
    self.class.new( get_x + arg.get_x, get_y + arg.get_y )
  when Numeric
    self.class.new( (get_x + arg).to_i, (get_y + arg).to_i )
  else
    Kernel.raise TypeError, "Cannot add #{arg} to #{self.inspect}"
  end
end

#-(arg) ⇒ Object

Return a new Wx::Point with the x and y values both reduced by parameter arg. If arg is another Wx::Point, reduce x by the other’s x and y by the other’s y; if arg is a numeric value, reduce x and y both by that value.



31
32
33
34
35
36
37
38
39
40
# File 'lib/wx/classes/point.rb', line 31

def -(arg)
  case arg
  when self.class
    self.class.new( get_x - arg.get_x, get_y - arg.get_y )
  when Numeric
    self.class.new( (get_x - arg).to_i, (get_y - arg).to_i )
  else
    Kernel.raise TypeError, "Cannot add #{arg} to #{self.inspect}"
  end
end

#/(div) ⇒ Object

Return a new Wx::Point with the x and y parameters both divided by parameter div, which should be a Numeric



17
18
19
# File 'lib/wx/classes/point.rb', line 17

def /(div)
  self.class.new( (get_x / div).to_i, (get_y / div).to_i )
end

#==(other) ⇒ Object

Correct comparison for Points - same if same x and y



8
9
10
11
12
13
# File 'lib/wx/classes/point.rb', line 8

def ==(other)
  unless other.kind_of?(Wx::Point)
    Kernel.raise TypeError, "Cannot compare Point to #{other}"
  end
  x == other.x and y == other.y
end

#to_sObject

More informative output when converted to string



3
4
5
# File 'lib/wx/classes/point.rb', line 3

def to_s
  "#<Wx::Point: (#{x}, #{y})>"
end