1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 /** 17 * @file geometryL_dda_line.h 18 * @brief DDA2 Line Algorithm 19 * @since 1.0 20 * @version 1.0 21 */ 22 23 #ifndef GRAPHIC_LITE_GEOMETRY_DDA_LINE_H 24 #define GRAPHIC_LITE_GEOMETRY_DDA_LINE_H 25 26 #include "gfx_utils/diagram/common/common_basics.h" 27 28 namespace OHOS { 29 /** 30 * @brief Dda2 algorithm 31 * @see Dda2LineInterpolator 32 * @since 1.0 33 * @version 1.0 34 */ 35 class GeometryDdaLine { 36 public: GeometryDdaLine()37 GeometryDdaLine() {} 38 GeometryDdaLine(int32_t coordinate1,int32_t coordinate2,int32_t count)39 GeometryDdaLine(int32_t coordinate1, int32_t coordinate2, int32_t count) 40 : dividCount_(count <= 0 ? 1 : count), 41 leftSideCoordinate_((coordinate2 - coordinate1) / dividCount_), 42 remainderValue_((coordinate2 - coordinate1) % dividCount_), 43 moduloOperate_(remainderValue_), 44 coordinateData_(coordinate1) 45 { 46 if (moduloOperate_ <= 0) { 47 moduloOperate_ += count; 48 remainderValue_ += count; 49 leftSideCoordinate_--; 50 } 51 moduloOperate_ -= count; 52 } 53 54 void operator++() 55 { 56 moduloOperate_ += remainderValue_; 57 coordinateData_ += leftSideCoordinate_; 58 if (moduloOperate_ > 0) { 59 moduloOperate_ -= dividCount_; 60 coordinateData_++; 61 } 62 } 63 64 void operator--() 65 { 66 if (moduloOperate_ <= remainderValue_) { 67 moduloOperate_ += dividCount_; 68 coordinateData_--; 69 } 70 moduloOperate_ -= remainderValue_; 71 coordinateData_ -= leftSideCoordinate_; 72 } 73 GetCoordinate()74 int32_t GetCoordinate() const 75 { 76 return coordinateData_; 77 } 78 79 private: 80 int32_t dividCount_; 81 int32_t leftSideCoordinate_; 82 int32_t remainderValue_; 83 int32_t moduloOperate_; 84 int32_t coordinateData_; 85 }; 86 } // namespace OHOS 87 #endif 88