Cleanup: move BKE_scene_unit_scale to BKE_unit_value_scale
This doesn't use any scene types, move to BKE_unit.hh
This commit is contained in:
@@ -241,12 +241,6 @@ int BKE_render_preview_pixel_size(const RenderData *r);
|
||||
|
||||
/**********************************/
|
||||
|
||||
/**
|
||||
* Apply the needed correction factor to value, based on unit_type
|
||||
* (only length-related are affected currently) and `unit->scale_length`.
|
||||
*/
|
||||
double BKE_scene_unit_scale(const UnitSettings *unit, int unit_type, double value);
|
||||
|
||||
/* Multi-view. */
|
||||
|
||||
bool BKE_scene_multiview_is_stereo3d(const RenderData *rd);
|
||||
|
||||
@@ -87,6 +87,12 @@ double BKE_unit_base_scalar(int system, int type);
|
||||
*/
|
||||
bool BKE_unit_is_valid(int system, int type);
|
||||
|
||||
/**
|
||||
* Apply the needed correction factor to value, based on unit_type
|
||||
* (only length-related are affected currently) and `unit->scale_length`.
|
||||
*/
|
||||
double BKE_unit_value_scale(const UnitSettings *unit, int unit_type, double value);
|
||||
|
||||
/**
|
||||
* Loop over scales, could add names later.
|
||||
*/
|
||||
|
||||
@@ -2885,32 +2885,6 @@ int BKE_render_preview_pixel_size(const RenderData *r)
|
||||
return r->preview_pixel_size;
|
||||
}
|
||||
|
||||
double BKE_scene_unit_scale(const UnitSettings *unit, const int unit_type, double value)
|
||||
{
|
||||
if (unit->system == USER_UNIT_NONE) {
|
||||
/* Never apply scale_length when not using a unit setting! */
|
||||
return value;
|
||||
}
|
||||
|
||||
switch (unit_type) {
|
||||
case B_UNIT_LENGTH:
|
||||
case B_UNIT_VELOCITY:
|
||||
case B_UNIT_ACCELERATION:
|
||||
return value * double(unit->scale_length);
|
||||
case B_UNIT_AREA:
|
||||
case B_UNIT_POWER:
|
||||
return value * pow(unit->scale_length, 2);
|
||||
case B_UNIT_VOLUME:
|
||||
return value * pow(unit->scale_length, 3);
|
||||
case B_UNIT_MASS:
|
||||
return value * pow(unit->scale_length, 3);
|
||||
case B_UNIT_CAMERA: /* *Do not* use scene's unit scale for camera focal lens! See #42026. */
|
||||
case B_UNIT_WAVELENGTH: /* Wavelength values are independent of the scene scale. */
|
||||
default:
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
/******************** multiview *************************/
|
||||
|
||||
int BKE_scene_multiview_num_views_get(const RenderData *rd)
|
||||
|
||||
@@ -1886,6 +1886,32 @@ size_t BKE_unit_value_as_string(char *str,
|
||||
return unit_as_string_main(str, str_maxncpy, value, prec, type, do_split, pad, units);
|
||||
}
|
||||
|
||||
double BKE_unit_value_scale(const UnitSettings *unit, const int unit_type, double value)
|
||||
{
|
||||
if (unit->system == USER_UNIT_NONE) {
|
||||
/* Never apply scale_length when not using a unit setting! */
|
||||
return value;
|
||||
}
|
||||
|
||||
switch (unit_type) {
|
||||
case B_UNIT_LENGTH:
|
||||
case B_UNIT_VELOCITY:
|
||||
case B_UNIT_ACCELERATION:
|
||||
return value * double(unit->scale_length);
|
||||
case B_UNIT_AREA:
|
||||
case B_UNIT_POWER:
|
||||
return value * pow(unit->scale_length, 2);
|
||||
case B_UNIT_VOLUME:
|
||||
return value * pow(unit->scale_length, 3);
|
||||
case B_UNIT_MASS:
|
||||
return value * pow(unit->scale_length, 3);
|
||||
case B_UNIT_CAMERA: /* *Do not* use scene's unit scale for camera focal lens! See #42026. */
|
||||
case B_UNIT_WAVELENGTH: /* Wavelength values are independent of the scene scale. */
|
||||
default:
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
BLI_INLINE bool isalpha_or_utf8(const int ch)
|
||||
{
|
||||
return (ch >= 128 || isalpha(ch));
|
||||
|
||||
@@ -2832,12 +2832,12 @@ static double ui_get_but_scale_unit(uiBut *but, double value)
|
||||
const UnitSettings *unit = but->block->unit;
|
||||
const int unit_type = UI_but_unit_type_get(but);
|
||||
|
||||
/* Time unit is a bit special, not handled by BKE_scene_unit_scale() for now. */
|
||||
/* Time unit is a bit special, not handled by #BKE_unit_value_scale() for now. */
|
||||
if (unit_type == PROP_UNIT_TIME) { /* WARNING: using evil_C :| */
|
||||
Scene *scene = CTX_data_scene(static_cast<const bContext *>(but->block->evil_C));
|
||||
return FRA2TIME(value);
|
||||
}
|
||||
return BKE_scene_unit_scale(unit, RNA_SUBTYPE_UNIT_VALUE(unit_type), value);
|
||||
return BKE_unit_value_scale(unit, RNA_SUBTYPE_UNIT_VALUE(unit_type), value);
|
||||
}
|
||||
|
||||
void ui_but_convert_to_unit_alt_name(uiBut *but, char *str, size_t str_maxncpy)
|
||||
|
||||
@@ -98,7 +98,7 @@ void outputNumInput(NumInput *n, char *str, const UnitSettings *unit_settings)
|
||||
j;
|
||||
|
||||
/* Use scale_length if needed! */
|
||||
const float fac = float(BKE_scene_unit_scale(unit_settings, n->unit_type[j], 1.0));
|
||||
const float fac = float(BKE_unit_value_scale(unit_settings, n->unit_type[j], 1.0));
|
||||
|
||||
if (n->val_flag[i] & NUM_EDITED) {
|
||||
/* Get the best precision, allows us to draw '10.0001' as '10' instead! */
|
||||
@@ -276,7 +276,7 @@ bool user_string_to_number(bContext *C,
|
||||
err_info.use_single_line_error = use_single_line_error;
|
||||
err_info.r_string = r_error;
|
||||
|
||||
double unit_scale = BKE_scene_unit_scale(unit, type, 1.0);
|
||||
const double unit_scale = BKE_unit_value_scale(unit, type, 1.0);
|
||||
if (BKE_unit_string_contains_unit(str, type)) {
|
||||
char str_unit_convert[256];
|
||||
STRNCPY(str_unit_convert, str);
|
||||
|
||||
Reference in New Issue
Block a user