The rest of the Point functions.

This commit is contained in:
Richard Davey 2017-01-03 22:21:47 +00:00
parent 88344d095c
commit 52d769fc89
14 changed files with 136 additions and 69 deletions

View file

@ -5,6 +5,7 @@ module.exports = {
Circle: require('./circle'),
Ellipse: require('./ellipse'),
Intersects: require('./intersects'),
Point: require('./point'),
Rectangle: require('./rectangle')
};

View file

@ -0,0 +1,6 @@
var Ceil = function (point)
{
return point.setTo(Math.ceil(point.x), Math.ceil(point.y));
};
module.exports = Ceil;

View 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
View file

@ -0,0 +1,6 @@
var Dot = function (pointA, pointB)
{
return ((pointA.x * pointB.x) + (pointA.y * pointB.y));
};
module.exports = Dot;

View file

@ -0,0 +1,6 @@
var Floor = function (point)
{
return point.setTo(Math.floor(point.x), Math.floor(point.y));
};
module.exports = Floor;

View 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;

View 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;

View file

@ -0,0 +1,6 @@
var NormalizeRightHand = function (point)
{
return point.setTo(point.y * -1, point.x);
};
module.exports = NormalizeRightHand;

View file

@ -0,0 +1,6 @@
var Perp = function (point)
{
return point.setTo(-point.y, point.x);
};
module.exports = Perp;

View file

@ -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;

View 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;

View 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;

View file

@ -0,0 +1,6 @@
var RPerp = function (point)
{
return point.setTo(point.y, -point.x);
};
module.exports = RPerp;

View 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;