8 #ifndef DXLE_INC_BASIC_TYPES_POINT2D_HPP_ 9 #define DXLE_INC_BASIC_TYPES_POINT2D_HPP_ 27 #include <type_traits> 35 template<typename T, enable_if_t<std::is_nothrow_move_constructible<T>::value && std::is_nothrow_move_assignable<T>::value, nullptr_t>>
104 template<typename T, enable_if_t<std::is_nothrow_move_constructible<T>::value && std::is_nothrow_move_assignable<T>::value,
nullptr_t> =
nullptr>
125 : x(
std::move(o.x)), y(
std::move(o.y)) {}
130 : x(static_cast<value_type>(other.width)), y(static_cast<value_type>(other.height)) {}
134 : x(static_cast<value_type>(
std::move(other.width))), y(static_cast<value_type>(
std::move(other.height))) {}
138 : x(other.width), y(other.height) {}
142 : x(
std::move(other.width)), y(
std::move(other.height)) {}
154 this->x = std::move(r.x);
155 this->y = std::move(r.y);
169 return std::pair<Tp2_, Tp2_>(
static_cast<Tp2_
>(this->
x), static_cast<Tp2_>(this->y));
198 return point_c<T>(std::move(pa.first), std::move(pa.second));
203 template<
typename CharType,
typename Po
intType>
207 os << static_cast<use_big_type_when_one_byte_p>(p.
x) << str << static_cast<use_big_type_when_one_byte_p>(p.
y);
209 template<
typename CharType,
typename Po
intType>
214 is.ignore((std::numeric_limits<std::streamsize>::max)(), dxle::char_constant::comma<CharType>());
216 p.
x =
static_cast<PointType
>(
x); p.
y =
static_cast<PointType
>(
y);
230 template<
typename T> std::ostream& operator<<(std::ostream& os, const point_c<T>& p)
232 dxle::detail::ostream_operator_helper<char, T>(os,
", ", p);
246 template<
typename T> std::wostream& operator<<(std::wostream& os, const point_c<T>& p)
248 dxle::detail::ostream_operator_helper<wchar_t, T>(os, L
", ", p);
264 dxle::detail::istream_operator_helper<char, T>(is, p);
280 dxle::detail::istream_operator_helper<wchar_t, T>(is, p);
293 template <
typename T>
296 return { -r.x, -r.y };
308 template <
typename T>
320 template <
typename T>
334 template <typename T1, typename T2, enable_if_t<is_representable<T2, T1>::value, nullptr_t> =
nullptr>
353 template <typename T1, typename T2, enable_if_t<is_representable<T2, T1>::value, nullptr_t> =
nullptr>
372 template <
typename T1,
typename T2>
374 ->point_c<decltype(std::declval<std::remove_cv_t<T1>>() + std::declval<std::remove_cv_t<T2>>())>
376 return {l.
x + r.
x, l.
y + r.
y};
390 template <
typename T1,
typename T2>
392 ->point_c<decltype(std::declval<std::remove_cv_t<T1>>() - std::declval<std::remove_cv_t<T2>>())>
394 return {l.
x - r.
x, l.
y - r.
y};
408 template <
typename T1,
typename T2>
410 ->point_c<decltype(std::declval<std::remove_cv_t<T1>>() * std::declval<std::remove_cv_t<T2>>())>
412 return {l.
x * r, l.
y * r};
426 template <
typename T1,
typename T2>
428 ->point_c<decltype(std::declval<std::remove_cv_t<T1>>() * std::declval<std::remove_cv_t<T2>>())>
430 return {l * r.
x, l * r.
y};
444 template <typename T1, typename T2, enable_if_t<is_representable<T2, T1>::value, nullptr_t> =
nullptr>
463 template <
typename T1,
typename T2>
465 ->point_c<decltype(std::declval<std::remove_cv_t<T1>>() / std::declval<std::remove_cv_t<T2>>())>
467 return {l.
x / r, l.
y / r};
481 template <typename T1, typename T2, enable_if_t<is_representable<T2, T1>::value, nullptr_t> =
nullptr>
500 template <
typename T>
503 return (l.
x != r.
x) || (l.
y != r.
y);
517 template <
typename T>
533 template <
typename T>
536 return static_cast<bool>(p);
551 template <
typename T>
554 return static_cast<bool>(p);
569 template <
typename T>
572 return !
static_cast<bool>(p);
587 template <
typename T>
590 return !
static_cast<bool>(p);
621 template<
typename T1,
typename T2>
623 ->decltype(std::declval<std::remove_cv_t<T1>>() * std::declval<std::remove_cv_t<T2>>())
625 return p1.x * p2.x + p1.y * p2.y;
639 template<
typename T1,
typename T2>
642 static_cast_if<T1,
double, !std::is_floating_point<T1>::value>(std::declval<T1>()) * std::declval<T2>()
643 +
static_cast_if<T1,
double, !std::is_floating_point<T1>::value>(std::declval<T1>()) * std::declval<T2>()
646 return static_cast_if<T1, double, !std::is_floating_point<T1>::value>(p1.
x) * p2.
y +
static_cast_if<T1,
double, !std::is_floating_point<T1>::value>(p1.
y) * p2.
x;
659 template<
typename T1,
typename T2>
675 #define DXLE_TEMP_make_hash(int_t, bit, bit2)\ 676 template <> struct hash<dxle::point_c<int_t##bit##_t>> {\ 678 hash(const hash&) = default;\ 679 hash(hash&& other) :hash_run(std::move(other.hash_run)) {}\ 681 hash& operator=(const hash& other) { hash_run = other.hash_run; return *this; }\ 682 hash& operator=(hash&& other) { hash_run = std::move(other.hash_run); return *this; }\ 683 size_t operator()(const dxle::point_c<int_t##bit##_t>& key) const { return hash_run((static_cast<int_t##_fast##bit2##_t>(key.x) << bit) | static_cast<int_t##_fast##bit2##_t>(key.y)); }\ 685 std::hash<int_t##_fast##bit2##_t> hash_run;\ 695 #undef DXLE_TEMP_make_hash 698 #endif //DXLE_INC_BASIC_TYPES_POINT2D_HPP_ DXLE_CONSTEXPR point_c() DXLE_NOEXCEPT_IF((std
DXLE_CONSTEXPR point_c(size_c< value_type, nullptr > &&other) DXLE_NOEXCEPT_IF((dxle
Template class for 2D sizes specified by its coordinates width and height.
DXLE_CONSTEXPR auto operator*(const point_c< T1 > &l, T2 r) DXLE_NOEXCEPT_IF_EXPR(l.x *r) -> point_c< decltype(std::declval< std::remove_cv_t< T1 >>() *std::declval< std::remove_cv_t< T2 >>())>
Overload of binary operator *.
DXLE_CONSTEXPR point_c(const point_c< Tp2_ > &other) DXLE_NOEXCEPT_IF((dxle
point_c< T1 > T2 DXLE_CONSTEXPR auto dot(const point_c< T1 > &p1, const point_c< T2 > &p2) DXLE_NOEXCEPT_IF_EXPR(p1.x *p2.x+p1.y *p2.y) -> decltype(std::declval< std::remove_cv_t< T1 >>() *std::declval< std::remove_cv_t< T2 >>())
point_c< T1 > & operator/=(point_c< T1 > &l, T2 r) DXLE_NOEXCEPT_IF_EXPR(l.x/
Overload of binary operator /=.
DXLE_CONSTEXPR point_c(const value_type &x_, const value_type &y_) DXLE_NOEXCEPT_IF((std
point_c< T > make_point_c(std::pair< T, T > &&pa) DXLE_NOEXCEPT_OR_NOTHROW
conversion from std::pair
std::wistream & operator>>(std::wistream &is, point_c< T > &p)
istream operator
DXLE_CONSTEXPR int abs(int j) DXLE_NOEXCEPT_OR_NOTHROW
DXLE_CONSTEXPR point_c(point_c< Tp2_ > &&other) DXLE_NOEXCEPT_IF((dxle
DXLE_CONSTEXPR bool operator_bool_helper(const T &first, const T &second) DXLE_NOEXCEPT_IF_EXPR(dxle
point_c< T1 > T2 DXLE_CONSTEXPR auto operator/(const point_c< T1 > &l, T2 r) DXLE_NOEXCEPT_IF_EXPR(l.x/r) -> point_c< decltype(std::declval< std::remove_cv_t< T1 >>()/std::declval< std::remove_cv_t< T2 >>())>
DXLE_CONSTEXPR point_c(value_type &&x_, value_type &&y_) DXLE_NOEXCEPT_OR_NOTHROW
distance_result_type_t< T1, T2 > distance(const point_c< T1 > &p1, const point_c< T2 > &p2) DXLE_NOEXCEPT_IF_EXPR(hypot(safe_dist(std
Calculate the distance of the two point_c class object based on the Pythagorean theorem(std::hypot) ...
typename use_big_type_when_one_byte< T >::type use_big_type_when_one_byte_t
for int8_t/uint8_t
point_c & operator=(point_c< value_type > &&r) DXLE_NOEXCEPT_OR_NOTHROW
void ostream_operator_helper(std::basic_ostream< CharType > &os, const CharType *str, const point_c< PointType > &p)
point_c< std::int8_t > point8i
DXLE_CONSTEXPR point_c(size_c< Tp2_, nullptr > &&other) DXLE_NOEXCEPT_IF((dxle
std::remove_cv< T >::type value_type
point_c & operator=(const point_c< value_type > &r) DXLE_NOEXCEPT_IF((std
#define DXLE_TEMP_make_hash(int_t, bit, bit2)
DXLE_CONSTEXPR point_c< T > operator+(const point_c< T > &r) DXLE_NOEXCEPT_IF(std
Overload of unary operator +.
point_c< T > make_point_c(const std::pair< T, T > &pa) DXLE_NOEXCEPT_IF(std
conversion from std::pair
DXLE_CONSTEXPR point_c(const size_c< value_type, nullptr > &other) DXLE_NOEXCEPT_IF((dxle
#define DXLE_NOEXCEPT_IF_EXPR(EXPR)
DXLE_CONSTEXPR auto safe_dist(const T1 &n1, const T2 &n2) DXLE_NOEXCEPT_IF_EXPR((n1 - n2)) -> decltype(n1 - n2)
point_c< T1 > & operator*=(point_c< T1 > &l, T2 r) DXLE_NOEXCEPT_IF_EXPR(l.x *
Overload of binary operator *=.
DXLE_CONSTEXPR point_c< T > operator-(const point_c< T > &r) DXLE_NOEXCEPT_IF_EXPR(-r.x)
Overload of unary operator -.
DXLE_CONSTEXPR point_c(const point_c< value_type > &o) DXLE_NOEXCEPT_IF((std
#define DXLE_NOEXCEPT_IF(COND)
point_c< T1 > & operator+=(point_c< T1 > &l, const point_c< T2 > &r) DXLE_NOEXCEPT_IF_EXPR(l.x+
Overload of binary operator +=.
#define DXLE_NOEXCEPT_OR_NOTHROW
DXLE_CONSTEXPR double cross(const point_c< T1 > &p1, const point_c< T2 > &p2) DXLE_NOEXCEPT_IF_EXPR((static_cast_if< T1
Computes a cross-product of two point_c value as vectors.
typename distance_result_type< T1, T2 >::type distance_result_type_t
Template class for 2D points specified by its coordinates x and y.
std::istream & operator>>(std::istream &is, point_c< T > &p)
istream operator
DXLE_CONSTEXPR to static_cast_if(const from &n) DXLE_NOEXCEPT_IF_EXPR((dxle
DXLE_CONSTEXPR point_c(const size_c< Tp2_, nullptr > &other) DXLE_NOEXCEPT_IF((dxle
void istream_operator_helper(std::basic_istream< CharType > &is, point_c< PointType > &p)
point_c< std::uint8_t > pointu8i
DXLE_CONSTEXPR point_c(point_c< value_type > &&o) DXLE_NOEXCEPT_OR_NOTHROW