diff options
author | erdgeist <erdgeist@bauklotz.fritz.box> | 2017-04-09 22:08:28 +0200 |
---|---|---|
committer | erdgeist <erdgeist@bauklotz.fritz.box> | 2017-04-09 22:08:28 +0200 |
commit | 804f3bce8ad4dfd48186f0030252067f69b62e07 (patch) | |
tree | f70b7e33a3c3f34f615893b2e3d04feb51cbdc97 | |
parent | 0ab1e4878f9e2b592032dc7c67ae8018293058f6 (diff) |
Add function to find a point for a certain offset
-rw-r--r-- | geometry.c | 9 | ||||
-rw-r--r-- | geometry.h | 2 |
2 files changed, 10 insertions, 1 deletions
@@ -29,3 +29,12 @@ int | |||
29 | dist_pp(LPoint const * p0, LPoint const * p1) { | 29 | dist_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 | |||
33 | int | ||
34 | get_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 | } | ||
@@ -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) |
16 | int dist_pl(LPoint const * p, LLine const * l, int * offs); | 16 | int dist_pl(LPoint const * p, LLine const * l, int * offs); |
17 | int dist_pp(LPoint const * p0, LPoint const * p1); | 17 | int dist_pp(LPoint const * p0, LPoint const * p1); |
18 | 18 | int get_x_for_y(LPoint const * p0, LPoint const * p1, int y); | |