1 /*
2  * Copyright 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *       http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef PATH_CONIC_H
18 #define PATH_CONIC_H
19 
20 #include "Path.h"
21 
22 constexpr int kMaxConicToQuadCount = 5;
23 constexpr int kMaxQuadraticCount = 1 << kMaxConicToQuadCount;
24 
25 int conicToQuadratics(
26         const Point conicPoints[3], Point *quadraticPoints, int bufferSize,
27         float weight, float tolerance
28 ) noexcept;
29 
30 class ConicConverter {
31 public:
ConicConverter()32     ConicConverter() noexcept { }
33 
34     const Point* toQuadratics(const Point points[3], float weight, float tolerance = 0.25f) noexcept;
35 
quadraticCount()36     int quadraticCount() const noexcept { return mQuadraticCount; }
37 
quadratics()38     const Point* quadratics() const noexcept {
39         return mQuadraticCount > 0 ? mStorage : nullptr;
40     }
41 
42 private:
43     int mQuadraticCount = 0;
44     Point mStorage[1 + 2 * kMaxQuadraticCount];
45 };
46 
47 struct Conic {
ConicConic48     Conic() noexcept { }
49 
ConicConic50     Conic(Point p0, Point p1, Point p2, float weight) noexcept {
51         points[0] = p0;
52         points[1] = p1;
53         points[2] = p2;
54         this->weight = weight;
55     }
56 
57     void split(Conic* __restrict__ dst) const noexcept;
58     int computeQuadraticCount(float tolerance) const noexcept;
59     int splitIntoQuadratics(Point dstPoints[], int count) const noexcept;
60 
61     Point points[3];
62     float weight;
63 };
64 
65 #endif //PATH_CONIC_H
66