Skip to content

Add some gfx::Size operators #142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 1, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion gfx/size.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// LAF Gfx Library
// Copyright (C) 2020-2024 Igara Studio S.A.
// Copyright (C) 2020-2025 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This file is released under the terms of the MIT license.
Expand All @@ -15,6 +15,8 @@ namespace gfx {

template<typename T>
class PointT;
template<typename T>
class BorderT;

// A 2D size.
template<typename T>
Expand Down Expand Up @@ -64,6 +66,20 @@ class SizeT {
return *this;
}

const SizeT& operator+=(const BorderT<T>& br)
{
w += br.width();
h += br.height();
return *this;
}

const SizeT& operator-=(const BorderT<T>& br)
{
w -= br.width();
h -= br.height();
return *this;
}

const SizeT& operator+=(const T& value)
{
w += value;
Expand Down Expand Up @@ -100,6 +116,10 @@ class SizeT {

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

SizeT operator+(const BorderT<T>& br) const { return SizeT(w + br.width(), h + br.height()); }

SizeT operator-(const BorderT<T>& br) const { return SizeT(w - br.width(), h - br.height()); }

SizeT operator+(const T& value) const { return SizeT(w + value, h + value); }

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

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

SizeT operator|(const SizeT& other) const { return createUnion(other); }

SizeT operator&(const SizeT& other) const { return createIntersection(other); }

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

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