Skip to content

Commit 0903934

Browse files
committed
Add some gfx::Size operators
* To add/subtract a Border to a Size * To union/intersect two sizes
1 parent 4f005f8 commit 0903934

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

gfx/size.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// LAF Gfx Library
2-
// Copyright (C) 2020-2024 Igara Studio S.A.
2+
// Copyright (C) 2020-2025 Igara Studio S.A.
33
// Copyright (C) 2001-2018 David Capello
44
//
55
// This file is released under the terms of the MIT license.
@@ -15,6 +15,8 @@ namespace gfx {
1515

1616
template<typename T>
1717
class PointT;
18+
template<typename T>
19+
class BorderT;
1820

1921
// A 2D size.
2022
template<typename T>
@@ -64,6 +66,20 @@ class SizeT {
6466
return *this;
6567
}
6668

69+
const SizeT& operator+=(const BorderT<T>& br)
70+
{
71+
w += br.width();
72+
h += br.height();
73+
return *this;
74+
}
75+
76+
const SizeT& operator-=(const BorderT<T>& br)
77+
{
78+
w -= br.width();
79+
h -= br.height();
80+
return *this;
81+
}
82+
6783
const SizeT& operator+=(const T& value)
6884
{
6985
w += value;
@@ -100,6 +116,10 @@ class SizeT {
100116

101117
SizeT operator-(const SizeT& sz) const { return SizeT(w - sz.w, h - sz.h); }
102118

119+
SizeT operator+(const BorderT<T>& br) const { return SizeT(w + br.width(), h + br.height()); }
120+
121+
SizeT operator-(const BorderT<T>& br) const { return SizeT(w - br.width(), h - br.height()); }
122+
103123
SizeT operator+(const T& value) const { return SizeT(w + value, h + value); }
104124

105125
SizeT operator-(const T& value) const { return SizeT(w - value, h - value); }
@@ -110,6 +130,10 @@ class SizeT {
110130

111131
SizeT operator-() const { return SizeT(-w, -h); }
112132

133+
SizeT operator|(const SizeT& other) const { return createUnion(other); }
134+
135+
SizeT operator&(const SizeT& other) const { return createIntersection(other); }
136+
113137
bool operator==(const SizeT& sz) const { return w == sz.w && h == sz.h; }
114138

115139
bool operator!=(const SizeT& sz) const { return w != sz.w || h != sz.h; }

0 commit comments

Comments
 (0)