aboutsummaryrefslogtreecommitdiff
path: root/km-draw.c
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2019-02-03 15:10:44 -0500
committerPaul Duncan <pabs@pablotron.org>2019-02-03 15:10:44 -0500
commitdf06fe6084b1c1673348050309a3a0cb99b6634f (patch)
treebb51c86aee01ca235f7c6feb5fb08808c307e2ed /km-draw.c
parent68a4d7a514578f1360559c84ac08e3a1e2719826 (diff)
downloadkmeans-df06fe6084b1c1673348050309a3a0cb99b6634f.tar.bz2
kmeans-df06fe6084b1c1673348050309a3a0cb99b6634f.zip
add cluster support to gen-data.rb, show centroids on generated png
Diffstat (limited to 'km-draw.c')
-rw-r--r--km-draw.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/km-draw.c b/km-draw.c
index 7f59df3..ddf1b26 100644
--- a/km-draw.c
+++ b/km-draw.c
@@ -8,23 +8,24 @@ km_set_draw(
uint8_t * const rgb,
const size_t width,
const size_t height,
+ const int dot_size,
const uint32_t color
) {
for (size_t i = 0; i < set->num_rows; i++) {
const float *row = km_set_get_row(set, i);
- const size_t x = (width - 1) * row[0],
- y = (height - 1) * row[1],
- ofs = 3 * (width * y + x);
- if (x >= width || y >= height) {
- die(
- "km_set_draw(): point out of bounds (row: %zu, point: [%0.2f, %0.2f], pixel: %zux%zu, bounds: %zux%zu)",
- i, row[0], row[1], x, y, width, height
- );
+ for (int yo = 0; yo < dot_size; yo++) {
+ for (int xo = 0; xo < dot_size; xo++) {
+ const int x = (width - 1) * row[0] - dot_size / 2 + xo,
+ y = (height - 1) * row[1] - dot_size / 2 + yo,
+ ofs = 3 * (width * y + x);
+
+ if (x >= 0 && x < (int) width && y >= 0 && y < (int) height) {
+ rgb[ofs + 0] = (color & 0xff0000) >> 16;
+ rgb[ofs + 1] = (color & 0x00ff00) >> 8;
+ rgb[ofs + 2] = (color & 0x0000ff);
+ }
+ }
}
-
- rgb[ofs + 0] = (color & 0xff0000) >> 16;
- rgb[ofs + 1] = (color & 0x00ff00) >> 8;
- rgb[ofs + 2] = (color & 0x0000ff);
}
}