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