mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
parent
ca3993fe8e
commit
cbefaf0dd1
1 changed files with 11 additions and 3 deletions
|
@ -541,6 +541,10 @@ var Point = Base.extend(/** @lends Point# */{
|
|||
},
|
||||
|
||||
setAngle: function(angle) {
|
||||
// We store a reference to _angle internally so we still preserve it
|
||||
// when the vector's length is set to zero, and then anything else.
|
||||
// Note that we cannot rely on it if x and y are something else than 0,
|
||||
// since updating x / y does not automatically change _angle!
|
||||
angle = this._angle = angle * Math.PI / 180;
|
||||
if (!this.isZero()) {
|
||||
var length = this.getLength();
|
||||
|
@ -573,9 +577,13 @@ var Point = Base.extend(/** @lends Point# */{
|
|||
getAngleInRadians: function(/* point */) {
|
||||
// Hide parameters from Bootstrap so it injects bean too
|
||||
if (arguments[0] === undefined) {
|
||||
if (this._angle == null)
|
||||
this._angle = Math.atan2(this.y, this.x);
|
||||
return this._angle;
|
||||
return this.isZero()
|
||||
// Return the preseved angle in case the vector has no
|
||||
// length, and update the internal _angle in case the
|
||||
// vector has a length. See #setAngle() for more
|
||||
// explanations.
|
||||
? this._angle || 0
|
||||
: this._angle = Math.atan2(this.y, this.x);
|
||||
} else {
|
||||
var point = Point.read(arguments),
|
||||
div = this.getLength() * point.getLength();
|
||||
|
|
Loading…
Reference in a new issue