Skip to content

Commit

Permalink
review changes: method names, includes
Browse files Browse the repository at this point in the history
  • Loading branch information
turleypol committed Sep 3, 2021
1 parent 4ebead2 commit 79e38ab
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 47 deletions.
28 changes: 14 additions & 14 deletions pol-core/pol/base/position.cpp
@@ -1,6 +1,6 @@
#include "position.h"

#include "../realms/realm.h"
#include "realms/realm.h"

#include <algorithm>
#include <array>
Expand Down Expand Up @@ -105,7 +105,7 @@ u16 Pos2d::pol_distance( const Pos2d& other ) const
int yd = std::abs( static_cast<int>( _y ) - other._y );
return static_cast<u16>( std::max( xd, yd ) );
}
bool Pos2d::inRange( const Pos2d& other, u16 range ) const
bool Pos2d::in_range( const Pos2d& other, u16 range ) const
{
return pol_distance( other ) <= range;
}
Expand Down Expand Up @@ -317,13 +317,13 @@ u16 Pos3d::pol_distance( const Pos3d& other ) const
{
return _xy.pol_distance( other._xy );
}
bool Pos3d::inRange( const Pos3d& other, u16 range ) const
bool Pos3d::in_range( const Pos3d& other, u16 range ) const
{
return _xy.inRange( other._xy, range );
return _xy.in_range( other._xy, range );
}
bool Pos3d::inRange( const Pos2d& other, u16 range ) const
bool Pos3d::in_range( const Pos2d& other, u16 range ) const
{
return _xy.inRange( other, range );
return _xy.in_range( other, range );
}
Pos3d& Pos3d::crop( const Realms::Realm* realm )
{
Expand Down Expand Up @@ -351,13 +351,13 @@ fmt::Writer& operator<<( fmt::Writer& w, const Pos3d& v )
}


u16 Pos4d::cropX( u16 x ) const
u16 Pos4d::crop_x( u16 x ) const
{
if ( _realm != nullptr && x >= _realm->width() )
return _realm->width() - 1;
return x;
}
u16 Pos4d::cropY( u16 y ) const
u16 Pos4d::crop_y( u16 y ) const
{
if ( _realm != nullptr && y >= _realm->height() )
return _realm->height() - 1;
Expand Down Expand Up @@ -527,17 +527,17 @@ u16 Pos4d::pol_distance( const Pos4d& other ) const
return std::numeric_limits<u16>::max();
return _xyz.pol_distance( other._xyz );
}
bool Pos4d::inRange( const Pos4d& other, u16 range ) const
bool Pos4d::in_range( const Pos4d& other, u16 range ) const
{
return _realm == other._realm && _xyz.inRange( other._xyz, range );
return _realm == other._realm && _xyz.in_range( other._xyz, range );
}
bool Pos4d::inRange( const Pos3d& other, u16 range ) const
bool Pos4d::in_range( const Pos3d& other, u16 range ) const
{
return _xyz.inRange( other, range );
return _xyz.in_range( other, range );
}
bool Pos4d::inRange( const Pos2d& other, u16 range ) const
bool Pos4d::in_range( const Pos2d& other, u16 range ) const
{
return _xyz.inRange( other, range );
return _xyz.in_range( other, range );
}

fmt::Writer& operator<<( fmt::Writer& w, const Pos4d& v )
Expand Down
24 changes: 12 additions & 12 deletions pol-core/pol/base/position.h
@@ -1,8 +1,8 @@
#ifndef POL_BASE_POSITION_H
#define POL_BASE_POSITION_H

#include "../../clib/rawtypes.h"
#include "../../plib/uconst.h"
#include "clib/rawtypes.h"
#include "plib/uconst.h"
#include "vector.h"
#include <format/format.h>
#include <utility>
Expand Down Expand Up @@ -67,7 +67,7 @@ class Pos2d
bool can_move_to( const Vec2d& displacement, const Realms::Realm* realm ) const;

