1 /*
2 * Copyright (c) 2023 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 #include "drawing_point.h"
17
18 #include "utils/point.h"
19 #include "utils/point3.h"
20 #include "drawing_canvas_utils.h"
21
22 using namespace OHOS;
23 using namespace Rosen;
24 using namespace Drawing;
25
CastToPoint(OH_Drawing_Point * cPoint)26 static Point* CastToPoint(OH_Drawing_Point* cPoint)
27 {
28 return reinterpret_cast<Point*>(cPoint);
29 }
30
CastToPoint(const OH_Drawing_Point * cPoint)31 static const Point* CastToPoint(const OH_Drawing_Point* cPoint)
32 {
33 return reinterpret_cast<const Point*>(cPoint);
34 }
35
OH_Drawing_PointCreate(float x,float y)36 OH_Drawing_Point* OH_Drawing_PointCreate(float x, float y)
37 {
38 return (OH_Drawing_Point*)new Point(x, y);
39 }
40
OH_Drawing_PointDestroy(OH_Drawing_Point * cPoint)41 void OH_Drawing_PointDestroy(OH_Drawing_Point* cPoint)
42 {
43 if (!cPoint) {
44 return;
45 }
46 delete CastToPoint(cPoint);
47 }
48
OH_Drawing_PointGetX(const OH_Drawing_Point * cPoint,float * x)49 OH_Drawing_ErrorCode OH_Drawing_PointGetX(const OH_Drawing_Point* cPoint, float* x)
50 {
51 const Point* point = CastToPoint(cPoint);
52 if (point == nullptr || x == nullptr) {
53 return OH_DRAWING_ERROR_INVALID_PARAMETER;
54 }
55 *x = point->GetX();
56 return OH_DRAWING_SUCCESS;
57 }
58
OH_Drawing_PointGetY(const OH_Drawing_Point * cPoint,float * y)59 OH_Drawing_ErrorCode OH_Drawing_PointGetY(const OH_Drawing_Point* cPoint, float* y)
60 {
61 const Point* point = CastToPoint(cPoint);
62 if (point == nullptr || y == nullptr) {
63 return OH_DRAWING_ERROR_INVALID_PARAMETER;
64 }
65 *y = point->GetY();
66 return OH_DRAWING_SUCCESS;
67 }
68
OH_Drawing_PointSet(OH_Drawing_Point * cPoint,float x,float y)69 OH_Drawing_ErrorCode OH_Drawing_PointSet(OH_Drawing_Point* cPoint, float x, float y)
70 {
71 Point* point = CastToPoint(cPoint);
72 if (point == nullptr) {
73 return OH_DRAWING_ERROR_INVALID_PARAMETER;
74 }
75 point->Set(x, y);
76 return OH_DRAWING_SUCCESS;
77 }
78
79