diff --git a/src/line.cpp b/src/line.cpp index 1087dd135ff75..36529a0e942e9 100644 --- a/src/line.cpp +++ b/src/line.cpp @@ -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; @@ -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; } diff --git a/src/line.h b/src/line.h index 88a12bc9bf7fb..5b7a2158509f5 100644 --- a/src/line.h +++ b/src/line.h @@ -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 ); } @@ -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 ) diff --git a/src/magic_spell_effect.cpp b/src/magic_spell_effect.cpp index acf08815f6cac..1be6d84a4a423 100644 --- a/src/magic_spell_effect.cpp +++ b/src/magic_spell_effect.cpp @@ -233,7 +233,7 @@ std::set 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 diff --git a/src/point.h b/src/point.h index a724265687fc3..5bfaba1a153e2 100644 --- a/src/point.h +++ b/src/point.h @@ -72,6 +72,12 @@ struct point { return point( x / rhs, y / rhs ); } +#ifndef CATA_NO_STL + inline point abs() const { + return point( std::abs( x ), std::abs( y ) ); + } +#endif + /** * Rotate point clockwise @param turns times, 90 degrees per turn, * around the center of a rectangle with the dimensions specified @@ -178,6 +184,12 @@ struct tripoint { return *this; } +#ifndef CATA_NO_STL + inline tripoint abs() const { + return tripoint( std::abs( x ), std::abs( y ), std::abs( z ) ); + } +#endif + constexpr point xy() const { return point( x, y ); } @@ -311,16 +323,6 @@ std::vector closest_tripoints_first( const tripoint ¢er, int min_d std::vector closest_points_first( const point ¢er, int max_dist ); std::vector closest_points_first( const point ¢er, 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 }; diff --git a/src/tileray.cpp b/src/tileray.cpp index 3d595eadb7096..b5724b2656188 100644 --- a/src/tileray.cpp +++ b/src/tileray.cpp @@ -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 { @@ -49,7 +49,7 @@ void tileray::init( int adir ) float direction_radians = static_cast( 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; }