diff --git a/v3/src/geom/index.js b/v3/src/geom/index.js index 1ccc27e88..bbcbf62f8 100644 --- a/v3/src/geom/index.js +++ b/v3/src/geom/index.js @@ -5,6 +5,7 @@ module.exports = { Circle: require('./circle'), Ellipse: require('./ellipse'), Intersects: require('./intersects'), + Point: require('./point'), Rectangle: require('./rectangle') }; diff --git a/v3/src/geom/point/Ceil.js b/v3/src/geom/point/Ceil.js new file mode 100644 index 000000000..6361c5b4b --- /dev/null +++ b/v3/src/geom/point/Ceil.js @@ -0,0 +1,6 @@ +var Ceil = function (point) +{ + return point.setTo(Math.ceil(point.x), Math.ceil(point.y)); +}; + +module.exports = Ceil; diff --git a/v3/src/geom/point/Cross.js b/v3/src/geom/point/Cross.js new file mode 100644 index 000000000..89b997c3c --- /dev/null +++ b/v3/src/geom/point/Cross.js @@ -0,0 +1,6 @@ +var Cross = function (pointA, pointB) +{ + return ((pointA.x * pointB.y) - (pointA.y * pointB.x)); +}; + +module.exports = Cross; diff --git a/v3/src/geom/point/Dot.js b/v3/src/geom/point/Dot.js new file mode 100644 index 000000000..871dad8a7 --- /dev/null +++ b/v3/src/geom/point/Dot.js @@ -0,0 +1,6 @@ +var Dot = function (pointA, pointB) +{ + return ((pointA.x * pointB.x) + (pointA.y * pointB.y)); +}; + +module.exports = Dot; diff --git a/v3/src/geom/point/Floor.js b/v3/src/geom/point/Floor.js new file mode 100644 index 000000000..c4d79cc25 --- /dev/null +++ b/v3/src/geom/point/Floor.js @@ -0,0 +1,6 @@ +var Floor = function (point) +{ + return point.setTo(Math.floor(point.x), Math.floor(point.y)); +}; + +module.exports = Floor; diff --git a/v3/src/geom/point/Interpolate.js b/v3/src/geom/point/Interpolate.js new file mode 100644 index 000000000..95db58487 --- /dev/null +++ b/v3/src/geom/point/Interpolate.js @@ -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; diff --git a/v3/src/geom/point/Negative.js b/v3/src/geom/point/Negative.js new file mode 100644 index 000000000..83392c17a --- /dev/null +++ b/v3/src/geom/point/Negative.js @@ -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; diff --git a/v3/src/geom/point/NormalizeRightHand.js b/v3/src/geom/point/NormalizeRightHand.js new file mode 100644 index 000000000..fa96c4818 --- /dev/null +++ b/v3/src/geom/point/NormalizeRightHand.js @@ -0,0 +1,6 @@ +var NormalizeRightHand = function (point) +{ + return point.setTo(point.y * -1, point.x); +}; + +module.exports = NormalizeRightHand; diff --git a/v3/src/geom/point/Perp.js b/v3/src/geom/point/Perp.js new file mode 100644 index 000000000..4da8fc5b6 --- /dev/null +++ b/v3/src/geom/point/Perp.js @@ -0,0 +1,6 @@ +var Perp = function (point) +{ + return point.setTo(-point.y, point.x); +}; + +module.exports = Perp; diff --git a/v3/src/geom/point/Point.js b/v3/src/geom/point/Point.js index 1ea7bc9f9..ad580104c 100644 --- a/v3/src/geom/point/Point.js +++ b/v3/src/geom/point/Point.js @@ -1,7 +1,7 @@ var Point = function (x, y) { if (x === undefined) { x = 0; } - if (y === undefined) { y = 0; } + if (y === undefined) { y = 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; diff --git a/v3/src/geom/point/Project.js b/v3/src/geom/point/Project.js new file mode 100644 index 000000000..55dd55cfd --- /dev/null +++ b/v3/src/geom/point/Project.js @@ -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; diff --git a/v3/src/geom/point/ProjectUnit.js b/v3/src/geom/point/ProjectUnit.js new file mode 100644 index 000000000..bdd8630a9 --- /dev/null +++ b/v3/src/geom/point/ProjectUnit.js @@ -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; diff --git a/v3/src/geom/point/RPerp.js b/v3/src/geom/point/RPerp.js new file mode 100644 index 000000000..0ba3a22ed --- /dev/null +++ b/v3/src/geom/point/RPerp.js @@ -0,0 +1,6 @@ +var RPerp = function (point) +{ + return point.setTo(point.y, -point.x); +}; + +module.exports = RPerp; diff --git a/v3/src/geom/point/index.js b/v3/src/geom/point/index.js new file mode 100644 index 000000000..a31c21b3c --- /dev/null +++ b/v3/src/geom/point/index.js @@ -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;