Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef HTCW_GFX_POSITIONING_HPP
- #define HTCW_GFX_POSITIONING_HPP
- #include "gfx_core.hpp"
- #include <htcw_bits.hpp>
- namespace gfx {
- ...
- // represents a size with integer coordinates
- template <typename T>
- struct sizex final {
- using type = sizex;
- using value_type = T;
- // the width
- T width;
- // the height
- T height;
- // constructs a new instance
- inline sizex() {}
- // constructs a new instance with the specified width and height
- constexpr inline sizex(T width, T height) : width(width), height(height) {
- }
- // increases or decreases the width and height by the specified amounts.
- constexpr sizex inflate(typename bits::signedx<T> width,typename bits::signedx<T> height) const {
- return sizex(width+this->width,height+this->height);
- }
- constexpr inline rectx<T> bounds() const;
- constexpr explicit operator sizex<bits::signedx<value_type>>() const {
- return sizex<bits::signedx<value_type>>(bits::signedx<value_type>(width),bits::signedx<value_type>(height));
- }
- constexpr explicit operator sizex<bits::unsignedx<value_type>>() const {
- return sizex<bits::unsignedx<value_type>>(bits::unsignedx<value_type>(width),bits::unsignedx<value_type>(height));
- }
- // won't compile"
- constexpr inline explicit operator sizex<float>() const {
- return sizex<float>(float(width),float(height));
- }
- constexpr inline bool operator==(const sizex& rhs) const {
- return width==rhs.width && height==rhs.height;
- }
- constexpr inline bool operator!=(const sizex& rhs) const {
- return width!=rhs.width || height!=rhs.height;
- }
- constexpr static const inline sizex min() { return { bits::num_metrics<value_type>::min,bits::num_metrics<value_type>::min }; }
- constexpr static const inline sizex max() { return { bits::num_metrics<value_type>::max,bits::num_metrics<value_type>::max }; }
- constexpr inline float aspect_ratio() const {
- return (float)width/(float)height;
- }
- constexpr size_t area() const {
- return width*height;
- }
- constexpr sizex flip() const {
- return {height,width};
- }
- constexpr static const inline sizex zero() { return { bits::num_metrics<value_type>::zero,bits::num_metrics<value_type>::zero }; }
- ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement