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 objc2_foundation::*;

use crate::*;

/// Adjusts how graph nodes are created when you triangulate a GKMeshGrapk
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/gameplaykit/gkmeshgraphtriangulationmode?language=objc)
// NS_OPTIONS
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct GKMeshGraphTriangulationMode(pub NSUInteger);
bitflags::bitflags! {
    impl GKMeshGraphTriangulationMode: NSUInteger {
        #[doc(alias = "GKMeshGraphTriangulationModeVertices")]
        const Vertices = 1<<0;
        #[doc(alias = "GKMeshGraphTriangulationModeCenters")]
        const Centers = 1<<1;
        #[doc(alias = "GKMeshGraphTriangulationModeEdgeMidpoints")]
        const EdgeMidpoints = 1<<2;
    }
}

unsafe impl Encode for GKMeshGraphTriangulationMode {
    const ENCODING: Encoding = NSUInteger::ENCODING;
}

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

extern_class!(
    /// A collection of GKGraphNodes that are governed by a mesh formed by the space between a set of GKPolygonObstacles
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/gameplaykit/gkmeshgraph?language=objc)
    #[unsafe(super(GKGraph, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    #[cfg(all(feature = "GKGraph", feature = "GKGraphNode"))]
    pub struct GKMeshGraph<NodeType: ?Sized = AnyObject>;
);

#[cfg(all(feature = "GKGraph", feature = "GKGraphNode"))]
impl<NodeType: ?Sized + Message + AsRef<GKGraphNode2D>> GKMeshGraph<NodeType> {
    /// Unchecked conversion of the generic parameter.
    ///
    /// # Safety
    ///
    /// The generic must be valid to reinterpret as the given type.
    #[inline]
    pub unsafe fn cast_unchecked<NewNodeType: ?Sized + Message + AsRef<GKGraphNode2D>>(
        &self,
    ) -> &GKMeshGraph<NewNodeType> {
        unsafe { &*((self as *const Self).cast()) }
    }
}

#[cfg(all(feature = "GKGraph", feature = "GKGraphNode"))]
extern_conformance!(
    unsafe impl<NodeType: ?Sized + NSCoding + AsRef<GKGraphNode2D>> NSCoding for GKMeshGraph<NodeType> {}
);

#[cfg(all(feature = "GKGraph", feature = "GKGraphNode"))]
extern_conformance!(
    unsafe impl<NodeType: ?Sized + AsRef<GKGraphNode2D>> NSCopying for GKMeshGraph<NodeType> {}
);

#[cfg(all(feature = "GKGraph", feature = "GKGraphNode"))]
unsafe impl<NodeType: ?Sized + Message + AsRef<GKGraphNode2D>> CopyingHelper
    for GKMeshGraph<NodeType>
{
    type Result = Self;
}

#[cfg(all(feature = "GKGraph", feature = "GKGraphNode"))]
extern_conformance!(
    unsafe impl<NodeType: ?Sized + AsRef<GKGraphNode2D>> NSObjectProtocol for GKMeshGraph<NodeType> {}
);

#[cfg(all(feature = "GKGraph", feature = "GKGraphNode"))]
extern_conformance!(
    unsafe impl<NodeType: ?Sized + NSSecureCoding + AsRef<GKGraphNode2D>> NSSecureCoding
        for GKMeshGraph<NodeType>
    {
    }
);

#[cfg(all(feature = "GKGraph", feature = "GKGraphNode"))]
impl<NodeType: Message + AsRef<GKGraphNode2D>> GKMeshGraph<NodeType> {
    extern_methods!(
        #[cfg(feature = "GKObstacle")]
        /// Array of the extruded obstacles currently represented by this graph
        #[unsafe(method(obstacles))]
        #[unsafe(method_family = none)]
        pub unsafe fn obstacles(&self) -> Retained<NSArray<GKPolygonObstacle>>;

        /// The distance by which all obstacles are extruded.
        /// This is most commonly the spatial bounding radius of a potential traveler on this path
        #[unsafe(method(bufferRadius))]
        #[unsafe(method_family = none)]
        pub unsafe fn bufferRadius(&self) -> c_float;

        /// Specifies how graph nodes are generated when you triangulate this graph.
        /// You can combine triangulation modes using the | (OR) operator
        ///
        ///
        /// See: GKMeshGraphTriangulationMode
        #[unsafe(method(triangulationMode))]
        #[unsafe(method_family = none)]
        pub unsafe fn triangulationMode(&self) -> GKMeshGraphTriangulationMode;

        /// Setter for [`triangulationMode`][Self::triangulationMode].
        #[unsafe(method(setTriangulationMode:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setTriangulationMode(&self, triangulation_mode: GKMeshGraphTriangulationMode);

        /// The number of triangles currently in this mesh graph
        #[unsafe(method(triangleCount))]
        #[unsafe(method_family = none)]
        pub unsafe fn triangleCount(&self) -> NSUInteger;

        #[cfg(feature = "GKObstacle")]
        /// Adds obstacles to this mesh graph.  Only reflected after the next triangulate call.
        #[unsafe(method(addObstacles:))]
        #[unsafe(method_family = none)]
        pub unsafe fn addObstacles(&self, obstacles: &NSArray<GKPolygonObstacle>);

        #[cfg(feature = "GKObstacle")]
        /// Removes obstacles from this graph.  Only reflected after the next triangulate call.
        #[unsafe(method(removeObstacles:))]
        #[unsafe(method_family = none)]
        pub unsafe fn removeObstacles(&self, obstacles: &NSArray<GKPolygonObstacle>);

        /// Connects the node to this graph by inserting it into an existing triangle and making the appropriate connections
        /// Node must be in the space defined by the min and max coordinates of this graph.
        ///
        /// Parameter `node`: the node to connect
        #[unsafe(method(connectNodeUsingObstacles:))]
        #[unsafe(method_family = none)]
        pub unsafe fn connectNodeUsingObstacles(&self, node: &NodeType);

        /// Generates a new triangle mesh for the given obstacles.
        /// This should be called after some number of calls to addObstacle
        /// The negative space between all input obstacles are triangulated to create a mesh
        /// This mesh is turned into a set of connected graph nodes based on
        #[unsafe(method(triangulate))]
        #[unsafe(method_family = none)]
        pub unsafe fn triangulate(&self);

        /// Returns the class of the specified generic index
        #[unsafe(method(classForGenericArgumentAtIndex:))]
        #[unsafe(method_family = none)]
        pub unsafe fn classForGenericArgumentAtIndex(&self, index: NSUInteger)
            -> &'static AnyClass;
    );
}

/// Methods declared on superclass `GKGraph`.
#[cfg(all(feature = "GKGraph", feature = "GKGraphNode"))]
impl<NodeType: Message + AsRef<GKGraphNode2D>> GKMeshGraph<NodeType> {
    extern_methods!(
        /// Creates a graph with the provided array of nodes.
        ///
        /// Parameter `nodes`: the nodes to create the graph with
        #[unsafe(method(graphWithNodes:))]
        #[unsafe(method_family = none)]
        pub unsafe fn graphWithNodes(nodes: &NSArray<GKGraphNode>) -> Retained<Self>;

        #[unsafe(method(initWithNodes:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithNodes(
            this: Allocated<Self>,
            nodes: &NSArray<GKGraphNode>,
        ) -> Retained<Self>;
    );
}

/// Methods declared on superclass `NSObject`.
#[cfg(all(feature = "GKGraph", feature = "GKGraphNode"))]
impl<NodeType: Message + AsRef<GKGraphNode2D>> GKMeshGraph<NodeType> {
    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>;
    );
}