Flutter Engine
The Flutter Engine
Functions
SkPathBuilder.cpp File Reference
#include "include/core/SkPathBuilder.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkRRect.h"
#include "include/private/SkPathRef.h"
#include "include/private/base/SkFloatingPoint.h"
#include "include/private/base/SkSafe32.h"
#include "src/base/SkVx.h"
#include "src/core/SkGeometry.h"
#include "src/core/SkPathEnums.h"
#include "src/core/SkPathPriv.h"
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstring>
#include <iterator>
#include <utility>

Go to the source code of this file.

Functions

static bool arc_is_lone_point (const SkRect &oval, SkScalar startAngle, SkScalar sweepAngle, SkPoint *pt)
 
static void angles_to_unit_vectors (SkScalar startAngle, SkScalar sweepAngle, SkVector *startV, SkVector *stopV, SkRotationDirection *dir)
 
static int build_arc_conics (const SkRect &oval, const SkVector &start, const SkVector &stop, SkRotationDirection dir, SkConic conics[SkConic::kMaxConicsForArc], SkPoint *singlePt)
 
static bool nearly_equal (const SkPoint &a, const SkPoint &b)
 

Function Documentation

◆ angles_to_unit_vectors()

static void angles_to_unit_vectors ( SkScalar  startAngle,
SkScalar  sweepAngle,
SkVector startV,
SkVector stopV,
SkRotationDirection dir 
)
static

Definition at line 273 of file SkPathBuilder.cpp.

274 {
277
278 startV->fY = SkScalarSinSnapToZero(startRad);
279 startV->fX = SkScalarCosSnapToZero(startRad);
280 stopV->fY = SkScalarSinSnapToZero(stopRad);
281 stopV->fX = SkScalarCosSnapToZero(stopRad);
282
283 /* If the sweep angle is nearly (but less than) 360, then due to precision
284 loss in radians-conversion and/or sin/cos, we may end up with coincident
285 vectors, which will fool SkBuildQuadArc into doing nothing (bad) instead
286 of drawing a nearly complete circle (good).
287 e.g. canvas.drawArc(0, 359.99, ...)
288 -vs- canvas.drawArc(0, 359.9, ...)
289 We try to detect this edge case, and tweak the stop vector
290 */
291 if (*startV == *stopV) {
293 if (sw < SkIntToScalar(360) && sw > SkIntToScalar(359)) {
294 // make a guess at a tiny angle (in radians) to tweak by
296 // not sure how much will be enough, so we use a loop
297 do {
298 stopRad -= deltaRad;
299 stopV->fY = SkScalarSinSnapToZero(stopRad);
300 stopV->fX = SkScalarCosSnapToZero(stopRad);
301 } while (*startV == *stopV);
302 }
303 }
305}
@ kCW_SkRotationDirection
Definition: SkGeometry.h:322
@ kCCW_SkRotationDirection
Definition: SkGeometry.h:323
#define SkDegreesToRadians(degrees)
Definition: SkScalar.h:77
#define SkScalarCopySign(x, y)
Definition: SkScalar.h:40
static float SkScalarSinSnapToZero(SkScalar radians)
Definition: SkScalar.h:115
#define SK_Scalar1
Definition: SkScalar.h:18
#define SkIntToScalar(x)
Definition: SkScalar.h:57
#define SkScalarAbs(x)
Definition: SkScalar.h:39
static float SkScalarCosSnapToZero(SkScalar radians)
Definition: SkScalar.h:120
float SkScalar
Definition: extension.cpp:12
SkScalar startAngle
Definition: SkRecords.h:250
SkScalar sweepAngle
Definition: SkRecords.h:251
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets dir
Definition: switches.h:145
float fX
x-axis value
Definition: SkPoint_impl.h:164
float fY
y-axis value
Definition: SkPoint_impl.h:165

◆ arc_is_lone_point()

static bool arc_is_lone_point ( const SkRect oval,
SkScalar  startAngle,
SkScalar  sweepAngle,
SkPoint pt 
)
static

Definition at line 250 of file SkPathBuilder.cpp.

251 {
252 if (0 == sweepAngle && (0 == startAngle || SkIntToScalar(360) == startAngle)) {
253 // Chrome uses this path to move into and out of ovals. If not
254 // treated as a special case the moves can distort the oval's
255 // bounding box (and break the circle special case).
256 pt->set(oval.fRight, oval.centerY());
257 return true;
258 } else if (0 == oval.width() && 0 == oval.height()) {
259 // Chrome will sometimes create 0 radius round rects. Having degenerate
260 // quad segments in the path prevents the path from being recognized as
261 // a rect.
262 // TODO: optimizing the case where only one of width or height is zero
263 // should also be considered. This case, however, doesn't seem to be
264 // as common as the single point case.
265 pt->set(oval.fRight, oval.fTop);
266 return true;
267 }
268 return false;
269}
SkRect oval
Definition: SkRecords.h:249
void set(float x, float y)
Definition: SkPoint_impl.h:200
SkScalar fRight
larger x-axis bounds
Definition: extension.cpp:16
constexpr float height() const
Definition: SkRect.h:769
constexpr float centerY() const
Definition: SkRect.h:785
constexpr float width() const
Definition: SkRect.h:762
SkScalar fTop
smaller y-axis bounds
Definition: extension.cpp:15

◆ build_arc_conics()

static int build_arc_conics ( const SkRect oval,
const SkVector start,
const SkVector stop,
SkRotationDirection  dir,
SkConic  conics[SkConic::kMaxConicsForArc],
SkPoint singlePt 
)
static

If this returns 0, then the caller should just line-to the singlePt, else it should ignore singlePt and append the specified number of conics.

Definition at line 311 of file SkPathBuilder.cpp.

313 {
315
317 matrix.postTranslate(oval.centerX(), oval.centerY());
318
319 int count = SkConic::BuildUnitArc(start, stop, dir, &matrix, conics);
320 if (0 == count) {
321 matrix.mapXY(stop.x(), stop.y(), singlePt);
322 }
323 return count;
324}
int count
Definition: FontMgrTest.cpp:50
#define SkScalarHalf(a)
Definition: SkScalar.h:75
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
static int BuildUnitArc(const SkVector &start, const SkVector &stop, SkRotationDirection, const SkMatrix *, SkConic conics[kMaxConicsForArc])
constexpr float y() const
Definition: SkPoint_impl.h:187
constexpr float x() const
Definition: SkPoint_impl.h:181
constexpr float centerX() const
Definition: SkRect.h:776

◆ nearly_equal()

static bool nearly_equal ( const SkPoint a,
const SkPoint b 
)
static

Definition at line 326 of file SkPathBuilder.cpp.

326 {
327 return SkScalarNearlyEqual(a.fX, b.fX)
328 && SkScalarNearlyEqual(a.fY, b.fY);
329}
static bool SkScalarNearlyEqual(SkScalar x, SkScalar y, SkScalar tolerance=SK_ScalarNearlyZero)
Definition: SkScalar.h:107
static bool b
struct MyStruct a[10]