@@ -27,9 +27,9 @@ function GetLength (x1, y1, x2, y2)
2727 * @constructor
2828 * @since 3.50.0
2929 *
30- * @param {Phaser.GameObjects.Vertex } vertex1 - The first vertex in this Face.
31- * @param {Phaser.GameObjects.Vertex } vertex2 - The second vertex in this Face.
32- * @param {Phaser.GameObjects.Vertex } vertex3 - The third vertex in this Face.
30+ * @param {Phaser.GameObjects.Vertex } vertex1 - The first vertex of the Face.
31+ * @param {Phaser.GameObjects.Vertex } vertex2 - The second vertex of the Face.
32+ * @param {Phaser.GameObjects.Vertex } vertex3 - The third vertex of the Face.
3333 */
3434var Face = new Class ( {
3535
@@ -147,6 +147,69 @@ var Face = new Class({
147147 return this ;
148148 } ,
149149
150+ contains : function ( x , y , calcMatrix )
151+ {
152+ var v1x = this . vertex1 . x ;
153+ var v1y = this . vertex1 . y ;
154+
155+ var v2x = this . vertex2 . x ;
156+ var v2y = this . vertex2 . y ;
157+
158+ var v3x = this . vertex3 . x ;
159+ var v3y = this . vertex3 . y ;
160+
161+ if ( calcMatrix )
162+ {
163+ var a = calcMatrix . a ;
164+ var b = calcMatrix . b ;
165+ var c = calcMatrix . c ;
166+ var d = calcMatrix . d ;
167+ var e = calcMatrix . e ;
168+ var f = calcMatrix . f ;
169+
170+ v1x = this . vertex1 . x * a + this . vertex1 . y * c + e ;
171+ v1y = this . vertex1 . x * b + this . vertex1 . y * d + f ;
172+
173+ v2x = this . vertex2 . x * a + this . vertex2 . y * c + e ;
174+ v2y = this . vertex2 . x * b + this . vertex2 . y * d + f ;
175+
176+ v3x = this . vertex3 . x * a + this . vertex3 . y * c + e ;
177+ v3y = this . vertex3 . x * b + this . vertex3 . y * d + f ;
178+ }
179+
180+ var t0x = v3x - v1x ;
181+ var t0y = v3y - v1y ;
182+
183+ var t1x = v2x - v1x ;
184+ var t1y = v2y - v1y ;
185+
186+ var t2x = x - v1x ;
187+ var t2y = y - v1y ;
188+
189+ var dot00 = ( t0x * t0x ) + ( t0y * t0y ) ;
190+ var dot01 = ( t0x * t1x ) + ( t0y * t1y ) ;
191+ var dot02 = ( t0x * t2x ) + ( t0y * t2y ) ;
192+ var dot11 = ( t1x * t1x ) + ( t1y * t1y ) ;
193+ var dot12 = ( t1x * t2x ) + ( t1y * t2y ) ;
194+
195+ // Compute barycentric coordinates
196+ var bc = ( ( dot00 * dot11 ) - ( dot01 * dot01 ) ) ;
197+ var inv = ( bc === 0 ) ? 0 : ( 1 / bc ) ;
198+ var u = ( ( dot11 * dot02 ) - ( dot01 * dot12 ) ) * inv ;
199+ var v = ( ( dot00 * dot12 ) - ( dot01 * dot02 ) ) * inv ;
200+
201+ return ( u >= 0 && v >= 0 && ( u + v < 1 ) ) ;
202+ } ,
203+
204+ isCounterClockwise : function ( )
205+ {
206+ var v1 = this . vertex1 ;
207+ var v2 = this . vertex2 ;
208+ var v3 = this . vertex3 ;
209+
210+ return ( v2 . x - v1 . x ) * ( v3 . y - v1 . y ) - ( v2 . y - v1 . y ) * ( v3 . x - v1 . x ) >= 0 ;
211+ } ,
212+
150213 x : {
151214
152215 get : function ( )
@@ -179,6 +242,19 @@ var Face = new Class({
179242
180243 } ,
181244
245+ depth : {
246+
247+ get : function ( )
248+ {
249+ var v1 = this . vertex1 ;
250+ var v2 = this . vertex2 ;
251+ var v3 = this . vertex3 ;
252+
253+ return ( v1 . z + v2 . z + v3 . z ) / 3 ;
254+ }
255+
256+ } ,
257+
182258 destroy : function ( )
183259 {
184260 this . vertex1 = null ;
0 commit comments