CGGeometry+RSKImageCropper.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //
  2. // CGGeometry+RSKImageCropper.h
  3. //
  4. // Copyright (c) 2015 Ruslan Skorb, https://ruslanskorb.com
  5. //
  6. // Permission is hereby granted, free of charge, to any person obtaining a copy
  7. // of this software and associated documentation files (the "Software"), to deal
  8. // in the Software without restriction, including without limitation the rights
  9. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. // copies of the Software, and to permit persons to whom the Software is
  11. // furnished to do so, subject to the following conditions:
  12. //
  13. // The above copyright notice and this permission notice shall be included in
  14. // all copies or substantial portions of the Software.
  15. //
  16. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. // THE SOFTWARE.
  23. //
  24. #import <CoreGraphics/CoreGraphics.h>
  25. #import <tgmath.h>
  26. // tgmath functions aren't used on iOS when modules are enabled.
  27. // Open Radar - http://www.openradar.me/16744288
  28. // Work around this by redeclaring things here.
  29. #ifdef __tg_promote1
  30. #undef cos
  31. #define cos(__x) __tg_cos(__tg_promote1((__x))(__x))
  32. #undef sin
  33. #define sin(__x) __tg_sin(__tg_promote1((__x))(__x))
  34. #undef sqrt
  35. #define sqrt(__x) __tg_sqrt(__tg_promote1((__x))(__x))
  36. #undef fabs
  37. #define fabs(__x) __tg_fabs(__tg_promote1((__x))(__x))
  38. #undef ceil
  39. #define ceil(__x) __tg_ceil(__tg_promote1((__x))(__x))
  40. #undef floor
  41. #define floor(__x) __tg_floor(__tg_promote1((__x))(__x))
  42. #undef round
  43. #define round(__x) __tg_round(__tg_promote1((__x))(__x))
  44. #endif /* __tg_promote1 */
  45. #ifdef __tg_promote2
  46. #undef atan2
  47. #define atan2(__x, __y) __tg_atan2(__tg_promote2((__x), (__y))(__x), \
  48. __tg_promote2((__x), (__y))(__y))
  49. #undef pow
  50. #define pow(__x, __y) __tg_pow(__tg_promote2((__x), (__y))(__x), \
  51. __tg_promote2((__x), (__y))(__y))
  52. #endif /* __tg_promote2 */
  53. #ifdef CGFLOAT_IS_DOUBLE
  54. #define RSK_EPSILON DBL_EPSILON
  55. #define RSK_MIN DBL_MIN
  56. #else
  57. #define RSK_EPSILON FLT_EPSILON
  58. #define RSK_MIN FLT_MIN
  59. #endif
  60. // Line segments.
  61. struct RSKLineSegment {
  62. CGPoint start;
  63. CGPoint end;
  64. };
  65. typedef struct RSKLineSegment RSKLineSegment;
  66. // The "empty" point. This is the point returned when, for example, we
  67. // intersect two disjoint line segments. Note that the null point is not the
  68. // same as the zero point.
  69. CG_EXTERN const CGPoint RSKPointNull;
  70. // Returns the exact center point of the given rectangle.
  71. CGPoint RSKRectCenterPoint(CGRect rect);
  72. // Returns the `rect` with normalized values.
  73. CGRect RSKRectNormalize(CGRect rect);
  74. // Returns the `rect` scaled around the `point` by `sx` and `sy`.
  75. CGRect RSKRectScaleAroundPoint(CGRect rect, CGPoint point, CGFloat sx, CGFloat sy);
  76. // Returns true if `point' is the null point, false otherwise.
  77. bool RSKPointIsNull(CGPoint point);
  78. // Returns the `point` rotated around the `pivot` by `angle`.
  79. CGPoint RSKPointRotateAroundPoint(CGPoint point, CGPoint pivot, CGFloat angle);
  80. // Returns the distance between two points.
  81. CGFloat RSKPointDistance(CGPoint p1, CGPoint p2);
  82. // Make a line segment from two points `start` and `end`.
  83. RSKLineSegment RSKLineSegmentMake(CGPoint start, CGPoint end);
  84. // Returns the line segment rotated around the `pivot` by `angle`.
  85. RSKLineSegment RSKLineSegmentRotateAroundPoint(RSKLineSegment lineSegment, CGPoint pivot, CGFloat angle);
  86. // Returns the intersection of `ls1' and `ls2'. This may return a null point.
  87. CGPoint RSKLineSegmentIntersection(RSKLineSegment ls1, RSKLineSegment ls2);