diff --git a/libs/ui/tests/KisSpinBoxSplineUnitConverterTest.cpp b/libs/ui/tests/KisSpinBoxSplineUnitConverterTest.cpp index 543bc82ca1..6a398eb07c 100644 --- a/libs/ui/tests/KisSpinBoxSplineUnitConverterTest.cpp +++ b/libs/ui/tests/KisSpinBoxSplineUnitConverterTest.cpp @@ -1,115 +1,115 @@ /* - * Copyright (c) 2015 Agata Cacko + * Copyright (c) 2019 Agata Cacko * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include #include #include void KisSpinBoxSplineUnitConverterTest::testCurveCalculationToCurve_data() { QTest::addColumn("x"); QTest::addColumn("min"); QTest::addColumn("max"); QTest::addColumn("expected"); QTest::newRow("0.6 in (0, 10) = 6") << 6 << 0 << 10 << 0.6; } void KisSpinBoxSplineUnitConverterTest::testCurveCalculationToCurve() { QFETCH(int, x); QFETCH(int, min); QFETCH(int, max); QFETCH(double, expected); qreal result = converter.io2sp(x, min, max); QCOMPARE(result, expected); } void KisSpinBoxSplineUnitConverterTest::testCurveCalculationToSpinBox_data() { QTest::addColumn("x"); QTest::addColumn("min"); QTest::addColumn("max"); QTest::addColumn("expected"); QTest::newRow("0.4 in (0, 10) = 4") << 0.4 << 0 << 10 << 4; } void KisSpinBoxSplineUnitConverterTest::testCurveCalculationToSpinBox() { QFETCH(double, x); QFETCH(int, min); QFETCH(int, max); QFETCH(int, expected); int result = converter.sp2io(x, min, max); QCOMPARE(result, expected); } void KisSpinBoxSplineUnitConverterTest::testCurveCalculationTwoWay_data() { QTest::addColumn("xDouble"); QTest::addColumn("min"); QTest::addColumn("max"); QTest::addColumn("xInt"); QTest::newRow("0.5 in (0, 10) = 5") << 0.5 << 0 << 10 << 5; QTest::newRow("0.3 in (0, 10) = 3") << 0.3 << 0 << 10 << 3; QTest::newRow("0.7 in (0, 10) = 7") << 0.7 << 0 << 10 << 7; QTest::newRow("0.5 in (10, 0) = 5") << 0.5 << 10 << 0 << 5; QTest::newRow("0.7 in (10, 0) = 3") << 0.7 << 10 << 0 << 3; QTest::newRow("0.3 in (10, 0) = 7") << 0.3 << 10 << 0 << 7; } void KisSpinBoxSplineUnitConverterTest::testCurveCalculationTwoWay() { QFETCH(double, xDouble); QFETCH(int, min); QFETCH(int, max); QFETCH(int, xInt); int resultInt = converter.sp2io(xDouble, min, max); QCOMPARE(resultInt, xInt); double resultDouble = converter.io2sp(xInt, min, max); QCOMPARE(resultDouble, xDouble); } void KisSpinBoxSplineUnitConverterTest::testCurveCalculationCase64() { int inX = 64; int min = 90, max = 0; double resultDouble = converter.io2sp(inX, min, max); int resultInt = converter.sp2io(resultDouble, min, max); QCOMPARE(resultInt, inX); } KISTEST_MAIN(KisSpinBoxSplineUnitConverterTest) diff --git a/libs/ui/tests/KisSpinBoxSplineUnitConverterTest.h b/libs/ui/tests/KisSpinBoxSplineUnitConverterTest.h index f8ebd19fed..525f1171e5 100644 --- a/libs/ui/tests/KisSpinBoxSplineUnitConverterTest.h +++ b/libs/ui/tests/KisSpinBoxSplineUnitConverterTest.h @@ -1,49 +1,49 @@ /* - * Copyright (c) 2015 Agata Cacko + * Copyright (c) 2019 Agata Cacko * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KIS_ANIMATION_EXPORTER_TEST_H #define KIS_ANIMATION_EXPORTER_TEST_H #include #include /** * KisSpinBoxSplineUnitConverterTest contains tests * for class KisSpinBoxSplineUnitConverter */ class KisSpinBoxSplineUnitConverterTest : public QObject { Q_OBJECT KisSpinBoxSplineUnitConverter converter; private Q_SLOTS: void testCurveCalculationToSpinBox(); void testCurveCalculationToSpinBox_data(); void testCurveCalculationToCurve(); void testCurveCalculationToCurve_data(); void testCurveCalculationTwoWay(); void testCurveCalculationTwoWay_data(); void testCurveCalculationCase64(); }; #endif diff --git a/libs/ui/utils/KisSpinBoxSplineUnitConverter.cpp b/libs/ui/utils/KisSpinBoxSplineUnitConverter.cpp index c52f5c404c..4e24526a66 100644 --- a/libs/ui/utils/KisSpinBoxSplineUnitConverter.cpp +++ b/libs/ui/utils/KisSpinBoxSplineUnitConverter.cpp @@ -1,28 +1,44 @@ - +/* + * Copyright (c) 2019 Agata Cacko + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ #include "KisSpinBoxSplineUnitConverter.h" #include #include double KisSpinBoxSplineUnitConverter::io2sp(int x, int min, int max) { int reversedRange = max - min > 0 ? 1 : -1; // tilt elevation has range (90; 0) int rangeLen = qAbs(max - min); double response = reversedRange * double(x - min) / rangeLen; return response; } int KisSpinBoxSplineUnitConverter::sp2io(double x, int min, int max) { int rangeLen = max - min; // tilt elevation has range (90; 0) int response = qRound(x*rangeLen) + min; return response; } diff --git a/libs/ui/utils/KisSpinBoxSplineUnitConverter.h b/libs/ui/utils/KisSpinBoxSplineUnitConverter.h index c77df34015..5d2958a5c7 100644 --- a/libs/ui/utils/KisSpinBoxSplineUnitConverter.h +++ b/libs/ui/utils/KisSpinBoxSplineUnitConverter.h @@ -1,48 +1,48 @@ /* - * Copyright (c) 2017 Agata Cacko + * Copyright (c) 2019 Agata Cacko * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KIS_SPIN_BOX_SPLINE_UNITS_CONVERTER_H #define KIS_SPIN_BOX_SPLINE_UNITS_CONVERTER_H #include /** * KisSpinBoxSplineUnitConverter is a class that converts points * from ranges(0, 1) to ranges (min, max). * In case of reverted ranges (min > max), * smaller values from range (0, 1) correspond * to bigger values from range (min, max) * and the other way around. * Example: * 3 from (0, 10) is 0.3 from (0, 1) * 3 from (10, 0) is 0.7 from (0, 1) */ class KRITAUI_EXPORT KisSpinBoxSplineUnitConverter { public: double io2sp(int x, int min, int max); int sp2io(double x, int min, int max); }; #endif // KIS_SPIN_BOX_SPLINE_UNITS_CONVERTER_H