Board 0.9.6
examples/holes.cpp
#include <Board.h>
#include <board/Tools.h>
#include <ctime>
#include <set>
#include <vector>
using namespace LibBoard;
int main(int, char *[])
{
Board board;
Board::enableLineWidthScaling();
board.clear(Color::White);
Tools::initBoardRand(static_cast<unsigned int>(time(nullptr)));
Path pA(Path::Closed);
pA << Point(0, 0) << Point(180, 0) << Point(180, 300) << Point(0, 300);
Path pB(Path::Closed);
pB << Point(0, 0) << Point(200, 0) << Point(500, 5) << Point(150, 200);
Path losange;
losange.close();
losange << Point(0, 0) << Point(300, -500) << Point(600, 0) << Point(300, 500);
board << Line(-50, 0, 650, 0, Color::Red);
board << Line(-50, 300, 650, -300, Color::Red);
board << board.last<Line>();
board.last<Line>().rotate(90 * Board::Degree);
Polyline p(losange, Style::defaultPenColor(), Color::Green);
losange.scale(0.5);
p.addHole(losange);
board << p;
board.rotate(45 * Board::Degree);
board.append(board.last<Polyline>(), Direction::Right, Alignment::Center);
Polyline square(Path::Closed, Color::Black, Color(70, 70, 130), 0.1);
square << Point(-110, 110) << Point(110, 110) << Point(110, -110) << Point(-110, -110);
int n = 80;
std::set<std::pair<int, int>> holes;
while (n--) {
holes.insert(std::make_pair((int)(Tools::boardRand() % 20) - 10, (int)(Tools::boardRand() % 20) - 10));
}
std::set<std::pair<int, int>>::iterator it = holes.begin();
while (it != holes.end()) {
Path hole;
Point p(it->first * 10, it->second * 10);
hole << Point(p.x - 5, p.y + 5) << Point(p.x + 5, p.y + 5) << Point(p.x + 5, p.y - 5) << Point(p.x - 5, p.y - 5);
square.addHole(hole);
++it;
}
board << square.scaled(3).translated(1000, 0).rotated(45 * Board::Degree);
board.saveEPS("holes.eps", PageSize::A4);
board.scaleToWidth(25, UseLineWidth);
board.saveSVG("holes.svg", PageSize::BoundingBox, 0.0, Unit::Centimeter);
}
Declaration of the Board class.
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
int main(int argc, char *argv[])
Definition arithmetic.cpp:16
Structure representing an RGB triple.
Definition Color.h:43
Definition Board.h:55
Class for EPS, FIG or SVG drawings.
Definition Board.h:61
void saveEPS(std::ostream &out, PageSize size=PageSize::BoundingBox, double margin=0.0, Unit unit=Unit::Millimeter, const std::string &title=std::string()) const
Definition Board.cpp:539
Board & rotate(double angle, const Point &center) override
Rotate the board by an angle around a point.
Definition Board.cpp:155
void clear(const Color &color=Color::Null)
Definition Board.cpp:149
void saveSVG(const char *filename, PageSize size=PageSize::BoundingBox, double margin=0.0, Unit unit=Unit::Millimeter) const
Definition Board.cpp:765
A line between two points.
Definition Line.h:38
A path, according to Postscript and SVG definition.
Definition Path.h:45
Path & scale(double sx, double sy)
Apply a scaling factor to the path along each axis.
Definition Path.cpp:169
void close()
Close the path.
Definition Path.h:453
Struct representing a 2D point.
Definition Point.h:42
double y
Definition Point.h:44
double x
Definition Point.h:43
A polygonal line described by a series of 2D points.
Definition Polyline.h:38
void addHole(const Path &path)
Add a hole to the path. Warning: Hole share the polyline line style.
Definition Polyline.cpp:152
ShapeList & append(const Shape &shape, Direction direction=Direction::Right, Alignment alignment=Alignment::Center, double margin=0.0, LineWidthFlag lineWidthFlag=UseLineWidth)
Definition ShapeList.cpp:232
T & last(const std::size_t position=0)
Definition ShapeList.h:505
Shape & scaleToWidth(double w, LineWidthFlag lineWidthFlag)
Definition Shape.cpp:85