Board 0.9.6
examples/bezier.cpp
#include <cstdlib>
#include <Board.h>
using namespace LibBoard;
int main(int, char *[])
{
Board board;
Board::disableLineWidthScaling();
board.setLineWidth(1.0);
board.setPenColor(Color::Blue);
board.setFillColor(Color::Red);
board << Bezier(Point(10, 10), Point(10, 10) + Point(5, 5), Point(30, 10), Point(30, 10) + Point(-5, 5), Color::Red).rotated(45);
Bezier b(Point(0, 0), Point(0, 0) + Point(0, 20), Point(-30, 0), Point(-30, 0) + Point(0, -15), Color::Green, Color::Null, 1.0);
l << b; // << LibBoard::rectangle(b.boundingBox(UseLineWidth), Color::Black, Color::Null, 1.0);
board.append(b);
board.append(b.scaled(2, 2));
board.append(b.rotated(45 * Board::Degree));
Bezier b3 = b.rotated(45 * Board::Degree).scaled(5);
lb << b3;
lb << rectangle(lb.boundingBox(UseLineWidth));
auto ex = b3.pathThroughLocalExtremums();
std::cout << Path(ex, Path::Open) << std::endl;
for (const Point & p : ex) {
lb << cross(p);
}
lb << bezierControls(b3);
lb << Polyline(Path(ex, Path::Open), Color::Magenta);
board.append(lb);
board.append(l.rotated(45 * Board::Degree).translated(100, 0).scaled(5));
board.append(l.rotated(45 * Board::Degree).translated(200, 0).scaled(3, 2));
l.clear();
l << b;
l << b.rotated(45 * Board::Degree);
l << LibBoard::rectangle(b.rotated(45 * Board::Degree).boundingBox(UseLineWidth), Color::Black, Color::Null, 1.0);
Polyline dp(b.discretizedPath().rotated(45 * Board::Degree), Color::Blue);
l << dp;
board.append(l);
Path p = {Point(0, 0), Point(100, 0)};
std::vector<Point> c = {Point(125, 75), Point(-25, 75)};
l.clear();
Bezier b2(p.points(), c, Color::Green);
l << b2;
std::cout << Path(ex, Path::Open);
for (const Point & p : ex) {
l << cross(p);
}
l << bezierControls(b2);
l << Polyline(ex, Path::Open, Color::Magenta);
board.append(l);
Point y0(0, 0);
Point y1(10, 20);
Point y2(20, 3);
Point y3(25, -5);
{
l.clear();
l << cross(y0);
l << cross(y1);
l << cross(y2);
l << cross(y3);
Bezier b = Bezier::interpolation(y0, y1, y2, y3);
l << b;
board.append(l);
Path p = {y0, y1, y2, y3};
board.append(Bezier::smoothedPolyline(p, 0.5));
}
board.saveSVG("bezier.svg", PageSize::BoundingBox);
// system("svgviewer bezier.svg");
}
Declaration of the Board class.
int main(int argc, char *argv[])
Definition arithmetic.cpp:16
Definition Board.h:55
Polyline rectangle(double left, double top, double width, double height, Color penColor=Style::defaultPenColor(), Color fillColor=Style::defaultFillColor(), double lineWidth=Style::defaultLineWidth(), const LineStyle lineStyle=Style::defaultLineStyle(), const LineCap cap=Style::defaultLineCap(), const LineJoin join=Style::defaultLineJoin())
Definition Polyline.cpp:569
A Bezier curve described by two series of 2D points (curve points and control points).
Definition Bezier.h:42
std::vector< Point > pathThroughLocalExtremums() const
A path through local extremums.
Definition Bezier.cpp:269
Rect boundingBox(LineWidthFlag) const override
Return the bounding box of the curve.
Definition Bezier.cpp:617
Bezier scaled(double sx, double sy) const
Definition Bezier.cpp:184
Bezier rotated(double angle, const Point &center) const
Rotated copy of the curve.
Definition Bezier.cpp:119
Path discretizedPath() const
A sequence of properly spaced points approximating the curve.
Definition Bezier.cpp:327
Class for EPS, FIG or SVG drawings.
Definition Board.h:61
Board & setPenColor(const Color &color)
Definition Board.cpp:244
Board & setFillColor(const Color &color)
Definition Board.cpp:268
Board & setLineWidth(double width)
Definition Board.cpp:274
void saveSVG(const char *filename, PageSize size=PageSize::BoundingBox, double margin=0.0, Unit unit=Unit::Millimeter) const
Definition Board.cpp:765
A path, according to Postscript and SVG definition.
Definition Path.h:45
const std::vector< Point > & points() const
Definition Path.cpp:371
Path rotated(double angle, const Point &center) const
Return a rotated copy of the path, thanks to an angle and a rotation center.
Definition Path.cpp:93
Struct representing a 2D point.
Definition Point.h:42
A polygonal line described by a series of 2D points.
Definition Polyline.h:38
A group of shapes.
Definition ShapeList.h:47
Rect boundingBox(LineWidthFlag) const override
Definition ShapeList.cpp:405
ShapeList scaled(double sx, double sy) const
Definition ShapeList.cpp:352
ShapeList & append(const Shape &shape, Direction direction=Direction::Right, Alignment alignment=Alignment::Center, double margin=0.0, LineWidthFlag lineWidthFlag=UseLineWidth)
Definition ShapeList.cpp:232
ShapeList translated(double dx, double dy)
Definition ShapeList.cpp:325
ShapeList rotated(double angle, const Point &center)
Definition ShapeList.cpp:298
ShapeList & clear()
Definition ShapeList.cpp:90