This repository was archived by the owner on Feb 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
1,884 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright M. Griffie <[email protected]> | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
package nexus | ||
{ | ||
|
||
/** | ||
* A factory used to create instances of an object given a Class and an optional | ||
* Object to assign public properties/variables on the instantiated instance. | ||
*/ | ||
public class ClassFactory implements IFactory | ||
{ | ||
private var m_class : Class; | ||
private var m_properties : Object; | ||
|
||
public function ClassFactory(source:Class, properties:Object = null) | ||
{ | ||
m_class = source; | ||
m_properties = properties; | ||
} | ||
|
||
public function get type():Class { return m_class; } | ||
|
||
public function get properties():Object { return m_properties; } | ||
public function set properties(value:Object):void | ||
{ | ||
m_properties = value; | ||
} | ||
|
||
public function create():* | ||
{ | ||
var instance:* = new m_class(); | ||
if(m_properties != null) | ||
{ | ||
for(var property:String in m_properties) | ||
{ | ||
instance[property] = m_properties[property]; | ||
} | ||
} | ||
return instance; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Copyright M. Griffie <[email protected]> | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
package nexus.math | ||
{ | ||
|
||
/** | ||
* A collection of math utility methods. | ||
*/ | ||
public class MathHelper | ||
{ | ||
public static function clamp(value : Number, min : Number, max : Number) : Number | ||
{ | ||
value = (value > max) ? max : value; | ||
value = (value < min) ? min : value; | ||
return value; | ||
} | ||
|
||
public static function sign(value : Number) : int | ||
{ | ||
if (value == 0) | ||
{ | ||
return 0; | ||
} | ||
return value > 0 ? 1 : -1; | ||
} | ||
|
||
public static function distance(value1 : Number, value2 : Number) : Number | ||
{ | ||
return Math.abs(value1 - value2); | ||
} | ||
|
||
public static function toDegrees(radians : Number) : Number | ||
{ | ||
return (radians * 57.29578); | ||
} | ||
|
||
public static function toRadians(degrees : Number) : Number | ||
{ | ||
return (degrees * 0.01745329); | ||
} | ||
|
||
public static function wrapAngleRadians(angle : Number) : Number | ||
{ | ||
while(angle <= -3.141593) | ||
{ | ||
angle += 6.283185; | ||
} | ||
while(angle > 3.141593) | ||
{ | ||
angle -= 6.283185; | ||
} | ||
return angle; | ||
} | ||
|
||
public static function wrapAngleDegrees(angle : Number) : Number | ||
{ | ||
while(angle <= -180) | ||
{ | ||
angle += 360; | ||
} | ||
while(angle > 180) | ||
{ | ||
angle -= 360; | ||
} | ||
return angle; | ||
} | ||
|
||
/** | ||
* Compares the sign value of source to compareTo and returns source or -source as appropriate | ||
* @param source The value to check the sign of and return | ||
* @param compareTo The value to compare against | ||
*/ | ||
static public function matchSign(source:Number, compareTo:Number):Number | ||
{ | ||
if(compareTo < 0) | ||
{ | ||
return source <= 0 ? source : -source; | ||
} | ||
else | ||
{ | ||
return source >= 0 ? source : -source | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.