libcamera  v0.0.0
Supporting cameras in Linux since 2019
geometry.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 /*
3  * Copyright (C) 2019, Google Inc.
4  *
5  * geometry.h - Geometry-related structure
6  */
7 
8 #ifndef __LIBCAMERA_GEOMETRY_H__
9 #define __LIBCAMERA_GEOMETRY_H__
10 
11 #include <string>
12 
13 namespace libcamera {
14 
15 struct Rectangle {
16  int x;
17  int y;
18  unsigned int width;
19  unsigned int height;
20 
21  const std::string toString() const;
22 };
23 
24 bool operator==(const Rectangle &lhs, const Rectangle &rhs);
25 static inline bool operator!=(const Rectangle &lhs, const Rectangle &rhs)
26 {
27  return !(lhs == rhs);
28 }
29 
30 struct Size {
31  Size()
32  : Size(0, 0)
33  {
34  }
35 
36  Size(unsigned int w, unsigned int h)
37  : width(w), height(h)
38  {
39  }
40 
41  unsigned int width;
42  unsigned int height;
43 
44  bool isNull() const { return !width && !height; }
45  const std::string toString() const;
46 };
47 
48 bool operator==(const Size &lhs, const Size &rhs);
49 bool operator<(const Size &lhs, const Size &rhs);
50 
51 static inline bool operator!=(const Size &lhs, const Size &rhs)
52 {
53  return !(lhs == rhs);
54 }
55 
56 static inline bool operator<=(const Size &lhs, const Size &rhs)
57 {
58  return lhs < rhs || lhs == rhs;
59 }
60 
61 static inline bool operator>(const Size &lhs, const Size &rhs)
62 {
63  return !(lhs <= rhs);
64 }
65 
66 static inline bool operator>=(const Size &lhs, const Size &rhs)
67 {
68  return !(lhs < rhs);
69 }
70 
71 class SizeRange
72 {
73 public:
75  : hStep(0), vStep(0)
76  {
77  }
78 
79  SizeRange(const Size &size)
80  : min(size), max(size), hStep(1), vStep(1)
81  {
82  }
83 
84  SizeRange(const Size &minSize, const Size &maxSize)
85  : min(minSize), max(maxSize), hStep(1), vStep(1)
86  {
87  }
88 
89  SizeRange(const Size &minSize, const Size &maxSize,
90  unsigned int hstep, unsigned int vstep)
91  : min(minSize), max(maxSize), hStep(hstep), vStep(vstep)
92  {
93  }
94 
95  bool contains(const Size &size) const;
96 
97  std::string toString() const;
98 
101  unsigned int hStep;
102  unsigned int vStep;
103 };
104 
105 bool operator==(const SizeRange &lhs, const SizeRange &rhs);
106 static inline bool operator!=(const SizeRange &lhs, const SizeRange &rhs)
107 {
108  return !(lhs == rhs);
109 }
110 
111 } /* namespace libcamera */
112 
113 #endif /* __LIBCAMERA_GEOMETRY_H__ */
Describe a range of sizes.
Definition: geometry.h:72
SizeRange(const Size &minSize, const Size &maxSize, unsigned int hstep, unsigned int vstep)
Construct a size range with specified min, max and step.
Definition: geometry.h:89
SizeRange(const Size &minSize, const Size &maxSize)
Construct a size range with specified min and max, and steps of 1.
Definition: geometry.h:84
unsigned int vStep
The vertical step.
Definition: geometry.h:102
SizeRange(const Size &size)
Construct a size range representing a single size.
Definition: geometry.h:79
Size max
The maximum size.
Definition: geometry.h:100
unsigned int hStep
The horizontal step.
Definition: geometry.h:101
SizeRange()
Construct a size range initialized to 0.
Definition: geometry.h:74
Size min
The minimum size.
Definition: geometry.h:99
bool contains(const Size &size) const
Test if a size is contained in the range.
Definition: geometry.cpp:273
std::string toString() const
Assemble and return a string describing the size range.
Definition: geometry.cpp:288
bool operator==(const Rectangle &lhs, const Rectangle &rhs)
Compare rectangles for equality.
Definition: geometry.cpp:69
Describe a rectangle's position and dimensions.
Definition: geometry.h:15
int y
The vertical coordinate of the rectangle's top-left corner.
Definition: geometry.h:17
unsigned int height
The distance between the top and bottom sides.
Definition: geometry.h:19
const std::string toString() const
Assemble and return a string describing the rectangle.
Definition: geometry.cpp:56
unsigned int width
The distance between the left and right sides.
Definition: geometry.h:18
int x
The horizontal coordinate of the rectangle's top-left corner.
Definition: geometry.h:16
Describe a two-dimensional size.
Definition: geometry.h:30
const std::string toString() const
Assemble and return a string describing the size.
Definition: geometry.cpp:120
Size()
Construct a Size with width and height set to 0.
Definition: geometry.h:31
unsigned int width
The Size width.
Definition: geometry.h:41
Size(unsigned int w, unsigned int h)
Construct a Size with given width and height.
Definition: geometry.h:36
bool isNull() const
Check if the size is null.
Definition: geometry.h:44
unsigned int height
The Size height.
Definition: geometry.h:42