Module: CVFFI::CvPointMethods
- Included in:
- CvPointBase, Point
- Defined in:
- lib/opencv-ffi-wrappers/core/point.rb
Instance Method Summary collapse
- #*(a) ⇒ Object
- #+(a) ⇒ Object
- #-(a) ⇒ Object
- #/(a) ⇒ Object
- #==(b) ⇒ Object
- #===(b) ⇒ Object
- #got_what_i_need(a) ⇒ Object
- #l2_squared_distance(b) ⇒ Object
- #l2distance(b) ⇒ Object (also: #distance_to)
- #neighbor?(p, radius) ⇒ Boolean
- #neighbor_rsquared?(p, rsquared) ⇒ Boolean
- #rotate(rads) ⇒ Object
- #to_a(homogeneous = true) ⇒ Object
- #to_Vector(homogeneous = true) ⇒ Object (also: #to_vector)
Instance Method Details
#*(a) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/opencv-ffi-wrappers/core/point.rb', line 19 def *(a) if got_what_i_need a self.class.new( [ x*a.x, y*a.y ] ) else self.class.new( [ x*a, y*a ] ) end end |
#+(a) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/opencv-ffi-wrappers/core/point.rb', line 35 def +(a) if got_what_i_need a self.class.new( [ x+a.x, y+a.y ] ) else self.class.new( [ x+a, y+a ] ) end end |
#-(a) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/opencv-ffi-wrappers/core/point.rb', line 27 def -(a) if got_what_i_need a self.class.new( [ x.to_f-a.x, y.to_f-a.y ] ) else self.class.new( [ x.to_f-a, y.to_f-a ] ) end end |
#/(a) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/opencv-ffi-wrappers/core/point.rb', line 11 def /(a) if got_what_i_need a self.class.new( [ x.to_f/a.x.to_f, y.to_f/a.y.to_f ] ) else self.class.new( [ x.to_f/a, y.to_f/a ] ) end end |
#==(b) ⇒ Object
50 51 52 |
# File 'lib/opencv-ffi-wrappers/core/point.rb', line 50 def ==(b) @x == b.x and @y == b.y end |
#===(b) ⇒ Object
53 54 55 |
# File 'lib/opencv-ffi-wrappers/core/point.rb', line 53 def ===(b) @x === b.x and @y === b.y end |
#got_what_i_need(a) ⇒ Object
7 8 9 |
# File 'lib/opencv-ffi-wrappers/core/point.rb', line 7 def got_what_i_need(a) a.class.method_defined?(:x) and a.class.method_defined?(:y) end |
#l2_squared_distance(b) ⇒ Object
86 87 88 |
# File 'lib/opencv-ffi-wrappers/core/point.rb', line 86 def l2_squared_distance( b ) (x-b.x)**2 + (y-b.y)**2 end |
#l2distance(b) ⇒ Object Also known as: distance_to
81 82 83 |
# File 'lib/opencv-ffi-wrappers/core/point.rb', line 81 def l2distance( b ) Math::sqrt( l2_squared_distance(b) ) end |
#neighbor?(p, radius) ⇒ Boolean
70 71 72 73 74 |
# File 'lib/opencv-ffi-wrappers/core/point.rb', line 70 def neighbor?( p, radius ) return false if (x-p.x).abs > radius or (y-p.y).abs > radius return false if l2distance(p) > radius true end |
#neighbor_rsquared?(p, rsquared) ⇒ Boolean
76 77 78 79 |
# File 'lib/opencv-ffi-wrappers/core/point.rb', line 76 def neighbor_rsquared?( p, rsquared ) return false if l2_squared_distance(p) > rsquared true end |
#rotate(rads) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/opencv-ffi-wrappers/core/point.rb', line 43 def rotate( rads ) sa = Math::sin rads ca = Math::cos rads self.class.new( x*ca - y*sa, x*sa + y*ca ) end |
#to_a(homogeneous = true) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/opencv-ffi-wrappers/core/point.rb', line 62 def to_a(homogeneous=true) if homogeneous [ @x/@w, @y/@w, 1.0 ] else [ @x, @y ] end end |
#to_Vector(homogeneous = true) ⇒ Object Also known as: to_vector
57 58 59 |
# File 'lib/opencv-ffi-wrappers/core/point.rb', line 57 def to_Vector( homogeneous = true ) Vector.elements( to_a( homogeneous ) ) end |