YSTest: YGDIBase.cpp 源文件

YSTest PreAlpha_b700_20160611 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

YGDIBase.cpp
浏览该文件的文档.
1 /*
2 © 2011-2016 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
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 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 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
62 // XXX: Conversion to 'SPos' might be implementation-defined.
63 return IsInInterval<SPos>(px - r.X, SPos(r.Width))
64 && IsInInterval<SPos>(py - r.Y, SPos(r.Height));
65 }
66 inline bool
67 RectContainsRaw(const Rect& r, const Point& pt) ynothrow
68 {
69 return RectContainsRaw(r, pt.X, pt.Y);
70 }
71
72 bool
73 RectContainsStrictRaw(const Rect& r, SPos px, SPos py) ynothrow
74 {
75 YAssert(r.Width > 1, "Invalid width found."),
76 YAssert(r.Height > 1, "Invalid height found.");
77 // XXX: Conversion to 'SPos' might be implementation-defined.
78 return IsInOpenInterval<SPos>(px - r.X, SPos(r.Width - 1))
79 && IsInOpenInterval<SPos>(py - r.Y, SPos(r.Height - 1));
80 }
81 inline bool
82 RectContainsStrictRaw(const Rect& r, const Point& pt) ynothrow
83 {
84 return RectContainsStrictRaw(r, pt.X, pt.Y);
85 }
86
87 } // unnamed namespace;
88
89 const Rect Rect::Invalid(Size::Invalid);
90
91 bool
92 Rect::Contains(SPos px, SPos py) const ynothrow
93 {
94 return !IsUnstrictlyEmpty() && RectContainsRaw(*this, px, py);
95 }
96 bool
97 Rect::Contains(const Rect& r) const ynothrow
98 {
99 return !IsUnstrictlyEmpty() && RectContainsRaw(*this, r.GetPoint())
100 && RectContainsRaw(*this, r.GetPoint() + r.GetSize() - Vec(1, 1));
101 }
102
103 bool
104 Rect::ContainsStrict(SPos px, SPos py) const ynothrow
105 {
106 return Width > 1 && Height > 1 && RectContainsStrictRaw(*this, px, py);
107 }
108 bool
109 Rect::ContainsStrict(const Rect& r) const ynothrow
110 {
111 return Width > 1 && Height > 1 && !r.IsUnstrictlyEmpty()
112 && RectContainsStrictRaw(*this, r.GetPoint())
113 && RectContainsStrictRaw(*this, r.GetPoint() + r.GetSize() - Vec(1, 1));
114 }
115
116 Rect&
117 Rect::operator&=(const Rect& r) ynothrow
118 {
119 const SPos x1(max(X, r.X)), x2(min(GetRight(), r.GetRight())),
120 y1(max(Y, r.Y)), y2(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(min(X, r.X)), my(min(Y, r.Y));
135
136 return *this = Rect(mx, my, SDst(max(GetRight(), r.GetRight())
137 - mx), SDst(max(GetBottom(), r.GetBottom()) - my));
138 }
139
140 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::GGraphics::Height
const SizeType sGraphics Height
Definition: YGraphics.h:136
YSLib::Drawing::Rect::Contains
bool Contains(SPos px, SPos py) const ynothrow
判断点 (px, py) 是否在矩形内或边上。
Definition: YGDIBase.cpp:92
YSLib::Drawing::Rect::operator|=
Rect & operator|=(const Rect &) ynothrow
求与另一个屏幕标准矩形的并。
Definition: YGDIBase.cpp:127
YModules.h
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:45
YSLib::Drawing::GBinaryGroup::X
_type X
Definition: YGDIBase.h:63
YSLib::Drawing::Size::Width
SDst Width
Definition: YGDIBase.h:302
YSLib::Drawing::GBinaryGroup::Y
_type Y
分量。
Definition: YGDIBase.h:63
platform::KeyCodes::DS::Y
Definition: Keys.h:229
YSLib::Drawing::to_string
string to_string(const Rect &r)
Definition: YGDIBase.cpp:141
YSLib::ynothrow
YB_PURE const _type size_t n ynothrow
Definition: YCoreUtilities.h:168
YSLib::Drawing::to_string
string to_string(const ImageTag &tag, ImageMetadataModel model)
Definition: Image.cpp:699
platform::SPos
std::int16_t SPos
屏幕坐标度量。
Definition: Video.h:42
YSLib::Drawing::Vec
GBinaryGroup< SPos > Vec
屏幕二维向量（直角坐标表示）。
Definition: YGDIBase.h:285
YSLib::YAssert
YAssert(!(v< Deref(a)),"Value less than lower bound found.")
YSLib::Drawing::y2
The boundary is out of the const Rect SDst SPos SPos SPos y2
Definition: YDraw.h:127
YSLib::Drawing::Rect
屏幕标准矩形：表示屏幕矩形区域。
Definition: YGDIBase.h:540
ystdex::max
const _type & max(const _type &a, const _type &b, _fComp comp=less< _type >())
取较大的元素。
Definition: algorithm.hpp:543
YSLib::Drawing::Size
屏幕区域大小。
Definition: YGDIBase.h:293
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::Rect::ContainsStrict
bool ContainsStrict(SPos px, SPos py) const ynothrow
判断点 (px, py) 是否在矩形内。
Definition: YGDIBase.cpp:104
Drawing
YSLib::Drawing::Rect::Invalid
static const Rect Invalid
无效对象。
Definition: YGDIBase.h:548
YSLib::Drawing::Size::Height
SDst Height
宽和高。
Definition: YGDIBase.h:302
YSLib::Drawing::Point
GBinaryGroup< SPos > Point
屏幕二维点（直角坐标表示）。
Definition: YGDIBase.h:278
platform::KeyCodes::DS::X
Definition: Keys.h:228
YSLib::Drawing::y1
The boundary is out of the const Rect SDst SPos SPos y1
Definition: YDraw.h:127
ystdex::min
const _type & min(const _type &a, const _type &b, _fComp comp=less< _type >())
取较小的元素。
Definition: algorithm.hpp:521
ystdex::quote
_tString quote(const _tString &str, typename string_traits< _tString >::value_type c=typename string_traits< _tString >::value_type('"'))
取添加前缀和后缀的字符串。
Definition: string.hpp:741
YSLib::Drawing::Size::Invalid
static const Size Invalid
无效对象。
Definition: YGDIBase.h:300
CHRLib::s
_tDst const _tSrc * s
Definition: CharacterProcessing.h:140
YSLib::Drawing::x2
The boundary is out of the const Rect SDst SPos SPos SPos x2
Definition: YDraw.h:148
platform::SDst
std::uint16_t SDst
屏幕坐标距离。
Definition: Video.h:43