Skip to content

Commit

Permalink
Merge pull request #109 from GrafVonTee/develop
Browse files Browse the repository at this point in the history
Huge update
  • Loading branch information
GrafVonTee authored Jun 21, 2023
2 parents 5028f8c + dde85d1 commit 72aa84a
Show file tree
Hide file tree
Showing 30 changed files with 2,557 additions and 620 deletions.
17 changes: 9 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,12 @@ file(GLOB_RECURSE SOURCES_CONSOLE src/user_interaction/*.cpp)
file(GLOB_RECURSE SOURCES_GUI src/drawing/*.cpp)
file(GLOB_RECURSE SOURCES_UTILS src/utils/*.cpp)

file(GLOB_RECURSE TESTS tests/*.cpp)

# unit_test configuration
add_executable(
unit_tests
tests/unit_tests.cpp

${TESTS}
${SOURCES_MATH}
${SOURCES_CONSOLE}
${SOURCES_GUI}
Expand All @@ -141,7 +142,7 @@ target_link_libraries(

# triangle_intersection configuration
add_executable(
triangle_intersection
Interpol
src/main.cpp

${SOURCES_MATH}
Expand All @@ -150,13 +151,13 @@ add_executable(
${SOURCES_UTILS}
)

target_include_directories(triangle_intersection PUBLIC include)
target_include_directories(triangle_intersection PUBLIC imgui)
target_include_directories(triangle_intersection PUBLIC glad)
target_include_directories(triangle_intersection PUBLIC glfw)
target_include_directories(Interpol PUBLIC include)
target_include_directories(Interpol PUBLIC imgui)
target_include_directories(Interpol PUBLIC glad)
target_include_directories(Interpol PUBLIC glfw)

target_link_libraries(
triangle_intersection
Interpol
imgui
glfw
glad
Expand Down
6 changes: 4 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Contribution Guidelines

Help wanted! We'd love your contributions to `triangle_intersection`. Please review the following guidelines before contributing. Also, feel free to propose changes to these guidelines by updating this file and submitting a pull request.
Help wanted! We'd love your contributions to `Interpol`. Please review the following guidelines before contributing. Also, feel free to propose changes to these guidelines by updating this file and submitting a pull request.

## Have a question?

Expand All @@ -10,6 +10,8 @@ You can check our tg (@grafvontee and @kr1stt) and ask us!
You can use [issues](../../issues) to report bugs. Provide all the requested information, otherwise your issue could be closed. Please also feel free to submit a Pull Request with a fix for the bug! For sensitive security-related issues, please report via telegram!

Consider checking [Bug Template](.github/ISSUE_TEMPLATE/bug_report.md) before reporting.

## Have a Feature Request?

All feature requests should start with [submitting an issue](../../issues/new) documenting the user story and acceptance criteria. Provide all the requested information, otherwise your issue could be closed. Again, feel free to submit a `Pull Request` with a proposed implementation of the feature.
Expand All @@ -32,7 +34,7 @@ We may have additional questions and will communicate through the GitHub issue,
### How to submit Pull Requests

1. Fork this repo
2. Clone your fork and create a new branch: `git clone https://github.com/GrafVonTee/triangle_intersections.git -b name_for_new_branch`.
2. Clone your fork and create a new branch: `git clone https://github.com/GrafVonTee/Interpol.git -b name_for_new_branch`.
3. Make changes and test
4. Publish the changes to your fork
5. Submit a Pull Request with comprehensive description of changes
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ To run the project, you must compile and run the executable. Follow the steps be

Need `python 3.*` and `PyCocoa lib`.
```
git clone https://github.com/GrafVonTee/triangle_intersections.git
cd triangle_intersections
git clone https://github.com/GrafVonTee/Interpol.git
cd Interpol
mkdir build
cd build
cmake ..
make
./triangle_intersection
./Interpol
```

## Example
Expand Down
19 changes: 11 additions & 8 deletions include/CalculateIntersections.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef TRIANGLE_INTERSECTIONS_CALCULATEINTERSECTIONS_H
#define TRIANGLE_INTERSECTIONS_CALCULATEINTERSECTIONS_H
#ifndef POLYGON_INTERSECTIONS_CALCULATEINTERSECTIONS_H
#define POLYGON_INTERSECTIONS_CALCULATEINTERSECTIONS_H

#include <vector>
#include <algorithm>
Expand All @@ -9,7 +9,8 @@

namespace Math {

// Important case - it is when 2 lines not parallel and sections have intersection. If case is important, we get coords of intersection point, else we get (0,0) point
// Important case - it is when 2 lines not parallel and sections have intersection.
// If case is important, we get coords of intersection point, else we get (0,0) point
struct LineIntersection{
Geometry::Point point;
bool isImportantCase;
Expand All @@ -27,11 +28,13 @@ namespace Math {
// Adding into vector all vertex of "internal" polygon which is locating into "external polygon"
void addInsideVertex(std::vector<Geometry::Point>& list, const Geometry::Polygon& internal, const Geometry::Polygon& external);

// Important case - it is when 2 lines not parallel and sections have intersection. If case is important, we get coords of intersection point, else we get (0,0) point
LineIntersection findLinesInter(Geometry::Point& firstStart, Geometry::Point& firstEnd,
Geometry::Point& secondStart,Geometry::Point& secondEnd);
// Important case - it is when 2 lines not parallel and sections have intersection.
// If case is important, we get coords of intersection point, else we get (0,0) point
LineIntersection findLinesInter(const Geometry::Point &firstStart, const Geometry::Point &firstEnd,
const Geometry::Point &secondStart, const Geometry::Point &secondEnd);

// Main function of math module, find intersection area
Geometry::Intersection findTriangleInter(Geometry::Polygon& first, Geometry::Polygon& second);
Geometry::Intersection findPolygonsInter(const Geometry::Polygon &first, const Geometry::Polygon &second);

}
#endif //TRIANGLE_INTERSECTIONS_CALCULATEINTERSECTIONS_H
#endif //POLYGON_INTERSECTIONS_CALCULATEINTERSECTIONS_H
19 changes: 11 additions & 8 deletions include/ConsoleInteraction.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,32 @@

#include <tuple>
#include <string>
#include "StatesLibrary.h"

namespace Interaction {
using point_result_t = std::tuple<Geometry::Point, States::InputState>;
using triangle_result_t = std::tuple<Geometry::Polygon, States::InputState>;
using triangle_pair_t = std::tuple<Geometry::Polygon, Geometry::Polygon>;
using polygon_result_t = std::tuple<Geometry::Polygon, States::InputState>;
using polygon_pair_t = std::tuple<Geometry::Polygon, Geometry::Polygon>;

void greeting(const std::string &userName);
void goodbye(const std::string &userName);
void welcomeToGui();
std::string getUserName();
triangle_result_t getTriangle(const std::string &letter,
std::istream& inputStream = std::cin,
std::ostream& outputStream = std::cout);

point_result_t getPoint(const std::string &letter,
std::istream& inputStream = std::cin,
std::ostream& outputStream = std::cout);
triangle_pair_t getBothTriangles(std::istream& inputStream = std::cin,
std::ostream& outputStream = std::cout);

polygon_pair_t getBothPolygons(std::istream& inputStream = std::cin,
std::ostream& outputStream = std::cout);

Manipulator::FiguresState getFiguresStateFromInput(std::istream& inputStream = std::cin,
std::ostream& outputStream = std::cout);

void printPoint(const Geometry::Point &point);
void printTriangle(const Geometry::Polygon &triangle);
void printIntersection(const Geometry::Intersection &intersection);
void printPolygon(const Geometry::Polygon &polygon);
void printStateFromLibrary(size_t indexState = -1);

std::string getTypeNameOfPolygon(const States::PolygonState &state);
}
Expand Down
41 changes: 33 additions & 8 deletions include/ConstantsForDrawing.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,44 @@
#ifndef TRIANGLE_INTERSECTIONS_CONSTANTSFORDRAWING_H
#define TRIANGLE_INTERSECTIONS_CONSTANTSFORDRAWING_H

#include <string>
#include "imgui.h"

namespace DrawConst {

struct ColorParameters {
float Hue;
float Saturation;
float Value;
};

extern const ColorParameters HSV_GREEN_DEFAULT;
extern const ColorParameters HSV_GREEN_HOVERED;
extern const ColorParameters HSV_GREEN_ACTIVE;

extern const ColorParameters HSV_RED_DEFAULT;
extern const ColorParameters HSV_RED_HOVERED;
extern const ColorParameters HSV_RED_ACTIVE;

extern const float LETTER_FONT_SIZE;
extern const float LINE_THICKNESS;
extern const float INTERSECTION_POINT_SIZE;
extern const float POINT_SIZE;

extern const int WINDOW_WIDTH;
extern const int WINDOWS_HEIGHT;
extern const int DISPLAY_SIZE;
extern const int DISPLAY_SCALE;

extern const float WINDOW_WIDTH;
extern const float WINDOWS_HEIGHT;
extern const float DISPLAY_SIZE;
extern const float DISPLAY_SCALE;
extern const float SQUARE_SIDE_SIZE;
extern const float INDENT_SIZE;
}
extern constinit int BUFFER_SIZE;

#endif //TRIANGLE_INTERSECTIONS_CONSTANTSFORDRAWING_H
extern const ImU32& RED_COLOR;
extern const ImU32& GREEN_COLOR;
extern const ImU32& YELLOW_COLOR;
extern const ImU32& WHITE_COLOR;

extern const std::string HEX_AND_HEX_DEMO_INPUT;
extern const std::string TRIANGLE_AND_TRIANGLE_DEMO_INPUT;
}
#endif //TRIANGLE_INTERSECTIONS_CONSTANTSFORDRAWING_H
40 changes: 32 additions & 8 deletions include/DrawImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,39 @@
#include "imgui_impl_glfw.h"
#include "imgui_impl_opengl3.h"
#include "GeometryUtils.h"

#define RED_COLOR IM_COL32(186, 36, 66, 255)
#define GREEN_COLOR IM_COL32(40, 156, 80, 255)
#define YELLOW_COLOR IM_COL32(204, 189, 12, 255)
#define WHITE_COLOR IM_COL32(255, 255, 255, 255)
#include "GetImVecFromPolygon.h"
#include "ConstantsForDrawing.h"

namespace DrawOutput {
void draw_triangles_and_intersection(Geometry::Polygon &tr1,
Geometry::Polygon &tr2,
Geometry::Intersection &intersection);
void drawPolygonsAndIntersection();

void DrawPoint(
ImDrawList *draw_list,
const Geometry::Point& point,
const DrawUtils::scalingParameters& parameters,
const ImVec2& offset = ImVec2(0, 0),
const ImU32& col = DrawConst::WHITE_COLOR
);
void DrawPolygon(
ImDrawList *draw_list,
const Geometry::Polygon& polygon,
const DrawUtils::scalingParameters& parameters,
const ImVec2& offset = ImVec2(0, 0),
const ImU32& col = DrawConst::WHITE_COLOR
);
// set muted to "true" if you don't want your point to be editable
bool DisplayPoint(Geometry::Point &point, bool muted = false);
void DisplayPolygon(Geometry::Polygon &polygon,
const std::string& title = "default",
States::FigureName figname = States::FigureName::Intersection,
bool muted = false
);
void DisplayAddButton(Geometry::Polygon &polygon, States::FigureName figname);
void DisplayDeleteButton(Geometry::Polygon& polygon, Geometry::Point& point, States::FigureName figname);
void HelpMarker(const char* desc);
bool ErrorMarker(const char* desc);
void DisplayRevertButton();
inline void DrawCanvas();
inline void DrawProperties();
}
#endif // TRIANGLE_INTERSECTIONS_DRAW_IMAGE_H
36 changes: 28 additions & 8 deletions include/GeometryUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ namespace Geometry {
Point(Point &&other) noexcept;

// Getters
[[nodiscard]] coord_t getX() const;
[[nodiscard]] coord_t getY() const;
[[nodiscard]] std::string getLabel() const;
coord_t getX() const;
coord_t getY() const;
std::string getLabel() const;

// Setters
void setX(const coord_t &x);
Expand All @@ -59,6 +59,17 @@ namespace Geometry {
bool operator==(Point&& other) const noexcept;
bool operator!=(Point&& other) const noexcept;

struct HashFunction
{
size_t operator()(const Point& point) const
{
size_t xHash = std::hash<coord_t>()(point.getX());
size_t yHash = std::hash<coord_t>()(point.getY()) << 1;
return xHash ^ yHash;
}
};


Point& operator=(const Point &other);
Point& operator=(Point &&other) noexcept;

Expand All @@ -77,14 +88,17 @@ namespace Geometry {
@type m_state: PolygonState
Methods:
static checkPolygon: check polygon's points for valid input
size(): return size of a vector
sortPoints(): sort vector using atan2 function
emplaceBack(const Point& | Point&&): emplace point in Polygon, auto-validator and auto-sort
popBack(): delete last point from vector
*/
private:
std::vector<Point> m_pointList{};
States::PolygonState m_state = States::PolygonState::NotPolygon;

static void checkPolygon(const std::vector<Point> &points);
// Subfunction for checkPolygon(const std::vector<Point> &points)
static void checkPointsForPolygon(const Point &p1, const Point &p2, const Point &p3);
public:
// Constructors
Expand All @@ -94,13 +108,18 @@ namespace Geometry {
Polygon(Polygon &&other) noexcept;

// Getters
[[nodiscard]] States::PolygonState getState() const;
[[nodiscard]] std::vector<Point> &getPointsRef();
[[nodiscard]] std::vector<Point> getPointsCopy() const;
States::PolygonState getState() const;
std::vector<Point> &getPointsRef();
std::vector<Point> getPointsCopy() const;

// Methods
[[nodiscard]] size_t size() const;
static void checkPolygon(const std::vector<Point> &points);
size_t size() const;
void sortPoints();
void emplaceBack(const Point& point, bool sort = true, bool check = true);
void emplaceBack(Point&& point, bool sort = true, bool check = true);
void popBack();
void popAt(Point point);

// Operators
friend std::ostream &operator<<(std::ostream &out, const Polygon &polygon);
Expand Down Expand Up @@ -131,6 +150,7 @@ namespace Geometry {
States::IntersectionState state = States::IntersectionState::NoIntersection;
Polygon polygon;
};

}

#endif //TRIANGLE_INTERSECTIONS_GEOMETRYUTILS_H
Loading

0 comments on commit 72aa84a

Please sign in to comment.