Skip to content

Commit

Permalink
small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
JulioJPinto committed Feb 27, 2024
1 parent 505879b commit d11f5d9
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 48 deletions.
13 changes: 0 additions & 13 deletions include/figure.hpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
#pragma once
#include <string>
#include <tuple>
#include <vector>

typedef std::vector<std::tuple<std::string, std::string>> Point;

class Triangle {
public:
Triangle();
std::vector<Point> getPoints();

private:
std::vector<Point> points;
};

class Figure {
public:
Figure();
Expand Down
3 changes: 3 additions & 0 deletions include/figure_generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
#include "figure.hpp"

std::unique_ptr<Figure> generatePlane(float length, int divisions);

std::unique_ptr<Figure> generateBox(float dimension, int divisions);

std::unique_ptr<Figure> generateSphere(float radius, int slices, int stacks);

std::unique_ptr<Figure> generateCone(float radius, float height, int slices,
int stacks);
4 changes: 3 additions & 1 deletion include/figures/plane.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma once

#include "figure.hpp"
#include "figure.hpp"

std::vector<Triangle> calculateTriangles(float length, int divisions);
14 changes: 14 additions & 0 deletions include/triangle.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once
#include <vector>

#include "utils.hpp"

class Triangle {
public:
Triangle();
std::vector<Point> getPoints();
void print();

private:
std::vector<Point> points;
};
6 changes: 6 additions & 0 deletions include/utils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once
#include <string>
#include <tuple>
#include <vector>

typedef std::vector<std::tuple<std::string, std::string>> Point;
6 changes: 0 additions & 6 deletions src/figure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@

#include <fstream>

Triangle::Triangle(Point a, Point b, Point c) {
points = std::vector<Point> points.push_back(a);
points.push_back(b);
points.push_back(c);
}

Figure::Figure() { triangles = std::vector<Triangle>(); }

void Figure::exportFile(std::string filename) {
Expand Down
12 changes: 2 additions & 10 deletions src/figure_generator.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
#include "figure_generator.hpp"
#include "plane.hpp"

#include <iostream>

// This is a placeholder for the actual implementation of the functions

std::unique_ptr<Figure> generatePlane(float length, int divisions) {
std::cout << "Generating Plane\n";
float max = length / 2;
float min = -max;

float div = length / divisions;

std::vector<float> all_values;
for (float i = min; i <= max; i += div) {
all_values.push_back(i);
}

calculateTriangles(length, divisions);
return std::make_unique<Figure>();
}

Expand Down
35 changes: 17 additions & 18 deletions src/figures/plane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,22 @@ float planeWidth = 5.0f;
float planeLength = 5.0f;
int divisions = 3;

std::vector<std::vector<float>> calculateTriangles() {
std::vector<Triangle> calculateTriangles(float length, int divisions) {
// Calculate half dimensions
float halfWidth = planeWidth / 2.0f;
float halfLength = planeLength / 2.0f;
float half = length / 2.0f;

// Calculate step size for divisions
float stepX = planeWidth / divisions;
float stepY = planeLength / divisions;
float steps = length / divisions;

std::vector<std::vector<float>> matrix;
std::vector<Triangles> triangles;

for (int i = 0; i < divisions; i++) {
for (int j = 0; j < divisions; j++) {

float x1 = -halfWidth + i * stepX;
float y1 = -halfLength + j * stepY;
float x2 = -halfWidth + (i + 1) * stepX;
float y2 = -halfLength + (j + 1) * stepY;
float x1 = -half + i * steps;
float y1 = -half + j * steps;
float x2 = -half + (i + 1) * steps;
float y2 = -half + (j + 1) * steps;

Point::p1 = Point(x1, 0.0f, y1);
Point::p2 = Point(x2, 0.0f, y1);
Expand All @@ -31,15 +29,16 @@ std::vector<std::vector<float>> calculateTriangles() {

Triangle::t1 = Triangle(p1,p2,p3);
Traingle::t2 = Triangle(p2,p4,p3);
// x1, 0.0f, y1
// x2, 0.0f, y1
// x1, 0.0f, y2

// // Draw second triangle
// x2, 0.0f, y1
// x2, 0.0f, y2
// x1, 0.0f, y2

triangles.push_back(t1);
triangles.push_back(t2);

}
}

for(int i = 0; i < triangles.size(); i++) {

}
return triangles;

}
6 changes: 6 additions & 0 deletions src/generator.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <string.h>

#include <iostream>
#include <string>

#include "../include/figure.hpp"
#include "../include/figure_generator.hpp"
Expand All @@ -24,6 +25,11 @@ inline std::unique_ptr<Figure> generateFigure(int argc, char* argv[]) {
} else if (figureType == "plane.3d" && argc == 5) {
// Generate Plane
std::cout << "Generating Plane\n";
int division = std::stoi(argv[1]);
int length = std::stof(argv[0]);

generatePlane(length, division);

return 0;
} else if (figureType == "cone.3d" && argc == 7) {
// Generate Cone
Expand Down
21 changes: 21 additions & 0 deletions src/triangle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "triangle.hpp"

Triangle::Triangle(Point a, Point b, Point c) {
points = std::vector<Point> points.push_back(a);
points.push_back(b);
points.push_back(c);
}


std::vector<Point> getPoints() {
return this.points;
}

void print() {

std::vector<Point> all_points = this.getPoints();
for(int i = 0; i < all_points.size(); i++) {
std::cout << all_points.at(i)
}

}
Empty file added src/utils.cpp
Empty file.

0 comments on commit d11f5d9

Please sign in to comment.