Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Make path extension a bit safer#30208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -3,12 +3,12 @@ | ||
#ifndef MPL_PATH_H | ||
#define MPL_PATH_H | ||
#include <algorithm> | ||
#include <array> | ||
#include <cmath> | ||
#include <limits> | ||
#include <string> | ||
#include <vector> | ||
#include "agg_conv_contour.h" | ||
#include "agg_conv_curve.h" | ||
@@ -524,12 +524,11 @@ struct bisectx | ||
{ | ||
} | ||
inlineauto bisect(double sx, double sy, double px, double py) const | ||
{ | ||
double dx = px - sx; | ||
double dy = py - sy; | ||
return std::tuple(m_x, sy + dy * ((m_x - sx) / dx)); | ||
} | ||
}; | ||
@@ -565,12 +564,11 @@ struct bisecty | ||
{ | ||
} | ||
inlineauto bisect(double sx, double sy, double px, double py) const | ||
{ | ||
double dx = px - sx; | ||
double dy = py - sy; | ||
return std::tuple(sx + dx * ((m_y - sy) / dy), m_y); | ||
} | ||
}; | ||
@@ -615,8 +613,7 @@ inline void clip_to_rect_one_step(const Polygon &polygon, Polygon &result, const | ||
pinside = filter.is_inside(px, py); | ||
if (sinside ^ pinside) { | ||
auto [bx, by] = filter.bisect(sx, sy, px, py); | ||
result.emplace_back(bx, by); | ||
} | ||
@@ -1051,15 +1048,14 @@ void cleanup_path(PathIterator &path, | ||
void quad2cubic(double x0, double y0, | ||
double x1, double y1, | ||
double x2, double y2, | ||
std::array<double, 3> &outx,std::array<double, 3> &outy) | ||
{ | ||
std::get<0>(outx) = x0 + 2./3. * (x1 - x0); | ||
std::get<0>(outy) = y0 + 2./3. * (y1 - y0); | ||
std::get<1>(outx) = std::get<0>(outx) + 1./3. * (x2 - x0); | ||
std::get<1>(outy) = std::get<0>(outy) + 1./3. * (y2 - y0); | ||
std::get<2>(outx) = x2; | ||
std::get<2>(outy) = y2; | ||
} | ||
@@ -1104,27 +1100,27 @@ void __add_number(double val, char format_code, int precision, | ||
template <class PathIterator> | ||
bool __convert_to_string(PathIterator &path, | ||
int precision, | ||
const std::array<std::string, 5> &codes, | ||
bool postfix, | ||
std::string& buffer) | ||
{ | ||
const char format_code = 'f'; | ||
std::array<double, 3> x; | ||
std::array<double, 3> y; | ||
double last_x = 0.0; | ||
double last_y = 0.0; | ||
unsigned code; | ||
while ((code = path.vertex(&std::get<0>(x), &std::get<0>(y))) != agg::path_cmd_stop) { | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I think you can still do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Ugh, indeed, that's a bit annoying... | ||
if (code == CLOSEPOLY) { | ||
buffer +=std::get<4>(codes); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. ditto | ||
} else if (code < 5) { | ||
size_t size = NUM_VERTICES[code]; | ||
for (size_t i = 1; i < size; ++i) { | ||
unsigned subcode = path.vertex(&x.at(i), &y.at(i)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I don't think the compiler can safely elide the bounds check here, because it'll have trouble proving that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Well, | ||
if (subcode != code) { | ||
return false; | ||
} | ||
@@ -1133,29 +1129,29 @@ bool __convert_to_string(PathIterator &path, | ||
/* For formats that don't support quad curves, convert to | ||
cubic curves */ | ||
if (code == CURVE3 && codes[code - 1][0] == '\0') { | ||
quad2cubic(last_x, last_y, x.at(0), y.at(0), x.at(1), y.at(1), x, y); | ||
code++; | ||
size = 3; | ||
} | ||
if (!postfix) { | ||
buffer += codes.at(code - 1); | ||
buffer += ' '; | ||
} | ||
for (size_t i = 0; i < size; ++i) { | ||
__add_number(x.at(i), format_code, precision, buffer); | ||
buffer += ' '; | ||
__add_number(y.at(i), format_code, precision, buffer); | ||
buffer += ' '; | ||
} | ||
if (postfix) { | ||
buffer += codes.at(code - 1); | ||
} | ||
last_x = x.at(size - 1); | ||
last_y = y.at(size - 1); | ||
} else { | ||
// Unknown code value | ||
return false; | ||
@@ -1174,7 +1170,7 @@ bool convert_to_string(PathIterator &path, | ||
bool simplify, | ||
SketchParams sketch_params, | ||
int precision, | ||
const std::array<std::string, 5> &codes, | ||
bool postfix, | ||
std::string& buffer) | ||
{ | ||
@@ -1211,7 +1207,6 @@ bool convert_to_string(PathIterator &path, | ||
sketch_t sketch(curve, sketch_params.scale, sketch_params.length, sketch_params.randomness); | ||
return __convert_to_string(sketch, precision, codes, postfix, buffer); | ||
} | ||
} | ||
template<class T> | ||
Uh oh!
There was an error while loading.Please reload this page.