YSTest: ygdibase.cpp 源文件

YSTest PreAlpha_b400_20130424 The YSLib Test Project

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

- 文件列表
- 文件成员

全部 类 命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义 组 页
ygdibase.cpp
浏览该文件的文档.
1 ﻿/*
2 Copyright by FrankHB 2011 - 2013.
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/ygdibase.h"
29 #include "YSLib/Core/ycutil.h"
30 #include <ystdex/algorithm.hpp>
31
32 YSL_BEGIN
33
34 YSL_BEGIN_NAMESPACE(Drawing)
35
36 const Size Size::Invalid(std::numeric_limits<SDst>::lowest(),
37 std::numeric_limits<SDst>::lowest());
38
39
40 const Rect Rect::Invalid(Size::Invalid);
41
42 bool
43 Rect::Contains(int px, int py) const ynothrow
44 {
45 return Width > 0 && Height > 0 && IsInInterval<int>(px - X, Width)
46 && IsInInterval<int>(py - Y, Height);
47 }
48 bool
49 Rect::Contains(const Rect& r) const ynothrow
50 {
51 return Contains(r.GetPoint()) && Contains(r.GetPoint() + r.GetSize());
52 }
53
54 bool
55 Rect::ContainsStrict(int px, int py) const ynothrow
56 {
57 return Width > 1 && Height > 1 && IsInOpenInterval<int>(px - X,
58 Width - 1) && IsInOpenInterval<int>(py - Y, Height - 1);
59 }
60 bool
61 Rect::ContainsStrict(const Rect& r) const ynothrow
62 {
63 return ContainsStrict(r.GetPoint())
64 && ContainsStrict(r.GetPoint() + r.GetSize());
65 }
66
67 Rect&
68 Rect::operator&=(const Rect& r) ynothrow
69 {
70 const SPos x1(max(X, r.X)), x2(min(X + Width, r.X + r.Width)),
71 y1(max(Y, r.Y)), y2(min(Y + Height, r.Y + r.Height));
72
73 return *this = x2 < x1 || y2 < y1 ? Rect() : Rect(x1, y1, x2 - x1, y2 - y1);
74 }
75
76 Rect&
77 Rect::operator|=(const Rect& r) ynothrow
78 {
79 if(!*this)
80 return *this = r;
81 if(!r)
82 return *this;
83
84 const SPos mx(min(X, r.X)), my(min(Y, r.Y));
85
86 return *this = Rect(mx, my, max(X + Width, r.X + r.Width) - mx,
87 max(Y + Height, r.Y + r.Height) - my);
88 }
89
90 Rect
91 operator&(const Rect& a, const Rect& b) ynothrow
92 {
93 return Rect(a) &= b;
94 }
95
96 Rect
97 operator|(const Rect& a, const Rect& b) ynothrow
98 {
99 return Rect(a) |= b;
100 }
101
102
103 const Graphics Graphics::Invalid;
104
105 BitmapPtr
106 Graphics::operator[](size_t r) const ynothrow
107 {
108 YAssert(pBuffer, "Null pointer found.");
109 YAssert(r < size.Height, "Access out of range.");
110
111 return pBuffer + r * size.Width;
112 }
113 BitmapPtr
114 Graphics::at(size_t r) const ythrow(GeneralEvent, std::out_of_range)
115 {
116 if(YB_UNLIKELY(!pBuffer))
117 throw GeneralEvent("Null pointer found.");
118 if(YB_UNLIKELY(r >= size.Height))
119 throw std::out_of_range("Access out of range.");
120
121 return pBuffer + r * size.Width;
122 }
123
124 YSL_END_NAMESPACE(Drawing)
125
126 YSL_END
127