4 // Created by Giles Payne on 2019/10/09.
11 @implementation Point3d {
19 - (void)setX:(double)val {
27 - (void)setY:(double)val {
35 - (void)setZ:(double)val {
39 - (cv::Point3d&)nativeRef {
43 - (instancetype)init {
44 return [self initWithX:0 y:0 z:0];
47 - (instancetype)initWithX:(double)x y:(double)y z:(double)z {
57 - (instancetype)initWithPoint:(Point2d*)point {
58 return [self initWithX:point.x y:point.y z:0];
61 - (instancetype)initWithVals:(NSArray<NSNumber*>*)vals {
69 - (void)set:(NSArray<NSNumber*>*)vals {
70 self.x = (vals != nil && vals.count > 0) ? vals[0].doubleValue : 0.0;
71 self.y = (vals != nil && vals.count > 1) ? vals[1].doubleValue : 0.0;
72 self.z = (vals != nil && vals.count > 2) ? vals[2].doubleValue : 0.0;
76 return [[Point3d alloc] initWithX:self.x y:self.y z:self.z];
79 - (double)dot:(Point3d*)point {
80 return self.x * point.x + self.y * point.y + self.z * point.z;
83 - (Point3d*)cross:(Point3d*)point {
84 return [[Point3d alloc] initWithX:(self.y * point.z - self.z * point.y) y:(self.z * point.x - self.x * point.z) z:(self.x * point.y - self.y * point.x)];
87 - (BOOL)isEqual:(id)other {
90 } else if (![other isKindOfClass:[Point3d class]]) {
93 Point3d* point = (Point3d*)other;
94 return self.x == point.x && self.y == point.y && self.z == point.z;
101 int64_t temp = DOUBLE_TO_BITS(self.x);
102 result = prime * result + (int32_t) (temp ^ (temp >> 32));
103 temp = DOUBLE_TO_BITS(self.y);
104 result = prime * result + (int32_t) (temp ^ (temp >> 32));
105 temp = DOUBLE_TO_BITS(self.z);
106 result = prime * result + (int32_t) (temp ^ (temp >> 32));
110 - (NSString *)description {
111 return [NSString stringWithFormat:@"Point3 {%lf,%lf,%lf}", self.x, self.y, self.z];