Make template class Dali::IntPair 75/282675/13
authorEunki, Hong <eunkiki.hong@samsung.com>
Sat, 8 Oct 2022 07:32:02 +0000 (16:32 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Fri, 14 Oct 2022 05:44:09 +0000 (14:44 +0900)
Make integer pair case so we can use
integer based pair struct.

Dali::Uint16Pair already used for a long time.
But now, we need Dali::Int32Pair to use signed case.

uint-16-pair.h is used on third party app, we cannot
remove this file yet.
So, Let we define Uint16Pair in that class.

Change-Id: I24055b8f70c3948a51a0147786725f192ade8990
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
automated-tests/src/dali/CMakeLists.txt
automated-tests/src/dali/utc-Dali-IntPair.cpp [new file with mode: 0644]
automated-tests/src/dali/utc-Dali-Uint16Pair.cpp [deleted file]
dali/public-api/file.list
dali/public-api/math/int-pair.h [new file with mode: 0644]
dali/public-api/math/uint-16-pair.h

index 7c0ff3fbeeacd31bd2b6cf4d849550690690562e..0baf3ec37bed9201b4ccf25cf45cc6abb311c3d4 100644 (file)
@@ -38,6 +38,7 @@ SET(TC_SOURCES
         utc-Dali-Hash.cpp
         utc-Dali-HitTestAlgorithm.cpp
         utc-Dali-HoverProcessing.cpp
+        utc-Dali-IntPair.cpp
         utc-Dali-IntrusivePtr.cpp
         utc-Dali-KeyEvent.cpp
         utc-Dali-Layer.cpp
@@ -94,7 +95,6 @@ SET(TC_SOURCES
         utc-Dali-TouchProcessing.cpp
         utc-Dali-TypeRegistry.cpp
         utc-Dali-CSharp-TypeRegistry.cpp
-        utc-Dali-Uint16Pair.cpp
         utc-Dali-Vector.cpp
         utc-Dali-Vector2.cpp
         utc-Dali-Vector3.cpp
diff --git a/automated-tests/src/dali/utc-Dali-IntPair.cpp b/automated-tests/src/dali/utc-Dali-IntPair.cpp
new file mode 100644 (file)
index 0000000..2850915
--- /dev/null
@@ -0,0 +1,388 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * Licensed 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
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <dali-test-suite-utils.h>
+#include <dali/public-api/dali-core.h>
+#include <stdlib.h>
+
+#include <iostream>
+
+using namespace Dali;
+
+namespace
+{
+/// Compare a uint16_t value with an unsigned int
+void DALI_TEST_EQUALS(uint16_t value1, unsigned int value2, const char* location)
+{
+  ::DALI_TEST_EQUALS<uint16_t>(value1, static_cast<uint16_t>(value2), location);
+}
+} // unnamed namespace
+
+// class Uint16Pair
+
+int UtcDaliUint16PairConstructor01P(void)
+{
+  Uint16Pair v;
+
+  DALI_TEST_EQUALS(v.GetX(), 0u, TEST_LOCATION);
+  DALI_TEST_EQUALS(v.GetY(), 0u, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliUint16PairConstructor02P(void)
+{
+  Uint16Pair v(10u, 10u);
+
+  DALI_TEST_EQUALS(v.GetX(), 10u, TEST_LOCATION);
+  DALI_TEST_EQUALS(v.GetY(), 10u, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliUint16PairCopyConstructor(void)
+{
+  Uint16Pair u(5u, 5u);
+  Uint16Pair v(u);
+  DALI_TEST_EQUALS(v.GetX(), 5u, TEST_LOCATION);
+  DALI_TEST_EQUALS(v.GetY(), 5u, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliUint16PairMoveConstructor(void)
+{
+  Uint16Pair u(5u, 5u);
+  Uint16Pair v = std::move(u);
+  DALI_TEST_EQUALS(v.GetX(), 5u, TEST_LOCATION);
+  DALI_TEST_EQUALS(v.GetY(), 5u, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliUint16PairCopyAssignment(void)
+{
+  Uint16Pair u(5u, 5u);
+  Uint16Pair v;
+  v = u;
+  DALI_TEST_EQUALS(v.GetX(), 5u, TEST_LOCATION);
+  DALI_TEST_EQUALS(v.GetY(), 5u, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliUint16PairMoveAssignment(void)
+{
+  Uint16Pair u(5u, 5u);
+  Uint16Pair v;
+  v = std::move(u);
+  DALI_TEST_EQUALS(v.GetX(), 5u, TEST_LOCATION);
+  DALI_TEST_EQUALS(v.GetY(), 5u, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliUint16PairGetWidthP(void)
+{
+  Uint16Pair v(5u, 5u);
+  DALI_TEST_EQUALS(v.GetWidth(), 5u, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliUint16PairGetHeightP(void)
+{
+  Uint16Pair v(5u, 5u);
+  DALI_TEST_EQUALS(v.GetHeight(), 5u, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliUint16PairGetXP(void)
+{
+  Uint16Pair v(5u, 5u);
+  DALI_TEST_EQUALS(v.GetX(), 5u, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliUint16PairGetYP(void)
+{
+  Uint16Pair v(5u, 5u);
+  DALI_TEST_EQUALS(v.GetY(), 5u, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliUint16PairSetXP(void)
+{
+  Uint16Pair v(5u, 5u);
+  DALI_TEST_EQUALS(v.GetX(), 5u, TEST_LOCATION);
+  v.SetX(10u);
+  DALI_TEST_EQUALS(v.GetX(), 10u, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliUint16PairSetWidthP(void)
+{
+  Uint16Pair v(5u, 5u);
+  DALI_TEST_EQUALS(v.GetWidth(), 5u, TEST_LOCATION);
+  v.SetWidth(10u);
+  DALI_TEST_EQUALS(v.GetWidth(), 10u, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliUint16PairSetYP(void)
+{
+  Uint16Pair v(5u, 5u);
+  DALI_TEST_EQUALS(v.GetY(), 5u, TEST_LOCATION);
+  v.SetY(10u);
+  DALI_TEST_EQUALS(v.GetY(), 10u, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliUint16PairSetHeightP(void)
+{
+  Uint16Pair v(5u, 5u);
+  DALI_TEST_EQUALS(v.GetHeight(), 5u, TEST_LOCATION);
+  v.SetHeight(10u);
+  DALI_TEST_EQUALS(v.GetHeight(), 10u, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliUint16PairEqualsP(void)
+{
+  Uint16Pair v(5u, 5u);
+  Uint16Pair u(5u, 5u);
+  DALI_TEST_EQUALS(v == u, true, TEST_LOCATION);
+
+  v = Uint16Pair(5u, 4u);
+  u = Uint16Pair(5u, 5u);
+  DALI_TEST_EQUALS(v == u, false, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliUint16PairNotEqualsP(void)
+{
+  Uint16Pair v(5u, 5u);
+  Uint16Pair u(5u, 5u);
+  DALI_TEST_EQUALS(v != u, false, TEST_LOCATION);
+
+  v = Uint16Pair(5u, 4u);
+  u = Uint16Pair(5u, 5u);
+  DALI_TEST_EQUALS(v != u, true, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliUint16PairLessThanP(void)
+{
+  Uint16Pair u(5u, 5u);
+  Uint16Pair v(6u, 6u);
+  DALI_TEST_EQUALS(u < v, true, TEST_LOCATION);
+
+  u = Uint16Pair(0u, 1u);
+  v = Uint16Pair(1u, 0u);
+  DALI_TEST_EQUALS(v < u, true, TEST_LOCATION);
+
+  u = Uint16Pair(1u, 0u);
+  v = Uint16Pair(0u, 1u);
+  DALI_TEST_EQUALS(v < u, false, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliUint16PairGreaterThanP(void)
+{
+  Uint16Pair u;
+  Uint16Pair v;
+
+  u = Uint16Pair(0u, 1u);
+  v = Uint16Pair(1u, 0u);
+  DALI_TEST_EQUALS(u > v, true, TEST_LOCATION);
+
+  u = Uint16Pair(1u, 0u);
+  v = Uint16Pair(0u, 1u);
+  DALI_TEST_EQUALS(v > u, true, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliUint16PairFromFloatVecP(void)
+{
+  Dali::Vector2 v2(5.f, 5.f);
+
+  Uint16Pair u = Uint16Pair::FromFloatVec2(v2);
+  DALI_TEST_EQUALS(u.GetX(), 5u, TEST_LOCATION);
+  DALI_TEST_EQUALS(u.GetY(), 5u, TEST_LOCATION);
+
+  Dali::Vector3 v3(5.f, 5.f, 5.f);
+
+  u = Uint16Pair::FromFloatVec2(v3);
+  DALI_TEST_EQUALS(u.GetX(), 5u, TEST_LOCATION);
+  DALI_TEST_EQUALS(u.GetY(), 5u, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliUint16PairFromFloatArrayP(void)
+{
+  float array[] = {5.f, 5.f};
+
+  Uint16Pair u = Uint16Pair::FromFloatArray(array);
+  DALI_TEST_EQUALS(u.GetX(), 5u, TEST_LOCATION);
+  DALI_TEST_EQUALS(u.GetY(), 5u, TEST_LOCATION);
+
+  END_TEST;
+}
+
+// class Int32Pair
+
+int UtcDaliInt32PairConstructor01P(void)
+{
+  Int32Pair v;
+
+  DALI_TEST_EQUALS(v.GetX(), 0, TEST_LOCATION);
+  DALI_TEST_EQUALS(v.GetY(), 0, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliInt32PairConstructor02P(void)
+{
+  Int32Pair v(-10, 20);
+
+  DALI_TEST_EQUALS(v.GetX(), -10, TEST_LOCATION);
+  DALI_TEST_EQUALS(v.GetY(), 20, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliInt32PairCopyConstructor(void)
+{
+  Int32Pair u(-5, -10);
+  Int32Pair v(u);
+  DALI_TEST_EQUALS(v.GetX(), -5, TEST_LOCATION);
+  DALI_TEST_EQUALS(v.GetY(), -10, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliInt32PairMoveConstructor(void)
+{
+  Int32Pair u(5, -10);
+  Int32Pair v = std::move(u);
+  DALI_TEST_EQUALS(v.GetX(), 5, TEST_LOCATION);
+  DALI_TEST_EQUALS(v.GetY(), -10, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliInt32PairCopyAssignment(void)
+{
+  Int32Pair u(5, 10);
+  Int32Pair v;
+  v = u;
+  DALI_TEST_EQUALS(v.GetX(), 5, TEST_LOCATION);
+  DALI_TEST_EQUALS(v.GetY(), 10, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliInt32PairMoveAssignment(void)
+{
+  Int32Pair u(5, 10);
+  Int32Pair v;
+  v = std::move(u);
+  DALI_TEST_EQUALS(v.GetX(), 5, TEST_LOCATION);
+  DALI_TEST_EQUALS(v.GetY(), 10, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliInt32PairGetXP(void)
+{
+  Int32Pair v(5, 10);
+  DALI_TEST_EQUALS(v.GetX(), 5, TEST_LOCATION);
+  DALI_TEST_EQUALS(v.GetWidth(), 5, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliInt32PairGetYP(void)
+{
+  Int32Pair v(5, 10);
+  DALI_TEST_EQUALS(v.GetY(), 10, TEST_LOCATION);
+  DALI_TEST_EQUALS(v.GetHeight(), 10, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliInt32PairSetXP(void)
+{
+  Int32Pair v(5, 10);
+  DALI_TEST_EQUALS(v.GetX(), 5, TEST_LOCATION);
+  v.SetX(10);
+  DALI_TEST_EQUALS(v.GetX(), 10, TEST_LOCATION);
+  v.SetWidth(65539);
+  DALI_TEST_EQUALS(v.GetWidth(), 65539, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliInt32PairSetYP(void)
+{
+  Int32Pair v(5, 10);
+  DALI_TEST_EQUALS(v.GetY(), 10, TEST_LOCATION);
+  v.SetY(-5);
+  DALI_TEST_EQUALS(v.GetY(), -5, TEST_LOCATION);
+  v.SetHeight(65537);
+  DALI_TEST_EQUALS(v.GetHeight(), 65537, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliInt32PairEqualsP(void)
+{
+  Int32Pair v(5, 5);
+  Int32Pair u(5, 5);
+  DALI_TEST_EQUALS(v == u, true, TEST_LOCATION);
+
+  v = Int32Pair(5, 4);
+  u = Int32Pair(5, 5);
+  DALI_TEST_EQUALS(v == u, false, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliInt32PairNotEqualsP(void)
+{
+  Int32Pair v(5, 5);
+  Int32Pair u(5, 5);
+  DALI_TEST_EQUALS(v != u, false, TEST_LOCATION);
+
+  v = Int32Pair(5, 4);
+  u = Int32Pair(5, 5);
+  DALI_TEST_EQUALS(v != u, true, TEST_LOCATION);
+
+  END_TEST;
+}
diff --git a/automated-tests/src/dali/utc-Dali-Uint16Pair.cpp b/automated-tests/src/dali/utc-Dali-Uint16Pair.cpp
deleted file mode 100644 (file)
index 38a3f06..0000000
+++ /dev/null
@@ -1,254 +0,0 @@
-/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
- *
- * Licensed 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
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali-test-suite-utils.h>
-#include <dali/public-api/dali-core.h>
-#include <stdlib.h>
-
-#include <iostream>
-
-using namespace Dali;
-
-namespace
-{
-/// Compare a uint16_t value with an unsigned int
-void DALI_TEST_EQUALS(uint16_t value1, unsigned int value2, const char* location)
-{
-  ::DALI_TEST_EQUALS<uint16_t>(value1, static_cast<uint16_t>(value2), location);
-}
-} // unnamed namespace
-
-int UtcDaliUint16PairConstructor01P(void)
-{
-  Uint16Pair v;
-
-  DALI_TEST_EQUALS(v.GetX(), 0u, TEST_LOCATION);
-  DALI_TEST_EQUALS(v.GetY(), 0u, TEST_LOCATION);
-
-  END_TEST;
-}
-
-int UtcDaliUint16PairConstructor02P(void)
-{
-  Uint16Pair v(10u, 10u);
-
-  DALI_TEST_EQUALS(v.GetX(), 10u, TEST_LOCATION);
-  DALI_TEST_EQUALS(v.GetY(), 10u, TEST_LOCATION);
-
-  END_TEST;
-}
-
-int UtcDaliUint16PairCopyConstructor(void)
-{
-  Uint16Pair u(5u, 5u);
-  Uint16Pair v(u);
-  DALI_TEST_EQUALS(v.GetX(), 5u, TEST_LOCATION);
-  DALI_TEST_EQUALS(v.GetY(), 5u, TEST_LOCATION);
-
-  END_TEST;
-}
-
-int UtcDaliUint16PairMoveConstructor(void)
-{
-  Uint16Pair u(5u, 5u);
-  Uint16Pair v = std::move(u);
-  DALI_TEST_EQUALS(v.GetX(), 5u, TEST_LOCATION);
-  DALI_TEST_EQUALS(v.GetY(), 5u, TEST_LOCATION);
-
-  END_TEST;
-}
-
-int UtcDaliUint16PairCopyAssignment(void)
-{
-  Uint16Pair u(5u, 5u);
-  Uint16Pair v;
-  v = u;
-  DALI_TEST_EQUALS(v.GetX(), 5u, TEST_LOCATION);
-  DALI_TEST_EQUALS(v.GetY(), 5u, TEST_LOCATION);
-
-  END_TEST;
-}
-
-int UtcDaliUint16PairMoveAssignment(void)
-{
-  Uint16Pair u(5u, 5u);
-  Uint16Pair v;
-  v = std::move(u);
-  DALI_TEST_EQUALS(v.GetX(), 5u, TEST_LOCATION);
-  DALI_TEST_EQUALS(v.GetY(), 5u, TEST_LOCATION);
-
-  END_TEST;
-}
-
-int UtcDaliUint16PairGetWidthP(void)
-{
-  Uint16Pair v(5u, 5u);
-  DALI_TEST_EQUALS(v.GetWidth(), 5u, TEST_LOCATION);
-
-  END_TEST;
-}
-
-int UtcDaliUint16PairGetHeightP(void)
-{
-  Uint16Pair v(5u, 5u);
-  DALI_TEST_EQUALS(v.GetHeight(), 5u, TEST_LOCATION);
-
-  END_TEST;
-}
-
-int UtcDaliUint16PairGetXP(void)
-{
-  Uint16Pair v(5u, 5u);
-  DALI_TEST_EQUALS(v.GetX(), 5u, TEST_LOCATION);
-
-  END_TEST;
-}
-
-int UtcDaliUint16PairGetYP(void)
-{
-  Uint16Pair v(5u, 5u);
-  DALI_TEST_EQUALS(v.GetY(), 5u, TEST_LOCATION);
-
-  END_TEST;
-}
-
-int UtcDaliUint16PairSetXP(void)
-{
-  Uint16Pair v(5u, 5u);
-  DALI_TEST_EQUALS(v.GetX(), 5u, TEST_LOCATION);
-  v.SetX(10u);
-  DALI_TEST_EQUALS(v.GetX(), 10u, TEST_LOCATION);
-
-  END_TEST;
-}
-
-int UtcDaliUint16PairSetWidthP(void)
-{
-  Uint16Pair v(5u, 5u);
-  DALI_TEST_EQUALS(v.GetWidth(), 5u, TEST_LOCATION);
-  v.SetWidth(10u);
-  DALI_TEST_EQUALS(v.GetWidth(), 10u, TEST_LOCATION);
-
-  END_TEST;
-}
-
-int UtcDaliUint16PairSetYP(void)
-{
-  Uint16Pair v(5u, 5u);
-  DALI_TEST_EQUALS(v.GetY(), 5u, TEST_LOCATION);
-  v.SetY(10u);
-  DALI_TEST_EQUALS(v.GetY(), 10u, TEST_LOCATION);
-
-  END_TEST;
-}
-
-int UtcDaliUint16PairSetHeightP(void)
-{
-  Uint16Pair v(5u, 5u);
-  DALI_TEST_EQUALS(v.GetHeight(), 5u, TEST_LOCATION);
-  v.SetHeight(10u);
-  DALI_TEST_EQUALS(v.GetHeight(), 10u, TEST_LOCATION);
-
-  END_TEST;
-}
-
-int UtcDaliUint16PairEqualsP(void)
-{
-  Uint16Pair v(5u, 5u);
-  Uint16Pair u(5u, 5u);
-  DALI_TEST_EQUALS(v == u, true, TEST_LOCATION);
-
-  v = Uint16Pair(5u, 4u);
-  u = Uint16Pair(5u, 5u);
-  DALI_TEST_EQUALS(v == u, false, TEST_LOCATION);
-
-  END_TEST;
-}
-
-int UtcDaliUint16PairNotEqualsP(void)
-{
-  Uint16Pair v(5u, 5u);
-  Uint16Pair u(5u, 5u);
-  DALI_TEST_EQUALS(v != u, false, TEST_LOCATION);
-
-  v = Uint16Pair(5u, 4u);
-  u = Uint16Pair(5u, 5u);
-  DALI_TEST_EQUALS(v != u, true, TEST_LOCATION);
-
-  END_TEST;
-}
-
-int UtcDaliUint16PairLessThanP(void)
-{
-  Uint16Pair u(5u, 5u);
-  Uint16Pair v(6u, 6u);
-  DALI_TEST_EQUALS(u < v, true, TEST_LOCATION);
-
-  u = Uint16Pair(0u, 1u);
-  v = Uint16Pair(1u, 0u);
-  DALI_TEST_EQUALS(v < u, true, TEST_LOCATION);
-
-  u = Uint16Pair(1u, 0u);
-  v = Uint16Pair(0u, 1u);
-  DALI_TEST_EQUALS(v < u, false, TEST_LOCATION);
-
-  END_TEST;
-}
-
-int UtcDaliUint16PairGreaterThanP(void)
-{
-  Uint16Pair u;
-  Uint16Pair v;
-
-  u = Uint16Pair(0u, 1u);
-  v = Uint16Pair(1u, 0u);
-  DALI_TEST_EQUALS(u > v, true, TEST_LOCATION);
-
-  u = Uint16Pair(1u, 0u);
-  v = Uint16Pair(0u, 1u);
-  DALI_TEST_EQUALS(v > u, true, TEST_LOCATION);
-
-  END_TEST;
-}
-
-int UtcDaliUint16PairFromFloatVecP(void)
-{
-  Dali::Vector2 v2(5.f, 5.f);
-
-  Uint16Pair u = Uint16Pair::FromFloatVec2(v2);
-  DALI_TEST_EQUALS(u.GetX(), 5u, TEST_LOCATION);
-  DALI_TEST_EQUALS(u.GetY(), 5u, TEST_LOCATION);
-
-  Dali::Vector3 v3(5.f, 5.f, 5.f);
-
-  u = Uint16Pair::FromFloatVec2(v3);
-  DALI_TEST_EQUALS(u.GetX(), 5u, TEST_LOCATION);
-  DALI_TEST_EQUALS(u.GetY(), 5u, TEST_LOCATION);
-
-  END_TEST;
-}
-
-int UtcDaliUint16PairFromFloatArrayP(void)
-{
-  float array[] = {5.f, 5.f};
-
-  Uint16Pair u = Uint16Pair::FromFloatArray(array);
-  DALI_TEST_EQUALS(u.GetX(), 5u, TEST_LOCATION);
-  DALI_TEST_EQUALS(u.GetY(), 5u, TEST_LOCATION);
-
-  END_TEST;
-}
index 33c81532732dbdc12d9977a6b868a03ea2b36d12..08b1cf5f4a72716cbe6de3835eae7efa5103dc5b 100644 (file)
@@ -169,6 +169,7 @@ SET( public_api_core_math_header_files
   ${public_api_src_dir}/math/angle-axis.h
   ${public_api_src_dir}/math/compile-time-math.h
   ${public_api_src_dir}/math/degree.h
+  ${public_api_src_dir}/math/int-pair.h
   ${public_api_src_dir}/math/math-utils.h
   ${public_api_src_dir}/math/matrix.h
   ${public_api_src_dir}/math/matrix3.h
diff --git a/dali/public-api/math/int-pair.h b/dali/public-api/math/int-pair.h
new file mode 100644 (file)
index 0000000..bc87651
--- /dev/null
@@ -0,0 +1,296 @@
+#ifndef DALI_INT_PAIR_H
+#define DALI_INT_PAIR_H
+
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * Licensed 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
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <cstdint>
+#include <type_traits>
+
+// INTERNAL INCLUDES
+#include <dali/public-api/common/dali-common.h>
+#include <dali/public-api/common/type-traits.h>
+
+namespace Dali
+{
+/**
+ * @addtogroup dali_core_math
+ * @{
+ */
+
+/**
+ * @brief Simple class for passing around pairs of small integers.
+ *
+ * Use this for integer dimensions and points with limited range such as image
+ * sizes and pixel coordinates where a pair of floating point numbers is
+ * inefficient and illogical (i.e. the data is inherently integer).
+ *
+ * For example in IntPair<uint16_t>
+ * one of these can be passed in a single 32 bit integer register on
+ * common architectures.
+ *
+ * @SINCE_2_1.45
+ * @tparam Bits The number of bits. It should be 8, 16, or 32.
+ * @tparam IsSigned Determine whether we use signed integer or not.
+ */
+template<unsigned Bits, bool IsSigned, typename = std::enable_if_t<(Bits == 8 || Bits == 16 || Bits == 32)>>
+class IntPair
+{
+public:
+  // Type definition.
+
+  /**
+   * @brief Integer type for get/set access.
+   * @SINCE_2_1.45
+   */
+  using IntType = typename std::conditional<Bits == 8, typename std::conditional<IsSigned, int8_t, uint8_t>::type, typename std::conditional<Bits == 16, typename std::conditional<IsSigned, int16_t, uint16_t>::type, typename std::conditional<IsSigned, int32_t, uint32_t>::type>::type>::type;
+
+  /**
+   * @brief Unsigned integer type that will be stored.
+   * Signed integer bit shift is implementation-defined behaviour.
+   * To more safty works, we need to cast from IntType to UintType before store data.
+   * @SINCE_2_1.45
+   */
+  using UintType = typename std::conditional<Bits == 8, uint8_t, typename std::conditional<Bits == 16, uint16_t, uint32_t>::type>::type;
+
+  /**
+   * @brief 2-tuple stored integer type.
+   * @SINCE_2_1.45
+   */
+  using DataType = typename std::conditional<Bits == 8, uint16_t, typename std::conditional<Bits == 16, uint32_t, uint64_t>::type>::type;
+
+public:
+  /**
+   * @brief Default constructor for the (0, 0) tuple.
+   * @SINCE_2_1.45
+   */
+  constexpr IntPair()
+  : mData(0)
+  {
+  }
+
+  /**
+   * @brief Constructor taking separate x and y (width and height) parameters.
+   * @SINCE_2_1.45
+   * @param[in] width The width or X dimension of the tuple.
+   * @param[in] height The height or Y dimension of the tuple.
+   */
+  constexpr IntPair(IntType width, IntType height)
+  {
+    /* Do equivalent of the code below with one aligned memory access:
+     * mComponents[0] = width;
+     * mComponents[1] = height;
+     * Unit tests make sure this is equivalent.
+     **/
+    mData = (static_cast<DataType>(static_cast<UintType>(height)) << Bits) | static_cast<DataType>(static_cast<UintType>(width));
+  }
+
+  /**
+   * @brief Sets the width.
+   * @SINCE_2_1.45
+   * @param[in] width The x dimension to be stored in this 2-tuple
+   */
+  void SetWidth(IntType width)
+  {
+    mComponents[0] = width;
+  }
+
+  /**
+   * @brief Get the width.
+   * @SINCE_2_1.45
+   * @return the x dimension stored in this 2-tuple
+   */
+  IntType GetWidth() const
+  {
+    return mComponents[0];
+  }
+
+  /**
+   * @brief Sets the height.
+   * @SINCE_2_1.45
+   * @param[in] height The y dimension to be stored in this 2-tuple
+   */
+  void SetHeight(IntType height)
+  {
+    mComponents[1] = height;
+  }
+
+  /**
+   * @brief Returns the y dimension stored in this 2-tuple.
+   * @SINCE_2_1.45
+   * @return Height
+   */
+  IntType GetHeight() const
+  {
+    return mComponents[1];
+  }
+
+  /**
+   * @brief Sets the x dimension (same as width).
+   * @SINCE_2_1.45
+   * @param[in] x The x dimension to be stored in this 2-tuple
+   */
+  void SetX(IntType x)
+  {
+    mComponents[0] = x;
+  }
+
+  /**
+   * @brief Returns the x dimension stored in this 2-tuple.
+   * @SINCE_2_1.45
+   * @return X
+   */
+  IntType GetX() const
+  {
+    return mComponents[0];
+  }
+
+  /**
+   * @brief Sets the y dimension (same as height).
+   * @SINCE_2_1.45
+   * @param[in] y The y dimension to be stored in this 2-tuple
+   */
+  void SetY(IntType y)
+  {
+    mComponents[1] = y;
+  }
+
+  /**
+   * @brief Returns the y dimension stored in this 2-tuple.
+   * @SINCE_2_1.45
+   * @return Y
+   */
+  IntType GetY() const
+  {
+    return mComponents[1];
+  }
+
+  /**
+   * @brief Equality operator.
+   * @SINCE_2_1.45
+   * @param[in] rhs A reference for comparison
+   * @return True if same
+   */
+  bool operator==(const IntPair& rhs) const
+  {
+    return mData == rhs.mData;
+  }
+
+  /**
+   * @brief Inequality operator.
+   * @SINCE_2_1.45
+   * @param[in] rhs A reference for comparison
+   * @return True if different
+   */
+  bool operator!=(const IntPair& rhs) const
+  {
+    return mData != rhs.mData;
+  }
+
+  /**
+   * @brief Less than comparison operator for storing in collections (not geometrically
+   * meaningful).
+   * @SINCE_2_1.45
+   * @param[in] rhs A reference for comparison
+   * @return True if less
+   */
+  bool operator<(const IntPair& rhs) const
+  {
+    return mData < rhs.mData;
+  }
+
+  /**
+   * @brief Greater than comparison operator for storing in collections (not
+   * geometrically meaningful).
+   * @SINCE_2_1.45
+   * @param[in] rhs A reference for comparison
+   * @return True if greater
+   */
+  bool operator>(const IntPair& rhs) const
+  {
+    return mData > rhs.mData;
+  }
+
+public:
+  IntPair(const IntPair&)     = default;            ///< Default copy constructor
+  IntPair(IntPair&&) noexcept = default;            ///< Default move constructor
+  IntPair& operator=(const IntPair&) = default;     ///< Default copy assignment operator
+  IntPair& operator=(IntPair&&) noexcept = default; ///< Default move assignment operator
+
+private:
+  union
+  {
+    // Addressable view of X and Y:
+    IntType mComponents[2];
+    // Packed view of X and Y to force alignment and allow a faster copy:
+    DataType mData;
+  };
+};
+
+/**
+ * @brief Simple class for passing around pairs of signed integers.
+ *
+ * Use this for integer dimensions and points with limited range such as window
+ * position and screen coordinates where a pair of floating point numbers is
+ * inefficient and illogical (i.e. the data is inherently integer).
+ * One of these can be passed in a single 64 bit integer.
+ * @SINCE_2_1.45
+ */
+class Int32Pair : public IntPair<32, true>
+{
+public:
+  /**
+   * @brief Default constructor for the (0, 0) tuple.
+   * @SINCE_2_1.45
+   */
+  constexpr Int32Pair() = default;
+
+  /**
+   * @brief Constructor taking separate x and y (width and height) parameters.
+   * @SINCE_2_1.45
+   * @param[in] x The width or X dimension of the tuple.
+   * @param[in] y The height or Y dimension of the tuple.
+   */
+  constexpr Int32Pair(uint32_t x, uint32_t y)
+  : IntPair(x, y)
+  {
+  }
+
+public:
+  Int32Pair(const Int32Pair&)     = default;            ///< Default copy constructor
+  Int32Pair(Int32Pair&&) noexcept = default;            ///< Default move constructor
+  Int32Pair& operator=(const Int32Pair&) = default;     ///< Default copy assignment operator
+  Int32Pair& operator=(Int32Pair&&) noexcept = default; ///< Default move assignment operator
+};
+
+// Allow Int32Pair to be treated as a POD type
+template<>
+struct TypeTraits<Int32Pair> : public BasicTypes<Int32Pair>
+{
+  enum
+  {
+    IS_TRIVIAL_TYPE = true
+  };
+};
+
+/**
+ * @}
+ */
+} // namespace Dali
+
+#endif // DALI_INT_PAIR_H
index e3d9f4993270f68f7e4958646cd9af90020be84e..4b93c3d3a867180d039def30cd13ef8c681db8c2 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_UINT_16_PAIR_H
 
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  *
  */
 
-// EXTERNAL INCLUDES
-#include <stdint.h>
-
 // INTERNAL INCLUDES
-#include <dali/public-api/common/dali-common.h>
-#include <dali/public-api/common/type-traits.h>
+#include <dali/public-api/math/int-pair.h>
 
 namespace Dali
 {
@@ -42,161 +38,26 @@ namespace Dali
  * common architectures.
  * @SINCE_1_0.0
  */
-class Uint16Pair
+class Uint16Pair : public IntPair<16, false>
 {
 public:
   /**
    * @brief Default constructor for the (0, 0) tuple.
    * @SINCE_1_0.0
    */
-  Uint16Pair()
-  : mData(0)
-  {
-  }
+  constexpr Uint16Pair() = default;
 
   /**
    * @brief Constructor taking separate x and y (width and height) parameters.
    * @SINCE_1_0.0
-   * @param[in] width The width or X dimension of the tuple. Make sure it is less than 65536
-   * @param[in] height The height or Y dimension of the tuple. Make sure it is less than 65536
+   * @param[in] width The width or X dimension of the tuple. Make sure it is less than 65536.
+   * @param[in] height The height or Y dimension of the tuple. Make sure it is less than 65536.
    */
-  Uint16Pair(uint32_t width, uint32_t height)
+  constexpr Uint16Pair(uint32_t width, uint32_t height)
+  : IntPair(static_cast<uint16_t>(width), static_cast<uint16_t>(height))
   {
     DALI_ASSERT_DEBUG(width < (1u << 16) && "Width parameter not representable.");
     DALI_ASSERT_DEBUG(height < (1u << 16) && "Height parameter not representable.");
-
-    /* Do equivalent of the code below with one aligned memory access:
-     * mComponents[0] = width;
-     * mComponents[1] = height;
-     * Unit tests make sure this is equivalent.
-     **/
-    mData = (height << 16u) + width;
-  }
-
-  /**
-   * @brief Sets the width.
-   * @SINCE_1_1.13
-   * @param[in] width The x dimension to be stored in this 2-tuple
-   */
-  void SetWidth(uint16_t width)
-  {
-    mComponents[0] = width;
-  }
-
-  /**
-   * @brief Get the width.
-   * @SINCE_1_0.0
-   * @return the x dimension stored in this 2-tuple
-   */
-  uint16_t GetWidth() const
-  {
-    return mComponents[0];
-  }
-
-  /**
-   * @brief Sets the height.
-   * @SINCE_1_1.13
-   * @param[in] height The y dimension to be stored in this 2-tuple
-   */
-  void SetHeight(uint16_t height)
-  {
-    mComponents[1] = height;
-  }
-
-  /**
-   * @brief Returns the y dimension stored in this 2-tuple.
-   * @SINCE_1_0.0
-   * @return Height
-   */
-  uint16_t GetHeight() const
-  {
-    return mComponents[1];
-  }
-
-  /**
-   * @brief Sets the x dimension (same as width).
-   * @SINCE_1_1.14
-   * @param[in] x The x dimension to be stored in this 2-tuple
-   */
-  void SetX(uint16_t x)
-  {
-    mComponents[0] = x;
-  }
-
-  /**
-   * @brief Returns the x dimension stored in this 2-tuple.
-   * @SINCE_1_0.0
-   * @return X
-   */
-  uint16_t GetX() const
-  {
-    return mComponents[0];
-  }
-
-  /**
-   * @brief Sets the y dimension (same as height).
-   * @SINCE_1_1.14
-   * @param[in] y The y dimension to be stored in this 2-tuple
-   */
-  void SetY(uint16_t y)
-  {
-    mComponents[1] = y;
-  }
-
-  /**
-   * @brief Returns the y dimension stored in this 2-tuple.
-   * @SINCE_1_0.0
-   * @return Y
-   */
-  uint16_t GetY() const
-  {
-    return mComponents[1];
-  }
-
-  /**
-   * @brief Equality operator.
-   * @SINCE_1_0.0
-   * @param[in] rhs A reference for comparison
-   * @return True if same
-   */
-  bool operator==(const Uint16Pair& rhs) const
-  {
-    return mData == rhs.mData;
-  }
-
-  /**
-   * @brief Inequality operator.
-   * @SINCE_1_0.0
-   * @param[in] rhs A reference for comparison
-   * @return True if different
-   */
-  bool operator!=(const Uint16Pair& rhs) const
-  {
-    return mData != rhs.mData;
-  }
-
-  /**
-   * @brief Less than comparison operator for storing in collections (not geometrically
-   * meaningful).
-   * @SINCE_1_0.0
-   * @param[in] rhs A reference for comparison
-   * @return True if less
-   */
-  bool operator<(const Uint16Pair& rhs) const
-  {
-    return mData < rhs.mData;
-  }
-
-  /**
-   * @brief Greater than comparison operator for storing in collections (not
-   * geometrically meaningful).
-   * @SINCE_1_0.0
-   * @param[in] rhs A reference for comparison
-   * @return True if greater
-   */
-  bool operator>(const Uint16Pair& rhs) const
-  {
-    return mData > rhs.mData;
   }
 
   /**
@@ -236,19 +97,10 @@ public:
   }
 
 public:
-  Uint16Pair(const Uint16Pair&) = default;            ///< Default copy constructor
-  Uint16Pair(Uint16Pair&&)      = default;            ///< Default move constructor
-  Uint16Pair& operator=(const Uint16Pair&) = default; ///< Default copy assignment operator
-  Uint16Pair& operator=(Uint16Pair&&) = default;      ///< Default move assignment operator
-
-private:
-  union
-  {
-    // Addressable view of X and Y:
-    uint16_t mComponents[2];
-    // Packed view of X and Y to force alignment and allow a faster copy:
-    uint32_t mData;
-  };
+  Uint16Pair(const Uint16Pair&)     = default;            ///< Default copy constructor
+  Uint16Pair(Uint16Pair&&) noexcept = default;            ///< Default move constructor
+  Uint16Pair& operator=(const Uint16Pair&) = default;     ///< Default copy assignment operator
+  Uint16Pair& operator=(Uint16Pair&&) noexcept = default; ///< Default move assignment operator
 };
 
 // Allow Uint16Pair to be treated as a POD type