commit 9b9bc15a79d495a140ede7fd33dfa9bb4ed149aa parent 8fca640bea4ef2e99450992827f4aa54d53eb707 Author: sin <sin@2f30.org> Date: Tue, 9 Jun 2015 17:35:54 +0100 Use taxicab metric for k-medians Diffstat:
M | colors.c | | | 12 | +++++++++--- |
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/colors.c b/colors.c @@ -40,9 +40,15 @@ distance(struct point *p1, struct point *p2) { int dx, dy, dz; - dx = (p1->x - p2->x) * (p1->x - p2->x); - dy = (p1->y - p2->y) * (p1->y - p2->y); - dz = (p1->z - p2->z) * (p1->z - p2->z); + if (mflag) { + dx = abs(p1->x - p2->x); + dy = abs(p1->y - p2->y); + dz = abs(p1->z - p2->z); + } else { + dx = (p1->x - p2->x) * (p1->x - p2->x); + dy = (p1->y - p2->y) * (p1->y - p2->y); + dz = (p1->z - p2->z) * (p1->z - p2->z); + } return dx + dy + dz; }