@@ -9,7 +9,7 @@ local min, max = math.min, math.max
99--- @field public maxY number
1010--- @overload fun ( minX : number , minY : number , maxX : number , maxY : number ): Rect
1111--- @overload fun ( r : { minX : number , minY : number , maxX : number , maxY : number }): Rect
12- local Rect = {}
12+ local Rect = { _version = " 1.0 " }
1313Rect .__index = Rect
1414
1515--- Creates a new Rect. Equivalent to calling the class: `Rect(...)`.
@@ -68,6 +68,16 @@ function Rect:xywh()
6868 self .minY + (self .maxY - self .minY )
6969end
7070
71+ --- A variant of the `get_*` methods that takes in the side to get from.
72+ --- @param side " left" | " right" | " top" | " bottom"
73+ --- @param a number
74+ --- @return Rect
75+ function Rect :get (side , a )
76+ local f = self [" get_" .. side ]
77+ assert (f , " no such side: " .. side )
78+ return f (self , a )
79+ end
80+
7181--- Same as `cut_left`, except it keeps the Rect intact.
7282--- @param a number
7383--- @return Rect
@@ -108,6 +118,16 @@ function Rect:get_bottom(a)
108118 )
109119end
110120
121+ --- A variant of the `cut_*` methods that takes in the side to cut from.
122+ --- @param side " left" | " right" | " top" | " bottom"
123+ --- @param a number
124+ --- @return Rect
125+ function Rect :cut (side , a )
126+ local f = self [" cut_" .. side ]
127+ assert (f , " no such side: " .. side )
128+ return f (self , a )
129+ end
130+
111131--- Cuts `a` from the left side of the Rect, and returns the cut part.
112132--- @param a number
113133--- @return Rect
@@ -164,6 +184,16 @@ function Rect:add_top(a) return Rect.new(self.minX, self.minY - a, self.maxX, se
164184--- @return Rect
165185function Rect :add_bottom (a ) return Rect .new (self .minX , self .minY , self .maxX , self .maxY + a ) end
166186
187+ --- A variant of the `add_*` methods that takes in the side to add from.
188+ --- @param side " left" | " right" | " top" | " bottom"
189+ --- @param a number
190+ --- @return Rect
191+ function Rect :add (side , a )
192+ local f = self [" add_" .. side ]
193+ assert (f , " no such side: " .. side )
194+ return f (self , a )
195+ end
196+
167197--- Returns an extended version of this Rect.
168198--- @param a number
169199--- @return Rect
0 commit comments