Geometrize  1.0
C++ library for geometrizing images into geometric primitives
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
Namespaces | Classes | Enumerations | Functions | Variables
geometrize Namespace Reference

Namespaces

 commonutil
 
 core
 
 exporter
 

Classes

class  Bitmap
 The Bitmap class is a helper class for working with bitmap data. More...
 
struct  rgba
 The rgba struct is a helper for manipulating RGBA8888 color data. More...
 
class  Model
 The Model class is the model for the core optimization/fitting algorithm. More...
 
class  Scanline
 The Scanline class represents a scanline, a row of pixels running across a bitmap. More...
 
class  ImageRunner
 The ImageRunner class is a helper class for creating a set of primitives from a source image. More...
 
class  ImageRunnerOptions
 The ImageRunnerOptions class encapsulates preferences/options that the image runner uses. More...
 
class  Circle
 The Circle class represents a circle. More...
 
class  Ellipse
 The Ellipse class represents an ellipse. More...
 
class  Line
 The Line class represents a simple line. More...
 
class  Polyline
 The Polyline class represents a polyline. More...
 
class  QuadraticBezier
 The QuadraticBezier class represents a quadratic bezier curve. More...
 
class  Rectangle
 The Rectangle class represents a rectangle. More...
 
class  RotatedEllipse
 The RotatedEllipse class represents a rotated ellipse. More...
 
class  RotatedRectangle
 The RotatedRectangle class represents a rotated rectangle. More...
 
class  Shape
 
class  Triangle
 The Triangle class represents a triangle. More...
 
struct  ShapeResult
 The ShapeResult struct is a container for info about a shape added to the model. More...
 
class  State
 The State class relates a shape and related properties to a measure of how close it brings the working image closer to the target image. More...
 

Enumerations

enum  ShapeTypes : std::uint32_t {
  RECTANGLE = 1U, ROTATED_RECTANGLE = 2U, TRIANGLE = 4U, ELLIPSE = 8U,
  ROTATED_ELLIPSE = 16U, CIRCLE = 32U, LINE = 64U, QUADRATIC_BEZIER = 128U,
  POLYLINE = 256U, SHAPE_COUNT = 9U
}
 The ShapeTypes enum specifies the types of shapes that can be used. These can be combined to produce images composed of multiple primitive types. More...
 

Functions

bool operator== (const geometrize::rgba &lhs, const geometrize::rgba &rhs)
 
bool operator!= (const geometrize::rgba &lhs, const geometrize::rgba &rhs)
 
std::vector< float > getRawShapeData (const geometrize::Shape &s)
 
std::vector< float > getRawShapeData (const geometrize::Circle &s)
 
std::vector< float > getRawShapeData (const geometrize::Ellipse &s)
 
std::vector< float > getRawShapeData (const geometrize::Line &s)
 
std::vector< float > getRawShapeData (const geometrize::Polyline &s)
 
std::vector< float > getRawShapeData (const geometrize::QuadraticBezier &s)
 
std::vector< float > getRawShapeData (const geometrize::Rectangle &s)
 
std::vector< float > getRawShapeData (const geometrize::RotatedEllipse &s)
 
std::vector< float > getRawShapeData (const geometrize::RotatedRectangle &s)
 
std::vector< float > getRawShapeData (const geometrize::Triangle &s)
 
std::vector< std::pair< float,
float > > 
getCornerPoints (const geometrize::RotatedRectangle &r)
 getCornerPoints Gets the corner points of the given rotated rectangle. More...
 
std::vector< std::pair< float,
float > > 
getPointsOnRotatedEllipse (const geometrize::RotatedEllipse &e, std::size_t numPoints)
 getPointsOnRotatedEllipse Calculates and returns a number of points on the given rotated ellipse. More...
 
void drawLines (geometrize::Bitmap &image, geometrize::rgba color, const std::vector< geometrize::Scanline > &lines)
 drawLines Draws scanlines onto an image. More...
 
void copyLines (geometrize::Bitmap &destination, const geometrize::Bitmap &source, const std::vector< geometrize::Scanline > &lines)
 copyLines Copies source pixels to a destination defined by a set of scanlines. More...
 
std::vector< std::pair
< std::int32_t, std::int32_t > > 
bresenham (std::int32_t x1, std::int32_t y1, std::int32_t x2, std::int32_t y2)
 bresenham Bresenham's line algorithm. Returns the points on the line. More...
 
std::vector< geometrize::ScanlinescanlinesForPolygon (const std::vector< std::pair< float, float >> &points)
 scanlinesForPolygon Gets the scanlines for a series of points that make up an arbitrary polygon. More...
 
std::vector< geometrize::Scanlinerasterize (const geometrize::Shape &s, std::int32_t xBound, std::int32_t yBound)
 
std::vector< geometrize::Scanlinerasterize (const geometrize::Circle &s, const std::int32_t xBound, const std::int32_t yBound)
 
std::vector< geometrize::Scanlinerasterize (const geometrize::Ellipse &s, const std::int32_t w, const std::int32_t h)
 
std::vector< geometrize::Scanlinerasterize (const geometrize::Line &s, const std::int32_t xBound, const std::int32_t yBound)
 
std::vector< geometrize::Scanlinerasterize (const geometrize::Polyline &s, const std::int32_t xBound, const std::int32_t yBound)
 
std::vector< geometrize::Scanlinerasterize (const geometrize::QuadraticBezier &s, const std::int32_t xBound, const std::int32_t yBound)
 
std::vector< geometrize::Scanlinerasterize (const geometrize::Rectangle &s, const std::int32_t xBound, const std::int32_t yBound)
 
std::vector< geometrize::Scanlinerasterize (const geometrize::RotatedEllipse &s, const std::int32_t xBound, const std::int32_t yBound)
 
std::vector< geometrize::Scanlinerasterize (const geometrize::RotatedRectangle &s, const std::int32_t xBound, const std::int32_t yBound)
 
std::vector< geometrize::Scanlinerasterize (const geometrize::Triangle &s, const std::int32_t xBound, const std::int32_t yBound)
 
bool scanlinesOverlap (const std::vector< geometrize::Scanline > &first, const std::vector< geometrize::Scanline > &second)
 scanlinesOverlap Returns true if any of the scanlines from the first vector overlap the second More...
 
bool scanlinesContain (const std::vector< geometrize::Scanline > &first, const std::vector< geometrize::Scanline > &second)
 scanlinesContain Returns true if the first vector of scanlines wholly contain the second vector of scanlines. More...
 
bool shapesOverlap (const geometrize::Shape &a, const geometrize::Shape &b, const std::int32_t xBound, const std::int32_t yBound)
 
bool shapeContains (const geometrize::Shape &container, const geometrize::Shape &containee, const std::int32_t xBound, const std::int32_t yBound)
 
std::vector< std::pair
< std::int32_t, std::int32_t > > 
shapeToPixels (const geometrize::Shape &shape, const std::uint32_t xBound, const std::uint32_t yBound)
 
bool operator== (const geometrize::Scanline &lhs, const geometrize::Scanline &rhs)
 
bool operator!= (const geometrize::Scanline &lhs, const geometrize::Scanline &rhs)
 
std::vector< geometrize::ScanlinetrimScanlines (const std::vector< geometrize::Scanline > &scanlines, std::uint32_t w, std::uint32_t h)
 trimScanlines Crops the scanning width of an array of scanlines so they do not scan outside of the given area. More...
 
std::function< std::shared_ptr
< geometrize::Shape >)> 
createDefaultShapeCreator (geometrize::ShapeTypes types, std::int32_t w, std::int32_t h)
 createDefaultShapeCreator Creates an instance of the default shape creator object. The setup, mutate and rasterize methods are bound with default methods. More...
 
std::shared_ptr
< geometrize::Shape
create (geometrize::ShapeTypes t)
 create Creates a new shape of the specified type. More...
 
std::shared_ptr
< geometrize::Shape
randomShape ()
 randomShape Creates a random shape. More...
 
std::shared_ptr
< geometrize::Shape
randomShapeOf (geometrize::ShapeTypes t)
 randomShapeOf Creates a random shape from the types supplied. More...
 
void setup (geometrize::Shape &s, const std::int32_t xBound, const std::int32_t yBound)
 
void setup (geometrize::Circle &s, const std::int32_t xBound, const std::int32_t yBound)
 
void setup (geometrize::Ellipse &s, const std::int32_t xBound, const std::int32_t yBound)
 
void setup (geometrize::Line &s, const std::int32_t xBound, const std::int32_t yBound)
 
void setup (geometrize::Polyline &s, const std::int32_t xBound, const std::int32_t yBound)
 
void setup (geometrize::QuadraticBezier &s, const std::int32_t xBound, const std::int32_t yBound)
 
void setup (geometrize::Rectangle &s, const std::int32_t xBound, const std::int32_t yBound)
 
void setup (geometrize::RotatedEllipse &s, const std::int32_t xBound, const std::int32_t yBound)
 
void setup (geometrize::RotatedRectangle &s, const std::int32_t xBound, const std::int32_t yBound)
 
void setup (geometrize::Triangle &s, const std::int32_t xBound, const std::int32_t yBound)
 
void mutate (geometrize::Shape &s, const std::int32_t xBound, const std::int32_t yBound)
 
void mutate (geometrize::Circle &s, const std::int32_t xBound, const std::int32_t yBound)
 
void mutate (geometrize::Ellipse &s, const std::int32_t xBound, const std::int32_t yBound)
 
void mutate (geometrize::Line &s, const std::int32_t xBound, const std::int32_t yBound)
 
void mutate (geometrize::Polyline &s, const std::int32_t xBound, const std::int32_t yBound)
 
void mutate (geometrize::QuadraticBezier &s, const std::int32_t xBound, const std::int32_t yBound)
 
void mutate (geometrize::Rectangle &s, const std::int32_t xBound, const std::int32_t yBound)
 
void mutate (geometrize::RotatedEllipse &s, const std::int32_t xBound, const std::int32_t yBound)
 
void mutate (geometrize::RotatedRectangle &s, const std::int32_t xBound, const std::int32_t yBound)
 
void mutate (geometrize::Triangle &s, const std::int32_t xBound, const std::int32_t yBound)
 
void translate (geometrize::Shape &s, const float x, const float y)
 
void translate (geometrize::Circle &s, const float x, const float y)
 
void translate (geometrize::Ellipse &s, const float x, const float y)
 
void translate (geometrize::Line &s, const float x, const float y)
 
void translate (geometrize::Polyline &s, const float x, const float y)
 
void translate (geometrize::QuadraticBezier &s, const float x, const float y)
 
void translate (geometrize::Rectangle &s, const float x, const float y)
 
void translate (geometrize::RotatedEllipse &s, const float x, const float y)
 
void translate (geometrize::RotatedRectangle &s, const float x, const float y)
 
void translate (geometrize::Triangle &s, const float x, const float y)
 
void scale (geometrize::Shape &s, const float scaleFactor)
 
void scale (geometrize::Circle &s, const float scaleFactor)
 
void scale (geometrize::Ellipse &s, const float scaleFactor)
 
void scale (geometrize::Line &s, const float scaleFactor)
 
void scale (geometrize::Polyline &s, const float scaleFactor)
 
void scale (geometrize::QuadraticBezier &s, const float scaleFactor)
 
void scale (geometrize::Rectangle &s, const float scaleFactor)
 
void scale (geometrize::RotatedEllipse &s, const float scaleFactor)
 
void scale (geometrize::RotatedRectangle &s, const float scaleFactor)
 
void scale (geometrize::Triangle &s, const float scaleFactor)
 
void rotate (geometrize::Shape &s, const float angle)
 
void rotate (geometrize::Line &s, const float angle)
 
void rotate (geometrize::RotatedEllipse &s, const float angle)
 
void rotate (geometrize::RotatedRectangle &s, const float angle)
 
void rotate (geometrize::Triangle &s, const float angle)
 

Variables

const std::array< ShapeTypes,
static_cast< std::size_t >
ShapeTypes::SHAPE_COUNT)> 
allShapes
 allShapes is a convenient array of all of the members of ShapeTypes. More...
 
const std::vector< std::pair
< ShapeTypes, std::string > > 
shapeTypeNames
 shapeTypeNames provides a convenient mapping to names of types of shape (all lower case, underscores instead of spaces e.g. rotated_ellipse). More...
 

Enumeration Type Documentation

enum geometrize::ShapeTypes : std::uint32_t

The ShapeTypes enum specifies the types of shapes that can be used. These can be combined to produce images composed of multiple primitive types.

Author
Sam Twidale (https://samcodes.co.uk/)
Enumerator
RECTANGLE 
ROTATED_RECTANGLE 
TRIANGLE 
ELLIPSE 
ROTATED_ELLIPSE 
CIRCLE 
LINE 
QUADRATIC_BEZIER 
POLYLINE 
SHAPE_COUNT 
16  : std::uint32_t
17 {
18  RECTANGLE = 1U,
19  ROTATED_RECTANGLE = 2U,
20  TRIANGLE = 4U,
21  ELLIPSE = 8U,
22  ROTATED_ELLIPSE = 16U,
23  CIRCLE = 32U,
24  LINE = 64U,
25  QUADRATIC_BEZIER = 128U,
26  POLYLINE = 256U,
27  SHAPE_COUNT = 9U
28 };
Definition: shapetypes.h:26
Definition: shapetypes.h:21
Definition: shapetypes.h:25
Definition: shapetypes.h:24
Definition: shapetypes.h:27
Definition: shapetypes.h:19
Definition: shapetypes.h:23
Definition: shapetypes.h:18
Definition: shapetypes.h:20
Definition: shapetypes.h:22

Function Documentation

std::vector< std::pair< std::int32_t, std::int32_t > > geometrize::bresenham ( std::int32_t  x1,
std::int32_t  y1,
std::int32_t  x2,
std::int32_t  y2 
)

bresenham Bresenham's line algorithm. Returns the points on the line.

Parameters
x1The start x-coordinate.
y1The start y-coordinate.
x2The end x-coordinate.
y2The end y-coordinate.
Returns
The points on the resulting line.
123 {
124  std::int32_t dx{x2 - x1};
125  const std::int8_t ix{static_cast<std::int8_t>((dx > 0) - (dx < 0))};
126  dx = std::abs(dx) << 1;
127 
128  std::int32_t dy{y2 - y1};
129  const std::int8_t iy{static_cast<std::int8_t>((dy > 0) - (dy < 0))};
130  dy = std::abs(dy) << 1;
131 
132  std::vector<std::pair<std::int32_t, std::int32_t>> points;
133  points.push_back(std::make_pair(x1, y1));
134 
135  if (dx >= dy) {
136  std::int32_t error(dy - (dx >> 1));
137  while (x1 != x2) {
138  if (error >= 0 && (error || (ix > 0))) {
139  error -= dx;
140  y1 += iy;
141  }
142 
143  error += dy;
144  x1 += ix;
145 
146  points.push_back(std::make_pair(x1, y1));
147  }
148  } else {
149  std::int32_t error(dx - (dy >> 1));
150  while (y1 != y2) {
151  if (error >= 0 && (error || (iy > 0))) {
152  error -= dy;
153  x1 += ix;
154  }
155 
156  error += dx;
157  y1 += iy;
158 
159  points.push_back(std::make_pair(x1, y1));
160  }
161  }
162 
163  return points;
164 }

Here is the caller graph for this function:

void geometrize::copyLines ( geometrize::Bitmap destination,
const geometrize::Bitmap source,
const std::vector< geometrize::Scanline > &  lines 
)

copyLines Copies source pixels to a destination defined by a set of scanlines.

Parameters
destinationThe destination bitmap to copy the lines to.
sourceThe source bitmap to copy the lines from.
linesThe scanlines that comprise the source to destination copying mask.
113 {
114  for(const geometrize::Scanline& line : lines) {
115  const std::int32_t y{line.y};
116  for(std::int32_t x = line.x1; x < line.x2; x++) {
117  destination.setPixel(x, y, source.getPixel(x, y));
118  }
119  }
120 }
The Scanline class represents a scanline, a row of pixels running across a bitmap.
Definition: scanline.h:13
void setPixel(std::uint32_t x, std::uint32_t y, geometrize::rgba color)
setPixel Sets a pixel color value.
Definition: bitmap.cpp:46
geometrize::rgba getPixel(std::uint32_t x, std::uint32_t y) const
getPixel Gets a pixel color value.
Definition: bitmap.cpp:40

Here is the call graph for this function:

Here is the caller graph for this function:

std::shared_ptr< geometrize::Shape > geometrize::create ( geometrize::ShapeTypes  t)

create Creates a new shape of the specified type.

Parameters
tThe type of shape to create.
Returns
The new shape.
96 {
97  switch(t) {
99  return std::make_shared<geometrize::Polyline>();
101  return std::make_shared<geometrize::QuadraticBezier>();
103  return std::make_shared<geometrize::Circle>();
105  return std::make_shared<geometrize::Ellipse>();
107  return std::make_shared<geometrize::RotatedEllipse>();
109  return std::make_shared<geometrize::RotatedRectangle>();
111  return std::make_shared<geometrize::Triangle>();
113  return std::make_shared<geometrize::Rectangle>();
115  return std::make_shared<geometrize::Line>();
116  default:
117  assert(0 && "Bad shape type specified");
118  };
119 
120  assert(0 && "Unhandled shape type encountered");
121  return std::make_shared<geometrize::Rectangle>();
122 }
Definition: shapetypes.h:26
Definition: shapetypes.h:21
Definition: shapetypes.h:25
Definition: shapetypes.h:24
Definition: shapetypes.h:19
Definition: shapetypes.h:23
Definition: shapetypes.h:18
Definition: shapetypes.h:20
Definition: shapetypes.h:22

Here is the caller graph for this function:

std::function< std::shared_ptr< geometrize::Shape >)> geometrize::createDefaultShapeCreator ( geometrize::ShapeTypes  types,
std::int32_t  w,
std::int32_t  h 
)

createDefaultShapeCreator Creates an instance of the default shape creator object. The setup, mutate and rasterize methods are bound with default methods.

Parameters
typesThe types of shapes to create.
wThe max width of the shapes.
hThe max height of the shapes.
Returns
The default shape creator.
26 {
27  auto f = [types, w, h]() {
28  std::shared_ptr<geometrize::Shape> s = geometrize::randomShapeOf(types);
29 
30  switch(s->getType()) {
32  s->setup = [w, h](geometrize::Shape& s) { return geometrize::setup(static_cast<geometrize::Rectangle&>(s), w, h); };
33  s->mutate = [w, h](geometrize::Shape& s) { geometrize::mutate(static_cast<geometrize::Rectangle&>(s), w, h); };
34  s->rasterize = [w, h](const geometrize::Shape& s) { return geometrize::rasterize(static_cast<const geometrize::Rectangle&>(s), w, h); };
35  break;
36  }
38  s->setup = [w, h](geometrize::Shape& s) { return geometrize::setup(static_cast<geometrize::RotatedRectangle&>(s), w, h); };
39  s->mutate = [w, h](geometrize::Shape& s) { geometrize::mutate(static_cast<geometrize::RotatedRectangle&>(s), w, h); };
40  s->rasterize = [w, h](const geometrize::Shape& s) { return geometrize::rasterize(static_cast<const geometrize::RotatedRectangle&>(s), w, h); };
41  break;
42  }
44  s->setup = [w, h](geometrize::Shape& s) { return geometrize::setup(static_cast<geometrize::Triangle&>(s), w, h); };
45  s->mutate = [w, h](geometrize::Shape& s) { geometrize::mutate(static_cast<geometrize::Triangle&>(s), w, h); };
46  s->rasterize = [w, h](const geometrize::Shape& s) { return geometrize::rasterize(static_cast<const geometrize::Triangle&>(s), w, h); };
47  break;
48  }
50  s->setup = [w, h](geometrize::Shape& s) { return geometrize::setup(static_cast<geometrize::Ellipse&>(s), w, h); };
51  s->mutate = [w, h](geometrize::Shape& s) { geometrize::mutate(static_cast<geometrize::Ellipse&>(s), w, h); };
52  s->rasterize = [w, h](const geometrize::Shape& s) { return geometrize::rasterize(static_cast<const geometrize::Ellipse&>(s), w, h); };
53  break;
54  }
56  s->setup = [w, h](geometrize::Shape& s) { return geometrize::setup(static_cast<geometrize::RotatedEllipse&>(s), w, h); };
57  s->mutate = [w, h](geometrize::Shape& s) { geometrize::mutate(static_cast<geometrize::RotatedEllipse&>(s), w, h); };
58  s->rasterize = [w, h](const geometrize::Shape& s) { return geometrize::rasterize(static_cast<const geometrize::RotatedEllipse&>(s), w, h); };
59  break;
60  }
62  s->setup = [w, h](geometrize::Shape& s) { return geometrize::setup(static_cast<geometrize::Circle&>(s), w, h); };
63  s->mutate = [w, h](geometrize::Shape& s) { geometrize::mutate(static_cast<geometrize::Circle&>(s), w, h); };
64  s->rasterize = [w, h](const geometrize::Shape& s) { return geometrize::rasterize(static_cast<const geometrize::Circle&>(s), w, h); };
65  break;
66  }
68  s->setup = [w, h](geometrize::Shape& s) { return geometrize::setup(static_cast<geometrize::Line&>(s), w, h); };
69  s->mutate = [w, h](geometrize::Shape& s) { geometrize::mutate(static_cast<geometrize::Line&>(s), w, h); };
70  s->rasterize = [w, h](const geometrize::Shape& s) { return geometrize::rasterize(static_cast<const geometrize::Line&>(s), w, h); };
71  break;
72  }
74  s->setup = [w, h](geometrize::Shape& s) { return geometrize::setup(static_cast<geometrize::QuadraticBezier&>(s), w, h); };
75  s->mutate = [w, h](geometrize::Shape& s) { geometrize::mutate(static_cast<geometrize::QuadraticBezier&>(s), w, h); };
76  s->rasterize = [w, h](const geometrize::Shape& s) { return geometrize::rasterize(static_cast<const geometrize::QuadraticBezier&>(s), w, h); };
77  break;
78  }
80  s->setup = [w, h](geometrize::Shape& s) { return geometrize::setup(static_cast<geometrize::Polyline&>(s), w, h); };
81  s->mutate = [w, h](geometrize::Shape& s) { geometrize::mutate(static_cast<geometrize::Polyline&>(s), w, h); };
82  s->rasterize = [w, h](const geometrize::Shape& s) { return geometrize::rasterize(static_cast<const geometrize::Polyline&>(s), w, h); };
83  break;
84  }
85  default:
86  assert(0 && "Bad shape type");
87  }
88 
89  return s;
90  };
91 
92  return f;
93 }
std::vector< geometrize::Scanline > rasterize(const geometrize::Shape &s, std::int32_t xBound, std::int32_t yBound)
Definition: rasterizer.cpp:194
Definition: shapetypes.h:26
std::shared_ptr< geometrize::Shape > randomShapeOf(const ShapeTypes types)
randomShapeOf Creates a random shape from the types supplied.
Definition: shapefactory.cpp:129
Definition: shapetypes.h:21
Definition: shapetypes.h:25
void setup(geometrize::Shape &s, const std::int32_t xBound, const std::int32_t yBound)
Definition: shapemutator.cpp:37
Definition: shapetypes.h:24
void mutate(geometrize::Shape &s, const std::int32_t xBound, const std::int32_t yBound)
Definition: shapemutator.cpp:155
Definition: shapetypes.h:19
Definition: shapetypes.h:23
Definition: shapetypes.h:18
Definition: shapetypes.h:20
Definition: shapetypes.h:22
Definition: shape.h:17

Here is the call graph for this function:

Here is the caller graph for this function:

void geometrize::drawLines ( geometrize::Bitmap image,
geometrize::rgba  color,
const std::vector< geometrize::Scanline > &  lines 
)

drawLines Draws scanlines onto an image.

Parameters
imageThe image to be drawn to.
colorThe color of the scanlines.
linesThe scanlines to draw.
75 {
76  // Convert the non-premultiplied color to alpha-premultiplied 16-bits per channel RGBA
77  // In other words, scale the rgb color components by the alpha component
78  std::uint32_t sr{color.r};
79  sr |= sr << 8;
80  sr *= color.a;
81  sr /= UINT8_MAX;
82  std::uint32_t sg{color.g};
83  sg |= sg << 8;
84  sg *= color.a;
85  sg /= UINT8_MAX;
86  std::uint32_t sb{color.b};
87  sb |= sb << 8;
88  sb *= color.a;
89  sb /= UINT8_MAX;
90  std::uint32_t sa{color.a};
91  sa |= sa << 8;
92 
93  const std::uint32_t m{UINT16_MAX};
94  const std::uint32_t aa{(m - sa) * 257U};
95 
96  for(const geometrize::Scanline& line : lines) {
97  const std::int32_t y{line.y};
98 
99  for(std::int32_t x = line.x1; x <= line.x2; x++) {
100  const geometrize::rgba d(image.getPixel(x, y));
101 
102  const std::uint8_t r{static_cast<std::uint8_t>(((d.r * aa + sr * m) / m) >> 8)};
103  const std::uint8_t g{static_cast<std::uint8_t>(((d.g * aa + sg * m) / m) >> 8)};
104  const std::uint8_t b{static_cast<std::uint8_t>(((d.b * aa + sb * m) / m) >> 8)};
105  const std::uint8_t a{static_cast<std::uint8_t>(((d.a * aa + sa * m) / m) >> 8)};
106 
107  image.setPixel(x, y, geometrize::rgba{r, g, b, a});
108  }
109  }
110 }
The Scanline class represents a scanline, a row of pixels running across a bitmap.
Definition: scanline.h:13
std::uint8_t a
The blue component (0-255).
Definition: rgba.h:17
std::uint8_t g
The red component (0-255).
Definition: rgba.h:15
void setPixel(std::uint32_t x, std::uint32_t y, geometrize::rgba color)
setPixel Sets a pixel color value.
Definition: bitmap.cpp:46
geometrize::rgba getPixel(std::uint32_t x, std::uint32_t y) const
getPixel Gets a pixel color value.
Definition: bitmap.cpp:40
std::uint8_t b
The green component (0-255).
Definition: rgba.h:16
std::uint8_t r
Definition: rgba.h:14
The rgba struct is a helper for manipulating RGBA8888 color data.
Definition: rgba.h:12

Here is the call graph for this function:

Here is the caller graph for this function:

std::vector< std::pair< float, float > > geometrize::getCornerPoints ( const geometrize::RotatedRectangle r)

getCornerPoints Gets the corner points of the given rotated rectangle.

Parameters
rThe rotated rectangle.
Returns
The corner points of the rotated rectangle.
31 {
32  const float x1{(std::fmin)(r.m_x1, r.m_x2)};
33  const float x2{(std::fmax)(r.m_x1, r.m_x2)};
34  const float y1{(std::fmin)(r.m_y1, r.m_y2)};
35  const float y2{(std::fmax)(r.m_y1, r.m_y2)};
36 
37  const float cx{(x2 + x1) / 2.0f};
38  const float cy{(y2 + y1) / 2.0f};
39 
40  const float ox1{x1 - cx};
41  const float ox2{x2 - cx};
42  const float oy1{y1 - cy};
43  const float oy2{y2 - cy};
44 
45  const float rads{r.m_angle * 3.141f / 180.0f};
46  const float c{std::cos(rads)};
47  const float s{std::sin(rads)};
48 
49  const std::pair<float, float> ul{ox1 * c - oy1 * s + cx, ox1 * s + oy1 * c + cy};
50  const std::pair<float, float> bl{ox1 * c - oy2 * s + cx, ox1 * s + oy2 * c + cy};
51  const std::pair<float, float> ur{ox2 * c - oy1 * s + cx, ox2 * s + oy1 * c + cy};
52  const std::pair<float, float> br{ox2 * c - oy2 * s + cx, ox2 * s + oy2 * c + cy};
53 
54  return {ul, ur, br, bl};
55 }
float m_y2
Bottom coordinate.
Definition: rotatedrectangle.h:27
float m_x2
Right coordinate.
Definition: rotatedrectangle.h:26
float m_x1
Left coordinate.
Definition: rotatedrectangle.h:24
float m_y1
Top coordinate.
Definition: rotatedrectangle.h:25
float m_angle
Rotation angle.
Definition: rotatedrectangle.h:28

Here is the caller graph for this function:

std::vector< std::pair< float, float > > geometrize::getPointsOnRotatedEllipse ( const geometrize::RotatedEllipse e,
std::size_t  numPoints 
)

getPointsOnRotatedEllipse Calculates and returns a number of points on the given rotated ellipse.

Parameters
eThe rotated ellipse.
Returns
A vector containing the points on the rotated ellipse.
58 {
59  std::vector<std::pair<float, float>> points;
60  const float rads{e.m_angle * (3.141f / 180.0f)};
61  const float co{std::cos(rads)};
62  const float si{std::sin(rads)};
63 
64  for(std::uint32_t i = 0; i < numPoints; i++) {
65  const float angle{((360.0f / numPoints) * i) * (3.141f / 180.0f)};
66  const float crx{e.m_rx * std::cos(angle)};
67  const float cry{e.m_ry * std::sin(angle)};
68  points.push_back(std::make_pair(crx * co - cry * si + e.m_x, crx * si + cry * co + e.m_y));
69  }
70 
71  return points;
72 }
float m_y
y-coordinate.
Definition: rotatedellipse.h:25
float m_angle
Rotation angle.
Definition: rotatedellipse.h:28
float m_ry
y-radius.
Definition: rotatedellipse.h:27
float m_x
x-coordinate.
Definition: rotatedellipse.h:24
float m_rx
x-radius.
Definition: rotatedellipse.h:26

Here is the caller graph for this function:

std::vector< float > geometrize::getRawShapeData ( const geometrize::Shape s)
22 {
23  switch(s.getType()) {
25  return getRawShapeData(static_cast<const geometrize::Rectangle&>(s));
27  return getRawShapeData(static_cast<const geometrize::RotatedRectangle&>(s));
29  return getRawShapeData(static_cast<const geometrize::Triangle&>(s));
31  return getRawShapeData(static_cast<const geometrize::Ellipse&>(s));
33  return getRawShapeData(static_cast<const geometrize::RotatedEllipse&>(s));
35  return getRawShapeData(static_cast<const geometrize::Circle&>(s));
37  return getRawShapeData(static_cast<const geometrize::Line&>(s));
39  return getRawShapeData(static_cast<const geometrize::QuadraticBezier&>(s));
41  return getRawShapeData(static_cast<const geometrize::Polyline&>(s));
42  default:
43  assert(0 && "Bad shape type");
44  return {};
45  }
46 }
std::vector< float > getRawShapeData(const geometrize::Triangle &s)
Definition: shapeserializer.cpp:105
Definition: shapetypes.h:26
Definition: shapetypes.h:21
Definition: shapetypes.h:25
Definition: shapetypes.h:24
Definition: shapetypes.h:19
Definition: shapetypes.h:23
Definition: shapetypes.h:18
Definition: shapetypes.h:20
Definition: shapetypes.h:22
virtual geometrize::ShapeTypes getType() const
getType Gets the ShapeType of the shape.
Definition: shape.h:42

Here is the call graph for this function:

Here is the caller graph for this function:

std::vector< float > geometrize::getRawShapeData ( const geometrize::Circle s)
49 {
50  return { s.m_x, s.m_y, s.m_r };
51 }
float m_x
x-coordinate.
Definition: circle.h:24
float m_r
Radius.
Definition: circle.h:26
float m_y
y-coordinate.
Definition: circle.h:25
std::vector< float > geometrize::getRawShapeData ( const geometrize::Ellipse s)
54 {
55  return { s.m_x, s.m_y, s.m_rx, s.m_ry };
56 }
float m_x
x-coordinate.
Definition: ellipse.h:24
float m_ry
y-radius.
Definition: ellipse.h:27
float m_rx
x-radius.
Definition: ellipse.h:26
float m_y
y-coordinate.
Definition: ellipse.h:25
std::vector< float > geometrize::getRawShapeData ( const geometrize::Line s)
59 {
60  return { s.m_x1, s.m_y1, s.m_x2, s.m_y2 };
61 }
float m_y2
Second y-coordinate.
Definition: line.h:27
float m_y1
First y-coordinate.
Definition: line.h:25
float m_x1
First x-coordinate.
Definition: line.h:24
float m_x2
Second x-coordinate.
Definition: line.h:26
std::vector< float > geometrize::getRawShapeData ( const geometrize::Polyline s)
64 {
65  std::vector<float> data;
66  for(std::size_t i = 0; i < s.m_points.size(); i++) {
67  data.push_back(s.m_points[i].first);
68  data.push_back(s.m_points[i].second);
69  }
70 
71  return data;
72 }
std::vector< std::pair< float, float > > m_points
The points on the polyline.
Definition: polyline.h:26
std::vector< float > geometrize::getRawShapeData ( const geometrize::QuadraticBezier s)
75 {
76  return { s.m_x1, s.m_y1, s.m_cx, s.m_cy, s.m_x2, s.m_y2 };
77 }
float m_x1
First x-coordinate.
Definition: quadraticbezier.h:26
float m_x2
Second x-coordinate.
Definition: quadraticbezier.h:28
float m_y1
First y-coordinate.
Definition: quadraticbezier.h:27
float m_cx
Control point x-coordinate.
Definition: quadraticbezier.h:24
float m_y2
Second y-coordinate.
Definition: quadraticbezier.h:29
float m_cy
Control point y-coordinate.
Definition: quadraticbezier.h:25
std::vector< float > geometrize::getRawShapeData ( const geometrize::Rectangle s)
80 {
81  return {
82  ((std::fmin)(s.m_x1, s.m_x2)),
83  ((std::fmin)(s.m_y1, s.m_y2)),
84  ((std::fmax)(s.m_x1, s.m_x2)),
85  ((std::fmax)(s.m_y1, s.m_y2))
86  };
87 }
float m_x1
Left coordinate.
Definition: rectangle.h:24
float m_y2
Bottom coordinate.
Definition: rectangle.h:27
float m_y1
Top coordinate.
Definition: rectangle.h:25
float m_x2
Right coordinate.
Definition: rectangle.h:26
std::vector< float > geometrize::getRawShapeData ( const geometrize::RotatedEllipse s)
90 {
91  return { s.m_x, s.m_y, s.m_rx, s.m_ry, s.m_angle };
92 }
float m_y
y-coordinate.
Definition: rotatedellipse.h:25
float m_angle
Rotation angle.
Definition: rotatedellipse.h:28
float m_ry
y-radius.
Definition: rotatedellipse.h:27
float m_x
x-coordinate.
Definition: rotatedellipse.h:24
float m_rx
x-radius.
Definition: rotatedellipse.h:26
std::vector< float > geometrize::getRawShapeData ( const geometrize::RotatedRectangle s)
95 {
96  return {
97  ((std::fmin)(s.m_x1, s.m_x2)),
98  ((std::fmin)(s.m_y1, s.m_y2)),
99  ((std::fmax)(s.m_x1, s.m_x2)),
100  ((std::fmax)(s.m_y1, s.m_y2)),
101  s.m_angle
102  };
103 }
float m_y2
Bottom coordinate.
Definition: rotatedrectangle.h:27
float m_x2
Right coordinate.
Definition: rotatedrectangle.h:26
float m_x1
Left coordinate.
Definition: rotatedrectangle.h:24
float m_y1
Top coordinate.
Definition: rotatedrectangle.h:25
float m_angle
Rotation angle.
Definition: rotatedrectangle.h:28
std::vector< float > geometrize::getRawShapeData ( const geometrize::Triangle s)
106 {
107  return { s.m_x1, s.m_y1, s.m_x2, s.m_y2, s.m_x3, s.m_y3 };
108 }
float m_y2
Second y-coordinate.
Definition: triangle.h:27
float m_x3
Third x-coordinate.
Definition: triangle.h:28
float m_y1
First y-coordinate.
Definition: triangle.h:25
float m_x2
Second x-coordinate.
Definition: triangle.h:26
float m_x1
First x-coordinate.
Definition: triangle.h:24
float m_y3
Third y-coordinate.
Definition: triangle.h:29
void geometrize::mutate ( geometrize::Shape s,
const std::int32_t  xBound,
const std::int32_t  yBound 
)
156 {
157  switch(s.getType()) {
159  mutate(static_cast<geometrize::Rectangle&>(s), xBound, yBound);
160  break;
162  mutate(static_cast<geometrize::RotatedRectangle&>(s), xBound, yBound);
163  break;
165  mutate(static_cast<geometrize::Triangle&>(s), xBound, yBound);
166  break;
168  mutate(static_cast<geometrize::Ellipse&>(s), xBound, yBound);
169  break;
171  mutate(static_cast<geometrize::RotatedEllipse&>(s), xBound, yBound);
172  break;
174  mutate(static_cast<geometrize::Circle&>(s), xBound, yBound);
175  break;
177  mutate(static_cast<geometrize::Line&>(s), xBound, yBound);
178  break;
180  mutate(static_cast<geometrize::QuadraticBezier&>(s), xBound, yBound);
181  break;
183  mutate(static_cast<geometrize::Polyline&>(s), xBound, yBound);
184  break;
185  default:
186  assert(0 && "Bad shape type");
187  }
188 }
Definition: shapetypes.h:26
Definition: shapetypes.h:21
Definition: shapetypes.h:25
Definition: shapetypes.h:24
Definition: shapetypes.h:19
Definition: shapetypes.h:23
Definition: shapetypes.h:18
Definition: shapetypes.h:20
Definition: shapetypes.h:22
void mutate(geometrize::Triangle &s, const std::int32_t xBound, const std::int32_t yBound)
Definition: shapemutator.cpp:358
virtual geometrize::ShapeTypes getType() const
getType Gets the ShapeType of the shape.
Definition: shape.h:42

Here is the call graph for this function:

Here is the caller graph for this function:

void geometrize::mutate ( geometrize::Circle s,
const std::int32_t  xBound,
const std::int32_t  yBound 
)
191 {
192  const std::int32_t r{geometrize::commonutil::randomRange(0, 1)};
193  switch(r) {
194  case 0:
195  {
196  s.m_x = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_x) + geometrize::commonutil::randomRange(-16, 16), 0, xBound - 1);
197  s.m_y = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_y) + geometrize::commonutil::randomRange(-16, 16), 0, yBound - 1);
198  break;
199  }
200  case 1:
201  {
202  s.m_r = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_r) + geometrize::commonutil::randomRange(-16, 16), 1, xBound - 1);
203  break;
204  }
205  }
206 }
T clamp(const T &value, const T &lower, const T &upper)
clamp Clamps a value within a range.
Definition: commonutil.h:41
std::int32_t randomRange(const std::int32_t min, const std::int32_t max)
randomRange Returns a random integer in the range, inclusive. Uses thread-local random number generat...
Definition: commonutil.cpp:24
float m_x
x-coordinate.
Definition: circle.h:24
float m_r
Radius.
Definition: circle.h:26
float m_y
y-coordinate.
Definition: circle.h:25

Here is the call graph for this function:

void geometrize::mutate ( geometrize::Ellipse s,
const std::int32_t  xBound,
const std::int32_t  yBound 
)
209 {
210  const std::int32_t r{geometrize::commonutil::randomRange(0, 2)};
211  switch(r) {
212  case 0:
213  {
214  s.m_x = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_x) + geometrize::commonutil::randomRange(-16, 16), 0, xBound - 1);
215  s.m_y = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_y) + geometrize::commonutil::randomRange(-16, 16), 0, yBound - 1);
216  break;
217  }
218  case 1:
219  {
220  s.m_rx = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_rx) + geometrize::commonutil::randomRange(-16, 16), 1, xBound - 1);
221  break;
222  }
223  case 2:
224  {
225  s.m_ry = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_ry) + geometrize::commonutil::randomRange(-16, 16), 1, yBound - 1);
226  break;
227  }
228  }
229 }
T clamp(const T &value, const T &lower, const T &upper)
clamp Clamps a value within a range.
Definition: commonutil.h:41
float m_x
x-coordinate.
Definition: ellipse.h:24
std::int32_t randomRange(const std::int32_t min, const std::int32_t max)
randomRange Returns a random integer in the range, inclusive. Uses thread-local random number generat...
Definition: commonutil.cpp:24
float m_ry
y-radius.
Definition: ellipse.h:27
float m_rx
x-radius.
Definition: ellipse.h:26
float m_y
y-coordinate.
Definition: ellipse.h:25

Here is the call graph for this function:

void geometrize::mutate ( geometrize::Line s,
const std::int32_t  xBound,
const std::int32_t  yBound 
)
232 {
233  const std::int32_t r{geometrize::commonutil::randomRange(0, 1)};
234 
235  switch(r) {
236  case 0:
237  {
238  s.m_x1 = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_x1) + geometrize::commonutil::randomRange(-16, 16), 0, xBound - 1);
239  s.m_y1 = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_y1) + geometrize::commonutil::randomRange(-16, 16), 0, yBound - 1);
240  break;
241  }
242  case 1:
243  {
244  s.m_x2 = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_x2) + geometrize::commonutil::randomRange(-16, 16), 0, xBound - 1);
245  s.m_y2 = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_y2) + geometrize::commonutil::randomRange(-16, 16), 0, yBound - 1);
246  break;
247  }
248  }
249 }
T clamp(const T &value, const T &lower, const T &upper)
clamp Clamps a value within a range.
Definition: commonutil.h:41
float m_y2
Second y-coordinate.
Definition: line.h:27
std::int32_t randomRange(const std::int32_t min, const std::int32_t max)
randomRange Returns a random integer in the range, inclusive. Uses thread-local random number generat...
Definition: commonutil.cpp:24
float m_y1
First y-coordinate.
Definition: line.h:25
float m_x1
First x-coordinate.
Definition: line.h:24
float m_x2
Second x-coordinate.
Definition: line.h:26

Here is the call graph for this function:

