@@ -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 = { _version = " 1 .0" }
12+ local Rect = { _version = " 2 .0" }
1313Rect .__index = Rect
1414
1515--- Creates a new Rect. Equivalent to calling the class: `Rect(...)`.
@@ -29,7 +29,7 @@ function Rect.new(minX, minY, maxX, maxY)
2929 minY = minY ,
3030 maxX = maxX ,
3131 maxY = maxY ,
32- }, Rect )
32+ }, Rect --[[ @as table ]] )
3333end
3434
3535--- Creates a new Rect from XYWH parameters.
@@ -49,7 +49,7 @@ function Rect.fromXYWH(x, y, width, height)
4949 minY = y ,
5050 maxX = x + width ,
5151 maxY = y + height ,
52- }, Rect )
52+ }, Rect --[[ @as table ]] )
5353end
5454
5555--- Returns all components of this Rect.
157157--- @return Rect
158158function Rect :cut_left (a )
159159 local left = self :get_left (a )
160- self .minX = left .minX
160+ self .minX = left .maxX
161161 return left
162162end
163163
@@ -172,7 +172,7 @@ function Rect:cutLeft(a) return Rect:cut_left(a) end
172172--- @return Rect
173173function Rect :cut_right (a )
174174 local right = self :get_right (a )
175- self .maxX = right .maxX
175+ self .maxX = right .minX
176176 return right
177177end
178178
@@ -187,7 +187,7 @@ function Rect:cutRight(a) return Rect:cut_right(a) end
187187--- @return Rect
188188function Rect :cut_top (a )
189189 local top = self :get_top (a )
190- self .minY = top .minY
190+ self .minY = top .maxY
191191 return top
192192end
193193
@@ -202,7 +202,7 @@ function Rect:cutTop(a) return Rect:cut_top(a) end
202202--- @return Rect
203203function Rect :cut_bottom (a )
204204 local bottom = self :get_bottom (a )
205- self .maxY = bottom .maxY
205+ self .maxY = bottom .minY
206206 return bottom
207207end
208208
212212--- @see Rect.cut_bottom
213213function Rect :cutBottom (a ) return Rect :cut_bottom (a ) end
214214
215- --- Returns this rect, with `a` added to its left side.
215+ --- Returns a copy of this rect, with `a` added to its left side.
216216--- @param a number
217217--- @return Rect
218218function Rect :add_left (a ) return Rect .new (self .minX - a , self .minY , self .maxX , self .maxY ) end
@@ -223,7 +223,7 @@ function Rect:add_left(a) return Rect.new(self.minX - a, self.minY, self.maxX, s
223223--- @see Rect.add_left
224224function Rect :addLeft (a ) return Rect :add_left (a ) end
225225
226- --- Returns this rect, with `a` added to its right side.
226+ --- Returns a copy of this rect, with `a` added to its right side.
227227--- @param a number
228228--- @return Rect
229229function Rect :add_right (a ) return Rect .new (self .minX , self .minY , self .maxX + a , self .maxY ) end
@@ -234,7 +234,7 @@ function Rect:add_right(a) return Rect.new(self.minX, self.minY, self.maxX + a,
234234--- @see Rect.add_right
235235function Rect :addRight (a ) return Rect :add_right (a ) end
236236
237- --- Returns this rect, with `a` added to its top side.
237+ --- Returns a copy of this rect, with `a` added to its top side.
238238--- @param a number
239239--- @return Rect
240240function Rect :add_top (a ) return Rect .new (self .minX , self .minY - a , self .maxX , self .maxY ) end
@@ -245,7 +245,7 @@ function Rect:add_top(a) return Rect.new(self.minX, self.minY - a, self.maxX, se
245245--- @see Rect.add_top
246246function Rect :addTop (a ) return Rect :add_top (a ) end
247247
248- --- Returns this rect, with `a` added to its bottom side.
248+ --- Returns a copy of this rect, with `a` added to its bottom side.
249249--- @param a number
250250--- @return Rect
251251function Rect :add_bottom (a ) return Rect .new (self .minX , self .minY , self .maxX , self .maxY + a ) end
@@ -278,9 +278,9 @@ function Rect:contract(a) return Rect.new(self.minX + a, self.minY + a, self.max
278278
279279--- @return string
280280function Rect :__tostring ()
281- return string.format (" Rect: X(%f-%f ), Y(%f-%f )" , self :unpack ())
281+ return string.format (" Rect: min(%g,%g ), max(%g,%g )" , self :unpack ())
282282end
283283
284- return setmetatable (Rect , {
284+ return setmetatable (Rect --[[ @as table ]] , {
285285 __call = function (cls , ...) return cls .new (... ) end ,
286- })
286+ }) --[[ @as Rect ]]
0 commit comments