Add SkPath::isLastContourClosed()
authorfs <fs@opera.com>
Wed, 20 Jan 2016 17:51:07 +0000 (09:51 -0800)
committerCommit bot <commit-bot@chromium.org>
Wed, 20 Jan 2016 17:51:08 +0000 (09:51 -0800)
Adds a simple method for checking if the last command/verb in the
current contour is a 'close'.

This will simplify determining "closedness" for blink::Path, and aid
in the implementation of algorithms such as:

https://drafts.fxtf.org/motion-1/#motion-processing (second item in list)

GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1601103006

Review URL: https://codereview.chromium.org/1601103006

include/core/SkPath.h
src/core/SkPath.cpp
tests/PathTest.cpp

index 4ce816f..6952719 100644 (file)
@@ -187,6 +187,10 @@ public:
         return 0 == fPathRef->countVerbs();
     }
 
+    /** Return true if the last contour of this path ends with a close verb.
+     */
+    bool isLastContourClosed() const;
+
     /**
      *  Returns true if all of the points in this path are finite, meaning there
      *  are no infinities and no NaNs.
index 4af2dad..4c148c5 100644 (file)
@@ -318,6 +318,14 @@ void SkPath::rewind() {
     this->resetFields();
 }
 
+bool SkPath::isLastContourClosed() const {
+    int verbCount = fPathRef->countVerbs();
+    if (0 == verbCount) {
+        return false;
+    }
+    return kClose_Verb == fPathRef->atVerb(verbCount - 1);
+}
+
 bool SkPath::isLine(SkPoint line[2]) const {
     int verbCount = fPathRef->countVerbs();
 
index 3c4638d..1048fcd 100644 (file)
@@ -818,6 +818,23 @@ static void test_isfinite(skiatest::Reporter* reporter) {
     test_path_isfinite(reporter);
 }
 
+static void test_islastcontourclosed(skiatest::Reporter* reporter) {
+    SkPath path;
+    REPORTER_ASSERT(reporter, !path.isLastContourClosed());
+    path.moveTo(0, 0);
+    REPORTER_ASSERT(reporter, !path.isLastContourClosed());
+    path.close();
+    REPORTER_ASSERT(reporter, path.isLastContourClosed());
+    path.lineTo(100, 100);
+    REPORTER_ASSERT(reporter, !path.isLastContourClosed());
+    path.moveTo(200, 200);
+    REPORTER_ASSERT(reporter, !path.isLastContourClosed());
+    path.close();
+    REPORTER_ASSERT(reporter, path.isLastContourClosed());
+    path.moveTo(0, 0);
+    REPORTER_ASSERT(reporter, !path.isLastContourClosed());
+}
+
 // assert that we always
 //  start with a moveTo
 //  only have 1 moveTo
@@ -4005,6 +4022,7 @@ DEF_TEST(Paths, reporter) {
     test_addPoly(reporter);
     test_isfinite(reporter);
     test_isfinite_after_transform(reporter);
+    test_islastcontourclosed(reporter);
     test_arb_round_rect_is_convex(reporter);
     test_arb_zero_rad_round_rect_is_rect(reporter);
     test_addrect(reporter);