LIBEUNOMIA
読み取り中…
検索中…
一致する文字列を見つけられません
rect.h
[詳解]
1/*
2 * Copyright 2021 oZ/acy (名賀月晃嗣)
3 * Redistribution and use in source and binary forms,
4 * with or without modification,
5 * are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 */
35#ifndef INCLUDE_GUARD_EUNOMIA_RECTANGLE_H
36#define INCLUDE_GUARD_EUNOMIA_RECTANGLE_H
37
38#include <algorithm>
39#include <type_traits>
40
41namespace eunomia
42{
43
47struct Rect
48{
49 int left;
50 int top;
51 int right;
52 int bottom;
53
54 Rect() = default;
55 constexpr Rect(int l, int t, int r, int b) noexcept
56 : left(l), top(t), right(r), bottom(b)
57 {}
58
59 void normalize()
63 {
64 if (left > right)
65 std::swap(left, right);
66 if (top > bottom)
67 std::swap(top, bottom);
68 }
69
70 constexpr bool isNormalized() const noexcept
71 {
72 return left <= right && top <= bottom;
73 }
74
75 constexpr int width() const noexcept { return right - left; }
76 constexpr int height() const noexcept { return bottom - top; }
77};
78
79
84{
85 int x;
86 int y;
87 int width;
88 int height;
89
90 AnotherRect() = default;
91 constexpr AnotherRect(int xx, int yy, int w, int h) noexcept
92 : x(xx), y(yy), width(w), height(h)
93 {}
94 constexpr explicit AnotherRect(const Rect& r) noexcept
95 : x(std::min(r.left, r.right)), y(std::min(r.top, r.bottom)),
96 width(std::max(r.left, r.right) - x),
97 height(std::max(r.top, r.bottom) - y)
98 {}
99
100 constexpr explicit operator bool() const noexcept
101 {
102 return width >= 0 && height >= 0;
103 }
104
105 constexpr operator Rect() const noexcept
106 {
107 return Rect(x, y, x + width, y + height);
108 }
109};
110
111
112}//end of namespace eunomia
113
114
115
116
117#endif // INCLUDE_GUARD_EUNOMIA_RECTANGLE_H
畫像バッファ基底クラステンプレート
Definition imagebuffer.h:84
Definition colour.h:49
長方形の別表現
Definition rect.h:84
constexpr AnotherRect(int xx, int yy, int w, int h) noexcept
Definition rect.h:91
int height
高さ
Definition rect.h:88
int width
Definition rect.h:87
constexpr AnotherRect(const Rect &r) noexcept
Definition rect.h:94
int y
(上端の)Y座標
Definition rect.h:86
int x
(左端の)X座標
Definition rect.h:85
長方形
Definition rect.h:48
constexpr int height() const noexcept
Definition rect.h:76
int left
左端のX座標
Definition rect.h:49
constexpr Rect(int l, int t, int r, int b) noexcept
Definition rect.h:55
int right
右端のX座標
Definition rect.h:51
constexpr bool isNormalized() const noexcept
Definition rect.h:70
int bottom
下端のY座標
Definition rect.h:52
constexpr int width() const noexcept
Definition rect.h:75
void normalize() noexcept(std::is_nothrow_move_constructible< int >::value &&std::is_nothrow_move_assignable< int >::value)
Definition rect.h:59
Rect()=default
int top
上端のY座標
Definition rect.h:50