Skip to content

Commit 732b808

Browse files
committed
Line.rotate allows you to rotate a line by the given amount around its center point.
1 parent 5f9bff0 commit 732b808

4 files changed

Lines changed: 28 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ Version 2.4 - "Katar" - in dev
307307
* Line.random will return a random point from anywhere on the Line segment.
308308
* Ellipse.random will return a uniformly distributed random point from anywhere within the ellipse.
309309
* Rectangle.random will return a uniformly distributed random point from anywhere within the rectangle.
310+
* Line.rotate allows you to rotate a line by the given amount around its center point.
310311

311312
### Updates
312313

src/geom/Line.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,30 @@ Phaser.Line.prototype = {
102102

103103
},
104104

105+
/**
106+
* Rotates the line by the amount specified in `angle`.
107+
*
108+
* Rotation takes place from the center of the line.
109+
*
110+
* If you wish to rotate from either end see Line.start.rotate or Line.end.rotate.
111+
*
112+
* @method Phaser.Line#rotate
113+
* @param {number} angle - The angle in radians (unless asDegrees is true) to rotate the line by.
114+
* @param {boolean} [asDegrees=false] - Is the given angle in radians (false) or degrees (true)?
115+
* @return {Phaser.Line} This line object
116+
*/
117+
rotate: function (angle, asDegrees) {
118+
119+
var x = this.start.x;
120+
var y = this.start.y;
121+
122+
this.start.rotate(this.end.x, this.end.y, angle, asDegrees, this.length);
123+
this.end.rotate(x, y, angle, asDegrees, this.length);
124+
125+
return this;
126+
127+
},
128+
105129
/**
106130
* Checks for intersection between this line and another Line.
107131
* If asSegment is true it will check for segment intersection. If asSegment is false it will check for line intersection.

src/geom/Point.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ Phaser.Point.prototype = {
308308
* @param {number} x - The x coordinate of the anchor point.
309309
* @param {number} y - The y coordinate of the anchor point.
310310
* @param {number} angle - The angle in radians (unless asDegrees is true) to rotate the Point to.
311-
* @param {boolean} asDegrees - Is the given rotation in radians (false) or degrees (true)?
311+
* @param {boolean} [asDegrees=false] - Is the given angle in radians (false) or degrees (true)?
312312
* @param {number} [distance] - An optional distance constraint between the Point and the anchor.
313313
* @return {Phaser.Point} The modified point object.
314314
*/
@@ -797,7 +797,7 @@ Phaser.Point.normalize = function (a, out) {
797797
* @param {number} x - The x coordinate of the anchor point
798798
* @param {number} y - The y coordinate of the anchor point
799799
* @param {number} angle - The angle in radians (unless asDegrees is true) to rotate the Point by.
800-
* @param {boolean} [asDegrees=false] - Is the given angle to rotate by in radians (false) or degrees (true)?
800+
* @param {boolean} [asDegrees=false] - Is the given angle in radians (false) or degrees (true)?
801801
* @param {number} [distance] - An optional distance constraint between the Point and the anchor.
802802
* @return {Phaser.Point} The modified point object.
803803
*/

typescript/phaser.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,6 +1988,7 @@ declare module Phaser {
19881988
pointOnSegment(x: number, y: number): boolean;
19891989
random(out?: Phaser.Point): Phaser.Point;
19901990
reflect(line: Phaser.Line): number;
1991+
rotate(angle: number, asDegrees?: boolean): Phaser.Line;
19911992
setTo(x1?: number, y1?: number, x2?: number, y2?: number): Phaser.Line;
19921993

19931994
}

0 commit comments

Comments
 (0)