objc2_vision/generated/
VNGeometry.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6#[cfg(feature = "objc2-core-foundation")]
7use objc2_core_foundation::*;
8#[cfg(feature = "objc2-core-graphics")]
9use objc2_core_graphics::*;
10use objc2_foundation::*;
11
12use crate::*;
13
14extern_class!(
15    /// VNPoint represents a single, immutable, two-dimensional point in an image.
16    ///
17    /// It should be noted that VNPoint is not intended as an overall replacement of CGPoint, NSPoint or vec2, but is used by observations that need to present points which may contain additional metadata.
18    ///
19    /// See also [Apple's documentation](https://developer.apple.com/documentation/vision/vnpoint?language=objc)
20    #[unsafe(super(NSObject))]
21    #[derive(Debug, PartialEq, Eq, Hash)]
22    pub struct VNPoint;
23);
24
25unsafe impl NSCoding for VNPoint {}
26
27unsafe impl NSCopying for VNPoint {}
28
29unsafe impl CopyingHelper for VNPoint {
30    type Result = Self;
31}
32
33unsafe impl NSObjectProtocol for VNPoint {}
34
35unsafe impl NSSecureCoding for VNPoint {}
36
37impl VNPoint {
38    extern_methods!(
39        /// Returns a VNPoint object that represents the location of (0.0, 0.0).
40        #[unsafe(method(zeroPoint))]
41        #[unsafe(method_family = none)]
42        pub unsafe fn zeroPoint() -> Retained<VNPoint>;
43
44        /// Returns a new VNPoint object that is shifted by X and Y offsets of the vector.
45        ///
46        /// Parameter `vector`: The vector offset to be applied to a source point.
47        ///
48        /// Parameter `point`: The source point.
49        ///
50        /// Returns: the translated point.
51        #[unsafe(method(pointByApplyingVector:toPoint:))]
52        #[unsafe(method_family = none)]
53        pub unsafe fn pointByApplyingVector_toPoint(
54            vector: &VNVector,
55            point: &VNPoint,
56        ) -> Retained<VNPoint>;
57
58        /// Returns the Euclidean distance between two VNPoint objects.
59        #[deprecated]
60        #[unsafe(method(distanceBetweenPoint:point:))]
61        #[unsafe(method_family = none)]
62        pub unsafe fn distanceBetweenPoint_point(point1: &VNPoint, point2: &VNPoint) -> c_double;
63
64        /// Returns the Euclidean distance to another point.
65        ///
66        /// Parameter `point`: The destination point.
67        ///
68        /// Returns: the Euclidean distance between the target and specified points.
69        #[unsafe(method(distanceToPoint:))]
70        #[unsafe(method_family = none)]
71        pub unsafe fn distanceToPoint(&self, point: &VNPoint) -> c_double;
72
73        /// Initializes a VNPoint object from X and Y coordinates.
74        #[unsafe(method(initWithX:y:))]
75        #[unsafe(method_family = init)]
76        pub unsafe fn initWithX_y(
77            this: Allocated<Self>,
78            x: c_double,
79            y: c_double,
80        ) -> Retained<Self>;
81
82        #[cfg(feature = "objc2-core-foundation")]
83        /// Initializes a VNPoint object from a CGPoint.
84        #[unsafe(method(initWithLocation:))]
85        #[unsafe(method_family = init)]
86        pub unsafe fn initWithLocation(this: Allocated<Self>, location: CGPoint) -> Retained<Self>;
87
88        #[cfg(feature = "objc2-core-foundation")]
89        /// Returns the X and Y coordinates of the point, as CGPoint type, with respect to the origin of the coordinate system the point is defined in.
90        #[unsafe(method(location))]
91        #[unsafe(method_family = none)]
92        pub unsafe fn location(&self) -> CGPoint;
93
94        /// Returns the X coordinate of the point with respect to the origin of the coordinate system the point is defined in.
95        #[unsafe(method(x))]
96        #[unsafe(method_family = none)]
97        pub unsafe fn x(&self) -> c_double;
98
99        /// Returns the Y coordinate of the point with respect to the origin of the coordinate system the point is defined in.
100        #[unsafe(method(y))]
101        #[unsafe(method_family = none)]
102        pub unsafe fn y(&self) -> c_double;
103    );
104}
105
106/// Methods declared on superclass `NSObject`.
107impl VNPoint {
108    extern_methods!(
109        #[unsafe(method(init))]
110        #[unsafe(method_family = init)]
111        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
112
113        #[unsafe(method(new))]
114        #[unsafe(method_family = new)]
115        pub unsafe fn new() -> Retained<Self>;
116    );
117}
118
119extern_class!(
120    /// VNPoint3D represents a single, immutable, three-dimensional point in an image.
121    ///
122    /// It should be noted that VNPoint3D is not intended as an overall replacement of simd float4x4, but is used by observations that need to present points which may contain additional metadata.
123    ///
124    /// See also [Apple's documentation](https://developer.apple.com/documentation/vision/vnpoint3d?language=objc)
125    #[unsafe(super(NSObject))]
126    #[derive(Debug, PartialEq, Eq, Hash)]
127    pub struct VNPoint3D;
128);
129
130unsafe impl NSCoding for VNPoint3D {}
131
132unsafe impl NSCopying for VNPoint3D {}
133
134unsafe impl CopyingHelper for VNPoint3D {
135    type Result = Self;
136}
137
138unsafe impl NSObjectProtocol for VNPoint3D {}
139
140unsafe impl NSSecureCoding for VNPoint3D {}
141
142impl VNPoint3D {
143    extern_methods!(
144        #[unsafe(method(init))]
145        #[unsafe(method_family = init)]
146        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
147    );
148}
149
150/// Methods declared on superclass `NSObject`.
151impl VNPoint3D {
152    extern_methods!(
153        #[unsafe(method(new))]
154        #[unsafe(method_family = new)]
155        pub unsafe fn new() -> Retained<Self>;
156    );
157}
158
159extern_class!(
160    /// VNVector is a two-dimensional vector represented its X and Y axis projections. Once created, VNVector objects are immutable.
161    ///
162    /// See also [Apple's documentation](https://developer.apple.com/documentation/vision/vnvector?language=objc)
163    #[unsafe(super(NSObject))]
164    #[derive(Debug, PartialEq, Eq, Hash)]
165    pub struct VNVector;
166);
167
168unsafe impl NSCoding for VNVector {}
169
170unsafe impl NSCopying for VNVector {}
171
172unsafe impl CopyingHelper for VNVector {
173    type Result = Self;
174}
175
176unsafe impl NSObjectProtocol for VNVector {}
177
178unsafe impl NSSecureCoding for VNVector {}
179
180impl VNVector {
181    extern_methods!(
182        /// Returns a VNVector object with zero length. The theta for zeroVector is not defined (NaN).
183        #[unsafe(method(zeroVector))]
184        #[unsafe(method_family = none)]
185        pub unsafe fn zeroVector() -> Retained<VNVector>;
186
187        /// Returns a vector that is normalized by preserving direction, such as |v|, or vector length = 1.0.
188        #[unsafe(method(unitVectorForVector:))]
189        #[unsafe(method_family = none)]
190        pub unsafe fn unitVectorForVector(vector: &VNVector) -> Retained<VNVector>;
191
192        /// Returns a vector that whose X and Y projections multiplied by a scalar value.
193        #[unsafe(method(vectorByMultiplyingVector:byScalar:))]
194        #[unsafe(method_family = none)]
195        pub unsafe fn vectorByMultiplyingVector_byScalar(
196            vector: &VNVector,
197            scalar: c_double,
198        ) -> Retained<VNVector>;
199
200        /// Adds two vectors v1 and v2 and returns a resulting vector v, such as v = v1 + v2.
201        #[unsafe(method(vectorByAddingVector:toVector:))]
202        #[unsafe(method_family = none)]
203        pub unsafe fn vectorByAddingVector_toVector(
204            v1: &VNVector,
205            v2: &VNVector,
206        ) -> Retained<VNVector>;
207
208        /// Substructs vector v1 from v2 and returns a resulting vector v, such as v = v2 - v1.
209        #[unsafe(method(vectorBySubtractingVector:fromVector:))]
210        #[unsafe(method_family = none)]
211        pub unsafe fn vectorBySubtractingVector_fromVector(
212            v1: &VNVector,
213            v2: &VNVector,
214        ) -> Retained<VNVector>;
215
216        /// Caclulates a dot product (aka 'scalar product' or 'inner product') of two vectors v1 and v2 and returns dot product value.
217        #[unsafe(method(dotProductOfVector:vector:))]
218        #[unsafe(method_family = none)]
219        pub unsafe fn dotProductOfVector_vector(v1: &VNVector, v2: &VNVector) -> c_double;
220
221        /// Initializes a vector in Cartesian Coordinate space, using its X and Y axis projections.
222        #[unsafe(method(initWithXComponent:yComponent:))]
223        #[unsafe(method_family = init)]
224        pub unsafe fn initWithXComponent_yComponent(
225            this: Allocated<Self>,
226            x: c_double,
227            y: c_double,
228        ) -> Retained<Self>;
229
230        /// Initializes a vector in polar coordinate space, using R and Theta (radians), where R is the length of the vector and
231        /// Theta is the ange that the vector forms with the positive direction of X axis.
232        #[unsafe(method(initWithR:theta:))]
233        #[unsafe(method_family = init)]
234        pub unsafe fn initWithR_theta(
235            this: Allocated<Self>,
236            r: c_double,
237            theta: c_double,
238        ) -> Retained<Self>;
239
240        /// Initializes a vector in Cartesian Coordinate space, using two VNPoints - the head and the tail of the vector.
241        #[unsafe(method(initWithVectorHead:tail:))]
242        #[unsafe(method_family = init)]
243        pub unsafe fn initWithVectorHead_tail(
244            this: Allocated<Self>,
245            head: &VNPoint,
246            tail: &VNPoint,
247        ) -> Retained<Self>;
248
249        /// Signed projection on X-axis, or X component of the vector. Sign determines direction the vector is facing in X direction.
250        #[unsafe(method(x))]
251        #[unsafe(method_family = none)]
252        pub unsafe fn x(&self) -> c_double;
253
254        /// Signed projection on Y-axis, or Y component of the vector. Sign determines direction the vector is facing in Y direction.
255        #[unsafe(method(y))]
256        #[unsafe(method_family = none)]
257        pub unsafe fn y(&self) -> c_double;
258
259        /// Radius, or absolute value, or length of the vector.
260        #[unsafe(method(r))]
261        #[unsafe(method_family = none)]
262        pub unsafe fn r(&self) -> c_double;
263
264        /// Angle between the vector direction and positive direction of X axis.
265        #[unsafe(method(theta))]
266        #[unsafe(method_family = none)]
267        pub unsafe fn theta(&self) -> c_double;
268
269        /// Returns a length, or absolute value, of the vector.
270        #[unsafe(method(length))]
271        #[unsafe(method_family = none)]
272        pub unsafe fn length(&self) -> c_double;
273
274        /// Returns a length ^ 2 of a vector.
275        #[unsafe(method(squaredLength))]
276        #[unsafe(method_family = none)]
277        pub unsafe fn squaredLength(&self) -> c_double;
278    );
279}
280
281/// Methods declared on superclass `NSObject`.
282impl VNVector {
283    extern_methods!(
284        #[unsafe(method(init))]
285        #[unsafe(method_family = init)]
286        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
287
288        #[unsafe(method(new))]
289        #[unsafe(method_family = new)]
290        pub unsafe fn new() -> Retained<Self>;
291    );
292}
293
294extern_class!(
295    /// VNCircle is two-dimensional circle represented by the center point 'center' and its radius 'radius'. Once created, VNCircle objects are immutable.
296    ///
297    /// See also [Apple's documentation](https://developer.apple.com/documentation/vision/vncircle?language=objc)
298    #[unsafe(super(NSObject))]
299    #[derive(Debug, PartialEq, Eq, Hash)]
300    pub struct VNCircle;
301);
302
303unsafe impl NSCoding for VNCircle {}
304
305unsafe impl NSCopying for VNCircle {}
306
307unsafe impl CopyingHelper for VNCircle {
308    type Result = Self;
309}
310
311unsafe impl NSObjectProtocol for VNCircle {}
312
313unsafe impl NSSecureCoding for VNCircle {}
314
315impl VNCircle {
316    extern_methods!(
317        /// Returns a VNCircle object with center at the Origin [0.0; 0.0] and zero radius.
318        #[unsafe(method(zeroCircle))]
319        #[unsafe(method_family = none)]
320        pub unsafe fn zeroCircle() -> Retained<VNCircle>;
321
322        /// Initializes VNCircle object with given circle center and circle radius.
323        #[unsafe(method(initWithCenter:radius:))]
324        #[unsafe(method_family = init)]
325        pub unsafe fn initWithCenter_radius(
326            this: Allocated<Self>,
327            center: &VNPoint,
328            radius: c_double,
329        ) -> Retained<Self>;
330
331        /// Initializes VNCircle object with given circle center and circle diameter.
332        #[unsafe(method(initWithCenter:diameter:))]
333        #[unsafe(method_family = init)]
334        pub unsafe fn initWithCenter_diameter(
335            this: Allocated<Self>,
336            center: &VNPoint,
337            diameter: c_double,
338        ) -> Retained<Self>;
339
340        /// Returns YES if the point is inside the circle, including the boundary.
341        #[unsafe(method(containsPoint:))]
342        #[unsafe(method_family = none)]
343        pub unsafe fn containsPoint(&self, point: &VNPoint) -> bool;
344
345        /// Returns YES if the point is within the ring bound by two circles [radius - delta; radius + delta].
346        #[unsafe(method(containsPoint:inCircumferentialRingOfWidth:))]
347        #[unsafe(method_family = none)]
348        pub unsafe fn containsPoint_inCircumferentialRingOfWidth(
349            &self,
350            point: &VNPoint,
351            ring_width: c_double,
352        ) -> bool;
353
354        /// Returns circle center.
355        #[unsafe(method(center))]
356        #[unsafe(method_family = none)]
357        pub unsafe fn center(&self) -> Retained<VNPoint>;
358
359        /// Returns circle radius.
360        #[unsafe(method(radius))]
361        #[unsafe(method_family = none)]
362        pub unsafe fn radius(&self) -> c_double;
363
364        /// Returns circle diameter.
365        #[unsafe(method(diameter))]
366        #[unsafe(method_family = none)]
367        pub unsafe fn diameter(&self) -> c_double;
368    );
369}
370
371/// Methods declared on superclass `NSObject`.
372impl VNCircle {
373    extern_methods!(
374        #[unsafe(method(init))]
375        #[unsafe(method_family = init)]
376        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
377
378        #[unsafe(method(new))]
379        #[unsafe(method_family = new)]
380        pub unsafe fn new() -> Retained<Self>;
381    );
382}
383
384extern_class!(
385    /// The VNContour class describes a contour provided by a VNContoursObservation.
386    ///
387    ///
388    /// VNContour objects are lightweight objects that act as a façade which allows access to a small slice of the usually much larger block of data owned by a VNContoursObservation that represents all of the contours detected in an image.
389    /// While the interface does present the notion of a hierarchy of parent/child contours, the implementation purposefully does not contain any explicit internal bookkeeping for this relationship.  Instead, contours are uniquely identified via their indexPath property.
390    /// As a side effect of this choice, repeated calls to methods that would return relational contours (e.g., -childContours or -childContourAtIndex:error:) are NOT guaranteed to return the same VNContour instances over and over again.  If this kind of parent/child object stability is an absolute requirement of the client, then they are responsible for creating the necessary data structures to represent and build that instance-stable hierarchy.
391    ///
392    /// See also [Apple's documentation](https://developer.apple.com/documentation/vision/vncontour?language=objc)
393    #[unsafe(super(NSObject))]
394    #[derive(Debug, PartialEq, Eq, Hash)]
395    pub struct VNContour;
396);
397
398unsafe impl NSCopying for VNContour {}
399
400unsafe impl CopyingHelper for VNContour {
401    type Result = Self;
402}
403
404unsafe impl NSObjectProtocol for VNContour {}
405
406#[cfg(feature = "VNRequestRevisionProviding")]
407unsafe impl VNRequestRevisionProviding for VNContour {}
408
409impl VNContour {
410    extern_methods!(
411        #[unsafe(method(new))]
412        #[unsafe(method_family = new)]
413        pub unsafe fn new() -> Retained<Self>;
414
415        #[unsafe(method(init))]
416        #[unsafe(method_family = init)]
417        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
418
419        /// The path to the target VNContour as it is stored in the owning VNContoursObservation's hierarchy of contours.
420        #[unsafe(method(indexPath))]
421        #[unsafe(method_family = none)]
422        pub unsafe fn indexPath(&self) -> Retained<NSIndexPath>;
423
424        /// The total number of child contours in the target contour.
425        ///
426        /// The use of this property is preferred over childContours.count due to the cost of building the child objects.
427        #[unsafe(method(childContourCount))]
428        #[unsafe(method_family = none)]
429        pub unsafe fn childContourCount(&self) -> NSInteger;
430
431        /// The array of the contours enclosed by the target contour.
432        ///
433        /// This property may come with the cost of instantiating new VNContour objects; therefore, clients are strongly encouraged to hold the results in a local variable instead of repeatedly invoking it.
434        #[unsafe(method(childContours))]
435        #[unsafe(method_family = none)]
436        pub unsafe fn childContours(&self) -> Retained<NSArray<VNContour>>;
437
438        /// Returns a VNContour object that is a child of this VNContour at the specified index.
439        ///
440        /// Parameter `childContourIndex`: The index into the childContours array.
441        ///
442        /// Parameter `error`: The error returned if the child contour cannot be provided.
443        ///
444        /// Returns: The VNContour object at the specified index path, or nil of a failure occurs.
445        #[unsafe(method(childContourAtIndex:error:_))]
446        #[unsafe(method_family = none)]
447        pub unsafe fn childContourAtIndex_error(
448            &self,
449            child_contour_index: NSUInteger,
450        ) -> Result<Retained<VNContour>, Retained<NSError>>;
451
452        /// The number of points that describe the contour.
453        #[unsafe(method(pointCount))]
454        #[unsafe(method_family = none)]
455        pub unsafe fn pointCount(&self) -> NSInteger;
456
457        #[cfg(feature = "objc2-core-graphics")]
458        /// The contour represented as a CGPath in normalized coordinates.
459        ///
460        /// The path is owned by this object and therefore will be alive as long as the the observation is alive.
461        #[unsafe(method(normalizedPath))]
462        #[unsafe(method_family = none)]
463        pub unsafe fn normalizedPath(&self) -> Retained<CGPath>;
464
465        /// The aspect ratio of the contour from the original image aspect ratio expressed as width/height
466        #[unsafe(method(aspectRatio))]
467        #[unsafe(method_family = none)]
468        pub unsafe fn aspectRatio(&self) -> c_float;
469
470        /// Simplifies the contour's collection of points into a polygon using the Ramer Douglas Peucker Algorithm.
471        ///
472        /// See
473        /// <https
474        /// ://en.wikipedia.org/wiki/Ramer–Douglas–Peucker_algorithm>
475        ///
476        /// Parameter `epsilon`: Points that have a perpendicular distance to the line segment they are on which are greater than epsilon are kept, others are eliminated.
477        ///
478        /// Parameter `error`: The error returned if a simplified contour cannot be created.
479        ///
480        /// Returns: A new VNContour object with a simplified polygon consisting of a subset of the points that defined the original VNContour.
481        #[unsafe(method(polygonApproximationWithEpsilon:error:_))]
482        #[unsafe(method_family = none)]
483        pub unsafe fn polygonApproximationWithEpsilon_error(
484            &self,
485            epsilon: c_float,
486        ) -> Result<Retained<VNContour>, Retained<NSError>>;
487    );
488}