From 804f3bce8ad4dfd48186f0030252067f69b62e07 Mon Sep 17 00:00:00 2001 From: erdgeist Date: Sun, 9 Apr 2017 22:08:28 +0200 Subject: Add function to find a point for a certain offset --- geometry.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'geometry.c') diff --git a/geometry.c b/geometry.c index f2961c7..7c29f85 100644 --- a/geometry.c +++ b/geometry.c @@ -29,3 +29,12 @@ int dist_pp(LPoint const * p0, LPoint const * p1) { return impl_dist_pp(p0->x,p0->y,p1->x,p1->y); } + +int +get_x_for_y(LPoint const * p0, LPoint const * p1, int y) { + if (p1->x!=p0->x && p1->y!=p0->y) { + double m = (double)(p1->y-p0->y) / (double)(p1->x-p0->x); + return (int)((((double)y) - (double)(p0->y) + m * (double)p0->x)/m); + } + return p1->x; +} -- cgit v1.2.3