shithub: libgraphics

Download patch

ref: 524e19eee808837873435f908fd9b80a372673f8
parent: 6477319da461ad78a120a3c777228eaa8194c9f8
author: rodri <rgl@antares-labs.eu>
date: Sun Jul 5 06:41:59 EDT 2020

move the edge function out into libgeometry.

--- a/triangle.c
+++ b/triangle.c
@@ -4,27 +4,6 @@
 #include <geometry.h>
 #include <graphics.h>
 
-/*
- * comparison of a point p with an edge [e0 e1]
- * p to the right: +
- * p to the left: -
- * p on the edge: 0
- */
-static int
-edgeptcmp(Point e0, Point e1, Point p)
-{
-	Point3 e0p, e01, r;
-
-	p = subpt(p, e0);
-	e1 = subpt(e1, e0);
-	e0p = Vec3(p.x,p.y,0);
-	e01 = Vec3(e1.x,e1.y,0);
-	r = crossvec3(e0p, e01);
-
-	/* clamp to avoid overflow */
-	return fclamp(r.z, -1, 1); /* e0.x*e1.y - e0.y*e1.x */
-}
-
 Triangle
 Trian(int x0, int y0, int x1, int y1, int x2, int y2)
 {
@@ -60,13 +39,4 @@
 	pl[2] = t.p2;
 
 	fillpoly(dst, pl, nelem(pl), 0, src, sp);
-}
-
-int
-ptintriangle(Point p, Triangle t)
-{
-	/* counter-clockwise check */
-	return edgeptcmp(t.p0, t.p2, p) <= 0 &&
-		edgeptcmp(t.p2, t.p1, p) <= 0 &&
-		edgeptcmp(t.p1, t.p0, p) <= 0;
 }