Int4.mm 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //
  2. // Int4.mm
  3. //
  4. // Created by Giles Payne on 2020/02/05.
  5. //
  6. #import "Int4.h"
  7. #import "Mat.h"
  8. @implementation Int4 {
  9. cv::Vec4i native;
  10. }
  11. -(int)v0 {
  12. return native[0];
  13. }
  14. -(void)setV0:(int)v {
  15. native[0] = v;
  16. }
  17. -(int)v1 {
  18. return native[1];
  19. }
  20. -(void)setV1:(int)v {
  21. native[1] = v;
  22. }
  23. -(int)v2 {
  24. return native[2];
  25. }
  26. -(void)setV2:(int)v {
  27. native[2] = v;
  28. }
  29. -(int)v3 {
  30. return native[3];
  31. }
  32. -(void)setV3:(int)v {
  33. native[3] = v;
  34. }
  35. -(instancetype)init {
  36. return [self initWithV0:0 v1:0 v2:0 v3:0];
  37. }
  38. -(instancetype)initWithV0:(int)v0 v1:(int)v1 v2:(int)v2 v3:(int)v3 {
  39. self = [super init];
  40. if (self) {
  41. self.v0 = v0;
  42. self.v1 = v1;
  43. self.v2 = v2;
  44. self.v3 = v3;
  45. }
  46. return self;
  47. }
  48. -(instancetype)initWithVals:(NSArray<NSNumber*>*)vals {
  49. self = [super init];
  50. if (self) {
  51. [self set:vals];
  52. }
  53. return self;
  54. }
  55. +(instancetype)fromNative:(cv::Vec4i&)vec4i {
  56. return [[Int4 alloc] initWithV0:vec4i[0] v1:vec4i[1] v2:vec4i[2] v3:vec4i[3]];
  57. }
  58. -(void)set:(NSArray<NSNumber*>*)vals {
  59. self.v0 = (vals != nil && vals.count > 0) ? vals[0].intValue : 0;
  60. self.v1 = (vals != nil && vals.count > 1) ? vals[1].intValue : 0;
  61. self.v2 = (vals != nil && vals.count > 2) ? vals[2].intValue : 0;
  62. self.v3 = (vals != nil && vals.count > 3) ? vals[3].intValue : 0;
  63. }
  64. -(NSArray<NSNumber*>*)get {
  65. return @[[NSNumber numberWithFloat:native[0]], [NSNumber numberWithFloat:native[1]], [NSNumber numberWithFloat:native[2]], [NSNumber numberWithFloat:native[3]]];
  66. }
  67. - (BOOL)isEqual:(id)other {
  68. if (other == self) {
  69. return YES;
  70. } else if (![other isKindOfClass:[Int4 class]]) {
  71. return NO;
  72. } else {
  73. Int4* point = (Int4*)other;
  74. return self.v0 == point.v0 && self.v1 == point.v1 && self.v2 == point.v2 && self.v3 == point.v3;
  75. }
  76. }
  77. @end