1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 #include <sal/config.h>
12 #include <sal/types.h>
13 #include <tools/long.hxx>
16 #include <type_traits>
20 typename
std::enable_if
<
21 std::is_signed
<T
>::value
|| std::is_floating_point
<T
>::value
, long >::type
22 MinMax(T nVal
, tools::Long nMin
, tools::Long nMax
)
28 return static_cast<tools::Long
>(nVal
);
40 typename
std::enable_if
<
41 std::is_unsigned
<T
>::value
, long >::type
42 MinMax(T nVal
, tools::Long nMin
, tools::Long nMax
)
51 if (nMin
< 0 || nVal
>= static_cast<unsigned long>(nMin
))
53 if (nVal
<= static_cast<unsigned long>(nMax
))
54 return static_cast<tools::Long
>(nVal
);
65 inline sal_uInt32
AlignedWidth4Bytes(sal_uInt32 nWidthBits
)
67 if (nWidthBits
> SAL_MAX_UINT32
- 31)
68 nWidthBits
= SAL_MAX_UINT32
;
71 return (nWidthBits
>> 5) << 2;
74 inline tools::Long
FRound( double fVal
)
77 ? fVal
== double(std::numeric_limits
<tools::Long
>::max())
78 ? std::numeric_limits
<tools::Long
>::max() : static_cast<tools::Long
>( fVal
+ 0.5 )
79 : static_cast<tools::Long
>( fVal
- 0.5 );
82 //valid range: (-180,180]
84 [[nodiscard
]] inline typename
std::enable_if
<std::is_signed
<T
>::value
, T
>::type
94 //valid range: [0,360)
95 template <typename T
> [[nodiscard
]] inline T
NormAngle360(T angle
)
104 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */