You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
* 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
+
returnthis;
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
+
returnthis;
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
+
returnthis;
143
+
};
144
+
102
145
/**
103
146
* Copies all properties from the specified point to this point.
0 commit comments