/** Set the point (vector) to be unit-length in the same direction as it
already points. If the point has a degenerate length (i.e. nearly 0)
- then return false and do nothing; otherwise return true.
+ then set it to (0,0) and return false; otherwise return true.
*/
bool normalize();
/** Set the point (vector) to be unit-length in the same direction as the
x,y params. If the vector (x,y) has a degenerate length (i.e. nearly 0)
- then return false and do nothing, otherwise return true.
+ then set it to (0,0) and return false, otherwise return true.
*/
bool setNormalize(SkScalar x, SkScalar y);
/** Scale the point (vector) to have the specified length, and return that
length. If the original length is degenerately small (nearly zero),
- do nothing and return false, otherwise return true.
+ set it to (0,0) and return false, otherwise return true.
*/
bool setLength(SkScalar length);
/** Set the point (vector) to have the specified length in the same
direction as (x,y). If the vector (x,y) has a degenerate length
- (i.e. nearly 0) then return false and do nothing, otherwise return true.
+ (i.e. nearly 0) then set it to (0,0) and return false, otherwise return true.
*/
bool setLength(SkScalar x, SkScalar y, SkScalar length);
static SkScalar Length(SkScalar x, SkScalar y);
/** Normalize pt, returning its previous length. If the prev length is too
- small (degenerate), return 0 and leave pt unchanged. This uses the same
+ small (degenerate), set pt to (0,0) and return 0. This uses the same
tolerance as CanNormalize.
Note that this method may be significantly more expensive than
*/
void SkPath::arcTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2,
SkScalar radius) {
- SkVector before, after;
+ if (radius == 0) {
+ this->lineTo(x1, y1);
+ return;
+ }
+
+ SkVector before, after;
// need to know our prev pt so we can construct tangent vectors
{
this->getLastPt(&start);
// Handle degenerate cases by adding a line to the first point and
// bailing out.
- if ((x1 == start.fX && y1 == start.fY) ||
- (x1 == x2 && y1 == y2) ||
- radius == 0) {
- this->lineTo(x1, y1);
- return;
- }
before.setNormalize(x1 - start.fX, y1 - start.fY);
after.setNormalize(x2 - x1, y2 - y1);
}
float y = pt->fY;
float mag2;
if (isLengthNearlyZero(x, y, &mag2)) {
+ pt->set(0, 0);
return 0;
}
bool SkPoint::setLength(float x, float y, float length) {
float mag2;
if (isLengthNearlyZero(x, y, &mag2)) {
+ this->set(0, 0);
return false;
}
bool SkPoint::setLengthFast(float x, float y, float length) {
float mag2;
if (isLengthNearlyZero(x, y, &mag2)) {
+ this->set(0, 0);
return false;
}
// report failure if we try to normalize them.
static void test_underflow(skiatest::Reporter* reporter) {
SkPoint pt = { 1.0e-37f, 1.0e-37f };
- SkPoint copy = pt;
+ const SkPoint empty = { 0, 0 };
REPORTER_ASSERT(reporter, 0 == SkPoint::Normalize(&pt));
- REPORTER_ASSERT(reporter, pt == copy); // pt is unchanged
+ REPORTER_ASSERT(reporter, pt == empty);
REPORTER_ASSERT(reporter, !pt.setLength(SK_Scalar1));
- REPORTER_ASSERT(reporter, pt == copy); // pt is unchanged
+ REPORTER_ASSERT(reporter, pt == empty);
}
DEF_TEST(Point, reporter) {