Save vector clips with two decimal places

Co-authored-by: arch1t3cht <arch1t3cht@gmail.com>
This commit is contained in:
Asada shinon 2022-07-29 21:50:10 +02:00 committed by arch1t3cht
parent 58a6cf4793
commit d0efa0494a
5 changed files with 15 additions and 14 deletions

View File

@ -71,7 +71,7 @@ std::string Spline::EncodeToAss() const {
result += "m "; result += "m ";
last = 'm'; last = 'm';
} }
result += ToScript(pt.p1).DStr(' '); result += ToScript(pt.p1).Str(' ');
break; break;
case SplineCurve::LINE: case SplineCurve::LINE:
@ -79,7 +79,7 @@ std::string Spline::EncodeToAss() const {
result += "l "; result += "l ";
last = 'l'; last = 'l';
} }
result += ToScript(pt.p2).DStr(' '); result += ToScript(pt.p2).Str(' ');
break; break;
case SplineCurve::BICUBIC: case SplineCurve::BICUBIC:
@ -87,9 +87,9 @@ std::string Spline::EncodeToAss() const {
result += "b "; result += "b ";
last = 'b'; last = 'b';
} }
result += ToScript(pt.p2).DStr(' ') + " "; result += ToScript(pt.p2).Str(' ') + " ";
result += ToScript(pt.p3).DStr(' ') + " "; result += ToScript(pt.p3).Str(' ') + " ";
result += ToScript(pt.p4).DStr(' '); result += ToScript(pt.p4).Str(' ');
break; break;
default: break; default: break;

View File

@ -76,8 +76,9 @@ wxString PrettySize(int bytes) {
return agi::wxformat(fmt, size) + " " + suffix[i]; return agi::wxformat(fmt, size) + " " + suffix[i];
} }
std::string float_to_string(double val) { std::string float_to_string(double val, int precision) {
std::string s = agi::format("%.3f", val); std::string fmt = "%." + std::to_string(precision) + "f";
std::string s = agi::format(fmt, val);
size_t pos = s.find_last_not_of("0"); size_t pos = s.find_last_not_of("0");
if (pos != s.find(".")) ++pos; if (pos != s.find(".")) ++pos;
s.erase(begin(s) + pos, end(s)); s.erase(begin(s) + pos, end(s));

View File

@ -44,7 +44,7 @@ class wxWindow;
wxString PrettySize(int bytes); wxString PrettySize(int bytes);
std::string float_to_string(double val); std::string float_to_string(double val, int precision = 3);
/// @brief Get the smallest power of two that is greater or equal to x /// @brief Get the smallest power of two that is greater or equal to x
/// ///

View File

@ -88,5 +88,5 @@ std::string Vector2D::DStr(char sep) const {
} }
std::string Vector2D::Str(char sep) const { std::string Vector2D::Str(char sep) const {
return float_to_string(x) + sep + float_to_string(y); return float_to_string(x,2) + sep + float_to_string(y,2);
} }

View File

@ -504,11 +504,11 @@ std::string VisualToolBase::GetLineVectorClip(AssDialogue *diag, int &scale, boo
tag = find_tag(blocks, "\\clip"); tag = find_tag(blocks, "\\clip");
if (tag && tag->size() == 4) { if (tag && tag->size() == 4) {
return agi::format("m %d %d l %d %d %d %d %d %d" return agi::format("m %.2f %.2f l %.2f %.2f %.2f %.2f %.2f %.2f"
, (*tag)[0].Get<int>(), (*tag)[1].Get<int>() , (*tag)[0].Get<double>(), (*tag)[1].Get<double>()
, (*tag)[2].Get<int>(), (*tag)[1].Get<int>() , (*tag)[2].Get<double>(), (*tag)[1].Get<double>()
, (*tag)[2].Get<int>(), (*tag)[3].Get<int>() , (*tag)[2].Get<double>(), (*tag)[3].Get<double>()
, (*tag)[0].Get<int>(), (*tag)[3].Get<int>()); , (*tag)[0].Get<double>(), (*tag)[3].Get<double>());
} }
if (tag) { if (tag) {
scale = std::max((*tag)[0].Get(scale), 1); scale = std::max((*tag)[0].Get(scale), 1);