Skip to content

Commit

Permalink
Reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
ppizarror committed Oct 30, 2024
1 parent 88da99a commit 996d35d
Show file tree
Hide file tree
Showing 81 changed files with 886 additions and 965 deletions.
4 changes: 2 additions & 2 deletions Delynoi/include/Delynoi/config/DelynoiConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 &copy) = delete;
DelynoiConfig &operator=(const DelynoiConfig &copy) = delete; // NOLINT(*-use-equals-delete)

public:
/*
Expand Down
29 changes: 14 additions & 15 deletions Delynoi/include/Delynoi/models/Mesh.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#ifndef DELYNOI_MESH_H
#define DELYNOI_MESH_H

#include <Delynoi/config/DelynoiConfig.h>
#include <Delynoi/models/neighbourhood/PointMap.h>
#include <Delynoi/models/neighbourhood/SegmentMap.h>
#include <Delynoi/models/polygon/Polygon.h>
#include <Delynoi/models/polygon/Triangle.h>
#include <Delynoi/utilities/UniqueList.h>
#include <fstream>
#include <utility>

namespace Delynoi {
/*
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<typename T>
Expand All @@ -149,6 +147,7 @@ namespace Delynoi {

template<typename T>
Mesh<T>::Mesh(UniqueList<Point> &p, std::vector<T> &e, SegmentMap *s, PointMap *pM) {
// ReSharper disable once CppTemplateArgumentsCanBeDeduced
this->points = UniqueList<Point>(p);
this->polygons = e;
this->edges = s;
Expand All @@ -164,52 +163,52 @@ namespace Delynoi {
}

template<typename T>
void Mesh<T>::clear() {
void Mesh<T>::clear() const {
delete this->edges;
delete this->pointMap;
}

template<typename T>
void Mesh<T>::createFromFile(const std::string &fileName, int startIndex) {
void Mesh<T>::createFromFile(const std::string &fileName, const int startIndex) {
std::ifstream infile = utilities::openFile(fileName);
createFromStream(infile, startIndex);
infile.close();
}

template<typename T>
void Mesh<T>::createFromStream(std::ifstream &infile, int startIndex) {
void Mesh<T>::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<std::string> 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);
std::vector<std::string> splittedLine = utilities::splitBySpaces(line);

std::vector<int> 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());
this->polygons.push_back(newPolygon);
std::vector<IndexSegment> segments;
newPolygon.getSegments(segments);

for (IndexSegment s: segments) {
for (const IndexSegment &s: segments) {
this->edges->insert(s, i);
}
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -292,7 +291,7 @@ namespace Delynoi {
}

template<typename T>
NeighboursBySegment Mesh<T>::getNeighbours(IndexSegment s) {
NeighboursBySegment Mesh<T>::getNeighbours(const IndexSegment &s) const {
return this->edges->get(s);
}
} // namespace Delynoi
Expand Down
27 changes: 8 additions & 19 deletions Delynoi/include/Delynoi/models/Region.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
#ifndef DELYNOI_REGION_H
#define DELYNOI_REGION_H

#pragma clang diagnostic push
#pragma ide diagnostic ignored "HidingNonVirtualFunction"

#include <Delynoi/config/DelynoiConfig.h>
#include <Delynoi/models/basic/Segment.h>
#include <Delynoi/models/generator/PointGenerator.h>
#include <Delynoi/models/hole/Hole.h>
#include <Delynoi/models/hole/PolygonalHole.h>
#include <Delynoi/models/hole/clipper/ClipperWrapper.h>
#include <Delynoi/models/hole/clipper/lib/clipper.hpp>
#include <Delynoi/models/polygon/Polygon.h>
#include <Delynoi/utilities/delynoi_utilities.h>
#include <algorithm>
#include <climits>

#include <vector>

namespace Delynoi {
Expand Down Expand Up @@ -48,7 +38,7 @@ namespace Delynoi {
/*
* Constructor.
*/
explicit Region(std::vector<Point> &points);
explicit Region(const std::vector<Point> &points);

