Initial circuits plugin work.
This commit is contained in:
parent
b5f21900eb
commit
f8a2ce3c59
50 changed files with 1451 additions and 97 deletions
|
@ -16,7 +16,11 @@ list(APPEND HEADERS
|
|||
path/Path.h
|
||||
path/PathPostScriptConverter.h
|
||||
path/PathElement.h
|
||||
path/Arc.h
|
||||
path/QuadraticBezierCurve.h
|
||||
path/CubicBezierCurve.h
|
||||
points/Point.h
|
||||
points/PointParser.h
|
||||
points/PointCollection.h
|
||||
points/DiscretePoint.h
|
||||
primitives/Circle.h
|
||||
|
@ -37,7 +41,11 @@ list(APPEND SOURCES
|
|||
path/Path.cpp
|
||||
path/PathPostScriptConverter.cpp
|
||||
path/PathElement.cpp
|
||||
path/Arc.cpp
|
||||
path/QuadraticBezierCurve.cpp
|
||||
path/CubicBezierCurve.cpp
|
||||
points/Point.cpp
|
||||
points/PointParser.cpp
|
||||
points/PointCollection.cpp
|
||||
points/DiscretePoint.cpp
|
||||
primitives/Circle.cpp
|
||||
|
|
74
src/base/geometry/path/Arc.cpp
Normal file
74
src/base/geometry/path/Arc.cpp
Normal file
|
@ -0,0 +1,74 @@
|
|||
#include "Arc.h"
|
||||
|
||||
#include "PointParser.h"
|
||||
#include <sstream>
|
||||
|
||||
Arc::Arc(const Point& startPoint, const Point& endPoint, double rX, double rY, double rotation, bool largeArc, bool sweep)
|
||||
: mStartPoint(startPoint),
|
||||
mEndPoint(endPoint),
|
||||
mRx(rX),
|
||||
mRy(rY),
|
||||
mRotation(rotation),
|
||||
mLargeArc(largeArc),
|
||||
mSweep(sweep)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Point Arc::getFirstPoint() const
|
||||
{
|
||||
return mStartPoint;
|
||||
}
|
||||
|
||||
Point Arc::getEndPoint() const
|
||||
{
|
||||
return mEndPoint;
|
||||
}
|
||||
|
||||
std::string Arc::toPostScriptString(std::size_t precision) const
|
||||
{
|
||||
const auto large = mLargeArc ? "1" : "0";
|
||||
const auto sweep = mSweep ? "1" : "0";
|
||||
std::stringstream sstr;
|
||||
if (precision > 0)
|
||||
{
|
||||
sstr.precision(precision);
|
||||
}
|
||||
sstr << (mPostscriptPositioning == PostscriptPositioning::RELATIVE_TO) ? "a" : "A";
|
||||
sstr << mRx << " " << mRy << " " << mRotation << " " << large << " " << sweep << " ";
|
||||
|
||||
if (mPostscriptPositioning == PostscriptPositioning::RELATIVE_TO)
|
||||
{
|
||||
sstr << PointParser::toStringRelative(mEndPoint, mStartPoint, 2, " ", precision);
|
||||
}
|
||||
else
|
||||
{
|
||||
sstr << PointParser::toString(mEndPoint, 2, " ", precision);
|
||||
}
|
||||
return sstr.str();
|
||||
}
|
||||
|
||||
Bounds Arc::getBounds() const
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
const Point& Arc::getLocation() const
|
||||
{
|
||||
return mStartPoint;
|
||||
}
|
||||
|
||||
void Arc::sample(SparseGrid<bool>* grid) const
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Arc::Type Arc::getType() const
|
||||
{
|
||||
return Type::CURVE;
|
||||
}
|
||||
|
||||
Arc::CurveType Arc::getCurveType() const
|
||||
{
|
||||
return CurveType::ARC;
|
||||
}
|
35
src/base/geometry/path/Arc.h
Normal file
35
src/base/geometry/path/Arc.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
#pragma once
|
||||
|
||||
#include "Curve.h"
|
||||
#include "Point.h"
|
||||
|
||||
class Arc : public Curve
|
||||
{
|
||||
public:
|
||||
Arc(const Point& startPoint, const Point& endPoint, double rX, double rY, double rotation = 0, bool largeArc = false, bool sweep = false);
|
||||
|
||||
Point getFirstPoint() const override;
|
||||
|
||||
Point getEndPoint() const override;
|
||||
|
||||
Bounds getBounds() const override;
|
||||
|
||||
const Point& getLocation() const override;
|
||||
|
||||
Type getType() const override;
|
||||
|
||||
CurveType getCurveType() const override;
|
||||
|
||||
void sample(SparseGrid<bool>* grid) const override;
|
||||
|
||||
std::string toPostScriptString(std::size_t precision = 0) const override;
|
||||
|
||||
private:
|
||||
Point mStartPoint;
|
||||
Point mEndPoint;
|
||||
double mRx{ 0.0 };
|
||||
double mRy{ 0.0 };
|
||||
double mRotation{ 0 };
|
||||
bool mLargeArc{ false };
|
||||
bool mSweep{ false };
|
||||
};
|
65
src/base/geometry/path/CubicBezierCurve.cpp
Normal file
65
src/base/geometry/path/CubicBezierCurve.cpp
Normal file
|
@ -0,0 +1,65 @@
|
|||
#include "CubicBezierCurve.h"
|
||||
|
||||
#include "PointParser.h"
|
||||
|
||||
CubicBezierCurve::CubicBezierCurve(const Point& startPoint, const Point& endPoint, const Point& startControlPoint, const Point& endControlPoint)
|
||||
: mStartPoint(startPoint),
|
||||
mEndPoint(endPoint),
|
||||
mStartControlPoint(startControlPoint),
|
||||
mEndControlPoint(endControlPoint)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Point CubicBezierCurve::getFirstPoint() const
|
||||
{
|
||||
return mStartPoint;
|
||||
}
|
||||
|
||||
Point CubicBezierCurve::getEndPoint() const
|
||||
{
|
||||
return mEndPoint;
|
||||
}
|
||||
|
||||
std::string CubicBezierCurve::toPostScriptString(std::size_t precision) const
|
||||
{
|
||||
if (mPostscriptPositioning == PostscriptPositioning::RELATIVE_TO)
|
||||
{
|
||||
const auto start_control = PointParser::toStringRelative(mStartControlPoint, mStartPoint, 2, " ", precision);
|
||||
const auto end_control = PointParser::toStringRelative(mEndControlPoint, mStartPoint, 2, " ", precision);
|
||||
const auto end = PointParser::toStringRelative(mEndPoint, mStartPoint, 2, " ", precision);
|
||||
return "c" + start_control + " " + end_control + " " + end;
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto start_control = PointParser::toString(mStartControlPoint, 2, " ", precision);
|
||||
const auto end_control = PointParser::toString(mEndControlPoint, 2, " ", precision);
|
||||
const auto end = PointParser::toString(mEndPoint, 2, " ", precision);
|
||||
return "C" + start_control + " " + end_control + " " + end;
|
||||
}
|
||||
}
|
||||
|
||||
Bounds CubicBezierCurve::getBounds() const
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
const Point& CubicBezierCurve::getLocation() const
|
||||
{
|
||||
return mStartPoint;
|
||||
}
|
||||
|
||||
void CubicBezierCurve::sample(SparseGrid<bool>* grid) const
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CubicBezierCurve::Type CubicBezierCurve::getType() const
|
||||
{
|
||||
return Type::CURVE;
|
||||
}
|
||||
|
||||
CubicBezierCurve::CurveType CubicBezierCurve::getCurveType() const
|
||||
{
|
||||
return CurveType::CUBIC_BEZIER;
|
||||
}
|
32
src/base/geometry/path/CubicBezierCurve.h
Normal file
32
src/base/geometry/path/CubicBezierCurve.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
#pragma once
|
||||
|
||||
#include "Curve.h"
|
||||
#include "Point.h"
|
||||
|
||||
class CubicBezierCurve : public Curve
|
||||
{
|
||||
public:
|
||||
CubicBezierCurve(const Point& startPoint, const Point& endPoint, const Point& startControlPoint, const Point& endControlPoint);
|
||||
|
||||
Point getFirstPoint() const override;
|
||||
|
||||
Point getEndPoint() const override;
|
||||
|
||||
Bounds getBounds() const override;
|
||||
|
||||
const Point& getLocation() const override;
|
||||
|
||||
Type getType() const override;
|
||||
|
||||
CurveType getCurveType() const override;
|
||||
|
||||
void sample(SparseGrid<bool>* grid) const override;
|
||||
|
||||
std::string toPostScriptString(std::size_t precision = 0) const override;
|
||||
|
||||
private:
|
||||
Point mStartPoint;
|
||||
Point mEndPoint;
|
||||
Point mStartControlPoint;
|
||||
Point mEndControlPoint;
|
||||
};
|
|
@ -8,6 +8,10 @@ public:
|
|||
enum class CurveType
|
||||
{
|
||||
ARC,
|
||||
CUBIC_BEZIER
|
||||
QUADRATIC_BEZIER,
|
||||
CUBIC_BEZIER,
|
||||
UNKNOWN
|
||||
};
|
||||
|
||||
virtual CurveType getCurveType() const = 0;
|
||||
};
|
|
@ -1,5 +1,7 @@
|
|||
#include "Line.h"
|
||||
|
||||
#include "PointParser.h"
|
||||
|
||||
Line::Line(const Point& start, const PointCollection& points)
|
||||
: mStartPoint(start),
|
||||
mPoints(points)
|
||||
|
@ -62,14 +64,26 @@ Line::Line(const Point& start, InputBufferType bufferType, const std::vector<dou
|
|||
}
|
||||
}
|
||||
|
||||
std::string Line::toPostScriptString() const
|
||||
std::string Line::toPostScriptString(std::size_t precision) const
|
||||
{
|
||||
std::string path = "L ";
|
||||
for (const auto& point : mPoints.getPoints())
|
||||
if (mPostscriptPositioning == PostscriptPositioning::ABSOLUTE_TO)
|
||||
{
|
||||
path += std::to_string(point.getX()) + " " + std::to_string(point.getY()) + " ";
|
||||
std::string path = "L";
|
||||
for (const auto& point : mPoints.getPoints())
|
||||
{
|
||||
path += PointParser::toString(point, 2, " ", precision) + " ";
|
||||
}
|
||||
return path;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string path = "l";
|
||||
for (const auto& point : mPoints.getPoints())
|
||||
{
|
||||
path += PointParser::toStringRelative(point, mStartPoint, 2, " ", precision) + " ";
|
||||
}
|
||||
return path;
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
Point Line::getFirstPoint() const
|
||||
|
|
|
@ -37,7 +37,7 @@ public:
|
|||
|
||||
void sample(SparseGrid<bool>* grid) const override {};
|
||||
|
||||
std::string toPostScriptString() const override;
|
||||
std::string toPostScriptString(std::size_t precision = 0) const override;
|
||||
|
||||
private:
|
||||
Point mStartPoint;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "LineSegment.h"
|
||||
|
||||
#include "PointParser.h"
|
||||
|
||||
LineSegment::LineSegment(const Point& p0, const Point& p1)
|
||||
: mP0(p0),
|
||||
mP1(p1)
|
||||
|
@ -32,9 +34,51 @@ void LineSegment::sample(SparseGrid<bool>* grid) const
|
|||
|
||||
}
|
||||
|
||||
std::string LineSegment::toPostScriptString() const
|
||||
std::string LineSegment::toPostScriptString(std::size_t precision) const
|
||||
{
|
||||
return "L " + std::to_string(mP1.getX()) + " " + std::to_string(mP1.getY());
|
||||
if (isHorizontal())
|
||||
{
|
||||
if (mPostscriptPositioning == PostscriptPositioning::ABSOLUTE_TO)
|
||||
{
|
||||
return "H" + PointParser::toString(mP1.getX(), precision);
|
||||
}
|
||||
else
|
||||
{
|
||||
return "h" + PointParser::toString(mP0.getDeltaX(mP1), precision);
|
||||
}
|
||||
}
|
||||
else if (isVertical())
|
||||
{
|
||||
if (mPostscriptPositioning == PostscriptPositioning::ABSOLUTE_TO)
|
||||
{
|
||||
return "V" + PointParser::toString(mP1.getY(), precision);
|
||||
}
|
||||
else
|
||||
{
|
||||
return "v" + PointParser::toString(mP0.getDeltaY(mP1), precision);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mPostscriptPositioning == PostscriptPositioning::ABSOLUTE_TO)
|
||||
{
|
||||
return "L" + PointParser::toString(mP1, 2, " ", precision);
|
||||
}
|
||||
else
|
||||
{
|
||||
return "l" + PointParser::toStringRelative(mP1, mP0, 2, " ", precision);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool LineSegment::isHorizontal() const
|
||||
{
|
||||
return mP0.getDeltaY(mP1) == 0.0;
|
||||
}
|
||||
|
||||
bool LineSegment::isVertical() const
|
||||
{
|
||||
return mP0.getDeltaX(mP1) == 0.0;
|
||||
}
|
||||
|
||||
Bounds LineSegment::getBounds() const
|
||||
|
|
|
@ -17,8 +17,6 @@ public:
|
|||
|
||||
const Point& getPoint1() const;
|
||||
|
||||
void sample(SparseGrid<bool>* grid) const override;
|
||||
|
||||
Bounds getBounds() const override;
|
||||
|
||||
const Point& getLocation() const override;
|
||||
|
@ -27,10 +25,16 @@ public:
|
|||
|
||||
Point getEndPoint() const override;
|
||||
|
||||
std::string toPostScriptString() const override;
|
||||
|
||||
Type getType() const override;
|
||||
|
||||
bool isHorizontal() const;
|
||||
|
||||
bool isVertical() const;
|
||||
|
||||
void sample(SparseGrid<bool>* grid) const override;
|
||||
|
||||
std::string toPostScriptString(std::size_t precision = 0) const override;
|
||||
|
||||
private:
|
||||
Point mP0;
|
||||
Point mP1;
|
||||
|
|
|
@ -7,11 +7,25 @@
|
|||
class PathElement : public AbstractGeometricItem
|
||||
{
|
||||
public:
|
||||
enum class PostscriptPositioning
|
||||
{
|
||||
RELATIVE_TO,
|
||||
ABSOLUTE_TO
|
||||
};
|
||||
|
||||
~PathElement();
|
||||
|
||||
virtual Point getFirstPoint() const = 0;
|
||||
|
||||
virtual Point getEndPoint() const = 0;
|
||||
|
||||
virtual std::string toPostScriptString() const = 0;
|
||||
void setPostscriptPositioning(PostscriptPositioning positioning)
|
||||
{
|
||||
mPostscriptPositioning = positioning;
|
||||
}
|
||||
|
||||
virtual std::string toPostScriptString(std::size_t precision = 0) const = 0;
|
||||
|
||||
protected:
|
||||
PostscriptPositioning mPostscriptPositioning{ PostscriptPositioning::RELATIVE_TO};
|
||||
};
|
|
@ -7,6 +7,9 @@
|
|||
|
||||
#include "Line.h"
|
||||
#include "LineSegment.h"
|
||||
#include "Arc.h"
|
||||
#include "QuadraticBezierCurve.h"
|
||||
#include "CubicBezierCurve.h"
|
||||
|
||||
void PathPostScriptConverter::fromPostScript(GeometryPath* targetPath, const std::string& postScriptPath)
|
||||
{
|
||||
|
@ -118,6 +121,18 @@ void PathPostScriptConverter::onElementEnd()
|
|||
{
|
||||
element = onLineTo();
|
||||
}
|
||||
else if (mLineState == LineState::IN_ARC)
|
||||
{
|
||||
element = onArc();
|
||||
}
|
||||
else if (mLineState == LineState::IN_QUADRATIC_BEZIER)
|
||||
{
|
||||
element = onQuadraticBezier();
|
||||
}
|
||||
else if (mLineState == LineState::IN_CUBIC_BEZIER)
|
||||
{
|
||||
element = onCubicBezier();
|
||||
}
|
||||
else if (mLineState == LineState::IN_FIRST_POINT)
|
||||
{
|
||||
onMoveTo();
|
||||
|
@ -125,6 +140,8 @@ void PathPostScriptConverter::onElementEnd()
|
|||
|
||||
if (element)
|
||||
{
|
||||
const auto positioning = (mPositionState == PositionState::RELATIVE) ? PathElement::PostscriptPositioning::RELATIVE_TO : PathElement::PostscriptPositioning::ABSOLUTE_TO;
|
||||
element->setPostscriptPositioning(positioning);
|
||||
mCurrentPoint = element->getEndPoint();
|
||||
mWorkingFeature->addElement(std::move(element));
|
||||
}
|
||||
|
@ -216,6 +233,85 @@ PathElementPtr PathPostScriptConverter::onLineTo()
|
|||
return element;
|
||||
}
|
||||
|
||||
PathElementPtr PathPostScriptConverter::onArc()
|
||||
{
|
||||
PathElementPtr element;
|
||||
if (mPointBuffer.size() == 7)
|
||||
{
|
||||
double rx = mPointBuffer[0];
|
||||
double ry = mPointBuffer[1];
|
||||
double rotation = mPointBuffer[2];
|
||||
bool large_arc = bool(mPointBuffer[3]);
|
||||
bool sweep = bool(mPointBuffer[4]);
|
||||
|
||||
if (mPositionState == PositionState::RELATIVE)
|
||||
{
|
||||
const auto end_point = Point(mCurrentPoint.getX() + mPointBuffer[5], mCurrentPoint.getY() + mPointBuffer[6]);
|
||||
element = std::make_unique<Arc>(mCurrentPoint, end_point, rx, ry, rotation, large_arc, sweep);
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto end_point = Point(mPointBuffer[5], mPointBuffer[6]);
|
||||
element = std::make_unique<Arc>(mCurrentPoint, end_point, rx, ry, rotation, large_arc, sweep);
|
||||
}
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
PathElementPtr PathPostScriptConverter::onQuadraticBezier()
|
||||
{
|
||||
PathElementPtr element;
|
||||
if (mPointBuffer.size() == 4)
|
||||
{
|
||||
double control_x = mPointBuffer[0];
|
||||
double control_y = mPointBuffer[1];
|
||||
double end_x = mPointBuffer[2];
|
||||
bool end_y = mPointBuffer[3];
|
||||
if (mPositionState == PositionState::RELATIVE)
|
||||
{
|
||||
const auto control_point = Point(mCurrentPoint.getX() + control_x, mCurrentPoint.getY() + control_y);
|
||||
const auto end_point = Point(mCurrentPoint.getX() + end_x, mCurrentPoint.getY() + end_y);
|
||||
element = std::make_unique<QuadraticBezierCurve>(mCurrentPoint, end_point, control_point);
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto control_point = Point(control_x, control_y);
|
||||
const auto end_point = Point(end_x, end_y);
|
||||
element = std::make_unique<QuadraticBezierCurve>(mCurrentPoint, end_point, control_point);
|
||||
}
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
PathElementPtr PathPostScriptConverter::onCubicBezier()
|
||||
{
|
||||
PathElementPtr element;
|
||||
if (mPointBuffer.size() == 4)
|
||||
{
|
||||
double control0_x = mPointBuffer[0];
|
||||
double control0_y = mPointBuffer[1];
|
||||
double control1_x = mPointBuffer[0];
|
||||
double control1_y = mPointBuffer[1];
|
||||
double end_x = mPointBuffer[2];
|
||||
bool end_y = mPointBuffer[3];
|
||||
if (mPositionState == PositionState::RELATIVE)
|
||||
{
|
||||
const auto control_point0 = Point(mCurrentPoint.getX() + control0_x, mCurrentPoint.getY() + control0_y);
|
||||
const auto control_point1 = Point(mCurrentPoint.getX() + control1_x, mCurrentPoint.getY() + control1_y);
|
||||
const auto end_point = Point(mCurrentPoint.getX() + end_x, mCurrentPoint.getY() + end_y);
|
||||
element = std::make_unique<CubicBezierCurve>(mCurrentPoint, end_point, control_point0, control_point1);
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto control_point0 = Point(control0_x, control0_y);
|
||||
const auto control_point1 = Point(control1_x, control1_y);
|
||||
const auto end_point = Point(end_x, end_y);
|
||||
element = std::make_unique<CubicBezierCurve>(mCurrentPoint, end_point, control_point0, control_point1);
|
||||
}
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
std::string PathPostScriptConverter::toPostScript(const GeometryPath* targetPath)
|
||||
{
|
||||
std::string path;
|
||||
|
@ -226,7 +322,7 @@ std::string PathPostScriptConverter::toPostScript(const GeometryPath* targetPath
|
|||
|
||||
for (const auto& path_element : feature->getElements())
|
||||
{
|
||||
path += " " + path_element->toPostScriptString();
|
||||
path += " " + path_element->toPostScriptString(mPrecision);
|
||||
}
|
||||
path += "Z ";
|
||||
}
|
||||
|
|
|
@ -51,6 +51,10 @@ private:
|
|||
PathElementPtr onVerticalLineTo();
|
||||
PathElementPtr onLineTo();
|
||||
|
||||
PathElementPtr onArc();
|
||||
PathElementPtr onQuadraticBezier();
|
||||
PathElementPtr onCubicBezier();
|
||||
|
||||
LineState mLineState{ LineState::START };
|
||||
PositionState mPositionState{ PositionState::ABSOLUTE };
|
||||
std::string mBuffer;
|
||||
|
@ -58,4 +62,6 @@ private:
|
|||
|
||||
GeometryPathFeaturePtr mWorkingFeature;
|
||||
Point mCurrentPoint;
|
||||
|
||||
std::size_t mPrecision{ 3 };
|
||||
};
|
||||
|
|
58
src/base/geometry/path/QuadraticBezierCurve.cpp
Normal file
58
src/base/geometry/path/QuadraticBezierCurve.cpp
Normal file
|
@ -0,0 +1,58 @@
|
|||
#include "QuadraticBezierCurve.h"
|
||||
|
||||
#include "PointParser.h"
|
||||
|
||||
QuadraticBezierCurve::QuadraticBezierCurve(const Point& startPoint, const Point& endPoint, const Point& controlPoint)
|
||||
: mStartPoint(startPoint),
|
||||
mEndPoint(endPoint),
|
||||
mControlPoint(controlPoint)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Point QuadraticBezierCurve::getFirstPoint() const
|
||||
{
|
||||
return mStartPoint;
|
||||
}
|
||||
|
||||
Point QuadraticBezierCurve::getEndPoint() const
|
||||
{
|
||||
return mEndPoint;
|
||||
}
|
||||
|
||||
std::string QuadraticBezierCurve::toPostScriptString(std::size_t precision) const
|
||||
{
|
||||
if (mPostscriptPositioning == PostscriptPositioning::RELATIVE_TO)
|
||||
{
|
||||
return "q" + PointParser::toStringRelative(mControlPoint, mStartPoint, 2, " ", precision) + " " + PointParser::toStringRelative(mEndPoint, mStartPoint, 2, " ", precision);
|
||||
}
|
||||
else
|
||||
{
|
||||
return "Q" + PointParser::toString(mControlPoint, 2, " ", precision) + " " + PointParser::toString(mEndPoint, 2, " ", precision);
|
||||
}
|
||||
}
|
||||
|
||||
Bounds QuadraticBezierCurve::getBounds() const
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
const Point& QuadraticBezierCurve::getLocation() const
|
||||
{
|
||||
return mStartPoint;
|
||||
}
|
||||
|
||||
void QuadraticBezierCurve::sample(SparseGrid<bool>* grid) const
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QuadraticBezierCurve::Type QuadraticBezierCurve::getType() const
|
||||
{
|
||||
return Type::CURVE;
|
||||
}
|
||||
|
||||
QuadraticBezierCurve::CurveType QuadraticBezierCurve::getCurveType() const
|
||||
{
|
||||
return CurveType::QUADRATIC_BEZIER;
|
||||
}
|
31
src/base/geometry/path/QuadraticBezierCurve.h
Normal file
31
src/base/geometry/path/QuadraticBezierCurve.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
#pragma once
|
||||
|
||||
#include "Curve.h"
|
||||
#include "Point.h"
|
||||
|
||||
class QuadraticBezierCurve : public Curve
|
||||
{
|
||||
public:
|
||||
QuadraticBezierCurve(const Point& startPoint, const Point& endPoint, const Point& controlPoint);
|
||||
|
||||
Point getFirstPoint() const override;
|
||||
|
||||
Point getEndPoint() const override;
|
||||
|
||||
Bounds getBounds() const override;
|
||||
|
||||
const Point& getLocation() const override;
|
||||
|
||||
Type getType() const override;
|
||||
|
||||
CurveType getCurveType() const override;
|
||||
|
||||
void sample(SparseGrid<bool>* grid) const override;
|
||||
|
||||
std::string toPostScriptString(std::size_t precision = 0) const override;
|
||||
|
||||
private:
|
||||
Point mStartPoint;
|
||||
Point mEndPoint;
|
||||
Point mControlPoint;
|
||||
};
|
|
@ -31,9 +31,9 @@ Point::~Point()
|
|||
{
|
||||
};
|
||||
|
||||
std::shared_ptr<Point> Point::Create(double x, double y, double z)
|
||||
std::unique_ptr<Point> Point::Create(double x, double y, double z)
|
||||
{
|
||||
return std::make_shared<Point>(x, y, z);
|
||||
return std::make_unique<Point>(x, y, z);
|
||||
}
|
||||
|
||||
double Point::getX() const
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include "Vector.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
class Transform;
|
||||
|
||||
|
@ -19,7 +18,7 @@ public:
|
|||
|
||||
~Point();
|
||||
|
||||
static std::shared_ptr<Point> Create(double x, double y, double z = 0);
|
||||
static std::unique_ptr<Point> Create(double x, double y, double z = 0);
|
||||
|
||||
void apply(const Transform& transform);
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#include "Transform.h"
|
||||
#include "Bounds.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
class PointCollection
|
||||
{
|
||||
public:
|
||||
|
|
66
src/base/geometry/points/PointParser.cpp
Normal file
66
src/base/geometry/points/PointParser.cpp
Normal file
|
@ -0,0 +1,66 @@
|
|||
#include "PointParser.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
std::string PointParser::toString(const Point& p, std::size_t dimensions, const std::string& delimiter, std::size_t precision)
|
||||
{
|
||||
return toString(p.getX(), p.getY(), p.getZ(), dimensions, delimiter, precision);
|
||||
}
|
||||
|
||||
std::string PointParser::toStringRelative(const Point& p, const Point& relativeTo, std::size_t dimensions, const std::string& delimiter, std::size_t precision)
|
||||
{
|
||||
return toString(relativeTo.getDeltaX(p), relativeTo.getDeltaY(p), relativeTo.getDeltaZ(p), dimensions, delimiter, precision);
|
||||
}
|
||||
|
||||
std::string PointParser::toString(double x, double y, double z, std::size_t dimensions, const std::string& delimiter, std::size_t precision)
|
||||
{
|
||||
if (precision == 0)
|
||||
{
|
||||
if (dimensions == 1)
|
||||
{
|
||||
return std::to_string(x);
|
||||
}
|
||||
else if (dimensions == 2)
|
||||
{
|
||||
return std::to_string(x) + delimiter + std::to_string(y);
|
||||
}
|
||||
else
|
||||
{
|
||||
return std::to_string(x) + delimiter + std::to_string(y) + delimiter + std::to_string(z);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::stringstream sstr;
|
||||
sstr.precision(precision);
|
||||
if (dimensions == 1)
|
||||
{
|
||||
sstr << x;
|
||||
}
|
||||
else if (dimensions == 2)
|
||||
{
|
||||
sstr << x << delimiter << y;
|
||||
}
|
||||
else
|
||||
{
|
||||
sstr << x << delimiter << y << delimiter << z;
|
||||
}
|
||||
return sstr.str();
|
||||
}
|
||||
}
|
||||
|
||||
std::string PointParser::toString(double x, std::size_t precision)
|
||||
{
|
||||
if (precision == 0)
|
||||
{
|
||||
return std::to_string(x);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::stringstream sstr;
|
||||
sstr.precision(precision);
|
||||
sstr << x;
|
||||
return sstr.str();
|
||||
}
|
||||
}
|
||||
|
18
src/base/geometry/points/PointParser.h
Normal file
18
src/base/geometry/points/PointParser.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
#pragma once
|
||||
|
||||
#include "Point.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
class PointParser
|
||||
{
|
||||
public:
|
||||
|
||||
static std::string toString(const Point& p, std::size_t dimensions = 3, const std::string& delimiter = " ", std::size_t precision = 0);
|
||||
|
||||
static std::string toStringRelative(const Point& p, const Point& relativeTo, std::size_t dimensions = 3, const std::string& delimiter = " ", std::size_t precision = 0);
|
||||
|
||||
static std::string toString(double x, double y, double z, std::size_t dimensions = 3, const std::string& delimiter = " ", std::size_t precision = 0);
|
||||
|
||||
static std::string toString(double x, std::size_t precision = 0);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue