-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added area classes first Area2d tests * removed unneeded method * area3d tests * build fix * remaining tests * fixed typo * zip coverage report before uploading * renamed area to range. use std::minmax
- Loading branch information
Showing
13 changed files
with
528 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
#include "range.h" | ||
#include "realms/realm.h" | ||
|
||
#include <algorithm> | ||
#include <tuple> | ||
|
||
namespace Pol | ||
{ | ||
namespace Core | ||
{ | ||
Range2dItr::Range2dItr( Pos2d v, const Pos2d& v_max ) | ||
: _v( std::move( v ) ), _xbound( v_max.x() ), _xstart( _v.x() ){}; | ||
|
||
bool Range2dItr::operator==( const Range2dItr& other ) const | ||
{ | ||
return _v == other._v; | ||
} | ||
bool Range2dItr::operator!=( const Range2dItr& other ) const | ||
{ | ||
return !( *this == other ); | ||
} | ||
Range2dItr& Range2dItr::operator++() | ||
{ | ||
if ( _v.x() < _xbound ) | ||
_v += Vec2d( 1, 0 ); | ||
else | ||
{ | ||
_v.x( _xstart ); | ||
_v += Vec2d( 0, 1 ); | ||
} | ||
return *this; | ||
} | ||
|
||
Range2d::Range2d( const Pos2d& p1, const Pos2d& p2, const Realms::Realm* realm ) | ||
{ | ||
_nw = p1.min( p2 ); | ||
_se = p1.max( p2 ); | ||
if ( realm != nullptr ) | ||
{ | ||
_nw.crop( realm ); | ||
_se.crop( realm ); | ||
} | ||
} | ||
Range2d::Range2d( const Pos4d& p1, const Pos4d& p2 ) | ||
{ | ||
_nw = p1.xy().min( p2.xy() ); | ||
_se = p1.xy().max( p2.xy() ); | ||
} | ||
|
||
Range2dItr Range2d::begin() const | ||
{ | ||
return Range2dItr( _nw, _se ); | ||
} | ||
Range2dItr Range2d::end() const | ||
{ | ||
return Range2dItr( Pos2d( _nw.x(), _se.y() ) + Vec2d( 0, 1 ), _se ); | ||
} | ||
|
||
bool Range2d::contains( const Pos2d& other ) const | ||
{ | ||
return _nw <= other && _se >= other; | ||
} | ||
|
||
bool Range2d::intersect( const Range2d& other ) const | ||
{ | ||
return _nw.x() <= other._se.x() && other._nw.x() <= _se.x() && _nw.y() <= other._se.y() && | ||
other._nw.y() <= _se.y(); | ||
} | ||
|
||
bool Range2d::operator==( const Range2d& other ) const | ||
{ | ||
return _nw == other._nw && _se == other._se; | ||
} | ||
bool Range2d::operator!=( const Range2d& other ) const | ||
{ | ||
return !( *this == other ); | ||
} | ||
|
||
fmt::Writer& operator<<( fmt::Writer& w, const Range2d& v ) | ||
{ | ||
w << "( " << v.nw() << " - " << v.se() << " )"; | ||
return w; | ||
} | ||
|
||
Range3d::Range3d( const Pos3d& p1, const Pos3d& p2, const Realms::Realm* realm ) | ||
: _range( p1.xy(), p2.xy(), realm ) | ||
{ | ||
std::tie( _z_bottom, _z_top ) = std::minmax( p1.z(), p2.z() ); | ||
} | ||
Range3d::Range3d( const Pos4d& p1, const Pos4d& p2 ) : _range( p1, p2 ) | ||
{ | ||
std::tie( _z_bottom, _z_top ) = std::minmax( p1.z(), p2.z() ); | ||
} | ||
|
||
bool Range3d::contains( const Pos2d& other ) const | ||
{ | ||
return _range.contains( other ); | ||
} | ||
bool Range3d::contains( const Pos3d& other ) const | ||
{ | ||
return contains( other.xy() ) && _z_bottom <= other.z() && _z_top >= other.z(); | ||
} | ||
|
||
bool Range3d::intersect( const Range2d& other ) const | ||
{ | ||
return _range.intersect( other ); | ||
} | ||
bool Range3d::intersect( const Range3d& other ) const | ||
{ | ||
return intersect( other._range ) && _z_bottom <= other._z_top && other._z_bottom <= _z_top; | ||
} | ||
|
||
bool Range3d::operator==( const Range3d& other ) const | ||
{ | ||
return _range == other._range && _z_bottom == other._z_bottom && _z_top == other._z_top; | ||
} | ||
bool Range3d::operator!=( const Range3d& other ) const | ||
{ | ||
return !( *this == other ); | ||
} | ||
|
||
fmt::Writer& operator<<( fmt::Writer& w, const Range3d& v ) | ||
{ | ||
w << "( " << v.nw_b() << " - " << v.se_t() << " )"; | ||
return w; | ||
} | ||
} // namespace Core | ||
} // namespace Pol |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
#ifndef POL_BASE_RANGE_H | ||
#define POL_BASE_RANGE_H | ||
|
||
#include "position.h" | ||
#include <format/format.h> | ||
#include <iterator> | ||
|
||
namespace Pol | ||
{ | ||
namespace Core | ||
{ | ||
class Range2dItr | ||
{ | ||
private: | ||
Pos2d _v; | ||
u16 _xbound; | ||
u16 _xstart; | ||
|
||
public: | ||
Range2dItr( Pos2d v, const Pos2d& v_max ); | ||
|
||
typedef Pos2d value_type; | ||
typedef std::ptrdiff_t difference_type; | ||
typedef const Pos2d* pointer; | ||
typedef const Pos2d& reference; | ||
typedef std::input_iterator_tag iterator_category; | ||
|
||
reference operator*() const; | ||
bool operator==( const Range2dItr& other ) const; | ||
bool operator!=( const Range2dItr& other ) const; | ||
// does someone really need itr++? | ||
Range2dItr& operator++(); | ||
}; | ||
|
||
class Range2d | ||
{ | ||
private: | ||
Pos2d _nw; | ||
Pos2d _se; | ||
|
||
public: | ||
Range2d() = default; | ||
Range2d( const Pos2d& p1, const Pos2d& p2, const Realms::Realm* realm ); | ||
Range2d( const Pos4d& p1, const Pos4d& p2 ); | ||
Range2d( const Range2d& other ) = default; | ||
Range2d( Range2d&& other ) = default; | ||
~Range2d() = default; | ||
Range2d& operator=( const Range2d& other ) = default; | ||
Range2d& operator=( Range2d&& other ) = default; | ||
|
||
const Pos2d& nw() const; | ||
const Pos2d& se() const; | ||
// not implemented on purpose, forced min/max could give weird results | ||
// Range2d& nw( const Pos2d& p ); | ||
// Range2d& se( const Pos2d& p ); | ||
|
||
Range2dItr begin() const; | ||
Range2dItr end() const; | ||
|
||
bool contains( const Pos2d& other ) const; | ||
bool intersect( const Range2d& other ) const; | ||
|
||
bool operator==( const Range2d& other ) const; | ||
bool operator!=( const Range2d& other ) const; | ||
}; | ||
fmt::Writer& operator<<( fmt::Writer& w, const Range2d& v ); | ||
|
||
class Range3d | ||
{ | ||
private: | ||
Range2d _range; | ||
s8 _z_bottom; | ||
s8 _z_top; | ||
|
||
public: | ||
Range3d() = default; | ||
Range3d( const Pos3d& p1, const Pos3d& p2, const Realms::Realm* realm ); | ||
Range3d( const Pos4d& p1, const Pos4d& p2 ); | ||
Range3d( const Range3d& other ) = default; | ||
Range3d( Range3d&& other ) = default; | ||
~Range3d() = default; | ||
Range3d& operator=( const Range3d& other ) = default; | ||
Range3d& operator=( Range3d&& other ) = default; | ||
|
||
const Pos2d& nw() const; | ||
const Pos2d& se() const; | ||
Pos3d nw_b() const; | ||
Pos3d se_t() const; | ||
// not implemented on purpose, forced min/max could give weird results | ||
// Range3d& nw_b( const Pos3d& p ); | ||
// Range3d& se_t( const Pos3d& p ); | ||
|
||
const Range2d& range() const; | ||
|
||
bool contains( const Pos2d& other ) const; | ||
bool contains( const Pos3d& other ) const; | ||
bool intersect( const Range2d& other ) const; | ||
bool intersect( const Range3d& other ) const; | ||
|
||
bool operator==( const Range3d& other ) const; | ||
bool operator!=( const Range3d& other ) const; | ||
}; | ||
fmt::Writer& operator<<( fmt::Writer& w, const Range3d& v ); | ||
|
||
inline Range2dItr::reference Range2dItr::operator*() const | ||
{ | ||
return _v; | ||
} | ||
|
||
inline const Pos2d& Range2d::nw() const | ||
{ | ||
return _nw; | ||
} | ||
inline const Pos2d& Range2d::se() const | ||
{ | ||
return _se; | ||
} | ||
|
||
inline const Pos2d& Range3d::nw() const | ||
{ | ||
return _range.nw(); | ||
} | ||
inline const Pos2d& Range3d::se() const | ||
{ | ||
return _range.se(); | ||
} | ||
inline Pos3d Range3d::nw_b() const | ||
{ | ||
return Pos3d( _range.nw(), _z_bottom ); | ||
} | ||
inline Pos3d Range3d::se_t() const | ||
{ | ||
return Pos3d( _range.se(), _z_top ); | ||
} | ||
inline const Range2d& Range3d::range() const | ||
{ | ||
return _range; | ||
} | ||
} // namespace Core | ||
} // namespace Pol | ||
|
||
#endif |
Oops, something went wrong.