Board  0.9.5
RoughVisitor.h
Go to the documentation of this file.
1 /* -*- mode: c++ -*- */
26 #ifndef BOARD_ROUGH_VISITOR_H
27 #define BOARD_ROUGH_VISITOR_H
28 
29 /*
30  *
31  * matplotlib.pyplot.xkcd
32  *
33  * https://shihn.ca/posts/2020/roughjs-algorithms/
34  *
35  * https://openaccess.city.ac.uk/id/eprint/1274/
36  */
37 
38 #include <cstddef> // For std::size_t
39 #include "board/Point.h"
40 #include "board/ShapeVisitor.h"
41 #include "board/Types.h"
42 
43 namespace LibBoard
44 {
45 
47  RoughVisitor();
48  void setRepeat(int n);
49  void setFilling(SketchFilling filling);
50  void setHachureAngle(double angle);
51  void setHachureSpacing(double spacing);
52  void setAutomaticHachureSpacing(bool);
53  virtual Shape * map(const Shape & shape) override;
54  virtual Shape * map(const Shape & shape) const override;
55  virtual Shape * map(const Line &) override;
56  virtual Shape * map(const Line &) const override;
57  virtual Shape * map(const Arrow &) override;
58  virtual Shape * map(const Arrow &) const override;
59  virtual Shape * map(const Polyline &) override;
60  virtual Shape * map(const Polyline &) const override;
61  virtual Shape * map(const Ellipse &) override;
62  virtual Shape * map(const Ellipse &) const override;
63  virtual Shape * map(const Bezier &) override;
64  virtual Shape * map(const Bezier &) const override;
65 
66  virtual ~RoughVisitor() override;
67 
75  static void slideRandomly(Point & point, const double & radius);
76 
84  static Point randomlySlided(const Point & point, const double & radius);
85 
94  static void slideRandomlyAwayFromSegment(Point & p, const Point & a, const Point & b, const double magnitude);
95 
106  static Point randomlySlidedAwayFromSegment(const Point & p, const Point & a, const Point & b, const double magnitude);
107 
115  static void slideRandomlyAwayFromSegment(Point & p, const Point & a, const Point & b);
116 
126  static Point randomlySlidedAwayFromSegment(const Point & p, const Point & a, const Point & b);
127 
137  static void slideRandomlyAwayFromSegmentInBox(Point & p, const Point & u, double uMagnitude, const Point & v, double vMagnitude);
138 
150  static Point randomlySlidedAwayFromSegmentInBox(const Point & p, const Point & u, double uMagnitude, const Point & v, double vMagnitude);
151 
152 private:
153  int _repeat;
154  SketchFilling _filling;
155  double _hachureAngle;
156  double _hachureSpacing;
157  bool _automaticHachureSpacing;
158 };
159 
160 } // namespace LibBoard
161 
162 #endif /* BOARD_ROUGH_VISITOR_H */
LibBoard::RoughVisitor::slideRandomlyAwayFromSegmentInBox
static void slideRandomlyAwayFromSegmentInBox(Point &p, const Point &u, double uMagnitude, const Point &v, double vMagnitude)
Definition: RoughVisitor.cpp:362
LibBoard::RoughVisitor::randomlySlidedAwayFromSegmentInBox
static Point randomlySlidedAwayFromSegmentInBox(const Point &p, const Point &u, double uMagnitude, const Point &v, double vMagnitude)
Definition: RoughVisitor.cpp:370
Point.h
The Point structure. @copyright This source code is part of the Board project, a C++ library whose pu...
LibBoard::Polyline
A polygonal line described by a series of 2D points.
Definition: Polyline.h:38
Types.h
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
LibBoard::RoughVisitor::randomlySlidedAwayFromSegment
static Point randomlySlidedAwayFromSegment(const Point &p, const Point &a, const Point &b, const double magnitude)
Definition: RoughVisitor.cpp:339
LibBoard::Arrow
A line between two points with an arrow at one extremity.
Definition: Arrow.h:38
LibBoard::RoughVisitor::randomlySlided
static Point randomlySlided(const Point &point, const double &radius)
Definition: RoughVisitor.cpp:325
LibBoard::CompositeShapeTransform
A CompositeShapeTransform may be used to duplicate/transform a composite shape tree.
Definition: ShapeVisitor.h:103
LibBoard::RoughVisitor
Definition: RoughVisitor.h:46
LibBoard::RoughVisitor::slideRandomlyAwayFromSegment
static void slideRandomlyAwayFromSegment(Point &p, const Point &a, const Point &b, const double magnitude)
Definition: RoughVisitor.cpp:332
LibBoard::Point
Struct representing a 2D point.
Definition: Point.h:42
LibBoard::Line
A line between two points.
Definition: Line.h:38
LibBoard::Bezier
A cubice polygonal line described by a series of 2D points.
Definition: Bezier.h:40
LibBoard::Shape
Abstract structure for a 2D shape.
Definition: Shape.h:63
ShapeVisitor.h
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
LibBoard::Ellipse
An ellipse.
Definition: Ellipse.h:38
LibBoard::RoughVisitor::slideRandomly
static void slideRandomly(Point &point, const double &radius)
Definition: RoughVisitor.cpp:320