hi guys,,,can u plz tell me why i get the following error when i compile my 4 files?????
i have in my image.h file :
#include <vector>
#include "colour.h"
#include <iostream>
#include "canvas.h"
class Image {
public:
Image( );
~Image();
void draw_line(int x1, int y1, int x2, int y2);
void draw_box(int x1, int y2, int x2, int y2);
void draw_circle(int x, int y, int r);
void draw_fill(int x, int y);
};
and my image.cc is :
#include Image.h
#include<iostream>
#include<cmath>
#include <algorithm>
void draw_line(int x1, int y1, int x2, int y2) {
int dx = x2-x1;
int dy = y2-y1;
set_pixel(x1,y1);
if (std::abs(dx) > std::abs(dy)) {
double m = static_cast<double>(dy) / static_cast<double>(dx);
double b = y1 - m*x1;
dx = (dx < 0) ? -1 : 1;
while (x1 != x2) {
x1+=dx;
set_pixel(x1,static_cast<int>(std::floor(m*x1+b+0. 5)));
}
} else {
double m = static_cast<double>(dx) / static_cast<double>(dy);
double b = x1 - m*y1;
dy = (dy < 0) ? -1 : 1;
while (y1 != y2) {
y1+=dy;
set_pixel(static_cast<int>(std::floor(m*y1+b+0.5)) ,y1);
}
}
}
void draw_box(int x1, int y1, int x2, int y2) {
if (x1>x2)
std::swap(x1,x2);
if (y1>y2)
std::swap(y1,y2);
if (x1==x2 || y1==y2)
draw_line(x1,y1,x2,y2);
else if (x1+1 == x2) {
draw_line(x1,y1,x1,y2);
draw_line(x2,y1,x2,y2);
} else if (y1+1 == y2) {
draw_line(x1,y1,x2,y1);
draw_line(x1,y2,x2,y2);
} else {
draw_line(x1,y1,x1,y2);
draw_line(x2,y1,x2,y2);
draw_line(x1+1,y2,x2-1,y2);
draw_line(x1+1,y1,x2-1,y1);
}
}
void draw_circle(int x, int y, int r) {
set_pixel(x,y+r);
set_pixel(x,y-r);
set_pixel(x+r,y);
set_pixel(x-r,y);
int r2 = r*r;
int xp = 1;
int yp = static_cast<int>(std::sqrt(static_cast<double>(r2-1))+0.5);
while (xp < yp) {
set_pixel(x + xp, y + yp);
set_pixel(x + xp, y - yp);
set_pixel(x - xp, y + yp);
set_pixel(x - xp, y - yp);
set_pixel(x + yp, y + xp);
set_pixel(x + yp, y - xp);
set_pixel(x - yp, y + xp);
set_pixel(x - yp, y - xp);
xp++;
yp = static_cast<int>(std::sqrt(static_cast<double>(r2-xp*xp)) +0.5)
}
if (xp == yp) {
set_pixel(x + xp, y + yp);
set_pixel(x + xp, y - yp);
set_pixel(x - xp, y + yp);
set_pixel(x - xp, y - yp);
}
}
void draw_fill(int x, int y) {
if ( x <0 || x >= get_width() || y<0 || y>=get_height())
return;
if (get_pixel(x,y) != get_colour()) {
set_pixel(x,y);
draw_fill(x-1,y);
draw_fill(x+1,y);
draw_fill(x,y+1);
draw_fill(x,y-1);
}
}
the command class.h is:
#ifndef COMMAND_H
#define COMMAND_H
bool parse_command(std::istream &is);
#endif
and the command.cc is:
#include <string>
#include <iostream>
#include "Image.h"
static bool size_done = false;
static bool cmd_size(std::istream &is) {
int x,y;
is >> x >> y;
if (! is)
return false;
if (size_done)
return false;
size_done = true;
set_size(x,y);
return true;
}
static bool cmd_colour(std::istream &is) {
std::string col;
is >> col;
if (col == "black")
set_colour(BLACK);
else if (col == "white")
set_colour(WHITE);
else if (col == "xor")
set_colour(XOR);
else
return false;
return true;
}
static bool cmd_point(std::istream &is) {
int x,y;
is >> x >> y;
if (! is)
return false;
set_pixel(x,y);
return true;
}
static bool cmd_line(std::istream &is) {
int x1, y1, x2, y2;
is >> x1 >> y1 >> x2 >> y2;
if (! is)
return false;
draw_line(x1,y1,x2,y2);
return true;
}
static bool cmd_box(std::istream &is) {
int x1,y1,x2,y2;
is >> x1 >> y1 >> x2 >> y2;
if (! is)
return false;
draw_box(x1,y1,x2,y2);
return true;
}
static bool cmd_circle(std::istream &is) {
int x,y,r;
is >> x >> y >> r;
if (! is)
return false;
draw_circle(x,y,r);
return true;
}
static bool cmd_fill(std::istream &is) {
int x,y;
is >> x >> y;
if (! is)
return false;
if (get_colour() == XOR)
return false;
draw_fill(x,y);
return true;
}
bool parse_command(std::istream &is) {
std::string cmd;
is >> cmd;
if (! is)
return false;
if (cmd == "size")
return cmd_size(is);
if (!size_done)
return false;
if (cmd == "colour")
return cmd_colour(is);
else if (cmd == "point")
return cmd_point(is);
else if (cmd == "line")
return cmd_line(is);
else if (cmd == "box")
return cmd_box(is);
else if (cmd == "circle")
return cmd_circle(is);
else if (cmd == "fill")
return cmd_fill(is);
return false;
}
sorry for the long post,,,i dont have anyone to help me out and i cant figure out what it is that i am doing wrong,,,,all the header files seem right to me,,,dont they?
canvas and main compile ok!
any ideas guys???? i am stuck