/src/skia/include/core/SkArc.h
Line | Count | Source (jump to first uncovered line) |
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 | 0 | const SkRect& oval() const { return fOval; } |
26 | 0 | SkScalar startAngle() const { return fStartAngle; } |
27 | 0 | SkScalar sweepAngle() const { return fSweepAngle; } |
28 | 2.14k | bool isWedge() const { return fType == Type::kWedge; } |
29 | | |
30 | 0 | friend bool operator==(const SkArc& a, const SkArc& b) { |
31 | 0 | return a.fOval == b.fOval && a.fStartAngle == b.fStartAngle && |
32 | 0 | a.fSweepAngle == b.fSweepAngle && a.fType == b.fType; |
33 | 0 | } |
34 | | |
35 | 0 | 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 | 2.78k | Type type) { |
42 | 2.78k | return SkArc(oval, startAngleDegrees, sweepAngleDegrees, type); |
43 | 2.78k | } |
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 | 743 | bool useCenter) { |
50 | 743 | return SkArc( |
51 | 743 | oval, startAngleDegrees, sweepAngleDegrees, useCenter ? Type::kWedge : Type::kArc); |
52 | 743 | } |
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 | 3.52k | : fOval(oval), fStartAngle(startAngle), fSweepAngle(sweepAngle), fType(type) {} |
67 | | }; |
68 | | |
69 | | #endif |