Float6.mm 2.4 KB

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