1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
//
// Point2i.m
//
// Created by Giles Payne on 2019/10/09.
//
#import "Point2i.h"
#import "Rect2i.h"
#import "CVObjcUtil.h"
@implementation Point2i {
cv::Point2i native;
}
- (int)x {
return native.x;
}
- (void)setX:(int)val {
native.x = val;
}
- (int)y {
return native.y;
}
- (void)setY:(int)val {
native.y = val;
}
- (cv::Point2i&)nativeRef {
return native;
}
- (instancetype)init {
return [self initWithX:0 y:0];
}
- (instancetype)initWithX:(int)x y:(int)y {
self = [super init];
if (self) {
self.x = x;
self.y = y;
}
return self;
}
- (instancetype)initWithVals:(NSArray<NSNumber*>*)vals {
self = [super init];
if (self) {
[self set:vals];
}
return self;
}
+ (instancetype)fromNative:(cv::Point2i&)point {
return [[Point2i alloc] initWithX:point.x y:point.y];
}
- (void)update:(cv::Point2i&)point {
self.x = point.x;
self.y = point.y;
}
- (Point2i*) clone {
return [[Point2i alloc] initWithX:self.x y:self.y];
}
- (double)dot:(Point2i*)point {
return self.x * point.x + self.y * point.y;
}
- (void)set:(NSArray<NSNumber*>*)vals {
self.x = (vals != nil && vals.count > 0) ? vals[0].doubleValue : 0;
self.y = (vals != nil && vals.count > 1) ? vals[1].doubleValue : 0;
}
- (BOOL)isEqual:(id)other {
if (other == self) {
return YES;
} else if (![other isKindOfClass:[Point2i class]]) {
return NO;
} else {
Point2i* point = (Point2i*)other;
return self.x == point.x && self.y == point.y;
}
}
- (BOOL)inside:(Rect2i*)rect {
return [rect contains:self];
}
- (NSUInteger)hash {
int prime = 31;
uint32_t result = 1;
result = prime * result + self.x;
result = prime * result + self.y;
return result;
}
- (NSString *)description {
return [NSString stringWithFormat:@"Point2i {%d,%d}", self.x, self.y];
}
@end
|