mirror of
https://github.com/photonstorm/phaser
synced 2025-02-17 14:38:30 +00:00
The rest of the Point functions.
This commit is contained in:
parent
88344d095c
commit
52d769fc89
14 changed files with 136 additions and 69 deletions
|
@ -5,6 +5,7 @@ module.exports = {
|
||||||
Circle: require('./circle'),
|
Circle: require('./circle'),
|
||||||
Ellipse: require('./ellipse'),
|
Ellipse: require('./ellipse'),
|
||||||
Intersects: require('./intersects'),
|
Intersects: require('./intersects'),
|
||||||
|
Point: require('./point'),
|
||||||
Rectangle: require('./rectangle')
|
Rectangle: require('./rectangle')
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
6
v3/src/geom/point/Ceil.js
Normal file
6
v3/src/geom/point/Ceil.js
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
var Ceil = function (point)
|
||||||
|
{
|
||||||
|
return point.setTo(Math.ceil(point.x), Math.ceil(point.y));
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = Ceil;
|
6
v3/src/geom/point/Cross.js
Normal file
6
v3/src/geom/point/Cross.js
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
var Cross = function (pointA, pointB)
|
||||||
|
{
|
||||||
|
return ((pointA.x * pointB.y) - (pointA.y * pointB.x));
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = Cross;
|
6
v3/src/geom/point/Dot.js
Normal file
6
v3/src/geom/point/Dot.js
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
var Dot = function (pointA, pointB)
|
||||||
|
{
|
||||||
|
return ((pointA.x * pointB.x) + (pointA.y * pointB.y));
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = Dot;
|
6
v3/src/geom/point/Floor.js
Normal file
6
v3/src/geom/point/Floor.js
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
var Floor = function (point)
|
||||||
|
{
|
||||||
|
return point.setTo(Math.floor(point.x), Math.floor(point.y));
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = Floor;
|
14
v3/src/geom/point/Interpolate.js
Normal file
14
v3/src/geom/point/Interpolate.js
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
var Point = require('./Point');
|
||||||
|
|
||||||
|
var Interpolate = function (pointA, pointB, t, out)
|
||||||
|
{
|
||||||
|
if (t === undefined) { t = 0; }
|
||||||
|
if (out === undefined) { out = new Point(); }
|
||||||
|
|
||||||
|
out.x = pointA.x + ((pointB.x - pointA.x) * t);
|
||||||
|
out.y = pointA.y + ((pointB.y - pointA.y) * t);
|
||||||
|
|
||||||
|
return out;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = Interpolate;
|
10
v3/src/geom/point/Negative.js
Normal file
10
v3/src/geom/point/Negative.js
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
var Point = require('./Point');
|
||||||
|
|
||||||
|
var Negative = function (point, out)
|
||||||
|
{
|
||||||
|
if (out === undefined) { out = new Point(); }
|
||||||
|
|
||||||
|
return out.setTo(-point.x, -point.y);
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = Negative;
|
6
v3/src/geom/point/NormalizeRightHand.js
Normal file
6
v3/src/geom/point/NormalizeRightHand.js
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
var NormalizeRightHand = function (point)
|
||||||
|
{
|
||||||
|
return point.setTo(point.y * -1, point.x);
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = NormalizeRightHand;
|
6
v3/src/geom/point/Perp.js
Normal file
6
v3/src/geom/point/Perp.js
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
var Perp = function (point)
|
||||||
|
{
|
||||||
|
return point.setTo(-point.y, point.x);
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = Perp;
|
|
@ -1,7 +1,7 @@
|
||||||
var Point = function (x, y)
|
var Point = function (x, y)
|
||||||
{
|
{
|
||||||
if (x === undefined) { x = 0; }
|
if (x === undefined) { x = 0; }
|
||||||
if (y === undefined) { y = 0; }
|
if (y === undefined) { y = x; }
|
||||||
|
|
||||||
this.x = x;
|
this.x = x;
|
||||||
|
|
||||||
|
@ -25,72 +25,4 @@ Point.prototype = {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Object.defineProperties(Point.prototype, {
|
|
||||||
|
|
||||||
left: {
|
|
||||||
|
|
||||||
enumerable: true,
|
|
||||||
|
|
||||||
get: function ()
|
|
||||||
{
|
|
||||||
return this.x;
|
|
||||||
},
|
|
||||||
|
|
||||||
set: function (value)
|
|
||||||
{
|
|
||||||
this.x = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
right: {
|
|
||||||
|
|
||||||
enumerable: true,
|
|
||||||
|
|
||||||
get: function ()
|
|
||||||
{
|
|
||||||
return this.x;
|
|
||||||
},
|
|
||||||
|
|
||||||
set: function (value)
|
|
||||||
{
|
|
||||||
this.x = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
top: {
|
|
||||||
|
|
||||||
enumerable: true,
|
|
||||||
|
|
||||||
get: function ()
|
|
||||||
{
|
|
||||||
return this.y;
|
|
||||||
},
|
|
||||||
|
|
||||||
set: function (value)
|
|
||||||
{
|
|
||||||
this.y = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
bottom: {
|
|
||||||
|
|
||||||
enumerable: true,
|
|
||||||
|
|
||||||
get: function ()
|
|
||||||
{
|
|
||||||
return this.y;
|
|
||||||
},
|
|
||||||
|
|
||||||
set: function (value)
|
|
||||||
{
|
|
||||||
this.y = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = Point;
|
module.exports = Point;
|
||||||
|
|
20
v3/src/geom/point/Project.js
Normal file
20
v3/src/geom/point/Project.js
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
var Dot = require('./Dot');
|
||||||
|
var Point = require('./Point');
|
||||||
|
var GetMagnitudeSq = require('./GetMagnitudeSq');
|
||||||
|
|
||||||
|
var Project = function (pointA, pointB, out)
|
||||||
|
{
|
||||||
|
if (out === undefined) { out = new Point(); }
|
||||||
|
|
||||||
|
var amt = Dot(pointA, pointB) / GetMagnitudeSq(pointB);
|
||||||
|
|
||||||
|
if (amt !== 0)
|
||||||
|
{
|
||||||
|
out.x = amt * pointB.x;
|
||||||
|
out.y = amt * pointB.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = Project;
|
19
v3/src/geom/point/ProjectUnit.js
Normal file
19
v3/src/geom/point/ProjectUnit.js
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
var Dot = require('./Dot');
|
||||||
|
var Point = require('./Point');
|
||||||
|
|
||||||
|
var ProjectUnit = function (pointA, pointB, out)
|
||||||
|
{
|
||||||
|
if (out === undefined) { out = new Point(); }
|
||||||
|
|
||||||
|
var amt = Dot(pointA, pointB);
|
||||||
|
|
||||||
|
if (amt !== 0)
|
||||||
|
{
|
||||||
|
out.x = amt * pointB.x;
|
||||||
|
out.y = amt * pointB.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = ProjectUnit;
|
6
v3/src/geom/point/RPerp.js
Normal file
6
v3/src/geom/point/RPerp.js
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
var RPerp = function (point)
|
||||||
|
{
|
||||||
|
return point.setTo(point.y, -point.x);
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = RPerp;
|
29
v3/src/geom/point/index.js
Normal file
29
v3/src/geom/point/index.js
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
// Phaser.Geom.Point
|
||||||
|
|
||||||
|
var Point = require('./Point');
|
||||||
|
|
||||||
|
Point.Add = require('./Add');
|
||||||
|
Point.Ceil = require('./Ceil');
|
||||||
|
Point.Clone = require('./Clone');
|
||||||
|
Point.CopyFrom = require('./CopyFrom');
|
||||||
|
Point.Cross = require('./Cross');
|
||||||
|
Point.Divide = require('./Divide');
|
||||||
|
Point.Dot = require('./Dot');
|
||||||
|
Point.Equals = require('./Equals');
|
||||||
|
Point.Floor = require('./Floor');
|
||||||
|
Point.GetMagnitude = require('./GetMagnitude');
|
||||||
|
Point.GetMagnitudeSq = require('./GetMagnitudeSq');
|
||||||
|
Point.Interpolate = require('./Interpolate');
|
||||||
|
Point.Invert = require('./Invert');
|
||||||
|
Point.Multiply = require('./Multiply');
|
||||||
|
Point.Negative = require('./Negative');
|
||||||
|
Point.Normalize = require('./Normalize');
|
||||||
|
Point.NormalizeRightHand = require('./NormalizeRightHand');
|
||||||
|
Point.Perp = require('./Perp');
|
||||||
|
Point.Project = require('./Project');
|
||||||
|
Point.ProjectUnit = require('./ProjectUnit');
|
||||||
|
Point.RPerp = require('./RPerp');
|
||||||
|
Point.SetMagnitude = require('./SetMagnitude');
|
||||||
|
Point.Subtract = require('./Subtract');
|
||||||
|
|
||||||
|
module.exports = Point;
|
Loading…
Add table
Reference in a new issue