m = mData->mTransform->matrix(frameNo) * parentMatrix;
alpha *= mData->mTransform->opacity(frameNo);
- if (!floatCmp(alpha, parentAlpha)) {
+ if (!vCompare(alpha, parentAlpha)) {
newFlag |= DirtyFlagBit::Alpha;
}
}
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 */
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;
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;
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
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;
}
template <typename T>
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.
bool VMatrix::isInvertible() const
{
- return !vIsNull(determinant());
+ return !vIsZero(determinant());
}
bool VMatrix::isScaling() const
switch (static_cast<MatrixType>(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;
}
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;
default:
// general case
float det = determinant();
- inv = !vIsNull(det);
+ inv = !vIsZero(det);
if (inv)
invert = (adjoint() /= det);
//TODO Test above line
{
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;
}
// 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;
}
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;
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) {
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;
}
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));
}