summaryrefslogtreecommitdiff
path: root/meme
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2014-09-12 12:30:58 -0300
committerWerner Almesberger <werner@almesberger.net>2014-09-12 12:30:58 -0300
commit13c605449235253d363e0dc1653e7a09f6c700be (patch)
tree2dec11ee2045bea5b0300a001755190de2b6224d /meme
parent4bf74ea8830dad30563b77143da0c7c57ae03a01 (diff)
downloadmisc-13c605449235253d363e0dc1653e7a09f6c700be.tar.gz
misc-13c605449235253d363e0dc1653e7a09f6c700be.tar.bz2
misc-13c605449235253d363e0dc1653e7a09f6c700be.zip
meme/gui.c (proximity_fn): faster processing of points that are far away
before: min/avg/max = 31/38/52 ms after: min/avg/max = 17/25/39 ms
Diffstat (limited to 'meme')
-rw-r--r--meme/gui.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/meme/gui.c b/meme/gui.c
index 2dd247b..7d02ad4 100644
--- a/meme/gui.c
+++ b/meme/gui.c
@@ -19,6 +19,7 @@
#include "SDL_gfxPrimitives.h"
#include "util.h"
+#include "time.h"
#include "mesh.h"
@@ -271,6 +272,7 @@ struct proximity {
};
+#if 0
static bool proximity_fn(const struct vertex *v, void *user)
{
struct proximity *p = user;
@@ -283,6 +285,28 @@ static bool proximity_fn(const struct vertex *v, void *user)
return 0;
}
+#else
+
+
+static bool proximity_fn(const struct vertex *v, void *user)
+{
+ struct proximity *p = user;
+ double d;
+
+ if (p->best &&
+ (abs(v->x - p->x) >= p->best_d || abs(v->y - p->y) >= p->best_d))
+ return 0;
+
+ d = hypot(v->x - p->x, v->y - p->y);
+ if (p->best && d >= p->best_d)
+ return 0;
+
+ p->best_d = d;
+ p->best = v;
+ return 0;
+}
+#endif
+
static const struct vertex *find_nearest(int x, int y)
{
@@ -291,8 +315,12 @@ static const struct vertex *find_nearest(int x, int y)
.y = y,
.best = NULL,
};
+ struct time t;
+ time_start(&t);
vertex_foreach_const(proximity_fn, &p);
+ time_stop(&t);
+ fprintf(stderr, "%.3f\t", time_ms(&t)/1000.0);
return p.best;
}