mr-crocs-adventures/js/geometry/GeometryPoint.js

30 lines
656 B
JavaScript
Raw Permalink Normal View History

2020-01-19 00:45:17 +01:00
export default class GeometryPoint
{
2020-01-22 22:50:45 +01:00
constructor(x = 0, y = 0)
2020-01-19 00:45:17 +01:00
{
this.x = x;
this.y = y;
}
isEqual(geometryPoint)
{
return this.x === geometryPoint.x && this.y === geometryPoint.y;
}
getDistanceToPoint(geometryPoint)
{
return Math.sqrt(Math.pow(geometryPoint.x - this.x,2) + Math.pow(geometryPoint.y - this.y,2));
}
getAngleToPoint(geometryPoint)
{
return Math.atan2(this.y - geometryPoint.y, this.x - geometryPoint.x);
}
draw(context)
{
context.beginPath();
context.arc(this.x, this.y, 3, 0, 2 * Math.PI);
context.stroke();
}
}