mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-29 01:35:06 +01:00
Fence removal did not account for track direction. Added the rotation for the track/fence intersection test.
72 lines
2.3 KiB
C++
72 lines
2.3 KiB
C++
/*****************************************************************************
|
|
* Copyright (c) 2014-2019 OpenRCT2 developers
|
|
*
|
|
* For a complete list of all authors, please refer to contributors.md
|
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
|
*
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
|
*****************************************************************************/
|
|
|
|
#pragma once
|
|
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <limits>
|
|
#include <type_traits>
|
|
|
|
namespace Numerics
|
|
{
|
|
/**
|
|
* Bitwise left rotate
|
|
* @tparam _UIntType unsigned integral type
|
|
* @param x value
|
|
* @param shift positions to shift
|
|
* @return rotated value
|
|
*/
|
|
template<typename _UIntType> static constexpr _UIntType rol(_UIntType x, size_t shift)
|
|
{
|
|
static_assert(std::is_unsigned<_UIntType>::value, "result_type must be an unsigned integral type");
|
|
using limits = typename std::numeric_limits<_UIntType>;
|
|
return (((_UIntType)(x) << shift) | ((_UIntType)(x) >> (limits::digits - shift)));
|
|
}
|
|
|
|
/**
|
|
* Bitwise left rotate of lowest 4 bits
|
|
* @param x unsigned 8-bit integer value
|
|
* @param shift positions to shift
|
|
* @return rotated value
|
|
*/
|
|
[[maybe_unused]] static constexpr uint8_t rol4(uint8_t x, size_t shift)
|
|
{
|
|
x &= 0x0F;
|
|
return (x << shift | x >> (4 - shift)) & 0x0F;
|
|
}
|
|
|
|
/**
|
|
* Bitwise right rotate
|
|
* @tparam _UIntType unsigned integral type
|
|
* @param x value
|
|
* @param shift positions to shift
|
|
* @return rotated value
|
|
*/
|
|
template<typename _UIntType> static constexpr _UIntType ror(_UIntType x, size_t shift)
|
|
{
|
|
static_assert(std::is_unsigned<_UIntType>::value, "result_type must be an unsigned integral type");
|
|
using limits = std::numeric_limits<_UIntType>;
|
|
return (((_UIntType)(x) >> shift) | ((_UIntType)(x) << (limits::digits - shift)));
|
|
}
|
|
|
|
/**
|
|
* Bitwise right rotate of lowest 4 bits
|
|
* @param x unsigned 8-bit integer value
|
|
* @param shift positions to shift
|
|
* @return rotated value
|
|
*/
|
|
[[maybe_unused]] static constexpr uint8_t ror4(uint8_t x, size_t shift)
|
|
{
|
|
x &= 0x0F;
|
|
return (x >> shift | x << (4 - shift)) & 0x0F;
|
|
}
|
|
|
|
} // namespace Numerics
|