void geometrize::mutate ( geometrize::Polyline s,
const std::int32_t  xBound,
const std::int32_t  yBound 
)
252 {
253  const std::int32_t i{geometrize::commonutil::randomRange(static_cast<std::size_t>(0), s.m_points.size() - 1)};
254 
255  std::pair<std::int32_t, std::int32_t> point{s.m_points[i]};
256  point.first = geometrize::commonutil::clamp(point.first + geometrize::commonutil::randomRange(-64, 64), 0, xBound - 1);
257  point.second = geometrize::commonutil::clamp(point.second + geometrize::commonutil::randomRange(-64, 64), 0, yBound - 1);
258 
259  s.m_points[i] = point;
260 }
std::vector< std::pair< float, float > > m_points
The points on the polyline.
Definition: polyline.h:26
T clamp(const T &value, const T &lower, const T &upper)
clamp Clamps a value within a range.
Definition: commonutil.h:41
std::int32_t randomRange(const std::int32_t min, const std::int32_t max)
randomRange Returns a random integer in the range, inclusive. Uses thread-local random number generat...
Definition: commonutil.cpp:24

Here is the call graph for this function:

void geometrize::mutate ( geometrize::QuadraticBezier s,
const std::int32_t  xBound,
const std::int32_t  yBound 
)
263 {
264  const std::int32_t r{geometrize::commonutil::randomRange(0, 2)};
265  switch(r) {
266  case 0:
267  {
268  s.m_cx = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_cx) + geometrize::commonutil::randomRange(-8, 8), 0, xBound - 1);
269  s.m_cy = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_cy) + geometrize::commonutil::randomRange(-8, 8), 0, yBound - 1);
270  break;
271  }
272  case 1:
273  {
274  s.m_x1 = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_x1) + geometrize::commonutil::randomRange(-8, 8), 1, xBound - 1);
275  s.m_y1 = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_y1) + geometrize::commonutil::randomRange(-8, 8), 1, yBound - 1);
276  break;
277  }
278  case 2:
279  {
280  s.m_x2 = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_x2) + geometrize::commonutil::randomRange(-8, 8), 1, xBound - 1);
281  s.m_y2 = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_y2) + geometrize::commonutil::randomRange(-8, 8), 1, yBound - 1);
282  break;
283  }
284  }
285 }
float m_x1
First x-coordinate.
Definition: quadraticbezier.h:26
float m_x2
Second x-coordinate.
Definition: quadraticbezier.h:28
float m_y1
First y-coordinate.
Definition: quadraticbezier.h:27
T clamp(const T &value, const T &lower, const T &upper)
clamp Clamps a value within a range.
Definition: commonutil.h:41
float m_cx
Control point x-coordinate.
Definition: quadraticbezier.h:24
std::int32_t randomRange(const std::int32_t min, const std::int32_t max)
randomRange Returns a random integer in the range, inclusive. Uses thread-local random number generat...
Definition: commonutil.cpp:24
float m_y2
Second y-coordinate.
Definition: quadraticbezier.h:29
float m_cy
Control point y-coordinate.
Definition: quadraticbezier.h:25

Here is the call graph for this function:

void geometrize::mutate ( geometrize::Rectangle s,
const std::int32_t  xBound,
const std::int32_t  yBound 
)
288 {
289  const std::int32_t r{geometrize::commonutil::randomRange(0, 1)};
290  switch(r) {
291  case 0:
292  {
293  s.m_x1 = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_x1) + geometrize::commonutil::randomRange(-16, 16), 0, xBound - 1);
294  s.m_y1 = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_y1) + geometrize::commonutil::randomRange(-16, 16), 0, yBound - 1);
295  break;
296  }
297  case 1:
298  {
299  s.m_x2 = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_x2) + geometrize::commonutil::randomRange(-16, 16), 0, xBound - 1);
300  s.m_y2 = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_y2) + geometrize::commonutil::randomRange(-16, 16), 0, yBound - 1);
301  break;
302  }
303  }
304 }
float m_x1
Left coordinate.
Definition: rectangle.h:24
T clamp(const T &value, const T &lower, const T &upper)
clamp Clamps a value within a range.
Definition: commonutil.h:41
float m_y2
Bottom coordinate.
Definition: rectangle.h:27
std::int32_t randomRange(const std::int32_t min, const std::int32_t max)
randomRange Returns a random integer in the range, inclusive. Uses thread-local random number generat...
Definition: commonutil.cpp:24
float m_y1
Top coordinate.
Definition: rectangle.h:25
float m_x2
Right coordinate.
Definition: rectangle.h:26

Here is the call graph for this function:

void geometrize::mutate ( geometrize::RotatedEllipse s,
const std::int32_t  xBound,
const std::int32_t  yBound 
)
307 {
308  const std::int32_t r{geometrize::commonutil::randomRange(0, 3)};
309  switch(r) {
310  case 0:
311  {
312  s.m_x = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_x) + geometrize::commonutil::randomRange(-16, 16), 0, xBound - 1);
313  s.m_y = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_y) + geometrize::commonutil::randomRange(-16, 16), 0, yBound - 1);
314  break;
315  }
316  case 1:
317  {
318  s.m_rx = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_rx) + geometrize::commonutil::randomRange(-16, 16), 1, xBound - 1);
319  break;
320  }
321  case 2:
322  {
323  s.m_ry = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_ry) + geometrize::commonutil::randomRange(-16, 16), 1, yBound - 1);
324  break;
325  }
326  case 3:
327  {
328  s.m_angle = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_angle) + geometrize::commonutil::randomRange(-16, 16), 0, 360);
329  break;
330  }
331  }
332 }
float m_y
y-coordinate.
Definition: rotatedellipse.h:25
float m_angle
Rotation angle.
Definition: rotatedellipse.h:28
float m_ry
y-radius.
Definition: rotatedellipse.h:27
T clamp(const T &value, const T &lower, const T &upper)
clamp Clamps a value within a range.
Definition: commonutil.h:41
float m_x
x-coordinate.
Definition: rotatedellipse.h:24
std::int32_t randomRange(const std::int32_t min, const std::int32_t max)
randomRange Returns a random integer in the range, inclusive. Uses thread-local random number generat...
Definition: commonutil.cpp:24
float m_rx
x-radius.
Definition: rotatedellipse.h:26

Here is the call graph for this function:

void geometrize::mutate ( geometrize::RotatedRectangle s,
const std::int32_t  xBound,
const std::int32_t  yBound 
)
335 {
336  const std::int32_t r{geometrize::commonutil::randomRange(0, 2)};
337  switch(r) {
338  case 0:
339  {
340  s.m_x1 = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_x1) + geometrize::commonutil::randomRange(-16, 16), 0, xBound);
341  s.m_y1 = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_y1) + geometrize::commonutil::randomRange(-16, 16), 0, yBound);
342  break;
343  }
344  case 1:
345  {
346  s.m_x2 = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_x2) + geometrize::commonutil::randomRange(-16, 16), 0, xBound);
347  s.m_y2 = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_y2) + geometrize::commonutil::randomRange(-16, 16), 0, yBound);
348  break;
349  }
350  case 2:
351  {
352  s.m_angle = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_angle) + geometrize::commonutil::randomRange(-4, 4), 0, 360);
353  break;
354  }
355  }
356 }
float m_y2
Bottom coordinate.
Definition: rotatedrectangle.h:27
float m_x2
Right coordinate.
Definition: rotatedrectangle.h:26
T clamp(const T &value, const T &lower, const T &upper)
clamp Clamps a value within a range.
Definition: commonutil.h:41
float m_x1
Left coordinate.
Definition: rotatedrectangle.h:24
std::int32_t randomRange(const std::int32_t min, const std::int32_t max)
randomRange Returns a random integer in the range, inclusive. Uses thread-local random number generat...
Definition: commonutil.cpp:24
float m_y1
Top coordinate.
Definition: rotatedrectangle.h:25
float m_angle
Rotation angle.
Definition: rotatedrectangle.h:28

Here is the call graph for this function:

void geometrize::mutate ( geometrize::Triangle s,
const std::int32_t  xBound,
const std::int32_t  yBound 
)
359 {
360  const std::int32_t r{geometrize::commonutil::randomRange(0, 2)};
361  switch(r) {
362  case 0:
363  {
364  s.m_x1 = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_x1) + geometrize::commonutil::randomRange(-32, 32), 0, xBound);
365  s.m_y1 = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_y1) + geometrize::commonutil::randomRange(-32, 32), 0, yBound);
366  break;
367  }
368  case 1:
369  {
370  s.m_x2 = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_x2) + geometrize::commonutil::randomRange(-32, 32), 0, xBound);
371  s.m_y2 = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_y2) + geometrize::commonutil::randomRange(-32, 32), 0, yBound);
372  break;
373  }
374  case 2:
375  {
376  s.m_x3 = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_x3) + geometrize::commonutil::randomRange(-32, 32), 0, xBound);
377  s.m_y3 = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_y3) + geometrize::commonutil::randomRange(-32, 32), 0, yBound);
378  break;
379  }
380  }
381 }
float m_y2
Second y-coordinate.
Definition: triangle.h:27
float m_x3
Third x-coordinate.
Definition: triangle.h:28
float m_y1
First y-coordinate.
Definition: triangle.h:25
float m_x2
Second x-coordinate.
Definition: triangle.h:26
float m_x1
First x-coordinate.
Definition: triangle.h:24
T clamp(const T &value, const T &lower, const T &upper)
clamp Clamps a value within a range.
Definition: commonutil.h:41
std::int32_t randomRange(const std::int32_t min, const std::int32_t max)
randomRange Returns a random integer in the range, inclusive. Uses thread-local random number generat...
Definition: commonutil.cpp:24
float m_y3
Third y-coordinate.
Definition: triangle.h:29

Here is the call graph for this function:

bool geometrize::operator!= ( const geometrize::rgba lhs,
const geometrize::rgba rhs 
)
12 {
13  return lhs.r != rhs.r || lhs.g != rhs.g || lhs.b != rhs.b || lhs.a != rhs.a;
14 }
std::uint8_t a
The blue component (0-255).
Definition: rgba.h:17
std::uint8_t g
The red component (0-255).
Definition: rgba.h:15
std::uint8_t b
The green component (0-255).
Definition: rgba.h:16
std::uint8_t r
Definition: rgba.h:14
bool geometrize::operator!= ( const geometrize::Scanline lhs,
const geometrize::Scanline rhs 
)
19 {
20  return lhs.y != rhs.y || lhs.x1 != rhs.x1 || lhs.x2 != rhs.x2;
21 }
std::int32_t x2
The rightmost x-coordinate of the scanline.
Definition: scanline.h:35
std::int32_t y
The y-coordinate of the scanline.
Definition: scanline.h:33
std::int32_t x1
The leftmost x-coordinate of the scanline.
Definition: scanline.h:34
bool geometrize::operator== ( const geometrize::rgba lhs,
const geometrize::rgba rhs 
)
7 {
8  return lhs.r == rhs.r && lhs.g == rhs.g && lhs.b == rhs.b && lhs.a == rhs.a;
9 }
std::uint8_t a
The blue component (0-255).
Definition: rgba.h:17
std::uint8_t g
The red component (0-255).
Definition: rgba.h:15
std::uint8_t b
The green component (0-255).
Definition: rgba.h:16
std::uint8_t r
Definition: rgba.h:14
bool geometrize::operator== ( const geometrize::Scanline lhs,
const geometrize::Scanline rhs 
)
14 {
15  return lhs.y == rhs.y && lhs.x1 == rhs.x1 && lhs.x2 == rhs.x2;
16 }
std::int32_t x2
The rightmost x-coordinate of the scanline.
Definition: scanline.h:35
std::int32_t y
The y-coordinate of the scanline.
Definition: scanline.h:33
std::int32_t x1
The leftmost x-coordinate of the scanline.
Definition: scanline.h:34
std::shared_ptr< geometrize::Shape > geometrize::randomShape ( )

randomShape Creates a random shape.

Returns
The new shape.
125 {
126  return create(geometrize::allShapes[commonutil::randomRange(0, static_cast<int>(geometrize::allShapes.size()) - 1)]);
127 }
const std::array< ShapeTypes, static_cast< std::size_t >ShapeTypes::SHAPE_COUNT)> allShapes
allShapes is a convenient array of all of the members of ShapeTypes.
Definition: shapetypes.cpp:6
std::int32_t randomRange(const std::int32_t min, const std::int32_t max)
randomRange Returns a random integer in the range, inclusive. Uses thread-local random number generat...
Definition: commonutil.cpp:24
std::shared_ptr< geometrize::Shape > create(const geometrize::ShapeTypes t)
create Creates a new shape of the specified type.
Definition: shapefactory.cpp:95

Here is the call graph for this function:

Here is the caller graph for this function:

std::shared_ptr< geometrize::Shape > geometrize::randomShapeOf ( geometrize::ShapeTypes  t)

randomShapeOf Creates a random shape from the types supplied.

Parameters
tThe types of shape to possibly create.
Returns
The new shape.
130 {
131  std::vector<ShapeTypes> typeVector;
132  for(const ShapeTypes type : geometrize::allShapes) {
133  if((type & types) == type) {
134  typeVector.push_back(type);
135  }
136  }
137 
138  if(typeVector.size() == 0) {
139  return randomShape(); // If there are no types specified, create one randomly
140  }
141 
142  return create(typeVector.at(commonutil::randomRange(0, static_cast<std::int32_t>(typeVector.size() - 1))));
143 }
std::shared_ptr< geometrize::Shape > randomShape()
randomShape Creates a random shape.
Definition: shapefactory.cpp:124
ShapeTypes
The ShapeTypes enum specifies the types of shapes that can be used. These can be combined to produce ...
Definition: shapetypes.h:16
const std::array< ShapeTypes, static_cast< std::size_t >ShapeTypes::SHAPE_COUNT)> allShapes
allShapes is a convenient array of all of the members of ShapeTypes.
Definition: shapetypes.cpp:6
std::int32_t randomRange(const std::int32_t min, const std::int32_t max)
randomRange Returns a random integer in the range, inclusive. Uses thread-local random number generat...
Definition: commonutil.cpp:24
std::shared_ptr< geometrize::Shape > create(const geometrize::ShapeTypes t)
create Creates a new shape of the specified type.
Definition: shapefactory.cpp:95

Here is the call graph for this function:

Here is the caller graph for this function:

std::vector< geometrize::Scanline > geometrize::rasterize ( const geometrize::Shape s,
std::int32_t  xBound,
std::int32_t  yBound 
)
195 {
196  switch(s.getType()) {
198  return rasterize(static_cast<const geometrize::Rectangle&>(s), xBound, yBound);
200  return rasterize(static_cast<const geometrize::RotatedRectangle&>(s), xBound, yBound);
202  return rasterize(static_cast<const geometrize::Triangle&>(s), xBound, yBound);
204  return rasterize(static_cast<const geometrize::Ellipse&>(s), xBound, yBound);
206  return rasterize(static_cast<const geometrize::RotatedEllipse&>(s), xBound, yBound);
208  return rasterize(static_cast<const geometrize::Circle&>(s), xBound, yBound);
210  return rasterize(static_cast<const geometrize::Line&>(s), xBound, yBound);
212  return rasterize(static_cast<const geometrize::QuadraticBezier&>(s), xBound, yBound);
214  return rasterize(static_cast<const geometrize::Polyline&>(s), xBound, yBound);
215  default:
216  assert(0 && "Bad shape type");
217  return std::vector<geometrize::Scanline>{};
218  }
219 }
Definition: shapetypes.h:26
Definition: shapetypes.h:21
Definition: shapetypes.h:25
Definition: shapetypes.h:24
Definition: shapetypes.h:19
Definition: shapetypes.h:23
std::vector< geometrize::Scanline > rasterize(const geometrize::Triangle &s, const std::int32_t xBound, const std::int32_t yBound)
Definition: rasterizer.cpp:365
Definition: shapetypes.h:18
Definition: shapetypes.h:20
Definition: shapetypes.h:22
virtual geometrize::ShapeTypes getType() const
getType Gets the ShapeType of the shape.
Definition: shape.h:42

Here is the call graph for this function:

Here is the caller graph for this function:

std::vector< geometrize::Scanline > geometrize::rasterize ( const geometrize::Circle s,
const std::int32_t  xBound,
const std::int32_t  yBound 
)
222 {
223  std::vector<geometrize::Scanline> lines;
224 
225  const std::int32_t r{static_cast<std::int32_t>(s.m_r)};
226  for(std::int32_t y = -r; y <= r; y++) {
227  std::vector<std::int32_t> xScan;
228  for(std::int32_t x = -r; x <= r; x++) {
229  if(x * x + y * y <= r * r) {
230  xScan.push_back(x);
231  }
232  }
233 
234  if(!xScan.empty()) {
235  const std::int32_t fy{static_cast<std::int32_t>(s.m_y) + y};
236  const std::int32_t x1{commonutil::clamp(static_cast<std::int32_t>(s.m_x) + xScan.front(), 0, xBound - 1)};
237  const std::int32_t x2{commonutil::clamp(static_cast<std::int32_t>(s.m_x) + xScan.back(), 0, xBound - 1)};
238  lines.push_back(geometrize::Scanline(fy, x1, x2));
239  }
240  }
241 
242  return geometrize::trimScanlines(lines, xBound, yBound);
243 }
The Scanline class represents a scanline, a row of pixels running across a bitmap.
Definition: scanline.h:13
T clamp(const T &value, const T &lower, const T &upper)
clamp Clamps a value within a range.
Definition: commonutil.h:41
std::vector< geometrize::Scanline > trimScanlines(const std::vector< geometrize::Scanline > &scanlines, const std::uint32_t w, const std::uint32_t h)
trimScanlines Crops the scanning width of an array of scanlines so they do not scan outside of the gi...
Definition: scanline.cpp:23
float m_x
x-coordinate.
Definition: circle.h:24
float m_r
Radius.
Definition: circle.h:26
float m_y
y-coordinate.
Definition: circle.h:25

Here is the call graph for this function:

std::vector< geometrize::Scanline > geometrize::rasterize ( const geometrize::Ellipse s,
const std::int32_t  w,
const std::int32_t  h 
)
246 {
247  std::vector<geometrize::Scanline> lines;
248 
249  const float aspect{static_cast<float>(s.m_rx) / static_cast<float>(s.m_ry)};
250 
251  for (std::int32_t dy = 0; dy < s.m_ry; dy++) {
252  const std::int32_t y1{static_cast<std::int32_t>(s.m_y) - dy};
253  const std::int32_t y2{static_cast<std::int32_t>(s.m_y) + dy};
254 
255  if ((y1 < 0 || y1 >= h) && (y2 < 0 || y2 >= h)) {
256  continue;
257  }
258 
259  const std::int32_t v{static_cast<std::int32_t>(std::sqrt(s.m_ry * s.m_ry - dy * dy) * aspect)};
260  std::int32_t x1{static_cast<std::int32_t>(s.m_x) - v};
261  std::int32_t x2{static_cast<std::int32_t>(s.m_x) + v};
262  if (x1 < 0) {
263  x1 = 0;
264  }
265  if (x2 >= w) {
266  x2 = w - 1;
267  }
268 
269  if (y1 >= 0 && y1 < h) {
270  lines.push_back(Scanline(y1, x1, x2));
271  }
272  if (y2 >= 0 && y2 < h && dy > 0) {
273  lines.push_back(Scanline(y2, x1, x2));
274  }
275  }
276 
277  return geometrize::trimScanlines(lines, w, h);
278 }
std::vector< geometrize::Scanline > trimScanlines(const std::vector< geometrize::Scanline > &scanlines, const std::uint32_t w, const std::uint32_t h)
trimScanlines Crops the scanning width of an array of scanlines so they do not scan outside of the gi...
Definition: scanline.cpp:23
float m_x
x-coordinate.
Definition: ellipse.h:24
float m_ry
y-radius.
Definition: ellipse.h:27
float m_rx
x-radius.
Definition: ellipse.h:26
float m_y
y-coordinate.
Definition: ellipse.h:25

Here is the call graph for this function:

std::vector< geometrize::Scanline > geometrize::rasterize ( const geometrize::Line s,
const std::int32_t  xBound,
const std::int32_t  yBound 
)
281 {
282  std::vector<geometrize::Scanline> lines;
283 
284  const std::vector<std::pair<std::int32_t, std::int32_t>> points{geometrize::bresenham(static_cast<std::int32_t>(s.m_x1), static_cast<std::int32_t>(s.m_y1), static_cast<std::int32_t>(s.m_x2), static_cast<std::int32_t>(s.m_y2))};
285  for(const auto& point : points) {
286  lines.push_back(geometrize::Scanline(point.second, point.first, point.first));
287  }
288 
289  return geometrize::trimScanlines(lines, xBound, yBound);
290 }
The Scanline class represents a scanline, a row of pixels running across a bitmap.
Definition: scanline.h:13
std::vector< std::pair< std::int32_t, std::int32_t > > bresenham(std::int32_t x1, std::int32_t y1, const std::int32_t x2, const std::int32_t y2)
bresenham Bresenham's line algorithm. Returns the points on the line.
Definition: rasterizer.cpp:122
std::vector< geometrize::Scanline > trimScanlines(const std::vector< geometrize::Scanline > &scanlines, const std::uint32_t w, const std::uint32_t h)
trimScanlines Crops the scanning width of an array of scanlines so they do not scan outside of the gi...
Definition: scanline.cpp:23
float m_y2
Second y-coordinate.
Definition: line.h:27
float m_y1
First y-coordinate.
Definition: line.h:25
float m_x1
First x-coordinate.
Definition: line.h:24
float m_x2
Second x-coordinate.
Definition: line.h:26

Here is the call graph for this function:

std::vector< geometrize::Scanline > geometrize::rasterize ( const geometrize::Polyline s,
const std::int32_t  xBound,
const std::int32_t  yBound 
)
293 {
294  std::vector<geometrize::Scanline> lines;
295 
296  for(std::size_t i = 0; i < s.m_points.size(); i++) {
297  const std::pair<std::int32_t, std::int32_t> p0{s.m_points[i].first, s.m_points[i].second};
298  const std::pair<std::int32_t, std::int32_t> p1{i < (s.m_points.size() - 1) ? std::make_pair(static_cast<std::int32_t>(s.m_points[i + 1].first), static_cast<std::int32_t>(s.m_points[i + 1].second)) : p0};
299 
300  const std::vector<std::pair<std::int32_t, std::int32_t>> points{geometrize::bresenham(p0.first, p0.second, p1.first, p1.second)};
301  for(const auto& point : points) {
302  lines.push_back(geometrize::Scanline(point.second, point.first, point.first));
303  }
304  }
305 
306  return geometrize::trimScanlines(lines, xBound, yBound);
307 }
The Scanline class represents a scanline, a row of pixels running across a bitmap.
Definition: scanline.h:13
std::vector< std::pair< std::int32_t, std::int32_t > > bresenham(std::int32_t x1, std::int32_t y1, const std::int32_t x2, const std::int32_t y2)
bresenham Bresenham's line algorithm. Returns the points on the line.
Definition: rasterizer.cpp:122
std::vector< std::pair< float, float > > m_points
The points on the polyline.
Definition: polyline.h:26
std::vector< geometrize::Scanline > trimScanlines(const std::vector< geometrize::Scanline > &scanlines, const std::uint32_t w, const std::uint32_t h)
trimScanlines Crops the scanning width of an array of scanlines so they do not scan outside of the gi...
Definition: scanline.cpp:23

Here is the call graph for this function:

std::vector< geometrize::Scanline > geometrize::rasterize ( const geometrize::QuadraticBezier s,
const std::int32_t  xBound,
const std::int32_t  yBound 
)
310 {
311  std::vector<geometrize::Scanline> scanlines;
312 
313  std::vector<std::pair<std::int32_t, std::int32_t>> points;
314  const std::uint32_t pointCount{20};
315  for(std::uint32_t i = 0; i <= pointCount; i++) {
316  const float t{static_cast<float>(i) / static_cast<float>(pointCount)};
317  const float tp{1 - t};
318  const std::int32_t x{static_cast<std::int32_t>(tp * (tp * s.m_x1 + (t * s.m_cx)) + t * ((tp * s.m_cx) + (t * s.m_x2)))};
319  const std::int32_t y{static_cast<std::int32_t>(tp * (tp * s.m_y1 + (t * s.m_cy)) + t * ((tp * s.m_cy) + (t * s.m_y2)))};
320  points.push_back(std::make_pair(x, y));
321  }
322 
323  for(std::uint32_t i = 0; i < points.size() - 1; i++) {
324  const std::pair<std::int32_t, std::int32_t> p0{points[i]};
325  const std::pair<std::int32_t, std::int32_t> p1{points[i + 1]};
326 
327  const std::vector<std::pair<std::int32_t, std::int32_t>> points{geometrize::bresenham(static_cast<std::int32_t>(p0.first), static_cast<std::int32_t>(p0.second), static_cast<std::int32_t>(p1.first), static_cast<std::int32_t>(p1.second))};
328  for(const std::pair<std::int32_t, std::int32_t>& point : points) {
329  scanlines.push_back(geometrize::Scanline(point.second, point.first, point.first));
330  }
331  }
332 
333  return geometrize::trimScanlines(scanlines, xBound, yBound);
334 }
float m_x1
First x-coordinate.
Definition: quadraticbezier.h:26
The Scanline class represents a scanline, a row of pixels running across a bitmap.
Definition: scanline.h:13
float m_x2
Second x-coordinate.
Definition: quadraticbezier.h:28
std::vector< std::pair< std::int32_t, std::int32_t > > bresenham(std::int32_t x1, std::int32_t y1, const std::int32_t x2, const std::int32_t y2)
bresenham Bresenham's line algorithm. Returns the points on the line.
Definition: rasterizer.cpp:122
float m_y1
First y-coordinate.
Definition: quadraticbezier.h:27
float m_cx
Control point x-coordinate.
Definition: quadraticbezier.h:24
std::vector< geometrize::Scanline > trimScanlines(const std::vector< geometrize::Scanline > &scanlines, const std::uint32_t w, const std::uint32_t h)
trimScanlines Crops the scanning width of an array of scanlines so they do not scan outside of the gi...
Definition: scanline.cpp:23
float m_y2
Second y-coordinate.
Definition: quadraticbezier.h:29
float m_cy
Control point y-coordinate.
Definition: quadraticbezier.h:25

Here is the call graph for this function:

std::vector< geometrize::Scanline > geometrize::rasterize ( const geometrize::Rectangle s,
const std::int32_t  xBound,
const std::int32_t  yBound 
)
337 {
338  const std::int32_t x1{static_cast<std::int32_t>((std::fmin)(s.m_x1, s.m_x2))};
339  const std::int32_t x2{static_cast<std::int32_t>((std::fmax)(s.m_x1, s.m_x2))};
340  const std::int32_t y1{static_cast<std::int32_t>((std::fmin)(s.m_y1, s.m_y2))};
341  const std::int32_t y2{static_cast<std::int32_t>((std::fmax)(s.m_y1, s.m_y2))};
342 
343  std::vector<geometrize::Scanline> lines;
344  for(std::int32_t y = y1; y < y2; y++) {
345  lines.push_back(geometrize::Scanline(y, x1, x2));
346  }
347  return geometrize::trimScanlines(lines, xBound, yBound);
348 }
The Scanline class represents a scanline, a row of pixels running across a bitmap.
Definition: scanline.h:13
float m_x1
Left coordinate.
Definition: rectangle.h:24
std::vector< geometrize::Scanline > trimScanlines(const std::vector< geometrize::Scanline > &scanlines, const std::uint32_t w, const std::uint32_t h)
trimScanlines Crops the scanning width of an array of scanlines so they do not scan outside of the gi...
Definition: scanline.cpp:23
float m_y2
Bottom coordinate.
Definition: rectangle.h:27
float m_y1
Top coordinate.
Definition: rectangle.h:25
float m_x2
Right coordinate.
Definition: rectangle.h:26

Here is the call graph for this function:

