Audacity 3.2.0
Rect.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*!********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 Rect.h
7
8 Dmitry Vedenko
9
10**********************************************************************/
11#pragma once
12
13#include "Point.h"
14#include "Size.h"
15
16#include <algorithm>
17
18namespace graphics
19{
21template <typename DataType>
22struct RectType final
23{
28
30 bool IsValid() const noexcept
31 {
32 return size.width > 0 && size.height > 0;
33 }
34
36 bool Contains(PointType<DataType> pt) const noexcept
37 {
38 return pt.x >= origin.x && pt.y >= origin.y &&
39 (pt.x < (origin.x + size.width)) &&
40 (pt.y < (origin.y + size.height));
41 }
42};
43
44template <typename DataType>
46 const RectType<DataType> lhs, const RectType<DataType> rhs) noexcept
47{
48 return lhs.origin == rhs.origin && lhs.size == rhs.size;
49}
50
51template <typename DataType>
53 const RectType<DataType> lhs, const RectType<DataType> rhs) noexcept
54{
55 return !(lhs == rhs);
56}
57
59template <typename To, typename From>
61{
62 return { point_cast<To>(rect.origin), size_cast<To>(rect.size) };
63}
64
67
68} // namespace graphics
Definition: Color.h:18
bool operator==(PointType< DataType > lhs, PointType< DataType > rhs) noexcept
Definition: Point.h:97
RectType< To > rect_cast(RectType< From > rect)
Cast the rectangle to another data type.
Definition: Rect.h:60
bool operator!=(PointType< DataType > lhs, PointType< DataType > rhs) noexcept
Definition: Point.h:103
A point in 2D space.
Definition: Point.h:23
Rectangle that is defined by the top left corner and the size.
Definition: Rect.h:23
PointType< DataType > origin
Origin of the rectangle.
Definition: Rect.h:25
SizeType< DataType > size
Size of the rectangle.
Definition: Rect.h:27
bool Contains(PointType< DataType > pt) const noexcept
Return true if the rectangle contains the point specified.
Definition: Rect.h:36
bool IsValid() const noexcept
Return true if the rectangle is not empty.
Definition: Rect.h:30
A class that represents size in 2D space.
Definition: Size.h:33