skia2/include/effects/SkTrimPathEffect.h
Florin Malita 0022f5cf1b [SkTrimPathEffect] Preserve wrap-around continuity
In inverted mode (Mode::kInverted), the trim result represents the
logical segment [stop..start] (wrapping around at the path's end).

We currently emit two segments [0..start] and [stop..1], in that
exact order.  This behavior breaks continuity for single closed
contour paths.

Update SkTrimPath to

1) emit the segments in the correct order ([stop..1],[0..start])

2) skip the connecting moveTo for closed paths

Bug: skia:10107
Change-Id: Icd280554ba7291c985f504793feff104df2a4a99
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/281882
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Florin Malita <fmalita@chromium.org>
2020-04-07 14:40:17 +00:00

42 lines
1.4 KiB
C++

/*
* Copyright 2018 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkTrimPathEffect_DEFINED
#define SkTrimPathEffect_DEFINED
#include "include/core/SkPathEffect.h"
class SK_API SkTrimPathEffect {
public:
enum class Mode {
kNormal, // return the subset path [start,stop]
kInverted, // return the complement/subset paths [0,start] + [stop,1]
};
/**
* Take start and stop "t" values (values between 0...1), and return a path that is that
* subset of the original path.
*
* e.g.
* Make(0.5, 1.0) --> return the 2nd half of the path
* Make(0.33333, 0.66667) --> return the middle third of the path
*
* The trim values apply to the entire path, so if it contains several contours, all of them
* are including in the calculation.
*
* startT and stopT must be 0..1 inclusive. If they are outside of that interval, they will
* be pinned to the nearest legal value. If either is NaN, null will be returned.
*
* Note: for Mode::kNormal, this will return one (logical) segment (even if it is spread
* across multiple contours). For Mode::kInverted, this will return 2 logical
* segments: stopT..1 and 0...startT, in this order.
*/
static sk_sp<SkPathEffect> Make(SkScalar startT, SkScalar stopT, Mode = Mode::kNormal);
};
#endif