You need to sign in or sign up before continuing.
draw_arc.cpp 19.2 KB
Newer Older
M
mamingshuai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "draw/draw_arc.h"
#include "common/image.h"
Z
zhangguyuan 已提交
18
#include "gfx_utils/graphic_math.h"
M
mamingshuai 已提交
19 20 21 22

namespace OHOS {
#define IS_IN_DEGREERANE(d, s, e) ((s) <= (e)) ? (((d) >= (s)) && ((d) <= (e))) : (((d) >= (s)) || ((d) <= (e)))

N
niulihua 已提交
23 24
void DrawArc::DrawImg(BufferInfo& gfxDstBuffer,
                      const Point& imgPos,
M
mamingshuai 已提交
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
                      Rect& area,
                      const Rect& invalidatedArea,
                      const Style& style,
                      uint8_t opaScale,
                      const Image* image)
{
    if (image == nullptr) {
        return;
    }
    ImageHeader header = {0};
    image->GetHeader(header);

    Rect cordsTmp;
    cordsTmp.SetPosition(imgPos.x, imgPos.y);
    cordsTmp.SetHeight(header.height);
    cordsTmp.SetWidth(header.width);
    if (area.Intersect(area, invalidatedArea)) {
N
niulihua 已提交
42
        image->DrawImage(gfxDstBuffer, cordsTmp, area, style, opaScale);
M
mamingshuai 已提交
43 44 45
    }
}

N
niulihua 已提交
46 47
void DrawArc::DrawVerLine(BufferInfo& gfxDstBuffer,
                          const Point& begin,
M
mamingshuai 已提交
48 49 50 51 52 53 54 55 56
                          const Point& imgPos,
                          const Rect& mask,
                          int16_t len,
                          const Style& style,
                          uint8_t opaScale,
                          const Image* image)
{
    Rect rect(begin.x, begin.y, begin.x, begin.y + len);
    if ((image != nullptr) && (image->GetSrcType() != IMG_SRC_UNKNOWN)) {
N
niulihua 已提交
57
        DrawImg(gfxDstBuffer, imgPos, rect, mask, style, opaScale, image);
M
mamingshuai 已提交
58
    } else {
N
niulihua 已提交
59
        DrawUtils::GetInstance()->DrawColorArea(gfxDstBuffer, rect, mask, style.lineColor_, opaScale);
M
mamingshuai 已提交
60 61 62
    }
}

N
niulihua 已提交
63 64
void DrawArc::DrawHorLine(BufferInfo& gfxDstBuffer,
                          const Point& begin,
M
mamingshuai 已提交
65 66 67 68 69 70 71 72 73
                          const Point& imgPos,
                          const Rect& mask,
                          int16_t len,
                          const Style& style,
                          uint8_t opaScale,
                          const Image* image)
{
    if ((image != nullptr) && (image->GetSrcType() != IMG_SRC_UNKNOWN)) {
        Rect rect(begin.x, begin.y, begin.x + len, begin.y);
N
niulihua 已提交
74
        DrawImg(gfxDstBuffer, imgPos, rect, mask, style, opaScale, image);
M
mamingshuai 已提交
75 76
    } else {
        if (len == 0) {
N
niulihua 已提交
77
            DrawUtils::GetInstance()->DrawPixel(gfxDstBuffer, begin.x, begin.y, mask, style.lineColor_, opaScale);
M
mamingshuai 已提交
78 79
        } else {
            Rect rect(begin.x, begin.y, begin.x + len, begin.y);
N
niulihua 已提交
80
            DrawUtils::GetInstance()->DrawColorArea(gfxDstBuffer, rect, mask, style.lineColor_, opaScale);
M
mamingshuai 已提交
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
        }
    }
}

int16_t DrawArc::GetDrawAngle(int16_t angle)
{
    if (angle < 0) {
        angle = (angle % CIRCLE_IN_DEGREE) + CIRCLE_IN_DEGREE;
    } else if (angle > CIRCLE_IN_DEGREE) {
        angle = angle % CIRCLE_IN_DEGREE;
    }
    return angle;
}

void DrawArc::GetDrawRange(int16_t& start, int16_t& end)
{
    int16_t tempAngle = GetDrawAngle(start);
    if (start == end) {
        start = tempAngle;
        end = tempAngle;
    } else if (end - start >= CIRCLE_IN_DEGREE) {
        // draw circle
        start = 0;
        end = CIRCLE_IN_DEGREE;
    } else {
        start = tempAngle;
        end = GetDrawAngle(end);
    }
}

uint16_t DrawArc::CalculateTanDegree(uint16_t x, uint16_t y)
{
    uint16_t degree = FastAtan2(x, y);
    if ((degree == QUARTER_IN_DEGREE) && (y != 0)) {
        degree--;
    }
    if ((degree == 0) && (x != 0)) {
        degree++;
    }
    return degree;
}

N
niulihua 已提交
123 124 125 126 127 128
void DrawArc::DrawCircleNoEndpoint(BufferInfo& gfxDstBuffer,
                                   ArcInfo& arcInfo,
                                   const Rect& mask,
                                   const Style& style,
                                   uint8_t opa,
                                   bool anti)
M
mamingshuai 已提交
129
{
N
niulihua 已提交
130
    DrawAxisLine(gfxDstBuffer, arcInfo, mask, style, opa);
M
mamingshuai 已提交
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181

    int16_t yStart = mask.GetTop() - arcInfo.center.y;
    int16_t yEnd = mask.GetBottom() - arcInfo.center.y;
    if ((yStart >= 0) && (yEnd >= 0)) {
        int16_t tmp = yStart;
        yStart = -yEnd;
        yEnd = -tmp;
    } else if ((yStart < 0) && (yEnd > 0)) {
        yStart = MATH_MIN(yStart, -yEnd);
        yEnd = -1;
    }
    yStart = MATH_MAX(yStart, -outRadius_) - 1;
    yEnd = MATH_MIN(yEnd, -1);

    int16_t xi;
    int16_t xLineStart = -outRadius_;
    int16_t xLineStart2 = xLineStart - 1;
    int16_t xLineStart3 = COORD_MIN;

    for (y_ = yEnd; y_ > yStart; y_--) {
        ySqr_ = static_cast<int32_t>(y_) * y_;
        bool isSetStartPot = false;
        for (xi = xLineStart2; xi < 0; xi++) {
            uint32_t currentSqr = static_cast<int32_t>(xi) * xi + ySqr_;
            if (currentSqr > outRadiusSqr_) {
                continue;
            }
            if (!isSetStartPot) {
                xLineStart2 = xi;
                lineStart_ = xi;
                if (xLineStart3 != COORD_MIN) {
                    xi = xLineStart3;
                }
                isSetStartPot = true;
            }
            if (y_ <= -inRadius_) {
                lineEnd_ = -1;
                xi = -1;
                break;
            }
            if (currentSqr < inRadiusSqr_) {
                xLineStart3 = xi - 1;
                lineEnd_ = xi - 1;
                break;
            }
        }
        if (!isSetStartPot) {
            continue;
        }
#if ENABLE_ANTIALIAS
        if (anti) {
N
niulihua 已提交
182
            DrawLineAnti(gfxDstBuffer, arcInfo, mask, style, opa);
M
mamingshuai 已提交
183 184
        }
#endif
N
niulihua 已提交
185
        DrawLineWithDegree(gfxDstBuffer, arcInfo, -lineEnd_, -lineStart_, y_, mask, style, opa, ARC_QUADRANT_ONE);
M
mamingshuai 已提交
186

N
niulihua 已提交
187
        DrawLineWithDegree(gfxDstBuffer, arcInfo, -lineEnd_, -lineStart_, -y_, mask, style, opa, ARC_QUADRANT_TWO);
M
mamingshuai 已提交
188

N
niulihua 已提交
189
        DrawLineWithDegree(gfxDstBuffer, arcInfo, lineStart_, lineEnd_, -y_, mask, style, opa, ARC_QUADRANT_THREE);
M
mamingshuai 已提交
190

N
niulihua 已提交
191
        DrawLineWithDegree(gfxDstBuffer, arcInfo, lineStart_, lineEnd_, y_, mask, style, opa, ARC_QUADRANT_FOUR);
M
mamingshuai 已提交
192 193 194
    }
}

N
niulihua 已提交
195
void DrawArc::DrawAxisLine(BufferInfo& gfxDstBuffer, ArcInfo& arcInfo, const Rect& mask, const Style& style, uint8_t opa)
M
mamingshuai 已提交
196 197 198 199 200 201
{
    int16_t lineWidth = 0;
    int16_t outRadius = outRadius_ - 1;
    int16_t inRadius = inRadius_;
    if (inRadius <= 0) {
        inRadius = 1;
N
niulihua 已提交
202
        DrawHorLine(gfxDstBuffer, arcInfo.center, arcInfo.imgPos, mask, 0, style, opa, arcInfo.imgSrc);
M
mamingshuai 已提交
203 204 205 206
    }
    lineWidth = outRadius - inRadius;

    if (isCircle_ || (IS_IN_DEGREERANE(THREE_QUARTER_IN_DEGREE, arcInfo.startAngle, arcInfo.endAngle))) {
N
niulihua 已提交
207 208
        DrawHorLine(gfxDstBuffer, Point{static_cast<int16_t>(arcInfo.center.x - outRadius), arcInfo.center.y},
                    arcInfo.imgPos, mask, lineWidth, style, opa, arcInfo.imgSrc);
M
mamingshuai 已提交
209 210 211
    }

    if (isCircle_ || (IS_IN_DEGREERANE(QUARTER_IN_DEGREE, arcInfo.startAngle, arcInfo.endAngle))) {
N
niulihua 已提交
212 213
        DrawHorLine(gfxDstBuffer, Point{static_cast<int16_t>(arcInfo.center.x + inRadius), arcInfo.center.y},
                    arcInfo.imgPos, mask, lineWidth, style, opa, arcInfo.imgSrc);
M
mamingshuai 已提交
214 215 216
    }

    if (isCircle_ || (IS_IN_DEGREERANE(0, arcInfo.startAngle, arcInfo.endAngle))) {
N
niulihua 已提交
217 218
        DrawVerLine(gfxDstBuffer, Point{arcInfo.center.x, static_cast<int16_t>(arcInfo.center.y - outRadius)},
                    arcInfo.imgPos, mask, lineWidth, style, opa, arcInfo.imgSrc);
M
mamingshuai 已提交
219 220 221
    }

    if (isCircle_ || (IS_IN_DEGREERANE(SEMICIRCLE_IN_DEGREE, arcInfo.startAngle, arcInfo.endAngle))) {
N
niulihua 已提交
222 223
        DrawVerLine(gfxDstBuffer, Point{arcInfo.center.x, static_cast<int16_t>(arcInfo.center.y + inRadius)},
                    arcInfo.imgPos, mask, lineWidth, style, opa, arcInfo.imgSrc);
M
mamingshuai 已提交
224 225 226
    }
}

N
niulihua 已提交
227 228
void DrawArc::DrawLineWithDegree(BufferInfo& gfxDstBuffer,
                                 ArcInfo& arcInfo,
M
mamingshuai 已提交
229 230 231 232 233 234 235 236 237
                                 int16_t start,
                                 int16_t end,
                                 int16_t y,
                                 const Rect& mask,
                                 const Style& style,
                                 uint8_t opaScale,
                                 uint8_t quadrant)
{
    if (isCircle_) {
N
niulihua 已提交
238 239 240
        DrawHorLine(gfxDstBuffer, Point{static_cast<int16_t>(arcInfo.center.x + start),
                    static_cast<int16_t>(arcInfo.center.y + y)}, arcInfo.imgPos,
                    mask, end - start, style, opaScale, arcInfo.imgSrc);
M
mamingshuai 已提交
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
        return;
    }
    uint16_t degreeStart = GetDegreeInQuadrant(CalculateTanDegree(MATH_ABS(start), MATH_ABS(y)), quadrant);
    uint16_t degreeEnd = GetDegreeInQuadrant(CalculateTanDegree(MATH_ABS(end), MATH_ABS(y)), quadrant);
    if (degreeStart > degreeEnd) {
        uint16_t tmp = degreeStart;
        degreeStart = degreeEnd;
        degreeEnd = tmp;
    }

    int16_t lineDegreeRet = GetDegreeRangeIntersectState(degreeStart, degreeEnd, arcInfo.startAngle, arcInfo.endAngle);
    int16_t drawEnd = 0;
    switch (lineDegreeRet) {
        case OUT_DEGREE_RANG:
            return;
        case IN_DEGREE_RANG:
N
niulihua 已提交
257
            DrawHorLine(gfxDstBuffer,
M
mamingshuai 已提交
258 259 260 261
                Point{static_cast<int16_t>(arcInfo.center.x + start), static_cast<int16_t>(arcInfo.center.y + y)},
                arcInfo.imgPos, mask, end - start, style, opaScale, arcInfo.imgSrc);
            return;
        case INTERSECT:
N
niulihua 已提交
262
            DrawLineWithDegreeInner(gfxDstBuffer, arcInfo, start, end, y, mask, style, opaScale, quadrant);
M
mamingshuai 已提交
263 264
            return;
        case DOUBLE_INTERSECT:
N
niulihua 已提交
265 266
            drawEnd = DrawLineWithDegreeInner(gfxDstBuffer, arcInfo, start, end, y, mask, style, opaScale, quadrant);
            DrawLineWithDegreeInner(gfxDstBuffer, arcInfo, drawEnd + 1, end, y, mask, style, opaScale, quadrant);
M
mamingshuai 已提交
267 268 269 270 271 272
            return;
        default:
            return;
    }
}

N
niulihua 已提交
273 274
int16_t DrawArc::DrawLineWithDegreeInner(BufferInfo& gfxDstBuffer,
                                         ArcInfo& arcInfo,
M
mamingshuai 已提交
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
                                         int16_t start,
                                         int16_t end,
                                         int16_t y,
                                         const Rect& mask,
                                         const Style& style,
                                         uint8_t opaScale,
                                         uint8_t quadrant)
{
    int16_t drawStart = COORD_MIN;
    int16_t drawEnd = COORD_MIN;
    for (int16_t xi = start; xi <= end; xi++) {
        uint16_t degreeBase = CalculateTanDegree(MATH_ABS(xi), MATH_ABS(y));
        uint16_t degree = GetDegreeInQuadrant(degreeBase, quadrant);
        if (IS_IN_DEGREERANE(degree, arcInfo.startAngle, arcInfo.endAngle)) {
            if (drawStart == COORD_MIN) {
                drawStart = xi;
            }
        } else {
            if ((drawStart != COORD_MIN) && (drawEnd == COORD_MIN)) {
                drawEnd = xi - 1;
                break;
            }
        }
    }
    if (drawEnd == COORD_MIN) {
        drawEnd = end;
    }
    if ((drawStart != COORD_MIN) && (drawEnd != COORD_MIN)) {
N
niulihua 已提交
303
        DrawHorLine(gfxDstBuffer,
M
mamingshuai 已提交
304 305 306 307 308 309 310
            Point{static_cast<int16_t>(arcInfo.center.x + drawStart), static_cast<int16_t>(arcInfo.center.y + y)},
            arcInfo.imgPos, mask, drawEnd - drawStart, style, opaScale, arcInfo.imgSrc);
    }
    return drawEnd;
}

#if ENABLE_ANTIALIAS
N
niulihua 已提交
311 312
void DrawArc::DrawLineAnti(BufferInfo& gfxDstBuffer, ArcInfo& arcInfo, const Rect& mask,
                           const Style& style, uint8_t opa)
M
mamingshuai 已提交
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
{
    outAntiStart_ = lineStart_;
    outAntiEnd_ = lineStart_;
    inAntiStart_ = lineEnd_ + 1;
    inAntiEnd_ = COORD_MIN;

    for (int16_t xAnti = lineStart_; xAnti <= lineEnd_; xAnti++) {
        uint32_t currentSqr = static_cast<int32_t>(xAnti) * xAnti + ySqr_;
        if ((currentSqr <= antiOutRadiusSqr_) || (xAnti == lineEnd_)) {
            lineStart_ = xAnti;
            outAntiEnd_ = xAnti - 1;
            break;
        }
    }

    for (int16_t xAnti = lineEnd_ + 1; xAnti <= -1; xAnti++) {
        uint32_t currentSqr = static_cast<int32_t>(xAnti) * xAnti + ySqr_;
        if ((currentSqr <= antiInRadiusSqr_) || (xAnti == -1)) {
            inAntiEnd_ = xAnti;
            break;
        }
    }

    for (int16_t xAnti = outAntiStart_; xAnti <= outAntiEnd_; xAnti++) {
        uint32_t currentSqr = static_cast<int32_t>(xAnti) * xAnti + ySqr_;
        uint8_t antiOpa =
            (((static_cast<uint64_t>(outRadius_) << 1) - 1 - (currentSqr - antiOutRadiusSqr_)) * OPA_OPAQUE) /
            ((outRadius_ << 1) - 1);
        antiOpa = (opa == OPA_OPAQUE) ? antiOpa : (static_cast<uint16_t>(antiOpa) * opa) >> SHIFT_8;
N
niulihua 已提交
342
        DrawPointAnti(gfxDstBuffer, arcInfo, xAnti, mask, style, antiOpa);
M
mamingshuai 已提交
343 344 345 346 347 348 349 350 351
    }

    for (int16_t xAnti = inAntiStart_; xAnti <= inAntiEnd_; xAnti++) {
        uint32_t currentSqr = static_cast<int32_t>(xAnti) * xAnti + ySqr_;
        if (currentSqr <= antiInRadiusSqr_) {
            break;
        }
        uint8_t antiOpa = (static_cast<uint64_t>(currentSqr - antiInRadiusSqr_) * OPA_OPAQUE) / ((inRadius_ << 1) - 1);
        antiOpa = (opa == OPA_OPAQUE) ? antiOpa : (static_cast<uint16_t>(antiOpa) * opa) >> SHIFT_8;
N
niulihua 已提交
352
        DrawPointAnti(gfxDstBuffer, arcInfo, xAnti, mask, style, antiOpa);
M
mamingshuai 已提交
353 354 355
    }
}

N
niulihua 已提交
356 357
void DrawArc::DrawPointAnti(BufferInfo& gfxDstBuffer, ArcInfo& arcInfo, int16_t x, const Rect& mask,
                            const Style& style, uint8_t antiOpa)
M
mamingshuai 已提交
358 359 360 361 362 363 364
{
    int16_t startX;
    int16_t starty;
    uint16_t degreeBase = CalculateTanDegree(MATH_ABS(x), MATH_ABS(y_));
    if (isCircle_ || (IS_IN_DEGREERANE(CIRCLE_IN_DEGREE - degreeBase, arcInfo.startAngle, arcInfo.endAngle))) {
        startX = arcInfo.center.x + x;
        starty = arcInfo.center.y + y_;
N
niulihua 已提交
365
        DrawHorLine(gfxDstBuffer, Point{startX, starty}, arcInfo.imgPos, mask, 0, style, antiOpa, arcInfo.imgSrc);
M
mamingshuai 已提交
366 367 368 369
    }
    if (isCircle_ || (IS_IN_DEGREERANE(SEMICIRCLE_IN_DEGREE + degreeBase, arcInfo.startAngle, arcInfo.endAngle))) {
        startX = arcInfo.center.x + x;
        starty = arcInfo.center.y - y_;
N
niulihua 已提交
370
        DrawHorLine(gfxDstBuffer, Point{startX, starty}, arcInfo.imgPos, mask, 0, style, antiOpa, arcInfo.imgSrc);
M
mamingshuai 已提交
371 372 373 374
    }
    if (isCircle_ || (IS_IN_DEGREERANE(degreeBase, arcInfo.startAngle, arcInfo.endAngle))) {
        startX = arcInfo.center.x - x;
        starty = arcInfo.center.y + y_;
N
niulihua 已提交
375
        DrawHorLine(gfxDstBuffer, Point{startX, starty}, arcInfo.imgPos, mask, 0, style, antiOpa, arcInfo.imgSrc);
M
mamingshuai 已提交
376 377 378 379
    }
    if (isCircle_ || (IS_IN_DEGREERANE(SEMICIRCLE_IN_DEGREE - degreeBase, arcInfo.startAngle, arcInfo.endAngle))) {
        startX = arcInfo.center.x - x;
        starty = arcInfo.center.y - y_;
N
niulihua 已提交
380
        DrawHorLine(gfxDstBuffer, Point{startX, starty}, arcInfo.imgPos, mask, 0, style, antiOpa, arcInfo.imgSrc);
M
mamingshuai 已提交
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
    }
}
#endif

uint16_t DrawArc::GetDegreeInQuadrant(uint16_t degree, uint8_t quadrant)
{
    switch (quadrant) {
        case ARC_QUADRANT_ONE:
            return degree;
        case ARC_QUADRANT_TWO:
            return SEMICIRCLE_IN_DEGREE - degree;
        case ARC_QUADRANT_THREE:
            return SEMICIRCLE_IN_DEGREE + degree;
        case ARC_QUADRANT_FOUR:
            return CIRCLE_IN_DEGREE - degree;
        default:
            return degree;
    }
}

N
niulihua 已提交
401 402
void DrawArc::Draw(BufferInfo& gfxDstBuffer, ArcInfo& arcInfo, const Rect& mask,
                   const Style& style, uint8_t opaScale, uint8_t cap)
M
mamingshuai 已提交
403 404
{
    OpacityType opa = DrawUtils::GetMixOpacity(opaScale, style.lineOpa_);
405
    if ((opa == OPA_TRANSPARENT) || (style.lineWidth_ < 1)) {
M
mamingshuai 已提交
406 407 408 409
        return;
    }

    SetArcInfo(arcInfo, style);
410 411
    if (arcInfo.startAngle != arcInfo.endAngle) {
        if ((arcInfo.imgSrc != nullptr) && (arcInfo.imgSrc->GetSrcType() != IMG_SRC_UNKNOWN)) {
412
            DrawCircleNoEndpoint(gfxDstBuffer, arcInfo, mask, style, opa, false);
413
        } else {
414
            DrawCircleNoEndpoint(gfxDstBuffer, arcInfo, mask, style, opa, true);
415
        }
M
mamingshuai 已提交
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442
    }

    if (!isCircle_ && (cap == CapType::CAP_ROUND)) {
        int16_t lineWidth = style.lineWidth_;
        if (lineWidth > arcInfo.radius) {
            lineWidth = arcInfo.radius;
        }

        ArcInfo endArcInfo = arcInfo;
        endArcInfo.startAngle = 0;
        endArcInfo.endAngle = CIRCLE_IN_DEGREE;

        int16_t outRadius = arcInfo.radius - 1;
        lineWidth--;
        /* the arc radius of the round cap should be half the line width */
        endArcInfo.radius = (static_cast<uint16_t>(lineWidth + 1) >> 1) + 1;

        /* 0.5: round up */
        float temp = (outRadius - endArcInfo.radius + 1) * Sin(arcInfo.startAngle);
        int16_t startCapX = static_cast<int16_t>((temp > 0) ? (temp + 0.5f) : (temp - 0.5f));

        temp = (outRadius - endArcInfo.radius + 1) * Sin(QUARTER_IN_DEGREE - arcInfo.startAngle);
        int16_t startCapY = static_cast<int16_t>((temp > 0) ? (temp + 0.5f) : (temp - 0.5f));

        endArcInfo.center.x += startCapX;
        endArcInfo.center.y -= startCapY;
        SetArcInfo(endArcInfo, style);
N
niulihua 已提交
443
        DrawCircleNoEndpoint(gfxDstBuffer, endArcInfo, mask, style, opa, true);
M
mamingshuai 已提交
444 445 446 447 448 449 450 451 452 453 454

        temp = (outRadius - endArcInfo.radius + 1) * Sin(arcInfo.endAngle);
        int16_t endCapX = static_cast<int16_t>((temp > 0) ? (temp + 0.5f) : (temp - 0.5f));

        temp = (outRadius - endArcInfo.radius + 1) * Sin(QUARTER_IN_DEGREE - arcInfo.endAngle);
        int16_t endCapY = static_cast<int16_t>((temp > 0) ? (temp + 0.5f) : (temp - 0.5f));

        endArcInfo.center = arcInfo.center;
        endArcInfo.center.x += endCapX;
        endArcInfo.center.y -= endCapY;
        SetArcInfo(endArcInfo, style);
N
niulihua 已提交
455
        DrawCircleNoEndpoint(gfxDstBuffer, endArcInfo, mask, style, opa, true);
M
mamingshuai 已提交
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480
    }
}

int16_t DrawArc::GetDegreeRangeIntersectState(uint16_t degreeStart, uint16_t degreeEnd, uint16_t start, uint16_t end)
{
    if (start <= end) {
        if ((degreeStart >= start) && (degreeStart <= end) && (degreeEnd >= start) && (degreeEnd <= end)) {
            return IN_DEGREE_RANG;
        } else if ((degreeEnd < start) || (degreeStart > end)) {
            return OUT_DEGREE_RANG;
        } else {
            return INTERSECT;
        }
    } else {
        if (((degreeStart >= start) && (degreeEnd >= start)) || ((degreeStart <= end) && (degreeEnd <= end))) {
            return IN_DEGREE_RANG;
        } else if ((degreeStart > end) && (degreeEnd < start)) {
            return OUT_DEGREE_RANG;
        } else if ((degreeStart <= end) && (degreeEnd >= start)) {
            return DOUBLE_INTERSECT;
        } else {
            return INTERSECT;
        }
    }
}
M
m7996 已提交
481

M
mamingshuai 已提交
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
void DrawArc::SetArcInfo(ArcInfo& arcInfo, const Style& style)
{
    outRadius_ = arcInfo.radius;
    inRadius_ = outRadius_ - style.lineWidth_;
    if (inRadius_ < 0) {
        inRadius_ = 0;
    }
    outRadiusSqr_ = outRadius_ * outRadius_;
    inRadiusSqr_ = inRadius_ * inRadius_;

    if ((arcInfo.startAngle == 0) && (arcInfo.endAngle == CIRCLE_IN_DEGREE)) {
        isCircle_ = true;
    } else {
        isCircle_ = false;
    }
M
m7996 已提交
497

M
mamingshuai 已提交
498 499 500 501 502 503 504 505 506 507
#if ENABLE_ANTIALIAS
    antiOutRadiusSqr_ = (outRadius_ - 1) * (outRadius_ - 1);
    if (inRadius_ == 0) {
        antiInRadiusSqr_ = 0;
    } else {
        antiInRadiusSqr_ = (inRadius_ - 1) * (inRadius_ - 1);
    }
#endif
}
} // namespace OHOS