6 #include "gtest/gtest.h"
29 const std::string& label) {
38 EXPECT_GE(arc_iteration.
start.
Cross(arc_iteration.
end), 0.0f);
42 const size_t steps = trigs.
size() - 1;
49 const Scalar edge_min_cross = std::sin(step_angle * 0.099f);
50 const Scalar edge_max_cross = std::sin(step_angle * 1.101f);
51 const Scalar typical_min_cross = std::sin(step_angle * 0.999f);
52 const Scalar typical_max_cross = std::sin(step_angle * 1.001f);
56 const std::string& label) ->
void {
57 EXPECT_GT(cur_vector.Cross(vector), min_cross) << label;
58 EXPECT_LT(cur_vector.Cross(vector), max_cross) << label;
65 Scalar min_cross = edge_min_cross;
66 Scalar max_cross = edge_max_cross;
68 cur_vector = arc_iteration.
start;
70 auto& quadrant = arc_iteration.
quadrants[i];
71 EXPECT_LT(quadrant.start_index, quadrant.end_index)
72 << label <<
", quadrant: " << i;
73 for (
size_t j = quadrant.start_index; j < quadrant.end_index; j++) {
74 trace(trigs[j] * quadrant.axis, min_cross, max_cross,
75 label +
", quadrant: " + std::to_string(i) +
76 ", step: " + std::to_string(j));
79 min_cross = typical_min_cross;
80 max_cross = typical_max_cross;
85 trace(arc_iteration.
end, edge_min_cross, edge_max_cross,
86 label +
" step to end");
89 void TestFullCircleArc(Degrees
start, Degrees sweep) {
91 std::to_string(
start.degrees) +
" += " + std::to_string(sweep.degrees);
96 Tessellator tessellator;
97 const auto trigs = tessellator.GetTrigsForDeviceRadius(100);
99 const auto& arc_iteration = arc.ComputeIterations(steps);
101 EXPECT_EQ(arc_iteration.
start,
Vector2(1.0f, 0.0f)) << label;
115 EXPECT_EQ(arc_iteration.
end,
Vector2(1.0f, 0.0f)) << label;
119 TestArcIterator(arc_iteration, trigs, Degrees(0), Degrees(360),
120 "Full Circle(" + label +
")");
125 TEST(ArcTest, ArcIterationsFullCircle) {
129 for (
int sweep = 360; sweep < 1080; sweep += 45) {
141 const auto& arc_iteration = arc.ComputeIterations(trigs.
GetSteps());
147 std::string label =
"Quadrant(" + std::to_string(
start.degrees) +
148 " += " + std::to_string(sweep.
degrees) +
")";
149 TestArcIterator(arc_iteration, trigs,
start, sweep, label);
153 TEST(ArcTest, ArcIterationsVariousStartAnglesNearQuadrantAxis) {
158 for (
int start_i = -1000; start_i < 1000; start_i += 5) {
159 Scalar start_degrees = start_i * 0.01f;
160 for (
int quadrant = -360; quadrant <= 360; quadrant += 90) {
165 TestArcIterator(arc_iteration, trigs,
start, sweep,
166 "Various angles(" + std::to_string(
start.degrees) +
167 " += " + std::to_string(sweep.
degrees));
172 TEST(ArcTest, ArcIterationsVariousEndAnglesNearQuadrantAxis) {
176 for (
int sweep_i = 5; sweep_i < 20000; sweep_i += 5) {
177 const Degrees sweep(sweep_i * 0.01f);
178 for (
int quadrant = -360; quadrant <= 360; quadrant += 90) {
183 TestArcIterator(arc_iteration, trigs,
start, sweep,
184 "Various angles(" + std::to_string(
start.degrees) +
185 " += " + std::to_string(sweep.
degrees));
190 TEST(ArcTest, ArcIterationsVariousTinyArcsNearQuadrantAxis) {
195 for (
int start_i = -1000; start_i < 1000; start_i += 5) {
196 Scalar start_degrees = start_i * 0.01f;
197 for (
int quadrant = -360; quadrant <= 360; quadrant += 90) {
203 TestArcIterator(arc_iteration, trigs,
start, sweep,
204 "Various angles(" + std::to_string(
start.degrees) +
205 " += " + std::to_string(sweep.
degrees));
210 TEST(ArcTest, ArcIterationsOnlyFirstQuadrant) {
214 TEST(ArcTest, ArcIterationsOnlySecondQuadrant) {
218 TEST(ArcTest, ArcIterationsOnlyThirdQuadrant) {
222 TEST(ArcTest, ArcIterationsOnlyFourthQuadrant) {
229 std::to_string(
start.degrees) +
" += " + std::to_string(sweep.
degrees);
234 const auto& arc_iteration = arc.ComputeIterations(trigs.
GetSteps());
235 size_t steps = trigs.
size() - 1;
257 TestArcIterator(arc_iteration, trigs,
start, sweep,
258 "Five quadrants(" + label +
")");
262 TEST(ArcTest, ArcIterationsAllQuadrantsFromFirst) {
266 TEST(ArcTest, ArcIterationsAllQuadrantsFromSecond) {
270 TEST(ArcTest, ArcIterationsAllQuadrantsFromThird) {
274 TEST(ArcTest, ArcIterationsAllQuadrantsFromFourth) {
A utility that generates triangles of the specified fill type given a polyline. This happens on the C...
Trigs GetTrigsForDeviceRadius(Scalar pixel_radius)
#define EXPECT_POINT_NEAR(a, b)
TEST(AllocationSizeTest, CanCreateTypedAllocations)
Iteration ComputeIterations(size_t step_count, bool simplify_360=true) const
static Vector2 CosSin(Radians radians)
constexpr Type Cross(const TPoint &p) const
constexpr static TRect MakeLTRB(Type left, Type top, Type right, Type bottom)