Comment + unique_ptr issue + correct horse battery staple

This commit is contained in:
Tyler Beckman 2024-11-18 00:18:28 -07:00
parent 99f1a4863a
commit 764f468028
Signed by: Ty
GPG key ID: 2813440C772555A4
19 changed files with 222 additions and 220 deletions

View file

@ -1,7 +1,7 @@
#ifndef COORDINATE_H #ifndef COORDINATE_H
#define COORDINATE_H #define COORDINATE_H
class Coordinate { class Coordinate {
public: public:
Coordinate(); Coordinate();
Coordinate(const double X, const double Y); Coordinate(const double X, const double Y);

View file

@ -2,7 +2,7 @@
#define EQUILATERAL_TRIANGLE_H #define EQUILATERAL_TRIANGLE_H
#include "Triangle.h" #include "Triangle.h"
class EquilateralTriangle : public ATriangle { class EquilateralTriangle : public ATriangle {
public: public:
bool validate() override; bool validate() override;
}; };

View file

@ -12,7 +12,7 @@ bool double_eq(double first, double second) {
} }
} }
double calculate_distance(Coordinate &firstPoint, Coordinate &secondPoint) { double calculate_distance(Coordinate& firstPoint, Coordinate& secondPoint) {
return std::sqrt(std::pow(secondPoint.x - firstPoint.x, 2) + return std::sqrt(std::pow(secondPoint.x - firstPoint.x, 2) +
std::pow(secondPoint.y - firstPoint.y, 2)); std::pow(secondPoint.y - firstPoint.y, 2));
} }

View file

@ -22,7 +22,7 @@ bool double_eq(double first, double second);
* @param secondPoint The second coordinate point to compare the first to * @param secondPoint The second coordinate point to compare the first to
* @return double The pythagorean distance between the two points * @return double The pythagorean distance between the two points
*/ */
double calculate_distance(Coordinate &firstPoint, Coordinate &secondPoint); double calculate_distance(Coordinate& firstPoint, Coordinate& secondPoint);
/** /**
* @brief Returns true if all of the side lengths in the specified array make a * @brief Returns true if all of the side lengths in the specified array make a

View file

@ -2,7 +2,7 @@
#define ISOSCELES_TRIANGLE_H #define ISOSCELES_TRIANGLE_H
#include "Triangle.h" #include "Triangle.h"
class IsoscelesTriangle : public ATriangle { class IsoscelesTriangle : public ATriangle {
public: public:
bool validate() override; bool validate() override;
}; };

View file

@ -15,7 +15,7 @@ APolygon::~APolygon() { delete[] mVertices; }
void APolygon::setColor(const sf::Color COLOR) { _color = COLOR; } void APolygon::setColor(const sf::Color COLOR) { _color = COLOR; }
void APolygon::draw(sf::RenderTarget &window) { void APolygon::draw(sf::RenderTarget& window) {
sf::ConvexShape shape(mNumVertices); sf::ConvexShape shape(mNumVertices);
for (int i = 0; i < mNumVertices; i++) { for (int i = 0; i < mNumVertices; i++) {
shape.setPoint(i, sf::Vector2f(mVertices[i].x, mVertices[i].y)); shape.setPoint(i, sf::Vector2f(mVertices[i].x, mVertices[i].y));

View file

@ -5,7 +5,7 @@
#include <SFML/Graphics.hpp> #include <SFML/Graphics.hpp>
class APolygon { class APolygon {
public: public:
/** /**
* @brief Construct a new Polygon object, with a white color and 0 vertices * @brief Construct a new Polygon object, with a white color and 0 vertices
*/ */
@ -26,7 +26,7 @@ class APolygon {
* *
* @param window The render target to draw the polygon on * @param window The render target to draw the polygon on
*/ */
void draw(sf::RenderTarget &window); void draw(sf::RenderTarget& window);
/** /**
* @brief Sets the coordinate point at a specific vertex of this polygon * @brief Sets the coordinate point at a specific vertex of this polygon
* *
@ -43,11 +43,11 @@ class APolygon {
*/ */
virtual bool validate() = 0; virtual bool validate() = 0;
protected: protected:
short mNumVertices; short mNumVertices;
Coordinate *mVertices; Coordinate* mVertices;
private: private:
sf::Color _color; sf::Color _color;
}; };

