Rect2f.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. //
  2. // Rect.h
  3. //
  4. // Created by Giles Payne on 2019/10/09.
  5. //
  6. #pragma once
  7. #ifdef __cplusplus
  8. #import "opencv2/core.hpp"
  9. #else
  10. #define CV_EXPORTS
  11. #endif
  12. @class Point2f;
  13. @class Size2f;
  14. #import <Foundation/Foundation.h>
  15. NS_ASSUME_NONNULL_BEGIN
  16. /**
  17. * Represents a rectange the coordinate and dimension values of which are of type `float`
  18. */
  19. CV_EXPORTS @interface Rect2f : NSObject
  20. #pragma mark - Properties
  21. @property float x;
  22. @property float y;
  23. @property float width;
  24. @property float height;
  25. #ifdef __cplusplus
  26. @property(readonly) cv::Rect2f& nativeRef;
  27. #endif
  28. #pragma mark - Constructors
  29. - (instancetype)init;
  30. - (instancetype)initWithX:(float)x y:(float)y width:(float)width height:(float)height;
  31. - (instancetype)initWithPoint:(Point2f*)point1 point:(Point2f*)point2;
  32. - (instancetype)initWithPoint:(Point2f*)point size:(Size2f*)size;
  33. - (instancetype)initWithVals:(NSArray<NSNumber*>*)vals;
  34. #ifdef __cplusplus
  35. + (instancetype)fromNative:(cv::Rect2f&)point;
  36. #endif
  37. #pragma mark - Methods
  38. /**
  39. * Returns the top left coordinate of the rectangle
  40. */
  41. - (Point2f*)tl;
  42. /**
  43. * Returns the bottom right coordinate of the rectangle
  44. */
  45. - (Point2f*)br;
  46. /**
  47. * Returns the size of the rectangle
  48. */
  49. - (Size2f*)size;
  50. /**
  51. * Returns the area of the rectangle
  52. */
  53. - (double)area;
  54. /**
  55. * Determines if the rectangle is empty
  56. */
  57. - (BOOL)empty;
  58. /**
  59. * Determines if the rectangle contains a given point
  60. * @param point The point
  61. */
  62. - (BOOL)contains:(Point2f*)point;
  63. /**
  64. * Set the rectangle coordinates and dimensions from the values of an array
  65. * @param vals The array of values from which to set the rectangle coordinates and dimensions
  66. */
  67. - (void)set:(NSArray<NSNumber*>*)vals NS_SWIFT_NAME(set(vals:));
  68. #pragma mark - Common Methods
  69. /**
  70. * Clone object
  71. */
  72. - (Rect2f*)clone;
  73. /**
  74. * Compare for equality
  75. * @param other Object to compare
  76. */
  77. - (BOOL)isEqual:(nullable id)object;
  78. /**
  79. * Calculate hash value for this object
  80. */
  81. - (NSUInteger)hash;
  82. /**
  83. * Returns a string that describes the contents of the object
  84. */
  85. - (NSString*)description;
  86. @end
  87. NS_ASSUME_NONNULL_END