Class: Vector2d
- Inherits:
-
Object
- Object
- Vector2d
- Extended by:
- Calculations::ClassMethods
- Includes:
- Calculations, Coercions, Fitting, Properties, Transformations
- Defined in:
- lib/vector2d.rb,
lib/vector2d/fitting.rb,
lib/vector2d/version.rb,
lib/vector2d/coercions.rb,
lib/vector2d/properties.rb,
lib/vector2d/calculations.rb,
lib/vector2d/transformations.rb
Defined Under Namespace
Modules: Calculations, Coercions, Fitting, Properties, Transformations
Constant Summary collapse
- VERSION =
"2.0.2"
Instance Attribute Summary collapse
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Class Method Summary collapse
-
.parse(arg, second_arg = nil) ⇒ Object
Creates a new vector.
Instance Method Summary collapse
-
#==(comp) ⇒ Object
Compares two vectors.
-
#initialize(x, y) ⇒ Vector2d
constructor
A new instance of Vector2d.
Methods included from Calculations::ClassMethods
angle_between, cross_product, dot_product
Methods included from Transformations
#ceil, #floor, #normalize, #perpendicular, #resize, #reverse, #round, #truncate
Methods included from Properties
#angle, #aspect_ratio, #length, #normalized?, #squared_length
Methods included from Fitting
Methods included from Coercions
#coerce, #inspect, #to_a, #to_f_vector, #to_hash, #to_i_vector, #to_s
Methods included from Calculations
#*, #+, #-, #/, #angle_between, #cross_product, #distance, #dot_product, #squared_distance
Constructor Details
#initialize(x, y) ⇒ Vector2d
Returns a new instance of Vector2d.
72 73 74 |
# File 'lib/vector2d.rb', line 72 def initialize(x, y) @x, @y = x, y end |
Instance Attribute Details
#x ⇒ Object (readonly)
Returns the value of attribute x.
70 71 72 |
# File 'lib/vector2d.rb', line 70 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
70 71 72 |
# File 'lib/vector2d.rb', line 70 def y @y end |
Class Method Details
.parse(arg, second_arg = nil) ⇒ Object
Creates a new vector. The following examples are all valid:
Vector2d.parse(150, 100)
Vector2d.parse(150.0, 100.0)
Vector2d.parse("150x100")
Vector2d.parse("150.0x100.0")
Vector2d.parse([150,100})
Vector2d.parse({x: 150, y: 100})
Vector2d.parse({"x" => 150.0, "y" => 100.0})
Vector2d.parse(Vector2d(150, 100))
30 31 32 33 34 35 36 |
# File 'lib/vector2d.rb', line 30 def parse(arg, second_arg=nil) if second_arg.nil? parse_single_arg(arg) else self.new(arg, second_arg) end end |