diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-02-09 19:02:48 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-02-09 19:02:48 +0100 |
commit | c428c495b56a53ac77d9e0b356a5b0014589be76 (patch) | |
tree | 2965dd897eb2ccad3eec3c9d514db7cf610ef7ab /src | |
parent | f009ba6263e55383395ac3afb2335816846b333b (diff) |
scenery: update following .json schema change
Diffstat (limited to 'src')
-rw-r--r-- | src/anim.cpp | 18 | ||||
-rw-r--r-- | src/anim.hpp | 1 |
2 files changed, 13 insertions, 6 deletions
diff --git a/src/anim.cpp b/src/anim.cpp index f4850deb..cf2317bc 100644 --- a/src/anim.cpp +++ b/src/anim.cpp @@ -4,10 +4,10 @@ namespace floormat { -Vector2ui anim_scale::scale_to(Vector2ui image_size) const +Vector2 anim_scale::scale_to_(Vector2ui image_size) const { fm_soft_assert(image_size.product() > 0); - Vector2ui ret; + Vector2 ret; switch (type) { default: @@ -16,18 +16,24 @@ Vector2ui anim_scale::scale_to(Vector2ui image_size) const fm_throw("anim_scale is invalid"_cf); case anim_scale_type::fixed: fm_soft_assert(f.width_or_height > 0); - if (f.is_width) - ret = { f.width_or_height, (unsigned)std::round((float)f.width_or_height * (float)image_size.y()/(float)image_size.x()) }; + if (auto x = (float)image_size.x(), y = (float)image_size.y(), wh = (float)f.width_or_height; f.is_width) + ret = { wh, wh * y/x }; else - ret = { (unsigned)std::round((float)f.width_or_height * (float)image_size.x()/(float)image_size.y()), f.width_or_height }; + ret = { wh * x/y, wh }; break; case anim_scale_type::ratio: fm_soft_assert(r.f > 0 && r.f <= 1); - ret = { (unsigned)std::round(image_size.x() * r.f), (unsigned)std::round(image_size.y() * r.f) }; + ret = { image_size.x() * r.f, image_size.y() * r.f }; break; } fm_soft_assert(ret.product() > 0); return ret; } +Vector2ui anim_scale::scale_to(Vector2ui image_size) const +{ + Vector2 value = scale_to_(image_size); + return { (unsigned)std::round(value[0]), (unsigned)std::round(value[1]) }; +} + } // namespace floormat diff --git a/src/anim.hpp b/src/anim.hpp index a8fb63a3..bee8147a 100644 --- a/src/anim.hpp +++ b/src/anim.hpp @@ -42,6 +42,7 @@ struct anim_scale final }; anim_scale_type type = anim_scale_type::invalid; Vector2ui scale_to(Vector2ui image_size) const; + Vector2 scale_to_(Vector2ui image_size) const; }; struct anim_def final |