blob: f3e9bea4c7f594cba73c56a6f082c203b450ee8d [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Pablo Marquez Tellob1db6e12021-09-01 10:18:57 +01002 * Copyright (c) 2016-2021 Arm Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_SIZE2D_H
25#define ARM_COMPUTE_SIZE2D_H
Anthony Barbier6ff3b192017-09-04 18:44:23 +010026
27#include <cstddef>
Matthew Bentham758b5ba2020-03-05 23:37:48 +000028#include <string>
Isabella Gottardi6e464c32018-01-26 12:32:45 +000029#include <utility>
Anthony Barbier6ff3b192017-09-04 18:44:23 +010030
31namespace arm_compute
32{
33/** Class for specifying the size of an image or rectangle */
34class Size2D
35{
36public:
37 /** Default constructor */
Isabella Gottardi6e464c32018-01-26 12:32:45 +000038 Size2D() = default;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010039 /** Constructor. Initializes "width" and "height" respectively with "w" and "h"
40 *
41 * @param[in] w Width of the image or rectangle
42 * @param[in] h Height of the image or rectangle
43 */
Pablo Marquez Tellob1db6e12021-09-01 10:18:57 +010044 Size2D(size_t w, size_t h) noexcept
45 : width(w),
46 height(h)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010047 {
48 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +010049 /** The area of the image or rectangle calculated as (width * height)
50 *
51 * @return Area (width * height)
52 *
53 */
54 size_t area() const
55 {
56 return (width * height);
57 }
58
Giorgio Arena2d9de0a2018-03-15 17:58:20 +000059 bool operator==(const Size2D &other) const
60 {
61 return (width == other.width) && (height == other.height);
62 }
63
64 bool operator!=(const Size2D &other) const
65 {
66 return !(*this == other);
67 }
68
Matthew Bentham758b5ba2020-03-05 23:37:48 +000069 std::string to_string() const;
Giorgio Arena2d9de0a2018-03-15 17:58:20 +000070
Alex Gilday7da29b62018-03-23 14:16:00 +000071 /** Semantic accessor for width as x.
72 *
73 * @return x.
74 */
75 size_t x() const
76 {
77 return width;
78 }
79
80 /** Semantic accessor for height as y.
81 *
82 * @return y.
83 */
84 size_t y() const
85 {
86 return height;
87 }
88
Anthony Barbier6ff3b192017-09-04 18:44:23 +010089public:
Isabella Gottardi6e464c32018-01-26 12:32:45 +000090 size_t width = {}; /**< Width of the image region or rectangle */
91 size_t height = {}; /**< Height of the image region or rectangle */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010092};
93}
Michalis Spyrouf4643372019-11-29 16:17:13 +000094#endif /*ARM_COMPUTE_SIZE2D_H */