#include <ctime>
#include <iostream>
{
if (!n) {
}
if (n == 1) {
switch (Tools::boardRand() % 2) {
case 0:
case 1:
}
}
int count[4] = {0, 0, 0, 0};
while (count[0] + count[1] + count[2] + count[3] != n) {
count[Tools::boardRand() % 4] += 1;
}
top << topLeft;
top.
append(topRight, Direction::Right, Alignment::Center, 0.0, UseLineWidth);
bottom << bottomLeft;
bottom.
append(bottomRight, Direction::Right, Alignment::Center, 0.0, UseLineWidth);
top.
append(bottom, Direction::Bottom, Alignment::Center, 0.0, UseLineWidth);
if (n >= 2) {
group << top;
Rect r = top.bbox(UseLineWidth);
list << group;
return list;
} else {
list << top;
return list;
}
}
{
try {
while (true) {
++n;
}
}
return result;
}
{
Tools::initBoardRand(1000);
Style::setDefaultLineWidth(0.5);
Style::setDefaultPenColor(Color::Blue);
Style::setDefaultFillColor(Color::Null);
cross <<
Line(0, 0, 10, 10, Color::Green) <<
Line(0, 10, 10, 0, Color::Green);
int n = 25;
while (n--) {
int r = Tools::boardRand() % 3;
switch (r) {
case 0:
board.
append(
circle(0, 0, 5.0), Direction::Right, Alignment::Center);
break;
case 1:
board.
append(
rectangle(0, 0, 10, 10), Direction::Right, Alignment::Center);
break;
case 2:
board.
append(cross, Direction::Right, Alignment::Center);
break;
}
}
ShapeList rectangles = findAll<Polyline>(board);
board.
append(circles, Direction::Bottom, Alignment::Left);
board.
append(rectangles, Direction::Bottom, Alignment::Left);
board.
append(crosses, Direction::Bottom, Alignment::Left);
for (
Shape & s : circles) {
}
board.
append(circles, Direction::Bottom, Alignment::Right);
std::cout << "List of shapes at to level\n";
std::cout << "==========================\n";
for (
const Shape & s : board) {
std::cout << s.
name() <<
", ";
}
std::cout << "\n\n";
std::cout << "Beadth-First traversal of the shapes tree\n";
std::cout << "=========================================\n";
while (bfi != bfe) {
std::cout << (*bfi).name() << ", ";
++bfi;
}
std::cout << "\n\n";
std::cout << "Depth-First traversal of the shapes tree\n";
std::cout << "========================================\n";
while (dfi != dfe) {
std::cout << (*dfi).name() << ", ";
++dfi;
}
std::cout << "\n\n";
std::cout <<
"Size is " << board.
size() << std::endl;
std::cout <<
"Board deep size is " << board.
deepSize() << std::endl;
std::cout << "Tree deep size is " << deepSize << std::endl;
std::size_t counter = 0;
while (dfi != dfe) {
if (!r) {
}
if (r) {
shade.
setRGBf(0.2f + 0.8f * (counter / (
float)deepSize), 0, 0, 1.0);
}
++dfi;
++counter;
}
std::cout << counter << " shapes visited.\n";
board << points;
board <<
Polyline(path,
Color(
"#00c000"), Color::Null, 0.5, SolidStyle, RoundCap, RoundJoin);
}
Declaration of the Board class.
int main(int argc, char *argv[])
Definition arithmetic.cpp:16
Structure representing an RGB triple.
Definition Color.h:43
Color & setRGBf(float red, float green, float blue, float alpha=1.0)
Definition Color.cpp:71
Definition Exception.h:36
@ Helvetica
Definition PSFonts.h:68
Ellipse circle(double x, double y, double radius, Color penColor=Style::defaultPenColor(), Color fillColor=Style::defaultFillColor(), double lineWidth=Style::defaultLineWidth(), const LineStyle lineStyle=Style::defaultLineStyle())
Definition Ellipse.cpp:371
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
Group cross(Point p, const Style &style=Style::defaultStyle())
Definition Board.cpp:1024
Class for EPS, FIG or SVG drawings.
Definition Board.h:61
void saveSVG(const char *filename, PageSize size=PageSize::BoundingBox, double margin=0.0, Unit unit=Unit::Millimeter) const
Definition Board.cpp:765
An ellipse.
Definition Ellipse.h:38
A group of shapes. A group is basically a ShapeList except that when rendered in either an SVG of a F...
Definition Group.h:40
A line between two points.
Definition Line.h:38
A path, according to Postscript and SVG definition.
Definition Path.h:45
A polygonal line described by a series of 2D points.
Definition Polyline.h:38
Struct representing a rectangle on the plane.
Definition Rect.h:40
The BreadthFirstIterator struct allows to traverse the shape tree using a breadth-first strategy.
Definition ShapeList.h:392
The DepthFirstIterator struct allows to traverse the shape tree using a depth-first strategy.
Definition ShapeList.h:370
Shape * pointer()
Definition ShapeList.h:693
A group of shapes.
Definition ShapeList.h:47
BreadthFirstIterator breadthFirstBegin()
breadthFirstBegin
Definition ShapeList.h:659
BreadthFirstIterator breadthFirstEnd()
breadthFirstEnd
Definition ShapeList.h:664
const std::string & name() const override
Definition ShapeList.cpp:49
DepthFirstIterator depthFirstBegin()
depthFirstBegin
Definition ShapeList.h:649
ShapeList & append(const Shape &shape, Direction direction=Direction::Right, Alignment alignment=Alignment::Center, double margin=0.0, LineWidthFlag lineWidthFlag=UseLineWidth)
Definition ShapeList.cpp:232
std::size_t size() const
The number of shapes in the list (at top level).
Definition ShapeList.h:669
std::size_t deepSize() const
Recursively counts the number of shapes in the list.
Definition ShapeList.cpp:501
DepthFirstIterator depthFirstEnd()
depthFirstEnd
Definition ShapeList.h:654
std::vector< Shape * >::size_type size_type
Definition ShapeList.h:49
ShapeList & scale(double sx, double sy) override
Definition ShapeList.cpp:330
T & topLevelFindLast(std::size_t position=0)
Definition ShapeList.h:522
T & last(const std::size_t position=0)
Definition ShapeList.h:505
Abstract structure for a 2D shape.
Definition Shape.h:64
virtual Point center(LineWidthFlag lineWidthFlag=IgnoreLineWidth) const
Definition Shape.cpp:59
A piece of text.
Definition Text.h:40
const Color Colors[NbColors]
Definition traversal.cpp:18
ShapeList generateGroup(int n)
Definition traversal.cpp:20
ShapeList findAll(ShapeList &list)
Definition traversal.cpp:67
const int NbColors
Definition traversal.cpp:17