updated licenses info
[platform/core/uifw/lottie-player.git] / src / vector / vdasher.cpp
index 095738b..cc4a8b8 100644 (file)
@@ -1,67 +1,31 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the LGPL License, Version 2.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     https://www.gnu.org/licenses/
+ *
+ * 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 "vdasher.h"
 #include "vbezier.h"
+#include "vline.h"
 
 V_BEGIN_NAMESPACE
 
-class VLine {
-public:
-    VLine() : mX1(0), mY1(0), mX2(0), mY2(0) {}
-    VLine(float x1, float y1, float x2, float y2)
-        : mX1(x1), mY1(y1), mX2(x2), mY2(y2)
-    {
-    }
-    VLine(const VPointF &p1, const VPointF &p2)
-        : mX1(p1.x()), mY1(p1.y()), mX2(p2.x()), mY2(p2.y())
-    {
-    }
-    float   length() const;
-    void    splitAtLength(float length, VLine &left, VLine &right) const;
-    VPointF p1() const { return VPointF(mX1, mY1); }
-    VPointF p2() const { return VPointF(mX2, mY2); }
-
-private:
-    float mX1;
-    float mY1;
-    float mX2;
-    float mY2;
-};
-
-// approximate sqrt(x*x + y*y) using alpha max plus beta min algorithm.
-// With alpha = 1, beta = 3/8, giving results with the largest error less
-// than 7% compared to the exact value.
-float VLine::length() const
-{
-    float x = mX2 - mX1;
-    float y = mY2 - mY1;
-    x = x < 0 ? -x : x;
-    y = y < 0 ? -y : y;
-    return (x > y ? x + 0.375 * y : y + 0.375 * x);
-}
-
-void VLine::splitAtLength(float lengthAt, VLine &left, VLine &right) const
-{
-    float  len = length();
-    double dx = ((mX2 - mX1) / len) * lengthAt;
-    double dy = ((mY2 - mY1) / len) * lengthAt;
-
-    left.mX1 = mX1;
-    left.mY1 = mY1;
-    left.mX2 = left.mX1 + dx;
-    left.mY2 = left.mY1 + dy;
-
-    right.mX1 = left.mX2;
-    right.mY1 = left.mY2;
-    right.mX2 = mX2;
-    right.mY2 = mY2;
-}
-
 VDasher::VDasher(const float *dashArray, int size)
 {
-    if (!(size % 2)) vCritical << "invalid dashArray format";
-
     mDashArray = reinterpret_cast<const VDasher::Dash *>(dashArray);
     mArraySize = size / 2;
-    mDashOffset = dashArray[size - 1];
+    if (size % 2)
+        mDashOffset = dashArray[size - 1];
     mIndex = 0;
     mCurrentLength = 0;
     mDiscard = false;
@@ -72,6 +36,7 @@ void VDasher::moveTo(const VPointF &p)
     mDiscard = false;
     mStartNewSegment = true;
     mCurPt = p;
+    mIndex = 0;
 
     if (!vCompare(mDashOffset, 0.0f)) {
         float totalLength = 0.0;
@@ -103,6 +68,7 @@ void VDasher::moveTo(const VPointF &p)
     } else {
         mCurrentLength = mDashArray[mIndex].length;
     }
+    if (vIsZero(mCurrentLength)) updateActiveSegment();
 }
 
 void VDasher::addLine(const VPointF &p)
@@ -128,6 +94,7 @@ void VDasher::updateActiveSegment()
         mDiscard = true;
         mCurrentLength = mDashArray[mIndex].gap;
     }
+    if (vIsZero(mCurrentLength)) updateActiveSegment();
 }
 
 void VDasher::lineTo(const VPointF &p)
@@ -208,7 +175,7 @@ void VDasher::cubicTo(const VPointF &cp1, const VPointF &cp2, const VPointF &e)
 
 VPath VDasher::dashed(const VPath &path)
 {
-    if (path.isEmpty()) return VPath();
+    if (path.empty()) return VPath();
 
     mResult = VPath();
     mIndex = 0;