YSTest: YGDIBase.cpp 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

YGDIBase.cpp
浏览该文件的文档.
1 /*
2 © 2011-2016, 2019 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
28 #include "YSLib/Core/YModules.h"
29 #include YFM_YSLib_Core_YGDIBase // for ystdex::quote, ystdex::min, ystdex::max;
30 #include YFM_YSLib_Core_YCoreUtilities
31
32 namespace YSLib
33 {
34
35 namespace Drawing
36 {
37
38 const Size Size::Invalid(std::numeric_limits<SDst>::lowest(),
39 std::numeric_limits<SDst>::lowest());
40
41 std::string
42 to_string(const Size& s)
43 {
44 using YSLib::to_string;
45
46 return ystdex::quote(to_string(s.Width) + ", " + to_string(s.Height), '(',
47 ')');
48 }
49
50
52 namespace
53 {
54
56 YB_ATTR_nodiscard YB_PURE bool
57 RectContainsRaw(const Rect& r, SPos px, SPos py) ynothrow
58 {
59 YAssert(r.Width > 0, "Invalid width found."),
60 YAssert(r.Height > 0, "Invalid height found.");
61 // XXX: Conversion to 'SPos' might be implementation-defined.
62 return IsInInterval<SPos>(px - r.X, SPos(r.Width))
63 && IsInInterval<SPos>(py - r.Y, SPos(r.Height));
64 }
65 YB_ATTR_nodiscard YB_PURE inline bool
66 RectContainsRaw(const Rect& r, const Point& pt) ynothrow
67 {
68 return RectContainsRaw(r, pt.X, pt.Y);
69 }
70
71 YB_ATTR_nodiscard YB_PURE bool
72 RectContainsStrictRaw(const Rect& r, SPos px, SPos py) ynothrow
73 {
74 YAssert(r.Width > 1, "Invalid width found."),
75 YAssert(r.Height > 1, "Invalid height found.");
76 // XXX: Conversion to 'SPos' might be implementation-defined.
77 return IsInOpenInterval<SPos>(px - r.X, SPos(r.Width - 1))
78 && IsInOpenInterval<SPos>(py - r.Y, SPos(r.Height - 1));
79 }
80 YB_ATTR_nodiscard YB_PURE inline bool
81 RectContainsStrictRaw(const Rect& r, const Point& pt) ynothrow
82 {
83 return RectContainsStrictRaw(r, pt.X, pt.Y);
84 }
85
86 } // unnamed namespace;
87
88 const Rect Rect::Invalid(Size::Invalid);
89
90 bool
91 Rect::Contains(SPos px, SPos py) const ynothrow
92 {
93 return !IsUnstrictlyEmpty() && RectContainsRaw(*this, px, py);
94 }
95 bool
96 Rect::Contains(const Rect& r) const ynothrow
97 {
98 return !IsUnstrictlyEmpty() && RectContainsRaw(*this, r.GetPoint())
99 && RectContainsRaw(*this, r.GetPoint() + r.GetSize() - Vec(1, 1));
100 }
101
102 bool
103 Rect::ContainsStrict(SPos px, SPos py) const ynothrow
104 {
105 return Width > 1 && Height > 1 && RectContainsStrictRaw(*this, px, py);
106 }
107 bool
108 Rect::ContainsStrict(const Rect& r) const ynothrow
109 {
110 return Width > 1 && Height > 1 && !r.IsUnstrictlyEmpty()
111 && RectContainsStrictRaw(*this, r.GetPoint())
112 && RectContainsStrictRaw(*this, r.GetPoint() + r.GetSize() - Vec(1, 1));
113 }
114
115 Rect&
116 Rect::operator&=(const Rect& r) ynothrow
117 {
118 const SPos x1(ystdex::max(X, r.X)),
119 x2(ystdex::min(GetRight(), r.GetRight())),
120 y1(ystdex::max(Y, r.Y)), y2(ystdex::min(GetBottom(), r.GetBottom()));
121
122 return *this = x2 < x1 || y2 < y1 ? Rect()
123 : Rect(x1, y1, SDst(x2 - x1), SDst(y2 - y1));
124 }
125
126 Rect&
127 Rect::operator|=(const Rect& r) ynothrow
128 {
129 if(!*this)
130 return *this = r;
131 if(!r)
132 return *this;
133
134 const SPos mx(ystdex::min(X, r.X)), my(ystdex::min(Y, r.Y));
135
136 return *this = Rect(mx, my, SDst(ystdex::max(GetRight(), r.GetRight())
137 - mx), SDst(ystdex::max(GetBottom(), r.GetBottom()) - my));
138 }
139
140 std::string
141 to_string(const Rect& r)
142 {
143 using YSLib::to_string;
144
145 return ystdex::quote(to_string(r.X) + ", " + to_string(r.Y) + ", "
146 + to_string(r.Width) + ", " + to_string(r.Height), '(', ')');
147 }
148
149 } // namespace Drawing;
150
151 } // namespace YSLib;
152
YSLib::Drawing::SPos
YB_ATTR_nodiscard yconstfn YB_PURE x x x Bottom YB_ATTR_nodiscard yconstfn YB_PURE x Right y x Top y x Bottom y Bottom YB_ATTR_nodiscard yconstfn YB_PURE x Right y x Top y x Bottom y Bottom YB_ATTR_nodiscard yconstfn YB_PURE SPos(x.Right *ptrdiff_t(n))
YB_ATTR_nodiscard
#define YB_ATTR_nodiscard
标记返回值不被忽略的属性。
Definition: ydef.h:715
YSLib::Drawing::y2
The boundary is out of the const Rect SDst SPos SPos SPos y2
Definition: YDraw.h:128
YSLib::Drawing::Size
屏幕区域大小。
Definition: YGDIBase.h:536
YSLib::Drawing::Rect::Invalid
static const Rect Invalid
无效对象。
Definition: YGDIBase.h:794
ystdex::quote
decay_t< _tString > quote(_tString &&str, typename string_traits< decay_t< _tString >>::value_type c=typename string_traits< decay_t< _tString >>::value_type('"'))
取添加前缀和后缀的字符串。
Definition: string.hpp:1579
YB_PURE
#define YB_PURE
指示函数或函数模板实例为纯函数。
Definition: ydef.h:919
ystdex::cpp2014::min
const _type & min(const _type &a, const _type &b, _fComp comp=less< _type >())
取较小的元素。
Definition: algorithm.hpp:614
YSLib::Drawing::x1
The boundary is out of the const Rect SDst SPos x1
Definition: YDraw.h:148
YSLib::Drawing::r
The boundary is out of the const Graphics const Rect const Point const Point Color c const Rect const Rect & r
Definition: YDraw.h:174
YSLib::Drawing::GGraphics::Height
const SizeType sGraphics Height
Definition: YGraphics.h:136
YModules.h
YSLib 核心模块配置文件。
YSLib::Drawing::Rect::operator|=
Rect & operator|=(const Rect &) ynothrow
求与另一个屏幕标准矩形的并。
Definition: YGDIBase.cpp:127
ystdex::cpp2014::max
const _type & max(const _type &a, const _type &b, _fComp comp=less< _type >())
取较大的元素。
Definition: algorithm.hpp:635
YSLib::Drawing::x2
The boundary is out of the const Rect SDst SPos SPos SPos x2
Definition: YDraw.h:149
YSLib::Drawing::Size::Invalid
static const Size Invalid
无效对象。
Definition: YGDIBase.h:542
YSLib::Drawing::Rect::Contains
YB_ATTR_nodiscard YB_PURE bool Contains(SPos px, SPos py) const ynothrow
判断点 (px, py) 是否在矩形内或边上。
Definition: YGDIBase.cpp:91
YSLib::YAssert
YAssert(!(v< Deref(a)), "Value less than lower bound found.")
YSLib::Drawing::Point
GBinaryGroup< SPos > Point
屏幕二维点（直角坐标表示）。
Definition: YGDIBase.h:520
YSLib::Drawing::to_string
std::string to_string(const Rect &r)
Definition: YGDIBase.cpp:141
YSLib::Drawing::IsUnstrictlyEmpty
YB_ATTR_nodiscard !x IsUnstrictlyEmpty()) YB_ATTR_nodiscard YF_API Point ClipBounds(Rect &
根据指定源的边界优化绘制上下文的剪切区域。
YSLib::Drawing::GBinaryGroup< SPos >
platform::KeyCodes::DS::X
@ X
Definition: Keys.h:229
platform::SDst
std::uint16_t SDst
屏幕坐标距离。
Definition: Video.h:44
YSLib::Drawing::Rect::ContainsStrict
YB_ATTR_nodiscard YB_PURE bool ContainsStrict(SPos px, SPos py) const ynothrow
判断点 (px, py) 是否在矩形内。
Definition: YGDIBase.cpp:103
platform::KeyCodes::DS::Y
@ Y
Definition: Keys.h:230
YSLib::Drawing::Rect
屏幕标准矩形：表示屏幕矩形区域。
Definition: YGDIBase.h:788
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:46
CHRLib::s
_tDst const _tSrc * s
Definition: CharacterProcessing.h:143
YSLib::Drawing::y1
The boundary is out of the const Rect SDst SPos SPos y1
Definition: YDraw.h:127
YSLib::Drawing::ynothrow
YB_ATTR_nodiscard yconstfn YB_PURE x x x Bottom YB_ATTR_nodiscard yconstfn YB_PURE x Right y x Top y x Bottom y Bottom YB_ATTR_nodiscard yconstfn YB_PURE x Right y x Top y x Bottom y Bottom YB_ATTR_nodiscard yconstfn YB_PURE const Padding & ynothrow
Definition: YGDI.h:132
platform::SPos
std::int16_t SPos
屏幕坐标度量。
Definition: Video.h:43
ystdex::cpp2017::string
basic_string< char > string
Definition: string.hpp:772
YSLib::Drawing::to_string
YB_ATTR_nodiscard YB_PURE std::string to_string(const GBinaryGroup< _type > &val)
转换为字符串。
Definition: YGDIBase.h:507