summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--geometry.c9
-rw-r--r--geometry.h2
2 files changed, 10 insertions, 1 deletions
diff --git a/geometry.c b/geometry.c
index f2961c7..7c29f85 100644
--- a/geometry.c
+++ b/geometry.c
@@ -29,3 +29,12 @@ int
29dist_pp(LPoint const * p0, LPoint const * p1) { 29dist_pp(LPoint const * p0, LPoint const * p1) {
30 return impl_dist_pp(p0->x,p0->y,p1->x,p1->y); 30 return impl_dist_pp(p0->x,p0->y,p1->x,p1->y);
31} 31}
32
33int
34get_x_for_y(LPoint const * p0, LPoint const * p1, int y) {
35 if (p1->x!=p0->x && p1->y!=p0->y) {
36 double m = (double)(p1->y-p0->y) / (double)(p1->x-p0->x);
37 return (int)((((double)y) - (double)(p0->y) + m * (double)p0->x)/m);
38 }
39 return p1->x;
40}
diff --git a/geometry.h b/geometry.h
index 509ec7e..049fba4 100644
--- a/geometry.h
+++ b/geometry.h
@@ -15,4 +15,4 @@ typedef struct {
15// range 0..65536 (but can extend, if normale hits line outside line segment) 15// range 0..65536 (but can extend, if normale hits line outside line segment)
16int dist_pl(LPoint const * p, LLine const * l, int * offs); 16int dist_pl(LPoint const * p, LLine const * l, int * offs);
17int dist_pp(LPoint const * p0, LPoint const * p1); 17int dist_pp(LPoint const * p0, LPoint const * p1);
18 18int get_x_for_y(LPoint const * p0, LPoint const * p1, int y);