diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2023-10-04 15:13:53 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2023-10-05 13:58:12 +0200 |
commit | d205274a014acabbed88b18d5058682a0ca46f9c (patch) | |
tree | 826c236b1104d262122f74d0277e0fff206ed273 /tools | |
parent | 3c162a7a312022716e0648f95662b33577b5993d (diff) |
Drop MinMax in favor of std::clamp
Change-Id: I021f524b232ddbe091981444d859d35dd9cd05ac
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157582
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/CppunitTest_tools_test.mk | 1 | ||||
-rw-r--r-- | tools/qa/cppunit/test_minmax.cxx | 98 | ||||
-rw-r--r-- | tools/source/generic/poly.cxx | 8 |
3 files changed, 4 insertions, 103 deletions
diff --git a/tools/CppunitTest_tools_test.mk b/tools/CppunitTest_tools_test.mk index d27f8c3efa58..1063b778ab0a 100644 --- a/tools/CppunitTest_tools_test.mk +++ b/tools/CppunitTest_tools_test.mk @@ -28,7 +28,6 @@ $(eval $(call gb_CppunitTest_add_exception_objects,tools_test, \ tools/qa/cppunit/test_urlobj \ tools/qa/cppunit/test_color \ tools/qa/cppunit/test_rectangle \ - tools/qa/cppunit/test_minmax \ tools/qa/cppunit/test_100mm2twips \ tools/qa/cppunit/test_fround \ tools/qa/cppunit/test_xmlwalker \ diff --git a/tools/qa/cppunit/test_minmax.cxx b/tools/qa/cppunit/test_minmax.cxx deleted file mode 100644 index 509499910216..000000000000 --- a/tools/qa/cppunit/test_minmax.cxx +++ /dev/null @@ -1,98 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include <sal/types.h> -#include <cppunit/TestFixture.h> -#include <cppunit/extensions/HelperMacros.h> - -#include <tools/helpers.hxx> - -namespace tools -{ -class MinMaxTest : public CppUnit::TestFixture -{ -public: - void testSignedMinMax() - { - sal_Int32 nSignedVal = -10; - tools::Long nMin = 1; - tools::Long nMax = 10; - CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(nMin), - static_cast<sal_Int32>(MinMax(nSignedVal, nMin, nMax))); - - nSignedVal = -10; - nMin = -15; - nMax = 10; - CPPUNIT_ASSERT_EQUAL(nSignedVal, static_cast<sal_Int32>(MinMax(nSignedVal, nMin, nMax))); - - nSignedVal = -15; - nMin = -15; - nMax = 10; - CPPUNIT_ASSERT_EQUAL(nSignedVal, static_cast<sal_Int32>(MinMax(nSignedVal, nMin, nMax))); - } - - void testUnsignedMinMax() - { - sal_uInt32 nUnsignedVal = 5; - tools::Long nMin = 1; - tools::Long nMax = 10; - CPPUNIT_ASSERT_EQUAL(nUnsignedVal, - static_cast<sal_uInt32>(MinMax(nUnsignedVal, nMin, nMax))); - - nUnsignedVal = 5; - nMin = 1; - nMax = 5; - CPPUNIT_ASSERT_EQUAL(nUnsignedVal, - static_cast<sal_uInt32>(MinMax(nUnsignedVal, nMin, nMax))); - - nUnsignedVal = 5; - nMin = 5; - nMax = 5; - CPPUNIT_ASSERT_EQUAL(nUnsignedVal, - static_cast<sal_uInt32>(MinMax(nUnsignedVal, nMin, nMax))); - - nUnsignedVal = 10; - nMin = -20; - nMax = 15; - CPPUNIT_ASSERT_EQUAL(nUnsignedVal, - static_cast<sal_uInt32>(MinMax(nUnsignedVal, nMin, nMax))); - - nUnsignedVal = 20; - nMin = 10; - nMax = 15; - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(nMax), - static_cast<sal_uInt32>(MinMax(nUnsignedVal, nMin, nMax))); - - nUnsignedVal = 5; - nMin = 10; - nMax = 15; // irrelevant, but cannot be less than nMin - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(nMin), - static_cast<sal_uInt32>(MinMax(nUnsignedVal, nMin, nMax))); - } - - CPPUNIT_TEST_SUITE(MinMaxTest); - CPPUNIT_TEST(testSignedMinMax); - CPPUNIT_TEST(testUnsignedMinMax); - CPPUNIT_TEST_SUITE_END(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(MinMaxTest); -} // namespace tools - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/tools/source/generic/poly.cxx b/tools/source/generic/poly.cxx index efd04b9b3e3d..89405eea410a 100644 --- a/tools/source/generic/poly.cxx +++ b/tools/source/generic/poly.cxx @@ -178,10 +178,10 @@ ImplPolygon::ImplPolygon( const Point& rCenter, tools::Long nRadX, tools::Long n const bool bOverflow = o3tl::checked_multiply(nRadX, nRadY, nRadXY); if (!bOverflow) { - nPoints = static_cast<sal_uInt16>(MinMax( + nPoints = std::clamp( ( M_PI * ( 1.5 * ( nRadX + nRadY ) - sqrt( static_cast<double>(std::abs(nRadXY)) ) ) ), - 32, 256 )); + 32.0, 256.0 ); } else { @@ -244,10 +244,10 @@ ImplPolygon::ImplPolygon(const tools::Rectangle& rBound, const Point& rStart, co const bool bOverflow = o3tl::checked_multiply(nRadX, nRadY, nRadXY); if (!bOverflow) { - nPoints = static_cast<sal_uInt16>(MinMax( + nPoints = std::clamp( ( M_PI * ( 1.5 * ( nRadX + nRadY ) - sqrt( static_cast<double>(std::abs(nRadXY)) ) ) ), - 32, 256 )); + 32.0, 256.0 ); } else { |