Fix path stroking
This commit is contained in:
parent
da743e0e16
commit
9b43c90802
@ -60,7 +60,7 @@ double get_angle(Point start, Point end)
|
|||||||
|
|
||||||
if (vec.y < 0)
|
if (vec.y < 0)
|
||||||
{
|
{
|
||||||
angle += 180.0;
|
angle = 360 - angle;
|
||||||
}
|
}
|
||||||
|
|
||||||
return angle;
|
return angle;
|
||||||
@ -89,9 +89,28 @@ pair<Point, Point> perform_stroke(double stroke_size, double stroke_angle, Point
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pair<Point, Point> perform_stroke(double stroke_size, double prev_angle, double curr_angle, Point point)
|
||||||
|
{
|
||||||
|
pair<Point, Point> result;
|
||||||
|
Point add;
|
||||||
|
double stroke_angle;
|
||||||
|
double extra_angle;
|
||||||
|
|
||||||
|
extra_angle = (curr_angle - prev_angle) / 2 + 90.0;
|
||||||
|
stroke_angle = extra_angle + prev_angle;
|
||||||
|
|
||||||
|
add.x = cos(radians(stroke_angle)) * stroke_size / 2 / sin(radians(extra_angle));
|
||||||
|
add.y = sin(radians(stroke_angle)) * stroke_size / 2 / sin(radians(extra_angle));
|
||||||
|
|
||||||
|
result.first = point + add;
|
||||||
|
result.second = point - add;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void usage(const string& name)
|
void usage(const string& name)
|
||||||
{
|
{
|
||||||
cout << "Usage: " << name << "<stroke size> <x1> <y1> <x2> <y2> [<xN> <yN> ...]" << endl;
|
cout << "Usage: " << name << " <stroke size> <x1> <y1> <x2> <y2> [<xN> <yN> ...]" << endl;
|
||||||
cout << "\tstroke size - how big the stroke should be" << endl;
|
cout << "\tstroke size - how big the stroke should be" << endl;
|
||||||
cout << "\tx1 - x coordinate of first point" << endl;
|
cout << "\tx1 - x coordinate of first point" << endl;
|
||||||
cout << "\ty1 - y coordinate of first point" << endl;
|
cout << "\ty1 - y coordinate of first point" << endl;
|
||||||
@ -117,7 +136,7 @@ void get_polygon(double stroke_size, const vector<Point>& points)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
tmp = perform_stroke(stroke_size, get_stroke_angle(prev_angle, curr_angle), points[i - 1]);
|
tmp = perform_stroke(stroke_size, prev_angle, curr_angle, points[i - 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
forward.push_back(tmp.first);
|
forward.push_back(tmp.first);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user