/* * Copyright 2012 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file.
*/ #ifndef SkPathOpsPoint_DEFINED #define SkPathOpsPoint_DEFINED
// only used by testing voidoperator+=(const SkDVector& v) {
fX += v.fX;
fY += v.fY;
}
// only used by testing void operator-=(const SkDVector& v) {
fX -= v.fX;
fY -= v.fY;
}
// only used by testing
SkDPoint operator+(const SkDVector& v) {
SkDPoint result = *this;
result += v; return result;
}
// only used by testing
SkDPoint operator-(const SkDVector& v) {
SkDPoint result = *this;
result -= v; return result;
}
// note: this can not be implemented with // return approximately_equal(a.fY, fY) && approximately_equal(a.fX, fX); // because that will not take the magnitude of the values into account bool approximatelyDEqual(const SkDPoint& a) const { if (approximately_equal(fX, a.fX) && approximately_equal(fY, a.fY)) { returntrue;
} if (!RoughlyEqualUlps(fX, a.fX) || !RoughlyEqualUlps(fY, a.fY)) { returnfalse;
} double dist = distance(a); // OPTIMIZATION: can we compare against distSq instead ? double tiniest = std::min(std::min(std::min(fX, a.fX), fY), a.fY); double largest = std::max(std::max(std::max(fX, a.fX), fY), a.fY);
largest = std::max(largest, -tiniest); return AlmostDequalUlps(largest, largest + dist); // is the dist within ULPS tolerance?
}
bool approximatelyDEqual(const SkPoint& a) const {
SkDPoint dA;
dA.set(a); return approximatelyDEqual(dA);
}
bool approximatelyEqual(const SkDPoint& a) const { if (approximately_equal(fX, a.fX) && approximately_equal(fY, a.fY)) { returntrue;
} if (!RoughlyEqualUlps(fX, a.fX) || !RoughlyEqualUlps(fY, a.fY)) { returnfalse;
} double dist = distance(a); // OPTIMIZATION: can we compare against distSq instead ? double tiniest = std::min(std::min(std::min(fX, a.fX), fY), a.fY); double largest = std::max(std::max(std::max(fX, a.fX), fY), a.fY);
largest = std::max(largest, -tiniest); return AlmostPequalUlps(largest, largest + dist); // is the dist within ULPS tolerance?
}
bool approximatelyEqual(const SkPoint& a) const {
SkDPoint dA;
dA.set(a); return approximatelyEqual(dA);
}
staticbool ApproximatelyEqual(const SkPoint& a, const SkPoint& b) { if (approximately_equal(a.fX, b.fX) && approximately_equal(a.fY, b.fY)) { returntrue;
} if (!RoughlyEqualUlps(a.fX, b.fX) || !RoughlyEqualUlps(a.fY, b.fY)) { returnfalse;
}
SkDPoint dA, dB;
dA.set(a);
dB.set(b); double dist = dA.distance(dB); // OPTIMIZATION: can we compare against distSq instead ? float tiniest = std::min(std::min(std::min(a.fX, b.fX), a.fY), b.fY); float largest = std::max(std::max(std::max(a.fX, b.fX), a.fY), b.fY);
largest = std::max(largest, -tiniest); return AlmostDequalUlps((double) largest, largest + dist); // is dist within ULPS tolerance?
}
// only used by testing bool approximatelyZero() const { return approximately_zero(fX) && approximately_zero(fY);
}
bool roughlyEqual(const SkDPoint& a) const { if (roughly_equal(fX, a.fX) && roughly_equal(fY, a.fY)) { returntrue;
} double dist = distance(a); // OPTIMIZATION: can we compare against distSq instead ? double tiniest = std::min(std::min(std::min(fX, a.fX), fY), a.fY); double largest = std::max(std::max(std::max(fX, a.fX), fY), a.fY);
largest = std::max(largest, -tiniest); return RoughlyEqualUlps(largest, largest + dist); // is the dist within ULPS tolerance?
}
staticbool RoughlyEqual(const SkPoint& a, const SkPoint& b) { if (!RoughlyEqualUlps(a.fX, b.fX) && !RoughlyEqualUlps(a.fY, b.fY)) { returnfalse;
}
SkDPoint dA, dB;
dA.set(a);
dB.set(b); double dist = dA.distance(dB); // OPTIMIZATION: can we compare against distSq instead ? float tiniest = std::min(std::min(std::min(a.fX, b.fX), a.fY), b.fY); float largest = std::max(std::max(std::max(a.fX, b.fX), a.fY), b.fY);
largest = std::max(largest, -tiniest); return RoughlyEqualUlps((double) largest, largest + dist); // is dist within ULPS tolerance?
}
// very light weight check, should only be used for inequality check staticbool WayRoughlyEqual(const SkPoint& a, const SkPoint& b) { float largestNumber = std::max(SkTAbs(a.fX), std::max(SkTAbs(a.fY),
std::max(SkTAbs(b.fX), SkTAbs(b.fY))));
SkVector diffs = a - b; float largestDiff = std::max(diffs.fX, diffs.fY); return roughly_zero_when_compared_to(largestDiff, largestNumber);
}
// utilities callable by the user from the debugger when the implementation code is linked in void dump() const; staticvoid Dump(const SkPoint& pt); staticvoid DumpHex(const SkPoint& pt);
};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.