Skip to content

Commit 0fd6b99

Browse files
Save vector clips with two decimal places
Co-authored-by: arch1t3cht <arch1t3cht@gmail.com>
1 parent a12c437 commit 0fd6b99

File tree

7 files changed

+18
-17
lines changed

7 files changed

+18
-17
lines changed

src/spline.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,25 +71,25 @@ std::string Spline::EncodeToAss() const {
7171
result += "m ";
7272
last = 'm';
7373
}
74-
result += ToScript(pt.p1).DStr(' ');
74+
result += ToScript(pt.p1).Str(' ');
7575
break;
7676

7777
case SplineCurve::LINE:
7878
if (last != 'l') {
7979
result += "l ";
8080
last = 'l';
8181
}
82-
result += ToScript(pt.p2).DStr(' ');
82+
result += ToScript(pt.p2).Str(' ');
8383
break;
8484

8585
case SplineCurve::BICUBIC:
8686
if (last != 'b') {
8787
result += "b ";
8888
last = 'b';
8989
}
90-
result += ToScript(pt.p2).DStr(' ') + " ";
91-
result += ToScript(pt.p3).DStr(' ') + " ";
92-
result += ToScript(pt.p4).DStr(' ');
90+
result += ToScript(pt.p2).Str(' ') + " ";
91+
result += ToScript(pt.p3).Str(' ') + " ";
92+
result += ToScript(pt.p4).Str(' ');
9393
break;
9494

9595
default: break;

src/utils.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ wxString PrettySize(int bytes) {
7575
return agi::wxformat(fmt, size) + " " + suffix[i];
7676
}
7777

78-
std::string float_to_string(double val) {
79-
std::string s = agi::format("%.3f", val);
78+
std::string float_to_string(double val, int precision) {
79+
std::string fmt = "%." + std::to_string(precision) + "f";
80+
std::string s = agi::format(fmt, val);
8081
size_t pos = s.find_last_not_of("0");
8182
if (pos != s.find(".")) ++pos;
8283
s.erase(begin(s) + pos, end(s));

src/utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class wxWindow;
4646

4747
wxString PrettySize(int bytes);
4848

49-
std::string float_to_string(double val);
49+
std::string float_to_string(double val, int precision = 3);
5050

5151
/// @brief Get the smallest power of two that is greater or equal to x
5252
///

src/vector2d.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,6 @@ std::string Vector2D::DStr(char sep) const {
8787
return agi::format("%d%c%d", (int)x, sep, (int)y);
8888
}
8989

90-
std::string Vector2D::Str(char sep) const {
91-
return float_to_string(x) + sep + float_to_string(y);
90+
std::string Vector2D::Str(char sep, int precision) const {
91+
return float_to_string(x, precision) + sep + float_to_string(y, precision);
9292
}

src/vector2d.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class Vector2D {
7070
float Angle() const { return atan2(y, x); }
7171

7272
/// Get as string with given separator
73-
std::string Str(char sep = ',') const;
73+
std::string Str(char sep = ',', int precision = 2) const;
7474
/// Get as string surrounded by parentheses with given separator
7575
std::string PStr(char sep = ',') const;
7676
/// Get as string with given separator with values rounded to ints

src/visual_tool.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -501,11 +501,11 @@ std::string VisualToolBase::GetLineVectorClip(AssDialogue *diag, int &scale, boo
501501
tag = find_tag(blocks, "\\clip");
502502

503503
if (tag && tag->size() == 4) {
504-
return agi::format("m %d %d l %d %d %d %d %d %d"
505-
, (*tag)[0].Get<int>(), (*tag)[1].Get<int>()
506-
, (*tag)[2].Get<int>(), (*tag)[1].Get<int>()
507-
, (*tag)[2].Get<int>(), (*tag)[3].Get<int>()
508-
, (*tag)[0].Get<int>(), (*tag)[3].Get<int>());
504+
return agi::format("m %.2f %.2f l %.2f %.2f %.2f %.2f %.2f %.2f"
505+
, (*tag)[0].Get<double>(), (*tag)[1].Get<double>()
506+
, (*tag)[2].Get<double>(), (*tag)[1].Get<double>()
507+
, (*tag)[2].Get<double>(), (*tag)[3].Get<double>()
508+
, (*tag)[0].Get<double>(), (*tag)[3].Get<double>());
509509
}
510510
if (tag) {
511511
scale = std::max((*tag)[0].Get(scale), 1);

src/visual_tool_cross.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,5 @@ void VisualToolCross::Draw() {
100100
}
101101

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

0 commit comments

Comments
 (0)