blob: f4850deb7aac788e1bff0df7b596f69e15b1b984 (
plain)
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
|
#include "anim.hpp"
#include "compat/exception.hpp"
#include <cmath>
namespace floormat {
Vector2ui anim_scale::scale_to(Vector2ui image_size) const
{
fm_soft_assert(image_size.product() > 0);
Vector2ui ret;
switch (type)
{
default:
fm_throw("invalid anim_scale_type '{}'"_cf, (unsigned)type);
case anim_scale_type::invalid:
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()) };
else
ret = { (unsigned)std::round((float)f.width_or_height * (float)image_size.x()/(float)image_size.y()), f.width_or_height };
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) };
break;
}
fm_soft_assert(ret.product() > 0);
return ret;
}
} // namespace floormat
|