diff --git a/Delynoi/include/Delynoi/config/DelynoiConfig.h b/Delynoi/include/Delynoi/config/DelynoiConfig.h index 0611459..43f848e 100644 --- a/Delynoi/include/Delynoi/config/DelynoiConfig.h +++ b/Delynoi/include/Delynoi/config/DelynoiConfig.h @@ -40,12 +40,12 @@ namespace Delynoi { /* * Deletes the copy constructor following the singleton pattern */ - DelynoiConfig(const DelynoiConfig &other) = delete; + DelynoiConfig(const DelynoiConfig &other) = delete; // NOLINT(*-use-equals-delete) /* * Deletes the assignment operator following the singleton pattern */ - DelynoiConfig &operator=(const DelynoiConfig ©) = delete; + DelynoiConfig &operator=(const DelynoiConfig ©) = delete; // NOLINT(*-use-equals-delete) public: /* diff --git a/Delynoi/include/Delynoi/models/Mesh.h b/Delynoi/include/Delynoi/models/Mesh.h index 0b4e1b1..d42fd20 100644 --- a/Delynoi/include/Delynoi/models/Mesh.h +++ b/Delynoi/include/Delynoi/models/Mesh.h @@ -1,13 +1,11 @@ #ifndef DELYNOI_MESH_H #define DELYNOI_MESH_H +#include #include #include -#include -#include #include #include -#include namespace Delynoi { /* @@ -56,7 +54,7 @@ namespace Delynoi { /* * Clear mesh data */ - void clear(); + void clear() const; /* Prints the mesh contents in a file stream * @param file file stream to print the mesh @@ -133,7 +131,7 @@ namespace Delynoi { * @param s segment to lookup * @return all incident polygons to s */ - NeighboursBySegment getNeighbours(IndexSegment s); + NeighboursBySegment getNeighbours(const IndexSegment &s) const; }; template @@ -149,6 +147,7 @@ namespace Delynoi { template Mesh::Mesh(UniqueList &p, std::vector &e, SegmentMap *s, PointMap *pM) { + // ReSharper disable once CppTemplateArgumentsCanBeDeduced this->points = UniqueList(p); this->polygons = e; this->edges = s; @@ -164,36 +163,36 @@ namespace Delynoi { } template - void Mesh::clear() { + void Mesh::clear() const { delete this->edges; delete this->pointMap; } template - void Mesh::createFromFile(const std::string &fileName, int startIndex) { + void Mesh::createFromFile(const std::string &fileName, const int startIndex) { std::ifstream infile = utilities::openFile(fileName); createFromStream(infile, startIndex); infile.close(); } template - void Mesh::createFromStream(std::ifstream &infile, int startIndex) { + void Mesh::createFromStream(std::ifstream &infile, const int startIndex) { if (this->edges == nullptr) this->edges = new SegmentMap; if (this->pointMap == nullptr) this->pointMap = new PointMap; std::string line; std::getline(infile, line); - int numberMeshPoints = std::atoi(line.c_str()); + const int numberMeshPoints = std::atoi(line.c_str()); // NOLINT(*-err34-c) for (int i = 0; i < numberMeshPoints; ++i) { std::getline(infile, line); std::vector splittedLine = utilities::splitBySpaces(line); - Point newPoint(std::atof(splittedLine[0].c_str()), std::atof(splittedLine[1].c_str())); + Point newPoint(std::atof(splittedLine[0].c_str()), std::atof(splittedLine[1].c_str())); // NOLINT(*-err34-c) this->points.push_back(newPoint); } std::getline(infile, line); - int numberMeshPolygons = std::atoi(line.c_str()); + const int numberMeshPolygons = std::atoi(line.c_str()); // NOLINT(*-err34-c) for (int i = 0; i < numberMeshPolygons; ++i) { std::getline(infile, line); @@ -201,7 +200,7 @@ namespace Delynoi { std::vector polygonPoints; for (int j = 1; j < splittedLine.size(); ++j) { - polygonPoints.push_back(std::atoi(splittedLine[j].c_str()) - startIndex); + polygonPoints.push_back(std::atoi(splittedLine[j].c_str()) - startIndex); // NOLINT(*-err34-c) } T newPolygon(polygonPoints, this->points.getList()); @@ -209,7 +208,7 @@ namespace Delynoi { std::vector segments; newPolygon.getSegments(segments); - for (IndexSegment s: segments) { + for (const IndexSegment &s: segments) { this->edges->insert(s, i); } } @@ -254,7 +253,7 @@ namespace Delynoi { if (this->edges != nullptr) { file << this->edges->size() << std::endl; - for (auto e: this->edges->getMap()) { + for (const auto &e: this->edges->getMap()) { IndexSegment edge = e.first; file << edge.getString() << std::endl; } @@ -292,7 +291,7 @@ namespace Delynoi { } template - NeighboursBySegment Mesh::getNeighbours(IndexSegment s) { + NeighboursBySegment Mesh::getNeighbours(const IndexSegment &s) const { return this->edges->get(s); } } // namespace Delynoi diff --git a/Delynoi/include/Delynoi/models/Region.h b/Delynoi/include/Delynoi/models/Region.h index 289736e..37b3f41 100644 --- a/Delynoi/include/Delynoi/models/Region.h +++ b/Delynoi/include/Delynoi/models/Region.h @@ -1,20 +1,10 @@ #ifndef DELYNOI_REGION_H #define DELYNOI_REGION_H -#pragma clang diagnostic push -#pragma ide diagnostic ignored "HidingNonVirtualFunction" - -#include -#include #include #include -#include -#include -#include #include -#include -#include -#include + #include namespace Delynoi { @@ -48,7 +38,7 @@ namespace Delynoi { /* * Constructor. */ - explicit Region(std::vector &points); + explicit Region(const std::vector &points); /* * Default constructor @@ -58,7 +48,7 @@ namespace Delynoi { /* * Constructor. Creates a region from a polygon instance and the list of mesh points */ - Region(const Polygon &other, std::vector &points); + Region(const Polygon &other, const std::vector &points); /* * Copy constructor. @@ -68,7 +58,7 @@ namespace Delynoi { /* Changes the points of the region (defining a new one), without changing the instance itself * @param points new points of the region */ - void mutate(std::vector &points); + void mutate(const std::vector &points); /* * @return list of seed points of the region @@ -102,7 +92,7 @@ namespace Delynoi { * @param nX number of points to create in the horizontal axis * @param nY number of points to create in the vertical axis */ - void generateSeedPoints(PointGenerator _p, int nX, int nY); + void generateSeedPoints(const PointGenerator &_p, int nX, int nY); /* Adds already seed points to the list * @param seeds list of points to add @@ -117,7 +107,7 @@ namespace Delynoi { /* * @return the axis oriented bounding box of the region */ - BoundingBox getBox(); + BoundingBox getBox() const; /* Sets the region segments in a vector * @param s vector where the segments will be assigned @@ -128,13 +118,13 @@ namespace Delynoi { * @param p point to check * @return whether the point is inside the region or not */ - bool containsPoint(Point _p); + bool containsPoint(const Point &_p) const; /* Checks if a given point is in the border of the region * @param p point to check * @return whether the point is in the boundary or not */ - bool inEdges(Point _p); + bool inEdges(const Point &_p) const; /* * Empties the seed point list @@ -153,5 +143,4 @@ namespace Delynoi { }; } // namespace Delynoi -#pragma clang diagnostic pop #endif diff --git a/Delynoi/include/Delynoi/models/basic/Angle.h b/Delynoi/include/Delynoi/models/basic/Angle.h index dd9af26..efc8b75 100644 --- a/Delynoi/include/Delynoi/models/basic/Angle.h +++ b/Delynoi/include/Delynoi/models/basic/Angle.h @@ -18,7 +18,7 @@ namespace Delynoi { * Constructor. Takes an angle value and obtains the equivalent between 0 and 180. */ explicit Angle(double a) { - a = a - 360.0 * int(a / 360); + a = a - 360.0 * static_cast(a / 360); if (a >= 0 && a < 180) { angle = a; } else { @@ -32,14 +32,14 @@ namespace Delynoi { * @return whether this angle is lesser than the given one */ bool operator<(const Angle &other) const { - DelynoiConfig *config = DelynoiConfig::instance(); + const DelynoiConfig *config = DelynoiConfig::instance(); if (std::abs(angle - other.angle) < config->getTolerance()) { return false; } return angle < other.angle; - }; + } }; } // namespace Delynoi diff --git a/Delynoi/include/Delynoi/models/basic/IndexSegment.h b/Delynoi/include/Delynoi/models/basic/IndexSegment.h index 8f06986..7c7a1f6 100644 --- a/Delynoi/include/Delynoi/models/basic/IndexSegment.h +++ b/Delynoi/include/Delynoi/models/basic/IndexSegment.h @@ -8,7 +8,7 @@ namespace Delynoi { /* * This class models a segment which endpoints are represented by their indexes in the mesh. */ - class IndexSegment : public Segment { + class IndexSegment final : public Segment { public: /* * Hash @@ -36,7 +36,7 @@ namespace Delynoi { * @param point to check * @return if the point is contained or not */ - bool contains(const std::vector &p, Point point); + bool contains(const std::vector &p, const Point &point) const; /* * Determines if a point is contained in the segment. @@ -44,19 +44,19 @@ namespace Delynoi { * @param point to check * @return if the point is contained or not */ - bool contains(const std::vector &p, const IndexSegment &s); + bool contains(const std::vector &p, const IndexSegment &s) const; /* * @param p mesh points * @return point in the middle of the segment */ - Point middlePoint(const std::vector &p); + Point middlePoint(const std::vector &p) const; /* * @param p mesh points * @return angle of the segment in degrees */ - double cartesianAngle(const std::vector &p); + double cartesianAngle(const std::vector &p) const; /* Determines whether two segments intersect or not. Sets the intersection point in the last argument. * @param p mesh points @@ -64,7 +64,7 @@ namespace Delynoi { * @param inter intersection point (only valid if segments intersect) * @return segments intersect or not */ - bool intersection(const std::vector &points, const PointSegment &other, Point &inter); + bool intersection(const std::vector &points, const PointSegment &other, Point &inter) const; /* Determines whether two segments intersect or not. Sets the intersection point in the last argument. * @param p mesh points @@ -72,27 +72,27 @@ namespace Delynoi { * @param inter intersection point (only valid if segments intersect) * @return segments intersect or not */ - bool intersection(const std::vector &points, const IndexSegment &other, Point &inter); + bool intersection(const std::vector &points, const IndexSegment &other, Point &inter) const; /* Determines a segment is contained in this one. * @param s segment to check * @param p mesh points * @return segment is contained or not */ - bool isContained(PointSegment s, const std::vector &p); + bool isContained(const PointSegment &s, const std::vector &p) const; /* Orders the segment in counter-clockwise order with respect a reference point. * @param points mesh points * @param reference point */ - void orderCCW(const std::vector &points, Point center); + void orderCCW(const std::vector &points, const Point ¢er); /* * @param points mesh points * @param center reference point * @return is the segment ordered in counter-clockwise order */ - bool isCCW(const std::vector &points, Point center); + bool isCCW(const std::vector &points, const Point ¢er) const; /* * Returns the string representation of the segment. @@ -116,12 +116,12 @@ namespace Delynoi { * @param points mesh points * @return length of the segment */ - double length(const std::vector &points); + double length(const std::vector &points) const; /* Displaces the segment. * @param o value of the segment displacement */ - IndexSegment add(int o); + IndexSegment add(int o) const; }; } // namespace Delynoi diff --git a/Delynoi/include/Delynoi/models/basic/Point.h b/Delynoi/include/Delynoi/models/basic/Point.h index 2467799..692d9d1 100644 --- a/Delynoi/include/Delynoi/models/basic/Point.h +++ b/Delynoi/include/Delynoi/models/basic/Point.h @@ -2,8 +2,6 @@ #define DELYNOI_POINT_H #include -#include -#include #include namespace Delynoi { diff --git a/Delynoi/include/Delynoi/models/basic/PointSegment.h b/Delynoi/include/Delynoi/models/basic/PointSegment.h index a799146..34ad14c 100644 --- a/Delynoi/include/Delynoi/models/basic/PointSegment.h +++ b/Delynoi/include/Delynoi/models/basic/PointSegment.h @@ -8,12 +8,12 @@ namespace Delynoi { /* * This class models a segment which endpoints are represented by the points directly. */ - class PointSegment : public Segment { + class PointSegment final : public Segment { public: /* * Constructor. Creates a segment with two endpoints. */ - PointSegment(Point p1, Point p2); + PointSegment(const Point &p1, const Point &p2); /* * Constructor. Creates an empty segment. @@ -23,14 +23,14 @@ namespace Delynoi { /* * @return the length of the segment */ - double length(); + double length() const; /* * Determines whether a point is contained in the segment. * @param point point to check * @return whether the point is contained or not */ - bool contains(Point point); + bool contains(const Point &point) const; /* * Returns the string representation of the segment. @@ -41,7 +41,7 @@ namespace Delynoi { /* * @return angle of the line segment in degrees. */ - double cartesianAngle(); + double cartesianAngle() const; /* Equality operator. * @param other segment to compare diff --git a/Delynoi/include/Delynoi/models/basic/Segment.h b/Delynoi/include/Delynoi/models/basic/Segment.h index ca23887..52cc6e2 100644 --- a/Delynoi/include/Delynoi/models/basic/Segment.h +++ b/Delynoi/include/Delynoi/models/basic/Segment.h @@ -1,10 +1,8 @@ +// ReSharper disable CppFunctionIsNotImplemented #ifndef DELYNOI_SEGMENT_H #define DELYNOI_SEGMENT_H -#include #include -#include -#include namespace Delynoi { /* @@ -22,7 +20,7 @@ namespace Delynoi { /* * @return the length of the segment */ - double length(Point _p1, Point _p2); + static double length(const Point &_p1, const Point &_p2); /* * Determines whether four points (defining two line segments) intersect or not, and set as the last value the intersection @@ -32,12 +30,12 @@ namespace Delynoi { * @param inter intersection point (only valid if segments intersect) * @return segments intersect or not */ - bool intersects(Point _p1, Point _p2, Point o1, Point o2, Point &inter); + static bool intersects(const Point &_p1, const Point &_p2, const Point &o1, const Point &o2, Point &inter); /* * @return angle of the line segment in degrees. */ - double cartesianAngle(Point _p1, Point _p2); + static double cartesianAngle(const Point &_p1, const Point &_p2); /* * Determines whether four points (defining two infinite lines) intersect or not (it is always the case unless they are parallel). @@ -55,9 +53,10 @@ namespace Delynoi { * @param p1 p2 points defining a segment * @return whether the point is contained or not */ - bool contains(Point point, Point _p1, Point _p2); + bool contains(const Point &point, const Point &_p1, const Point &_p2) const; public: + virtual ~Segment() = default; /* * Constructor. Empty segment. */ diff --git a/Delynoi/include/Delynoi/models/generator/Functor.h b/Delynoi/include/Delynoi/models/generator/Functor.h index 1171b9e..0e367d3 100644 --- a/Delynoi/include/Delynoi/models/generator/Functor.h +++ b/Delynoi/include/Delynoi/models/generator/Functor.h @@ -7,6 +7,7 @@ namespace Delynoi { */ class Functor { public: + virtual ~Functor() = default; /* * Applies the function on a number * @param x parameter of the function diff --git a/Delynoi/include/Delynoi/models/generator/PointGenerator.h b/Delynoi/include/Delynoi/models/generator/PointGenerator.h index c62f585..84c45b7 100644 --- a/Delynoi/include/Delynoi/models/generator/PointGenerator.h +++ b/Delynoi/include/Delynoi/models/generator/PointGenerator.h @@ -11,7 +11,7 @@ namespace Delynoi { /* * Class in charge of keeping the generator functions and applying them on all points generated. */ - class PointGenerator { + class PointGenerator final { private: /* * Function classes that will be used to generate the points values @@ -31,7 +31,7 @@ namespace Delynoi { * @param x y base coordinates to generate the point * @return generated point */ - Point result(double x, double y); + Point result(double x, double y) const; public: /* @@ -58,7 +58,7 @@ namespace Delynoi { * @param nX number of points in the horizontal axis * @param nY number of points in the vertical axis */ - virtual void generate(std::vector &vector, BoundingBox box, int nX, int nY); + void generate(std::vector &vector, const BoundingBox &box, int nX, int nY) const; }; } // namespace Delynoi diff --git a/Delynoi/include/Delynoi/models/generator/functions/RandomDouble.h b/Delynoi/include/Delynoi/models/generator/functions/RandomDouble.h index fa4bf5b..8602cf3 100644 --- a/Delynoi/include/Delynoi/models/generator/functions/RandomDouble.h +++ b/Delynoi/include/Delynoi/models/generator/functions/RandomDouble.h @@ -8,7 +8,7 @@ namespace Delynoi { /* * Generates random double numbers. */ - class Random_Double : public Functor { + class Random_Double final : public Functor { public: /* * Parameters for the number generation. Maximum and minimum possible values. @@ -21,7 +21,7 @@ namespace Delynoi { */ static std::default_random_engine rd; static std::mt19937 rng; - std::uniform_real_distribution uni; + std::uniform_real_distribution<> uni; /* * Constructor. diff --git a/Delynoi/include/Delynoi/models/generator/functions/RandomInteger.h b/Delynoi/include/Delynoi/models/generator/functions/RandomInteger.h index 650a685..8768c4b 100644 --- a/Delynoi/include/Delynoi/models/generator/functions/RandomInteger.h +++ b/Delynoi/include/Delynoi/models/generator/functions/RandomInteger.h @@ -8,7 +8,7 @@ namespace Delynoi { /* * Generates random integer numbers. */ - class Random_Integer : public Functor { + class Random_Integer final : public Functor { private: /* * Parameters for the number generation. Maximum and minimum possible values. @@ -21,7 +21,7 @@ namespace Delynoi { */ static std::default_random_engine rd; static std::mt19937 rng; - std::uniform_int_distribution uni; + std::uniform_int_distribution<> uni; public: /* diff --git a/Delynoi/include/Delynoi/models/generator/functions/functions.h b/Delynoi/include/Delynoi/models/generator/functions/functions.h index 56f5b32..f4e5280 100644 --- a/Delynoi/include/Delynoi/models/generator/functions/functions.h +++ b/Delynoi/include/Delynoi/models/generator/functions/functions.h @@ -3,73 +3,71 @@ #include -namespace Delynoi { +/* + * Namespace with all generator functions definitions. + */ +namespace Delynoi::functions { /* - * Namespace with all generator functions definitions. + * Defines the different options for the Fucntion classes variables. */ - namespace functions { - /* - * Defines the different options for the Fucntion classes variables. - */ - enum independent_variable { - x, - y, - both - }; + enum independent_variable { + x, + y, + both + }; - /* Creates a class that given a coordinate, returns the same value. - * @return an instance of a Constant class. - */ - Functor *constant(); + /* Creates a class that given a coordinate, returns the same value. + * @return an instance of a Constant class. + */ + Functor *constant(); - /* Creates a class that given a coordinate, displace every even point the given value. - * @param delta value to displace the points - * @return an instance of a DisplacePoints class. - */ - Functor *displace_points(double delta); + /* Creates a class that given a coordinate, displace every even point the given value. + * @param delta value to displace the points + * @return an instance of a DisplacePoints class. + */ + Functor *displace_points(double delta); - /* Creates a class that given a coordinate, returns all the first batch constant, and the second displaced - * by half the difference between the elements of the first batch. - * @return an instance of the ConstantAlternating class - */ - Functor *constantAlternating(); + /* Creates a class that given a coordinate, returns all the first batch constant, and the second displaced + * by half the difference between the elements of the first batch. + * @return an instance of the ConstantAlternating class + */ + Functor *constantAlternating(); - /* Creates a class that given a coordinate, it multiplies its value by delta. - * @param delta value to multiplicate each coordinate - * @return an instance of the Uniform class - */ - Functor *uniform(double delta); + /* Creates a class that given a coordinate, it multiplies its value by delta. + * @param delta value to multiplicate each coordinate + * @return an instance of the Uniform class + */ + Functor *uniform(double delta); - /* Creates a class that generates random integer numbers in the interval (min,max) - * @param min minimum value to generate - * @param max maximum value to generate - * @return an instance of the RandomInteger class - */ - Functor *random_integer(double min, double max); + /* Creates a class that generates random integer numbers in the interval (min,max) + * @param min minimum value to generate + * @param max maximum value to generate + * @return an instance of the RandomInteger class + */ + Functor *random_integer(double min, double max); - /* Creates a class that generates random double numbers in the interval (min,max) - * @param min minimum value to generate - * @param max maximum value to generate - * @return an instance of the RandomDouble class - */ - Functor *random_double(double min, double max); + /* Creates a class that generates random double numbers in the interval (min,max) + * @param min minimum value to generate + * @param max maximum value to generate + * @return an instance of the RandomDouble class + */ + Functor *random_double(double min, double max); - /* Creates a class that generates number following a sine curve, of the form amplitude*sin(frecuency*value + phase) - * @param amplitude amplitude value of the function - * @param frecuency frecuency value - * @param phase value - * @return an instance of the Sine class - */ - Functor *sine(double amplitude, double frecuency, double phase); + /* Creates a class that generates number following a sine curve, of the form amplitude*sin(frecuency*value + phase) + * @param amplitude amplitude value of the function + * @param frecuency frecuency value + * @param phase value + * @return an instance of the Sine class + */ + Functor *sine(double amplitude, double frecuency, double phase); - /* Creates a class that generates number following a cosine curve, of the form amplitude*cos(frecuency*value + phase) - * @param amplitude amplitude value of the function - * @param frecuency frecuency value - * @param phase value - * @return an instance of the Cosine class - */ - Functor *cosine(double amplitude, double frecuency, double phase); - } // namespace functions -} // namespace Delynoi + /* Creates a class that generates number following a cosine curve, of the form amplitude*cos(frecuency*value + phase) + * @param amplitude amplitude value of the function + * @param frecuency frecuency value + * @param phase value + * @return an instance of the Cosine class + */ + Functor *cosine(double amplitude, double frecuency, double phase); +} // namespace Delynoi::functions #endif diff --git a/Delynoi/include/Delynoi/models/generator/noise/RandomDoubleNoise.h b/Delynoi/include/Delynoi/models/generator/noise/RandomDoubleNoise.h index 24a409f..39ab4d5 100644 --- a/Delynoi/include/Delynoi/models/generator/noise/RandomDoubleNoise.h +++ b/Delynoi/include/Delynoi/models/generator/noise/RandomDoubleNoise.h @@ -2,14 +2,13 @@ #define DELYNOI_RANDOMDOUBLENOISE_H #include -#include #include namespace Delynoi { /* * Generates random double noise and applies it to a given Function class. */ - class RandomDoubleNoise : public Functor { + class RandomDoubleNoise final : public Functor { private: /* * Parameters for noise generation. Maximum and minimum possible noise value. Note that there is no constraint in @@ -28,8 +27,8 @@ namespace Delynoi { */ static std::default_random_engine rd; static std::mt19937 rng; - std::uniform_real_distribution uni; - std::uniform_int_distribution uni_int; + std::uniform_real_distribution<> uni; + std::uniform_int_distribution<> uni_int; public: /* diff --git a/Delynoi/include/Delynoi/models/generator/noise/RandomIntegerNoise.h b/Delynoi/include/Delynoi/models/generator/noise/RandomIntegerNoise.h index a365e0e..bd23ded 100644 --- a/Delynoi/include/Delynoi/models/generator/noise/RandomIntegerNoise.h +++ b/Delynoi/include/Delynoi/models/generator/noise/RandomIntegerNoise.h @@ -8,7 +8,7 @@ namespace Delynoi { /* * Generates random integer noise and applies it to a given Function class. */ - class RandomIntegerNoise : public Functor { + class RandomIntegerNoise final : public Functor { private: /* * Parameters for noise generation. Maximum and minimum possible noise value. Note that there is no constraint in @@ -27,7 +27,7 @@ namespace Delynoi { */ static std::default_random_engine rd; static std::mt19937 rng; - std::uniform_int_distribution uni; + std::uniform_int_distribution<> uni; public: /* diff --git a/Delynoi/include/Delynoi/models/hole/CircularHole.h b/Delynoi/include/Delynoi/models/hole/CircularHole.h index ff5c790..a1f7cb2 100644 --- a/Delynoi/include/Delynoi/models/hole/CircularHole.h +++ b/Delynoi/include/Delynoi/models/hole/CircularHole.h @@ -2,17 +2,14 @@ #define DELYNOI_CIRCULARHOLE_H #include -#include #include #include -#include -#include namespace Delynoi { /* * Class modeling a circular hole. */ - class CircularHole : public Hole, public Circle { + class CircularHole final : public Hole, public Circle { private: /* * Calculates the segments of the hole based on the radius and center of the circle. @@ -23,7 +20,7 @@ namespace Delynoi { /* * Constructor. */ - CircularHole(Point p, double r); + CircularHole(const Point &p, double r); }; } // namespace Delynoi diff --git a/Delynoi/include/Delynoi/models/hole/Hole.h b/Delynoi/include/Delynoi/models/hole/Hole.h index f8ab933..10d4ec0 100644 --- a/Delynoi/include/Delynoi/models/hole/Hole.h +++ b/Delynoi/include/Delynoi/models/hole/Hole.h @@ -20,6 +20,7 @@ namespace Delynoi { std::vector segments; public: + virtual ~Hole() = default; /* * Default constructor. */ @@ -28,7 +29,7 @@ namespace Delynoi { /* * Constructor. */ - Hole(std::vector points, Point center, std::vector seg) { + Hole(std::vector points, const Point ¢er, std::vector seg) { this->center = center; this->HolePoints.assign(points.begin(), points.end()); this->segments.assign(seg.begin(), seg.end()); @@ -48,30 +49,30 @@ namespace Delynoi { */ virtual Point getCenter() { return this->center; - }; + } /* * @param s vector in which the hole segments will be set * @param offset value to add to the segment (representing that the hole could belong in a mesh with many points) */ - void getSegments(std::vector &s, int offset) { - for (IndexSegment seg: this->segments) { + void getSegments(std::vector &s, const int offset) { + for (const IndexSegment &seg: this->segments) { s.push_back(seg.add(offset)); } - }; + } /* * @return list of points defining the hole */ virtual std::vector getPoints() { return this->HolePoints; - }; + } /* Checks if a point is inside the hole * @param p point to check * @return if the point is inside the hole or not */ - bool containsPoint(Point point) { + bool containsPoint(const Point &point) { int j = HolePoints.size() - 1; bool oddNodes = false; @@ -107,7 +108,7 @@ namespace Delynoi { } return container.getFirst() != -1 && container.getSecond() != -1; - }; + } }; } // namespace Delynoi diff --git a/Delynoi/include/Delynoi/models/hole/PolygonalHole.h b/Delynoi/include/Delynoi/models/hole/PolygonalHole.h index d0a18d4..9f77707 100644 --- a/Delynoi/include/Delynoi/models/hole/PolygonalHole.h +++ b/Delynoi/include/Delynoi/models/hole/PolygonalHole.h @@ -9,7 +9,7 @@ namespace Delynoi { /* * Class modeling a polygonal hole. */ - class PolygonalHole : public Hole, public Polygon { + class PolygonalHole final : public Hole, public Polygon { public: /* * Constructor. diff --git a/Delynoi/include/Delynoi/models/hole/clipper/ClipperWrapper.h b/Delynoi/include/Delynoi/models/hole/clipper/ClipperWrapper.h index 99e6fa0..1b1b307 100644 --- a/Delynoi/include/Delynoi/models/hole/clipper/ClipperWrapper.h +++ b/Delynoi/include/Delynoi/models/hole/clipper/ClipperWrapper.h @@ -3,7 +3,6 @@ #include #include -#include namespace Delynoi { /* @@ -15,7 +14,7 @@ namespace Delynoi { /* * Scales a point (which has double precision coordinates) to an integer, using the given scale. */ - static ClipperLib::IntPoint scalePoint(Point point, int maxScale); + static ClipperLib::IntPoint scalePoint(const Point &point, int maxScale); public: /* Computes the intersection between two polygons using Clipper diff --git a/Delynoi/include/Delynoi/models/neighbourhood/EdgeData.h b/Delynoi/include/Delynoi/models/neighbourhood/EdgeData.h index 6828e53..6bc4f03 100644 --- a/Delynoi/include/Delynoi/models/neighbourhood/EdgeData.h +++ b/Delynoi/include/Delynoi/models/neighbourhood/EdgeData.h @@ -2,7 +2,6 @@ #define DELYNOI_EDGEDATA_H #include -#include namespace Delynoi { /* diff --git a/Delynoi/include/Delynoi/models/neighbourhood/NeighboursBySegment.h b/Delynoi/include/Delynoi/models/neighbourhood/NeighboursBySegment.h index 9d434ee..958856f 100644 --- a/Delynoi/include/Delynoi/models/neighbourhood/NeighboursBySegment.h +++ b/Delynoi/include/Delynoi/models/neighbourhood/NeighboursBySegment.h @@ -2,7 +2,6 @@ #define DELYNOI_NEIGHBOURS_H #include -#include namespace Delynoi { /* diff --git a/Delynoi/include/Delynoi/models/neighbourhood/PointMap.h b/Delynoi/include/Delynoi/models/neighbourhood/PointMap.h index 9427046..03546db 100644 --- a/Delynoi/include/Delynoi/models/neighbourhood/PointMap.h +++ b/Delynoi/include/Delynoi/models/neighbourhood/PointMap.h @@ -3,7 +3,6 @@ #include #include -#include #include #include @@ -42,13 +41,13 @@ namespace Delynoi { * @param p point to insert * @param neighbours list of the indexes of polygons that contain the point */ - void insert(Point &p, std::vector &neighbours); + void insert(Point &p, const std::vector &neighbours); /* * @param p point to lookup * @return all polygons that contain point p */ - NeighboursByPoint &get(Point p); + NeighboursByPoint &get(const Point &p); /* * @return map that contains all relationship information @@ -58,17 +57,17 @@ namespace Delynoi { /* * @return number of elements of the map */ - int size(); + int size() const; /* Prints the map to a file relative to user path * @param fileName name of the file to print */ - void printInFile(const std::string &fileName); + void printInFile(const std::string &fileName) const; /* Prints the map to a file relative to absolute path * @param fileName name of the file to print */ - void printInPath(const std::string &path); + void printInPath(const std::string &path) const; }; } // namespace Delynoi diff --git a/Delynoi/include/Delynoi/models/neighbourhood/SegmentMap.h b/Delynoi/include/Delynoi/models/neighbourhood/SegmentMap.h index 5c6a417..3be2189 100644 --- a/Delynoi/include/Delynoi/models/neighbourhood/SegmentMap.h +++ b/Delynoi/include/Delynoi/models/neighbourhood/SegmentMap.h @@ -3,7 +3,6 @@ #include #include -#include #include #include #include @@ -71,17 +70,17 @@ namespace Delynoi { /* * @return number of elements on the map */ - int size(); + int size() const; /* Prints the map information in a file relative to user path * @param fileName name of the file to print */ - void printInFile(const std::string &fileName); + void printInFile(const std::string &fileName) const; /* Prints the map information in a file relative to absolute path * @param fileName name of the file to print */ - void printInPath(const std::string &path); + void printInPath(const std::string &path) const; /* Checks if a given segment is in the map * @param s segment to check diff --git a/Delynoi/include/Delynoi/models/polygon/BoundingBox.h b/Delynoi/include/Delynoi/models/polygon/BoundingBox.h index 9028223..1023f03 100644 --- a/Delynoi/include/Delynoi/models/polygon/BoundingBox.h +++ b/Delynoi/include/Delynoi/models/polygon/BoundingBox.h @@ -20,7 +20,7 @@ namespace Delynoi { /* * Constructor */ - BoundingBox(Point p1, Point p2); + BoundingBox(const Point &p1, const Point &p2); /* * @return the first corner of the bounding box @@ -35,32 +35,32 @@ namespace Delynoi { /* * @return width of the box */ - double getWidth(); + double getWidth() const; /* * @return height of the box */ - double getHeight(); + double getHeight() const; /* * @return x-axis value of the left side of the box */ - double xMin(); + double xMin() const; /* * @return y-axis value of the bottom side of the box */ - double yMin(); + double yMin() const; /* * @return x-axis value of the right side of the box */ - double xMax(); + double xMax() const; /* * @return y-axis value of the top side of the box */ - double yMax(); + double yMax() const; /* Equality operator * @param @@ -72,7 +72,7 @@ namespace Delynoi { * @param p point to check * @return whether the point is inside the box or not */ - bool contains(Point p); + bool contains(const Point &p) const; /* Fills a vector with the segments of the box * @param segments vector in which the segments of the box will be kept diff --git a/Delynoi/include/Delynoi/models/polygon/Circle.h b/Delynoi/include/Delynoi/models/polygon/Circle.h index f1df0d9..0dcf5a8 100644 --- a/Delynoi/include/Delynoi/models/polygon/Circle.h +++ b/Delynoi/include/Delynoi/models/polygon/Circle.h @@ -2,10 +2,6 @@ #define DELYNOI_CIRCLE_H #include -#include -#include -#include -#include #include namespace Delynoi { @@ -27,12 +23,12 @@ namespace Delynoi { /* * Constructor */ - Circle(double r, Point c); + Circle(double r, const Point &c); /* Generates points that represent the boundary of the circle * @return list of points that model the circle boundary */ - std::vector discretizeCircle(); + std::vector discretizeCircle() const; }; } // namespace Delynoi diff --git a/Delynoi/include/Delynoi/models/polygon/Polygon.h b/Delynoi/include/Delynoi/models/polygon/Polygon.h index 08ee913..0499cb4 100644 --- a/Delynoi/include/Delynoi/models/polygon/Polygon.h +++ b/Delynoi/include/Delynoi/models/polygon/Polygon.h @@ -3,15 +3,7 @@ #include #include -#include -#include -#include -#include -#include -#include -#include #include -#include #include namespace Delynoi { @@ -42,13 +34,13 @@ namespace Delynoi { * @param p mesh points * @return polygon area */ - double calculateArea(std::vector &p); + double calculateArea(const std::vector &p) const; /* Calculates the polygon centroid * @param p mesh points * @return polygon centroid */ - Point calculateCentroid(std::vector &p); + Point calculateCentroid(const std::vector &p) const; /* * Calculates the polygon hash value @@ -59,12 +51,12 @@ namespace Delynoi { /* * Constructor. Receives a list of point indexes and the mesh points to create the polygon */ - Polygon(std::vector &points, std::vector &p); + Polygon(std::vector &points, const std::vector &p); /* * Constructor. Receives a list of points representing the polygon */ - explicit Polygon(std::vector &p); + explicit Polygon(const std::vector &p); /* * Copy constructor. @@ -79,22 +71,22 @@ namespace Delynoi { /* * @return polygon diameter */ - double getDiameter(std::vector &_points); + double getDiameter(const std::vector &_points); /* * @return polygon area */ - double getArea(std::vector &_points); + double getArea(const std::vector &_points); /* * @return polygon centroid */ - Point getCentroid(std::vector &_points); + Point getCentroid(const std::vector &_points); /* Gets the polygon segments and set them in the given vector * @param segments vector that will contain the segments */ - void getSegments(std::vector &segments); + void getSegments(std::vector &segments) const; /* * @return polygon points indexes list @@ -110,7 +102,7 @@ namespace Delynoi { * @param p mesh points * @return polygon point list (Point instances, not their indexes) */ - std::vector getPoints(std::vector &p); + std::vector getPoints(const std::vector &p); /* * @return number of sides of the polygon @@ -140,45 +132,45 @@ namespace Delynoi { /* Changes the points defining the polygon, changing the value of the object without destroying this instance * @param p points to assign to this polygon */ - void mutate(std::vector &p); + void mutate(const std::vector &p); /* Determines if a point is inside the polygon * @param p mesh points * @param point point to check * @return whether the point is inside the polygon or not */ - bool containsPoint(std::vector &p, Point point); + bool containsPoint(const std::vector &p, const Point &point) const; /* Determines if a point is in the border of the polygon * @param p mesh points * @param point point to check * @return whether the point is in the border of the polygon or not */ - bool inEdges(std::vector &p, Point point); + bool inEdges(const std::vector &p, const Point &point) const; /* Calculates the signed area of the polygon (using the counter-clockwise rule) * @param p mesh points * @return signed polygon area */ - double signedArea(std::vector &p); + double signedArea(const std::vector &p) const; /* Checks if a segment is part of the polygon * @param s segment to check * @return if the segment is part of the polygon */ - bool containsEdge(IndexSegment &s); + bool containsEdge(const IndexSegment &s) const; /* Checks if the polygon is convex * @param p mesh points * @return if the polygon is convex or not */ - bool isConvex(std::vector &p); + bool isConvex(const std::vector &p) const; /* Checks if the polygon points are counter or clockwise checking the signed area of the points * @param p mesh points * @return if the points are ordered clockwise or not */ - bool isClockwise(std::vector &p); + bool isClockwise(const std::vector &p) const; /* Checks if a given point index is part of the polygon (is a vertex) * @param index point index to check @@ -190,7 +182,7 @@ namespace Delynoi { * @param points mesh points * @return if the polygon is self-intersecting */ - bool isSelfIntersecting(std::vector &_points); + bool isSelfIntersecting(const std::vector &_points) const; /* * Hash value of the polygon (calculated using the indexes of the points) @@ -201,26 +193,26 @@ namespace Delynoi { * case. * @param p mesh points */ - void fixCCW(std::vector &p); + void fixCCW(const std::vector &p); /* Finds the segment of the polygon that contains a given point * @param p mesh points * @param point point to use * @return segment that contains point */ - IndexSegment containerEdge(std::vector &p, Point point); + IndexSegment containerEdge(const std::vector &p, const Point &point) const; /* Gets the average vertex value of the polygon * @param p mesh points * @return average point */ - Point getAverage(std::vector &p); + Point getAverage(const std::vector &p); /* Computes the maximum distance between any two vertexes of the polygon * @param points mesh points * @return max distance between points of the polygon */ - double getMaxDistance(std::vector &points); + double getMaxDistance(const std::vector &points) const; }; } // namespace Delynoi diff --git a/Delynoi/include/Delynoi/models/polygon/Triangle.h b/Delynoi/include/Delynoi/models/polygon/Triangle.h index 7f27047..35a64e8 100644 --- a/Delynoi/include/Delynoi/models/polygon/Triangle.h +++ b/Delynoi/include/Delynoi/models/polygon/Triangle.h @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -24,7 +25,7 @@ namespace Delynoi { * @param p mesh points * @return triangle circumcenter */ - Point calculateCircumcenter(std::vector &p); + Point calculateCircumcenter(const std::vector &p) const; public: /* @@ -35,16 +36,16 @@ namespace Delynoi { /* * Constructor */ - Triangle(std::vector points, std::vector &p); + Triangle(std::vector points, const std::vector &p); - Triangle(std::vector points, std::vector &p, UniqueList &circumcenters); + Triangle(std::vector points, const std::vector &p, UniqueList &circumcenters); - Triangle(std::vector points, std::vector &p, std::vector &circumcenters); + Triangle(std::vector points, const std::vector &p, std::vector &circumcenters); /* * @return circumcenter of the triangle */ - Point getCircumcenter(); + Point getCircumcenter() const; int getCircumcenterIndex() const; @@ -56,19 +57,19 @@ namespace Delynoi { * @param edgeMap map with the information relating edge endpoints and EdgeData indexes * @return index of the next EdgeData for the Voronoi diagram computation */ - int nextEdge(int center, EdgeData edge, std::unordered_map &edgeMap); + int nextEdge(int center, EdgeData edge, std::unordered_map &edgeMap) const; /* * Given an edge, it determines the point of the triangle not contained in it * @param edge edge to operate on * @return index (in the mesh points list) of the point not contained in the edge */ - int thirdPoint(EdgeData edge); + int thirdPoint(EdgeData edge) const; /* * @return is the triangle valid (have its endpoints been set) */ - bool isNull(); + bool isNull() const; }; } // namespace Delynoi diff --git a/Delynoi/include/Delynoi/triangulation/CenterTriangulationGenerator.h b/Delynoi/include/Delynoi/triangulation/CenterTriangulationGenerator.h index 0f5f007..c95d00f 100644 --- a/Delynoi/include/Delynoi/triangulation/CenterTriangulationGenerator.h +++ b/Delynoi/include/Delynoi/triangulation/CenterTriangulationGenerator.h @@ -7,7 +7,7 @@ namespace Delynoi { /* * Class that triangulates a Polygon (necessarily convex) using its geometrical center. */ - class CenterTriangulationGenerator : public TriangulationGenerator { + class CenterTriangulationGenerator final : public TriangulationGenerator { public: /* Triangulates a polygon. * @param p polygon to triangulate diff --git a/Delynoi/include/Delynoi/triangulation/DelaunayTriangulationGenerator.h b/Delynoi/include/Delynoi/triangulation/DelaunayTriangulationGenerator.h index 3db4418..61fa824 100644 --- a/Delynoi/include/Delynoi/triangulation/DelaunayTriangulationGenerator.h +++ b/Delynoi/include/Delynoi/triangulation/DelaunayTriangulationGenerator.h @@ -9,7 +9,7 @@ namespace Delynoi { /* * Class that trriangulates a Polygon using its Delaunay triangulation. */ - class DelaunayTriangulationGenerator : public TriangulationGenerator { + class DelaunayTriangulationGenerator final : public TriangulationGenerator { public: /* Triangulates a polygon. * @param p polygon to triangulate diff --git a/Delynoi/include/Delynoi/triangulation/EarTriangulationGenerator.h b/Delynoi/include/Delynoi/triangulation/EarTriangulationGenerator.h index 899af77..12e26c2 100644 --- a/Delynoi/include/Delynoi/triangulation/EarTriangulationGenerator.h +++ b/Delynoi/include/Delynoi/triangulation/EarTriangulationGenerator.h @@ -7,14 +7,14 @@ namespace Delynoi { /* * Class that triangulates a polygon using the classic ear triangulation scheme. */ - class EarTriangulationGenerator : public TriangulationGenerator { + class EarTriangulationGenerator final : public TriangulationGenerator { private: /* Gets an independant ear out of the polygon * @param point mesh points * @param pointList list of points of the polygon * @return a triangle (an ear of the polygon) */ - static Triangle getEar(std::vector &points, std::vector &pointList); + static Triangle getEar(const std::vector &points, std::vector &pointList); public: /* Triangulates a polygon. diff --git a/Delynoi/include/Delynoi/triangulation/TriangulationGenerator.h b/Delynoi/include/Delynoi/triangulation/TriangulationGenerator.h index 4080398..e2e5c0f 100644 --- a/Delynoi/include/Delynoi/triangulation/TriangulationGenerator.h +++ b/Delynoi/include/Delynoi/triangulation/TriangulationGenerator.h @@ -1,9 +1,6 @@ #ifndef DELYNOI_TRIANGULATIONGENERATOR_H #define DELYNOI_TRIANGULATIONGENERATOR_H -#pragma clang diagnostic push -#pragma ide diagnostic ignored "UnusedParameter" - #include #include @@ -21,11 +18,13 @@ namespace Delynoi { */ virtual std::vector triangulate(Polygon p, std::vector &points) = 0; - std::vector triangulate(Triangle p, std::vector &points) { + virtual ~TriangulationGenerator() = default; + + // ReSharper disable once CppMemberFunctionMayBeStatic + std::vector triangulate(Triangle p, [[maybe_unused]] std::vector &points) { return {std::move(p)}; } }; } // namespace Delynoi -#pragma clang diagnostic pop #endif diff --git a/Delynoi/include/Delynoi/utilities/convexHull.h b/Delynoi/include/Delynoi/utilities/convexHull.h index d5640b3..a6a2be9 100644 --- a/Delynoi/include/Delynoi/utilities/convexHull.h +++ b/Delynoi/include/Delynoi/utilities/convexHull.h @@ -3,24 +3,22 @@ #include -namespace Delynoi { - /* - * Namespace that contains all functions related to the computation of the convex hull. +/* + * Namespace that contains all functions related to the computation of the convex hull. + */ +namespace Delynoi::convex { + /* Computes the convex hull of a set of points + * @param points list of points which convex hull will be calculated + * @param u list of points defining the upper convex hull + * @param l list of points defining the lower convex hull */ - namespace convex { - /* Computes the convex hull of a set of points - * @param points list of points which convex hull will be calculated - * @param u list of points defining the upper convex hull - * @param l list of points defining the lower convex hull - */ - extern void convexHull(std::vector &points, std::vector &u, std::vector &l); + extern void convexHull(std::vector &points, std::vector &u, std::vector &l); - /* Computes the pair of antipodal pairs of the points, through the rotating callipers algorithm - * @param points point that will be processed - * @return the list of antipodal pairs - */ - extern std::vector> rotatingCalipers(std::vector &points); - } // namespace convex -} // namespace Delynoi + /* Computes the pair of antipodal pairs of the points, through the rotating callipers algorithm + * @param points point that will be processed + * @return the list of antipodal pairs + */ + extern std::vector> rotatingCalipers(std::vector &points); +} // namespace Delynoi::convex #endif diff --git a/Delynoi/include/Delynoi/utilities/delynoi_utilities.h b/Delynoi/include/Delynoi/utilities/delynoi_utilities.h index e8d2a5c..9812c0e 100644 --- a/Delynoi/include/Delynoi/utilities/delynoi_utilities.h +++ b/Delynoi/include/Delynoi/utilities/delynoi_utilities.h @@ -2,60 +2,56 @@ #define DELYNOI_DELYNOIUTILITIES_H #include -#include -#include #include -namespace Delynoi { +/* + * Namespace that includes common geometric utilities of the Delynoi library. + */ +namespace Delynoi::delynoi_utilities { /* - * Namespace that includes common geometric utilities of the Delynoi library. + * Returns the trivial vector of indexes of length n (0,1,2...,n-1) + * @param index_vector vector that will be set with the trivial vector + * @param n length of the generated vector */ - namespace delynoi_utilities { - /* - * Returns the trivial vector of indexes of length n (0,1,2...,n-1) - * @param index_vector vector that will be set with the trivial vector - * @param n length of the generated vector - */ - extern void TrivialIndexVector(std::vector &index_vector, int n); - - /* Computes the cross product of two points - * @param a b points to operate - * @return result of the operation - */ - extern double crossProduct(Point a, Point b); - - /* Computes the norm of a point (basically, a vector starting from the origin) - * @param p point which norm will be calculated - * @return norm of the point - */ - extern double norm(Point p); - - /*Computes the square of the norm of a point (basically, a vector starting from the origin) - * @param p point which square norm will be calculated - * @return norm of the point - */ - extern double squareNorm(Point p); - - /* Determines the orientation of three points (counter clockwise or clockwise) - * @param p q r points to operate - * @return whether the points are oriented counter clockwise (positive) or clockwise (negative) - */ - extern double orientation(Point p, Point q, Point r); - - /* Creates a number of points that discretize a circle arc - * @param center center of the circle - * @param radius radius of the circle - * @param initAngle initial angle of the curve - * @param endAngle final angle of the curve - * @return vector with the points representing the curve - */ - extern std::vector generateArcPoints(Point center, double radius, double initAngle, double endAngle); - - /* Check if a given triangle is valid (have three vertex, all different). Throws an error if not. - * @param trianglePoints list of indexes of the triangle - */ - extern void checkTriangleIntegrity(std::vector &trianglePoints); - } // namespace delynoi_utilities -} // namespace Delynoi + extern void TrivialIndexVector(std::vector &index_vector, int n); + + /* Computes the cross product of two points + * @param a b points to operate + * @return result of the operation + */ + extern double crossProduct(const Point &a, const Point &b); + + /* Computes the norm of a point (basically, a vector starting from the origin) + * @param p point which norm will be calculated + * @return norm of the point + */ + extern double norm(const Point &p); + + /*Computes the square of the norm of a point (basically, a vector starting from the origin) + * @param p point which square norm will be calculated + * @return norm of the point + */ + extern double squareNorm(const Point &p); + + /* Determines the orientation of three points (counter clockwise or clockwise) + * @param p q r points to operate + * @return whether the points are oriented counter clockwise (positive) or clockwise (negative) + */ + extern double orientation(const Point &p, const Point &q, const Point &r); + + /* Creates a number of points that discretize a circle arc + * @param center center of the circle + * @param radius radius of the circle + * @param initAngle initial angle of the curve + * @param endAngle final angle of the curve + * @return vector with the points representing the curve + */ + extern std::vector generateArcPoints(const Point ¢er, double radius, double initAngle, double endAngle); + + /* Check if a given triangle is valid (have three vertex, all different). Throws an error if not. + * @param trianglePoints list of indexes of the triangle + */ + extern void checkTriangleIntegrity(const std::vector &trianglePoints); +} // namespace Delynoi::delynoi_utilities #endif diff --git a/Delynoi/include/Delynoi/utilities/geometryFunctions.h b/Delynoi/include/Delynoi/utilities/geometryFunctions.h index 2dd6619..fc9b90f 100644 --- a/Delynoi/include/Delynoi/utilities/geometryFunctions.h +++ b/Delynoi/include/Delynoi/utilities/geometryFunctions.h @@ -5,48 +5,46 @@ #include #include -namespace Delynoi { - /* - * Namespace that contains all standard geometric functions. +/* + * Namespace that contains all standard geometric functions. + */ +namespace Delynoi::geometry_functions { + /* Calculates the area2 defined by three points + * @param p1 p2 p3 points that define the area + * @return the value of the area2 */ - namespace geometry_functions { - /* Calculates the area2 defined by three points - * @param p1 p2 p3 points that define the area - * @return the value of the area2 - */ - extern double area2(Point p1, Point p2, Point p3); - - /* Determines if three points are collinear - * @param p1 p2 p3 points to test - * @return are the points collinear or not - */ - extern bool collinear(Point p1, Point p2, Point p3); - - /* Determmines if two line segments are collinear - * @param seg1 seg2 segments to test - * @return are the segments collinear or not - */ - extern bool collinear(PointSegment &seg1, PointSegment &seg2); - - /* Calculates the area of a triangle defined by three points - * @param p1 p2 origin points that define an area - * @return area of the triangle - */ - extern double triangleArea(Point p1, Point p2, Point origin); - - /* Computes the area of a polygon defined by a set of point indexes - * @param points points with the indexes reference - * @param index indexes of the points defining the polygon - * @return area of the polygon - */ - extern double area(std::vector &points, std::vector index); - - /* Computes the area of a polygon defined by a set of points - * @param points points that define the polygon - * @return area of the polygon - */ - extern double area(std::vector &points); - } // namespace geometry_functions -} // namespace Delynoi + extern double area2(const Point &p1, const Point &p2, const Point &p3); + + /* Determines if three points are collinear + * @param p1 p2 p3 points to test + * @return are the points collinear or not + */ + extern bool collinear(const Point &p1, const Point &p2, const Point &p3); + + /* Determmines if two line segments are collinear + * @param seg1 seg2 segments to test + * @return are the segments collinear or not + */ + extern bool collinear(PointSegment &seg1, PointSegment &seg2); + + /* Calculates the area of a triangle defined by three points + * @param p1 p2 origin points that define an area + * @return area of the triangle + */ + extern double triangleArea(const Point &p1, const Point &p2, const Point &origin); + + /* Computes the area of a polygon defined by a set of point indexes + * @param points points with the indexes reference + * @param index indexes of the points defining the polygon + * @return area of the polygon + */ + extern double area(const std::vector &points, const std::vector &index); + + /* Computes the area of a polygon defined by a set of points + * @param points points that define the polygon + * @return area of the polygon + */ + extern double area(const std::vector &points); +} // namespace Delynoi::geometry_functions #endif diff --git a/Delynoi/include/Delynoi/voronoi/DelaunayToVoronoi.h b/Delynoi/include/Delynoi/voronoi/DelaunayToVoronoi.h index 823c1d5..d1541ca 100644 --- a/Delynoi/include/Delynoi/voronoi/DelaunayToVoronoi.h +++ b/Delynoi/include/Delynoi/voronoi/DelaunayToVoronoi.h @@ -2,10 +2,8 @@ #define DELYNOI_DELAUNAYTOVORONOI_H #include -#include #include #include -#include namespace Delynoi { /* diff --git a/Delynoi/include/Delynoi/voronoi/TriangleDelaunayGenerator.h b/Delynoi/include/Delynoi/voronoi/TriangleDelaunayGenerator.h index 1e3bc04..4894ebd 100644 --- a/Delynoi/include/Delynoi/voronoi/TriangleDelaunayGenerator.h +++ b/Delynoi/include/Delynoi/voronoi/TriangleDelaunayGenerator.h @@ -6,11 +6,6 @@ #include #include #include -#include - -extern "C" { -#include -} namespace Delynoi { /* @@ -96,10 +91,10 @@ namespace Delynoi { * @return Delaunay triangulation in Mesh form */ template - Mesh initializeMesh(bool ignoreInvalidTriangles = false) { + Mesh initializeMesh(const bool ignoreInvalidTriangles = false) { UniqueList _points; auto *pointMap = new PointMap; - std::vector indexes = _points.push_list(this->meshPoints); + const std::vector indexes = _points.push_list(this->meshPoints); std::vector polygons; for (int i = 0; i < triangles.size(); i++) { @@ -115,13 +110,13 @@ namespace Delynoi { try { delynoi_utilities::checkTriangleIntegrity(newPoints); polygons.push_back(T(newPoints, meshPoints)); - } catch (std::exception &e) { - if (!ignoreInvalidTriangles) throw e; + } catch (std::exception &) { + if (!ignoreInvalidTriangles) throw; } } return Mesh(_points, polygons, this->delaunayEdges, pointMap); - }; + } }; } // namespace Delynoi diff --git a/Delynoi/include/Delynoi/voronoi/TriangleVoronoiGenerator.h b/Delynoi/include/Delynoi/voronoi/TriangleVoronoiGenerator.h index 063a2a4..3ee960a 100644 --- a/Delynoi/include/Delynoi/voronoi/TriangleVoronoiGenerator.h +++ b/Delynoi/include/Delynoi/voronoi/TriangleVoronoiGenerator.h @@ -3,7 +3,6 @@ #include #include -#include namespace Delynoi { /* @@ -22,7 +21,7 @@ namespace Delynoi { * Constructor. Using the point list (seed points) and a domain it computes the Voronoi diagram and sets it in the * class member */ - TriangleVoronoiGenerator(std::vector &point_list, const Region ®ion, bool ignoreInvalidTriangles = false); + TriangleVoronoiGenerator(const std::vector &point_list, const Region ®ion, bool ignoreInvalidTriangles = false); /* * @return voronoi diagram @@ -37,7 +36,7 @@ namespace Delynoi { /* * Clear mesh data */ - void clear(); + void clear() const; }; } // namespace Delynoi diff --git a/Delynoi/include/Delynoi/voronoi/structures/DelaunayInfo.h b/Delynoi/include/Delynoi/voronoi/structures/DelaunayInfo.h index 2687f3e..bee8bb3 100644 --- a/Delynoi/include/Delynoi/voronoi/structures/DelaunayInfo.h +++ b/Delynoi/include/Delynoi/voronoi/structures/DelaunayInfo.h @@ -50,9 +50,7 @@ namespace Delynoi { /* * Constructor */ - DelaunayInfo(std::vector &t, std::vector &p, SegmentMap *e, std::vector &pD, - UniqueList &rP, std::vector &eD, std::unordered_map &eM, - UniqueList &c) { + DelaunayInfo(const std::vector &t, const std::vector &p, SegmentMap *e, const std::vector &pD, const UniqueList &rP, const std::vector &eD, const std::unordered_map &eM, const UniqueList &c) { triangles = t; meshPoints = p; delaunayEdges = e; diff --git a/Delynoi/include/Delynoi/voronoi/structures/PointData.h b/Delynoi/include/Delynoi/voronoi/structures/PointData.h index 07d44d7..a05ba06 100644 --- a/Delynoi/include/Delynoi/voronoi/structures/PointData.h +++ b/Delynoi/include/Delynoi/voronoi/structures/PointData.h @@ -16,17 +16,17 @@ namespace Delynoi { /* * Constructor */ - explicit PointData(int p) { + explicit PointData(const int p) { this->point = p; this->edge = -1; - }; + } /* Sets an edge to the point, checking if it is a boundary one (they have prioirity for the Voronoi diagram * algorithm) * @param edge edge to check * @param marker flag indicating whether the segment is in the boundary or not */ - inline void setEdge(int _edge, int marker) { + void setEdge(const int _edge, const int marker) { if (this->edge == -1 || marker == 1) this->edge = _edge; } }; diff --git a/Delynoi/include/Delynoi/voronoi/structures/mapdata.h b/Delynoi/include/Delynoi/voronoi/structures/mapdata.h index a9087ed..33b2efa 100644 --- a/Delynoi/include/Delynoi/voronoi/structures/mapdata.h +++ b/Delynoi/include/Delynoi/voronoi/structures/mapdata.h @@ -13,7 +13,7 @@ namespace Delynoi { int second; std::size_t hash; - Key(int f, int s) { + Key(const int f, const int s) { first = f; second = s; hash = utilities::hash32(first) + utilities::hash32(second); diff --git a/Delynoi/lib/utilities/include/Delynoi/utilities/Pair.h b/Delynoi/lib/utilities/include/Delynoi/utilities/Pair.h index cffdbfc..4b5d5b0 100644 --- a/Delynoi/lib/utilities/include/Delynoi/utilities/Pair.h +++ b/Delynoi/lib/utilities/include/Delynoi/utilities/Pair.h @@ -20,9 +20,9 @@ namespace Delynoi { T dot(Pair other); - Pair operator*(double other); + Pair operator*(double other); - Pair operator+(const Pair &other) const; + Pair operator+(const Pair &other) const; }; template @@ -52,12 +52,12 @@ namespace Delynoi { template Pair Pair::operator*(const double other) { - return Pair(this->first * other, this->second * other); + return Pair(this->first * other, this->second * other); } template Pair Pair::operator+(const Pair &other) const { - return Pair(this->first + other.first, this->second + other.second); + return Pair(this->first + other.first, this->second + other.second); } template diff --git a/Delynoi/lib/utilities/include/Delynoi/utilities/Precision.h b/Delynoi/lib/utilities/include/Delynoi/utilities/Precision.h index 2f18bb0..2a87027 100644 --- a/Delynoi/lib/utilities/include/Delynoi/utilities/Precision.h +++ b/Delynoi/lib/utilities/include/Delynoi/utilities/Precision.h @@ -1,14 +1,12 @@ #ifndef UTILITIES_PRECISION_H #define UTILITIES_PRECISION_H -namespace Delynoi { - namespace Precision { - enum precision { - small = 6, - mid = 10, - large = 16 - }; - } -} // namespace Delynoi +namespace Delynoi::Precision { + enum precision { + small = 6, + mid = 10, + large = 16 + }; +} #endif diff --git a/Delynoi/lib/utilities/include/Delynoi/utilities/UniqueList.h b/Delynoi/lib/utilities/include/Delynoi/utilities/UniqueList.h index 9b15af3..4c82654 100644 --- a/Delynoi/lib/utilities/include/Delynoi/utilities/UniqueList.h +++ b/Delynoi/lib/utilities/include/Delynoi/utilities/UniqueList.h @@ -15,7 +15,7 @@ namespace Delynoi { public: UniqueList(); - UniqueList(const UniqueList &other); + UniqueList(const UniqueList &other); int push_back(T &item); @@ -25,7 +25,7 @@ namespace Delynoi { std::vector push_list(std::vector &_list); - std::vector push_list(UniqueList &_list); + std::vector push_list(UniqueList &_list); void pop_front(); @@ -37,11 +37,11 @@ namespace Delynoi { T &operator[](int i); - bool operator==(const UniqueList &other); + bool operator==(const UniqueList &other); bool contains(T elem); - bool hasCommonElement(UniqueList &other); + bool hasCommonElement(UniqueList &other); void clear(); @@ -52,7 +52,7 @@ namespace Delynoi { UniqueList::UniqueList() = default; template - UniqueList::UniqueList(const UniqueList &other) { + UniqueList::UniqueList(const UniqueList &other) { this->list = other.list; this->map = other.map; } @@ -65,17 +65,16 @@ namespace Delynoi { map.insert(it, std::make_pair(item, list.size())); list.push_back(item); - return (int) list.size() - 1; - } else { - return it->second; + return static_cast(list.size()) - 1; } + return it->second; } template int UniqueList::force_push_back(T &item) { list.push_back(item); - return (int) list.size() - 1; + return static_cast(list.size()) - 1; } template @@ -88,7 +87,7 @@ namespace Delynoi { template int UniqueList::size() { - return (int) list.size(); + return static_cast(list.size()); } template @@ -102,7 +101,7 @@ namespace Delynoi { } template - bool UniqueList::operator==(const UniqueList &other) { + bool UniqueList::operator==(const UniqueList &other) { return this->list == other.getList(); } @@ -123,7 +122,7 @@ namespace Delynoi { } template - std::vector UniqueList::push_list(UniqueList &_list) { + std::vector UniqueList::push_list(UniqueList &_list) { std::vector index; for (int i = 0; i < _list.size(); i++) { @@ -145,7 +144,7 @@ namespace Delynoi { } template - bool UniqueList::hasCommonElement(UniqueList &other) { + bool UniqueList::hasCommonElement(UniqueList &other) { for (int i = 0; i < other.size(); i++) { if (this->contains(other[i])) { return true; diff --git a/Delynoi/lib/utilities/include/Delynoi/utilities/utilities.h b/Delynoi/lib/utilities/include/Delynoi/utilities/utilities.h index a339103..2660e2c 100644 --- a/Delynoi/lib/utilities/include/Delynoi/utilities/utilities.h +++ b/Delynoi/lib/utilities/include/Delynoi/utilities/utilities.h @@ -4,54 +4,51 @@ #include #include #include -#include #include #include #include -namespace Delynoi { - namespace utilities { - template - std::string toString(T a) { - std::stringstream sstream; - sstream << a; - std::string s = sstream.str(); +namespace Delynoi::utilities { + template + std::string toString(T a) { + std::stringstream sstream; + sstream << a; + std::string s = sstream.str(); - return s; - } + return s; + } - template - int indexOf(const std::vector &vector, T element) { - int pos = std::find(vector.begin(), vector.end(), element) - vector.begin(); + template + int indexOf(const std::vector &vector, T element) { + const int pos = std::find(vector.begin(), vector.end(), element) - vector.begin(); - return pos < (int) vector.size() ? pos : -1; - } + return pos < static_cast(vector.size()) ? pos : -1; + } - template - int sign(T x) { - return (x > 0) - (x < 0); - } + template + int sign(T x) { + return (x > 0) - (x < 0); + } - extern std::string toStringWithPrecision(double d, int precision); + extern std::string toStringWithPrecision(double d, int precision); - extern int hash32(int key); + extern int hash32(int key); - extern int random_integer(int min, int max); + extern int random_integer(int min, int max); - extern std::string getPath(); + extern std::string getPath(); - extern Pair normalize(const Pair &vector); + extern Pair normalize(const Pair &vector); - extern double radian(double angle); + extern double radian(double angle); - extern double degrees(double angle); + extern double degrees(double angle); - extern std::vector split(std::string s, const std::regex ®ex); + extern std::vector split(std::string s, const std::regex ®ex); - extern std::vector splitBySpaces(std::string s); + extern std::vector splitBySpaces(std::string s); - extern std::ifstream openFile(const std::string &fileName); - } // namespace utilities -} // namespace Delynoi + extern std::ifstream openFile(const std::string &fileName); +} // namespace Delynoi::utilities #endif diff --git a/Delynoi/lib/utilities/src/utilities.cpp b/Delynoi/lib/utilities/src/utilities.cpp index 468eb2e..0a1aea3 100644 --- a/Delynoi/lib/utilities/src/utilities.cpp +++ b/Delynoi/lib/utilities/src/utilities.cpp @@ -3,94 +3,90 @@ #include #include #include -#include #include #include #include // Required for Mac-OS #include #include -namespace Delynoi { - namespace utilities { - std::string toStringWithPrecision(double d, int precision) { - std::stringstream sstream; - sstream << std::fixed << std::setprecision(precision); - sstream << d; - std::string s = sstream.str(); +namespace Delynoi::utilities { + std::string toStringWithPrecision(const double d, const int precision) { + std::stringstream sstream; + sstream << std::fixed << std::setprecision(precision); + sstream << d; + std::string s = sstream.str(); - return s; - } + return s; + } - int random_integer(int min, int max) { - static std::random_device rd; - static std::mt19937 rng(rd()); - std::uniform_int_distribution uni(min, max); + int random_integer(const int min, const int max) { + static std::random_device rd; + static std::mt19937 rng(rd()); + std::uniform_int_distribution uni(min, max); - return uni(rng); - } + return uni(rng); + } - std::string getPath() { + std::string getPath() { #if defined(_WIN64) || defined(_WIN32) - std::string path = std::getenv("USERPROFILE"); - return path + "\\"; + std::string path = std::getenv("USERPROFILE"); + return path + "\\"; #elif defined(__linux__) || defined(__APPLE__) - std::string path = std::getenv("HOME"); - return path + "/"; + std::string path = std::getenv("HOME"); + return path + "/"; #endif - } + } - Pair normalize(const Pair &vector) { - double norm = std::sqrt(std::pow(vector.first, 2) + std::pow(vector.second, 2)); - - return {vector.first / norm, vector.second / norm}; - } + Pair normalize(const Pair &vector) { + const double norm = std::sqrt(std::pow(vector.first, 2) + std::pow(vector.second, 2)); - double radian(double angle) { - return angle * M_PI / 180; - } + return {vector.first / norm, vector.second / norm}; + } - double degrees(double angle) { - double a = (angle > 0 ? angle : (2 * M_PI + angle)); - return a * 180 / (M_PI); - } + double radian(const double angle) { + return angle * M_PI / 180; + } - int hash32(int key) { - int c2 = 0x27d4eb2d; - key = (key ^ 61) ^ (key >> 16); - key = key + (key << 3); - key = key ^ (key >> 4); - key = key * c2; - key = key ^ (key >> 15); - return key; - } + double degrees(const double angle) { + const double a = angle > 0 ? angle : 2 * M_PI + angle; + return a * 180 / M_PI; + } - std::vector split(std::string s, const std::regex ®ex) { - std::vector result; + int hash32(int key) { + constexpr int c2 = 0x27d4eb2d; + key = key ^ 61 ^ key >> 16; + key = key + (key << 3); + key = key ^ key >> 4; + key = key * c2; + key = key ^ key >> 15; + return key; + } - std::sregex_token_iterator it(s.begin(), s.end(), regex, -1); - std::sregex_token_iterator reg_end; + std::vector split(std::string s, const std::regex ®ex) { + std::vector result; - for (; it != reg_end; ++it) { - if (!it->str().empty()) - result.push_back(it->str()); - } + std::sregex_token_iterator it(s.begin(), s.end(), regex, -1); - return result; + for (const std::sregex_token_iterator reg_end; it != reg_end; ++it) { + if (!it->str().empty()) + result.push_back(it->str()); } - std::vector splitBySpaces(std::string s) { - return split(std::move(s), std::regex("\\s+")); - } + return result; + } - std::ifstream openFile(const std::string &fileName) { - std::string completeName = utilities::getPath() + fileName; - std::ifstream infile(completeName); + std::vector splitBySpaces(std::string s) { + return split(std::move(s), std::regex("\\s+")); + } - if (!infile.good()) { - throw std::runtime_error("Could not open file. Please check path."); - } + std::ifstream openFile(const std::string &fileName) { + const std::string completeName = getPath() + fileName; + std::ifstream infile(completeName); - return infile; + if (!infile.good()) { + throw std::runtime_error("Could not open file. Please check path."); } - } // namespace utilities -} // namespace Delynoi + + return infile; + } +} // namespace Delynoi::utilities diff --git a/Delynoi/src/config/DelynoiConfig.cpp b/Delynoi/src/config/DelynoiConfig.cpp index dc460e9..8f28353 100644 --- a/Delynoi/src/config/DelynoiConfig.cpp +++ b/Delynoi/src/config/DelynoiConfig.cpp @@ -11,23 +11,23 @@ DelynoiConfig::DelynoiConfig() { this->precision = 6; } -void DelynoiConfig::setDiscretizationGrade(int d) { +void DelynoiConfig::setDiscretizationGrade(const int d) { this->circle_discretization_grade = d; } -void DelynoiConfig::setTolerance(double t) { +void DelynoiConfig::setTolerance(const double t) { this->double_comparison_tolerance = t; } -void DelynoiConfig::setScale(int s) { +void DelynoiConfig::setScale(const int s) { this->scale_for_clipper = s; } -void DelynoiConfig::setPrecision(Precision::precision p) { +void DelynoiConfig::setPrecision(const Precision::precision p) { this->precision = p; } -void DelynoiConfig::setPrecision(int p) { +void DelynoiConfig::setPrecision(const int p) { this->precision = p; } diff --git a/Delynoi/src/models/Region.cpp b/Delynoi/src/models/Region.cpp index 2d02aa9..6a584af 100644 --- a/Delynoi/src/models/Region.cpp +++ b/Delynoi/src/models/Region.cpp @@ -1,23 +1,32 @@ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wimplicit-const-int-float-conversion" - #include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + using namespace Delynoi; -Region::Region(std::vector &points) : Polygon(points) { +Region::Region(const std::vector &points) + : Polygon(points) { this->p = points; } -void Region::mutate(std::vector &points) { +void Region::mutate(const std::vector &points) { this->p = points; Polygon::mutate(points); } -Region::Region() : Polygon() {} +Region::Region() = default; -Region::Region(const Polygon &other, std::vector &points) : Polygon() { - std::vector otherPoints = other.getPoints(); +Region::Region(const Polygon &other, const std::vector &points) { + const std::vector otherPoints = other.getPoints(); for (int i = 0; i < other.numberOfSides(); ++i) { this->p.push_back(points[otherPoints[i]]); @@ -26,7 +35,8 @@ Region::Region(const Polygon &other, std::vector &points) : Polygon() { Polygon::mutate(this->p); } -Region::Region(const Region &other) : Polygon(other) { +Region::Region(const Region &other) + : Polygon(other) { this->p = other.p; this->holes.assign(other.holes.begin(), other.holes.end()); } @@ -42,17 +52,17 @@ std::vector Region::getSeedPoints() { void Region::addHole(Hole h) { //When we receive a hole we check whether the difference between the region and the hole is just //one path (according to the used library) - DelynoiConfig *config = DelynoiConfig::instance(); + const DelynoiConfig *config = DelynoiConfig::instance(); ClipperLib::Path region, hole; ClipperLib::Paths solution; for (auto &i: this->p) { - region << ClipperLib::IntPoint((int) (config->getScale() * i.getX()), (int) (config->getScale() * i.getY())); + region << ClipperLib::IntPoint(static_cast(config->getScale() * i.getX()), static_cast(config->getScale() * i.getY())); } - std::vector holePoints = h.getPoints(); + const std::vector holePoints = h.getPoints(); for (auto &holePoint: holePoints) { - hole << ClipperLib::IntPoint((int) (config->getScale() * holePoint.getX()), (int) (config->getScale() * holePoint.getY())); + hole << ClipperLib::IntPoint(static_cast(config->getScale() * holePoint.getX()), static_cast(config->getScale() * holePoint.getY())); } ClipperLib::Clipper clipper; @@ -64,7 +74,7 @@ void Region::addHole(Hole h) { //Hole does intersect, so Region has to change and the hole "disappears" std::vector newPoints; - for (auto &i: solution[0]) { + for (const auto &i: solution[0]) { newPoints.emplace_back(i.X / (1.0 * config->getScale()), i.Y / (1.0 * config->getScale())); } @@ -84,8 +94,8 @@ void Region::cleanInternalHoles() { this->holes.clear(); } -void Region::generateSeedPoints(PointGenerator _p, int nX, int nY) { - BoundingBox box = this->getBox(); +void Region::generateSeedPoints(const PointGenerator &_p, const int nX, const int nY) { + const BoundingBox box = this->getBox(); _p.generate(this->seedPoints, box, nX, nY); this->clean(); } @@ -101,12 +111,12 @@ void Region::addSeedsFromFile(const std::string &fileName) { std::string line; std::getline(infile, line); - int numberMeshPoints = std::atoi(line.c_str()); + int numberMeshPoints = std::atoi(line.c_str()); // NOLINT(*-err34-c) for (int i = 0; i < numberMeshPoints; ++i) { std::getline(infile, line); std::vector splittedLine = utilities::splitBySpaces(line); - Point newPoint(std::atof(splittedLine[0].c_str()), std::atof(splittedLine[1].c_str())); + Point newPoint(std::atof(splittedLine[0].c_str()), std::atof(splittedLine[1].c_str())); // NOLINT(*-err34-c) this->seedPoints.push_back(newPoint); } @@ -114,7 +124,7 @@ void Region::addSeedsFromFile(const std::string &fileName) { this->clean(); } -BoundingBox Region::getBox() { +BoundingBox Region::getBox() const { double xMin = LLONG_MAX; double xMax = LLONG_MIN; double yMin = LLONG_MAX; @@ -149,7 +159,7 @@ void Region::clean() { } newSeeds.reserve(toKeep.size()); - for (int i: toKeep) { + for (const int i: toKeep) { newSeeds.push_back(seedPoints[i]); } @@ -170,7 +180,7 @@ std::vector Region::getRegionPoints() { void Region::getSegments(std::vector &s) { Polygon::getSegments(s); - int offset = (int) this->p.size(); + int offset = static_cast(this->p.size()); for (Hole h: this->holes) { h.getSegments(s, offset); @@ -178,14 +188,14 @@ void Region::getSegments(std::vector &s) { } } -bool Region::containsPoint(Point _p) { - std::vector regionPoints = this->p; +bool Region::containsPoint(const Point &_p) const { + const std::vector regionPoints = this->p; return Polygon::containsPoint(regionPoints, _p); } -bool Region::inEdges(Point _p) { - std::vector regionPoints = this->p; +bool Region::inEdges(const Point &_p) const { + const std::vector regionPoints = this->p; return Polygon::inEdges(regionPoints, _p); } @@ -202,9 +212,9 @@ void Region::printInPath(const std::string &path) { std::ofstream file; file.open(path, std::ios::out); - std::vector points = this->getRegionPoints(); + const std::vector points = this->getRegionPoints(); - file << (points.size() + seedPoints.size()) << std::endl; + file << points.size() + seedPoints.size() << std::endl; for (auto &point: points) { file << point.getString() << std::endl; } @@ -225,5 +235,3 @@ void Region::printInPath(const std::string &path) { file.close(); } - -#pragma clang diagnostic pop diff --git a/Delynoi/src/models/basic/IndexSegment.cpp b/Delynoi/src/models/basic/IndexSegment.cpp index 0d7e93c..f2dad0c 100644 --- a/Delynoi/src/models/basic/IndexSegment.cpp +++ b/Delynoi/src/models/basic/IndexSegment.cpp @@ -1,55 +1,58 @@ #include +#include using namespace Delynoi; -IndexSegment::IndexSegment(int i1, int i2) : Segment(i1, i2) { +IndexSegment::IndexSegment(const int i1, const int i2) + : Segment(i1, i2) { this->hash = utilities::hash32(i1) + utilities::hash32(i2); } -IndexSegment::IndexSegment(const IndexSegment &other) : Segment(other) { +IndexSegment::IndexSegment(const IndexSegment &other) + : Segment(other) { this->p1 = other.p1; this->p2 = other.p2; this->hash = utilities::hash32(this->p1) + utilities::hash32(this->p2); } -IndexSegment::IndexSegment() : Segment() {} +IndexSegment::IndexSegment() = default; -bool IndexSegment::contains(const std::vector &p, Point point) { +bool IndexSegment::contains(const std::vector &p, const Point &point) const { return Segment::contains(point, p[this->p1], p[this->p2]); } -bool IndexSegment::contains(const std::vector &p, const IndexSegment &s) { +bool IndexSegment::contains(const std::vector &p, const IndexSegment &s) const { return this->contains(p, p[s.getFirst()]) && this->contains(p, p[s.getSecond()]); } -Point IndexSegment::middlePoint(const std::vector &p) { +Point IndexSegment::middlePoint(const std::vector &p) const { return {(p[this->p1].getX() + p[this->p2].getX()) / 2, (p[this->p1].getY() + p[this->p2].getY()) / 2}; } -double IndexSegment::cartesianAngle(const std::vector &p) { +double IndexSegment::cartesianAngle(const std::vector &p) const { return Segment::cartesianAngle(p[this->p1], p[this->p2]); } -bool IndexSegment::intersection(const std::vector &points, const PointSegment &other, Point &inter) { - return Segment::intersects(points[this->p1], points[this->p2], other.getFirst(), other.getSecond(), inter); +bool IndexSegment::intersection(const std::vector &points, const PointSegment &other, Point &inter) const { + return intersects(points[this->p1], points[this->p2], other.getFirst(), other.getSecond(), inter); } -bool IndexSegment::intersection(const std::vector &points, const IndexSegment &other, Point &inter) { - return Segment::intersects(points[this->p1], points[this->p2], points[other.getFirst()], points[other.getSecond()], inter); +bool IndexSegment::intersection(const std::vector &points, const IndexSegment &other, Point &inter) const { + return intersects(points[this->p1], points[this->p2], points[other.getFirst()], points[other.getSecond()], inter); } -void IndexSegment::orderCCW(const std::vector &points, Point center) { +void IndexSegment::orderCCW(const std::vector &points, const Point ¢er) { if (!this->isCCW(points, center)) { - int tmp = this->p1; + const int tmp = this->p1; this->p1 = this->p2; this->p2 = tmp; } } -bool IndexSegment::isCCW(const std::vector &points, Point center) { - Point p1 = points[this->p1]; - Point p2 = points[this->p2]; +bool IndexSegment::isCCW(const std::vector &points, const Point ¢er) const { + const Point p1 = points[this->p1]; + const Point p2 = points[this->p2]; return delynoi_utilities::orientation(p1, p2, center) > 0; } @@ -71,14 +74,14 @@ bool IndexSegment::operator<(const IndexSegment &other) const { return this->p1 < other.p1; } -double IndexSegment::length(const std::vector &points) { +double IndexSegment::length(const std::vector &points) const { return Segment::length(points[this->p1], points[this->p2]); } -bool IndexSegment::isContained(PointSegment s, const std::vector &p) { +bool IndexSegment::isContained(const PointSegment &s, const std::vector &p) const { return s.contains(p[this->p1]) && s.contains(p[this->p2]); } -IndexSegment IndexSegment::add(int o) { +IndexSegment IndexSegment::add(const int o) const { return {this->p1 + o, this->p2 + o}; } diff --git a/Delynoi/src/models/basic/Point.cpp b/Delynoi/src/models/basic/Point.cpp index 4828ed4..6f411aa 100644 --- a/Delynoi/src/models/basic/Point.cpp +++ b/Delynoi/src/models/basic/Point.cpp @@ -1,9 +1,11 @@ #include #include +#include + using namespace Delynoi; -Point::Point(double x, double y) { +Point::Point(const double x, const double y) { this->x = x; this->y = y; } @@ -36,7 +38,7 @@ double Point::squareNorm() const { } bool Point::operator==(const Point &other) const { - DelynoiConfig *config = DelynoiConfig::instance(); + const DelynoiConfig *config = DelynoiConfig::instance(); return std::abs(this->x - other.x) < config->getTolerance() && std::abs(this->y - other.y) < config->getTolerance(); @@ -54,18 +56,17 @@ void Point::setBoundary() { this->isBoundaryPoint = true; } -void Point::setX(double newX) { +void Point::setX(const double newX) { this->x = newX; } -void Point::setY(double newY) { +void Point::setY(const double newY) { this->y = newY; } bool Point::operator<(const Point &other) const { - DelynoiConfig *config = DelynoiConfig::instance(); - - if (std::abs(this->x - other.x) < config->getTolerance()) { + if (const DelynoiConfig *config = DelynoiConfig::instance(); + std::abs(this->x - other.x) < config->getTolerance()) { if (std::abs(this->y - other.y) < config->getTolerance()) { return false; } diff --git a/Delynoi/src/models/basic/PointSegment.cpp b/Delynoi/src/models/basic/PointSegment.cpp index 3d8dd31..62d26e1 100644 --- a/Delynoi/src/models/basic/PointSegment.cpp +++ b/Delynoi/src/models/basic/PointSegment.cpp @@ -2,15 +2,17 @@ using namespace Delynoi; -PointSegment::PointSegment(Point p1, Point p2) : Segment(p1, p2) {} +PointSegment::PointSegment(const Point &p1, const Point &p2) + : Segment(p1, p2) { +} -PointSegment::PointSegment() : Segment() {} +PointSegment::PointSegment() = default; -bool PointSegment::contains(Point point) { +bool PointSegment::contains(const Point &point) const { return Segment::contains(point, p1, p2); } -double PointSegment::length() { +double PointSegment::length() const { return Segment::length(this->p1, this->p2); } @@ -18,7 +20,7 @@ std::string PointSegment::getString() const { return this->getFirst().getString() + " " + this->getSecond().getString(); } -double PointSegment::cartesianAngle() { +double PointSegment::cartesianAngle() const { return Segment::cartesianAngle(this->p1, this->p2); } diff --git a/Delynoi/src/models/basic/Segment.cpp b/Delynoi/src/models/basic/Segment.cpp index 95353cd..8df0074 100644 --- a/Delynoi/src/models/basic/Segment.cpp +++ b/Delynoi/src/models/basic/Segment.cpp @@ -1,9 +1,8 @@ -#pragma clang diagnostic push -#pragma ide diagnostic ignored "UnusedLocalVariable" -#pragma ide diagnostic ignored "UnusedValue" - +#include #include +#include + using namespace Delynoi; template @@ -26,17 +25,14 @@ T Segment::getSecond() const { } template -bool Segment::contains(Point point, Point _p1, Point _p2) { - DelynoiConfig *config = DelynoiConfig::instance(); +bool Segment::contains(const Point &point, const Point &_p1, const Point &_p2) const { + const DelynoiConfig *config = DelynoiConfig::instance(); bool test1 = ((point.getX() >= _p1.getX() || std::abs(point.getX() - _p1.getX()) < config->getTolerance()) && (point.getX() <= _p2.getX() || std::abs(point.getX() - _p2.getX()) < config->getTolerance())) || ((point.getX() >= _p2.getX() || std::abs(point.getX() - _p2.getX()) < config->getTolerance()) && (point.getX() <= _p1.getX() || std::abs(point.getX() - _p1.getX()) < config->getTolerance())); - bool test2 = ((point.getY() >= _p1.getY() || std::abs(point.getY() - _p1.getY()) < config->getTolerance()) && - (point.getY() <= _p2.getY() || std::abs(point.getY() - _p2.getY()) < config->getTolerance()) || - ((point.getY() >= _p2.getY() || std::abs(point.getY() - _p2.getY()) < config->getTolerance()) && - (point.getY() <= _p1.getY() || std::abs(point.getY() - _p1.getY()) < config->getTolerance()))); + bool test2 = (point.getY() >= _p1.getY() || std::abs(point.getY() - _p1.getY()) < config->getTolerance()) && (point.getY() <= _p2.getY() || std::abs(point.getY() - _p2.getY()) < config->getTolerance()) || ((point.getY() >= _p2.getY() || std::abs(point.getY() - _p2.getY()) < config->getTolerance()) && (point.getY() <= _p1.getY() || std::abs(point.getY() - _p1.getY()) < config->getTolerance())); return test1 && test2 && std::abs(_p1.getX() * (_p2.getY() - point.getY()) + _p2.getX() * (point.getY() - _p1.getY()) + point.getX() * (_p1.getY() - _p2.getY())) < config->getTolerance(); @@ -48,30 +44,27 @@ bool Segment::isVertex(T p) { } template -double Segment::cartesianAngle(Point _p1, Point _p2) { - double dY = _p2.getY() - _p1.getY(); - double dX = _p2.getX() - _p1.getX(); +double Segment::cartesianAngle(const Point &_p1, const Point &_p2) { + const double dY = _p2.getY() - _p1.getY(); + const double dX = _p2.getX() - _p1.getX(); return utilities::degrees(atan2(dY, dX)); } template -bool Segment::intersects(Point _p1, Point _p2, Point o1, Point o2, Point &inter) { - double tolerance = DelynoiConfig::instance()->getTolerance(); +bool Segment::intersects(const Point &_p1, const Point &_p2, const Point &o1, const Point &o2, Point &inter) { + const double tolerance = DelynoiConfig::instance()->getTolerance(); - double s1_x, s1_y, s2_x, s2_y; - s1_x = _p2.getX() - _p1.getX(); - s1_y = _p2.getY() - _p1.getY(); - s2_x = o2.getX() - o1.getX(); - s2_y = o2.getY() - o1.getY(); + const double s1_x = _p2.getX() - _p1.getX(); + const double s1_y = _p2.getY() - _p1.getY(); + const double s2_x = o2.getX() - o1.getX(); + const double s2_y = o2.getY() - o1.getY(); - double s, t; - s = (-s1_y * (_p1.getX() - o1.getX()) + s1_x * (_p1.getY() - o1.getY())) / (-s2_x * s1_y + s1_x * s2_y); - t = (s2_x * (_p1.getY() - o1.getY()) - s2_y * (_p1.getX() - o1.getX())) / (-s2_x * s1_y + s1_x * s2_y); + const double s = (-s1_y * (_p1.getX() - o1.getX()) + s1_x * (_p1.getY() - o1.getY())) / (-s2_x * s1_y + s1_x * s2_y); - if (s >= (0 - tolerance) && s <= (1 + tolerance) && t >= (0 - tolerance) && t <= (1 + tolerance)) { - double i_x = _p1.getX() + (t * s1_x); - double i_y = _p1.getY() + (t * s1_y); + if (const double t = (s2_x * (_p1.getY() - o1.getY()) - s2_y * (_p1.getX() - o1.getX())) / (-s2_x * s1_y + s1_x * s2_y); s >= 0 - tolerance && s <= 1 + tolerance && t >= 0 - tolerance && t <= 1 + tolerance) { + const double i_x = _p1.getX() + t * s1_x; + const double i_y = _p1.getY() + t * s1_y; inter.setX(i_x); inter.setY(i_y); @@ -83,22 +76,17 @@ bool Segment::intersects(Point _p1, Point _p2, Point o1, Point o2, Point &int } template -bool Segment::intersectionInfinite(Point _p1, Point _p2, Point o1, Point o2, Point &inter) { - double tolerance = DelynoiConfig::instance()->getTolerance(); +bool Segment::intersectionInfinite(const Point _p1, const Point _p2, const Point o1, const Point o2, Point &inter) { + const double tolerance = DelynoiConfig::instance()->getTolerance(); - double s1_x, s1_y, s2_x, s2_y; - s1_x = _p2.getX() - _p1.getX(); - s1_y = _p2.getY() - _p1.getY(); - s2_x = o2.getX() - o1.getX(); - s2_y = o2.getY() - o1.getY(); + const double s1_x = _p2.getX() - _p1.getX(); + const double s1_y = _p2.getY() - _p1.getY(); + const double s2_x = o2.getX() - o1.getX(); + const double s2_y = o2.getY() - o1.getY(); - double s, t; - s = (-s1_y * (_p1.getX() - o1.getX()) + s1_x * (_p1.getY() - o1.getY())) / (-s2_x * s1_y + s1_x * s2_y); - t = (s2_x * (_p1.getY() - o1.getY()) - s2_y * (_p1.getX() - o1.getX())) / (-s2_x * s1_y + s1_x * s2_y); - - if (t <= (1 + tolerance) && t >= (0 - tolerance)) { - double i_x = _p1.getX() + (t * s1_x); - double i_y = _p1.getY() + (t * s1_y); + if (const double t = (s2_x * (_p1.getY() - o1.getY()) - s2_y * (_p1.getX() - o1.getX())) / (-s2_x * s1_y + s1_x * s2_y); t <= 1 + tolerance && t >= 0 - tolerance) { + const double i_x = _p1.getX() + t * s1_x; + const double i_y = _p1.getY() + t * s1_y; inter.setX(i_x); inter.setY(i_y); @@ -110,12 +98,10 @@ bool Segment::intersectionInfinite(Point _p1, Point _p2, Point o1, Point o2, } template -double Segment::length(Point _p1, Point _p2) { +double Segment::length(const Point &_p1, const Point &_p2) { return std::sqrt(std::pow(_p1.getX() - _p2.getX(), 2) + std::pow(_p1.getY() - _p2.getY(), 2)); } -template class Delynoi::Segment; - -template class Delynoi::Segment; +template class Segment; -#pragma clang diagnostic pop +template class Segment; diff --git a/Delynoi/src/models/generator/PointGenerator.cpp b/Delynoi/src/models/generator/PointGenerator.cpp index 608e0b5..a6801d7 100644 --- a/Delynoi/src/models/generator/PointGenerator.cpp +++ b/Delynoi/src/models/generator/PointGenerator.cpp @@ -11,7 +11,7 @@ PointGenerator::PointGenerator(Functor *lX, Functor *lY) { this->variable = functions::independent_variable::both; } -PointGenerator::PointGenerator(Functor *l, functions::independent_variable variable) { +PointGenerator::PointGenerator(Functor *l, const functions::independent_variable variable) { this->variable = variable; switch (variable) { @@ -26,21 +26,21 @@ PointGenerator::PointGenerator(Functor *l, functions::independent_variable varia } } -void PointGenerator::generate(std::vector &vector, BoundingBox box, int nX, int nY) { - double dX = box.getWidth() / (nX - 1); - double dY = box.getHeight() / (nY - 1); +void PointGenerator::generate(std::vector &vector, const BoundingBox &box, const int nX, const int nY) const { + const double dX = box.getWidth() / (nX - 1); + const double dY = box.getHeight() / (nY - 1); for (int i = 0; i < nY; i++) { for (int j = 0; j < nX; j++) { - double x = box.xMin() + j * dX; - double y = box.yMin() + i * dY; + const double x = box.xMin() + j * dX; + const double y = box.yMin() + i * dY; vector.push_back(result(x, y)); } } } -Point PointGenerator::result(double x, double y) { +Point PointGenerator::result(double x, double y) const { switch (variable) { case functions::independent_variable::x: return {x, y + this->lY->apply(x)}; diff --git a/Delynoi/src/models/generator/functions/RandomDouble.cpp b/Delynoi/src/models/generator/functions/RandomDouble.cpp index 2a427cd..3963a91 100644 --- a/Delynoi/src/models/generator/functions/RandomDouble.cpp +++ b/Delynoi/src/models/generator/functions/RandomDouble.cpp @@ -2,15 +2,15 @@ using namespace Delynoi; -std::default_random_engine Random_Double::rd; +std::default_random_engine Random_Double::rd; // NOLINT(*-msc51-cpp) std::mt19937 Random_Double::rng(rd()); -Random_Double::Random_Double(double min, double max) { +Random_Double::Random_Double(const double min, const double max) { this->min = min; this->max = max; - this->uni = std::uniform_real_distribution(min, max); + this->uni = std::uniform_real_distribution(min, max); } double Random_Double::apply(double x) { - return (uni) (Delynoi::Random_Double::rng); + return (uni) (rng); } diff --git a/Delynoi/src/models/generator/functions/RandomInteger.cpp b/Delynoi/src/models/generator/functions/RandomInteger.cpp index 426cdaf..5ee260d 100644 --- a/Delynoi/src/models/generator/functions/RandomInteger.cpp +++ b/Delynoi/src/models/generator/functions/RandomInteger.cpp @@ -1,21 +1,16 @@ -#pragma clang diagnostic push -#pragma ide diagnostic ignored "UnusedValue" - #include using namespace Delynoi; -std::default_random_engine Random_Integer::rd; +std::default_random_engine Random_Integer::rd; // NOLINT(*-msc51-cpp) std::mt19937 Random_Integer::rng(rd()); -Random_Integer::Random_Integer(double min, double max) { +Random_Integer::Random_Integer(const double min, const double max) { this->min = min; this->max = max; - this->uni = std::uniform_int_distribution(min, max); + this->uni = std::uniform_int_distribution<>(min, max); } double Random_Integer::apply(double x) { - return (uni) (Delynoi::Random_Integer::rng); + return (uni) (rng); } - -#pragma clang diagnostic pop diff --git a/Delynoi/src/models/generator/functions/functions.cpp b/Delynoi/src/models/generator/functions/functions.cpp index d09cac1..c619e2e 100644 --- a/Delynoi/src/models/generator/functions/functions.cpp +++ b/Delynoi/src/models/generator/functions/functions.cpp @@ -10,7 +10,9 @@ namespace Delynoi { public: Constant() = default; - inline double apply(double x) override { return x; } + double apply(const double x) override { + return x; + } }; class Uniform final : public Functor { @@ -18,9 +20,13 @@ namespace Delynoi { double delta; public: - explicit Uniform(double delta) { this->delta = delta; } + explicit Uniform(const double delta) { + this->delta = delta; + } - inline double apply(double x) override { return x * delta; } + double apply(const double x) override { + return x * delta; + } }; class Sine final : public Functor { @@ -30,15 +36,15 @@ namespace Delynoi { double phase; public: - Sine(double a, double f, double p) { + Sine(const double a, const double f, const double p) { this->amplitude = a; this->frecuency = f; this->phase = p; } - inline double apply(double x) override { + double apply(const double x) override { return amplitude * std::sin(utilities::radian(frecuency * x * 180) + utilities::radian(phase)); - }; + } }; class Cosine final : public Functor { @@ -48,15 +54,15 @@ namespace Delynoi { double phase; public: - Cosine(double a, double f, double p) { + Cosine(const double a, const double f, const double p) { this->amplitude = a; this->frecuency = f; this->phase = p; } - inline double apply(double x) override { + double apply(const double x) override { return amplitude * std::cos(utilities::radian(frecuency * x * 180) + utilities::radian(phase)); - }; + } }; class DisplaceDelta final : public Functor { @@ -65,11 +71,11 @@ namespace Delynoi { bool alternating = false; public: - explicit DisplaceDelta(double delta) { + explicit DisplaceDelta(const double delta) { this->delta = delta; } - inline double apply(double x) override { + double apply(const double x) override { alternating = !alternating; if (alternating) { @@ -88,14 +94,12 @@ namespace Delynoi { public: ConstantAlternating() = default; - inline double apply(double x) override { + double apply(double x) override { if (visitedPlaces.size() == 1) { delta = std::abs(visitedPlaces[0] - x); } - int index = visitedPlaces.push_back(x); - - if (index < visitedPlaces.size() - 1) { + if (const int index = visitedPlaces.push_back(x); index < visitedPlaces.size() - 1) { alternating = !alternating; visitedPlaces.clear(); } @@ -112,7 +116,7 @@ namespace Delynoi { return new Uniform(1.0); } - Functor *displace_points(double delta) { + Functor *displace_points(const double delta) { return new DisplaceDelta(delta); } @@ -120,23 +124,23 @@ namespace Delynoi { return new ConstantAlternating(); } - Functor *uniform(double delta) { + Functor *uniform(const double delta) { return new Uniform(delta); } - Functor *sine(double amplitude, double frecuency, double phase) { + Functor *sine(const double amplitude, const double frecuency, const double phase) { return new Sine(amplitude, frecuency, phase); } - Functor *cosine(double amplitude, double frecuency, double phase) { + Functor *cosine(const double amplitude, const double frecuency, const double phase) { return new Cosine(amplitude, frecuency, phase); } - Functor *random_integer(double min, double max) { + Functor *random_integer(const double min, const double max) { return new Random_Integer(min, max); } - Functor *random_double(double min, double max) { + Functor *random_double(const double min, const double max) { return new Random_Double(min, max); } } // namespace functions diff --git a/Delynoi/src/models/generator/noise/RandomDoubleNoise.cpp b/Delynoi/src/models/generator/noise/RandomDoubleNoise.cpp index 19c2824..c487152 100644 --- a/Delynoi/src/models/generator/noise/RandomDoubleNoise.cpp +++ b/Delynoi/src/models/generator/noise/RandomDoubleNoise.cpp @@ -1,24 +1,19 @@ -#pragma clang diagnostic push -#pragma ide diagnostic ignored "UnusedValue" - #include using namespace Delynoi; -std::default_random_engine RandomDoubleNoise::rd; +std::default_random_engine RandomDoubleNoise::rd; // NOLINT(*-msc51-cpp) std::mt19937 RandomDoubleNoise::rng(rd()); -RandomDoubleNoise::RandomDoubleNoise(Functor *f, double min, double max) { +RandomDoubleNoise::RandomDoubleNoise(Functor *f, const double min, const double max) { this->min = min; this->max = max; this->f = f; - this->uni = std::uniform_real_distribution(min, max); - this->uni_int = std::uniform_int_distribution(INT_MIN + 100000, INT_MAX - 100000); + this->uni = std::uniform_real_distribution(min, max); + this->uni_int = std::uniform_int_distribution(INT_MIN + 100000, INT_MAX - 100000); } -double RandomDoubleNoise::apply(double x) { - return f->apply(x) + (uni) (Delynoi::RandomDoubleNoise::rng) * ((uni_int) (Delynoi::RandomDoubleNoise::rng) % 2 ? 1 : -1); +double RandomDoubleNoise::apply(const double x) { + return f->apply(x) + (uni) (rng) * ((uni_int) (rng) % 2 ? 1 : -1); } - -#pragma clang diagnostic pop diff --git a/Delynoi/src/models/generator/noise/RandomIntegerNoise.cpp b/Delynoi/src/models/generator/noise/RandomIntegerNoise.cpp index d2a42a0..74dd465 100644 --- a/Delynoi/src/models/generator/noise/RandomIntegerNoise.cpp +++ b/Delynoi/src/models/generator/noise/RandomIntegerNoise.cpp @@ -1,22 +1,17 @@ -#pragma clang diagnostic push -#pragma ide diagnostic ignored "UnusedValue" - #include using namespace Delynoi; -std::default_random_engine RandomIntegerNoise::rd; +std::default_random_engine RandomIntegerNoise::rd; // NOLINT(*-msc51-cpp) std::mt19937 RandomIntegerNoise::rng(rd()); -RandomIntegerNoise::RandomIntegerNoise(Functor *f, double min, double max) { +RandomIntegerNoise::RandomIntegerNoise(Functor *f, const double min, const double max) { this->min = min; this->max = max; this->f = f; - this->uni = std::uniform_int_distribution(min, max); + this->uni = std::uniform_int_distribution<>(min, max); } -double RandomIntegerNoise::apply(double x) { - return f->apply(x) + (uni) (Delynoi::RandomIntegerNoise::rng) * ((uni) (Delynoi::RandomIntegerNoise::rng) % 2 ? 1 : -1); +double RandomIntegerNoise::apply(const double x) { + return f->apply(x) + (uni) (rng) * ((uni) (rng) % 2 ? 1 : -1); } - -#pragma clang diagnostic pop diff --git a/Delynoi/src/models/generator/noise/noise.cpp b/Delynoi/src/models/generator/noise/noise.cpp index 3ab983a..b20a728 100644 --- a/Delynoi/src/models/generator/noise/noise.cpp +++ b/Delynoi/src/models/generator/noise/noise.cpp @@ -2,14 +2,12 @@ #include #include -namespace Delynoi { - namespace noise { - Functor *random_double_noise(Functor *f, double min, double max) { - return new RandomDoubleNoise(f, min, max); - } +namespace Delynoi::noise { + Functor *random_double_noise(Functor *f, const double min, const double max) { + return new RandomDoubleNoise(f, min, max); + } - Functor *random_integer_noise(Functor *f, double min, double max) { - return new RandomIntegerNoise(f, min, max); - } - } // namespace noise -} // namespace Delynoi + Functor *random_integer_noise(Functor *f, const double min, const double max) { + return new RandomIntegerNoise(f, min, max); + } +} // namespace Delynoi::noise \ No newline at end of file diff --git a/Delynoi/src/models/hole/CircularHole.cpp b/Delynoi/src/models/hole/CircularHole.cpp index d72bf0e..a531988 100644 --- a/Delynoi/src/models/hole/CircularHole.cpp +++ b/Delynoi/src/models/hole/CircularHole.cpp @@ -1,8 +1,11 @@ #include +#include +#include using namespace Delynoi; -CircularHole::CircularHole(Point p, double r) : Circle(r, p) { +CircularHole::CircularHole(const Point &p, const double r) + : Circle(r, p) { this->HolePoints = discretizeCircle(); Hole::center = Circle::center; computeSegments(); @@ -10,8 +13,8 @@ CircularHole::CircularHole(Point p, double r) : Circle(r, p) { void CircularHole::computeSegments() { std::vector indexes; - delynoi_utilities::TrivialIndexVector(indexes, (int) this->HolePoints.size()); + delynoi_utilities::TrivialIndexVector(indexes, static_cast(this->HolePoints.size())); - Polygon discretePolygon(indexes, this->HolePoints); + const Polygon discretePolygon(indexes, this->HolePoints); discretePolygon.getSegments(this->segments); } diff --git a/Delynoi/src/models/hole/PolygonalHole.cpp b/Delynoi/src/models/hole/PolygonalHole.cpp index 1154e03..d8fdfe6 100644 --- a/Delynoi/src/models/hole/PolygonalHole.cpp +++ b/Delynoi/src/models/hole/PolygonalHole.cpp @@ -2,7 +2,8 @@ using namespace Delynoi; -PolygonalHole::PolygonalHole(std::vector &p) : Polygon(p) { +PolygonalHole::PolygonalHole(std::vector &p) + : Polygon(p) { for (auto &i: p) { this->HolePoints.push_back(i); } diff --git a/Delynoi/src/models/hole/clipper/ClipperWrapper.cpp b/Delynoi/src/models/hole/clipper/ClipperWrapper.cpp index 67fb290..16c4052 100644 --- a/Delynoi/src/models/hole/clipper/ClipperWrapper.cpp +++ b/Delynoi/src/models/hole/clipper/ClipperWrapper.cpp @@ -2,7 +2,7 @@ using namespace Delynoi; -ClipperLib::Paths ClipperWrapper::polyIntersection(const std::vector &parent, const std::vector &child, int maxScale) { +ClipperLib::Paths ClipperWrapper::polyIntersection(const std::vector &parent, const std::vector &child, const int maxScale) { ClipperLib::Path region, hole; ClipperLib::Paths solution; @@ -22,6 +22,6 @@ ClipperLib::Paths ClipperWrapper::polyIntersection(const std::vector &par return solution; } -ClipperLib::IntPoint ClipperWrapper::scalePoint(Point point, int maxScale) { - return {(int) (maxScale * point.getX()), (int) (maxScale * point.getY())}; +ClipperLib::IntPoint ClipperWrapper::scalePoint(const Point &point, const int maxScale) { + return {static_cast(maxScale * point.getX()), static_cast(maxScale * point.getY())}; } diff --git a/Delynoi/src/models/hole/clipper/lib/clipper.cpp b/Delynoi/src/models/hole/clipper/lib/clipper.cpp index 379226e..5e42708 100644 --- a/Delynoi/src/models/hole/clipper/lib/clipper.cpp +++ b/Delynoi/src/models/hole/clipper/lib/clipper.cpp @@ -137,7 +137,8 @@ struct LocMinSorter inline cInt Round(double val) { if ((val < 0)) return static_cast(val - 0.5); - else return static_cast(val + 0.5); + else + return static_cast(val + 0.5); } //------------------------------------------------------------------------------ @@ -162,9 +163,9 @@ void PolyTree::Clear() PolyNode* PolyTree::GetFirst() const { if (!Childs.empty()) - return Childs[0]; - else - return 0; + return Childs[0]; + else + return 0; } //------------------------------------------------------------------------------ @@ -203,20 +204,20 @@ void PolyNode::AddChild(PolyNode& child) PolyNode* PolyNode::GetNext() const { if (!Childs.empty()) - return Childs[0]; - else - return GetNextSiblingUp(); + return Childs[0]; + else + return GetNextSiblingUp(); } //------------------------------------------------------------------------------ PolyNode* PolyNode::GetNextSiblingUp() const { if (!Parent) //protects against PolyTree.GetNextSiblingUp() - return 0; - else if (Index == Parent->Childs.size() - 1) - return Parent->GetNextSiblingUp(); - else - return Parent->Childs[Index + 1]; + return 0; + else if (Index == Parent->Childs.size() - 1) + return Parent->GetNextSiblingUp(); + else + return Parent->Childs[Index + 1]; } //------------------------------------------------------------------------------ diff --git a/Delynoi/src/models/neighbourhood/EdgeData.cpp b/Delynoi/src/models/neighbourhood/EdgeData.cpp index fd15f36..31c7fa6 100644 --- a/Delynoi/src/models/neighbourhood/EdgeData.cpp +++ b/Delynoi/src/models/neighbourhood/EdgeData.cpp @@ -2,14 +2,14 @@ using namespace Delynoi; -EdgeData::EdgeData(int p1, int p2) { +EdgeData::EdgeData(const int p1, const int p2) { this->p1 = p1; this->p2 = p2; this->t1 = -1; this->t2 = -1; } -void EdgeData::setTriangle(int t) { +void EdgeData::setTriangle(const int t) { if (this->t1 == -1) { this->t1 = t; } else { diff --git a/Delynoi/src/models/neighbourhood/NeighboursByPoint.cpp b/Delynoi/src/models/neighbourhood/NeighboursByPoint.cpp index 47d907a..74f41d6 100644 --- a/Delynoi/src/models/neighbourhood/NeighboursByPoint.cpp +++ b/Delynoi/src/models/neighbourhood/NeighboursByPoint.cpp @@ -4,7 +4,7 @@ using namespace Delynoi; NeighboursByPoint::NeighboursByPoint() = default; -NeighboursByPoint::NeighboursByPoint(int n) { +NeighboursByPoint::NeighboursByPoint(const int n) { this->neighbours.push_back(n); } @@ -12,7 +12,7 @@ NeighboursByPoint::NeighboursByPoint(std::vector n) { this->neighbours.assign(n.begin(), n.end()); } -void NeighboursByPoint::add(int n) { +void NeighboursByPoint::add(const int n) { this->neighbours.push_back(n); } diff --git a/Delynoi/src/models/neighbourhood/NeighboursBySegment.cpp b/Delynoi/src/models/neighbourhood/NeighboursBySegment.cpp index 245b922..5b53c04 100644 --- a/Delynoi/src/models/neighbourhood/NeighboursBySegment.cpp +++ b/Delynoi/src/models/neighbourhood/NeighboursBySegment.cpp @@ -4,11 +4,11 @@ using namespace Delynoi; NeighboursBySegment::NeighboursBySegment() = default; -NeighboursBySegment::NeighboursBySegment(int i1) { +NeighboursBySegment::NeighboursBySegment(const int i1) { this->n1 = i1; } -NeighboursBySegment::NeighboursBySegment(int i1, int i2) { +NeighboursBySegment::NeighboursBySegment(const int i1, const int i2) { this->n1 = i1; this->n2 = i2; } @@ -18,7 +18,7 @@ NeighboursBySegment::NeighboursBySegment(const Pair &p) { this->n2 = p.second; } -void NeighboursBySegment::setNeighbour(int i) { +void NeighboursBySegment::setNeighbour(const int i) { this->n2 = i; } @@ -39,10 +39,10 @@ bool NeighboursBySegment::operator==(const NeighboursBySegment &other) const { this->getFirst() == other.getSecond() && this->getSecond() == other.getFirst(); } -void NeighboursBySegment::setFirst(int value) { +void NeighboursBySegment::setFirst(const int value) { this->n1 = value; } -void NeighboursBySegment::setSecond(int value) { +void NeighboursBySegment::setSecond(const int value) { this->n2 = value; } diff --git a/Delynoi/src/models/neighbourhood/PointMap.cpp b/Delynoi/src/models/neighbourhood/PointMap.cpp index 1171e24..58e4918 100644 --- a/Delynoi/src/models/neighbourhood/PointMap.cpp +++ b/Delynoi/src/models/neighbourhood/PointMap.cpp @@ -1,5 +1,7 @@ #include +#include + using namespace Delynoi; PointMap::PointMap() = default; @@ -8,10 +10,8 @@ PointMap::~PointMap() { map.clear(); } -void PointMap::insert(Point p, int neighbour) { - auto got = this->map.find(p); - - if (got == this->map.end()) { +void PointMap::insert(Point p, const int neighbour) { + if (const auto got = this->map.find(p); got == this->map.end()) { NeighboursByPoint n(neighbour); this->map.insert(std::make_pair(p, n)); } else { @@ -20,10 +20,8 @@ void PointMap::insert(Point p, int neighbour) { } } -void PointMap::insert(Point &p, std::vector &neighbours) { - auto got = this->map.find(p); - - if (got == this->map.end()) { +void PointMap::insert(Point &p, const std::vector &neighbours) { + if (const auto got = this->map.find(p); got == this->map.end()) { NeighboursByPoint n(neighbours); this->map.insert(std::make_pair(p, n)); } else { @@ -32,7 +30,7 @@ void PointMap::insert(Point &p, std::vector &neighbours) { } } -NeighboursByPoint &PointMap::get(Point p) { +NeighboursByPoint &PointMap::get(const Point &p) { return this->map[p]; } @@ -40,23 +38,23 @@ std::map &PointMap::getMap() { return this->map; } -int PointMap::size() { +int PointMap::size() const { return this->map.size(); } -void PointMap::printInFile(const std::string &fileName) { +void PointMap::printInFile(const std::string &fileName) const { this->printInPath(utilities::getPath() + fileName); } -void PointMap::printInPath(const std::string &path) { +void PointMap::printInPath(const std::string &path) const { std::ofstream file; file.open(path, std::ios::out); - for (const auto &v: this->map) { - file << v.first.getString() + " "; - NeighboursByPoint n = v.second; + for (const auto &[fst, snd]: this->map) { + file << fst.getString() + " "; + NeighboursByPoint n = snd; - for (int i: n.getNeighbours()) { + for (const int i: n.getNeighbours()) { file << i << " "; } diff --git a/Delynoi/src/models/neighbourhood/SegmentMap.cpp b/Delynoi/src/models/neighbourhood/SegmentMap.cpp index 68937b2..94cff9e 100644 --- a/Delynoi/src/models/neighbourhood/SegmentMap.cpp +++ b/Delynoi/src/models/neighbourhood/SegmentMap.cpp @@ -8,10 +8,8 @@ SegmentMap::~SegmentMap() { this->map.clear(); } -void SegmentMap::insert(const IndexSegment &s, int polygonIndex) { - auto got = this->map.find(s); - - if (got == this->map.end()) { +void SegmentMap::insert(const IndexSegment &s, const int polygonIndex) { + if (const auto got = this->map.find(s); got == this->map.end()) { NeighboursBySegment n(polygonIndex); this->map.insert(std::make_pair(s, n)); } else { @@ -19,7 +17,7 @@ void SegmentMap::insert(const IndexSegment &s, int polygonIndex) { } } -void SegmentMap::insert(const IndexSegment &s, NeighboursBySegment n) { +void SegmentMap::insert(const IndexSegment &s, const NeighboursBySegment n) { this->map[s] = n; } @@ -35,20 +33,20 @@ std::unordered_map SegmentMap: return this->map; } -int SegmentMap::size() { +int SegmentMap::size() const { return this->map.size(); } -void SegmentMap::printInFile(const std::string &fileName) { +void SegmentMap::printInFile(const std::string &fileName) const { this->printInPath(utilities::getPath() + fileName); } -void SegmentMap::printInPath(const std::string &path) { +void SegmentMap::printInPath(const std::string &path) const { std::ofstream file; file.open(path, std::ios::out); - for (const auto &v: this->map) { - file << v.first.getString() + " " + v.second.getString() << std::endl; + for (const auto &[fst, snd]: this->map) { + file << fst.getString() + " " + snd.getString() << std::endl; } file.close(); diff --git a/Delynoi/src/models/polygon/BoundingBox.cpp b/Delynoi/src/models/polygon/BoundingBox.cpp index ef24920..a5dc4cf 100644 --- a/Delynoi/src/models/polygon/BoundingBox.cpp +++ b/Delynoi/src/models/polygon/BoundingBox.cpp @@ -2,7 +2,7 @@ using namespace Delynoi; -BoundingBox::BoundingBox(Point p1, Point p2) { +BoundingBox::BoundingBox(const Point &p1, const Point &p2) { this->p1 = p1; this->p2 = p2; } @@ -15,27 +15,27 @@ Point BoundingBox::getSecond() const { return this->p2; } -double BoundingBox::getWidth() { +double BoundingBox::getWidth() const { return std::abs(p1.getX() - p2.getX()); } -double BoundingBox::getHeight() { +double BoundingBox::getHeight() const { return std::abs(p1.getY() - p2.getY()); } -double BoundingBox::xMin() { +double BoundingBox::xMin() const { return std::min(p1.getX(), p2.getX()); } -double BoundingBox::yMin() { +double BoundingBox::yMin() const { return std::min(p1.getY(), p2.getY()); } -double BoundingBox::xMax() { +double BoundingBox::xMax() const { return std::max(p1.getX(), p2.getX()); } -double BoundingBox::yMax() { +double BoundingBox::yMax() const { return std::max(p1.getY(), p2.getY()); } @@ -54,6 +54,6 @@ void BoundingBox::getSegments(std::vector &segments) { segments.emplace_back(p4, p1); } -bool BoundingBox::contains(Point p) { +bool BoundingBox::contains(const Point &p) const { return p.getX() >= xMin() && p.getX() <= xMax() && p.getY() >= yMin() && p.getY() <= yMax(); } diff --git a/Delynoi/src/models/polygon/Circle.cpp b/Delynoi/src/models/polygon/Circle.cpp index 1d026a8..a6098fc 100644 --- a/Delynoi/src/models/polygon/Circle.cpp +++ b/Delynoi/src/models/polygon/Circle.cpp @@ -2,18 +2,20 @@ #include #include +#include + using namespace Delynoi; -Circle::Circle(double r, Point c) { +Circle::Circle(const double r, const Point &c) { this->radius = r; this->center = c; } -std::vector Circle::discretizeCircle() { - DelynoiConfig *config = DelynoiConfig::instance(); +std::vector Circle::discretizeCircle() const { + const DelynoiConfig *config = DelynoiConfig::instance(); std::vector points; - double delta = 360.0 / config->getDiscretizationGrade(); + const double delta = 360.0 / config->getDiscretizationGrade(); double angle = 0; while (angle < 360) { diff --git a/Delynoi/src/models/polygon/Polygon.cpp b/Delynoi/src/models/polygon/Polygon.cpp index e1dfab3..5b5950b 100644 --- a/Delynoi/src/models/polygon/Polygon.cpp +++ b/Delynoi/src/models/polygon/Polygon.cpp @@ -1,11 +1,12 @@ #include #include -#include -#include +#include +#include +#include using namespace Delynoi; -Polygon::Polygon(std::vector &points, std::vector &p) { +Polygon::Polygon(std::vector &points, const std::vector &p) { if (isSelfIntersecting(p)) { throw std::invalid_argument("Self intersecting polygons are not supported"); } @@ -15,7 +16,7 @@ Polygon::Polygon(std::vector &points, std::vector &p) { calculateHash(); } -void Polygon::mutate(std::vector &p) { +void Polygon::mutate(const std::vector &p) { this->points.clear(); delynoi_utilities::TrivialIndexVector(this->points, p.size()); @@ -27,7 +28,7 @@ void Polygon::mutate(std::vector &p) { calculateHash(); } -Polygon::Polygon(std::vector &p) { +Polygon::Polygon(const std::vector &p) { if (isSelfIntersecting(p)) { throw std::invalid_argument("Self intersecting polygons are not supported"); } @@ -36,7 +37,7 @@ Polygon::Polygon(std::vector &p) { std::vector this_points; this_points.reserve(points.size()); - for (int point: points) { + for (const int point: points) { this_points.push_back(p[point]); } @@ -59,9 +60,8 @@ double Polygon::calculateDiameter(std::vector &p) { std::vector> rotatingCalipers = convex::rotatingCalipers(p); double max = -1; - for (auto &rotatingCaliper: rotatingCalipers) { - double distance = delynoi_utilities::norm(rotatingCaliper.first - rotatingCaliper.second); - if (distance > max) { + for (auto &[fst, snd]: rotatingCalipers) { + if (const double distance = delynoi_utilities::norm(fst - snd); distance > max) { max = distance; } } @@ -69,11 +69,11 @@ double Polygon::calculateDiameter(std::vector &p) { return max; } -double Polygon::calculateArea(std::vector &p) { +double Polygon::calculateArea(const std::vector &p) const { return geometry_functions::area(p, this->points); } -double Polygon::getArea(std::vector &_points) { +double Polygon::getArea(const std::vector &_points) { if (this->area == -1) { this->area = this->calculateArea(_points); } @@ -81,16 +81,16 @@ double Polygon::getArea(std::vector &_points) { return this->area; } -double Polygon::getDiameter(std::vector &_points) { +double Polygon::getDiameter(const std::vector &_points) { if (this->diameter < 0) { std::vector thisPoints = this->getPoints(_points); - this->diameter = this->calculateDiameter(thisPoints); + this->diameter = calculateDiameter(thisPoints); } return this->diameter; } -Point Polygon::getCentroid(std::vector &_points) { +Point Polygon::getCentroid(const std::vector &_points) { if (!this->centroid.isValid()) { this->centroid = this->calculateCentroid(_points); } @@ -98,9 +98,9 @@ Point Polygon::getCentroid(std::vector &_points) { return this->centroid; } -double Polygon::signedArea(std::vector &p) { +double Polygon::signedArea(const std::vector &p) const { double _area = 0; - int n = (int) this->points.size(); + const int n = static_cast(this->points.size()); for (int i = 0; i < n; i++) { _area += p[points[i]].getX() * p[points[(i + 1) % n]].getY() - p[points[(i + 1) % n]].getX() * p[points[i]].getY(); @@ -109,8 +109,8 @@ double Polygon::signedArea(std::vector &p) { return 0.5 * _area; } -void Polygon::getSegments(std::vector &segments) { - int n = (int) this->points.size(); +void Polygon::getSegments(std::vector &segments) const { + const int n = static_cast(this->points.size()); for (int i = 0; i < n; i++) { IndexSegment s(this->points[i % n], this->points[(i + 1) % n]); @@ -118,8 +118,8 @@ void Polygon::getSegments(std::vector &segments) { } } -Point Polygon::calculateCentroid(std::vector &p) { - int n = this->points.size(); +Point Polygon::calculateCentroid(const std::vector &p) const { + const int n = this->points.size(); double partial_x = 0; double partial_y = 0; @@ -131,14 +131,14 @@ Point Polygon::calculateCentroid(std::vector &p) { partial_y += (pi.getY() + pi1.getY()) * (pi.getX() * pi1.getY() - pi1.getX() * pi.getY()); } - double A = this->signedArea(p); + const double A = this->signedArea(p); double cX = partial_x / (6 * A); double cY = partial_y / (6 * A); return {cX, cY}; } -bool Polygon::containsPoint(std::vector &p, Point point) { +bool Polygon::containsPoint(const std::vector &p, const Point &point) const { int j = points.size() - 1; bool oddNodes = false; @@ -166,7 +166,7 @@ bool Polygon::containsPoint(std::vector &p, Point point) { return inEdges(p, point); } -IndexSegment Polygon::containerEdge(std::vector &p, Point point) { +IndexSegment Polygon::containerEdge(const std::vector &p, const Point &point) const { std::vector segments; this->getSegments(segments); @@ -179,21 +179,23 @@ IndexSegment Polygon::containerEdge(std::vector &p, Point point) { return {-1, -1}; } -bool Polygon::inEdges(std::vector &p, Point point) { - IndexSegment container = containerEdge(p, point); +bool Polygon::inEdges(const std::vector &p, const Point &point) const { + const IndexSegment container = containerEdge(p, point); return container.getFirst() != -1 && container.getSecond() != -1; } -bool Polygon::isConvex(std::vector &p) { - int n = (int) this->points.size(); +bool Polygon::isConvex(const std::vector &p) const { + const int n = static_cast(this->points.size()); - double determinant = delynoi_utilities::orientation(p[this->points[0]], p[this->points[1]], p[this->points[2]]); + const double determinant = delynoi_utilities::orientation(p[this->points[0]], p[this->points[1]], p[this->points[2]]); for (int i = 1; i < n; i++) { - double newResult = delynoi_utilities::orientation(p[this->points[i]], p[this->points[(i + 1) % n]], p[this->points[(i + 2) % n]]); - - if (determinant * newResult < 0) { + if (const double newResult = delynoi_utilities::orientation( + p[this->points[i]], + p[this->points[(i + 1) % n]], + p[this->points[(i + 2) % n]]); + determinant * newResult < 0) { return false; } } @@ -210,11 +212,11 @@ std::vector &Polygon::getPoints() { } int Polygon::numberOfSides() const { - return (int) points.size(); + return static_cast(points.size()); } -bool Polygon::isClockwise(std::vector &p) { - int n = (int) points.size(); +bool Polygon::isClockwise(const std::vector &p) const { + const int n = static_cast(points.size()); Point pI = p[points[0]]; Point pI1 = p[points[n - 1]]; @@ -238,39 +240,39 @@ bool Polygon::operator==(const Polygon &other) const { std::string Polygon::getString() { std::string base = utilities::toString(this->points.size()); - for (int point: this->points) { + for (const int point: this->points) { base += " " + utilities::toString(point); } return base; } -bool Polygon::isVertex(int index) { +bool Polygon::isVertex(const int index) { return std::find(points.begin(), points.end(), index) != points.end(); } void Polygon::calculateHash() { std::size_t _hash = 0; - for (int point: points) { + for (const int point: points) { _hash += utilities::hash32(point); } this->hash = _hash; } -void Polygon::fixCCW(std::vector &p) { +void Polygon::fixCCW(const std::vector &p) { if (isClockwise(p)) { std::reverse(this->points.begin(), this->points.end()); this->area = -1; } } -std::vector Polygon::getPoints(std::vector &p) { +std::vector Polygon::getPoints(const std::vector &p) { std::vector returnPoints; returnPoints.reserve(this->points.size()); - for (int point: this->points) { + for (const int point: this->points) { returnPoints.push_back(p[point]); } @@ -281,14 +283,14 @@ bool Polygon::operator<(const Polygon &other) const { return this->hash < other.hash; } -bool Polygon::isSelfIntersecting(std::vector &_points) { +bool Polygon::isSelfIntersecting(const std::vector &_points) const { std::vector segments; this->getSegments(segments); - int n = segments.size(); + const int n = segments.size(); Point intersection; for (int i = 0; i < n; ++i) { - IndexSegment s = segments[i]; + const IndexSegment &s = segments[i]; for (int j = 0; j < n; ++j) { if (i == j || j == (i - 1 + n) % n || j == (i + 1) % n) { @@ -303,20 +305,20 @@ bool Polygon::isSelfIntersecting(std::vector &_points) { return false; } -bool Polygon::containsEdge(IndexSegment &s) { - int n = this->numberOfSides(); +bool Polygon::containsEdge(const IndexSegment &s) const { + const int n = this->numberOfSides(); - int i = utilities::indexOf(this->points, s.getFirst()); - int j = utilities::indexOf(this->points, s.getSecond()); + const int i = utilities::indexOf(this->points, s.getFirst()); + const int j = utilities::indexOf(this->points, s.getSecond()); - return i != -1 && j != -1 && (std::abs(i - j) == 1 || std::abs(i - j) == (n - 1)); + return i != -1 && j != -1 && (std::abs(i - j) == 1 || std::abs(i - j) == n - 1); } -Point Polygon::getAverage(std::vector &p) { +Point Polygon::getAverage(const std::vector &p) { double x = 0; double y = 0; - for (int v: points) { + for (const int v: points) { Point vertex = p[v]; x += vertex.getX(); @@ -329,14 +331,12 @@ Point Polygon::getAverage(std::vector &p) { return {x, y}; } -double Polygon::getMaxDistance(std::vector &_points) { - int n = this->points.size(); +double Polygon::getMaxDistance(const std::vector &points) const { + const int n = this->points.size(); double maxEdge = LLONG_MIN; for (int i = 0; i < this->points.size(); ++i) { - double distance = IndexSegment(this->points[i], this->points[(i + 1) % n]).length(_points); - - if (distance > maxEdge) { + if (const double distance = IndexSegment(this->points[i], this->points[(i + 1) % n]).length(points); distance > maxEdge) { maxEdge = distance; } } diff --git a/Delynoi/src/models/polygon/Triangle.cpp b/Delynoi/src/models/polygon/Triangle.cpp index 6b9c15c..a7d6c22 100644 --- a/Delynoi/src/models/polygon/Triangle.cpp +++ b/Delynoi/src/models/polygon/Triangle.cpp @@ -4,22 +4,25 @@ using namespace Delynoi; Triangle::Triangle() = default; -Triangle::Triangle(std::vector points, std::vector &p) : Polygon(points, p) { +Triangle::Triangle(std::vector points, const std::vector &p) + : Polygon(points, p) { this->circumcenter = this->calculateCircumcenter(p); } -Triangle::Triangle(std::vector points, std::vector &p, UniqueList &circumcenters) : Polygon(points, p) { +Triangle::Triangle(std::vector points, const std::vector &p, UniqueList &circumcenters) + : Polygon(points, p) { this->circumcenter = this->calculateCircumcenter(p); this->circumcenterIndex = circumcenters.push_back(this->circumcenter); } -Triangle::Triangle(std::vector points, std::vector &p, std::vector &circumcenters) : Polygon(points, p) { +Triangle::Triangle(std::vector points, const std::vector &p, std::vector &circumcenters) + : Polygon(points, p) { this->circumcenter = this->calculateCircumcenter(p); this->circumcenterIndex = circumcenters.size(); circumcenters.push_back(this->circumcenter); } -Point Triangle::getCircumcenter() { +Point Triangle::getCircumcenter() const { return this->circumcenter; } @@ -27,12 +30,12 @@ int Triangle::getCircumcenterIndex() const { return this->circumcenterIndex; } -Point Triangle::calculateCircumcenter(std::vector &p) { - Point A = p[this->points[0]]; - Point B = p[this->points[1]]; - Point C = p[this->points[2]]; +Point Triangle::calculateCircumcenter(const std::vector &p) const { + const Point A = p[this->points[0]]; + const Point B = p[this->points[1]]; + const Point C = p[this->points[2]]; - double d = 2 * (A.getX() * (B.getY() - C.getY()) + B.getX() * (C.getY() - A.getY()) + C.getX() * (A.getY() - B.getY())); + const double d = 2 * (A.getX() * (B.getY() - C.getY()) + B.getX() * (C.getY() - A.getY()) + C.getX() * (A.getY() - B.getY())); double uX = (A.squareNorm() * (B.getY() - C.getY()) + B.squareNorm() * (C.getY() - A.getY()) + C.squareNorm() * (A.getY() - B.getY())) / d; double uY = (A.squareNorm() * (C.getX() - B.getX()) + B.squareNorm() * (A.getX() - C.getX()) + C.squareNorm() * (B.getX() - A.getX())) / d; @@ -40,31 +43,31 @@ Point Triangle::calculateCircumcenter(std::vector &p) { return {uX, uY}; } -int Triangle::nextEdge(int center, EdgeData edge, std::unordered_map &edgeMap) { - Key nextEdge = Key(center, thirdPoint(edge)); +int Triangle::nextEdge(const int center, const EdgeData edge, std::unordered_map &edgeMap) const { + const auto nextEdge = Key(center, thirdPoint(edge)); return edgeMap[nextEdge]; } -int Triangle::thirdPoint(EdgeData edge) { +int Triangle::thirdPoint(const EdgeData edge) const { if (this->points[0] == edge.p1) { if (this->points[1] == edge.p2) { return this->points[2]; } return this->points[1]; - } else if (this->points[1] == edge.p1) { + } + if (this->points[1] == edge.p1) { if (this->points[0] == edge.p2) { return this->points[2]; } return this->points[0]; - } else { - if (this->points[0] == edge.p2) { - return this->points[1]; - } - return this->points[0]; } + if (this->points[0] == edge.p2) { + return this->points[1]; + } + return this->points[0]; } -bool Triangle::isNull() { +bool Triangle::isNull() const { return this->points.empty(); } diff --git a/Delynoi/src/triangulation/CenterTriangulationGenerator.cpp b/Delynoi/src/triangulation/CenterTriangulationGenerator.cpp index bbd0dc6..21a2b35 100644 --- a/Delynoi/src/triangulation/CenterTriangulationGenerator.cpp +++ b/Delynoi/src/triangulation/CenterTriangulationGenerator.cpp @@ -7,16 +7,16 @@ std::vector CenterTriangulationGenerator::triangulate(Polygon p, std:: throw std::invalid_argument("Can not use a center triangulation scheme on a non convex polygon"); } - std::vector polyPoints = p.getPoints(); - int n = polyPoints.size(); + const std::vector polyPoints = p.getPoints(); + const int n = polyPoints.size(); std::vector triangles; - Point center = p.getAverage(points); + const Point center = p.getAverage(points); points.push_back(center); - int centerIndex = points.size() - 1; + const int centerIndex = points.size() - 1; for (int i = 0; i < n; ++i) { - std::vector trianglePoints = {polyPoints[i], polyPoints[(i + 1) % n], centerIndex}; + const std::vector trianglePoints = {polyPoints[i], polyPoints[(i + 1) % n], centerIndex}; Triangle t(trianglePoints, points); triangles.push_back(t); diff --git a/Delynoi/src/triangulation/DelaunayTriangulationGenerator.cpp b/Delynoi/src/triangulation/DelaunayTriangulationGenerator.cpp index 4b44ca8..0621ddb 100644 --- a/Delynoi/src/triangulation/DelaunayTriangulationGenerator.cpp +++ b/Delynoi/src/triangulation/DelaunayTriangulationGenerator.cpp @@ -2,8 +2,8 @@ using namespace Delynoi; -std::vector DelaunayTriangulationGenerator::triangulate(Polygon p, std::vector &points) { - Region r(p, points); +std::vector DelaunayTriangulationGenerator::triangulate(const Polygon p, std::vector &points) { + const Region r(p, points); TriangleDelaunayGenerator generator(points, r); Mesh triangulation = generator.getConstrainedDelaunayTriangulation(); diff --git a/Delynoi/src/triangulation/EarTriangulationGenerator.cpp b/Delynoi/src/triangulation/EarTriangulationGenerator.cpp index 945f16e..fdccc14 100644 --- a/Delynoi/src/triangulation/EarTriangulationGenerator.cpp +++ b/Delynoi/src/triangulation/EarTriangulationGenerator.cpp @@ -2,8 +2,8 @@ using namespace Delynoi; -Triangle EarTriangulationGenerator::getEar(std::vector &points, std::vector &pointList) { - int size = (int) pointList.size(); +Triangle EarTriangulationGenerator::getEar(const std::vector &points, std::vector &pointList) { + const int size = static_cast(pointList.size()); if (size < 3) { Triangle t; @@ -17,10 +17,8 @@ Triangle EarTriangulationGenerator::getEar(std::vector &points, std::vect } for (int i = 0; i < size; i++) { - bool test = false; - Triangle t({pointList[(size + i - 1) % size], pointList[i % size], pointList[(size + i + 1) % size]}, points); - - if (t.isConvex(points)) { + if (Triangle t({pointList[(size + i - 1) % size], pointList[i % size], pointList[(size + i + 1) % size]}, points); t.isConvex(points)) { + bool test = false; for (int j = 0; j < size; j++) { if (!t.isVertex(pointList[j]) && t.containsPoint(points, points[pointList[j]])) { test = true; diff --git a/Delynoi/src/utilities/convexHull.cpp b/Delynoi/src/utilities/convexHull.cpp index 3264a0c..01dc4ae 100644 --- a/Delynoi/src/utilities/convexHull.cpp +++ b/Delynoi/src/utilities/convexHull.cpp @@ -3,58 +3,55 @@ #include #include -namespace Delynoi { - namespace convex { - struct PointComparator { - bool operator()(Point p1, Point p2) { - if (p1.getX() == p2.getX()) { - return p1.getY() < p2.getY(); - } - - return p1.getX() < p2.getX(); +namespace Delynoi::convex { + struct PointComparator { + bool operator()(const Point &p1, const Point &p2) const { + if (p1.getX() == p2.getX()) { + return p1.getY() < p2.getY(); } - } comparator; - void convexHull(std::vector &points, std::vector &upper, std::vector &lower) { - std::sort(points.begin(), points.end(), comparator); - for (auto &point: points) { - - while (upper.size() > 1 && delynoi_utilities::orientation(upper[upper.size() - 2], upper[upper.size() - 1], point) >= 0) { - upper.pop_back(); - } + return p1.getX() < p2.getX(); + } + } comparator; - while (lower.size() > 1 && delynoi_utilities::orientation(lower[lower.size() - 2], lower[lower.size() - 1], point) <= 0) { - lower.pop_back(); - } + void convexHull(std::vector &points, std::vector &upper, std::vector &lower) { + std::sort(points.begin(), points.end(), comparator); + for (auto &point: points) { - upper.push_back(point); - lower.push_back(point); + while (upper.size() > 1 && delynoi_utilities::orientation(upper[upper.size() - 2], upper[upper.size() - 1], point) >= 0) { + upper.pop_back(); } - } - std::vector> rotatingCalipers(std::vector &points) { - std::vector u; - std::vector l; - convexHull(points, u, l); - - std::vector> pairs; - - int i = 0, j = l.size() - 1; - while (i < u.size() - 1 || j > 0) { - pairs.emplace_back(u[i], l[j]); - - if (i == u.size() - 1) - j--; - else if (j == 0) - i++; - else if ((u[i + 1].getY() - u[i].getY()) * (l[j].getX() - l[j - 1].getX()) > - (l[j].getY() - l[j - 1].getY()) * (u[i + 1].getX() - u[i].getX())) - i++; - else - j--; + while (lower.size() > 1 && delynoi_utilities::orientation(lower[lower.size() - 2], lower[lower.size() - 1], point) <= 0) { + lower.pop_back(); } - return pairs; + upper.push_back(point); + lower.push_back(point); } - } // namespace convex -} // namespace Delynoi + } + + std::vector> rotatingCalipers(std::vector &points) { + std::vector u; + std::vector l; + convexHull(points, u, l); + + std::vector> pairs; + + int i = 0, j = l.size() - 1; + while (i < u.size() - 1 || j > 0) { + pairs.emplace_back(u[i], l[j]); + + if (i == u.size() - 1) + j--; + else if (j == 0) + i++; + else if ((u[i + 1].getY() - u[i].getY()) * (l[j].getX() - l[j - 1].getX()) > (l[j].getY() - l[j - 1].getY()) * (u[i + 1].getX() - u[i].getX())) + i++; + else + j--; + } + + return pairs; + } +} // namespace Delynoi::convex \ No newline at end of file diff --git a/Delynoi/src/utilities/delynoi_utilities.cpp b/Delynoi/src/utilities/delynoi_utilities.cpp index 257ca9d..7740799 100644 --- a/Delynoi/src/utilities/delynoi_utilities.cpp +++ b/Delynoi/src/utilities/delynoi_utilities.cpp @@ -3,53 +3,51 @@ #include #include -namespace Delynoi { - namespace delynoi_utilities { - void TrivialIndexVector(std::vector &index_vector, int n) { - for (int i = 0; i < n; i++) { - index_vector.push_back(i); - } +namespace Delynoi::delynoi_utilities { + void TrivialIndexVector(std::vector &index_vector, const int n) { + for (int i = 0; i < n; i++) { + index_vector.push_back(i); } + } - double crossProduct(Point a, Point b) { - return a.getX() * b.getY() - a.getY() * b.getX(); - } - - double squareNorm(Point p) { - return pow(p.getX(), 2) + pow(p.getY(), 2); - } + double crossProduct(const Point &a, const Point &b) { + return a.getX() * b.getY() - a.getY() * b.getX(); + } - double norm(Point p) { - return sqrt(squareNorm(p)); - } + double squareNorm(const Point &p) { + return pow(p.getX(), 2) + pow(p.getY(), 2); + } - double orientation(Point p, Point q, Point r) { - return delynoi_utilities::crossProduct((q - p), (r - p)); - } + double norm(const Point &p) { + return sqrt(squareNorm(p)); + } - std::vector generateArcPoints(Point center, double radius, double initAngle, double endAngle) { - std::vector arcPoints; + double orientation(const Point &p, const Point &q, const Point &r) { + return crossProduct(q - p, r - p); + } - int steps = DelynoiConfig::instance()->getDiscretizationGrade(); - double delta = (endAngle - initAngle) / steps; + std::vector generateArcPoints(const Point ¢er, const double radius, const double initAngle, const double endAngle) { + std::vector arcPoints; - for (int i = 0; i <= steps; i++) { - double angle = initAngle + delta * i; + const int steps = DelynoiConfig::instance()->getDiscretizationGrade(); + const double delta = (endAngle - initAngle) / steps; - double x = center.getX() + radius * std::cos(utilities::radian(angle)); - double y = center.getY() + radius * std::sin(utilities::radian(angle)); + for (int i = 0; i <= steps; i++) { + const double angle = initAngle + delta * i; - Point point(x, y); - arcPoints.push_back(point); - } + const double x = center.getX() + radius * std::cos(utilities::radian(angle)); + const double y = center.getY() + radius * std::sin(utilities::radian(angle)); - return arcPoints; + Point point(x, y); + arcPoints.push_back(point); } - void checkTriangleIntegrity(std::vector &trianglePoints) { - if (trianglePoints.size() != 3 || trianglePoints[0] == trianglePoints[1] || trianglePoints[1] == trianglePoints[2] || trianglePoints[2] == trianglePoints[0]) { - throw std::invalid_argument("Invalid triangle detected. Stopping meshing."); - } + return arcPoints; + } + + void checkTriangleIntegrity(const std::vector &trianglePoints) { + if (trianglePoints.size() != 3 || trianglePoints[0] == trianglePoints[1] || trianglePoints[1] == trianglePoints[2] || trianglePoints[2] == trianglePoints[0]) { + throw std::invalid_argument("Invalid triangle detected. Stopping meshing."); } - } // namespace delynoi_utilities -} // namespace Delynoi + } +} // namespace Delynoi::delynoi_utilities \ No newline at end of file diff --git a/Delynoi/src/utilities/geometryFunctions.cpp b/Delynoi/src/utilities/geometryFunctions.cpp index 6339c70..43e946f 100644 --- a/Delynoi/src/utilities/geometryFunctions.cpp +++ b/Delynoi/src/utilities/geometryFunctions.cpp @@ -3,51 +3,48 @@ #include #include -namespace Delynoi { - namespace geometry_functions { - double area2(Point p1, Point p2, Point p3) { - Point v1 = p2 - p1; - Point v2 = p3 - p1; +namespace Delynoi::geometry_functions { + double area2(const Point &p1, const Point &p2, const Point &p3) { + const Point v1 = p2 - p1; + const Point v2 = p3 - p1; - return delynoi_utilities::crossProduct(v1, v2); - } - - bool collinear(Point p1, Point p2, Point p3) { - DelynoiConfig *config = DelynoiConfig::instance(); + return delynoi_utilities::crossProduct(v1, v2); + } - return std::abs(area2(p1, p2, p3)) < config->getTolerance(); - } + bool collinear(const Point &p1, const Point &p2, const Point &p3) { + const DelynoiConfig *config = DelynoiConfig::instance(); - bool collinear(const PointSegment &seg1, const PointSegment &seg2) { - return collinear(seg1.getFirst(), seg1.getSecond(), seg2.getFirst()) && - collinear(seg1.getFirst(), seg1.getSecond(), seg2.getSecond()); - } + return std::abs(area2(p1, p2, p3)) < config->getTolerance(); + } - double triangleArea(Point p1, Point p2, Point origin) { - return area2(p1, p2, origin) / 2.0; - } + bool collinear(const PointSegment &seg1, const PointSegment &seg2) { + return collinear(seg1.getFirst(), seg1.getSecond(), seg2.getFirst()) && + collinear(seg1.getFirst(), seg1.getSecond(), seg2.getSecond()); + } - double area(std::vector &points, std::vector index) { - double area = 0.0; - int n = (int) index.size(); + double triangleArea(const Point &p1, const Point &p2, const Point &origin) { + return area2(p1, p2, origin) / 2.0; + } - for (int i = 0; i < n; i++) { - area += triangleArea(points[index[i % n]], points[index[(i + 1) % n]], - points[index[0]]); - } + double area(const std::vector &points, const std::vector &index) { + double area = 0.0; + const int n = static_cast(index.size()); - return area; + for (int i = 0; i < n; i++) { + area += triangleArea(points[index[i % n]], points[index[(i + 1) % n]], points[index[0]]); } - double area(std::vector &points) { - double area = 0.0; - int n = (int) points.size(); + return area; + } - for (int i = 0; i < n; i++) { - area += triangleArea(points[i % n], points[(i + 1) % n], points[0]); - } + double area(const std::vector &points) { + double area = 0.0; + const int n = static_cast(points.size()); - return area; + for (int i = 0; i < n; i++) { + area += triangleArea(points[i % n], points[(i + 1) % n], points[0]); } - } // namespace geometry_functions -} // namespace Delynoi + + return area; + } +} // namespace Delynoi::geometry_functions \ No newline at end of file diff --git a/Delynoi/src/voronoi/DelaunayToVoronoi.cpp b/Delynoi/src/voronoi/DelaunayToVoronoi.cpp index 949dd6a..4499246 100644 --- a/Delynoi/src/voronoi/DelaunayToVoronoi.cpp +++ b/Delynoi/src/voronoi/DelaunayToVoronoi.cpp @@ -1,3 +1,4 @@ +#include #include using namespace Delynoi; @@ -67,9 +68,8 @@ DelaunayToVoronoi::DelaunayToVoronoi(DelaunayInfo &del) { if (edge.t2 == -1) { int firstPoint = cellPoints[0]; - int lastPoint = cellPoints[cellPoints.size() - 1]; - if (geometry_functions::collinear(del.circumcenters[firstPoint], regionCenter, del.circumcenters[lastPoint])) { + if (int lastPoint = cellPoints[cellPoints.size() - 1]; geometry_functions::collinear(del.circumcenters[firstPoint], regionCenter, del.circumcenters[lastPoint])) { IndexSegment e(lastPoint, firstPoint); thisEdges.push_back(e); @@ -95,7 +95,7 @@ DelaunayToVoronoi::DelaunayToVoronoi(DelaunayInfo &del) { std::vector &pointList = del.circumcenters.getList(); std::vector &cellPointsList = cellPoints.getList(); - Polygon p = Polygon(cellPointsList, pointList); + auto p = Polygon(cellPointsList, pointList); p.fixCCW(pointList); voronoiCells.push_back(p); @@ -103,17 +103,17 @@ DelaunayToVoronoi::DelaunayToVoronoi(DelaunayInfo &del) { UniqueList &points = del.circumcenters; - this->mesh = Mesh(points, voronoiCells, voronoiEdges, pointMap); + this->mesh = Mesh(points, voronoiCells, voronoiEdges, pointMap); } -int DelaunayToVoronoi::getCircumcenter(DelaunayInfo &del, int triangle, int edge) { +int DelaunayToVoronoi::getCircumcenter(DelaunayInfo &del, const int triangle, const int edge) { if (triangle != -1) { return del.triangles[triangle].getCircumcenterIndex(); } Point middlePoint = IndexSegment(del.edges[edge].p1, del.edges[edge].p2).middlePoint(del.meshPoints); middlePoint.setBoundary(); - int circumcenterIndex = del.circumcenters.push_back(middlePoint); + const int circumcenterIndex = del.circumcenters.push_back(middlePoint); return circumcenterIndex; } diff --git a/Delynoi/src/voronoi/TriangleDelaunayGenerator.cpp b/Delynoi/src/voronoi/TriangleDelaunayGenerator.cpp index 2e4eddf..c8d9924 100644 --- a/Delynoi/src/voronoi/TriangleDelaunayGenerator.cpp +++ b/Delynoi/src/voronoi/TriangleDelaunayGenerator.cpp @@ -1,6 +1,10 @@ #include #include +extern "C" { +#include +} + using namespace Delynoi; TriangleDelaunayGenerator::TriangleDelaunayGenerator(const std::vector &points, const Region ®ion) { @@ -16,8 +20,7 @@ void TriangleDelaunayGenerator::callTriangle(std::vector &point_list, cha void TriangleDelaunayGenerator::callTriangle(std::vector &point_list, char *switches, const std::vector &restrictedSegments) { this->empty = true; - struct triangulateio in { - }, out{}; + triangulateio in{}, out{}; std::vector regionPoints = region.getRegionPoints(); UniqueList pointList; @@ -25,9 +28,9 @@ void TriangleDelaunayGenerator::callTriangle(std::vector &point_list, cha std::vector regionIndex = pointList.push_list(regionPoints); in.numberofpoints = pointList.size(); - in.pointlist = (REAL_TRIANGLE *) malloc(in.numberofpoints * 2 * sizeof(REAL_TRIANGLE)); + in.pointlist = static_cast(malloc(in.numberofpoints * 2 * sizeof(REAL_TRIANGLE))); in.numberofpointattributes = 1; - in.pointattributelist = (REAL_TRIANGLE *) malloc(in.numberofpoints * in.numberofpointattributes * sizeof(REAL_TRIANGLE)); + in.pointattributelist = static_cast(malloc(in.numberofpoints * in.numberofpointattributes * sizeof(REAL_TRIANGLE))); int _points = 0; for (int i = 0; i < pointList.size(); i++) { @@ -37,14 +40,14 @@ void TriangleDelaunayGenerator::callTriangle(std::vector &point_list, cha _points += 2; } - in.pointmarkerlist = (int *) NULL; + in.pointmarkerlist = static_cast(nullptr); std::vector segments; region.getSegments(segments); - in.numberofsegments = (int) (segments.size() + restrictedSegments.size()); - in.segmentlist = (int *) malloc(in.numberofsegments * 2 * sizeof(int)); - in.segmentmarkerlist = (int *) NULL; + in.numberofsegments = static_cast(segments.size() + restrictedSegments.size()); + in.segmentlist = static_cast(malloc(in.numberofsegments * 2 * sizeof(int))); + in.segmentmarkerlist = static_cast(nullptr); int k; for (k = 0; k < segments.size(); k++) { in.segmentlist[2 * k] = regionIndex[segments[k].getFirst()]; @@ -58,8 +61,8 @@ void TriangleDelaunayGenerator::callTriangle(std::vector &point_list, cha } std::vector &holes = region.getHoles(); - in.numberofholes = (int) holes.size(); - in.holelist = (REAL_TRIANGLE *) malloc(in.numberofholes * 2 * sizeof(REAL_TRIANGLE)); + in.numberofholes = static_cast(holes.size()); + in.holelist = static_cast(malloc(in.numberofholes * 2 * sizeof(REAL_TRIANGLE))); for (int i = 0; i < holes.size(); i++) { in.holelist[2 * i] = holes[i].getCenter().getX(); in.holelist[2 * i + 1] = holes[i].getCenter().getY(); @@ -67,17 +70,17 @@ void TriangleDelaunayGenerator::callTriangle(std::vector &point_list, cha in.numberofregions = 0; - out.pointlist = (REAL_TRIANGLE *) NULL; - out.pointattributelist = (REAL_TRIANGLE *) NULL; - out.pointmarkerlist = (int *) NULL; - out.trianglelist = (int *) NULL; - out.triangleattributelist = (REAL_TRIANGLE *) NULL; - out.segmentmarkerlist = (int *) NULL; - out.segmentlist = (int *) NULL; - out.edgelist = (int *) NULL; - out.edgemarkerlist = (int *) NULL; + out.pointlist = static_cast(nullptr); + out.pointattributelist = static_cast(nullptr); + out.pointmarkerlist = static_cast(nullptr); + out.trianglelist = static_cast(nullptr); + out.triangleattributelist = static_cast(nullptr); + out.segmentmarkerlist = static_cast(nullptr); + out.segmentlist = static_cast(nullptr); + out.edgelist = static_cast(nullptr); + out.edgemarkerlist = static_cast(nullptr); - triangulate(switches, &in, &out, (struct triangulateio *) NULL); + triangulate(switches, &in, &out, nullptr); for (int i = 0; i < out.numberofpoints; i++) { PointData data(i); @@ -97,8 +100,7 @@ void TriangleDelaunayGenerator::callTriangle(std::vector &point_list, cha } for (int i = 0; i < out.numberoftriangles; i++) { - std::vector triangle_points = {out.trianglelist[3 * i], out.trianglelist[3 * i + 1], - out.trianglelist[3 * i + 2]}; + std::vector triangle_points = {out.trianglelist[3 * i], out.trianglelist[3 * i + 1], out.trianglelist[3 * i + 2]}; realPoints.push_back(out.trianglelist[3 * i]); realPoints.push_back(out.trianglelist[3 * i + 1]); realPoints.push_back(out.trianglelist[3 * i + 2]); @@ -140,7 +142,7 @@ void TriangleDelaunayGenerator::callTriangle(std::vector &point_list, cha free(out.edgemarkerlist); } -Mesh &TriangleDelaunayGenerator::getConformingDelaunayTriangulation(bool ignoreInvalidTriangles) { +Mesh &TriangleDelaunayGenerator::getConformingDelaunayTriangulation(const bool ignoreInvalidTriangles) { if (!this->empty) { char switches[] = "pzejDQ"; callTriangle(seedPoints, switches); @@ -191,7 +193,7 @@ DelaunayInfo TriangleDelaunayGenerator::getConformingDelaunay() { return DelaunayInfo(triangles, meshPoints, delaunayEdges, points, realPoints, edges, edgeMap, circumcenters); } -Mesh TriangleDelaunayGenerator::getConstrainedDelaunayTriangulation(bool ignoreInvalidTriangles) { +Mesh TriangleDelaunayGenerator::getConstrainedDelaunayTriangulation(const bool ignoreInvalidTriangles) { if (!this->empty) { char switches[] = "pzejQ"; callTriangle(seedPoints, switches); @@ -200,7 +202,7 @@ Mesh TriangleDelaunayGenerator::getConstrainedDelaunayTriangulation(bo return initializeMesh(ignoreInvalidTriangles); } -Mesh TriangleDelaunayGenerator::getConstrainedDelaunayTriangulation(const std::vector &restrictedSegments, bool ignoreInvalidTriangles) { +Mesh TriangleDelaunayGenerator::getConstrainedDelaunayTriangulation(const std::vector &restrictedSegments, const bool ignoreInvalidTriangles) { if (!this->empty) { char switches[] = "pzejQ"; callTriangle(seedPoints, switches, restrictedSegments); diff --git a/Delynoi/src/voronoi/TriangleVoronoiGenerator.cpp b/Delynoi/src/voronoi/TriangleVoronoiGenerator.cpp index 41b42bd..a23ebd6 100644 --- a/Delynoi/src/voronoi/TriangleVoronoiGenerator.cpp +++ b/Delynoi/src/voronoi/TriangleVoronoiGenerator.cpp @@ -3,7 +3,7 @@ using namespace Delynoi; -TriangleVoronoiGenerator::TriangleVoronoiGenerator(std::vector &point_list, const Region ®ion, bool ignoreInvalidTriangles) { +TriangleVoronoiGenerator::TriangleVoronoiGenerator(const std::vector &point_list, const Region ®ion, const bool ignoreInvalidTriangles) { TriangleDelaunayGenerator delaunayGenerator(point_list, region); DelaunayInfo _delaunay = delaunayGenerator.getConformingDelaunay(); @@ -19,7 +19,7 @@ Mesh &TriangleVoronoiGenerator::getTriangulation() { return this->delaunay; } -void TriangleVoronoiGenerator::clear() { +void TriangleVoronoiGenerator::clear() const { this->voronoi.clear(); this->delaunay.clear(); } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 94b1d42..f239f2f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -6,6 +6,6 @@ else() SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pg") endif() -set(SOURCE_FILES TimeSquareTestMain.cpp) +set(SOURCE_FILES AllTests.cpp) add_executable(DelynoiTest ${SOURCE_FILES}) target_link_libraries(DelynoiTest Delynoi) \ No newline at end of file