Skip to content
Snippets Groups Projects
Commit 61c7ff5c authored by Brandon Lai-Cheong's avatar Brandon Lai-Cheong
Browse files

refactored edge & triangle

parent b8f8e5a2
No related branches found
No related tags found
No related merge requests found
...@@ -24,6 +24,8 @@ add_executable( ...@@ -24,6 +24,8 @@ add_executable(
src/intersections/intersections.cpp src/intersections/intersections.cpp
src/shapes/triangle.cpp src/shapes/triangle.cpp
src/shapes/triangle_edges.cpp src/shapes/triangle_edges.cpp
src/contourize/contourize.cpp
src/shapes/edge.cpp
) )
include_directories(src) include_directories(src)
......
#include <shapes/triangle.h> #include <shapes/triangle.h>
#include <shapes/edge.h>
#include <shapes/triangle_edges.h>
#include <vector> #include <vector>
#include "contourize.h"
std::vector<Point> sortPoints(std::vector<Point> &points) {
bool positiveSide(Edge e, Point p) {
float h = e.p1.y - e.p2.y;
float g = e.p1.x - e.p2.x;
return -h * (p.x - e.p1.x) + g * (p.y - e.p1.y) >= 0;
} }
bool pointInTriangle(Point p, Triangle t) {
// all tests must be positive
auto edges = TriangleEdges(t);
return positiveSide(edges.e1, p) &&
positiveSide(edges.e2, p) &&
positiveSide(edges.e3, p);
}
void contourize(Triangle t1, Triangle t2, std::vector<Point> newIntersections) {
std::vector<Point> contourize(const Triangle &t1, const Triangle &t2, const std::vector<Point> &newIntersections) {
std::vector<Point> result;
// Go through each event point.
// If an even point is in a triangle, it is not part of the final Triangle
for (auto &p : t1.points) {
if (!t2.pointInTriangle(p)) {
result.push_back(p);
}
}
for (auto &p : t2.points) {
if (!t2.pointInTriangle(p)) {
result.push_back(p);
}
}
result.insert(result.end(), newIntersections.begin(), newIntersections.end());
return result;
} }
\ No newline at end of file
#pragma once
#include <vector>
struct Triangle;
struct Point;
std::vector<Point> contourize(const Triangle &t1, const Triangle &t2, const std::vector<Point> &newIntersections);
std::vector<Point> sortPoints(std::vector<Point> &points);
\ No newline at end of file
#include "edge.h"
bool Edge::positiveSide(const Point &p) const {
float h = p1.y - p2.y;
float g = p1.x - p2.x;
return -h * (p.x - p1.x) + g * (p.y - p1.y) >= 0;
}
\ No newline at end of file
...@@ -3,4 +3,6 @@ ...@@ -3,4 +3,6 @@
struct Edge { struct Edge {
Point p1, p2; Point p1, p2;
bool positiveSide(const Point &p) const;
}; };
\ No newline at end of file
#include "triangle.h" #include "triangle.h"
#include "triangle_edges.h"
#include "edge.h"
bool Triangle::neighbours(Triangle &other) { bool Triangle::neighbours(Triangle &other) {
return false; return false;
} }
Triangle::Triangle(Point p1, Point p2, Point p3, int depth) : points{p1,p2,p3}, depth{depth} {} Triangle::Triangle(Point p1, Point p2, Point p3, int depth) : points{p1,p2,p3}, depth{depth} {}
\ No newline at end of file
bool Triangle::pointInTriangle(const Point &p) const {
// all tests must be positive
auto edges = TriangleEdges(*this);
return edges.e1.positiveSide(p) &&
edges.e2.positiveSide(p) &&
edges.e3.positiveSide(p);
}
\ No newline at end of file
...@@ -7,4 +7,5 @@ struct Triangle { ...@@ -7,4 +7,5 @@ struct Triangle {
int depth; int depth;
bool neighbours(Triangle &other); bool neighbours(Triangle &other);
Triangle(Point p1, Point p2, Point p3, int depth); Triangle(Point p1, Point p2, Point p3, int depth);
bool pointInTriangle(const Point &p) const;
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment