Vector2d

Vector2d allows for easy handling of two-dimensionals coordinates and vectors. It’s very flexible, most methods accepts arguments as strings, arrays, hashes or Vector2d objects.

Installation

Install from RubyForge:

sudo gem install vector2d

Install from GitHub:

gem sources -a http://gems.github.com
sudo gem install elektronaut-vector2d

Usage examples

require 'vector2d'

# These are equal
v = Vector2d.new(50, 70)  
v = Vector2d.new('50x70')

v.aspect_ratio # => 0.714285714285714
v.length       # => 86.0232526704263

# Calculations work as expected
v * 2                   # => #<Vector2d:0x5d994 @y=140.0, @x=100.0>
v + Vector2d.new(20,30) # => #<Vector2d:0x59c54 @y=100.0, @x=70.0>

v.constrain_both(64, 64) # => #<Vector2d:0x47e28 @y=64.0, @x=45.7142857142857>

API Documentation

Is available at vector2d.rubyforge.org/

Source code

Is available at github.com/elektronaut/vector2d

Licence

(The MIT License)

Copyright © 2006-2009 Inge Jørgensen

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.