@@ -71,12 +71,19 @@ import openfl.geom.Point;
7171 */
7272@:forward abstract FlxPoint (FlxBasePoint ) to FlxBasePoint from FlxBasePoint
7373{
74+
75+ /**
76+ * Vector components less than this are considered zero, to account for rounding errors
77+ */
7478 public static inline var EPSILON : Float = 0.0000001 ;
7579 public static inline var EPSILON_SQUARED : Float = EPSILON * EPSILON ;
80+
81+ /**
82+ * Vector lengths less than this are considered zero, to account for rounding errors
83+ */
84+ public static inline var EPSILON_LENGTH : Float = EPSILON * FlxMath .SQUARE_ROOT_OF_TWO ;
7685
7786 static var _point1 = new FlxPoint ();
78- static var _point2 = new FlxPoint ();
79- static var _point3 = new FlxPoint ();
8087
8188 /**
8289 * Recycle or create new FlxPoint.
@@ -162,7 +169,7 @@ import openfl.geom.Point;
162169 @:op (A + = B )
163170 static inline function plusEqualOp (a : FlxPoint , b : FlxPoint ): FlxPoint
164171 {
165- return a .addPoint (b );
172+ return a .add (b );
166173 }
167174
168175 /**
@@ -172,7 +179,7 @@ import openfl.geom.Point;
172179 @:op (A - = B )
173180 static inline function minusEqualOp (a : FlxPoint , b : FlxPoint ): FlxPoint
174181 {
175- return a .subtractPoint (b );
182+ return a .subtract (b );
176183 }
177184
178185 /**
@@ -357,7 +364,7 @@ import openfl.geom.Point;
357364 * @param point The point to add to this point
358365 * @return This point.
359366 */
360- // @:deprecated("addPoint is deprecated, use add(point), instead")// 6.0.0
367+ @:deprecated (" addPoint is deprecated, use add(point), instead" )// 6.1.2
361368 public inline function addPoint (point : FlxPoint ): FlxPoint
362369 {
363370 return add (point );
@@ -408,7 +415,7 @@ import openfl.geom.Point;
408415 * @param point The point to subtract from this point
409416 * @return This point.
410417 */
411- // @:deprecated("subtractPoint is deprecated, use subtract(point), instead")// 6.0.0
418+ @:deprecated (" subtractPoint is deprecated, use subtract(point), instead" )// 6.1.2
412419 public inline function subtractPoint (point : FlxPoint ): FlxPoint
413420 {
414421 subtract (point .x , point .y );
@@ -470,7 +477,7 @@ import openfl.geom.Point;
470477 * @param point The x and y scale coefficient
471478 * @return scaled point
472479 */
473- // @:deprecated("scalePoint is deprecated, use scale(point), instead")// 6.0.0
480+ @:deprecated (" scalePoint is deprecated, use scale(point), instead" )// 6.1.2
474481 public inline function scalePoint (point : FlxPoint ): FlxPoint
475482 {
476483 scale (point .x , point .y );
@@ -497,7 +504,7 @@ import openfl.geom.Point;
497504 */
498505 public inline function addNew (p : FlxPoint ): FlxPoint
499506 {
500- return clone ().addPoint (p );
507+ return clone ().add (p );
501508 }
502509
503510 /**
@@ -508,7 +515,7 @@ import openfl.geom.Point;
508515 */
509516 public inline function subtractNew (p : FlxPoint ): FlxPoint
510517 {
511- return clone ().subtractPoint (p );
518+ return clone ().subtract (p );
512519 }
513520
514521 /**
@@ -542,7 +549,7 @@ import openfl.geom.Point;
542549 * @param p Any Point.
543550 * @return A reference to itself.
544551 */
545- // @:deprecated("copyFromFlash is deprecated, use copyFrom, instead")// 6.0.0
552+ @:deprecated (" copyFromFlash is deprecated, use copyFrom, instead" )// 6.1.2
546553 public inline function copyFromFlash (p : Point ): FlxPoint
547554 {
548555 return set (p .x , p .y );
@@ -583,7 +590,7 @@ import openfl.geom.Point;
583590 * @param p Any Point.
584591 * @return A reference to the altered point parameter.
585592 */
586- // @:deprecated("copyToFlash is deprecated, use copyTo, instead")// 6.0.0
593+ @:deprecated (" copyToFlash is deprecated, use copyTo, instead" )// 6.1.2
587594 public inline function copyToFlash (? p : Point ): Point
588595 {
589596 return copyTo (p != null ? p : new Point ());
@@ -677,7 +684,7 @@ import openfl.geom.Point;
677684 */
678685 public function pivotRadians (pivot : FlxPoint , radians : Float ): FlxPoint
679686 {
680- _point1 .copyFrom (this ).subtractPoint (pivot );
687+ _point1 .copyFrom (this ).subtract (pivot );
681688 _point1 .radians + = radians ;
682689 set (_point1 .x + pivot .x , _point1 .y + pivot .y );
683690 pivot .putWeak ();
@@ -845,7 +852,12 @@ import openfl.geom.Point;
845852 */
846853 inline function dotProductWeak (p : FlxPoint ): Float
847854 {
848- return x * p .x + y * p .y ;
855+ return dotProductXY (p .x , p .y );
856+ }
857+
858+ inline function dotProductXY (x : Float , y : Float ): Float
859+ {
860+ return this .x * x + this .y * y ;
849861 }
850862
851863 /**
@@ -856,9 +868,10 @@ import openfl.geom.Point;
856868 */
857869 public inline function dotProdWithNormalizing (p : FlxPoint ): Float
858870 {
859- var normalized : FlxPoint = p .clone (_point1 ).normalize ();
871+ final length = p .length ;
872+ final result = length < EPSILON_LENGTH ? 0 : dotProductXY (p .x / length , p .y / length );
860873 p .putWeak ();
861- return dotProductWeak ( normalized ) ;
874+ return result ;
862875 }
863876
864877 /**
@@ -929,7 +942,8 @@ import openfl.geom.Point;
929942 */
930943 public inline function isZero (): Bool
931944 {
932- return Math .abs (x ) < EPSILON && Math .abs (y ) < EPSILON ;
945+ // i.e: x*x < EPSILON_SQUARED && y*y < EPSILON_SQUARED;
946+ return lengthSquared < 2 * EPSILON_SQUARED ;
933947 }
934948
935949 /**
@@ -1033,7 +1047,7 @@ import openfl.geom.Point;
10331047 {
10341048 p = get ();
10351049 }
1036- p .set (- y , x );
1050+ p .set (rx , ry );
10371051 return p ;
10381052 }
10391053
@@ -1046,7 +1060,7 @@ import openfl.geom.Point;
10461060 {
10471061 p = get ();
10481062 }
1049- p .set (y , - x );
1063+ p .set (lx , ly );
10501064 return p ;
10511065 }
10521066
@@ -1058,9 +1072,9 @@ import openfl.geom.Point;
10581072 return set (x * - 1 , y * - 1 );
10591073 }
10601074
1061- public inline function negateNew (): FlxPoint
1075+ public inline function negateNew (? result : FlxPoint ): FlxPoint
10621076 {
1063- return clone ().negate ();
1077+ return clone (result ).negate ();
10641078 }
10651079
10661080 /**
@@ -1136,7 +1150,12 @@ import openfl.geom.Point;
11361150 */
11371151 inline function perpProductWeak (p : FlxPoint ): Float
11381152 {
1139- return lx * p .x + ly * p .y ;
1153+ return perpProductXY (p .x , p .y );
1154+ }
1155+
1156+ inline function perpProductXY (x : Float , y : Float ): Float
1157+ {
1158+ return lx * x + ly * y ;
11401159 }
11411160
11421161 /**
@@ -1354,12 +1373,13 @@ import openfl.geom.Point;
13541373 */
13551374 public inline function bounceWithFriction (normal : FlxPoint , bounceCoeff : Float = 1 , friction : Float = 0 ): FlxPoint
13561375 {
1357- var p1 : FlxPoint = projectToNormalizedWeak (normal .rightNormal (_point3 ), _point1 );
1358- var p2 : FlxPoint = projectToNormalizedWeak (normal , _point2 );
1359- var bounceX : Float = - p2 .x ;
1360- var bounceY : Float = - p2 .y ;
1361- var frictionX : Float = p1 .x ;
1362- var frictionY : Float = p1 .y ;
1376+ final dp = dotProductWeak (normal );
1377+ final bounceX = - normal .x * dp ;
1378+ final bounceY = - normal .y * dp ;
1379+ final pp = perpProductWeak (normal );
1380+ final frictionX = normal .rx * pp ;
1381+ final frictionY = normal .ry * pp ;
1382+
13631383 normal .putWeak ();
13641384
13651385 return set (bounceX * bounceCoeff + frictionX * friction , bounceY * bounceCoeff + frictionY * friction );
0 commit comments