class Graphics.Point
Data type, represents 2D point (also known as 2D vector).
const position1 = Point(10,10);
const position2 = Point.make(20,20);
const position3 = Point(Rect(10,10,100,100)); // origin of the rect
// operators
const sum = Point(0,0) + Point(50,50);
const sub = Point(0,0) - Point(50,50); // [-50,-50]
constructor
Point instances can be constructed by new Point(...) or by Point(...) "convesrsion" constructor.
Point()- constructs 0,0 point;Point(Point)- constructs copy of the point;Point(Size)- constructs point by converting it from Size;Point(x,y)- constructs pont from two numbers;
properties:
x, y
numbers
length
number, length of the vector - sqrt(x*x + y*y);
methods:
distance()
point.distance(other:Point):number
returns distance between this and other point.
distanceToLineSegment()
point.distanceToLineSegment(lp1:Point, lp2:Point): [distance:number, lp: Point]
Distance from this point to the line segment [lp1,lp2].
Returns the distance and lp - closest point to this point on the line segment or lp1 or lp2 if this point projection falls outside the segment.
dot()
point.dot(other:Point): number
returns DOT product of this and other point.
unit()
point.unit():Point
returns normalized unit vector that goes in the same direction but has length of 1.
inscribe()
point.inscribe(Rect):Point
moves (if needed) copy of the point inside the Rect, returns the copy that is always inside the Rect.
operators:
Point supports following operators:
point * n|size- per component multiplication by number or size (scaling);point / n|size- per component division by number or size (scaling);point + point|size- sum of two points (vectors);point - point|size- substraction of two points;point == point- equality of two points, implementation uses float EPSILON precision;+point- unary + (copy);-point- unary - (inversion);
static methods:
make()
Point.make(x,y):Point
Constructs point from x,y