aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2025-02-28 18:41:07 -0500
committerSam Anthony <sam@samanthony.xyz>2025-02-28 18:41:07 -0500
commita7c99e7bed015db546969d5f9a87fc6ffd1f2ea8 (patch)
tree82b11719cd67149d46e78e243d5b04634ae560d5
parent5af0508c969105060871a8be0c9885c8c331fa98 (diff)
downloadvolute-a7c99e7bed015db546969d5f9a87fc6ffd1f2ea8.zip
volume flow rate conversion functions
-rw-r--r--Makefile2
-rw-r--r--test_volume_flow_rate.c15
-rw-r--r--unit.c37
3 files changed, 47 insertions, 7 deletions
diff --git a/Makefile b/Makefile
index 8dd85cc..8f0bbe1 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@ SRC = main.c microui.c renderer.c widget.c ui.c unit.c engine.c
OBJ = ${SRC:.c=.o}
HDR = microui.h renderer.h widget.h ui.h unit.h engine.h
-TEST_SRC = test.c test_angular_speed.c test_pressure.c test_volume.c unit.c
+TEST_SRC = test.c test_angular_speed.c test_pressure.c test_volume.c test_volume_flow_rate.c unit.c
TEST_OBJ = ${TEST_SRC:.c=.o}
volute: ${OBJ}
diff --git a/test_volume_flow_rate.c b/test_volume_flow_rate.c
index 148d58f..4c4d3c7 100644
--- a/test_volume_flow_rate.c
+++ b/test_volume_flow_rate.c
@@ -1,32 +1,35 @@
+#include <assert.h>
+#include <stdio.h>
+
#include "test.h"
#include "unit.h"
void
test_cubic_metre_per_sec(void) {
- assert(0);
+ test(cubic_metre_per_sec(123.456), 123.456);
}
void
test_cubic_metre_per_min(void) {
- assert(0);
+ test(cubic_metre_per_min(123.456), 2.0576);
}
void
test_cubic_foot_per_min(void) {
- assert(0);
+ test(cubic_foot_per_min(123.456), 0.0582647436);
}
void
test_as_cubic_metre_per_sec(void) {
- assert(0);
+ test(as_cubic_metre_per_sec(cubic_metre_per_sec(123.456)), 123.456);
}
void
test_as_cubic_metre_per_min(void) {
- assert(0);
+ test(as_cubic_metre_per_min(cubic_metre_per_min(123.456)), 123.456);
}
void
test_as_cubic_foot_per_min(void) {
- assert(0);
+ test(as_cubic_foot_per_min(cubic_foot_per_min(123.456)), 123.456);
}
diff --git a/unit.c b/unit.c
index 316a39a..9e03abf 100644
--- a/unit.c
+++ b/unit.c
@@ -12,6 +12,12 @@
/* Metres per inch. */
#define M_PER_IN 0.0254
+/* Metres per foot. */
+#define M_PER_FT 0.3048
+
+/* Seconds per minute. */
+#define SEC_PER_MIN 60.0
+
AngularSpeed
rad_per_sec(double x) {
@@ -133,3 +139,34 @@ double
as_cubic_inch(double x) {
return x / 1.6387064e-5;
}
+
+
+VolumeFlowRate
+cubic_metre_per_sec(double x) {
+ return x;
+}
+
+VolumeFlowRate
+cubic_metre_per_min(double x) {
+ return x / SEC_PER_MIN;
+}
+
+VolumeFlowRate
+cubic_foot_per_min(double x) {
+ return x * pow(M_PER_FT, 3) / SEC_PER_MIN;
+}
+
+double
+as_cubic_metre_per_sec(VolumeFlowRate x) {
+ return x;
+}
+
+double
+as_cubic_metre_per_min(VolumeFlowRate x) {
+ return x * SEC_PER_MIN;
+}
+
+double
+as_cubic_foot_per_min(VolumeFlowRate x) {
+ return x * SEC_PER_MIN / pow(M_PER_FT, 3);
+}