Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make point and tripoint abs functions into methods. #40106

Merged
merged 4 commits into from
May 4, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void bresenham( const point &p1, const point &p2, int t,
const int sx = ( d.x == 0 ) ? 0 : sgn( d.x );
const int sy = ( d.y == 0 ) ? 0 : sgn( d.y );
// Absolute values of slopes x2 to avoid rounding errors.
const point a = abs( d ) * 2;
const point a = d.abs() * 2;

point cur = p1;

Expand Down Expand Up @@ -266,7 +266,7 @@ float rl_dist_exact( const tripoint &loc1, const tripoint &loc2 )

int manhattan_dist( const point &loc1, const point &loc2 )
{
const point d = abs( loc1 - loc2 );
const point d = ( loc1 - loc2 ).abs();
return d.x + d.y;
}

Expand Down
6 changes: 3 additions & 3 deletions src/line.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,12 @@ inline float trig_dist( const point &loc1, const point &loc2 )
// Roguelike distance; maximum of dX and dY
inline int square_dist( const tripoint &loc1, const tripoint &loc2 )
{
const tripoint d = abs( loc1 - loc2 );
const tripoint d = ( loc1 - loc2 ).abs();
return std::max( { d.x, d.y, d.z } );
}
inline int square_dist( const point &loc1, const point &loc2 )
{
const point d = abs( loc1 - loc2 );
const point d = ( loc1 - loc2 ).abs();
return std::max( d.x, d.y );
}

Expand Down Expand Up @@ -225,7 +225,7 @@ inline FastDistanceApproximation trig_dist_fast( const tripoint &loc1, const tri
}
inline FastDistanceApproximation square_dist_fast( const tripoint &loc1, const tripoint &loc2 )
{
const tripoint d = abs( loc1 - loc2 );
const tripoint d = ( loc1 - loc2 ).abs();
return std::max( { d.x, d.y, d.z } );
}
inline FastDistanceApproximation rl_dist_fast( const tripoint &loc1, const tripoint &loc2 )
Expand Down
2 changes: 1 addition & 1 deletion src/magic_spell_effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ std::set<tripoint> spell_effect::spell_effect_line( const spell &, const tripoin
// Clockwise Perpendicular of Delta vector
const point delta_perp( -delta.y, delta.x );

const point abs_delta = abs( delta );
const point abs_delta = delta.abs();
// Primary axis of delta vector
const point axis_delta = abs_delta.x > abs_delta.y ? point( delta.x, 0 ) : point( 0, delta.y );
// Clockwise Perpendicular of axis vector
Expand Down
22 changes: 12 additions & 10 deletions src/point.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ struct point {
return point( x / rhs, y / rhs );
}

#ifndef CATA_NO_STL
constexpr point abs() const {
kevingranade marked this conversation as resolved.
Show resolved Hide resolved
return point( std::abs( x ), std::abs( y ) );
}
kevingranade marked this conversation as resolved.
Show resolved Hide resolved
#endif

/**
* Rotate point clockwise @param turns times, 90 degrees per turn,
* around the center of a rectangle with the dimensions specified
Expand Down Expand Up @@ -178,6 +184,12 @@ struct tripoint {
return *this;
}

#ifndef CATA_NO_STL
constexpr tripoint abs() const {
kevingranade marked this conversation as resolved.
Show resolved Hide resolved
return tripoint( std::abs( x ), std::abs( y ), std::abs( z ) );
}
kevingranade marked this conversation as resolved.
Show resolved Hide resolved
#endif

constexpr point xy() const {
return point( x, y );
}
Expand Down Expand Up @@ -311,16 +323,6 @@ std::vector<tripoint> closest_tripoints_first( const tripoint &center, int min_d
std::vector<point> closest_points_first( const point &center, int max_dist );
std::vector<point> closest_points_first( const point &center, int min_dist, int max_dist );

inline point abs( const point &p )
{
return point( std::abs( p.x ), std::abs( p.y ) );
}

inline tripoint abs( const tripoint &p )
{
return tripoint( std::abs( p.x ), std::abs( p.y ), std::abs( p.z ) );
}

static constexpr tripoint tripoint_min { INT_MIN, INT_MIN, INT_MIN };
static constexpr tripoint tripoint_max{ INT_MAX, INT_MAX, INT_MAX };

Expand Down
4 changes: 2 additions & 2 deletions src/tileray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ tileray::tileray( int adir ): direction( adir )
void tileray::init( const point &ad )
{
delta = ad;
abs_d = abs( delta );
abs_d = delta.abs();
if( delta == point_zero ) {
direction = 0;
} else {
Expand All @@ -49,7 +49,7 @@ void tileray::init( int adir )
float direction_radians = static_cast<float>( direction ) * M_PI / 180.0;
rl_vec2d delta_f( std::cos( direction_radians ), std::sin( direction_radians ) );
delta = ( delta_f * 100 ).as_point();
abs_d = abs( delta );
abs_d = delta.abs();
steps = 0;
infinite = true;
}
Expand Down