1 | /* |
2 | * Copyright (C) 2010 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 | * THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #ifndef WKGeometry_h |
27 | #define WKGeometry_h |
28 | |
29 | #include <WebKit/WKBase.h> |
30 | |
31 | #ifdef __cplusplus |
32 | extern "C" { |
33 | #endif |
34 | |
35 | struct WKPoint { |
36 | double x; |
37 | double y; |
38 | }; |
39 | typedef struct WKPoint WKPoint; |
40 | |
41 | WK_INLINE WKPoint WKPointMake(double x, double y) |
42 | { |
43 | WKPoint point; |
44 | point.x = x; |
45 | point.y = y; |
46 | return point; |
47 | } |
48 | |
49 | struct WKSize { |
50 | double width; |
51 | double height; |
52 | }; |
53 | typedef struct WKSize WKSize; |
54 | |
55 | WK_INLINE WKSize WKSizeMake(double width, double height) |
56 | { |
57 | WKSize size; |
58 | size.width = width; |
59 | size.height = height; |
60 | return size; |
61 | } |
62 | |
63 | struct WKRect { |
64 | WKPoint origin; |
65 | WKSize size; |
66 | }; |
67 | typedef struct WKRect WKRect; |
68 | |
69 | WK_INLINE WKRect WKRectMake(double x, double y, double width, double height) |
70 | { |
71 | WKRect rect; |
72 | rect.origin.x = x; |
73 | rect.origin.y = y; |
74 | rect.size.width = width; |
75 | rect.size.height = height; |
76 | return rect; |
77 | } |
78 | |
79 | WK_EXPORT WKTypeID WKSizeGetTypeID(void); |
80 | WK_EXPORT WKTypeID WKPointGetTypeID(void); |
81 | WK_EXPORT WKTypeID WKRectGetTypeID(void); |
82 | |
83 | WK_EXPORT WKPointRef WKPointCreate(WKPoint point); |
84 | WK_EXPORT WKSizeRef WKSizeCreate(WKSize size); |
85 | WK_EXPORT WKRectRef WKRectCreate(WKRect rect); |
86 | |
87 | WK_EXPORT WKSize WKSizeGetValue(WKSizeRef size); |
88 | WK_EXPORT WKPoint WKPointGetValue(WKPointRef point); |
89 | WK_EXPORT WKRect WKRectGetValue(WKRectRef rect); |
90 | |
91 | |
92 | #ifdef __cplusplus |
93 | } |
94 | |
95 | inline bool operator==(const WKPoint& a, const WKPoint& b) |
96 | { |
97 | return a.x == b.x && a.y == b.y; |
98 | } |
99 | #endif |
100 | |
101 | #endif /* WKGeometry_h */ |
102 | |