/*
* Default constructor
Expand All @@ -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<Point> &points);
Region(const Polygon &other, const std::vector<Point> &points);

/*
* Copy constructor.
Expand All @@ -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<Point> &points);
void mutate(const std::vector<Point> &points);

/*
* @return list of seed points of the region
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -153,5 +143,4 @@ namespace Delynoi {
};
} // namespace Delynoi

#pragma clang diagnostic pop
#endif
6 changes: 3 additions & 3 deletions Delynoi/include/Delynoi/models/basic/Angle.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(a / 360);
if (a >= 0 && a < 180) {
angle = a;
} else {
Expand All @@ -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

Expand Down
24 changes: 12 additions & 12 deletions Delynoi/include/Delynoi/models/basic/IndexSegment.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> {
class IndexSegment final : public Segment<int> {
public:
/*
* Hash
Expand Down Expand Up @@ -36,63 +36,63 @@ namespace Delynoi {
* @param point to check
* @return if the point is contained or not
*/
bool contains(const std::vector<Point> &p, Point point);
bool contains(const std::vector<Point> &p, const Point &point) const;

/*
* Determines if a point is contained in the segment.
* @param p mesh points
* @param point to check
* @return if the point is contained or not
*/
bool contains(const std::vector<Point> &p, const IndexSegment &s);
bool contains(const std::vector<Point> &p, const IndexSegment &s) const;

/*
* @param p mesh points
* @return point in the middle of the segment
*/
Point middlePoint(const std::vector<Point> &p);
Point middlePoint(const std::vector<Point> &p) const;

/*
* @param p mesh points
* @return angle of the segment in degrees
*/
double cartesianAngle(const std::vector<Point> &p);
double cartesianAngle(const std::vector<Point> &p) const;

/* Determines whether two segments intersect or not. Sets the intersection point in the last argument.
* @param p mesh points
* @param other second segment
* @param inter intersection point (only valid if segments intersect)
* @return segments intersect or not
*/
bool intersection(const std::vector<Point> &points, const PointSegment &other, Point &inter);
bool intersection(const std::vector<Point> &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
* @param other second segment
* @param inter intersection point (only valid if segments intersect)
* @return segments intersect or not
*/
bool intersection(const std::vector<Point> &points, const IndexSegment &other, Point &inter);
bool intersection(const std::vector<Point> &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<Point> &p);
bool isContained(const PointSegment &s, const std::vector<Point> &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<Point> &points, Point center);
void orderCCW(const std::vector<Point> &points, const Point &center);

/*
* @param points mesh points
* @param center reference point
* @return is the segment ordered in counter-clockwise order
*/
bool isCCW(const std::vector<Point> &points, Point center);
bool isCCW(const std::vector<Point> &points, const Point &center) const;

/*
* Returns the string representation of the segment.
Expand All @@ -116,12 +116,12 @@ namespace Delynoi {
* @param points mesh points
* @return length of the segment
*/
double length(const std::vector<Point> &points);
double length(const std::vector<Point> &points) const;

/* Displaces the segment.
* @param o value of the segment displacement
*/
IndexSegment add(int o);
IndexSegment add(int o) const;
};
} // namespace Delynoi

Expand Down
2 changes: 0 additions & 2 deletions Delynoi/include/Delynoi/models/basic/Point.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#define DELYNOI_POINT_H

#include <Delynoi/utilities/utilities.h>
#include <cmath>
#include <sstream>
#include <string>

namespace Delynoi {
Expand Down
10 changes: 5 additions & 5 deletions Delynoi/include/Delynoi/models/basic/PointSegment.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ namespace Delynoi {
/*
* This class models a segment which endpoints are represented by the points directly.
*/
class PointSegment : public Segment<Point> {
class PointSegment final : public Segment<Point> {
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.
Expand All @@ -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.
Expand All @@ -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
Expand Down
Loading

0 comments on commit 996d35d

Please sign in to comment.