shithub: lua9

Download patch

ref: bf655bb17b29d15adba296dd9bd1ae1d8983e744
parent: 7e5fa392e9477ea3c15741a6c4a579cebf17263f
author: telephil9 <telephil9@gmail.com>
date: Tue Oct 27 05:25:30 EDT 2020

Added most missing geometry functions

	New functions added:
		rpt, eqpt, eqrect, ptinrect, rectinrect, rectxrect, badrect, dx, dy

	Documentation updated to reflect these additions.

--- a/doc/README.md
+++ b/doc/README.md
@@ -82,6 +82,7 @@
 
 #### `g.pt(x, y)`
 #### `g.rect(x0, y0, x1, y1)`
+#### `g.rpt(p, q)`
 #### `g.addpt(p, q)`
 #### `g.subpt(p, q)`
 #### `g.mulpt(p, a)`
@@ -90,7 +91,14 @@
 #### `g.rectsubpt(r, p)`
 #### `g.insetrect(r, n)`
 #### `g.canonrect(r)`
-
+#### `g.eqpt(p, q)`
+#### `g.eqrect(r, s)`
+#### `g.ptinrect(p, r)`
+#### `g.rectinrect(r, s)`
+#### `g.rectxrect(r, s)`
+#### `g.badrect(r)`
+#### `g.dx(r)`
+#### `g.dy(r)`
 
 ### Module `key`
 
--- a/geometry.c
+++ b/geometry.c
@@ -137,6 +137,17 @@
 }
 
 static int
+lrpt(lua_State *L)
+{
+	Point p, q;
+
+	p = checkpoint(L, 1);
+	q = checkpoint(L, 2);
+	pushrect(L, Rpt(p, q));
+	return 1;
+}
+
+static int
 laddpt(lua_State *L)
 {
 	Point p, q, r;
@@ -230,9 +241,96 @@
 	return 1;
 }
 
+static int
+leqpt(lua_State *L)
+{
+	Point p, q;
+
+	p = checkpoint(L, 1);
+	q = checkpoint(L, 2);
+	lua_pushboolean(L, eqpt(p, q));
+	return 1;
+}
+
+static int
+leqrect(lua_State *L)
+{
+	Rectangle r, s;
+
+	r = checkrect(L, 1);
+	s = checkrect(L, 2);
+	lua_pushboolean(L, eqrect(r, s));
+	return 1;
+}
+
+static int
+lptinrect(lua_State *L)
+{
+	Point p;
+	Rectangle r;
+
+	p = checkpoint(L, 1);
+	r = checkrect(L, 2);
+	lua_pushboolean(L, ptinrect(p, r));
+	return 1;
+}
+
+static int
+lrectinrect(lua_State *L)
+{
+	Rectangle r, s;
+
+	r = checkrect(L, 1);
+	s = checkrect(L, 2);
+	lua_pushboolean(L, rectinrect(r, s));
+	return 1;
+}
+
+static int
+lrectxrect(lua_State *L)
+{
+	Rectangle r, s;
+
+	r = checkrect(L, 1);
+	s = checkrect(L, 2);
+	lua_pushboolean(L, rectXrect(r, s));
+	return 1;
+}
+
+static int
+lbadrect(lua_State *L)
+{
+	Rectangle r;
+
+	r = checkrect(L, 1);
+	lua_pushboolean(L, badrect(r));
+	return 1;
+}
+
+static int
+ldx(lua_State *L)
+{
+	Rectangle r;
+
+	r = checkrect(L, 1);
+	lua_pushinteger(L, Dx(r));
+	return 1;
+}
+
+static int
+ldy(lua_State *L)
+{
+	Rectangle r;
+
+	r = checkrect(L, 1);
+	lua_pushinteger(L, Dy(r));
+	return 1;
+}
+
 static const struct luaL_Reg libgeometry [] = {
 	{ "pt", lpt },
 	{ "rect", lrect },
+	{ "rpt", lrpt },
 	{ "addpt", laddpt },
 	{ "subpt", lsubpt },
 	{ "mulpt", lmulpt },
@@ -241,6 +339,14 @@
 	{ "rectsubpt", lrectsubpt },
 	{ "insetrect", linsetrect },
 	{ "canonrect", lcanonrect },
+	{ "eqpt", leqpt },
+	{ "eqrect", leqrect },
+	{ "ptinrect", lptinrect },
+	{ "rectinrect", lrectinrect },
+	{ "rectxrect", lrectxrect },
+	{ "badrect", lbadrect },
+	{ "dx", ldx },
+	{ "dy", ldy },
 	{ NULL, NULL },
 };