project-kyoku/include/core/area.h

49 lines
899 B
C
Raw Permalink Normal View History

2021-12-29 15:59:18 +01:00
#pragma once
#include <type_traits>
#include "core/point.h"
#include "core/vector.h"
namespace kku
{
2022-05-08 05:43:12 +02:00
/// Area
///
/// Consists of 2 arithmetic
/// points that represent
/// a rectangle position
/// and 2 arithmetic
/// lengths by x and y
/// that represent
/// rectangle coverage area
2021-12-29 15:59:18 +01:00
template <typename T, typename = std::enable_if_t<std::is_arithmetic_v<T>>>
struct Area
{
T left = 0;
T top = 0;
T width = 0;
T height = 0;
inline kku::Point position() const noexcept
{
return kku::Point{
static_cast<float>(left),
static_cast<float>(top),
};
2021-12-29 15:59:18 +01:00
}
inline void moveBy(const kku::Vector2<T> &vector)
2021-12-29 15:59:18 +01:00
{
top += vector.second;
left += vector.first;
}
inline bool contains(const kku::Point &point) const
2021-12-29 15:59:18 +01:00
{
return point.x >= left; // debug it when on computer
2021-12-29 15:59:18 +01:00
}
};
} // namespace kku