Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 72 additions & 78 deletions flixel/math/FlxPoint.hx
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,7 @@ import openfl.geom.Point;
*/
public inline function set(x:Float = 0, y:Float = 0):FlxPoint
{
this.x = x;
this.y = y;
return this;
return this.set(x, y);
}

/**
Expand All @@ -324,9 +322,7 @@ import openfl.geom.Point;
*/
public overload extern inline function add(x:Float = 0, y:Float = 0):FlxPoint
{
this.x += x;
this.y += y;
return this;
return set(this.x + x, this.y + y);
}

/**
Expand All @@ -352,10 +348,7 @@ import openfl.geom.Point;
*/
public overload inline extern function add(p:Point):FlxPoint
{
x += p.x;
y += p.y;

return this;
return add(p.x, p.y);
}

/**
Expand All @@ -379,9 +372,7 @@ import openfl.geom.Point;
*/
public overload inline extern function subtract(x:Float = 0, y:Float = 0):FlxPoint
{
this.x -= x;
this.y -= y;
return this;
return set(this.x - x, this.y - y);
}

/**
Expand Down Expand Up @@ -434,9 +425,7 @@ import openfl.geom.Point;
*/
public overload inline extern function scale(x:Float, y:Float):FlxPoint
{
this.x *= x;
this.y *= y;
return this;
return set(this.x * x, this.y * y);
}

/**
Expand All @@ -448,9 +437,19 @@ import openfl.geom.Point;
*/
public overload inline extern function scale(amount:Float):FlxPoint
{
this.x *= amount;
this.y *= amount;
return this;
return scale(amount, amount);
}

/**
* Scale this point by another point.
* @since 6.0.0
*
* @param point The x and y scale coefficient
* @return this point
*/
public overload inline extern function scale(point:FlxPoint):FlxPoint
{
return scale(point.x, point.y);
}

/**
Expand All @@ -462,8 +461,7 @@ import openfl.geom.Point;
*/
public overload inline extern function scale(point:Point):FlxPoint
{
scale(point.x, point.y);
return this;
return scale(point.x, point.y);
}

/**
Expand Down Expand Up @@ -535,7 +533,7 @@ import openfl.geom.Point;
*/
public overload inline extern function copyFrom(p:Point):FlxPoint
{
return this.set(p.x, p.y);
return set(p.x, p.y);
}