View file

@ -2,7 +2,7 @@
#define QUADRILATERAL_H #define QUADRILATERAL_H
#include "Polygon.h" #include "Polygon.h"
class AQuadrilateral : public APolygon { class AQuadrilateral : public APolygon {
public: public:
AQuadrilateral(); AQuadrilateral();
}; };

View file

@ -2,7 +2,7 @@
#define RHOMBUS_H #define RHOMBUS_H
#include "Quadrilateral.h" #include "Quadrilateral.h"
class Rhombus : public AQuadrilateral { class Rhombus : public AQuadrilateral {
public: public:
bool validate() override; bool validate() override;
}; };

View file

@ -2,7 +2,7 @@
#define SCALENE_TRIANGLE_H #define SCALENE_TRIANGLE_H
#include "Triangle.h" #include "Triangle.h"
class ScaleneTriangle : public ATriangle { class ScaleneTriangle : public ATriangle {
public: public:
bool validate() override; bool validate() override;
}; };

View file

@ -2,7 +2,7 @@
#define TRIANGLE_H #define TRIANGLE_H
#include "Polygon.h" #include "Polygon.h"
class ATriangle : public APolygon { class ATriangle : public APolygon {
public: public:
ATriangle(); ATriangle();
}; };

View file

@ -1,8 +1,10 @@
/** /**
* @author Tyler Beckman (tyler_beckman@mines.edu) * @author Tyler Beckman (tyler_beckman@mines.edu)
* @brief A program template for CSCI200 * @brief A program to read polygon points and colors from a data file and
* display them utilizing the SFML library, validating all shapes at each point
* during processing.
* @version 1 * @version 1
* @date 2024-09-21 * @date 2024-11-11
*/ */
#include "Coordinate.h" #include "Coordinate.h"
@ -64,10 +66,10 @@ int main(void) {
currentPolygon = std::make_unique<Rhombus>(); currentPolygon = std::make_unique<Rhombus>();
break; break;
default: default:
std::cout << "polygon is invalid - \"" << type << " " << x1 std::cout << "polygon is invalid - \"" << type << " " << x1 << " " << y1
<< " " << y1 << " " << x2 << " " << y2 << " " << x3 << " " << x2 << " " << y2 << " " << x3 << " " << y3 << " "
<< " " << y3 << " " << x4 << " " << y4 << " " << r << x4 << " " << y4 << " " << r << " " << g << " " << b << "\""
<< " " << g << " " << b << "\"" << std::endl; << std::endl;
continue; continue;
} }
@ -80,20 +82,20 @@ int main(void) {
currentPolygon->setColor(sf::Color(r, g, b)); currentPolygon->setColor(sf::Color(r, g, b));
if (!currentPolygon->validate()) { if (!currentPolygon->validate()) {
std::cout << "polygon is invalid - \"" << type << " " << x1 << " " std::cout << "polygon is invalid - \"" << type << " " << x1 << " " << y1
<< y1 << " " << x2 << " " << y2 << " " << x3 << " " << y3; << " " << x2 << " " << y2 << " " << x3 << " " << y3;
if (x4 != -1) { if (x4 != -1) {
std::cout << " " << x4 << " " << y4; std::cout << " " << x4 << " " << y4;
} }
std::cout << " " << r << " " << g << " " << b << "\"" << std::endl; std::cout << " " << r << " " << g << " " << b << "\"" << std::endl;
} else { } else {
polygonList.push_back(currentPolygon); polygonList.push_back(std::move(currentPolygon));
} }
}; };
// Start SFML Rendering logic // Start SFML Rendering logic
sf::RenderWindow window( sf::RenderWindow window(
sf::VideoMode(640, 640), ":3", sf::VideoMode(640, 640), "correct horse battery staple",
sf::Style::Titlebar | sf::Style::Close // Disable window resize sf::Style::Titlebar | sf::Style::Close // Disable window resize
); );
window.setVerticalSyncEnabled(true); window.setVerticalSyncEnabled(true);