Karana.Math.Ktyping
===================

.. py:module:: Karana.Math.Ktyping

.. autoapi-nested-parse::

   Module containing types used throughout kdFlex.



Submodules
----------

.. toctree::
   :maxdepth: 1

   /generated/python_api/Karana/Math/Ktyping/Math_types/index


Attributes
----------

.. autoapisummary::

   Karana.Math.Ktyping.mass
   Karana.Math.Ktyping.inertia
   Karana.Math.Ktyping.length
   Karana.Math.Ktyping.angle
   Karana.Math.Ktyping.velocity
   Karana.Math.Ktyping.acceleration
   Karana.Math.Ktyping.force
   Karana.Math.Ktyping.torque
   Karana.Math.Ktyping.angular_velocity
   Karana.Math.Ktyping.angular_acceleration
   Karana.Math.Ktyping.gravitational_parameter
   Karana.Math.Ktyping.linear_spring_constant
   Karana.Math.Ktyping.linear_damping_constant
   Karana.Math.Ktyping.rotational_spring_constant
   Karana.Math.Ktyping.rotational_damping_constant
   Karana.Math.Ktyping.momentum
   Karana.Math.Ktyping.angular_momentum
   Karana.Math.Ktyping.MATH_EPSILON
   Karana.Math.Ktyping.NonNegativeInt
   Karana.Math.Ktyping.NonNegativeFloat
   Karana.Math.Ktyping.Vec
   Karana.Math.Ktyping.Mat
   Karana.Math.Ktyping.Vec3
   Karana.Math.Ktyping.Mat33
   Karana.Math.Ktyping.Mat66
   Karana.Math.Ktyping.Mat6n
   Karana.Math.Ktyping.Mass
   Karana.Math.Ktyping.Length
   Karana.Math.Ktyping.Length3
   Karana.Math.Ktyping.LengthVec
   Karana.Math.Ktyping.Angle
   Karana.Math.Ktyping.Angle3
   Karana.Math.Ktyping.AngleVec
   Karana.Math.Ktyping.Velocity3
   Karana.Math.Ktyping.AngularVelocity3
   Karana.Math.Ktyping.Acceleration3
   Karana.Math.Ktyping.AngularAcceleration3
   Karana.Math.Ktyping.Momentum3
   Karana.Math.Ktyping.AngularMomentum3
   Karana.Math.Ktyping.Inertia
   Karana.Math.Ktyping.Force3
   Karana.Math.Ktyping.Torque3
   Karana.Math.Ktyping.GravitationalParameter
   Karana.Math.Ktyping.LinearSpringConstant
   Karana.Math.Ktyping.RotationalSpringConstant
   Karana.Math.Ktyping.LinearDampingConstant
   Karana.Math.Ktyping.RotationalDampingConstant
   Karana.Math.Ktyping.MassDS
   Karana.Math.Ktyping.LengthDS
   Karana.Math.Ktyping.Length3DS
   Karana.Math.Ktyping.LengthVecDS
   Karana.Math.Ktyping.AngleDS
   Karana.Math.Ktyping.Angle3DS
   Karana.Math.Ktyping.AngleVecDS
   Karana.Math.Ktyping.Velocity3DS
   Karana.Math.Ktyping.AngularVelocity3DS
   Karana.Math.Ktyping.Acceleration3DS
   Karana.Math.Ktyping.AngularAcceleration3DS
   Karana.Math.Ktyping.InertiaDS
   Karana.Math.Ktyping.Force3DS
   Karana.Math.Ktyping.Torque3DS
   Karana.Math.Ktyping.GravitationalParameterDS
   Karana.Math.Ktyping.LinearSpringConstantDS
   Karana.Math.Ktyping.LinearDampingConstantDS
   Karana.Math.Ktyping.RotationalSpringConstantDS
   Karana.Math.Ktyping.RotationalDampingConstantDS


Functions
---------

.. autoapisummary::

   Karana.Math.Ktyping.getDefaultUnits
   Karana.Math.Ktyping.npSizeCheck
   Karana.Math.Ktyping.quantityCheck
   Karana.Math.Ktyping.optionallyWithUnits
   Karana.Math.Ktyping.normCheck
   Karana.Math.Ktyping.beforeVal
   Karana.Math.Ktyping.ser
   Karana.Math.Ktyping.SerializeAsId


Package Contents
----------------

.. py:data:: mass

.. py:data:: inertia

.. py:data:: length

.. py:data:: angle

.. py:data:: velocity

.. py:data:: acceleration

.. py:data:: force

.. py:data:: torque

.. py:data:: angular_velocity

.. py:data:: angular_acceleration

.. py:data:: gravitational_parameter

.. py:data:: linear_spring_constant

.. py:data:: linear_damping_constant

.. py:data:: rotational_spring_constant

.. py:data:: rotational_damping_constant

.. py:function:: getDefaultUnits(quantity: pint.util.UnitsContainer) -> pint.facets.plain.objects.PlainUnit

   Get the default units for a quantity.

   :param quantity: The quantity to get default units for.
   :type quantity: UnitsContainer

   :returns: The default units for the provided quantity.
   :rtype: PlainUnit


.. py:data:: momentum

.. py:data:: angular_momentum

.. py:data:: MATH_EPSILON
   :type:  float
   :value: 1e-12


.. py:data:: NonNegativeInt

