google code style

This commit is contained in:
Isaac Connor 2020-03-04 14:14:38 -05:00
parent 683bf3f982
commit f96cc66b9d
4 changed files with 52 additions and 66 deletions

View File

@ -33,37 +33,33 @@
// Class used for storing a box, which is defined as a region
// defined by two coordinates
//
class Box
{
class Box {
private:
Coord lo, hi;
Coord size;
public:
inline Box()
{
}
inline Box() { }
explicit inline Box( int p_size ) : lo( 0, 0 ), hi ( p_size-1, p_size-1 ), size( Coord::Range( hi, lo ) ) { }
inline Box( int p_x_size, int p_y_size ) : lo( 0, 0 ), hi ( p_x_size-1, p_y_size-1 ), size( Coord::Range( hi, lo ) ) { }
inline Box( int lo_x, int lo_y, int hi_x, int hi_y ) : lo( lo_x, lo_y ), hi( hi_x, hi_y ), size( Coord::Range( hi, lo ) ) { }
inline Box( const Coord &p_lo, const Coord &p_hi ) : lo( p_lo ), hi( p_hi ), size( Coord::Range( hi, lo ) ) { }
inline const Coord &Lo() const { return( lo ); }
inline int LoX() const { return( lo.X() ); }
inline int LoY() const { return( lo.Y() ); }
inline const Coord &Hi() const { return( hi ); }
inline int HiX() const { return( hi.X() ); }
inline int HiY() const { return( hi.Y() ); }
inline const Coord &Size() const { return( size ); }
inline int Width() const { return( size.X() ); }
inline int Height() const { return( size.Y() ); }
inline int Area() const { return( size.X()*size.Y() ); }
inline const Coord &Lo() const { return lo; }
inline int LoX() const { return lo.X(); }
inline int LoY() const { return lo.Y(); }
inline const Coord &Hi() const { return hi; }
inline int HiX() const { return hi.X(); }
inline int HiY() const { return hi.Y(); }
inline const Coord &Size() const { return size; }
inline int Width() const { return size.X(); }
inline int Height() const { return size.Y(); }
inline int Area() const { return size.X()*size.Y(); }
inline const Coord Centre() const
{
inline const Coord Centre() const {
int mid_x = int(round(lo.X()+(size.X()/2.0)));
int mid_y = int(round(lo.Y()+(size.Y()/2.0)));
return( Coord( mid_x, mid_y ) );
return Coord( mid_x, mid_y );
}
inline bool Inside( const Coord &coord ) const
{

View File

@ -25,8 +25,7 @@
//
// Class used for storing an x,y pair, i.e. a coordinate
//
class Coord
{
class Coord {
private:
int x, y;
@ -44,8 +43,7 @@ public:
inline int &Y() { return( y ); }
inline const int &Y() const { return( y ); }
inline static Coord Range( const Coord &coord1, const Coord &coord2 )
{
inline static Coord Range( const Coord &coord1, const Coord &coord2 ) {
Coord result( (coord1.x-coord2.x)+1, (coord1.y-coord2.y)+1 );
return( result );
}

View File

@ -26,11 +26,9 @@
#include <cmath>
#endif
void Polygon::calcArea()
{
void Polygon::calcArea() {
double float_area = 0.0L;
for ( int i = 0, j = n_coords-1; i < n_coords; j = i++ )
{
for ( int i = 0, j = n_coords-1; i < n_coords; j = i++ ) {
double trap_area = ((coords[i].X()-coords[j].X())*((coords[i].Y()+coords[j].Y())))/2.0L;
float_area += trap_area;
//printf( "%.2f (%.2f)\n", float_area, trap_area );
@ -38,13 +36,11 @@ void Polygon::calcArea()
area = (int)round(fabs(float_area));
}
void Polygon::calcCentre()
{
void Polygon::calcCentre() {
if ( !area && n_coords )
calcArea();
double float_x = 0.0L, float_y = 0.0L;
for ( int i = 0, j = n_coords-1; i < n_coords; j = i++ )
{
for ( int i = 0, j = n_coords-1; i < n_coords; j = i++ ) {
float_x += ((coords[i].Y()-coords[j].Y())*((coords[i].X()*2)+(coords[i].X()*coords[j].X())+(coords[j].X()*2)));
float_y += ((coords[j].X()-coords[i].X())*((coords[i].Y()*2)+(coords[i].Y()*coords[j].Y())+(coords[j].Y()*2)));
}
@ -54,16 +50,14 @@ void Polygon::calcCentre()
centre = Coord( (int)round(float_x), (int)round(float_y) );
}
Polygon::Polygon( int p_n_coords, const Coord *p_coords ) : n_coords( p_n_coords )
{
Polygon::Polygon(int p_n_coords, const Coord *p_coords) : n_coords( p_n_coords ) {
coords = new Coord[n_coords];
int min_x = -1;
int max_x = -1;
int min_y = -1;
int max_y = -1;
for( int i = 0; i < n_coords; i++ )
{
for ( int i = 0; i < n_coords; i++ ) {
coords[i] = p_coords[i];
if ( min_x == -1 || coords[i].X() < min_x )
min_x = coords[i].X();
@ -79,38 +73,36 @@ Polygon::Polygon( int p_n_coords, const Coord *p_coords ) : n_coords( p_n_coords
calcCentre();
}
Polygon::Polygon( const Polygon &p_polygon ) : n_coords( p_polygon.n_coords ), extent( p_polygon.extent ), area( p_polygon.area ), centre( p_polygon.centre )
Polygon::Polygon( const Polygon &p_polygon ) :
n_coords(p_polygon.n_coords),
extent(p_polygon.extent),
area(p_polygon.area),
centre(p_polygon.centre)
{
coords = new Coord[n_coords];
for( int i = 0; i < n_coords; i++ )
{
for( int i = 0; i < n_coords; i++ ) {
coords[i] = p_polygon.coords[i];
}
}
Polygon &Polygon::operator=( const Polygon &p_polygon )
{
if ( n_coords < p_polygon.n_coords )
{
Polygon &Polygon::operator=( const Polygon &p_polygon ) {
if ( n_coords < p_polygon.n_coords ) {
delete[] coords;
coords = new Coord[p_polygon.n_coords];
}
n_coords = p_polygon.n_coords;
for( int i = 0; i < n_coords; i++ )
{
for ( int i = 0; i < n_coords; i++ ) {
coords[i] = p_polygon.coords[i];
}
extent = p_polygon.extent;
area = p_polygon.area;
centre = p_polygon.centre;
return( *this );
return *this ;
}
bool Polygon::isInside( const Coord &coord ) const
{
bool Polygon::isInside( const Coord &coord ) const {
bool inside = false;
for ( int i = 0, j = n_coords-1; i < n_coords; j = i++ )
{
for ( int i = 0, j = n_coords-1; i < n_coords; j = i++ ) {
if ( (((coords[i].Y() <= coord.Y()) && (coord.Y() < coords[j].Y()) )
|| ((coords[j].Y() <= coord.Y()) && (coord.Y() < coords[i].Y())))
&& (coord.X() < (coords[j].X() - coords[i].X()) * (coord.Y() - coords[i].Y()) / (coords[j].Y() - coords[i].Y()) + coords[i].X()))
@ -118,5 +110,5 @@ bool Polygon::isInside( const Coord &coord ) const
inside = !inside;
}
}
return( inside );
return inside;
}

View File

@ -41,13 +41,13 @@ protected:
static int CompareYX( const void *p1, const void *p2 ) {
const Edge *e1 = reinterpret_cast<const Edge *>(p1), *e2 = reinterpret_cast<const Edge *>(p2);
if ( e1->min_y == e2->min_y )
return( int(e1->min_x - e2->min_x) );
return int(e1->min_x - e2->min_x);
else
return( int(e1->min_y - e2->min_y) );
return int(e1->min_y - e2->min_y);
}
static int CompareX( const void *p1, const void *p2 ) {
const Edge *e1 = reinterpret_cast<const Edge *>(p1), *e2 = reinterpret_cast<const Edge *>(p2);
return( int(e1->min_x - e2->min_x) );
return int(e1->min_x - e2->min_x);
}
};
@ -83,32 +83,32 @@ protected:
void calcCentre();
public:
inline Polygon() : n_coords( 0 ), coords( 0 ), area( 0 ), edges(0), slices(0) {
inline Polygon() : n_coords(0), coords(0), area(0), edges(0), slices(0) {
}
Polygon( int p_n_coords, const Coord *p_coords );
Polygon( const Polygon &p_polygon );
Polygon(int p_n_coords, const Coord *p_coords);
Polygon(const Polygon &p_polygon);
~Polygon() {
delete[] coords;
}
Polygon &operator=( const Polygon &p_polygon );
inline int getNumCoords() const { return( n_coords ); }
inline int getNumCoords() const { return n_coords; }
inline const Coord &getCoord( int index ) const {
return( coords[index] );
return coords[index];
}
inline const Box &Extent() const { return( extent ); }
inline int LoX() const { return( extent.LoX() ); }
inline int HiX() const { return( extent.HiX() ); }
inline int LoY() const { return( extent.LoY() ); }
inline int HiY() const { return( extent.HiY() ); }
inline int Width() const { return( extent.Width() ); }
inline int Height() const { return( extent.Height() ); }
inline const Box &Extent() const { return extent; }
inline int LoX() const { return extent.LoX(); }
inline int HiX() const { return extent.HiX(); }
inline int LoY() const { return extent.LoY(); }
inline int HiY() const { return extent.HiY(); }
inline int Width() const { return extent.Width(); }
inline int Height() const { return extent.Height(); }
inline int Area() const { return( area ); }
inline int Area() const { return area; }
inline const Coord &Centre() const {
return( centre );
return centre;
}
bool isInside( const Coord &coord ) const;
};