/**
Expand All @@ -547,14 +545,14 @@ import openfl.geom.Point;
// @:deprecated("copyFromFlash is deprecated, use copyFrom, instead")// 6.0.0
public inline function copyFromFlash(p:Point):FlxPoint
{
return this.set(p.x, p.y);
return set(p.x, p.y);
}

/**
* Helper function, just copies the values from this point to the specified point.
*
* @param p optional point to copy this point to
* @return copy of this point
* @param p An optional point to copy this point to
* @return The new point
*/
public overload inline extern function copyTo(?p:FlxPoint):FlxPoint
{
Expand All @@ -569,8 +567,8 @@ import openfl.geom.Point;
* Helper function, just copies the values from this point to the specified Flash point.
* @since 6.0.0
*
* @param p Any Point.
* @return A reference to the altered point parameter.
* @param p The point to copy this point to
* @return The new point
*/
public overload inline extern function copyTo(p:Point):Point
{
Expand Down Expand Up @@ -624,29 +622,23 @@ import openfl.geom.Point;
*/
public inline function floor():FlxPoint
{
x = Math.floor(x);
y = Math.floor(y);
return this;
return set(Math.floor(x), Math.floor(y));
}

/**
* Rounds x and y using Math.ceil()
*/
public inline function ceil():FlxPoint
{
x = Math.ceil(x);
y = Math.ceil(y);
return this;
return set(Math.ceil(x), Math.ceil(y));
}

/**
* Rounds x and y using Math.round()
*/
public inline function round():FlxPoint
{
x = Math.round(x);
y = Math.round(y);
return this;
return set(Math.round(x), Math.round(y));
}

/**
Expand Down Expand Up @@ -945,8 +937,7 @@ import openfl.geom.Point;
*/
public inline function zero():FlxPoint
{
x = y = 0;
return this;
return set(0, 0);
}

/**
Expand Down Expand Up @@ -979,12 +970,7 @@ import openfl.geom.Point;
{
var s:Float = Math.sin(rads);
var c:Float = Math.cos(rads);
var tempX:Float = x;

x = tempX * c - y * s;
y = tempX * s + y * c;

return this;
return set(x * c - y * s, x * s + y * c);
}

/**
Expand All @@ -1007,10 +993,7 @@ import openfl.geom.Point;
*/
public inline function rotateWithTrig(sin:Float, cos:Float):FlxPoint
{
var tempX:Float = x;
x = tempX * cos - y * sin;
y = tempX * sin + y * cos;
return this;
return set(x * cos - y * sin, x * sin + y * cos);
}

/**
Expand All @@ -1024,9 +1007,7 @@ import openfl.geom.Point;
*/
public function setPolarRadians(length:Float, radians:Float):FlxPoint
{
x = length * Math.cos(radians);
y = length * Math.sin(radians);
return this;
return set(length * Math.cos(radians), length * Math.sin(radians));
}

/**
Expand Down Expand Up @@ -1074,9 +1055,7 @@ import openfl.geom.Point;
*/
public inline function negate():FlxPoint
{
x *= -1;
y *= -1;
return this;
return set(x * -1, y * -1);
}

public inline function negateNew():FlxPoint
Expand Down Expand Up @@ -1360,8 +1339,7 @@ import openfl.geom.Point;
public inline function bounce(normal:FlxPoint, bounceCoeff:Float = 1):FlxPoint
{
var d:Float = (1 + bounceCoeff) * dotProductWeak(normal);
x -= d * normal.x;
y -= d * normal.y;
set(x - d * normal.x, y - d * normal.y);
normal.putWeak();
return this;
}
Expand All @@ -1382,10 +1360,9 @@ import openfl.geom.Point;
var bounceY:Float = -p2.y;
var frictionX:Float = p1.x;
var frictionY:Float = p1.y;
x = bounceX * bounceCoeff + frictionX * friction;
y = bounceY * bounceCoeff + frictionY * friction;
normal.putWeak();
return this;

return set(bounceX * bounceCoeff + frictionX * friction, bounceY * bounceCoeff + frictionY * friction);
}

/**
Expand All @@ -1401,8 +1378,8 @@ import openfl.geom.Point;
/**
* Copies this point.
*
* @param p optional point to copy this point to
* @return copy of this point
* @param p An optional point to copy this point to
* @return The new point
*/
public inline function clone(?p:FlxPoint):FlxPoint
{
Expand Down Expand Up @@ -1455,8 +1432,7 @@ import openfl.geom.Point;
if (!isZero())
{
var a:Float = radians;
x = l * Math.cos(a);
y = l * Math.sin(a);
set(l * Math.cos(a), l * Math.sin(a));
}
return l;
}
Expand Down Expand Up @@ -1486,8 +1462,7 @@ import openfl.geom.Point;
{
var len:Float = length;

x = len * Math.cos(rads);
y = len * Math.sin(rads);
set(len * Math.cos(rads), len * Math.sin(rads));
return rads;
}

Expand Down Expand Up @@ -1726,8 +1701,8 @@ abstract FlxReadOnlyPoint(FlxPoint) from FlxPoint
class FlxCallbackPoint extends FlxBasePoint
{
var _setXCallback:FlxPoint->Void;
var _setYCallback:FlxPoint->Void;
var _setXYCallback:FlxPoint->Void;
var _setYCallback:Null<FlxPoint->Void>;
var _setXYCallback:Null<FlxPoint->Void>;

/**
* If you only specify one callback function, then the remaining two will use the same.
Expand All @@ -1739,41 +1714,60 @@ class FlxCallbackPoint extends FlxBasePoint
public function new(setXCallback:FlxPoint->Void, ?setYCallback:FlxPoint->Void, ?setXYCallback:FlxPoint->Void)
{
super();

_setXCallback = setXCallback;
_setYCallback = setXYCallback;
_setXYCallback = setXYCallback;

if (_setXCallback != null)

// TODO: operator overloading?
if (setXCallback != null && setYCallback == null && setXYCallback == null)
{
_setXYCallback = setXCallback;
}
else
{
if (_setYCallback == null)
_setYCallback = setXCallback;
if (_setXYCallback == null)
_setXYCallback = setXCallback;
_setXCallback = setXCallback;
_setYCallback = setYCallback;
_setXYCallback = setXYCallback;
}
}

override public function set(x:Float = 0, y:Float = 0):FlxCallbackPoint
{
super.set(x, y);
@:bypassAccessor this.x = x;
@:bypassAccessor this.y = y;

if (_setXCallback != null)
_setXCallback(this);

if (_setYCallback != null)
_setYCallback(this);

if (_setXYCallback != null)
_setXYCallback(this);

return this;
}

override function set_x(value:Float):Float
{
super.set_x(value);

if (_setXCallback != null)
_setXCallback(this);

if (_setXYCallback != null)
_setXYCallback(this);

return value;
}

override function set_y(value:Float):Float
{
super.set_y(value);

if (_setYCallback != null)
_setYCallback(this);

if (_setXYCallback != null)
_setXYCallback(this);

return value;
}

Expand Down
Loading