Double3.mm 1.6 KB

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