nape.geom.Vec2

type
class
2 Dimensional vector.

Note that in many cases of a Vec2 object being returned by a Nape function the Vec2 object will be marked internally as an 'immutable' Vec2. This will always be documented and trying to mutate such a Vec2 will result in an error being thrown.

Vec2 objects can make use of a global object pool, attempting to make use of a disposed Vec2 will also result in an error with the object pool working in a FILO order to increase the likelihood of such misuse being caught.

Additionally Vec2 objects can be created as 'weak'. Passing a weak Vec2 to any Nape function as an argument will result in the automatic disposal of the Vec2 once the method has finished with it. There may be exceptions to this rule which will also be documented; a notable case being the appending of a weak Vec2 to a Nape Vec2List in which case the disposal of the weak Vec2 is performed when that Vec2List is handed to a Nape function instead.

Example:
var vertices = Polygon.box(20, 20, true);
var polygon = new Polygon(vertices);
In this example, passing true to the Polygon.box method means that we will be returned a Vec2List containing only 'weak' Vec2s. Upon passing this Vec2List to the Polygon constructor, all of the Vec2s from that list will be automatically disposed.

Static Methods

static inline function distance(a:Vec2, b:Vec2):Float

+ Compute distance between two points.

static inline function dsq(a:Vec2, b:Vec2):Float

+ Compute square distance between two points.

static function fromPoint(point:flash.geom.Point, weak:Bool = false):Vec2

+ Allocate a Vec2 from AS3 Point object.

static function fromPolar(length:Float, angle:Float, weak:Bool = false):Vec2

+ Allocate a Vec2 given polar coordinates.

static inline function get(x:Float = 0, y:Float = 0, weak:Bool = false):Vec2

+ Allocates a Vec2 from the global object pool.

static inline function weak(x:Float = 0, y:Float = 0):Vec2

+ Allocate a weak Vec2 from global object pool.

Constructor

function new(x:Float = 0, y:Float = 0)
+ Construct a new Vec2.

Instance Properties

var angle : Float = 0

+ Angle of this Vec2.

var length : Float = 0

+ Length of this Vec2.

var x : Float = 0

x coordinate of vector.

var y : Float = 0

y coordinate of vector.

Instance Methods

function add(vector:Vec2, weak:Bool = false):Vec2

+ Add another vector to this vector.

function addMul(vector:Vec2, scalar:Float, weak:Bool = false):Vec2

+ Add a multiple of a vector to this vector.

function addeq(vector:Vec2):Vec2

+ Add another vector into this vector.

inline function copy(weak:Bool = false):Vec2

+ Produce a copy of this Vec2.

function cross(vector:Vec2):Float

+ Cross product with another vector.

inline function dispose():Void

+ Release this Vec2 to global object pool.

function dot(vector:Vec2):Float

+ Dot product with another vector.

function lsq():Float

+ Compute squared length of this Vec2.

function mul(scalar:Float, weak:Bool = false):Vec2

+ Multiply this vector with a number.

function muleq(scalar:Float):Vec2

+ Multiply this vector with a number.

function normalise():Vec2

+ Normalise this vector.

function perp(weak:Bool = false):Vec2

+ The right-perpendicular to this vector.

function reflect(vec:Vec2, weak:Bool = false):Vec2

+ Reflect given Vec2 in plane whose normal is this Vec2.

function rotate(angle:Float):Vec2

+ Rotate Vec2 in-place by given number of radians..

inline function set(vector:Vec2):Vec2

+ Set values of this Vec2 to those of the argument.

inline function setxy(x:Float, y:Float):Vec2

+ Set values of this Vec2 given pair of x/y values.

function sub(vector:Vec2, weak:Bool = false):Vec2

+ Subtract another vector from this vector.

function subeq(vector:Vec2):Vec2

+ Subtract another vector from this vector.

function toPoint(output:flash.geom.Point = null):flash.geom.Point

+ Create an AS3 Point object from Vec2.

function unit(weak:Bool = false):Vec2

+ Return normalisation of this vector.