Skip to content

Commit

Permalink
Save vector clips with two decimal places
Browse files Browse the repository at this point in the history
Co-authored-by: arch1t3cht <[email protected]>
  • Loading branch information
Ristellise and arch1t3cht committed Jan 11, 2025
1 parent a12c437 commit 0fd6b99
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 17 deletions.
10 changes: 5 additions & 5 deletions src/spline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,25 @@ std::string Spline::EncodeToAss() const {
result += "m ";
last = 'm';
}
result += ToScript(pt.p1).DStr(' ');
result += ToScript(pt.p1).Str(' ');
break;

case SplineCurve::LINE:
if (last != 'l') {
result += "l ";
last = 'l';
}
result += ToScript(pt.p2).DStr(' ');
result += ToScript(pt.p2).Str(' ');
break;

case SplineCurve::BICUBIC:
if (last != 'b') {
result += "b ";
last = 'b';
}
result += ToScript(pt.p2).DStr(' ') + " ";
result += ToScript(pt.p3).DStr(' ') + " ";
result += ToScript(pt.p4).DStr(' ');
result += ToScript(pt.p2).Str(' ') + " ";
result += ToScript(pt.p3).Str(' ') + " ";
result += ToScript(pt.p4).Str(' ');
break;

default: break;
Expand Down
5 changes: 3 additions & 2 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ wxString PrettySize(int bytes) {
return agi::wxformat(fmt, size) + " " + suffix[i];
}

std::string float_to_string(double val) {
std::string s = agi::format("%.3f", val);
std::string float_to_string(double val, int precision) {
std::string fmt = "%." + std::to_string(precision) + "f";
std::string s = agi::format(fmt, val);
size_t pos = s.find_last_not_of("0");
if (pos != s.find(".")) ++pos;
s.erase(begin(s) + pos, end(s));
Expand Down
2 changes: 1 addition & 1 deletion src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class wxWindow;

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
///
Expand Down
4 changes: 2 additions & 2 deletions src/vector2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@ std::string Vector2D::DStr(char sep) const {
return agi::format("%d%c%d", (int)x, sep, (int)y);
}

std::string Vector2D::Str(char sep) const {
return float_to_string(x) + sep + float_to_string(y);
std::string Vector2D::Str(char sep, int precision) const {
return float_to_string(x, precision) + sep + float_to_string(y, precision);
}
2 changes: 1 addition & 1 deletion src/vector2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Vector2D {
float Angle() const { return atan2(y, x); }

/// Get as string with given separator
std::string Str(char sep = ',') const;
std::string Str(char sep = ',', int precision = 2) const;
/// Get as string surrounded by parentheses with given separator
std::string PStr(char sep = ',') const;
/// Get as string with given separator with values rounded to ints
Expand Down
10 changes: 5 additions & 5 deletions src/visual_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,11 +501,11 @@ std::string VisualToolBase::GetLineVectorClip(AssDialogue *diag, int &scale, boo
tag = find_tag(blocks, "\\clip");

if (tag && tag->size() == 4) {
return agi::format("m %d %d l %d %d %d %d %d %d"
, (*tag)[0].Get<int>(), (*tag)[1].Get<int>()
, (*tag)[2].Get<int>(), (*tag)[1].Get<int>()
, (*tag)[2].Get<int>(), (*tag)[3].Get<int>()
, (*tag)[0].Get<int>(), (*tag)[3].Get<int>());
return agi::format("m %.2f %.2f l %.2f %.2f %.2f %.2f %.2f %.2f"
, (*tag)[0].Get<double>(), (*tag)[1].Get<double>()
, (*tag)[2].Get<double>(), (*tag)[1].Get<double>()
, (*tag)[2].Get<double>(), (*tag)[3].Get<double>()
, (*tag)[0].Get<double>(), (*tag)[3].Get<double>());
}
if (tag) {
scale = std::max((*tag)[0].Get(scale), 1);
Expand Down
2 changes: 1 addition & 1 deletion src/visual_tool_cross.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,5 @@ void VisualToolCross::Draw() {
}

std::string VisualToolCross::Text(Vector2D v) {
return video_res.X() > script_res.X() ? v.Str() : v.DStr();
return video_res.X() > script_res.X() ? v.Str(',', 3) : v.DStr();
}

0 comments on commit 0fd6b99

Please sign in to comment.