- 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:
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.