home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Computer Panoráma
/
computer_panorama_1997-12-hibas.iso
/
SHARE
/
GRAPH
/
PTC051.ZIP
/
SRC
/
RECT.H
< prev
next >
Wrap
C/C++ Source or Header
|
1997-09-20
|
2KB
|
154 lines
/////////////////////
// rectangle class //
/////////////////////
#ifndef __RECTANGLE_H
#define __RECTANGLE_H
#include "misc.h"
#include "globals.h"
#include <math.h>
#include <stdlib.h>
class RECTANGLE
{
public:
// construct
inline RECTANGLE();
inline RECTANGLE(float x1,float y1,float x2,float y2,int mode=ABSOLUTE);
// fix rectangle
inline void fix();
// cool stuff
inline float width() const;
inline float height() const;
inline float area() const;
// operators
inline int operator ==(RECTANGLE const &other) const;
inline int operator !=(RECTANGLE const &other) const;
// operation mode
char mode;
// data
float x1,y1,x2,y2;
};
inline RECTANGLE::RECTANGLE()
{
// defaults
x1=(float)0;
y1=(float)0;
x2=(float)0;
y2=(float)0;
mode=0;
}
inline RECTANGLE::RECTANGLE(float ix1,float iy1,float ix2,float iy2,int imode)
{
// init
x1=ix1;
y1=iy1;
x2=ix2;
y2=iy2;
mode=(char)imode;
}
inline void RECTANGLE::fix()
{
// fix x coords so that x1 is leftmost
float temp;
if (x1>x2)
{
temp=x1;
x1=x2;
x2=temp;
}
// fix y coords so that y1 is topmost
if (y1>y2)
{
temp=y1;
y1=y2;
y2=temp;
}
}
inline float RECTANGLE::width() const
{
// rect width
return x2-x1;
}
inline float RECTANGLE::height() const
{
// rect height
return y2-y1;
}
inline float RECTANGLE::area() const
{
// rect area
return (float)fabs((x2-x1)*(y2-y1));
}
inline int RECTANGLE::operator ==(RECTANGLE const &other) const
{
if (mode!=other.mode || x1!=other.x1 || y1!=other.y1 || x2!=other.x2 || y2!=other.y2) return 0;
else return 1;
}
inline int RECTANGLE::operator !=(RECTANGLE const &other) const
{
return !(*this==other);
}
#endif