diff options
-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); | |