std::vector< geometrize::Scanline > geometrize::rasterize ( const geometrize::RotatedEllipse s,
const std::int32_t  xBound,
const std::int32_t  yBound 
)
351 {
352  const std::uint32_t pointCount{20};
353  std::vector<std::pair<float, float>> points = getPointsOnRotatedEllipse(s, pointCount);
354 
355  std::vector<geometrize::Scanline> scanlines{geometrize::scanlinesForPolygon(points)};
356  return geometrize::trimScanlines(scanlines, xBound, yBound);
357 }
std::vector< geometrize::Scanline > trimScanlines(const std::vector< geometrize::Scanline > &scanlines, const std::uint32_t w, const std::uint32_t h)
trimScanlines Crops the scanning width of an array of scanlines so they do not scan outside of the gi...
Definition: scanline.cpp:23
std::vector< geometrize::Scanline > scanlinesForPolygon(const std::vector< std::pair< float, float >> &points)
scanlinesForPolygon Gets the scanlines for a series of points that make up an arbitrary polygon...
Definition: rasterizer.cpp:166
std::vector< std::pair< float, float > > getPointsOnRotatedEllipse(const geometrize::RotatedEllipse &e, const std::size_t numPoints)
getPointsOnRotatedEllipse Calculates and returns a number of points on the given rotated ellipse...
Definition: rasterizer.cpp:57

Here is the call graph for this function:

std::vector< geometrize::Scanline > geometrize::rasterize ( const geometrize::RotatedRectangle s,
const std::int32_t  xBound,
const std::int32_t  yBound 
)
360 {
361  std::vector<geometrize::Scanline> scanlines{geometrize::scanlinesForPolygon(getCornerPoints(s))};
362  return geometrize::trimScanlines(scanlines, xBound, yBound);
363 }
std::vector< geometrize::Scanline > trimScanlines(const std::vector< geometrize::Scanline > &scanlines, const std::uint32_t w, const std::uint32_t h)
trimScanlines Crops the scanning width of an array of scanlines so they do not scan outside of the gi...
Definition: scanline.cpp:23
std::vector< geometrize::Scanline > scanlinesForPolygon(const std::vector< std::pair< float, float >> &points)
scanlinesForPolygon Gets the scanlines for a series of points that make up an arbitrary polygon...
Definition: rasterizer.cpp:166
std::vector< std::pair< float, float > > getCornerPoints(const geometrize::RotatedRectangle &r)
getCornerPoints Gets the corner points of the given rotated rectangle.
Definition: rasterizer.cpp:30

Here is the call graph for this function:

std::vector< geometrize::Scanline > geometrize::rasterize ( const geometrize::Triangle s,
const std::int32_t  xBound,
const std::int32_t  yBound 
)
366 {
367  std::vector<geometrize::Scanline> scanlines = geometrize::scanlinesForPolygon({
368  {static_cast<std::int32_t>(s.m_x1), static_cast<std::int32_t>(s.m_y1)},
369  {static_cast<std::int32_t>(s.m_x2), static_cast<std::int32_t>(s.m_y2)},
370  {static_cast<std::int32_t>(s.m_x3), static_cast<std::int32_t>(s.m_y3)}});
371 
372  return geometrize::trimScanlines(scanlines, xBound, yBound);
373 }
float m_y2
Second y-coordinate.
Definition: triangle.h:27
float m_x3
Third x-coordinate.
Definition: triangle.h:28
float m_y1
First y-coordinate.
Definition: triangle.h:25
float m_x2
Second x-coordinate.
Definition: triangle.h:26
float m_x1
First x-coordinate.
Definition: triangle.h:24
std::vector< geometrize::Scanline > trimScanlines(const std::vector< geometrize::Scanline > &scanlines, const std::uint32_t w, const std::uint32_t h)
trimScanlines Crops the scanning width of an array of scanlines so they do not scan outside of the gi...
Definition: scanline.cpp:23
std::vector< geometrize::Scanline > scanlinesForPolygon(const std::vector< std::pair< float, float >> &points)
scanlinesForPolygon Gets the scanlines for a series of points that make up an arbitrary polygon...
Definition: rasterizer.cpp:166
float m_y3
Third y-coordinate.
Definition: triangle.h:29

Here is the call graph for this function:

void geometrize::rotate ( geometrize::Shape s,
const float  angle 
)
616 {
617  switch(s.getType()) {
619  rotate(static_cast<geometrize::RotatedRectangle&>(s), angle);
620  break;
622  rotate(static_cast<geometrize::Triangle&>(s), angle);
623  break;
625  rotate(static_cast<geometrize::RotatedEllipse&>(s), angle);
626  break;
628  rotate(static_cast<geometrize::Line&>(s), angle);
629  break;
630  default:
631  break;
632  }
633 }
Definition: shapetypes.h:24
Definition: shapetypes.h:19
Definition: shapetypes.h:20
Definition: shapetypes.h:22
void rotate(geometrize::Triangle &s, const float angle)
Definition: shapemutator.cpp:667
virtual geometrize::ShapeTypes getType() const
getType Gets the ShapeType of the shape.
Definition: shape.h:42

Here is the call graph for this function:

void geometrize::rotate ( geometrize::Line s,
const float  angle 
)
636 {
637  const float xMid = (s.m_x1 + s.m_x2) / 2;
638  const float yMid = (s.m_y1 + s.m_y2) / 2;
639 
640  translate(s, -xMid, -yMid);
641 
642  const float x1 = s.m_x1;
643  const float x2 = s.m_x2;
644  const float y1 = s.m_y1;
645  const float y2 = s.m_y2;
646  const float cosAngle = std::cos(angle);
647  const float sinAngle = std::sin(angle);
648 
649  s.m_x1 = x1 * cosAngle - y1 * sinAngle;
650  s.m_y1 = x1 * sinAngle + y1 * cosAngle;
651  s.m_x2 = x2 * cosAngle - y2 * sinAngle;
652  s.m_y2 = x2 * sinAngle + y2 * cosAngle;
653 
654  translate(s, xMid, yMid);
655 }
void translate(geometrize::Triangle &s, const float x, const float y)
Definition: shapemutator.cpp:478
float m_y2
Second y-coordinate.
Definition: line.h:27
float m_y1
First y-coordinate.
Definition: line.h:25
float m_x1
First x-coordinate.
Definition: line.h:24
float m_x2
Second x-coordinate.
Definition: line.h:26

Here is the call graph for this function:

void geometrize::rotate ( geometrize::RotatedEllipse s,
const float  angle 
)
658 {
659  s.m_angle = wrapMinMax(s.m_angle + angle, 0, 360);
660 }
float m_angle
Rotation angle.
Definition: rotatedellipse.h:28
void geometrize::rotate ( geometrize::RotatedRectangle s,
const float  angle 
)
663 {
664  s.m_angle = wrapMinMax(s.m_angle + angle, 0, 360);
665 }
float m_angle
Rotation angle.
Definition: rotatedrectangle.h:28
void geometrize::rotate ( geometrize::Triangle s,
const float  angle 
)
668 {
669  const float xMid = (s.m_x1 + s.m_x2 + s.m_x3) / 3;
670  const float yMid = (s.m_y1 + s.m_y2 + s.m_y3) / 3;
671 
672  translate(s, -xMid, -yMid);
673 
674  const float x1 = s.m_x1;
675  const float x2 = s.m_x2;
676  const float x3 = s.m_x3;
677  const float y1 = s.m_y1;
678  const float y2 = s.m_y2;
679  const float y3 = s.m_y3;
680  const float cosAngle = std::cos(angle);
681  const float sinAngle = std::sin(angle);
682 
683  s.m_x1 = x1 * cosAngle - y1 * sinAngle;
684  s.m_y1 = x1 * sinAngle + y1 * cosAngle;
685  s.m_x2 = x2 * cosAngle - y2 * sinAngle;
686  s.m_y2 = x2 * sinAngle + y2 * cosAngle;
687  s.m_x3 = x3 * cosAngle - y3 * sinAngle;
688  s.m_y3 = x3 * sinAngle + y3 * cosAngle;
689 
690  translate(s, xMid, yMid);
691 }
float m_y2
Second y-coordinate.
Definition: triangle.h:27
float m_x3
Third x-coordinate.
Definition: triangle.h:28
void translate(geometrize::Triangle &s, const float x, const float y)
Definition: shapemutator.cpp:478
float m_y1
First y-coordinate.
Definition: triangle.h:25
float m_x2
Second x-coordinate.
Definition: triangle.h:26
float m_x1
First x-coordinate.
Definition: triangle.h:24
float m_y3
Third y-coordinate.
Definition: triangle.h:29

Here is the call graph for this function:

void geometrize::scale ( geometrize::Shape s,
const float  scaleFactor 
)
489 {
490  switch(s.getType()) {
492  scale(static_cast<geometrize::Rectangle&>(s), scaleFactor);
493  break;
495  scale(static_cast<geometrize::RotatedRectangle&>(s), scaleFactor);
496  break;
498  scale(static_cast<geometrize::Triangle&>(s), scaleFactor);
499  break;
501  scale(static_cast<geometrize::Ellipse&>(s), scaleFactor);
502  break;
504  scale(static_cast<geometrize::RotatedEllipse&>(s), scaleFactor);
505  break;
507  scale(static_cast<geometrize::Circle&>(s), scaleFactor);
508  break;
510  scale(static_cast<geometrize::Line&>(s), scaleFactor);
511  break;
513  scale(static_cast<geometrize::QuadraticBezier&>(s), scaleFactor);
514  break;
516  scale(static_cast<geometrize::Polyline&>(s), scaleFactor);
517  break;
518  default:
519  assert(0 && "Bad shape type");
520  }
521 }
Definition: shapetypes.h:26
Definition: shapetypes.h:21
Definition: shapetypes.h:25
Definition: shapetypes.h:24
Definition: shapetypes.h:19
Definition: shapetypes.h:23
void scale(geometrize::Triangle &s, const float scaleFactor)
Definition: shapemutator.cpp:602
Definition: shapetypes.h:18
Definition: shapetypes.h:20
Definition: shapetypes.h:22
virtual geometrize::ShapeTypes getType() const
getType Gets the ShapeType of the shape.
Definition: shape.h:42

Here is the call graph for this function:

void geometrize::scale ( geometrize::Circle s,
const float  scaleFactor 
)
524 {
525  s.m_r *= scaleFactor;
526 }
float m_r
Radius.
Definition: circle.h:26
void geometrize::scale ( geometrize::Ellipse s,
const float  scaleFactor 
)
529 {
530  s.m_rx *= scaleFactor;
531  s.m_ry *= scaleFactor;
532 }
float m_ry
y-radius.
Definition: ellipse.h:27
float m_rx
x-radius.
Definition: ellipse.h:26
void geometrize::scale ( geometrize::Line s,
const float  scaleFactor 
)
535 {
536  const float xMid = (s.m_x1 + s.m_x2) / 2;
537  const float yMid = (s.m_y1 + s.m_y2) / 2;
538 
539  s.m_x1 = (s.m_x1 - xMid) * scaleFactor + xMid;
540  s.m_x2 = (s.m_x2 - xMid) * scaleFactor + xMid;
541 
542  s.m_y1 = (s.m_y1 - yMid) * scaleFactor + yMid;
543  s.m_y2 = (s.m_y2 - yMid) * scaleFactor + yMid;
544 }
float m_y2
Second y-coordinate.
Definition: line.h:27
float m_y1
First y-coordinate.
Definition: line.h:25
float m_x1
First x-coordinate.
Definition: line.h:24
float m_x2
Second x-coordinate.
Definition: line.h:26
void geometrize::scale ( geometrize::Polyline s,
const float  scaleFactor 
)
547 {
548  std::vector<std::pair<float, float>> points;
549 
550  for(std::size_t i = 0; i < s.m_points.size(); i+=2) {
551  if(i == s.m_points.size() - 1 || i == s.m_points.size()) {
552  continue;
553  }
554  const float x1 = s.m_points[i].first;
555  const float x2 = s.m_points[i + 1].first;
556  const float y1 = s.m_points[i].second;
557  const float y2 = s.m_points[i + 1].second;
558 
559  const float xLen = (x1 + x2) / 2;
560  const float yLen = (y1 + y2) / 2;
561 
562  points.push_back({(x1 - xLen) * scaleFactor + xLen, (y1 - yLen) * scaleFactor + yLen});
563  points.push_back({(x1 - xLen) * scaleFactor + xLen, (y2 - yLen) * scaleFactor + yLen});
564  }
565 
566  s.m_points = points;
567 }
std::vector< std::pair< float, float > > m_points
The points on the polyline.
Definition: polyline.h:26
void geometrize::scale ( geometrize::QuadraticBezier s,
const float  scaleFactor 
)
570 {
571  assert(0 && "TODO");
572 }
void geometrize::scale ( geometrize::Rectangle s,
const float  scaleFactor 
)
575 {
576  const float xMid = (s.m_x1 + s.m_x2) / 2;
577  const float yMid = (s.m_y1 + s.m_y2) / 2;
578 
579  s.m_x1 = (s.m_x1 - xMid) * scaleFactor + xMid;
580  s.m_y1 = (s.m_y1 - yMid) * scaleFactor + yMid;
581  s.m_x2 = (s.m_x2 - xMid) * scaleFactor + xMid;
582  s.m_y2 = (s.m_y2 - yMid) * scaleFactor + yMid;
583 }
float m_x1
Left coordinate.
Definition: rectangle.h:24
float m_y2
Bottom coordinate.
Definition: rectangle.h:27
float m_y1
Top coordinate.
Definition: rectangle.h:25
float m_x2
Right coordinate.
Definition: rectangle.h:26
void geometrize::scale ( geometrize::RotatedEllipse s,
const float  scaleFactor 
)
586 {
587  s.m_rx *= scaleFactor;
588  s.m_ry *= scaleFactor;
589 }
float m_ry
y-radius.
Definition: rotatedellipse.h:27
float m_rx
x-radius.
Definition: rotatedellipse.h:26
void geometrize::scale ( geometrize::RotatedRectangle s,
const float  scaleFactor 
)
592 {
593  const float xMid = (s.m_x1 + s.m_x2) / 2;
594  const float yMid = (s.m_y1 + s.m_y2) / 2;
595 
596  s.m_x1 = (s.m_x1 - xMid) * scaleFactor + xMid;
597  s.m_y1 = (s.m_y1 - yMid) * scaleFactor + yMid;
598  s.m_x2 = (s.m_x2 - xMid) * scaleFactor + xMid;
599  s.m_y2 = (s.m_y2 - yMid) * scaleFactor + yMid;
600 }
float m_y2
Bottom coordinate.
Definition: rotatedrectangle.h:27
float m_x2
Right coordinate.
Definition: rotatedrectangle.h:26
float m_x1
Left coordinate.
Definition: rotatedrectangle.h:24
float m_y1
Top coordinate.
Definition: rotatedrectangle.h:25
void geometrize::scale ( geometrize::Triangle s,
const float  scaleFactor 
)
603 {
604  const float xMid = (s.m_x1 + s.m_x2 + s.m_x3) / 3;
605  const float yMid = (s.m_y1 + s.m_y2 + s.m_y3) / 3;
606 
607  s.m_x1 = (s.m_x1 - xMid) * scaleFactor + xMid;
608  s.m_y1 = (s.m_y1 - yMid) * scaleFactor + yMid;
609  s.m_x2 = (s.m_x2 - xMid) * scaleFactor + xMid;
610  s.m_y2 = (s.m_y2 - yMid) * scaleFactor + yMid;
611  s.m_x3 = (s.m_x3 - xMid) * scaleFactor + xMid;
612  s.m_y3 = (s.m_y3 - yMid) * scaleFactor + yMid;
613 }
float m_y2
Second y-coordinate.
Definition: triangle.h:27
float m_x3
Third x-coordinate.
Definition: triangle.h:28
float m_y1
First y-coordinate.
Definition: triangle.h:25
float m_x2
Second x-coordinate.
Definition: triangle.h:26
float m_x1
First x-coordinate.
Definition: triangle.h:24
float m_y3
Third y-coordinate.
Definition: triangle.h:29
bool geometrize::scanlinesContain ( const std::vector< geometrize::Scanline > &  first,
const std::vector< geometrize::Scanline > &  second 
)

