| 1 |
/* |
| 2 |
* Copyright 2024 Google LLC |
| 3 |
* |
| 4 |
* Use of this source code is governed by a BSD-style license that can be |
| 5 |
* found in the LICENSE file. |
| 6 |
*/ |
| 7 |
|
| 8 |
#ifndef SkArc_DEFINED |
| 9 |
#define SkArc_DEFINED |
| 10 |
|
| 11 |
#include "include/core/SkRect.h" |
| 12 |
#include "include/core/SkScalar.h" |
| 13 |
|
| 14 |
// Represents an arc along an oval boundary, or a closed wedge of the oval. |
| 15 |
struct SkArc { |
| 16 |
enum class Type : bool { |
| 17 |
kArc, // An arc along the perimeter of the oval |
| 18 |
kWedge // A closed wedge that includes the oval's center |
| 19 |
}; |
| 20 |
|
| 21 |
SkArc() = default; |
| 22 |
SkArc(const SkArc& arc) = default; |
| 23 |
SkArc& operator=(const SkArc& arc) = default; |
| 24 |
|
| 25 |
const SkRect& oval() const { return fOval; } |
| 26 |
SkScalar startAngle() const { return fStartAngle; } |
| 27 |
SkScalar sweepAngle() const { return fSweepAngle; } |
| 28 |
bool isWedge() const { return fType == Type::kWedge; } |
| 29 |
|
| 30 |
friend bool operator==(const SkArc& a, const SkArc& b) { |
| 31 |
return a.fOval == b.fOval && a.fStartAngle == b.fStartAngle && |
| 32 |
a.fSweepAngle == b.fSweepAngle && a.fType == b.fType; |
| 33 |
} |
| 34 |
|
| 35 |
friend bool operator!=(const SkArc& a, const SkArc& b) { return !(a == b); } |
| 36 |
|
| 37 |
// Preferred factory that explicitly states which type of arc |
| 38 |
static SkArc Make(const SkRect& oval, |
| 39 |
SkScalar startAngleDegrees, |
| 40 |
SkScalar sweepAngleDegrees, |
| 41 |
Type type) { |
| 42 |
return SkArc(oval, startAngleDegrees, sweepAngleDegrees, type); |
| 43 |
} |
| 44 |
|
| 45 |
// Deprecated factory to assist with legacy code based on `useCenter` |
| 46 |
static SkArc Make(const SkRect& oval, |
| 47 |
SkScalar startAngleDegrees, |
| 48 |
SkScalar sweepAngleDegrees, |
| 49 |
bool useCenter) { |
| 50 |
return SkArc( |
| 51 |
oval, startAngleDegrees, sweepAngleDegrees, useCenter ? Type::kWedge : Type::kArc); |
| 52 |
} |
| 53 |
|
| 54 |
// Bounds of oval containing the arc. |
| 55 |
SkRect fOval = SkRect::MakeEmpty(); |
| 56 |
|
| 57 |
// Angle in degrees where the arc begins. Zero means horizontally to the right. |
| 58 |
SkScalar fStartAngle = 0; |
| 59 |
// Sweep angle in degrees; positive is clockwise. |
| 60 |
SkScalar fSweepAngle = 0; |
| 61 |
|
| 62 |
Type fType = Type::kArc; |
| 63 |
|
| 64 |
private: |
| 65 |
SkArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, Type type) |
| 66 |
: fOval(oval), fStartAngle(startAngle), fSweepAngle(sweepAngle), fType(type) {} |
| 67 |
}; |
| 68 |
|
| 69 |
#endif |