Skip to content

Commit 492961a

Browse files
committed
Updated Point:
* Return Point Objects instead of generic objects when using interpolate and polar * Fixed small documentation issues, and formatted docs * Added @default values on x/y
1 parent 4582b0e commit 492961a

File tree

1 file changed

+33
-17
lines changed

1 file changed

+33
-17
lines changed

src/easeljs/geom/Point.js

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,14 @@ this.createjs = this.createjs||{};
6060
* X position.
6161
* @property x
6262
* @type Number
63+
* @default 0
6364
**/
6465

6566
/**
6667
* Y position.
6768
* @property y
6869
* @type Number
70+
* @default 0
6971
**/
7072
}
7173
var p = Point.prototype;
@@ -86,10 +88,14 @@ this.createjs = this.createjs||{};
8688
};
8789

8890
/**
89-
* 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.
91+
* Offsets the Point object by the specified amount.
92+
* <ul>
93+
* <li>The value of `dx` is added to the original value of `x` to create the new `x` value</li>
94+
* <li>The value of `dy` is added to the original value of `y` to create the new `y` value</li>
95+
* </ul>
9096
* @method offset
91-
* @param {Number} dx The amount by which to offset the horizontal coordinate, x.
92-
* @param {Number} dy The amount by which to offset the vertical coordinate, y.
97+
* @param {Number} dx The amount by which to offset the horizontal coordinate, `x`.
98+
* @param {Number} dy The amount by which to offset the vertical coordinate, `y`.
9399
* @return {Point} This instance. Useful for chaining method calls.
94100
* @chainable
95101
*/
@@ -104,31 +110,41 @@ this.createjs = this.createjs||{};
104110
* @method polar
105111
* @param {Number} len The length coordinate of the polar pair.
106112
* @param {Number} angle The angle, in radians, of the polar pair.
107-
* @param {Point | Object} [pt] An object to copy the result into. If omitted a generic object with x/y properties will be returned.
113+
* @param {Point | Object} [pt] An object to copy the result into. If omitted a new {{#crossLink "Point"}}{{/crossLink}}
114+
* will be returned.
108115
* @return {Point} The new, interpolated point.
109-
* @chainable
110116
*/
111117
Point.polar = function(len, angle, pt) {
112-
pt = pt||{};
113-
pt.x = len * (Math.cos(angle));
114-
pt.y = len * (Math.sin(angle));
118+
pt = pt||new Point();
119+
pt.x = len * Math.cos(angle);
120+
pt.y = len * Math.sin(angle);
115121
return pt;
116122
};
117123

118-
/**
119-
* 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`).
124+
/**
125+
* Determine a point between two specified points.
126+
*
127+
* The parameter `f` determines where the new interpolated point is located relative to the two end points specified
128+
* by parameters `pt1` and `pt2`:
129+
* <ul>
130+
* <li>The closer the value of the parameter `f` is to 1.0, the closer the interpolated point is to the first
131+
* point (parameter `pt1`).</li>
132+
* <li>The closer the value of the parameter `f` is to 0, the closer the interpolated point is to the second
133+
* point (parameter `pt2`).</li>
134+
* </ul>
120135
* @method interpolate
121136
* @param {Point | Object} pt1 The first point as a Point or generic object.
122137
* @param {Point | Object} pt2 The second point as a Point or generic object.
123-
* @param {Number} f 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.
124-
* @param {Point | Object} [pt] An object to copy the result into. If omitted a generic object with x/y properties will be returned.
125-
* @return {Point} The new, interpolated point.
126-
* @chainable
138+
* @param {Number} f The level of interpolation between the two points. Indicates where the new point will be, along
139+
* the line between `pt1` and `pt2`. If `f=1`, `pt1` is returned; if `f=0`, `pt2` is returned.
140+
* @param {Point | Object} [pt] An object to copy the result into. If omitted, a new {{#crossLink "Point"}}{{/crossLink}}
141+
* will be returned.
142+
* @return {Point} A new interpolated Point, or the `pt` passed in the 4th parameter with the interpolated values.
127143
*/
128144
Point.interpolate = function(pt1, pt2, f, pt) {
129-
pt = pt||{};
130-
pt.x = pt2.x + (f * (pt1.x - pt2.x));
131-
pt.y = pt2.y + (f * (pt1.y - pt2.y));
145+
pt = pt || new Point();
146+
pt.x = pt2.x + f * (pt1.x - pt2.x);
147+
pt.y = pt2.y + f * (pt1.y - pt2.y);
132148
return pt;
133149
};
134150

0 commit comments

Comments
 (0)