Changeset View
Standalone View
source/blender/blenkernel/intern/unit.c
| Context not available. | |||||
| #define UN_SC_LB 0.45359237f | #define UN_SC_LB 0.45359237f | ||||
| #define UN_SC_OZ 0.028349523125f | #define UN_SC_OZ 0.028349523125f | ||||
| #define UN_SC_CEL 1.0f | |||||
| #define UN_SC_FAH 0.5555f | |||||
| /* define a single unit */ | /* define a single unit */ | ||||
| typedef struct bUnitDef { | typedef struct bUnitDef { | ||||
JacquesLucke: You can add a couple more 5s here. | |||||
| const char *name; | const char *name; | ||||
Done Inline ActionsThanks for those typo fixes. I'll commit those separately. JacquesLucke: Thanks for those typo fixes. I'll commit those separately. | |||||
| Context not available. | |||||
| {"watt", "watts", "W", NULL, "Watts", NULL, 1.0f, 0.0, B_UNIT_DEF_NONE}, /* base unit */ | {"watt", "watts", "W", NULL, "Watts", NULL, 1.0f, 0.0, B_UNIT_DEF_NONE}, /* base unit */ | ||||
| {"milliwatt", "milliwatts", "mW", NULL, "Milliwatts", NULL, 1e-3f, 0.0, B_UNIT_DEF_CASE_SENSITIVE}, | {"milliwatt", "milliwatts", "mW", NULL, "Milliwatts", NULL, 1e-3f, 0.0, B_UNIT_DEF_CASE_SENSITIVE}, | ||||
| {"microwatt", "microwatts", "µW", "uW", "Microwatts", NULL, 1e-6f, 0.0, B_UNIT_DEF_NONE}, | {"microwatt", "microwatts", "µW", "uW", "Microwatts", NULL, 1e-6f, 0.0, B_UNIT_DEF_NONE}, | ||||
| {"nanowatt", "nanowatts", "nW", NULL, "Nannowatts", NULL, 1e-9f, 0.0, B_UNIT_DEF_NONE}, | {"nanowatt", "nanowatts", "nW", NULL, "Nanowatts", NULL, 1e-9f, 0.0, B_UNIT_DEF_NONE}, | ||||
| NULL_UNIT, | NULL_UNIT, | ||||
| }; | }; | ||||
| static struct bUnitCollection buPowerCollection = {buPowerDef, 3, 0, UNIT_COLLECTION_LENGTH(buPowerDef)}; | static struct bUnitCollection buPowerCollection = {buPowerDef, 3, 0, UNIT_COLLECTION_LENGTH(buPowerDef)}; | ||||
Done Inline ActionsI wonder if we should use oC or just C. The latter is more comfortable to type. JacquesLucke: I wonder if we should use `oC` or just `C`. The latter is more comfortable to type. | |||||
| /* Temperature */ | |||||
| static struct bUnitDef buMetricTempDef[] = { | |||||
| {"celsius", "celsius", "°C", "C", "Celsius", NULL, UN_SC_CEL, 0.0, B_UNIT_DEF_NONE}, /* base unit */ | |||||
| NULL_UNIT, | |||||
| }; | |||||
| static struct bUnitCollection buMetricTempCollection = {buMetricTempDef, 0, 0, UNIT_COLLECTION_LENGTH(buMetricTempDef)}; | |||||
Done Inline ActionsUnfortunately, the conversion is not that simple. Currently switching between the unit systems changes the absolute value of the temperature, i.e. it thinks 5C = 5F. A bit more work has to be done to get this conversion working, because it is different from all the other conversions we have so far. Also there is a missing white space. JacquesLucke: Unfortunately, the conversion is not that simple. Currently switching between the unit systems… | |||||
| static struct bUnitDef buImperialTempDef[] = { | |||||
| {"fahrenheit", "fahrenheit", "°F", "F", "Fahrenheit", NULL, UN_SC_FAH, 32.0, B_UNIT_DEF_NONE}, /* base unit */ | |||||
| NULL_UNIT, | |||||
| }; | |||||
| static struct bUnitCollection buImperialTempCollection = {buImperialTempDef, 0, 0, UNIT_COLLECTION_LENGTH(buImperialTempDef)}; | |||||
| #define UNIT_SYSTEM_TOT (((sizeof(bUnitSystems) / B_UNIT_TYPE_TOT) / sizeof(void *)) - 1) | #define UNIT_SYSTEM_TOT (((sizeof(bUnitSystems) / B_UNIT_TYPE_TOT) / sizeof(void *)) - 1) | ||||
Done Inline ActionsIt's probably a good time to split this into multiple lines now, one line per unit collection. JacquesLucke: It's probably a good time to split this into multiple lines now, one line per unit collection. | |||||
| static const struct bUnitCollection *bUnitSystems[][B_UNIT_TYPE_TOT] = { | static const struct bUnitCollection *bUnitSystems[][B_UNIT_TYPE_TOT] = { | ||||
| {NULL, NULL, NULL, NULL, NULL, &buNaturalRotCollection, &buNaturalTimeCollection, NULL, NULL, NULL, NULL}, | {NULL, NULL, NULL, NULL, NULL, &buNaturalRotCollection, &buNaturalTimeCollection, NULL, NULL, NULL, NULL, NULL}, | ||||
| {NULL, &buMetricLenCollection, &buMetricAreaCollection, &buMetricVolCollection, &buMetricMassCollection, &buNaturalRotCollection, &buNaturalTimeCollection, &buMetricVelCollection, &buMetricAclCollection, &buCameraLenCollection, &buPowerCollection}, /* metric */ | {NULL, | ||||
| {NULL, &buImperialLenCollection, &buImperialAreaCollection, &buImperialVolCollection, &buImperialMassCollection, &buNaturalRotCollection, &buNaturalTimeCollection, &buImperialVelCollection, &buImperialAclCollection, &buCameraLenCollection, &buPowerCollection}, /* imperial */ | &buMetricLenCollection, | ||||
| {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, | &buMetricAreaCollection, | ||||
| &buMetricVolCollection, | |||||
| &buMetricMassCollection, | |||||
| &buNaturalRotCollection, | |||||
| &buNaturalTimeCollection, | |||||
Done Inline ActionsI think Kelvin should also be the base unit in imperial? Something like color temperature you would still want to see as Kelvin even if you use imperial length units. brecht: I think Kelvin should also be the base unit in imperial? Something like color temperature you… | |||||
Done Inline ActionsI was thinking about that too, I'll add that. HooglyBoogly: I was thinking about that too, I'll add that. | |||||
| &buMetricVelCollection, | |||||
| &buMetricAclCollection, | |||||
| &buCameraLenCollection, | |||||
| &buPowerCollection, | |||||
| &buMetricTempCollection}, /* metric */ | |||||
| {NULL, | |||||
| &buImperialLenCollection, | |||||
| &buImperialAreaCollection, | |||||
| &buImperialVolCollection, | |||||
| &buImperialMassCollection, | |||||
| &buNaturalRotCollection, | |||||
| &buNaturalTimeCollection, | |||||
| &buImperialVelCollection, | |||||
| &buImperialAclCollection, | |||||
| &buCameraLenCollection, | |||||
| &buPowerCollection, | |||||
| &buImperialTempCollection}, /* imperial */ | |||||
| {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, | |||||
| }; | }; | ||||
| Context not available. | |||||
| unit = unit_best_fit(value, usys, NULL, 1); | unit = unit_best_fit(value, usys, NULL, 1); | ||||
| } | } | ||||
| value_conv = value / unit->scalar; | value_conv = (value / unit->scalar) + unit->bias; | ||||
| /* Adjust precision to expected number of significant digits. | /* Adjust precision to expected number of significant digits. | ||||
| * Note that here, we shall not have to worry about very big/small numbers, units are expected to replace | * Note that here, we shall not have to worry about very big/small numbers, units are expected to replace | ||||
| Context not available. | |||||
Not Done Inline ActionsBased on the name, I'd expect this function to compare chars to digits, but that does not seem to be what it is doing. JacquesLucke: Based on the name, I'd expect this function to compare chars to digits, but that does not seem… | |||||
Done Inline ActionsI used "value" instead for both the helper functions. Hopefully that's more clear. HooglyBoogly: I used "value" instead for both the helper functions. Hopefully that's more clear. | |||||
Done Inline Actionstypo JacquesLucke: typo | |||||
Done Inline Actionstypo JacquesLucke: typo | |||||
You can add a couple more 5s here.