Board  0.9.5
examples/bezier.cpp
#include <cstdlib>
#include "Board.h"
using namespace LibBoard;
int main(int, char *[])
{
Board board;
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(Polyline(b.discretizedPath()));
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::OpenPath) << std::endl;
for (const Point & p : ex) {
lb << cross(p);
}
lb << bezierControls(b3);
lb << Polyline(Path(ex, Path::OpenPath), 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;
ex = b2.pathThroughLocalExtremums();
std::cout << Path(ex, Path::OpenPath);
for (const Point & p : ex) {
l << cross(p);
}
l << bezierControls(b2);
l << Polyline(ex, Path::OpenPath, 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", Board::BoundingBox);
board.saveEPS("bezier.eps", Board::BoundingBox);
system("svgviewer bezier.svg");
}
LibBoard::Board::saveEPS
void saveEPS(std::ostream &out, PageSize size=Board::BoundingBox, double margin=0.0, Unit unit=UMillimeter, const std::string &title=std::string()) const
Definition: Board.cpp:532
LibBoard::Board::setFillColor
Board & setFillColor(const Color &color)
Definition: Board.cpp:268
LibBoard::Polyline
A polygonal line described by a series of 2D points.
Definition: Polyline.h:38
LibBoard::Board::disableLineWidthScaling
static void disableLineWidthScaling()
Definition: Board.cpp:139
LibBoard::Board::saveSVG
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=0.0, Unit unit=UMillimeter) const
Definition: Board.cpp:758
LibBoard::Point
Struct representing a 2D point.
Definition: Point.h:42
LibBoard::Bezier
A cubice polygonal line described by a series of 2D points.
Definition: Bezier.h:40
LibBoard::cross
Group cross(Point p, const Style &style=Style::defaultStyle())
Definition: Board.cpp:968
LibBoard::ShapeList::translated
ShapeList translated(double dx, double dy)
Definition: ShapeList.cpp:339
LibBoard::Path
A path, according to Postscript and SVG definition.
Definition: Path.h:45
LibBoard::ShapeList::clear
ShapeList & clear()
Definition: ShapeList.cpp:86
LibBoard::Bezier::scaled
Bezier scaled(double sx, double sy) const
Definition: Bezier.cpp:184
LibBoard::ShapeList
A group of shapes.
Definition: ShapeList.h:46
LibBoard::bezierControls
Polyline bezierControls(const Bezier &bezier, const Style &style=Style::defaultStyle())
Produce a polyline of the Biezer vertices and control points.
Definition: Board.cpp:976
Board.h
Declaration of the Board class.
LibBoard::ShapeList::rotated
ShapeList rotated(double angle, const Point &center)
Definition: ShapeList.cpp:312
LibBoard::Board
Class for EPS, FIG or SVG drawings.
Definition: Board.h:62
LibBoard::ShapeList::scaled
ShapeList scaled(double sx, double sy) const
Definition: ShapeList.cpp:366
LibBoard::Board::setPenColor
Board & setPenColor(const Color &color)
Definition: Board.cpp:244
LibBoard::Board::setLineWidth
Board & setLineWidth(double width)
Definition: Board.cpp:274
LibBoard::ShapeList::append
ShapeList & append(const Shape &shape, Direction direction=ShapeList::Right, Alignment alignment=ShapeList::AlignCenter, double margin=0.0, LineWidthFlag lineWidthFlag=UseLineWidth)
Definition: ShapeList.cpp:246
LibBoard::ShapeList::boundingBox
Rect boundingBox(LineWidthFlag) const override
Definition: ShapeList.cpp:419