scanlinesContain Returns true if the first vector of scanlines wholly contain the second vector of scanlines.

Parameters
firstFirst collection of scanlines.
secondSecond collection of scanlines.
Returns
True if the first set of scanlines wholly contains the second set, else false.
390 {
391  for(const auto& s : first) {
392  bool contained = false;
393  for(const auto& f : second) {
394  if(f.y == s.y) {
395  if(f.x1 <= s.x1 && f.x2 >= s.x2) {
396  contained = true;
397  }
398  }
399  }
400 
401  if(!contained) {
402  return false;
403  }
404  }
405 
406  return true;
407 }

Here is the caller graph for this function:

std::vector< geometrize::Scanline > geometrize::scanlinesForPolygon ( const std::vector< std::pair< float, float >> &  points)

scanlinesForPolygon Gets the scanlines for a series of points that make up an arbitrary polygon.

Parameters
pointsThe vertices of the polygon.
Returns
Scanlines for the polygon.
167 {
168  std::vector<geometrize::Scanline> lines;
169 
170  // Get the pixel outline of the polygon
171  std::vector<std::pair<std::int32_t, std::int32_t>> edges;
172  for(std::size_t i = 0; i < points.size(); i++) {
173  const std::pair<std::int32_t, std::int32_t> p1{static_cast<std::int32_t>(points[i].first), static_cast<std::int32_t>(points[i].second)};
174  const std::pair<std::int32_t, std::int32_t> p2{(i == (points.size() - 1)) ? std::make_pair(static_cast<std::int32_t>(points[0U].first), static_cast<std::int32_t>(points[0U].second)) : std::make_pair(static_cast<std::int32_t>(points[i + 1U].first), static_cast<std::int32_t>(points[i + 1U].second))};
175  const std::vector<std::pair<std::int32_t, std::int32_t>> p1p2{geometrize::bresenham(p1.first, p1.second, p2.first, p2.second)};
176  edges.insert(edges.end(), p1p2.begin(), p1p2.end());
177  }
178 
179  // Convert outline to scanlines
180  std::map<std::int32_t, std::set<std::int32_t>> yToXs;
181  for(std::pair<std::int32_t, std::int32_t> point : edges) {
182  yToXs[point.second].insert(point.first);
183  }
184  for(const auto& it : yToXs) {
185  const geometrize::Scanline scanline(it.first,
186  *(std::min_element(it.second.begin(), it.second.end())),
187  *(std::max_element(it.second.begin(), it.second.end())));
188  lines.push_back(scanline);
189  }
190 
191  return lines;
192 }
The Scanline class represents a scanline, a row of pixels running across a bitmap.
Definition: scanline.h:13
std::vector< std::pair< std::int32_t, std::int32_t > > bresenham(std::int32_t x1, std::int32_t y1, const std::int32_t x2, const std::int32_t y2)
bresenham Bresenham's line algorithm. Returns the points on the line.
Definition: rasterizer.cpp:122

Here is the call graph for this function:

Here is the caller graph for this function:

bool geometrize::scanlinesOverlap ( const std::vector< geometrize::Scanline > &  first,
const std::vector< geometrize::Scanline > &  second 
)

scanlinesOverlap Returns true if any of the scanlines from the first vector overlap the second

Parameters
firstFirst collection of scanlines.
secondSecond collection of scanlines.
Returns
True if there are any overlaps, else false.
376 {
377  for(const auto& f : first) {
378  for(const auto& s : second) {
379  if(f.y == s.y) {
380  if(f.x1 >= s.x1 && f.x2 <= s.x2) {
381  return true;
382  }
383  }
384  }
385  }
386  return false;
387 }

Here is the caller graph for this function:

void geometrize::setup ( geometrize::Shape s,
const std::int32_t  xBound,
const std::int32_t  yBound 
)
38 {
39  switch(s.getType()) {
41  setup(static_cast<geometrize::Rectangle&>(s), xBound, yBound);
42  break;
44  setup(static_cast<geometrize::RotatedRectangle&>(s), xBound, yBound);
45  break;
47  setup(static_cast<geometrize::Triangle&>(s), xBound, yBound);
48  break;
50  setup(static_cast<geometrize::Ellipse&>(s), xBound, yBound);
51  break;
53  setup(static_cast<geometrize::RotatedEllipse&>(s), xBound, yBound);
54  break;
56  setup(static_cast<geometrize::Circle&>(s), xBound, yBound);
57  break;
59  setup(static_cast<geometrize::Line&>(s), xBound, yBound);
60  break;
62  setup(static_cast<geometrize::QuadraticBezier&>(s), xBound, yBound);
63  break;
65  setup(static_cast<geometrize::Polyline&>(s), xBound, yBound);
66  break;
67  default:
68  assert(0 && "Bad shape type");
69  }
70 }
Definition: shapetypes.h:26
void setup(geometrize::Triangle &s, const std::int32_t xBound, const std::int32_t yBound)
Definition: shapemutator.cpp:145
Definition: shapetypes.h:21
Definition: shapetypes.h:25
Definition: shapetypes.h:24
Definition: shapetypes.h:19
Definition: shapetypes.h:23
Definition: shapetypes.h:18
Definition: shapetypes.h:20
Definition: shapetypes.h:22
virtual geometrize::ShapeTypes getType() const
getType Gets the ShapeType of the shape.
Definition: shape.h:42

Here is the call graph for this function:

Here is the caller graph for this function:

void geometrize::setup ( geometrize::Circle s,
const std::int32_t  xBound,
const std::int32_t  yBound 
)
73 {
74  s.m_x = geometrize::commonutil::randomRange(0, xBound - 1);
75  s.m_y = geometrize::commonutil::randomRange(0, yBound - 1);
77 }
std::int32_t randomRange(const std::int32_t min, const std::int32_t max)
randomRange Returns a random integer in the range, inclusive. Uses thread-local random number generat...
Definition: commonutil.cpp:24
float m_x
x-coordinate.
Definition: circle.h:24
float m_r
Radius.
Definition: circle.h:26
float m_y
y-coordinate.
Definition: circle.h:25

Here is the call graph for this function:

void geometrize::setup ( geometrize::Ellipse s,
const std::int32_t  xBound,
const std::int32_t  yBound 
)
80 {
81  s.m_x = geometrize::commonutil::randomRange(0, xBound - 1);
82  s.m_y = geometrize::commonutil::randomRange(0, yBound - 1);
85 }
float m_x
x-coordinate.
Definition: ellipse.h:24
std::int32_t randomRange(const std::int32_t min, const std::int32_t max)
randomRange Returns a random integer in the range, inclusive. Uses thread-local random number generat...
Definition: commonutil.cpp:24
float m_ry
y-radius.
Definition: ellipse.h:27
float m_rx
x-radius.
Definition: ellipse.h:26
float m_y
y-coordinate.
Definition: ellipse.h:25

Here is the call graph for this function:

void geometrize::setup ( geometrize::Line s,
const std::int32_t  xBound,
const std::int32_t  yBound 
)
88 {
89  const std::pair<std::int32_t, std::int32_t> startingPoint{std::make_pair(geometrize::commonutil::randomRange(0, xBound), geometrize::commonutil::randomRange(0, yBound - 1))};
90 
91  s.m_x1 = geometrize::commonutil::clamp(startingPoint.first + geometrize::commonutil::randomRange(-32, 32), 0, xBound - 1);
92  s.m_y1 = geometrize::commonutil::clamp(startingPoint.second + geometrize::commonutil::randomRange(-32, 32), 0, yBound - 1);
93  s.m_x2 = geometrize::commonutil::clamp(startingPoint.first + geometrize::commonutil::randomRange(-32, 32), 0, xBound - 1);
94  s.m_y2 = geometrize::commonutil::clamp(startingPoint.second + geometrize::commonutil::randomRange(-32, 32), 0, yBound - 1);
95 }
T clamp(const T &value, const T &lower, const T &upper)
clamp Clamps a value within a range.
Definition: commonutil.h:41
float m_y2
Second y-coordinate.
Definition: line.h:27
std::int32_t randomRange(const std::int32_t min, const std::int32_t max)
randomRange Returns a random integer in the range, inclusive. Uses thread-local random number generat...
Definition: commonutil.cpp:24
float m_y1
First y-coordinate.
Definition: line.h:25
float m_x1
First x-coordinate.
Definition: line.h:24
float m_x2
Second x-coordinate.
Definition: line.h:26

Here is the call graph for this function:

void geometrize::setup ( geometrize::Polyline s,
const std::int32_t  xBound,
const std::int32_t  yBound 
)
98 {
99  const std::pair<std::int32_t, std::int32_t> startingPoint{std::make_pair(geometrize::commonutil::randomRange(0, xBound), geometrize::commonutil::randomRange(0, yBound - 1))};
100  for(std::int32_t i = 0; i < 4; i++) {
101  const std::pair<std::int32_t, std::int32_t> point{
102  geometrize::commonutil::clamp(startingPoint.first + geometrize::commonutil::randomRange(-32, 32), 0, xBound - 1),
103  geometrize::commonutil::clamp(startingPoint.second + geometrize::commonutil::randomRange(-32, 32), 0, yBound - 1)
104  };
105  s.m_points.push_back(point);
106  }
107 }
std::vector< std::pair< float, float > > m_points
The points on the polyline.
Definition: polyline.h:26
T clamp(const T &value, const T &lower, const T &upper)
clamp Clamps a value within a range.
Definition: commonutil.h:41
std::int32_t randomRange(const std::int32_t min, const std::int32_t max)
randomRange Returns a random integer in the range, inclusive. Uses thread-local random number generat...
Definition: commonutil.cpp:24

Here is the call graph for this function:

void geometrize::setup ( geometrize::QuadraticBezier s,
const std::int32_t  xBound,
const std::int32_t  yBound 
)
110 {
111  s.m_x1 = geometrize::commonutil::randomRange(0, xBound - 1);
112  s.m_y1 = geometrize::commonutil::randomRange(0, yBound - 1);
113  s.m_cx = geometrize::commonutil::randomRange(0, xBound - 1);
114  s.m_cy = geometrize::commonutil::randomRange(0, yBound - 1);
115  s.m_x2 = geometrize::commonutil::randomRange(0, xBound - 1);
116  s.m_y2 = geometrize::commonutil::randomRange(0, yBound - 1);
117 }
float m_x1
First x-coordinate.
Definition: quadraticbezier.h:26
float m_x2
Second x-coordinate.
Definition: quadraticbezier.h:28
float m_y1
First y-coordinate.
Definition: quadraticbezier.h:27
float m_cx
Control point x-coordinate.
Definition: quadraticbezier.h:24
std::int32_t randomRange(const std::int32_t min, const std::int32_t max)
randomRange Returns a random integer in the range, inclusive. Uses thread-local random number generat...
Definition: commonutil.cpp:24
float m_y2
Second y-coordinate.
Definition: quadraticbezier.h:29
float m_cy
Control point y-coordinate.
Definition: quadraticbezier.h:25

Here is the call graph for this function:

void geometrize::setup ( geometrize::Rectangle s,
const std::int32_t  xBound,
const std::int32_t  yBound 
)
120 {
121  s.m_x1 = geometrize::commonutil::randomRange(0, xBound - 1);
122  s.m_y1 = geometrize::commonutil::randomRange(0, yBound - 1);
123  s.m_x2 = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_x1) + geometrize::commonutil::randomRange(1, 32), 0, xBound - 1);
124  s.m_y2 = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_y1) + geometrize::commonutil::randomRange(1, 32), 0, yBound - 1);
125 }
float m_x1
Left coordinate.
Definition: rectangle.h:24
T clamp(const T &value, const T &lower, const T &upper)
clamp Clamps a value within a range.
Definition: commonutil.h:41
float m_y2
Bottom coordinate.
Definition: rectangle.h:27
std::int32_t randomRange(const std::int32_t min, const std::int32_t max)
randomRange Returns a random integer in the range, inclusive. Uses thread-local random number generat...
Definition: commonutil.cpp:24
float m_y1
Top coordinate.
Definition: rectangle.h:25
float m_x2
Right coordinate.
Definition: rectangle.h:26

Here is the call graph for this function:

