summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Spragg <adam@spra.gg>2022-12-19 13:51:54 +0000
committerAdam Spragg <adam@spra.gg>2022-12-19 13:51:54 +0000
commit53200a55a96854f293ec5bef38df08e4883bae1b (patch)
treec603a1b4a9914a40e48bcc474f89d2ec36610f1e
parent92db00a1c343680bf00123cc27153a4acef39a88 (diff)
Rename `struct face` to `struct point`
-rw-r--r--18.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/18.c b/18.c
index 05c7940..6d7ca6d 100644
--- a/18.c
+++ b/18.c
@@ -10,7 +10,7 @@
#define arrlen(x) (sizeof(x)/sizeof((x)[0]))
-struct face {
+struct point {
int x;
int y;
int z;
@@ -18,7 +18,7 @@ struct face {
int
-face_cmp(struct face const * a, struct face const * b)
+point_cmp(struct point const * a, struct point const * b)
{
if (a->x != b->x)
return a->x - b->x;
@@ -29,9 +29,9 @@ face_cmp(struct face const * a, struct face const * b)
int
-face_cmp_t(void const * a, void const * b)
+point_cmp_t(void const * a, void const * b)
{
- return face_cmp(a, b);
+ return point_cmp(a, b);
}
@@ -41,12 +41,12 @@ face_cmp_t(void const * a, void const * b)
// y = up-down
// z = front-back
//
-// For a cube, we scale it by a factor of two, and then identify each face by
-// the point at its center.
-struct face *
+// To uniquely identify the faces of a cube, we scale the cube by a factor of
+// two, and then identify each face by the point at the face's center.
+struct point *
cube_face(int x, int y, int z, int face)
{
- struct face * f;
+ struct point * f;
x *= 2;
y *= 2;
@@ -90,7 +90,7 @@ cube_face(int x, int y, int z, int face)
return NULL;
}
- if ((f = malloc(sizeof(struct face))) == NULL)
+ if ((f = malloc(sizeof(struct point))) == NULL)
return NULL;
f->x = x;
@@ -124,9 +124,9 @@ main()
z = atoi(buf + coords[3].rm_so);
for (f = 0; f < 6; ++f) {
- struct face * face = cube_face(x, y, z, f);
+ struct point * face = cube_face(x, y, z, f);
- struct face * exists = *((struct face **) tsearch(face, &faces, face_cmp_t));
+ struct point * exists = *((struct point **) tsearch(face, &faces, point_cmp_t));
if (exists == face) {
// Inserted new face
@@ -134,7 +134,7 @@ main()
}
else {
// Face already existed, so delete it
- tdelete(face, &faces, face_cmp_t);
+ tdelete(face, &faces, point_cmp_t);
--nfaces;
free(face);
free(exists);