From f96cc66b9d593f92186789795f3548eaf1d2cdb8 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Wed, 4 Mar 2020 14:14:38 -0500 Subject: [PATCH] google code style --- src/zm_box.h | 32 ++++++++++++++------------------ src/zm_coord.h | 6 ++---- src/zm_poly.cpp | 46 +++++++++++++++++++--------------------------- src/zm_poly.h | 34 +++++++++++++++++----------------- 4 files changed, 52 insertions(+), 66 deletions(-) diff --git a/src/zm_box.h b/src/zm_box.h index fa377e593..efc12cb18 100644 --- a/src/zm_box.h +++ b/src/zm_box.h @@ -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 { diff --git a/src/zm_coord.h b/src/zm_coord.h index 9bf31144c..c6234fb1c 100644 --- a/src/zm_coord.h +++ b/src/zm_coord.h @@ -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 ); } diff --git a/src/zm_poly.cpp b/src/zm_poly.cpp index 13a21e7e0..35319d6af 100644 --- a/src/zm_poly.cpp +++ b/src/zm_poly.cpp @@ -26,11 +26,9 @@ #include #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; } diff --git a/src/zm_poly.h b/src/zm_poly.h index 0fcf34a6e..be039ef3e 100644 --- a/src/zm_poly.h +++ b/src/zm_poly.h @@ -41,13 +41,13 @@ protected: static int CompareYX( const void *p1, const void *p2 ) { const Edge *e1 = reinterpret_cast(p1), *e2 = reinterpret_cast(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(p1), *e2 = reinterpret_cast(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; };