CGGeometry+RSKImageCropper.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //
  2. // CGGeometry+RSKImageCropper.h
  3. //
  4. // Copyright (c) 2015 Ruslan Skorb, http://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. #undef cos
  30. #define cos(__x) __tg_cos(__tg_promote1((__x))(__x))
  31. #undef sin
  32. #define sin(__x) __tg_sin(__tg_promote1((__x))(__x))
  33. #undef atan2
  34. #define atan2(__x, __y) __tg_atan2(__tg_promote2((__x), (__y))(__x), \
  35. __tg_promote2((__x), (__y))(__y))
  36. #undef pow
  37. #define pow(__x, __y) __tg_pow(__tg_promote2((__x), (__y))(__x), \
  38. __tg_promote2((__x), (__y))(__y))
  39. #undef sqrt
  40. #define sqrt(__x) __tg_sqrt(__tg_promote1((__x))(__x))
  41. #undef fabs
  42. #define fabs(__x) __tg_fabs(__tg_promote1((__x))(__x))
  43. #undef ceil
  44. #define ceil(__x) __tg_ceil(__tg_promote1((__x))(__x))
  45. #undef floor
  46. #define floor(__x) __tg_floor(__tg_promote1((__x))(__x))
  47. #undef round
  48. #define round(__x) __tg_round(__tg_promote1((__x))(__x))
  49. #ifdef CGFLOAT_IS_DOUBLE
  50. #define RSK_EPSILON DBL_EPSILON
  51. #define RSK_MIN DBL_MIN
  52. #else
  53. #define RSK_EPSILON FLT_EPSILON
  54. #define RSK_MIN FLT_MIN
  55. #endif
  56. // Line segments.
  57. struct RSKLineSegment {
  58. CGPoint start;
  59. CGPoint end;
  60. };
  61. typedef struct RSKLineSegment RSKLineSegment;
  62. // The "empty" point. This is the point returned when, for example, we
  63. // intersect two disjoint line segments. Note that the null point is not the
  64. // same as the zero point.
  65. CG_EXTERN const CGPoint RSKPointNull;
  66. // Returns the exact center point of the given rectangle.
  67. CGPoint RSKRectCenterPoint(CGRect rect);
  68. // Returns the `rect` with normalized values.
  69. CGRect RSKRectNormalize(CGRect rect);
  70. // Returns the `rect` scaled around the `point` by `sx` and `sy`.
  71. CGRect RSKRectScaleAroundPoint(CGRect rect, CGPoint point, CGFloat sx, CGFloat sy);
  72. // Returns true if `point' is the null point, false otherwise.
  73. bool RSKPointIsNull(CGPoint point);
  74. // Returns the `point` rotated around the `pivot` by `angle`.
  75. CGPoint RSKPointRotateAroundPoint(CGPoint point, CGPoint pivot, CGFloat angle);
  76. // Returns the distance between two points.
  77. CGFloat RSKPointDistance(CGPoint p1, CGPoint p2);
  78. // Make a line segment from two points `start` and `end`.
  79. RSKLineSegment RSKLineSegmentMake(CGPoint start, CGPoint end);
  80. // Returns the line segment rotated around the `pivot` by `angle`.
  81. RSKLineSegment RSKLineSegmentRotateAroundPoint(RSKLineSegment lineSegment, CGPoint pivot, CGFloat angle);
  82. // Returns the intersection of `ls1' and `ls2'. This may return a null point.
  83. CGPoint RSKLineSegmentIntersection(RSKLineSegment ls1, RSKLineSegment ls2);