u16 pol_distance( const Pos2d& other ) const;
bool inRange( const Pos2d& other, u16 range ) const;
bool in_range( const Pos2d& other, u16 range ) const;
Pos2d& crop( const Realms::Realm* realm );

UFACING direction_toward( const Pos2d& other ) const;
Expand Down Expand Up @@ -129,8 +129,8 @@ class Pos3d
bool can_move_to( const Vec2d& displacement, const Realms::Realm* realm ) const;

u16 pol_distance( const Pos3d& other ) const;
bool inRange( const Pos2d& other, u16 range ) const;
bool inRange( const Pos3d& other, u16 range ) const;
bool in_range( const Pos2d& other, u16 range ) const;
bool in_range( const Pos3d& other, u16 range ) const;
Pos3d& crop( const Realms::Realm* realm );

void update_min( const Pos3d& v );
Expand Down Expand Up @@ -204,15 +204,15 @@ class Pos4d
Pos4d move( UFACING dir ) const;
bool can_move_to( const Vec2d& displacement ) const;

bool inRange( const Pos4d& other, u16 range ) const;
bool inRange( const Pos3d& other, u16 range ) const;
bool inRange( const Pos2d& other, u16 range ) const;
bool in_range( const Pos4d& other, u16 range ) const;
bool in_range( const Pos3d& other, u16 range ) const;
bool in_range( const Pos2d& other, u16 range ) const;

u16 pol_distance( const Pos4d& other ) const;

private:
u16 cropX( u16 x ) const;
u16 cropY( u16 y ) const;
u16 crop_x( u16 x ) const;
u16 crop_y( u16 y ) const;
};
Pos4d operator-( Pos4d lhs, const Vec2d& rhs );
Pos4d operator+( Pos4d lhs, const Vec2d& rhs );
Expand Down Expand Up @@ -337,12 +337,12 @@ inline const Pos2d& Pos4d::xy() const

inline Pos4d& Pos4d::x( u16 x )
{
_xyz.x( cropX( x ) );
_xyz.x( crop_x( x ) );
return *this;
}
inline Pos4d& Pos4d::y( u16 y )
{
_xyz.y( cropY( y ) );
_xyz.y( crop_y( y ) );
return *this;
}
inline Pos4d& Pos4d::z( s8 z )
Expand Down
2 changes: 1 addition & 1 deletion pol-core/pol/base/vector.h
@@ -1,7 +1,7 @@
#ifndef POL_BASE_VECTOR_H
#define POL_BASE_VECTOR_H

#include "../../clib/rawtypes.h"
#include "clib/rawtypes.h"
#include <format/format.h>
#include <utility>

Expand Down
35 changes: 18 additions & 17 deletions pol-core/pol/testing/testpos.cpp
@@ -1,10 +1,11 @@

#include "../../clib/logfacility.h"
#include "../../clib/rawtypes.h"
#include "../base/position.h"
#include "../base/vector.h"
#include "../globals/uvars.h"
#include "../realms/realm.h"
#include "clib/logfacility.h"
#include "clib/rawtypes.h"

#include "base/position.h"
#include "base/vector.h"
#include "globals/uvars.h"
#include "realms/realm.h"
#include "testenv.h"

namespace Pol
Expand Down Expand Up @@ -56,7 +57,7 @@ void pos2d_test()

UnitTest( []() { return Pos2d( 2, 1 ).from_origin(); }, Vec2d( 2, 1 ), "2,1.from_origin()" );
UnitTest( []() { return Pos2d( 2, 1 ).pol_distance( Pos2d( 0, 0 ) ); }, 2, "2,1.pol_distance()" );
UnitTest( []() { return Pos2d( 2, 1 ).inRange( Pos2d( 0, 0 ), 2 ); }, true, "2,1.inRange()" );
UnitTest( []() { return Pos2d( 2, 1 ).in_range( Pos2d( 0, 0 ), 2 ); }, true, "2,1.in_range()" );

