Class: CP::Vec2
- Inherits:
-
Object
- Object
- CP::Vec2
- Defined in:
- lib/chipmunk-ffi/vec2.rb
Instance Attribute Summary collapse
-
#struct ⇒ Object
Returns the value of attribute struct.
Class Method Summary collapse
Instance Method Summary collapse
- #*(s) ⇒ Object
- #+(other_vec) ⇒ Object
- #-(other_vec) ⇒ Object
- #-@ ⇒ Object
- #/(s) ⇒ Object
- #==(other) ⇒ Object
- #clamp(other_vec) ⇒ Object
- #cross(other_vec) ⇒ Object
- #dist(other_vec) ⇒ Object
- #distsq(other_vec) ⇒ Object
- #dot(other_vec) ⇒ Object
-
#initialize(*args) ⇒ Vec2
constructor
A new instance of Vec2.
- #length ⇒ Object
- #lengthsq ⇒ Object
- #lerp(other_vec, t) ⇒ Object
- #lerpconst(other_vec, d) ⇒ Object
- #near?(other_vec, dist) ⇒ Boolean
- #normalize ⇒ Object
- #normalize! ⇒ Object
- #normalize_safe ⇒ Object
- #perp ⇒ Object
- #project(other_vec) ⇒ Object
- #rotate(other_vec) ⇒ Object
- #rperp ⇒ Object
- #to_a ⇒ Object
- #to_angle ⇒ Object
- #to_s ⇒ Object
- #unrotate(other_vec) ⇒ Object
- #x ⇒ Object
- #x=(new_x) ⇒ Object
- #y ⇒ Object
- #y=(new_y) ⇒ Object
Constructor Details
Instance Attribute Details
#struct ⇒ Object
Returns the value of attribute struct.
60 61 62 |
# File 'lib/chipmunk-ffi/vec2.rb', line 60 def struct @struct end |
Class Method Details
Instance Method Details
#*(s) ⇒ Object
115 116 117 |
# File 'lib/chipmunk-ffi/vec2.rb', line 115 def *(s) Vec2.new CP.cpvmult(@struct, s) end |
#+(other_vec) ⇒ Object
107 108 109 |
# File 'lib/chipmunk-ffi/vec2.rb', line 107 def +(other_vec) Vec2.new CP.cpvadd(@struct, other_vec.struct) end |
#-(other_vec) ⇒ Object
111 112 113 |
# File 'lib/chipmunk-ffi/vec2.rb', line 111 def -(other_vec) Vec2.new CP.cpvsub(@struct, other_vec.struct) end |
#-@ ⇒ Object
103 104 105 |
# File 'lib/chipmunk-ffi/vec2.rb', line 103 def -@ Vec2.new CP.cpvneg(@struct) end |
#/(s) ⇒ Object
119 120 121 122 |
# File 'lib/chipmunk-ffi/vec2.rb', line 119 def /(s) factor = 1.0/s Vec2.new CP.cpvmult(@struct, factor) end |
#==(other) ⇒ Object
198 199 200 |
# File 'lib/chipmunk-ffi/vec2.rb', line 198 def ==(other) self.x == other.x && self.y == other.y end |
#clamp(other_vec) ⇒ Object
173 174 175 |
# File 'lib/chipmunk-ffi/vec2.rb', line 173 def clamp(other_vec) Vec2.new CP.cpvclamp(@struct) end |
#cross(other_vec) ⇒ Object
128 129 130 |
# File 'lib/chipmunk-ffi/vec2.rb', line 128 def cross(other_vec) CP.cpvcross(@struct, other_vec.struct) end |
#dist(other_vec) ⇒ Object
181 182 183 |
# File 'lib/chipmunk-ffi/vec2.rb', line 181 def dist(other_vec) CP.cpvdist(@struct, other_vec.struct) end |
#distsq(other_vec) ⇒ Object
185 186 187 |
# File 'lib/chipmunk-ffi/vec2.rb', line 185 def distsq(other_vec) CP.cpvdistsq(@struct, other_vec.struct) end |
#dot(other_vec) ⇒ Object
124 125 126 |
# File 'lib/chipmunk-ffi/vec2.rb', line 124 def dot(other_vec) CP.cpvdot(@struct, other_vec.struct) end |
#length ⇒ Object
194 195 196 |
# File 'lib/chipmunk-ffi/vec2.rb', line 194 def length CP::cpvlength @struct end |
#lengthsq ⇒ Object
152 153 154 |
# File 'lib/chipmunk-ffi/vec2.rb', line 152 def lengthsq CP.cpvlengthsq(@struct) end |
#lerp(other_vec, t) ⇒ Object
156 157 158 |
# File 'lib/chipmunk-ffi/vec2.rb', line 156 def lerp(other_vec, t) Vec2.new CP.cpvlerp(@struct, other_vec.struct, t) end |
#lerpconst(other_vec, d) ⇒ Object
177 178 179 |
# File 'lib/chipmunk-ffi/vec2.rb', line 177 def lerpconst(other_vec, d) Vec2.new CP.cpvlerpconst(@struct, other_vec.struct, d) end |
#near?(other_vec, dist) ⇒ Boolean
189 190 191 192 |
# File 'lib/chipmunk-ffi/vec2.rb', line 189 def near?(other_vec, dist) delta_v = CP.cpvsub(@struct, other_vec.struct) CP.cpvdot(delta_v, delta_v) < dist*dist end |
#normalize ⇒ Object
160 161 162 |
# File 'lib/chipmunk-ffi/vec2.rb', line 160 def normalize Vec2.new CP.cpvnormalize(@struct) end |
#normalize! ⇒ Object
164 165 166 167 |
# File 'lib/chipmunk-ffi/vec2.rb', line 164 def normalize! @struct = CP.cpvnormalize(@struct) self end |
#normalize_safe ⇒ Object
169 170 171 |
# File 'lib/chipmunk-ffi/vec2.rb', line 169 def normalize_safe Vec2.new CP.cpvnormalize_safe(@struct) end |
#perp ⇒ Object
132 133 134 |
# File 'lib/chipmunk-ffi/vec2.rb', line 132 def perp Vec2.new CP.cpvperp(@struct) end |
#project(other_vec) ⇒ Object
140 141 142 |
# File 'lib/chipmunk-ffi/vec2.rb', line 140 def project(other_vec) Vec2.new CP.cpvproject(@struct, other_vec.struct) end |
#rotate(other_vec) ⇒ Object
144 145 146 |
# File 'lib/chipmunk-ffi/vec2.rb', line 144 def rotate(other_vec) Vec2.new CP.cpvrotate(@struct, other_vec.struct) end |
#rperp ⇒ Object
136 137 138 |
# File 'lib/chipmunk-ffi/vec2.rb', line 136 def rperp Vec2.new CP.cpvrperp(@struct) end |
#to_a ⇒ Object
99 100 101 |
# File 'lib/chipmunk-ffi/vec2.rb', line 99 def to_a [@struct[:x],@struct[:y]] end |
#to_angle ⇒ Object
95 96 97 |
# File 'lib/chipmunk-ffi/vec2.rb', line 95 def to_angle CP.cpvtoangle @struct end |
#to_s ⇒ Object
91 92 93 |
# File 'lib/chipmunk-ffi/vec2.rb', line 91 def to_s CP.cpvstr @struct end |
#unrotate(other_vec) ⇒ Object
148 149 150 |
# File 'lib/chipmunk-ffi/vec2.rb', line 148 def unrotate(other_vec) Vec2.new CP.cpvunrotate(@struct, other_vec.struct) end |
#x ⇒ Object
72 73 74 |
# File 'lib/chipmunk-ffi/vec2.rb', line 72 def x @struct[:x] end |
#x=(new_x) ⇒ Object
75 76 77 78 |
# File 'lib/chipmunk-ffi/vec2.rb', line 75 def x=(new_x) raise TypeError, "can't modify frozen vec2" if frozen? @struct[:x] = new_x end |
#y ⇒ Object
79 80 81 |
# File 'lib/chipmunk-ffi/vec2.rb', line 79 def y @struct[:y] end |
#y=(new_y) ⇒ Object
82 83 84 85 |
# File 'lib/chipmunk-ffi/vec2.rb', line 82 def y=(new_y) raise TypeError, "can't modify frozen vec2" if frozen? @struct[:y] = new_y end |