void geometrize::setup ( geometrize::RotatedEllipse s,
const std::int32_t  xBound,
const std::int32_t  yBound 
)
128 {
129  s.m_x = geometrize::commonutil::randomRange(0, xBound - 1);
130  s.m_y = geometrize::commonutil::randomRange(0, yBound - 1);
134 }
float m_y
y-coordinate.
Definition: rotatedellipse.h:25
float m_angle
Rotation angle.
Definition: rotatedellipse.h:28
float m_ry
y-radius.
Definition: rotatedellipse.h:27
float m_x
x-coordinate.
Definition: rotatedellipse.h:24
std::int32_t randomRange(const std::int32_t min, const std::int32_t max)
randomRange Returns a random integer in the range, inclusive. Uses thread-local random number generat...
Definition: commonutil.cpp:24
float m_rx
x-radius.
Definition: rotatedellipse.h:26

Here is the call graph for this function:

void geometrize::setup ( geometrize::RotatedRectangle s,
const std::int32_t  xBound,
const std::int32_t  yBound 
)
137 {
138  s.m_x1 = geometrize::commonutil::randomRange(0, xBound - 1);
139  s.m_y1 = geometrize::commonutil::randomRange(0, yBound - 1);
140  s.m_x2 = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_x1) + geometrize::commonutil::randomRange(1, 32), 0, xBound);
141  s.m_y2 = geometrize::commonutil::clamp(static_cast<std::int32_t>(s.m_y1) + geometrize::commonutil::randomRange(1, 32), 0, yBound);
143 }
float m_y2
Bottom coordinate.
Definition: rotatedrectangle.h:27
float m_x2
Right coordinate.
Definition: rotatedrectangle.h:26
T clamp(const T &value, const T &lower, const T &upper)
clamp Clamps a value within a range.
Definition: commonutil.h:41
float m_x1
Left coordinate.
Definition: rotatedrectangle.h:24
std::int32_t randomRange(const std::int32_t min, const std::int32_t max)
randomRange Returns a random integer in the range, inclusive. Uses thread-local random number generat...
Definition: commonutil.cpp:24
float m_y1
Top coordinate.
Definition: rotatedrectangle.h:25
float m_angle
Rotation angle.
Definition: rotatedrectangle.h:28

Here is the call graph for this function:

void geometrize::setup ( geometrize::Triangle s,
const std::int32_t  xBound,
const std::int32_t  yBound 
)
146 {
147  s.m_x1 = geometrize::commonutil::randomRange(0, xBound - 1);
148  s.m_y1 = geometrize::commonutil::randomRange(0, yBound - 1);
153 }
float m_y2
Second y-coordinate.
Definition: triangle.h:27
float m_x3
Third x-coordinate.
Definition: triangle.h:28
float m_y1
First y-coordinate.
Definition: triangle.h:25
float m_x2
Second x-coordinate.
Definition: triangle.h:26
float m_x1
First x-coordinate.
Definition: triangle.h:24
std::int32_t randomRange(const std::int32_t min, const std::int32_t max)
randomRange Returns a random integer in the range, inclusive. Uses thread-local random number generat...
Definition: commonutil.cpp:24
float m_y3
Third y-coordinate.
Definition: triangle.h:29

Here is the call graph for this function:

bool geometrize::shapeContains ( const geometrize::Shape container,
const geometrize::Shape containee,
const std::int32_t  xBound,
const std::int32_t  yBound 
)
415 {
416  return geometrize::scanlinesContain(rasterize(container, xBound, yBound), rasterize(containee, xBound, yBound));
417 }
bool scanlinesContain(const std::vector< geometrize::Scanline > &first, const std::vector< geometrize::Scanline > &second)
scanlinesContain Returns true if the first vector of scanlines wholly contain the second vector of sc...
Definition: rasterizer.cpp:389
std::vector< geometrize::Scanline > rasterize(const geometrize::Triangle &s, const std::int32_t xBound, const std::int32_t yBound)
Definition: rasterizer.cpp:365

Here is the call graph for this function:

bool geometrize::shapesOverlap ( const geometrize::Shape a,
const geometrize::Shape b,
const std::int32_t  xBound,
const std::int32_t  yBound 
)
410 {
411  return geometrize::scanlinesOverlap(geometrize::rasterize(a, xBound, yBound), geometrize::rasterize(b, xBound, yBound));
412 }
std::vector< geometrize::Scanline > rasterize(const geometrize::Shape &s, std::int32_t xBound, std::int32_t yBound)
Definition: rasterizer.cpp:194
bool scanlinesOverlap(const std::vector< geometrize::Scanline > &first, const std::vector< geometrize::Scanline > &second)
scanlinesOverlap Returns true if any of the scanlines from the first vector overlap the second ...
Definition: rasterizer.cpp:375

Here is the call graph for this function:

std::vector< std::pair< std::int32_t, std::int32_t > > geometrize::shapeToPixels ( const geometrize::Shape shape,
const std::uint32_t  xBound,
const std::uint32_t  yBound 
)
420 {
421  const auto scanlines = geometrize::rasterize(shape, static_cast<std::int32_t>(xBound), static_cast<std::int32_t>(yBound));
422  std::vector<std::pair<std::int32_t, std::int32_t>> points = {};
423  for(const auto& scanline : scanlines) {
424  for(std::int32_t x = scanline.x1; x < scanline.x2; x++) {
425  points.push_back({x, scanline.y});
426  }
427  }
428  return points;
429 }
std::vector< geometrize::Scanline > rasterize(const geometrize::Shape &s, std::int32_t xBound, std::int32_t yBound)
Definition: rasterizer.cpp:194

Here is the call graph for this function:

void geometrize::translate ( geometrize::Shape s,
const float  x,
const float  y 
)
384 {
385  switch(s.getType()) {
387  translate(static_cast<geometrize::Rectangle&>(s), x, y);
388  break;
390  translate(static_cast<geometrize::RotatedRectangle&>(s), x, y);
391  break;
393  translate(static_cast<geometrize::Triangle&>(s), x, y);
394  break;
396  translate(static_cast<geometrize::Ellipse&>(s), x, y);
397  break;
399  translate(static_cast<geometrize::RotatedEllipse&>(s), x, y);
400  break;
402  translate(static_cast<geometrize::Circle&>(s), x, y);
403  break;
405  translate(static_cast<geometrize::Line&>(s), x, y);
406  break;
408  translate(static_cast<geometrize::QuadraticBezier&>(s), x, y);
409  break;
411  translate(static_cast<geometrize::Polyline&>(s), x, y);
412  break;
413  default:
414  assert(0 && "Bad shape type");
415  }
416 }
Definition: shapetypes.h:26
void translate(geometrize::Triangle &s, const float x, const float y)
Definition: shapemutator.cpp:478
Definition: shapetypes.h:21
Definition: shapetypes.h:25
Definition: shapetypes.h:24
Definition: shapetypes.h:19
Definition: shapetypes.h:23
Definition: shapetypes.h:18
Definition: shapetypes.h:20
Definition: shapetypes.h:22
virtual geometrize::ShapeTypes getType() const
getType Gets the ShapeType of the shape.
Definition: shape.h:42

Here is the call graph for this function:

Here is the caller graph for this function:

void geometrize::translate ( geometrize::Circle s,
const float  x,
const float  y 
)
419 {
420  s.m_x += x;
421  s.m_y += y;
422 }
float m_x
x-coordinate.
Definition: circle.h:24
float m_y
y-coordinate.
Definition: circle.h:25
void geometrize::translate ( geometrize::Ellipse s,
const float  x,
const float  y 
)
425 {
426  s.m_x += x;
427  s.m_y += y;
428 }
float m_x
x-coordinate.
Definition: ellipse.h:24
float m_y
y-coordinate.
Definition: ellipse.h:25
void geometrize::translate ( geometrize::Line s,
const float  x,
const float  y 
)
431 {
432  s.m_x1 += x;
433  s.m_y1 += y;
434  s.m_x2 += x;
435  s.m_y2 += y;
436 }
float m_y2
Second y-coordinate.
Definition: line.h:27
float m_y1
First y-coordinate.
Definition: line.h:25
float m_x1
First x-coordinate.
Definition: line.h:24
float m_x2
Second x-coordinate.
Definition: line.h:26
void geometrize::translate ( geometrize::Polyline s,
const float  x,
const float  y 
)
439 {
440  for(auto& point : s.m_points) {
441  point.first += x;
442  point.second += y;
443  }
444 }
std::vector< std::pair< float, float > > m_points
The points on the polyline.
Definition: polyline.h:26
void geometrize::translate ( geometrize::QuadraticBezier s,
const float  x,
const float  y 
)
447 {
448  s.m_cx += x;
449  s.m_cy += y;
450  s.m_x1 += x;
451  s.m_y1 += y;
452  s.m_x2 += x;
453  s.m_y2 += y;
454 }
float m_x1
First x-coordinate.
Definition: quadraticbezier.h:26
float m_x2
Second x-coordinate.
Definition: quadraticbezier.h:28
float m_y1
First y-coordinate.
Definition: quadraticbezier.h:27
float m_cx
Control point x-coordinate.
Definition: quadraticbezier.h:24
float m_y2
Second y-coordinate.
Definition: quadraticbezier.h:29
float m_cy
Control point y-coordinate.
Definition: quadraticbezier.h:25
void geometrize::translate ( geometrize::Rectangle s,
const float  x,
const float  y 
)
457 {
458  s.m_x1 += x;
459  s.m_y1 += y;
460  s.m_x2 += x;
461  s.m_y2 += y;
462 }
float m_x1
Left coordinate.
Definition: rectangle.h:24
float m_y2
Bottom coordinate.
Definition: rectangle.h:27
float m_y1
Top coordinate.
Definition: rectangle.h:25
float m_x2
Right coordinate.
Definition: rectangle.h:26
void geometrize::translate ( geometrize::RotatedEllipse s,
const float  x,
const float  y 
)
465 {
466  s.m_x += x;
467  s.m_y += y;
468 }
float m_y
y-coordinate.
Definition: rotatedellipse.h:25
float m_x
x-coordinate.
Definition: rotatedellipse.h:24
void geometrize::translate ( geometrize::RotatedRectangle s,
const float  x,
const float  y 
)
471 {
472  s.m_x1 += x;
473  s.m_y1 += y;
474  s.m_x2 += x;
475  s.m_y2 += y;
476 }
float m_y2
Bottom coordinate.
Definition: rotatedrectangle.h:27
float m_x2
Right coordinate.
Definition: rotatedrectangle.h:26
float m_x1
Left coordinate.
Definition: rotatedrectangle.h:24
float m_y1
Top coordinate.
Definition: rotatedrectangle.h:25
void geometrize::translate ( geometrize::Triangle s,
const float  x,
const float  y 
)
479 {
480  s.m_x1 += x;
481  s.m_y1 += y;
482  s.m_x2 += x;
483  s.m_y2 += y;
484  s.m_x3 += x;
485  s.m_y3 += y;
486 }
float m_y2
Second y-coordinate.
Definition: triangle.h:27
float m_x3
Third x-coordinate.
Definition: triangle.h:28
float m_y1
First y-coordinate.
Definition: triangle.h:25
float m_x2
Second x-coordinate.
Definition: triangle.h:26
float m_x1
First x-coordinate.
Definition: triangle.h:24
float m_y3
Third y-coordinate.
Definition: triangle.h:29
std::vector< geometrize::Scanline > geometrize::trimScanlines ( const std::vector< geometrize::Scanline > &  scanlines,
std::uint32_t  w,
std::uint32_t  h 
)

trimScanlines Crops the scanning width of an array of scanlines so they do not scan outside of the given area.

Parameters
scanlinesThe scanlines to crop.
wThe width to crop.
hThe height to crop.
Returns
A new vector of cropped scanlines.
24 {
25  std::vector<geometrize::Scanline> trimmedScanlines;
26 
27  for(const geometrize::Scanline& line : scanlines) {
28  if(line.y < 0 || line.y >= static_cast<std::int32_t>(h)) {
29  continue;
30  }
31  if(line.x1 > line.x2) {
32  continue;
33  }
34  const float x1 = geometrize::commonutil::clamp(line.x1, 0, static_cast<std::int32_t>(w) - 1);
35  const float x2 = geometrize::commonutil::clamp(line.x2, 0, static_cast<std::int32_t>(w) - 1);
36  trimmedScanlines.emplace_back(Scanline(line.y, x1, x2));
37  }
38  return trimmedScanlines;
39 }
The Scanline class represents a scanline, a row of pixels running across a bitmap.
Definition: scanline.h:13
T clamp(const T &value, const T &lower, const T &upper)
clamp Clamps a value within a range.
Definition: commonutil.h:41

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

const std::array< ShapeTypes, static_cast< std::size_t >ShapeTypes::SHAPE_COUNT)> geometrize::allShapes
Initial value:
=
{
}
Definition: shapetypes.h:26
Definition: shapetypes.h:21
Definition: shapetypes.h:25
Definition: shapetypes.h:24
Definition: shapetypes.h:19
Definition: shapetypes.h:23
Definition: shapetypes.h:18
Definition: shapetypes.h:20
Definition: shapetypes.h:22

allShapes is a convenient array of all of the members of ShapeTypes.

const std::vector< std::pair< ShapeTypes, std::string > > geometrize::shapeTypeNames
Initial value:
=
{
{ ShapeTypes::RECTANGLE, "rectangle" },
{ ShapeTypes::ROTATED_RECTANGLE, "rotated_rectangle" },
{ ShapeTypes::TRIANGLE, "triangle" },
{ ShapeTypes::ELLIPSE, "ellipse" },
{ ShapeTypes::ROTATED_ELLIPSE, "rotated_ellipse" },
{ ShapeTypes::CIRCLE, "circle" },
{ ShapeTypes::LINE, "line" },
{ ShapeTypes::QUADRATIC_BEZIER, "quadratic_bezier" },
{ ShapeTypes::POLYLINE, "polyline" }
}
Definition: shapetypes.h:26
Definition: shapetypes.h:21
Definition: shapetypes.h:25
Definition: shapetypes.h:24
Definition: shapetypes.h:19
Definition: shapetypes.h:23
Definition: shapetypes.h:18
Definition: shapetypes.h:20
Definition: shapetypes.h:22

shapeTypeNames provides a convenient mapping to names of types of shape (all lower case, underscores instead of spaces e.g. rotated_ellipse).