Class: Skia::Point
- Inherits:
-
Object
- Object
- Skia::Point
- Defined in:
- lib/skia/point.rb
Instance Attribute Summary collapse
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Class Method Summary collapse
Instance Method Summary collapse
- #*(other) ⇒ Object
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #-@ ⇒ Object
- #/(other) ⇒ Object
- #==(other) ⇒ Object
-
#initialize(x = 0.0, y = 0.0) ⇒ Point
constructor
A new instance of Point.
- #length ⇒ Object
- #normalize ⇒ Object
- #to_a ⇒ Object
- #to_struct ⇒ Object
Constructor Details
#initialize(x = 0.0, y = 0.0) ⇒ Point
7 8 9 10 |
# File 'lib/skia/point.rb', line 7 def initialize(x = 0.0, y = 0.0) @x = x.to_f @y = y.to_f end |
Instance Attribute Details
#x ⇒ Object
Returns the value of attribute x.
5 6 7 |
# File 'lib/skia/point.rb', line 5 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
5 6 7 |
# File 'lib/skia/point.rb', line 5 def y @y end |
Class Method Details
.from_struct(struct) ⇒ Object
12 13 14 |
# File 'lib/skia/point.rb', line 12 def self.from_struct(struct) new(struct[:x], struct[:y]) end |
Instance Method Details
#*(other) ⇒ Object
31 32 33 |
# File 'lib/skia/point.rb', line 31 def *(other) self.class.new(@x * other, @y * other) end |
#+(other) ⇒ Object
23 24 25 |
# File 'lib/skia/point.rb', line 23 def +(other) self.class.new(@x + other.x, @y + other.y) end |
#-(other) ⇒ Object
27 28 29 |
# File 'lib/skia/point.rb', line 27 def -(other) self.class.new(@x - other.x, @y - other.y) end |
#-@ ⇒ Object
39 40 41 |
# File 'lib/skia/point.rb', line 39 def -@ self.class.new(-@x, -@y) end |
#/(other) ⇒ Object
35 36 37 |
# File 'lib/skia/point.rb', line 35 def /(other) self.class.new(@x / other, @y / other) end |
#==(other) ⇒ Object
54 55 56 57 58 |
# File 'lib/skia/point.rb', line 54 def ==(other) return false unless other.is_a?(Point) @x == other.x && @y == other.y end |
#length ⇒ Object
43 44 45 |
# File 'lib/skia/point.rb', line 43 def length Math.sqrt(@x * @x + @y * @y) end |
#normalize ⇒ Object
47 48 49 50 51 52 |
# File 'lib/skia/point.rb', line 47 def normalize len = length return self.class.new(0, 0) if len.zero? self / len end |
#to_a ⇒ Object
60 61 62 |
# File 'lib/skia/point.rb', line 60 def to_a [@x, @y] end |
#to_struct ⇒ Object
16 17 18 19 20 21 |
# File 'lib/skia/point.rb', line 16 def to_struct struct = Native::SKPoint.new struct[:x] = @x struct[:y] = @y struct end |