Skip to content

Commit 323edeb

Browse files
Jacob SchatzJacob Schatz
authored andcommitted
Add 3 methods to point class with documented comments.
* `offset`: which offsets the Point object by the specified amount. * `polar` : which converts a pair of polar coordinates to a Cartesian point coordinate. * `interpolate` : which determines a point between two specified points.
1 parent 58aaad3 commit 323edeb

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

src/easeljs/geom/Point.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,49 @@ this.createjs = this.createjs||{};
9999
return this;
100100
};
101101

102+
/**
103+
* Offsets the Point object by the specified amount. The value of dx is added to the original value of x to create the new x value. The value of dy is added to the original value of y to create the new y value.
104+
* @method offset
105+
* @param {Number} The amount by which to offset the horizontal coordinate, x.
106+
* @param {Number} The amount by which to offset the vertical coordinate, y.
107+
* @return {Point} This instance. Useful for chaining method calls.
108+
* @chainable
109+
*/
110+
p.offset = function(dx, dy) {
111+
this.x += dx;
112+
this.y += dy;
113+
return this;
114+
};
115+
116+
/**
117+
* Converts a pair of polar coordinates to a Cartesian point coordinate.
118+
* @method offset
119+
* @param {Number} The length coordinate of the polar pair.
120+
* @param {Number} The angle, in radians, of the polar pair.
121+
* @return {Point} This instance. Useful for chaining method calls.
122+
* @chainable
123+
*/
124+
p.polar = function(len, angle) {
125+
this.x = len * (Math.cos(angle));
126+
this.y = len * (Math.sin(angle));
127+
return this;
128+
};
129+
130+
/**
131+
* Determines a point between two specified points. The parameter `f` determines where the new interpolated point is located relative to the two end points specified by parameters `pt1` and `pt2`. The closer the value of the parameter `f` is to 1.0, the closer the interpolated point is to the first point (parameter `pt1`). The closer the value of the parameter `f` is to 0, the closer the interpolated point is to the second point (parameter `pt2`).
132+
* @method offset
133+
* @param {Point} The first point.
134+
* @param {Point} The second point.
135+
* @param {Number} The level of interpolation between the two points. Indicates where the new point will be, along the line between `pt1` and `pt2`. If `f=1`, `pt1` is returned; if `f=0`, `pt2` is returned.
136+
* @return {Point} This instance. Useful for chaining method calls.
137+
* @chainable
138+
*/
139+
p.interpolate = function(pt1, pt2, f) {
140+
this.x = pt2.x + (f * (pt1.x - pt2.x));
141+
this.y = pt2.y + (f * (pt1.y - pt2.y));
142+
return this;
143+
};
144+
102145
/**
103146
* Copies all properties from the specified point to this point.
104147
* @method copy

0 commit comments

Comments
 (0)