UnitTest( [&]() { return Pos2d( realm->width() + 10, realm->height() + 10 ).crop( realm ); },
Pos2d( realm->width() - 1, realm->height() - 1 ), "crop(realm)" );
Expand Down Expand Up @@ -153,10 +154,10 @@ void pos3d_test()
"2,1,-1.from_origin()" );
UnitTest( []() { return Pos3d( 2, 1, 1 ).pol_distance( Pos3d( 0, 0, 0 ) ); }, 2,
"2,1,1.pol_distance()" );
UnitTest( []() { return Pos3d( 2, 1, 1 ).inRange( Pos2d( 0, 0 ), 2 ); }, true,
"2,1,1.inRange()" );
UnitTest( []() { return Pos3d( 2, 1, 1 ).inRange( Pos3d( 10, 0, 0 ), 2 ); }, false,
"2,1,1.inRange(10,0,0)" );
UnitTest( []() { return Pos3d( 2, 1, 1 ).in_range( Pos2d( 0, 0 ), 2 ); }, true,
"2,1,1.in_range()" );
UnitTest( []() { return Pos3d( 2, 1, 1 ).in_range( Pos3d( 10, 0, 0 ), 2 ); }, false,
"2,1,1.in_range(10,0,0)" );

UnitTest( [&]() { return Pos3d( realm->width() + 10, realm->height() + 10, 0 ).crop( realm ); },
Pos3d( realm->width() - 1, realm->height() - 1, 0 ), "crop(realm)" );
Expand Down Expand Up @@ -268,12 +269,12 @@ void pos4d_test()
UnitTest( [&]() { return Pos4d( 2, 1, 1, r ) >= Pos2d( 1, 1 ); }, true, "2,1,1>=1,1" );
UnitTest( [&]() { return Pos4d( 2, 1, 1, r ) <= Pos2d( 3, 1 ); }, true, "2,1,1>=3,1" );

UnitTest( [&]() { return Pos4d( 2, 1, 1, r ).inRange( Pos2d( 0, 0 ), 2 ); }, true,
"2,1,1.inRange()" );
UnitTest( [&]() { return Pos4d( 2, 1, 1, r ).inRange( Pos3d( 10, 0, 0 ), 2 ); }, false,
"2,1,1.inRange(10,0,0)" );
UnitTest( [&]() { return Pos4d( 2, 1, 1, r ).inRange( Pos4d( 0, 0, 0, nullptr ), 2 ); }, false,
"2,1,1.inRange(nullptr)" );
UnitTest( [&]() { return Pos4d( 2, 1, 1, r ).in_range( Pos2d( 0, 0 ), 2 ); }, true,
"2,1,1.in_range()" );
UnitTest( [&]() { return Pos4d( 2, 1, 1, r ).in_range( Pos3d( 10, 0, 0 ), 2 ); }, false,
"2,1,1.in_range(10,0,0)" );
UnitTest( [&]() { return Pos4d( 2, 1, 1, r ).in_range( Pos4d( 0, 0, 0, nullptr ), 2 ); }, false,
"2,1,1.in_range(nullptr)" );

UnitTest( [&]() { return Pos4d( 2, 1, 0, r ).can_move_to( Vec2d( -2, -2 ) ); }, false,
"2,1,0.can_move_to(-2,-2)" );
Expand Down
6 changes: 3 additions & 3 deletions pol-core/pol/testing/testvector.cpp
@@ -1,7 +1,7 @@

#include "../../clib/logfacility.h"
#include "../../clib/rawtypes.h"
#include "../base/vector.h"
#include "base/vector.h"
#include "clib/logfacility.h"
#include "clib/rawtypes.h"
#include "testenv.h"

namespace Pol
Expand Down

0 comments on commit 79e38ab

Please sign in to comment.