objc2-gameplay-kit 0.3.2

Bindings to the GameplayKit framework
Documentation
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;

use crate::*;

/// Used to adjust the way in which RTree nodes are split when they grow too large.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/gameplaykit/gkrtreesplitstrategy?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct GKRTreeSplitStrategy(pub NSInteger);
impl GKRTreeSplitStrategy {
    #[doc(alias = "GKRTreeSplitStrategyHalve")]
    pub const Halve: Self = Self(0);
    #[doc(alias = "GKRTreeSplitStrategyLinear")]
    pub const Linear: Self = Self(1);
    #[doc(alias = "GKRTreeSplitStrategyQuadratic")]
    pub const Quadratic: Self = Self(2);
    #[doc(alias = "GKRTreeSplitStrategyReduceOverlap")]
    pub const ReduceOverlap: Self = Self(3);
}

unsafe impl Encode for GKRTreeSplitStrategy {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for GKRTreeSplitStrategy {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_class!(
    /// An R-tree is a data structure that partitions axis aligned bounding rectangles into groups spatially.
    /// When a group goes to large, it is split according to its split strategy into two new groups.
    /// Fast queries can be made on these partition bounding rectangles.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/gameplaykit/gkrtree?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct GKRTree<ElementType: ?Sized = AnyObject>;
);

impl<ElementType: ?Sized + Message + AsRef<NSObject>> GKRTree<ElementType> {
    /// Unchecked conversion of the generic parameter.
    ///
    /// # Safety
    ///
    /// The generic must be valid to reinterpret as the given type.
    #[inline]
    pub unsafe fn cast_unchecked<NewElementType: ?Sized + Message + AsRef<NSObject>>(
        &self,
    ) -> &GKRTree<NewElementType> {
        unsafe { &*((self as *const Self).cast()) }
    }
}

extern_conformance!(
    unsafe impl<ElementType: ?Sized + AsRef<NSObject>> NSObjectProtocol for GKRTree<ElementType> {}
);

impl<ElementType: Message + AsRef<NSObject>> GKRTree<ElementType> {
    extern_methods!(
        /// Amount of array items to reserve before a query.
        /// This improves query performance at the cost of memory
        #[unsafe(method(queryReserve))]
        #[unsafe(method_family = none)]
        pub unsafe fn queryReserve(&self) -> NSUInteger;

        /// Setter for [`queryReserve`][Self::queryReserve].
        #[unsafe(method(setQueryReserve:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setQueryReserve(&self, query_reserve: NSUInteger);

        /// Creates an RTree with a given maximum number of children per node.  Nodes that grow beyond this number of children will be split.
        ///
        ///
        /// Parameter `maxNumberOfChildren`: the maximum number of children per node before splitting
        #[unsafe(method(treeWithMaxNumberOfChildren:))]
        #[unsafe(method_family = none)]
        pub unsafe fn treeWithMaxNumberOfChildren(
            max_number_of_children: NSUInteger,
        ) -> Retained<Self>;

        #[unsafe(method(initWithMaxNumberOfChildren:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithMaxNumberOfChildren(
            this: Allocated<Self>,
            max_number_of_children: NSUInteger,
        ) -> Retained<Self>;
    );
}

/// Methods declared on superclass `NSObject`.
impl<ElementType: Message + AsRef<NSObject>> GKRTree<ElementType> {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}