Sha256: ccc215a2b864e49fd3fdb0c2802e2e5838018a85a0dd82dfb469b7661f6899fb

Contents?: true

Size: 1.75 KB

Versions: 25

Compression:

Stored size: 1.75 KB

Contents

class Wx::Point
  # More informative output when converted to string
  def to_s
    "#<Wx::Point: (#{x}, #{y})>"
  end

  # Correct comparison for Points - same if same x and y
  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

  # Return a new Wx::Point with the x and y parameters both divided by
  # parameter +div+, which should be a Numeric
  def /(div)
    self.class.new( (get_x / div).to_i, (get_y / div).to_i )
  end

  # Return a new Wx::Point with the x and y values both multiplied by
  # parameter +mul+, which should be a Numeric
  def *(mul)
    self.class.new( (get_x * mul).to_i, (get_y * mul).to_i )
  end

  # 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.
  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

  # 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.
  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
end

Version data entries

25 entries across 25 versions & 3 rubygems

Version Path
wxruby64-2.0.1-x64-mingw32 lib/wx/classes/point.rb
wxruby-ruby19-2.0.1-x86-mingw32 lib/wx/classes/point.rb
wxruby-ruby19-2.0.1-x86-linux lib/wx/classes/point.rb
wxruby-ruby19-2.0.1-x86-darwin-9 lib/wx/classes/point.rb
wxruby-2.0.1-x86-mswin32-60 lib/wx/classes/point.rb
wxruby-2.0.1-x86-mingw32 lib/wx/classes/point.rb
wxruby-2.0.1-x86-linux lib/wx/classes/point.rb
wxruby-2.0.1-universal-darwin-9 lib/wx/classes/point.rb
wxruby-1.9.10-universal-darwin-9 lib/wx/classes/point.rb
wxruby-1.9.10-x86-linux lib/wx/classes/point.rb
wxruby-1.9.10-x86_64-linux lib/wx/classes/point.rb
wxruby-1.9.10-x86-mswin32-60 lib/wx/classes/point.rb
wxruby-1.9.10-x86-mingw32 lib/wx/classes/point.rb
wxruby-2.0.0-universal-darwin-9 lib/wx/classes/point.rb
wxruby-2.0.0-x86-mingw32 lib/wx/classes/point.rb
wxruby-2.0.0-x86-linux lib/wx/classes/point.rb
wxruby-2.0.0-x86-mswin32-60 lib/wx/classes/point.rb
wxruby-2.0.0-x86_64-linux lib/wx/classes/point.rb
wxruby-ruby19-1.9.10-x86-darwin-9 lib/wx/classes/point.rb
wxruby-ruby19-1.9.10-x86-mingw32 lib/wx/classes/point.rb