File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /**
2+ * @author Richard Davey <rich@photonstorm.com>
3+ * @copyright 2018 Photon Storm Ltd.
4+ * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License }
5+ */
6+
7+ var Length = require ( '../line/Length' ) ;
8+ var Line = require ( '../line/Line' ) ;
9+
10+ /**
11+ * Returns the perimeter of the given Polygon.
12+ *
13+ * @function Phaser.Geom.Polygon.Perimeter
14+ * @since 3.12.0
15+ *
16+ * @param {Phaser.Geom.Polygon } polygon - The Polygon to get the perimeter of.
17+ *
18+ * @return {number } The perimeter of the Polygon.
19+ */
20+ var Perimeter = function ( polygon )
21+ {
22+ var points = polygon . points ;
23+ var perimeter = 0 ;
24+
25+ for ( var i = 0 ; i < points . length ; i ++ )
26+ {
27+ var pointA = points [ i ] ;
28+ var pointB = points [ ( i + 1 ) % points . length ] ;
29+ var line = new Line (
30+ pointA . x ,
31+ pointA . y ,
32+ pointB . x ,
33+ pointB . y
34+ ) ;
35+
36+ perimeter += Length ( line ) ;
37+ }
38+
39+ return perimeter ;
40+ } ;
41+
42+ module . exports = Perimeter ;
Original file line number Diff line number Diff line change @@ -11,5 +11,6 @@ Polygon.Contains = require('./Contains');
1111Polygon . ContainsPoint = require ( './ContainsPoint' ) ;
1212Polygon . GetAABB = require ( './GetAABB' ) ;
1313Polygon . GetNumberArray = require ( './GetNumberArray' ) ;
14+ Polygon . Perimeter = require ( './Perimeter' ) ;
1415
1516module . exports = Polygon ;
You can’t perform that action at this time.
0 commit comments