WKGeometry.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. #ifndef WKGeometry_h
  26. #define WKGeometry_h
  27. #include <WebKit2/WKBase.h>
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. struct WKPoint {
  32. double x;
  33. double y;
  34. };
  35. typedef struct WKPoint WKPoint;
  36. WK_INLINE WKPoint WKPointMake(double x, double y)
  37. {
  38. WKPoint point;
  39. point.x = x;
  40. point.y = y;
  41. return point;
  42. }
  43. struct WKSize {
  44. double width;
  45. double height;
  46. };
  47. typedef struct WKSize WKSize;
  48. WK_INLINE WKSize WKSizeMake(double width, double height)
  49. {
  50. WKSize size;
  51. size.width = width;
  52. size.height = height;
  53. return size;
  54. }
  55. struct WKRect {
  56. WKPoint origin;
  57. WKSize size;
  58. };
  59. typedef struct WKRect WKRect;
  60. WK_INLINE WKRect WKRectMake(double x, double y, double width, double height)
  61. {
  62. WKRect rect;
  63. rect.origin.x = x;
  64. rect.origin.y = y;
  65. rect.size.width = width;
  66. rect.size.height = height;
  67. return rect;
  68. }
  69. WK_EXPORT WKTypeID WKSizeGetTypeID();
  70. WK_EXPORT WKTypeID WKPointGetTypeID();
  71. WK_EXPORT WKTypeID WKRectGetTypeID();
  72. WK_EXPORT WKPointRef WKPointCreate(WKPoint point);
  73. WK_EXPORT WKSizeRef WKSizeCreate(WKSize size);
  74. WK_EXPORT WKRectRef WKRectCreate(WKRect rect);
  75. WK_EXPORT WKSize WKSizeGetValue(WKSizeRef size);
  76. WK_EXPORT WKPoint WKPointGetValue(WKPointRef point);
  77. WK_EXPORT WKRect WKRectGetValue(WKRectRef rect);
  78. #ifdef __cplusplus
  79. }
  80. inline bool operator==(const WKPoint& a, const WKPoint& b)
  81. {
  82. return a.x == b.x && a.y == b.y;
  83. }
  84. #endif
  85. #endif /* WKGeometry_h */