1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
class segment {
public:
char type;
two_vector start,dir;
static int L;
static int U;
static int x;
two_vector get_end() { return start+dir; }
segment();
segment (char, two_vector);
segment (char, int, int);
segment& operator= (const segment&) ;
void increment_counter(char, int);
void change_dir(char);
};
int segment::L = 0;
int segment::U = 0;
int segment::x = 0;
segment::segment(){
type ='x';
start = two_vector(-1,-1);
dir = two_vector(0,0);
x++;
}
segment::segment (char direction, two_vector start_point){
start = start_point;
change_dir(direction);
increment_counter(direction,1);
}
segment::segment (char direction, int a, int b){
start = two_vector(a,b);
change_dir(direction);
increment_counter(direction,1);
}
segment& segment::operator= (const segment& rhs) {
this->start= rhs.start;
if(this->type == 'x'){ // works for assigning saved instance to unintiatied *this
change_dir(rhs.type);
increment_counter(this->type,1);
} else { // works for assigning saved instance to initiated *this
increment_counter(this->type,-1);
change_dir(rhs.type);
increment_counter(this->type,1);
}
return *this;
}
void segment::change_dir(char direction){
switch (direction){
case 'L':
type = direction;
dir = two_vector(-1,0);
break;
case 'U':
type = direction;
dir = two_vector(0,-1);
break;
default:
std::cout << "Incorrect segment direction assignment. Direction given was: "<< direction <<std::endl;
break;
}
}
void segment::increment_counter(char direction, int increment) {
switch (direction){
case 'L':
L+= increment;
break;
case 'U':
U+= increment;
break;
case 'x':
x+= increment;
break;
default:
std::cout << "failure to incrmement counter as type passed was: "<<direction<<std::endl;
break;
}
}
|