Skip to content

Commit

Permalink
Small improvements in Path::flatArc()
Browse files Browse the repository at this point in the history
  • Loading branch information
ubruhin committed Feb 18, 2018
1 parent 0e658f7 commit b0f4a7c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
15 changes: 11 additions & 4 deletions libs/librepcb/common/geometry/path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,19 @@ Path Path::octagon(const Length& width, const Length& height) noexcept
return p;
}

Path Path::flatArc(const Point& p1, const Point& p2, const Angle& angle, qreal tolerance) noexcept
Path Path::flatArc(const Point& p1, const Point& p2, const Angle& angle,
const Length& maxTolerance) noexcept
{
// return straight line if radius is smaller than half of the allowed tolerance
Length radiusAbs = Toolbox::arcRadius(p1, p2, angle).abs();
if (radiusAbs <= maxTolerance.abs() / 2) {
return line(p1, p2);
}

// calculate how many lines we need to create
Length radius = Toolbox::arcRadius(p1, p2, angle).abs();
qreal y = qBound(0.0, tolerance, (qreal)radius.toNm() / 4);
qreal stepsPerRad = qMin(0.5 / qAcos(1 - y / radius.toNm()), radius.toNm() / 2.0);
qreal radiusAbsNm = static_cast<qreal>(radiusAbs.toNm());
qreal y = qBound(0.0, static_cast<qreal>(maxTolerance.toNm()), radiusAbsNm / 4);
qreal stepsPerRad = qMin(0.5 / qAcos(1 - y / radiusAbsNm), radiusAbsNm / 2);
int steps = qCeil(stepsPerRad * angle.abs().toRad());

// some other very complex calculations...
Expand Down
3 changes: 2 additions & 1 deletion libs/librepcb/common/geometry/path.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ class Path final : public SerializableObject
static Path rect(const Point& p1, const Point& p2) noexcept;
static Path centeredRect(const Length& width, const Length& height) noexcept;
static Path octagon(const Length& width, const Length& height) noexcept;
static Path flatArc(const Point& p1, const Point& p2, const Angle& angle, qreal tolerance) noexcept;
static Path flatArc(const Point& p1, const Point& p2, const Angle& angle,
const Length& maxTolerance) noexcept;
static QPainterPath toQPainterPathPx(const QList<Path>& paths) noexcept;


Expand Down

0 comments on commit b0f4a7c

Please sign in to comment.