Skip to content

Commit bf655bb

Browse files
committed
Added most missing geometry functions
New functions added: rpt, eqpt, eqrect, ptinrect, rectinrect, rectxrect, badrect, dx, dy Documentation updated to reflect these additions.
1 parent 7e5fa39 commit bf655bb

File tree

2 files changed

+115
-1
lines changed

2 files changed

+115
-1
lines changed

doc/README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ Geometry related functions.
8282

8383
#### `g.pt(x, y)`
8484
#### `g.rect(x0, y0, x1, y1)`
85+
#### `g.rpt(p, q)`
8586
#### `g.addpt(p, q)`
8687
#### `g.subpt(p, q)`
8788
#### `g.mulpt(p, a)`
@@ -90,7 +91,14 @@ Geometry related functions.
9091
#### `g.rectsubpt(r, p)`
9192
#### `g.insetrect(r, n)`
9293
#### `g.canonrect(r)`
93-
94+
#### `g.eqpt(p, q)`
95+
#### `g.eqrect(r, s)`
96+
#### `g.ptinrect(p, r)`
97+
#### `g.rectinrect(r, s)`
98+
#### `g.rectxrect(r, s)`
99+
#### `g.badrect(r)`
100+
#### `g.dx(r)`
101+
#### `g.dy(r)`
94102

95103
### Module `key`
96104

geometry.c

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,17 @@ lrect(lua_State *L)
136136
return 1;
137137
}
138138

139+
static int
140+
lrpt(lua_State *L)
141+
{
142+
Point p, q;
143+
144+
p = checkpoint(L, 1);
145+
q = checkpoint(L, 2);
146+
pushrect(L, Rpt(p, q));
147+
return 1;
148+
}
149+
139150
static int
140151
laddpt(lua_State *L)
141152
{
@@ -230,9 +241,96 @@ lcanonrect(lua_State *L)
230241
return 1;
231242
}
232243

244+
static int
245+
leqpt(lua_State *L)
246+
{
247+
Point p, q;
248+
249+
p = checkpoint(L, 1);
250+
q = checkpoint(L, 2);
251+
lua_pushboolean(L, eqpt(p, q));
252+
return 1;
253+
}
254+
255+
static int
256+
leqrect(lua_State *L)
257+
{
258+
Rectangle r, s;
259+
260+
r = checkrect(L, 1);
261+
s = checkrect(L, 2);
262+
lua_pushboolean(L, eqrect(r, s));
263+
return 1;
264+
}
265+
266+
static int
267+
lptinrect(lua_State *L)
268+
{
269+
Point p;
270+
Rectangle r;
271+
272+
p = checkpoint(L, 1);
273+
r = checkrect(L, 2);
274+
lua_pushboolean(L, ptinrect(p, r));
275+
return 1;
276+
}
277+
278+
static int
279+
lrectinrect(lua_State *L)
280+
{
281+
Rectangle r, s;
282+
283+
r = checkrect(L, 1);
284+
s = checkrect(L, 2);
285+
lua_pushboolean(L, rectinrect(r, s));
286+
return 1;
287+
}
288+
289+
static int
290+
lrectxrect(lua_State *L)
291+
{
292+
Rectangle r, s;
293+
294+
r = checkrect(L, 1);
295+
s = checkrect(L, 2);
296+
lua_pushboolean(L, rectXrect(r, s));
297+
return 1;
298+
}
299+
300+
static int
301+
lbadrect(lua_State *L)
302+
{
303+
Rectangle r;
304+
305+
r = checkrect(L, 1);
306+
lua_pushboolean(L, badrect(r));
307+
return 1;
308+
}
309+
310+
static int
311+
ldx(lua_State *L)
312+
{
313+
Rectangle r;
314+
315+
r = checkrect(L, 1);
316+
lua_pushinteger(L, Dx(r));
317+
return 1;
318+
}
319+
320+
static int
321+
ldy(lua_State *L)
322+
{
323+
Rectangle r;
324+
325+
r = checkrect(L, 1);
326+
lua_pushinteger(L, Dy(r));
327+
return 1;
328+
}
329+
233330
static const struct luaL_Reg libgeometry [] = {
234331
{ "pt", lpt },
235332
{ "rect", lrect },
333+
{ "rpt", lrpt },
236334
{ "addpt", laddpt },
237335
{ "subpt", lsubpt },
238336
{ "mulpt", lmulpt },
@@ -241,6 +339,14 @@ static const struct luaL_Reg libgeometry [] = {
241339
{ "rectsubpt", lrectsubpt },
242340
{ "insetrect", linsetrect },
243341
{ "canonrect", lcanonrect },
342+
{ "eqpt", leqpt },
343+
{ "eqrect", leqrect },
344+
{ "ptinrect", lptinrect },
345+
{ "rectinrect", lrectinrect },
346+
{ "rectxrect", lrectxrect },
347+
{ "badrect", lbadrect },
348+
{ "dx", ldx },
349+
{ "dy", ldy },
244350
{ NULL, NULL },
245351
};
246352

0 commit comments

Comments
 (0)