[an error occurred while processing this directive]
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= //
//
//  Project:   Talina Gaming System (TgS) (∂)
//  File:      TgS Collision - Box-Point.cpp
//  Author:    Andrew Aye (EMail: andrew.aye@gmail.com, Web: http://www.andrewaye.com) 
//  Version:   3.11
//
// ------------------------------------------------------------------------------------------------------------------------------ //
//
//  Copyright: © 2002-2008, Andrew Aye.  All Rights Reserved.
//
//  This software is free for non-commercial use. Redistribution and use in source and binary forms, with or without modification,
//  are permitted provided that the following conditions are met: 
//    Redistributions of source code must retain this copyright notice, this list of conditions and the following disclaimers. 
//    Redistributions in binary form must reproduce this copyright notice, this list of conditions and the following
//      disclaimers in the documentation and other materials provided with the distribution. 
//
//  Neither the names of the copyright owner nor the names of its contributors may be used to endorse or promote products derived
//  from this software without specific prior written permission. 
//
//  The intellectual property rights of the algorithms used reside with Andrew Aye.  You may not use this software, in whole or
//  in part, in support of any commercial product without the express written consent of the author.
//
//  There is no warranty or other guarantee of fitness of this software for any purpose. It is provided solely "as is".
//
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= //




namespace TGS { // START TGS ///////////////////////////////////////////////////////////////////////////////////////////////////////
namespace COL { // START COL ///////////////////////////////////////////////////////////////////////////////////////////////////////

// ============================================================================================================================== //

// ---- F_ClosestSq ------------------------------------------------------------------------------------------------------------- //
// Input:  tgBX0: Box primitive
// Input:  tvS0: Point
// Output: tyB0,tyB1,tyB2: Parametric parameters to generate the point of closest proximity on the box (one for each axis)
// Return: Minimal distance between the two primitives or negative type max if they intersect or are invalid.
// ------------------------------------------------------------------------------------------------------------------------------ //

template <typename TYPE, int DIM>
TYPE F_ClosestSq( TYPE *ptyB0, TYPE *ptyB1, TYPE *ptyB2, CR_(BOX,DIM) tgBX0, M_(VECTOR,DIM) tvS0 )
{
    TgASSERT(tgBX0.Is_Valid() && MATH::F_Is_Point_Valid( tvS0 ));

    C_(VECTOR,DIM)                      tvDS = MATH::F_SUB( tvS0, tgBX0.Query_Origin() );
    TYPE                                tyT0, tyT1, tyDistSq = TYPE(0.0);

    tyT0 = MATH::F_DOT(tvDS,tgBX0.Query_AxisUnit0());
    tyT1 = tgBX0.Query_Extent(0);
    if (tyT0 < -tyT1)
    {
        const TYPE                          tyDist = tyT0 + tyT1;
        tyDistSq += tyDist*tyDist;
        *ptyB0 = -tyT1;
    }
    else if (tyT0 > tyT1)
    {
        const TYPE                          tyDist = tyT0 - tyT1;
        tyDistSq += tyDist*tyDist;
        *ptyB0 = tyT1;
    }
    else
    {
        *ptyB0 = tyT0;
    };

    tyT0 = MATH::F_DOT(tvDS,tgBX0.Query_AxisUnit1());
    tyT1 = tgBX0.Query_Extent(1);
    if (tyT0 < -tyT1)
    {
        const TYPE                          tyDist = tyT0 + tyT1;
        tyDistSq += tyDist*tyDist;
        *ptyB1 = -tyT1;
    }
    else if (tyT0 > tyT1)
    {
        const TYPE                          tyDist = tyT0 - tyT1;
        tyDistSq += tyDist*tyDist;
        *ptyB1 = tyT1;
    }
    else
    {
        *ptyB1 = tyT0;
    };

    tyT0 = MATH::F_DOT(tvDS,tgBX0.Query_AxisUnit2());
    tyT1 = tgBX0.Query_Extent(2);
    if (tyT0 < -tyT1)
    {
        const TYPE                          tyDist = tyT0 + tyT1;
        tyDistSq += tyDist*tyDist;
        *ptyB2 = -tyT1;
    }
    else if (tyT0 > tyT1)
    {
        const TYPE                          tyDist = tyT0 - tyT1;
        tyDistSq += tyDist*tyDist;
        *ptyB2 = tyT1;
    }
    else
    {
        *ptyB2 = tyT0;
    };

    return (tyDistSq <= TYPE(0.0) ? -LIMITS<TYPE>::MAX : tyDistSq);
}

template TgFLOAT32 F_ClosestSq( P_TgFLOAT32, P_TgFLOAT32, P_TgFLOAT32, CR_TgF4BOX, M_TgF4VECTOR );


// ============================================================================================================================== //

}; // END COL //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}; // END TGS //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
[an error occurred while processing this directive]