lab 5 part 1 done

This commit is contained in:
2022-05-02 22:07:53 -05:00
parent bf5490504c
commit e381f5d7ca
7 changed files with 69 additions and 44 deletions

View File

@@ -35,28 +35,14 @@ Line::Line(int x0, int y0, int x1, int y1, uint32_t color){
Line::Line(const Line &from){ Line::Line(const Line &from){
this->color = from.color; this->color = from.color;
this->coords = new Matrix(4,3); this->coords = new Matrix(3,3);
// for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
// { {
// for (int j = 0; j < 2; j++) for (int j = 0; j < 2; j++)
// { {
// // Needs a look (*coords)[i][j] = (*from.coords)[i][j];
// this->coords[i][j] = from.coords[i][j]; }
// //(*coords)[i][j] = (*from.coords)[i][j]; }
// }
// }
this->coords[0][0] = from.coords[0][0];
this->coords[0][1] = from.coords[0][1];
this->coords[0][2] = from.coords[0][2];
this->coords[1][0] = from.coords[1][0];
this->coords[1][1] = from.coords[1][1];
this->coords[1][2] = from.coords[1][2];
this->coords[2][0] = from.coords[2][0];
this->coords[2][1] = from.coords[2][1];
this->coords[2][2] = from.coords[2][2];
} }
Line::~Line(){ Line::~Line(){
@@ -73,7 +59,7 @@ Line &Line::operator=(const Line &rhs){
{ {
for (int j = 0; j < 2; j++) for (int j = 0; j < 2; j++)
{ {
this->coords[i][j] = rhs.coords[i][j]; (*coords)[i][j] = (*rhs.coords)[i][j];
} }
} }
} }
@@ -86,6 +72,21 @@ void Line::draw(GraphicsContext *gc){
(*coords)[1][0], (*coords)[1][1]); (*coords)[1][0], (*coords)[1][1]);
} }
void Line::out(std::ostream& os) const{
os << "-Line-" << endl;
os << "Color: " << color << endl;
os << "Point 1 - X: " << (*coords)[0][0];
os << " Y: " << (*coords)[0][1];
os << " Z: " << (*coords)[0][2] << endl;
os << "Point 2 - X: " << (*coords)[1][0];
os << " Y: " << (*coords)[1][1];
os << " Z: " << (*coords)[1][2] << endl;
}
Shape* Line::clone(){ Shape* Line::clone(){
return new Line(*this); return new Line(*this);
} }

View File

@@ -23,6 +23,7 @@ class Line: public Shape{
~Line(); ~Line();
Line& operator=(const Line& rhs); Line& operator=(const Line& rhs);
void draw(GraphicsContext *gc); void draw(GraphicsContext *gc);
void out(std::ostream& os) const;
Shape* clone(); Shape* clone();
}; };

View File

@@ -23,13 +23,12 @@ int main(void)
Shape* T1 = new Triangle(250, 100, 50, 320, 125, 200, GraphicsContext::RED); Shape* T1 = new Triangle(250, 100, 50, 320, 125, 200, GraphicsContext::RED);
Shape* L2 = L1->clone(); Shape* L2 = L1->clone();
Shape* T2 = T1->clone(); Shape* T2 = T1->clone();
Shape* L3(L1);
Shape* T3(T1);
delete L1; delete L1;
delete T1; delete T1;
(*L3).draw(gc); (*L2).draw(gc);
(*T3).draw(gc); (*T2).draw(gc);
(*L2).out(cout);
(*T2).out(cout);
sleep(5); sleep(5);

View File

@@ -13,17 +13,10 @@
Shape::Shape(){ Shape::Shape(){
this->color = (uint32_t) 0x00FFFFFF; this->color = (uint32_t) 0x00FFFFFF;
} }
Shape::Shape(const Shape& from){ Shape::Shape(const Shape& from){};
this->color = from.color;
this->coords = from.coords;
}
Shape::~Shape(){}; Shape::~Shape(){};
void Shape::draw(GraphicsContext *gc){}
void Shape::out(std::ostream& os, const Shape& rhs){}
Shape& Shape::operator=(const Shape& rhs){ Shape& Shape::operator=(const Shape& rhs){
return *this; return *this;
} }

View File

@@ -1,5 +1,15 @@
#ifndef shape_h #ifndef shape_h
#define shape_h #define shape_h
/**
* @file shape.h
* @author Trevor Barnes (barnestr@msoe.edu)
* @brief
* @version 1.0
* @date 2022-04-12
*
* @copyright Copyright (c) 2022
*
*/
#include <iostream> #include <iostream>
#include "x11context.h" #include "x11context.h"
#include "matrix.h" #include "matrix.h"
@@ -15,9 +25,9 @@ class Shape{
// Destructor // Destructor
virtual ~Shape(); virtual ~Shape();
// Draw shape // Draw shape
virtual void draw(GraphicsContext *gc); virtual void draw(GraphicsContext *gc) = 0;
// Print to output stream // Print to output stream
virtual void out(std::ostream& os, const Shape& rhs); virtual void out(std::ostream& os)const = 0;
// Virtual Constructor // Virtual Constructor
virtual Shape* clone() = 0; // Pure virtual "=0" virtual Shape* clone() = 0; // Pure virtual "=0"
protected: protected:
@@ -26,7 +36,7 @@ class Shape{
// RGB color // RGB color
uint32_t color; uint32_t color;
// Assignment Operator // Assignment Operator
Shape& operator=(const Shape& rhs); virtual Shape& operator=(const Shape& rhs);
}; };
#endif #endif

View File

@@ -68,6 +68,26 @@ Triangle& Triangle::operator=(const Triangle& rhs){
return *this; return *this;
} }
void Triangle::out(std::ostream& os) const{
os << "-Triangle-" << endl;
os << "Color: " << color << endl;
os << "Point 1 - X: " << (*coords)[0][0];
os << " Y: " << (*coords)[0][1];
os << " Z: " << (*coords)[0][2] << endl;
os << "Point 2 - X: " << (*coords)[1][0];
os << " Y: " << (*coords)[1][1];
os << " Z: " << (*coords)[1][2] << endl;
os << "Point 3 - X: " << (*coords)[2][0];
os << " Y: " << (*coords)[2][1];
os << " Z: " << (*coords)[2][2] << endl;
}
Shape* Triangle::clone(){ Shape* Triangle::clone(){
return new Triangle(*this); return new Triangle(*this);
} }

View File

@@ -23,6 +23,7 @@ class Triangle: public Shape{
~Triangle(); ~Triangle();
Triangle& operator=(const Triangle& rhs); Triangle& operator=(const Triangle& rhs);
void draw(GraphicsContext *gc); void draw(GraphicsContext *gc);
void out(std::ostream& os) const;
Shape* clone(); Shape* clone();
private: private:
Matrix * coords; Matrix * coords;