| 1 | /* |
| 2 | SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org> |
| 3 | |
| 4 | SPDX-License-Identifier: LGPL-2.0-or-later |
| 5 | */ |
| 6 | |
| 7 | #ifndef SPATIAL_INDEX_ENTRY_P_H |
| 8 | #define SPATIAL_INDEX_ENTRY_P_H |
| 9 | |
| 10 | #include <cstdint> |
| 11 | |
| 12 | #pragma pack(push) |
| 13 | #pragma pack(1) |
| 14 | |
| 15 | /*! Entry in the spatial index. |
| 16 | * This is essentially just a pair of numbers, the first being the position |
| 17 | * on the z-order curve and defines the order, the second being the index into the |
| 18 | * property table. |
| 19 | * |
| 20 | * These entries exist in very large quantities, so compact storage is important. |
| 21 | * |
| 22 | * \internal |
| 23 | */ |
| 24 | class SpatialIndexEntry |
| 25 | { |
| 26 | public: |
| 27 | inline constexpr SpatialIndexEntry(uint32_t z, uint32_t propertyIdx) |
| 28 | : m_z(z) |
| 29 | , m_unused(0) |
| 30 | , m_propHigh(propertyIdx >> 8) |
| 31 | , m_propLow(propertyIdx) |
| 32 | { |
| 33 | } |
| 34 | |
| 35 | inline constexpr uint32_t z() const |
| 36 | { |
| 37 | return m_z; |
| 38 | } |
| 39 | |
| 40 | inline constexpr uint32_t propertyIndex() const |
| 41 | { |
| 42 | return m_propHigh << 8 | m_propLow; |
| 43 | } |
| 44 | |
| 45 | private: |
| 46 | uint32_t m_z : 22; |
| 47 | [[maybe_unused]] uint32_t m_unused : 6; |
| 48 | uint32_t m_propHigh : 4; |
| 49 | uint8_t m_propLow; |
| 50 | }; |
| 51 | |
| 52 | #pragma pack(pop) |
| 53 | |
| 54 | inline constexpr bool operator<(SpatialIndexEntry lhs, SpatialIndexEntry rhs) |
| 55 | { |
| 56 | return lhs.z() < rhs.z(); |
| 57 | } |
| 58 | |
| 59 | inline constexpr bool operator<(SpatialIndexEntry lhs, uint32_t rhs) |
| 60 | { |
| 61 | return lhs.z() < rhs; |
| 62 | } |
| 63 | |
| 64 | inline constexpr bool operator<(uint32_t lhs, SpatialIndexEntry rhs) |
| 65 | { |
| 66 | return lhs < rhs.z(); |
| 67 | } |
| 68 | |
| 69 | #endif |
| 70 | |