From 3b06ad551d6706907b0d6cbf25807e1ef7e62ca9 Mon Sep 17 00:00:00 2001 From: rodri Date: Tue, 27 Aug 2024 12:06:45 +0000 Subject: remove duplicate min and max functions. --- med.c | 20 ++++---------------- procgen.c | 3 --- solar.c | 28 ++++++++-------------------- vis.c | 30 +++++++++--------------------- 4 files changed, 21 insertions(+), 60 deletions(-) diff --git a/med.c b/med.c index 1f5949a..1ca8ce7 100644 --- a/med.c +++ b/med.c @@ -106,18 +106,6 @@ static int doprof; static int showhud; Color (*tsampler)(Texture*,Point2); -static int -min(int a, int b) -{ - return a < b? a: b; -} - -static int -max(int a, int b) -{ - return a > b? a: b; -} - static Point3 Vecquat(Quaternion q) { @@ -291,13 +279,13 @@ gouraudvshader(VSparams *sp) ambient = mulpt3(lightc, Ka); ambient = modulapt3(ambient, m.diffuse); - Kd = fmax(0, dotvec3(sp->v->n, lightdir)); + Kd = max(0, dotvec3(sp->v->n, lightdir)); diffuse = mulpt3(lightc, Kd); diffuse = modulapt3(diffuse, m.diffuse); lookdir = normvec3(subpt3(sp->su->camera->p, pos)); lightdir = qrotate(lightdir, sp->v->n, PI); - spec = pow(fmax(0, dotvec3(lookdir, lightdir)), m.shininess); + spec = pow(max(0, dotvec3(lookdir, lightdir)), m.shininess); specular = mulpt3(lightc, spec*Ks); specular = modulapt3(specular, m.specular); @@ -403,7 +391,7 @@ phongshader(FSparams *sp) ambient = mulpt3(lightc, Ka); ambient = modulapt3(ambient, m.diffuse); - Kd = fmax(0, dotvec3(n, lightdir)); + Kd = max(0, dotvec3(n, lightdir)); diffuse = mulpt3(lightc, Kd); diffuse = modulapt3(diffuse, m.diffuse); @@ -412,7 +400,7 @@ phongshader(FSparams *sp) lookdir = normvec3(subpt3(sp->su->camera->p, pos)); lightdir = qrotate(lightdir, n, PI); - spec = pow(fmax(0, dotvec3(lookdir, lightdir)), m.shininess); + spec = pow(max(0, dotvec3(lookdir, lightdir)), m.shininess); specular = mulpt3(lightc, spec*Ks); specular = modulapt3(specular, m.specular); diff --git a/procgen.c b/procgen.c index 7d48777..0cf6aab 100644 --- a/procgen.c +++ b/procgen.c @@ -17,9 +17,6 @@ #include "libgraphics/graphics.h" #include "fns.h" -#define min(a, b) ((a)<(b)?(a):(b)) -#define max(a, b) ((a)>(b)?(a):(b)) - Renderer *rctl; Camera *cam; Scene *scn; diff --git a/solar.c b/solar.c index f1cc68a..6a5bc75 100644 --- a/solar.c +++ b/solar.c @@ -168,26 +168,14 @@ static int showskybox; static int doprof; static int showhud; -static int -min(int a, int b) -{ - return a < b? a: b; -} - -static int -max(int a, int b) -{ - return a > b? a: b; -} - static Point3 minpt3(Point3 a, Point3 b) { return (Point3){ - fmin(a.x, b.x), - fmin(a.y, b.y), - fmin(a.z, b.z), - fmin(a.w, b.w) + min(a.x, b.x), + min(a.y, b.y), + min(a.z, b.z), + min(a.w, b.w) }; } @@ -195,10 +183,10 @@ static Point3 maxpt3(Point3 a, Point3 b) { return (Point3){ - fmax(a.x, b.x), - fmax(a.y, b.y), - fmax(a.z, b.z), - fmax(a.w, b.w) + max(a.x, b.x), + max(a.y, b.y), + max(a.z, b.z), + max(a.w, b.w) }; } diff --git a/vis.c b/vis.c index dbd08f1..89b862f 100644 --- a/vis.c +++ b/vis.c @@ -97,18 +97,6 @@ static int depthon; static int abuffon; Color (*tsampler)(Texture*,Point2); -static int -min(int a, int b) -{ - return a < b? a: b; -} - -static int -max(int a, int b) -{ - return a > b? a: b; -} - static Point3 Vecquat(Quaternion q) { @@ -151,13 +139,13 @@ gouraudvshader(VSparams *sp) ambient = mulpt3(lightc, Ka); ambient = modulapt3(ambient, m.diffuse); - Kd = fmax(0, dotvec3(sp->v->n, lightdir)); + Kd = max(0, dotvec3(sp->v->n, lightdir)); diffuse = mulpt3(lightc, Kd); diffuse = modulapt3(diffuse, m.diffuse); lookdir = normvec3(subpt3(sp->su->camera->p, pos)); lightdir = qrotate(lightdir, sp->v->n, PI); - spec = pow(fmax(0, dotvec3(lookdir, lightdir)), m.shininess); + spec = pow(max(0, dotvec3(lookdir, lightdir)), m.shininess); specular = mulpt3(lightc, spec*Ks); specular = modulapt3(specular, m.specular); @@ -263,7 +251,7 @@ phongshader(FSparams *sp) ambient = mulpt3(lightc, Ka); ambient = modulapt3(ambient, m.diffuse); - Kd = fmax(0, dotvec3(n, lightdir)); + Kd = max(0, dotvec3(n, lightdir)); diffuse = mulpt3(lightc, Kd); diffuse = modulapt3(diffuse, m.diffuse); @@ -272,7 +260,7 @@ phongshader(FSparams *sp) lookdir = normvec3(subpt3(sp->su->camera->p, pos)); lightdir = qrotate(lightdir, n, PI); - spec = pow(fmax(0, dotvec3(lookdir, lightdir)), m.shininess); + spec = pow(max(0, dotvec3(lookdir, lightdir)), m.shininess); specular = mulpt3(lightc, spec*Ks); specular = modulapt3(specular, m.specular); @@ -335,7 +323,7 @@ blinnshader(FSparams *sp) ambient = mulpt3(lightc, Ka); ambient = modulapt3(ambient, m.diffuse); - Kd = fmax(0, dotvec3(n, lightdir)); + Kd = max(0, dotvec3(n, lightdir)); diffuse = mulpt3(lightc, Kd); diffuse = modulapt3(diffuse, m.diffuse); @@ -344,7 +332,7 @@ blinnshader(FSparams *sp) lookdir = normvec3(subpt3(sp->su->camera->p, pos)); lightdir = normvec3(addpt3(lookdir, lightdir)); /* half vector */ - spec = pow(fmax(0, dotvec3(n, lightdir)), m.shininess); + spec = pow(max(0, dotvec3(n, lightdir)), m.shininess); specular = mulpt3(lightc, spec*Ks); specular = modulapt3(specular, m.specular); @@ -362,7 +350,7 @@ toonvshader(VSparams *sp) sp->v->n = model2world(sp->su->entity, sp->v->n); pos = model2world(sp->su->entity, sp->v->p); lightdir = normvec3(subpt3(light.p, pos)); - intens = fmax(0, dotvec3(sp->v->n, lightdir)); + intens = max(0, dotvec3(sp->v->n, lightdir)); addvattr(sp->v, "intensity", VANumber, &intens); if(sp->v->mtl != nil) sp->v->c = sp->v->mtl->diffuse; @@ -496,8 +484,8 @@ boxshader(FSparams *sp) p = Pt2(fabs(uv.x - 0.5), fabs(uv.y - 0.5), 1); p = subpt2(p, r); - p.x = fmax(p.x, 0); - p.y = fmax(p.y, 0); + p.x = max(p.x, 0); + p.y = max(p.y, 0); if(vec2len(p) > 0) return Vec3(0,0,0); -- cgit v1.2.3