aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/gas.c
blob: c59db2c2104f22751733e9614df01c5310625fd6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* SPDX-License-Identifier: MIT-0 */

#include <assert.h>

#include "gas.h"

double PO2_MAX = PO2_MAX_DEFAULT;

gas_t gas_new(unsigned char o2, unsigned char he, double mod)
{
    assert(o2 + he <= 100);

    if (mod == MOD_AUTO)
        mod = PO2_MAX / (o2 / 100.0);

    return (gas_t){.o2 = o2, .he = he, .n2 = 100 - o2 - he, .mod = mod};
}

int gas_equal(const gas_t *g1, const gas_t *g2)
{
    return g1->o2 == g2->o2 && g1->he == g2->he && g1->mod == g2->mod;
}

unsigned char gas_o2(const gas_t *gas)
{
    return gas->o2;
}

unsigned char gas_he(const gas_t *gas)
{
    return gas->he;
}

unsigned char gas_n2(const gas_t *gas)
{
    return gas->n2;
}

double gas_mod(const gas_t *gas)
{
    return gas->mod;
}