.. py:data:: NonNegativeFloat

.. py:function:: npSizeCheck(shape: tuple[int, Ellipsis]) -> pydantic.AfterValidator

   Ensure that the numpy array is the given shape.

   :param shape: Desired shape of the array. A value of -1 indicates that, that particular axis can be any size.
                 For example, a shape of (3, -1, 2) indicates the first axis must be size 3, the second axis can be
                 any size, and the third axis must be size 2.
   :type shape: tuple[int, ...]


.. py:function:: quantityCheck(quantity: pint.util.UnitsContainer, mag_type: type, shape: tuple[int, Ellipsis] | None = None) -> pydantic.AfterValidator

   Ensure that the quantity type and magnitude are the type specified.

   :param quantity: The type of quantity that the Quantity should be.
   :type quantity: UnitsContainer
   :param mag_type: The magnitude type desired.
   :type mag_type: type
   :param shape: If specified, then also check the shape. This is only for NDArrays.
   :type shape: tuple[int, ...] | None

   :returns: A validator that ensures the quantity's magnitude is the mag_type specified.
   :rtype: AfterValidator


.. py:function:: optionallyWithUnits(quantity: pint.util.UnitsContainer) -> pydantic.AfterValidator

   Ensure that if the value is a quantity, that it is the specific provided quantity.

   If it has no units, then apply the default units for that quantity to it.

   :param quantity: The quantity we want the value to be if it is a Quantity. If it is not a Quantity, then
                    apply the defaults units for this quantity to the value.
   :type quantity: UnitsContainer


.. py:function:: normCheck(norm: float, prec: float = MATH_EPSILON) -> pydantic.AfterValidator

   Ensure the given value is within prec of norm.

   :param norm: The value we want the norm to be.
   :type norm: float
   :param prec: The tolerance for the value to be within that norm.
   :type prec: float


.. py:data:: Vec

.. py:data:: Mat

.. py:data:: Vec3

.. py:data:: Mat33

.. py:data:: Mat66

.. py:data:: Mat6n

.. py:data:: Mass

.. py:data:: Length

.. py:data:: Length3

.. py:data:: LengthVec

.. py:data:: Angle

.. py:data:: Angle3

.. py:data:: AngleVec

.. py:data:: Velocity3

.. py:data:: AngularVelocity3

.. py:data:: Acceleration3

.. py:data:: AngularAcceleration3

.. py:data:: Momentum3

.. py:data:: AngularMomentum3

.. py:data:: Inertia

.. py:data:: Force3

.. py:data:: Torque3

.. py:data:: GravitationalParameter

.. py:data:: LinearSpringConstant

.. py:data:: RotationalSpringConstant

.. py:data:: LinearDampingConstant

.. py:data:: RotationalDampingConstant

.. py:data:: MassDS

.. py:data:: LengthDS

.. py:data:: Length3DS

.. py:data:: LengthVecDS

.. py:data:: AngleDS

.. py:data:: Angle3DS

.. py:data:: AngleVecDS

.. py:data:: Velocity3DS

.. py:data:: AngularVelocity3DS

.. py:data:: Acceleration3DS

.. py:data:: AngularAcceleration3DS

.. py:data:: InertiaDS

.. py:data:: Force3DS

.. py:data:: Torque3DS

.. py:data:: GravitationalParameterDS

.. py:data:: LinearSpringConstantDS

.. py:data:: LinearDampingConstantDS

.. py:data:: RotationalSpringConstantDS

.. py:data:: RotationalDampingConstantDS

.. py:function:: beforeVal(val: int | Any, allow_int: bool = False, allow_None: bool = True) -> Any

   Validate an incoming object.

   If this is an integer, then us IdMixin to look up the
   object that corresponds to that integer.

   :param val: The value to validate.
   :type val: int | Any
   :param allow_int: If True, then if the val does not correspond to an object that has been
                     created, then return the integer. This overshadows allow_None if both
                     are set. If False, then try allow_None before.
   :type allow_int: bool
   :param allow_None: If True, then if the val does not correspond to an object that has been
                      created, then return None. If False, then throw an error val does not
                      correspond to an object that has been created.
   :type allow_None: bool

   :returns: The value.
   :rtype: Any


.. py:function:: ser(val: Any) -> int | None

   Serialize an object using its ID rather than the object itself.

   :param val: Use the id() method to get the value to serialize.
   :type val: Any

   :returns: This returns an integer if Value is none None, and None otherwise.
   :rtype: int | None


.. py:function:: SerializeAsId(allow_int: bool = False, allow_None: bool = True) -> tuple[pydantic.BeforeValidator, pydantic.PlainSerializer]

   Create pydantic functions to serialize object as ID.

   This is typically used like:

   class MyDataStruct(DataStruct):
       body: Annotated[PhysicalBody, *SerializeAsId()]

   :param allow_int: If True, then if the val does not correspond to an object that has been
                     created, then return the integer. This overshadows allow_None if both
                     are set. If False, then try allow_None before.
   :type allow_int: bool
   :param allow_None: This affects deserialization. If True, then if the ID does not correspond to
                      an object that has been created, then return None. If False, then throw an
                      error if val does not correspond to an object that has been created.
   :type allow_None: bool

   :returns: A validator function and serializer function for the pydantic field to serialize
             as an ID.
   :rtype: tuple[BeforeValidator, PlainSerializer]


