package { /** * Utility functions are easy procedural functions that I put here to get out of the way. * @author Chad Nelson */ public class Utility { /** * Used to sort event list * @param a * @param b * @return */ public static function eventComparator(a:VoronoiEvent, b:VoronoiEvent):Number { return (b.y - a.y)*100; } /** * Calculates discriminant * @param a * @param b * @param c * @return */ public static function calcDiscriminant(a : Number, b : Number, c : Number):Number { return Math.pow(b, 2) - 4 * a * c; } /** * Checks a tuple of arcs for a circle event. Returns the circle event or null */ public static function checkForCircleEvent(center : Parabola):VoronoiCircleEvent { if (center == null) return null; else if (center.left == null || center.right == null) return null; // Co-linear test var slopeA : Number = (center.left.site.y - center.site.y) / (center.left.site.x - center.site.x); var slopeB : Number = (center.right.site.y - center.site.y) / (center.right.site.x - center.site.x); if (center.site.x == center.left.site.x == center.right.site.x) // Vertical line return null; else if (slopeA == slopeB) return null; // BC must be a right turn from AB if ((center.site.x-center.left.site.x)*(center.right.site.y-center.left.site.y) - (center.right.site.x-center.left.site.x)*(center.site.y-center.left.site.y) > 0) return null; return new VoronoiCircleEvent(center); } /** * Calculates the determinant of a 3 by 3 matrix * | a11 a12 a13 | * | a21 a22 a23 | * | a31 a32 a33 | * @return (Number) the determinant */ public static function determinant(a11:Number, a12:Number, a13:Number, a21:Number, a22:Number, a23:Number, a31:Number, a32:Number, a33:Number):Number { return a11*a22*a33 + a12*a23*a31 + a13*a21*a32 - a31*a22*a13 - a32*a23*a11 - a33*a21*a12; } } }