From: Hermet Park Date: Tue, 17 Jul 2018 10:23:22 +0000 (+0900) Subject: vector: clean up single, double-decision comparison X-Git-Tag: submit/tizen/20180917.042405~234 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F54%2F184354%2F5;p=platform%2Fcore%2Fuifw%2Flottie-player.git vector: clean up single, double-decision comparison Change-Id: I9ed37192c9c1236103aeeb7f239bbae2dabe6368 --- diff --git a/src/lottie/lottieitem.cpp b/src/lottie/lottieitem.cpp index 7274405..c4129ca 100644 --- a/src/lottie/lottieitem.cpp +++ b/src/lottie/lottieitem.cpp @@ -703,7 +703,7 @@ void LOTContentGroupItem::update(int frameNo, const VMatrix &parentMatrix, float m = mData->mTransform->matrix(frameNo) * parentMatrix; alpha *= mData->mTransform->opacity(frameNo); - if (!floatCmp(alpha, parentAlpha)) { + if (!vCompare(alpha, parentAlpha)) { newFlag |= DirtyFlagBit::Alpha; } } diff --git a/src/vector/vbezier.cpp b/src/vector/vbezier.cpp index 34e5093..c3874f4 100644 --- a/src/vector/vbezier.cpp +++ b/src/vector/vbezier.cpp @@ -48,7 +48,7 @@ VBezier::length()const chord = lineLength(x1, y1, x4, y4); - if (!floatCmp(len, chord)) { + if (!vCompare(len, chord)) { split(&left, &right); /* split in two */ length = left.length() + /* try left side */ @@ -80,7 +80,7 @@ float VBezier::tAtLength(float l) const float len = length(); float t = 1.0; const float error = 0.01; - if (l > len || floatCmp(l, len)) + if (l > len || vCompare(l, len)) return t; t *= 0.5; diff --git a/src/vector/vdasher.cpp b/src/vector/vdasher.cpp index 8c9f738..f3d7f88 100644 --- a/src/vector/vdasher.cpp +++ b/src/vector/vdasher.cpp @@ -70,7 +70,7 @@ void VDasher::moveTo(const VPointF &p) mStartPt = p; mCurPt = p; - if (!floatCmp(mDashOffset, 0.0)) { + if (!vCompare(mDashOffset, 0.0f)) { float totalLength = 0.0; for (int i = 0; i < mArraySize ; i++) { totalLength = mDashArray[i].length + mDashArray[i].gap; diff --git a/src/vector/vdrawhelper.cpp b/src/vector/vdrawhelper.cpp index a2c8932..d43198a 100644 --- a/src/vector/vdrawhelper.cpp +++ b/src/vector/vdrawhelper.cpp @@ -209,7 +209,7 @@ getRadialGradientValues(RadialGradientValues *v, const VSpanData *data) v->a = v->dr * v->dr - v->dx*v->dx - v->dy*v->dy; v->inv2a = 1 / (2 * v->a); - v->extended = !vIsNull(gradient.radial.fradius) || v->a <= 0; + v->extended = !vIsZero(gradient.radial.fradius) || v->a <= 0; } static inline int @@ -360,7 +360,7 @@ static void fetch(uint32_t *buffer, uint32_t *end, void fetch_radial_gradient(uint32_t *buffer, const Operator *op, const VSpanData *data, int y, int x, int length) { // avoid division by zero - if (vIsNull(op->radial.a)) { + if (vIsZero(op->radial.a)) { memfill32(buffer, 0, length); return; } diff --git a/src/vector/vglobal.h b/src/vector/vglobal.h index aa9e617..8984600 100644 --- a/src/vector/vglobal.h +++ b/src/vector/vglobal.h @@ -79,35 +79,29 @@ V_CONSTEXPR inline const T &vMin(const T &a, const T &b) { return (a < b) ? a : template V_CONSTEXPR inline const T &vMax(const T &a, const T &b) { return (a < b) ? b : a; } -static inline bool vCompare(double p1, double p2) -{ - return (std::abs(p1 - p2) * 1000000000000. <= vMin(std::abs(p1), std::abs(p2))); -} -static inline bool vCompare(float p1, float p2) -{ - return (std::abs(p1 - p2) * 100000.f <= vMin(std::abs(p1), std::abs(p2))); -} -static inline bool floatCmp(float p1, float p2) +static const double EPSILON_DOUBLE = 0.000000000001f; +static const float EPSILON_FLOAT = 0.000001f; + +static inline bool vCompare(double p1, double p2) { - return (std::abs(p1 - p2) * 100000.f <= fminf(std::abs(p1), std::abs(p2))); + return (std::abs(p1 - p2) < EPSILON_DOUBLE); } -static inline bool floatNull(float f) +static inline bool vCompare(float p1, float p2) { - return std::abs(f) <= 0.00001f; + return (std::abs(p1 - p2) < EPSILON_FLOAT); } - -static inline bool vIsNull(double d) +static inline bool vIsZero(float f) { - return std::abs(d) <= 0.000000000001; + return (std::abs(f) <= EPSILON_FLOAT); } -static inline bool vIsNull(float f) +static inline bool vIsZero(double f) { - return std::abs(f) <= 0.00001f; + return (std::abs(f) <= EPSILON_DOUBLE); } // Approximate sqrt(x*x + y*y) using the alpha max plus beta min algorithm. diff --git a/src/vector/vmatrix.cpp b/src/vector/vmatrix.cpp index ad5192d..2a72700 100644 --- a/src/vector/vmatrix.cpp +++ b/src/vector/vmatrix.cpp @@ -43,7 +43,7 @@ bool VMatrix::isIdentity() const bool VMatrix::isInvertible() const { - return !vIsNull(determinant()); + return !vIsZero(determinant()); } bool VMatrix::isScaling() const @@ -178,27 +178,27 @@ VMatrix::MatrixType VMatrix::type() const switch (static_cast(d->dirty)) { case MatrixType::Project: - if (!vIsNull(d->m13) || !vIsNull(d->m23) || !vIsNull(d->m33 - 1)) { + if (!vIsZero(d->m13) || !vIsZero(d->m23) || !vIsZero(d->m33 - 1)) { d->type = MatrixType::Project; break; } case MatrixType::Shear: case MatrixType::Rotate: - if (!vIsNull(d->m12) || !vIsNull(d->m21)) { + if (!vIsZero(d->m12) || !vIsZero(d->m21)) { const float dot = d->m11 * d->m12 + d->m21 * d->m22; - if (vIsNull(dot)) + if (vIsZero(dot)) d->type = MatrixType::Rotate; else d->type = MatrixType::Shear; break; } case MatrixType::Scale: - if (!vIsNull(d->m11 - 1) || !vIsNull(d->m22 - 1)) { + if (!vIsZero(d->m11 - 1) || !vIsZero(d->m22 - 1)) { d->type = MatrixType::Scale; break; } case MatrixType::Translate: - if (!vIsNull(d->mtx) || !vIsNull(d->mty)) { + if (!vIsZero(d->mtx) || !vIsZero(d->mty)) { d->type = MatrixType::Translate; break; } @@ -566,8 +566,8 @@ VMatrix VMatrix::inverted(bool *invertible) const invert.d->mty = -d->mty; break; case MatrixType::Scale: - inv = !vIsNull(d->m11); - inv &= !vIsNull(d->m22); + inv = !vIsZero(d->m11); + inv &= !vIsZero(d->m22); if (inv) { invert.d->m11 = 1. / d->m11; invert.d->m22 = 1. / d->m22; @@ -578,7 +578,7 @@ VMatrix VMatrix::inverted(bool *invertible) const default: // general case float det = determinant(); - inv = !vIsNull(det); + inv = !vIsZero(det); if (inv) invert = (adjoint() /= det); //TODO Test above line diff --git a/src/vector/vpath.cpp b/src/vector/vpath.cpp index 4df2918..ba352ee 100644 --- a/src/vector/vpath.cpp +++ b/src/vector/vpath.cpp @@ -280,8 +280,8 @@ tForArcAngle(float angle) { float radians, cos_angle, sin_angle, tc, ts, t; - if (floatCmp(angle,0.f)) return 0; - if (floatCmp(angle, 90.0)) return 1; + if (vCompare(angle,0.f)) return 0; + if (vCompare(angle, 90.0f)) return 1; radians = (angle/180) * M_PI; @@ -389,13 +389,13 @@ curvesForArc(const VRectF &rect, float startAngle, float sweepLength, } // avoid empty start segment - if (floatNull(startT - float(1))) { + if (vIsZero(startT - float(1))) { startT = 0; startSegment += delta; } // avoid empty end segment - if (floatNull(endT)) { + if (vIsZero(endT)) { endT = 1; endSegment -= delta; } @@ -403,8 +403,8 @@ curvesForArc(const VRectF &rect, float startAngle, float sweepLength, startT = tForArcAngle(startT * 90); endT = tForArcAngle(endT * 90); - const bool splitAtStart = !floatNull(startT); - const bool splitAtEnd = !floatNull(endT - float(1)); + const bool splitAtStart = !vIsZero(startT); + const bool splitAtEnd = !vIsZero(endT - float(1)); const int end = endSegment + delta; @@ -429,7 +429,7 @@ curvesForArc(const VRectF &rect, float startAngle, float sweepLength, b = VBezier::fromPoints(points[j], points[j + 1], points[j + 2], points[j + 3]); // empty arc? - if (startSegment == endSegment && floatCmp(startT, endT)) + if (startSegment == endSegment && vCompare(startT, endT)) return startPoint; if (i == startSegment) { @@ -546,7 +546,7 @@ void VPath::addRect(const VRectF &rect, VPath::Direction dir) void VPath::addRoundRect(const VRectF &rect, float rx, float ry, VPath::Direction dir) { - if (floatCmp(rx, 0.f) || floatCmp(ry, 0.f)) { + if (vCompare(rx, 0.f) || vCompare(ry, 0.f)) { addRect(rect, dir); return; } diff --git a/src/vector/vpoint.h b/src/vector/vpoint.h index 9206856..3d47514 100644 --- a/src/vector/vpoint.h +++ b/src/vector/vpoint.h @@ -37,7 +37,7 @@ private: inline const bool fuzzyCompare(const VPointF & p1, const VPointF & p2) { - return (floatCmp(p1.mx , p2.mx) && floatCmp(p1.my , p2.my)); + return (vCompare(p1.mx , p2.mx) && vCompare(p1.my , p2.my)); }