~aleteoryx/muditaos

ref: sign_test muditaos/module-gui/gui/core/BoundingBox.hpp -rw-r--r-- 1.8 KiB
a217eeb3 — Dawid Wojtas [BH-2024] Fix lack of alarm directory after updating software 1 year, 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include "Axes.hpp"
#include "gui/Common.hpp"
#include <cstdint>
#include <limits>
#include <string>

namespace gui
{

    /// defines both: size & position
    /// size is always in:     { zero_size < max_size }
    /// position is always in: { min_position < zero_position < max_position }
    class BoundingBox
    {
      public:
        static constexpr Length zero_size = 0;
        static constexpr Length max_size  = std::numeric_limits<Length>().max();
        static constexpr Length min_size  = std::numeric_limits<Length>().min();

        static constexpr Position zero_position = 0;
        static constexpr Position max_position  = std::numeric_limits<Position>().max();
        static constexpr Position min_position  = std::numeric_limits<Position>().min();

        struct
        {
            Position x = zero_position, y = zero_position;
            Length w = zero_size, h = zero_size;
        };
        BoundingBox() = default;
        BoundingBox(Position x, Position y, Length w, Length h);

        static bool intersect(const BoundingBox &box1, const BoundingBox &box2, BoundingBox &result);

        /// set x,y,w,h to zero
        void clear();
        /// get size in axis - in x get width in y get height
        Length size(gui::Axis axis) const;
        /// get position in axis - in x get x, in y get y
        Position pos(gui::Axis axis) const;
        std::string str() const;
        /// assign width and/or height of bigger bounding box
        void expandSize(const BoundingBox &box);

        bool operator==(const BoundingBox &box) const;
        bool operator!=(const BoundingBox &box) const;
    };

} /* namespace gui */