Skip to content

Commit 54ca61f

Browse files
committed
release 1.1: add camelCase aliases for all Rect methods, improve unknown side errors
1 parent c3c8390 commit 54ca61f

File tree

1 file changed

+75
-3
lines changed

1 file changed

+75
-3
lines changed

init.lua

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ end
7474
---@return Rect
7575
function Rect:get(side, a)
7676
local f = self["get_" .. side]
77-
assert(f, "no such side: " .. side)
77+
assert(f, "rectcut: no such side '" .. side .. "'")
7878
return f(self, a)
7979
end
8080

@@ -88,6 +88,12 @@ function Rect:get_left(a)
8888
)
8989
end
9090

91+
---Alias for `get_left`.
92+
---@param a number
93+
---@return Rect
94+
---@see Rect.get_left
95+
function Rect:getLeft(a) return Rect:get_left(a) end
96+
9197
---Same as `cut_right`, expect it keeps the Rect intact.
9298
---@param a number
9399
---@return Rect
@@ -98,6 +104,12 @@ function Rect:get_right(a)
98104
)
99105
end
100106

107+
---Alias for `get_right`.
108+
---@param a number
109+
---@return Rect
110+
---@see Rect.get_right
111+
function Rect:getRight(a) return Rect:get_right(a) end
112+
101113
---Same as `cut_top`, expect it keeps the Rect intact.
102114
---@param a number
103115
---@return Rect
@@ -108,6 +120,12 @@ function Rect:get_top(a)
108120
)
109121
end
110122

123+
---Alias for `get_top`.
124+
---@param a number
125+
---@return Rect
126+
---@see Rect.get_top
127+
function Rect:getTop(a) return Rect:get_top(a) end
128+
111129
---Same as `cut_bottom`, expect it keeps the Rect intact.
112130
---@param a number
113131
---@return Rect
@@ -118,13 +136,19 @@ function Rect:get_bottom(a)
118136
)
119137
end
120138

139+
---Alias for `get_bottom`.
140+
---@param a number
141+
---@return Rect
142+
---@see Rect.get_bottom
143+
function Rect:getBottom(a) return Rect:get_bottom(a) end
144+
121145
---A variant of the `cut_*` methods that takes in the side to cut from.
122146
---@param side "left"|"right"|"top"|"bottom"
123147
---@param a number
124148
---@return Rect
125149
function Rect:cut(side, a)
126150
local f = self["cut_" .. side]
127-
assert(f, "no such side: " .. side)
151+
assert(f, "rectcut: no such side '" .. side .. "'")
128152
return f(self, a)
129153
end
130154

@@ -137,6 +161,12 @@ function Rect:cut_left(a)
137161
return left
138162
end
139163

164+
---Alias for `cut_left`.
165+
---@param a number
166+
---@return Rect
167+
---@see Rect.cut_left
168+
function Rect:cutLeft(a) return Rect:cut_left(a) end
169+
140170
---Cuts `a` from the right side of the Rect, and returns the cut part.
141171
---@param a number
142172
---@return Rect
@@ -146,6 +176,12 @@ function Rect:cut_right(a)
146176
return right
147177
end
148178

179+
---Alias for `cut_right`.
180+
---@param a number
181+
---@return Rect
182+
---@see Rect.cut_right
183+
function Rect:cutRight(a) return Rect:cut_right(a) end
184+
149185
---Cuts `a` from the top side of the Rect, and returns the cut part.
150186
---@param a number
151187
---@return Rect
@@ -155,6 +191,12 @@ function Rect:cut_top(a)
155191
return top
156192
end
157193

194+
---Alias for `cut_top`.
195+
---@param a number
196+
---@return Rect
197+
---@see Rect.cut_top
198+
function Rect:cutTop(a) return Rect:cut_top(a) end
199+
158200
---Cuts `a` from the bottom side of the Rect, and returns the cut part.
159201
---@param a number
160202
---@return Rect
@@ -164,33 +206,63 @@ function Rect:cut_bottom(a)
164206
return bottom
165207
end
166208

209+
---Alias for `cut_bottom`.
210+
---@param a number
211+
---@return Rect
212+
---@see Rect.cut_bottom
213+
function Rect:cutBottom(a) return Rect:cut_bottom(a) end
214+
167215
---Returns this rect, with `a` added to its left side.
168216
---@param a number
169217
---@return Rect
170218
function Rect:add_left(a) return Rect.new(self.minX - a, self.minY, self.maxX, self.maxY) end
171219

220+
---Alias for `add_left`.
221+
---@param a number
222+
---@return Rect
223+
---@see Rect.add_left
224+
function Rect:addLeft(a) return Rect:add_left(a) end
225+
172226
---Returns this rect, with `a` added to its right side.
173227
---@param a number
174228
---@return Rect
175229
function Rect:add_right(a) return Rect.new(self.minX, self.minY, self.maxX + a, self.maxY) end
176230

231+
---Alias for `add_right`.
232+
---@param a number
233+
---@return Rect
234+
---@see Rect.add_right
235+
function Rect:addRight(a) return Rect:add_right(a) end
236+
177237
---Returns this rect, with `a` added to its top side.
178238
---@param a number
179239
---@return Rect
180240
function Rect:add_top(a) return Rect.new(self.minX, self.minY - a, self.maxX, self.maxY) end
181241

242+
---Alias for `add_top`.
243+
---@param a number
244+
---@return Rect
245+
---@see Rect.add_top
246+
function Rect:addTop(a) return Rect:add_top(a) end
247+
182248
---Returns this rect, with `a` added to its bottom side.
183249
---@param a number
184250
---@return Rect
185251
function Rect:add_bottom(a) return Rect.new(self.minX, self.minY, self.maxX, self.maxY + a) end
186252

253+
---Alias for `add_bottom`.
254+
---@param a number
255+
---@return Rect
256+
---@see Rect.add_bottom
257+
function Rect:addBottom(a) return Rect:add_bottom(a) end
258+
187259
---A variant of the `add_*` methods that takes in the side to add from.
188260
---@param side "left"|"right"|"top"|"bottom"
189261
---@param a number
190262
---@return Rect
191263
function Rect:add(side, a)
192264
local f = self["add_" .. side]
193-
assert(f, "no such side: " .. side)
265+
assert(f, "rectcut: no such side '" .. side .. "'")
194266
return f(self, a)
195267
end
196268

0 commit comments

Comments
 (0)