@@ -14,27 +14,31 @@ class FlxRect implements IFlxPooled
1414 static var _pool : FlxPool <FlxRect > = new FlxPool (FlxRect .new .bind (0 , 0 , 0 , 0 ));
1515 // With the version below, this caused weird CI issues when FLX_NO_POINT_POOL is defined
1616 // static var _pool = new FlxPool<FlxRect>(FlxRect);
17-
17+
18+ static inline function getPooled (weak = false ): FlxRect
19+ {
20+ final rect = _pool .get ();
21+ rect ._inPool = false ;
22+ rect ._weak = weak ;
23+ return rect ;
24+ }
25+
1826 /**
1927 * Recycle or create new FlxRect.
2028 * Be sure to put() them back into the pool after you're done with them!
2129 */
22- public static inline function get (X : Float = 0 , Y : Float = 0 , Width : Float = 0 , Height : Float = 0 ): FlxRect
30+ public static inline function get (x = 0.0 , y = 0.0 , width = 0.0 , height = 0. 0 ): FlxRect
2331 {
24- var rect = _pool .get ().set (X , Y , Width , Height );
25- rect ._inPool = false ;
26- return rect ;
32+ return getPooled ().set (x , y , width , height );
2733 }
2834
2935 /**
3036 * Recycle or create a new FlxRect which will automatically be released
3137 * to the pool when passed into a flixel function.
3238 */
33- public static inline function weak (X : Float = 0 , Y : Float = 0 , Width : Float = 0 , Height : Float = 0 ): FlxRect
39+ public static inline function weak (x = 0.0 , y = 0.0 , width = 0.0 , height = 0. 0 ): FlxRect
3440 {
35- var rect = get (X , Y , Width , Height );
36- rect ._weak = true ;
37- return rect ;
41+ return getPooled (true ).set (x , y , width , height );
3842 }
3943
4044 public var x : Float ;
@@ -84,7 +88,6 @@ class FlxRect implements IFlxPooled
8488 if (! _inPool )
8589 {
8690 _inPool = true ;
87- _weak = false ;
8891 _pool .putUnsafe (this );
8992 }
9093 }
@@ -220,46 +223,56 @@ class FlxRect implements IFlxPooled
220223 {
221224 return setAbs (x1 , y1 , x2 - x1 , y2 - y1 );
222225 }
223-
226+
224227 /**
225228 * Helper function, just copies the values from the specified rectangle.
226229 *
227- * @param Rect Any FlxRect.
228- * @return A reference to itself.
230+ * @param rect Any FlxRect.
231+ * @return A reference to itself.
229232 */
230- public inline function copyFrom (Rect : FlxRect ): FlxRect
233+ public inline function copyFrom (rect : FlxRect ): FlxRect
231234 {
232- x = Rect .x ;
233- y = Rect .y ;
234- width = Rect .width ;
235- height = Rect .height ;
236-
237- Rect .putWeak ();
235+ x = rect .x ;
236+ y = rect .y ;
237+ width = rect .width ;
238+ height = rect .height ;
239+
240+ rect .putWeak ();
238241 return this ;
239242 }
240-
243+
241244 /**
242245 * Helper function, just copies the values from this rectangle to the specified rectangle.
243246 *
244- * @param Point Any FlxRect.
245- * @return A reference to the altered rectangle parameter.
247+ * @param point Any FlxRect.
248+ * @return A reference to the altered rectangle parameter.
246249 */
247- public inline function copyTo (Rect : FlxRect ): FlxRect
250+ public inline function copyTo (rect : FlxRect ): FlxRect
248251 {
249- Rect .x = x ;
250- Rect .y = y ;
251- Rect .width = width ;
252- Rect .height = height ;
253-
254- Rect . putWeak ();
255- return Rect ;
252+ rect .x = x ;
253+ rect .y = y ;
254+ rect .width = width ;
255+ rect .height = height ;
256+
257+ putWeak ();
258+ return rect ;
256259 }
257260
261+ /**
262+ * Copies this rect's data into a new instance (from the pool)
263+ *
264+ * @return A new rectangle
265+ */
266+ public inline function clone (): FlxRect
267+ {
268+ return copyTo (getPooled ());
269+ }
270+
258271 /**
259272 * Helper function, just copies the values from the specified Flash rectangle.
260273 *
261- * @param FlashRect Any Rectangle.
262- * @return A reference to itself.
274+ * @param flashRect Any Rectangle.
275+ * @return A reference to itself.
263276 */
264277 public inline function copyFromFlash (FlashRect : Rectangle ): FlxRect
265278 {
0 commit comments