Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS Common - Geometry 3D - Box - Axis Aligned.i_inc
    »Author«    Andrew Aye (EMail: mailto:andrew.aye@gmail.com, Web: http://www.andrewaye.com)
    »Version«   4.51 / »GUID« A9981407-3EC9-42AF-8B6F-8BE6DD919615                                                                                                        */
/*   -------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
/*  Copyright: © 2002-2017, 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:
        Redistribution of source code must retain this copyright notice, this list of conditions and the following disclaimers.
        Redistribution 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.
    The name of the author may not 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".                                                   */
/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/* == Common ============================================================================================================================================================ */

/* ---- V(tgGM_BA_Is_Empty) --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgBOOL V(tgGM_BA_Is_Empty)( V(CPCU_TgBOXAA) psBA0 )
{
    return (
        (
            psBA0->m_vMin.m.x >= psBA0->m_vMax.m.x ||
            psBA0->m_vMin.m.y >= psBA0->m_vMax.m.y ||
            psBA0->m_vMin.m.z >= psBA0->m_vMax.m.z
            ) ? TgTRUE : TgFALSE
    );
}


/* ---- V(tgGM_BA_Union_PT) --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_BA_Union_PT)( V(PCU_TgBOXAA) psBA0, V(CPCU_TgVEC) pvS0 )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Point_Valid)( pvS0 ));

    psBA0->m_vMin.m.x = F(tgPM_FSEL)( psBA0->m_vMin.m.x - pvS0->m.x, pvS0->m.x, psBA0->m_vMin.m.x );
    psBA0->m_vMin.m.y = F(tgPM_FSEL)( psBA0->m_vMin.m.y - pvS0->m.y, pvS0->m.y, psBA0->m_vMin.m.y );
    psBA0->m_vMin.m.z = F(tgPM_FSEL)( psBA0->m_vMin.m.z - pvS0->m.z, pvS0->m.z, psBA0->m_vMin.m.z );

    psBA0->m_vMax.m.x = F(tgPM_FSEL)( pvS0->m.x - psBA0->m_vMax.m.x, pvS0->m.x, psBA0->m_vMax.m.x );
    psBA0->m_vMax.m.y = F(tgPM_FSEL)( pvS0->m.y - psBA0->m_vMax.m.y, pvS0->m.y, psBA0->m_vMax.m.y );
    psBA0->m_vMax.m.z = F(tgPM_FSEL)( pvS0->m.z - psBA0->m_vMax.m.z, pvS0->m.z, psBA0->m_vMax.m.z );
}


/* ---- V(tgGM_BA_Union_SP) --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_BA_Union_SP)( V(PCU_TgBOXAA) psBA0, V(CPCU_TgVEC) pvS0, const TYPE fRadius )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Point_Valid)( pvS0 ) && TgTRUE != F(tgPM_NAN)(fRadius));

    psBA0->m_vMin.m.x = F(tgPM_FSEL)( psBA0->m_vMin.m.x - pvS0->m.x + fRadius, pvS0->m.x - fRadius, psBA0->m_vMin.m.x );
    psBA0->m_vMin.m.y = F(tgPM_FSEL)( psBA0->m_vMin.m.y - pvS0->m.y + fRadius, pvS0->m.y - fRadius, psBA0->m_vMin.m.y );
    psBA0->m_vMin.m.z = F(tgPM_FSEL)( psBA0->m_vMin.m.z - pvS0->m.z + fRadius, pvS0->m.z - fRadius, psBA0->m_vMin.m.z );

    psBA0->m_vMax.m.x = F(tgPM_FSEL)( pvS0->m.x + fRadius - psBA0->m_vMax.m.x, pvS0->m.x + fRadius, psBA0->m_vMax.m.x );
    psBA0->m_vMax.m.y = F(tgPM_FSEL)( pvS0->m.y + fRadius - psBA0->m_vMax.m.y, pvS0->m.y + fRadius, psBA0->m_vMax.m.y );
    psBA0->m_vMax.m.z = F(tgPM_FSEL)( pvS0->m.z + fRadius - psBA0->m_vMax.m.z, pvS0->m.z + fRadius, psBA0->m_vMax.m.z );
}


/* ---- V(tgGM_BA_Union_BA) --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_BA_Union_BA)( V(PCU_TgBOXAA) psBA0, V(CPCU_TgBOXAA) psBA1 )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(tgGM_BA_Is_Valid)(psBA1));

    psBA0->m_vMin.m.x = F(tgPM_FSEL)( psBA0->m_vMin.m.x - psBA1->m_vMin.m.x, psBA1->m_vMin.m.x, psBA0->m_vMin.m.x );
    psBA0->m_vMin.m.y = F(tgPM_FSEL)( psBA0->m_vMin.m.y - psBA1->m_vMin.m.y, psBA1->m_vMin.m.y, psBA0->m_vMin.m.y );
    psBA0->m_vMin.m.z = F(tgPM_FSEL)( psBA0->m_vMin.m.z - psBA1->m_vMin.m.z, psBA1->m_vMin.m.z, psBA0->m_vMin.m.z );

    psBA0->m_vMax.m.x = F(tgPM_FSEL)( psBA1->m_vMax.m.x - psBA0->m_vMax.m.x, psBA1->m_vMax.m.x, psBA0->m_vMax.m.x );
    psBA0->m_vMax.m.y = F(tgPM_FSEL)( psBA1->m_vMax.m.y - psBA0->m_vMax.m.y, psBA1->m_vMax.m.y, psBA0->m_vMax.m.y );
    psBA0->m_vMax.m.z = F(tgPM_FSEL)( psBA1->m_vMax.m.z - psBA0->m_vMax.m.z, psBA1->m_vMax.m.z, psBA0->m_vMax.m.z );
}


/* ---- V(tgGM_BA_Sweep) ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_BA_Sweep)( V(PCU_TgBOXAA) psBA0, V(CPCU_TgVEC) pvDT )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Vector_Valid)(pvDT));

    psBA0->m_vMin.m.x = F(tgPM_FSEL)( pvDT->m.x, psBA0->m_vMin.m.x, psBA0->m_vMin.m.x + pvDT->m.x );
    psBA0->m_vMin.m.y = F(tgPM_FSEL)( pvDT->m.y, psBA0->m_vMin.m.y, psBA0->m_vMin.m.y + pvDT->m.y );
    psBA0->m_vMin.m.z = F(tgPM_FSEL)( pvDT->m.z, psBA0->m_vMin.m.z, psBA0->m_vMin.m.z + pvDT->m.z );

    psBA0->m_vMax.m.x = F(tgPM_FSEL)( pvDT->m.x, psBA0->m_vMax.m.x + pvDT->m.x, psBA0->m_vMax.m.x );
    psBA0->m_vMax.m.y = F(tgPM_FSEL)( pvDT->m.y, psBA0->m_vMax.m.y + pvDT->m.y, psBA0->m_vMax.m.y );
    psBA0->m_vMax.m.z = F(tgPM_FSEL)( pvDT->m.z, psBA0->m_vMax.m.z + pvDT->m.z, psBA0->m_vMax.m.z );
}


/* ---- V(tgGM_BA_Expand) ----------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_BA_Expand)( V(PCU_TgBOXAA) psBA0, const TYPE fExpand )
{
    V(TgVEC)                            tvExpand;

    TgGEOM_ASSERT_PARAM(TgTRUE != F(tgPM_NAN)(fExpand) && fExpand > MKL(0.0));

    tvExpand = V(FS_SET1)( fExpand );

    psBA0->m_vMin = V(F_SUB)( &(psBA0->m_vMin), &tvExpand );
    psBA0->m_vMax = V(F_ADD)( &(psBA0->m_vMax), &tvExpand );
}


/* ---- V(tgGM_BA_Scale) ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_BA_Scale)( V(PCU_TgBOXAA) psBA0, const TYPE fScale )
{
    V(TgVEC)                            tvScale;

    TgGEOM_ASSERT_PARAM(TgTRUE != F(tgPM_NAN)(fScale) && fScale > MKL(0.0));

    tvScale = V(FS_SET1)( fScale );

    psBA0->m_vMin = V(F_MUL)( &(psBA0->m_vMin), &tvScale );
    psBA0->m_vMax = V(F_MUL)( &(psBA0->m_vMax), &tvScale );
}


/* ---- V(tgGM_BA_Query_Centre) ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(TgVEC) V(tgGM_BA_Query_Centre)( V(CPCU_TgBOXAA) psBA1 )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(tgGM_BA_Is_Valid)(psBA1));

    return (V(FS_SETP)(
        MKL(0.5)*(psBA1->m_vMin.m.x + psBA1->m_vMax.m.x),
        MKL(0.5)*(psBA1->m_vMin.m.y + psBA1->m_vMax.m.y),
        MKL(0.5)*(psBA1->m_vMin.m.z + psBA1->m_vMax.m.z)
        ));
}


/* ---- V(tgGM_BA_Reset) ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_BA_Reset)( V(PCU_TgBOXAA) psBA0 )
{
    V(tgGM_BA_Zero)( psBA0 );
}


/* ---- V(tgGM_BA_Zero) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_BA_Zero)( V(PCU_TgBOXAA) psBA0 )
{
    psBA0->m_vMin = V(FS_SETV)( F(KTgMAX), F(KTgMAX), F(KTgMAX) );
    psBA0->m_vMax = V(FS_SETV)( F(-KTgMAX), F(-KTgMAX), F(-KTgMAX) );
}


/* ---- V(tgGM_BA_Is_Valid) --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgBOOL V(tgGM_BA_Is_Valid)( V(CPCU_TgBOXAA) psBA1 )
{
    if (TgTRUE == F(tgPM_NAN)(psBA1->m_vMin.m.x) || TgTRUE == F(tgPM_NAN)(psBA1->m_vMin.m.y) || TgTRUE == F(tgPM_NAN)(psBA1->m_vMin.m.z))
    {
        return (TgFALSE);
    };

    if (TgTRUE == F(tgPM_NAN)(psBA1->m_vMax.m.x) || TgTRUE == F(tgPM_NAN)(psBA1->m_vMax.m.y) || TgTRUE == F(tgPM_NAN)(psBA1->m_vMax.m.z))
    {
        return (TgFALSE);
    };

    if (psBA1->m_vMin.m.x >= psBA1->m_vMax.m.x || psBA1->m_vMin.m.y >= psBA1->m_vMax.m.y || psBA1->m_vMin.m.z >= psBA1->m_vMax.m.z)
    {
        return (TgFALSE);
    };

    return (TgTRUE);
}


/* ---- V(tgGM_BA_Support_Point) ---------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(TgVEC) V(tgGM_BA_Support_Point)( V(CPCU_TgBOXAA) psBA1, V(CPCU_TgVEC) pvDN )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(tgGM_BA_Is_Valid)(psBA1));
    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Vector_Valid)(pvDN));
    TgGEOM_ASSERT_PARAM(TgTRUE == F(tgCM_NR1)(V(F_LSQ)(pvDN)));

    return (V(FS_SETP)(
        F(tgPM_FSEL)(pvDN->m.x, psBA1->m_vMax.m.x, psBA1->m_vMin.m.x),
        F(tgPM_FSEL)(pvDN->m.y, psBA1->m_vMax.m.y, psBA1->m_vMin.m.y),
        F(tgPM_FSEL)(pvDN->m.z, psBA1->m_vMax.m.z, psBA1->m_vMin.m.z)
    ));
}


/* ---- V(tgGM_BA_Volume) ----------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TYPE V(tgGM_BA_Volume)( V(CPCU_TgBOXAA) psBA1 )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(tgGM_BA_Is_Valid)(psBA1));
    return ((psBA1->m_vMax.m.x - psBA1->m_vMin.m.x) * (psBA1->m_vMax.m.y - psBA1->m_vMin.m.y) * (psBA1->m_vMax.m.z - psBA1->m_vMin.m.z));
}


/* ---- V(tgGM_BA_Area) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TYPE V(tgGM_BA_Area)( V(CPCU_TgBOXAA) psBA1 )
{
    const TYPE              fdx = psBA1->m_vMax.m.x - psBA1->m_vMin.m.x;
    const TYPE              fdy = psBA1->m_vMax.m.y - psBA1->m_vMin.m.y;
    const TYPE              fdz = psBA1->m_vMax.m.z - psBA1->m_vMin.m.z;

    TgGEOM_ASSERT_PARAM(TgTRUE == V(tgGM_BA_Is_Valid)(psBA1));

    return (MKL(2.0)*fdx*fdy + MKL(2.0)*fdx*fdz + MKL(2.0)*fdy*fdz);
}


/* ---- V(tgGM_BA_BA) --------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_BA_BA)( V(PCU_TgBOXAA) psBA0, V(CPCU_TgBOXAA) psBA1 )
{
    V(tgGM_BA_Copy)( psBA0, psBA1 );
}


/* ---- V(tgGM_BA_Sweep_BA) --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_BA_Sweep_BA)( V(PCU_TgBOXAA) psBA0, V(CPCU_TgBOXAA) psBA1, V(CPCU_TgVEC) pvDT )
{
    V(tgGM_BA_Copy)( psBA0, psBA1 );
    V(tgGM_BA_Sweep)( psBA0, pvDT );
}


/* ---- V(tgGM_BA_Project) ---------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_BA_Project)( PCU_TYPE ptyMin, PCU_TYPE ptyMax, V(CPCU_TgBOXAA) psBA1, V(CPCU_TgVEC) pvAxis )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(tgGM_BA_Is_Valid)(psBA1) && TgTRUE == V(F_Is_Vector_Valid)(pvAxis));

    *ptyMin = pvAxis->m.x*psBA1->m_vMin.m.x + pvAxis->m.y*psBA1->m_vMin.m.y + pvAxis->m.z*psBA1->m_vMin.m.z;
    *ptyMax = pvAxis->m.x*psBA1->m_vMax.m.x + pvAxis->m.y*psBA1->m_vMax.m.y + pvAxis->m.z*psBA1->m_vMax.m.z;
}


/* ---- V(tgGM_BA_Is_Contained) ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgBOOL V(tgGM_BA_Is_Contained)( V(CPCU_TgBOXAA) psBA1, V(CPCU_TgVEC) pvP0 )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(tgGM_BA_Is_Valid)(psBA1) && TgTRUE == V(F_Is_Point_Valid)(pvP0));

    return (
        pvP0->m.x >= psBA1->m_vMin.m.x && pvP0->m.x <= psBA1->m_vMax.m.x &&
        pvP0->m.y >= psBA1->m_vMin.m.y && pvP0->m.y <= psBA1->m_vMax.m.y &&
        pvP0->m.z >= psBA1->m_vMin.m.z && pvP0->m.z <= psBA1->m_vMax.m.z ? TgTRUE : TgFALSE
    );
}


/* ---- V(tgGM_BA_TX) --------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_BA_TX)( V(PCU_TgBOXAA) psBA0, M34(CPCU_TgMAT) pxM0 )
{
    M44(TgMAT)                          tmM1;

    TgGEOM_ASSERT_PARAM(TgTRUE != M34(F_NaN)(pxM0));

    M34(F_TR)(&tmM1, pxM0);

    {
        V(C_TgVEC)                          tv0 = V(F_MUL_SV)(V(tgGM_BA_Query_SizeX)( psBA0), (V(CPU_TgVEC))(tmM1.m_avRow + 0) );
        V(C_TgVEC)                          tv1 = V(F_MUL_SV)(V(tgGM_BA_Query_SizeY)( psBA0), (V(CPU_TgVEC))(tmM1.m_avRow + 1) );
        V(C_TgVEC)                          tv2 = V(F_MUL_SV)(V(tgGM_BA_Query_SizeZ)( psBA0), (V(CPU_TgVEC))(tmM1.m_avRow + 2) );
        V(C_TgVEC)                          tv3 = V(F_SUB)( &tv1, &tv0 );
        V(C_TgVEC)                          tv4 = V(F_SUB)( &tv2, &tv0 );
        V(C_TgVEC)                          tv5 = V(F_SUB)( &tv2, &tv1 );
        V(C_TgVEC)                          tv7 = V(tgGM_BA_Query_Centre)( psBA0 );
        V(C_TgVEC)                          tv6 = V(F_ADD)( &tv7, (V(CPU_TgVEC))(tmM1.m_avRow + 3) );

        psBA0->m_vMin.m.x = tv6.m.x + F(tgPM_FSEL)( tv3.m.x, F(tgPM_FSEL)(tv4.m.x, tv0.m.x, tv2.m.x), F(tgPM_FSEL)(tv5.m.x, tv1.m.x, tv2.m.x) );
        psBA0->m_vMin.m.y = tv6.m.y + F(tgPM_FSEL)( tv3.m.y, F(tgPM_FSEL)(tv4.m.y, tv0.m.y, tv2.m.y), F(tgPM_FSEL)(tv5.m.y, tv1.m.y, tv2.m.y) );
        psBA0->m_vMin.m.z = tv6.m.z + F(tgPM_FSEL)( tv3.m.z, F(tgPM_FSEL)(tv4.m.z, tv0.m.z, tv2.m.z), F(tgPM_FSEL)(tv5.m.z, tv1.m.z, tv2.m.z) );

        psBA0->m_vMax.m.x = tv6.m.x + F(tgPM_FSEL)( tv3.m.x, F(tgPM_FSEL)(tv5.m.x, tv2.m.x, tv1.m.x), F(tgPM_FSEL)(tv4.m.x, tv2.m.x, tv0.m.x) );
        psBA0->m_vMax.m.y = tv6.m.y + F(tgPM_FSEL)( tv3.m.y, F(tgPM_FSEL)(tv5.m.y, tv2.m.y, tv1.m.y), F(tgPM_FSEL)(tv4.m.y, tv2.m.y, tv0.m.y) );
        psBA0->m_vMax.m.z = tv6.m.z + F(tgPM_FSEL)( tv3.m.z, F(tgPM_FSEL)(tv5.m.z, tv2.m.z, tv1.m.z), F(tgPM_FSEL)(tv4.m.z, tv2.m.z, tv0.m.z) );
    };
}


/* ---- V(tgGM_BA_Copy_TX) ---------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_BA_Copy_TX)( V(PCU_TgBOXAA) psBA0, V(CPCU_TgBOXAA) psBA1, M34(CPCU_TgMAT) pxM0 )
{
    M44(TgMAT)                          tmM1;

    TgGEOM_ASSERT_PARAM(TgTRUE == V(tgGM_BA_Is_Valid)(psBA1) && TgTRUE != M34(F_NaN)(pxM0));

    M34(F_TR)(&tmM1, pxM0);

    {
        V(C_TgVEC)                          tv0 = V(F_MUL_SV)(V(tgGM_BA_Query_SizeX)( psBA1), (V(CPU_TgVEC))(tmM1.m_avRow + 0) );
        V(C_TgVEC)                          tv1 = V(F_MUL_SV)(V(tgGM_BA_Query_SizeY)( psBA1), (V(CPU_TgVEC))(tmM1.m_avRow + 1) );
        V(C_TgVEC)                          tv2 = V(F_MUL_SV)(V(tgGM_BA_Query_SizeZ)( psBA1), (V(CPU_TgVEC))(tmM1.m_avRow + 2) );
        V(C_TgVEC)                          tv3 = V(F_SUB)( &tv1, &tv0 );
        V(C_TgVEC)                          tv4 = V(F_SUB)( &tv2, &tv0 );
        V(C_TgVEC)                          tv5 = V(F_SUB)( &tv2, &tv1 );
        V(C_TgVEC)                          tv7 = V(tgGM_BA_Query_Centre)( psBA1 );
        V(C_TgVEC)                          tv6 = V(F_ADD)( &tv7, (V(CPU_TgVEC))(tmM1.m_avRow + 3) );

        psBA0->m_vMin.m.x = tv6.m.x + F(tgPM_FSEL)( tv3.m.x, F(tgPM_FSEL)(tv4.m.x, tv0.m.x, tv2.m.x), F(tgPM_FSEL)(tv5.m.x, tv1.m.x, tv2.m.x) );
        psBA0->m_vMin.m.y = tv6.m.y + F(tgPM_FSEL)( tv3.m.y, F(tgPM_FSEL)(tv4.m.y, tv0.m.y, tv2.m.y), F(tgPM_FSEL)(tv5.m.y, tv1.m.y, tv2.m.y) );
        psBA0->m_vMin.m.z = tv6.m.z + F(tgPM_FSEL)( tv3.m.z, F(tgPM_FSEL)(tv4.m.z, tv0.m.z, tv2.m.z), F(tgPM_FSEL)(tv5.m.z, tv1.m.z, tv2.m.z) );

        psBA0->m_vMax.m.x = tv6.m.x + F(tgPM_FSEL)( tv3.m.x, F(tgPM_FSEL)(tv5.m.x, tv2.m.x, tv1.m.x), F(tgPM_FSEL)(tv4.m.x, tv2.m.x, tv0.m.x) );
        psBA0->m_vMax.m.y = tv6.m.y + F(tgPM_FSEL)( tv3.m.y, F(tgPM_FSEL)(tv5.m.y, tv2.m.y, tv1.m.y), F(tgPM_FSEL)(tv4.m.y, tv2.m.y, tv0.m.y) );
        psBA0->m_vMax.m.z = tv6.m.z + F(tgPM_FSEL)( tv3.m.z, F(tgPM_FSEL)(tv5.m.z, tv2.m.z, tv1.m.z), F(tgPM_FSEL)(tv4.m.z, tv2.m.z, tv0.m.z) );
    };
}


/* ---- V(tgGM_BA_Init) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_BA_Init)( V(PCU_TgBOXAA) psBA0, V(CPCU_TgVEC) pvMin, V(CPCU_TgVEC) pvMax )
{
    TgGEOM_ASSERT_PARAM(TgTRUE != V(F_NaN)(pvMin) && TgTRUE != V(F_NaN)(pvMax));

    psBA0->m_vMin = *pvMin;
    psBA0->m_vMax = *pvMax;
}


/* ---- V(tgGM_BA_Init_PT) ---------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_BA_Init_PT)( V(PCU_TgBOXAA) psBA0, V(CPCU_TgVEC) pvPoint )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Point_Valid)(pvPoint));

    psBA0->m_vMin = *pvPoint;
    psBA0->m_vMax = *pvPoint;
}


/* ---- V(tgGM_BA_Init_SP) ---------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_BA_Init_SP)( V(PCU_TgBOXAA) psBA0, V(CPCU_TgVEC) pvOrigin, const TYPE fRadius )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Point_Valid)(pvOrigin) && TgTRUE != F(tgPM_NAN)(fRadius));

    psBA0->m_vMin = V(FS_SETV)( pvOrigin->m.x - fRadius, pvOrigin->m.y - fRadius, pvOrigin->m.z - fRadius );
    psBA0->m_vMax = V(FS_SETV)( pvOrigin->m.x + fRadius, pvOrigin->m.y + fRadius, pvOrigin->m.z + fRadius );
}


/* ---- V(tgGM_BA_Copy) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_BA_Copy)( V(PCU_TgBOXAA) psBA0, V(CPCU_TgBOXAA) psBA1 )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(tgGM_BA_Is_Valid)(psBA1));

    psBA0->m_vMin = psBA1->m_vMin;
    psBA0->m_vMax = psBA1->m_vMax;
}


/* ---- V(tgGM_BA_Set_Invalid) ------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_BA_Set_Invalid)( V(PCU_TgBOXAA) psBA0 )
{
    psBA0->m_vMin.m.x = F(KTgMAX);
    psBA0->m_vMin.m.y = F(KTgMAX);
    psBA0->m_vMin.m.z = F(KTgMAX);

    psBA0->m_vMax.m.x = -F(KTgMAX);
    psBA0->m_vMax.m.y = -F(KTgMAX);
    psBA0->m_vMax.m.z = -F(KTgMAX);
}


/* ---- V(tgGM_BA_Set_Min) ---------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_BA_Set_Min)( V(PCU_TgBOXAA) psBA0, V(CPCU_TgVEC) pvMin )
{
    TgGEOM_ASSERT_PARAM(TgTRUE != V(F_NaN)(pvMin));
    psBA0->m_vMin = *pvMin;
}


/* ---- V(tgGM_BA_Set_Max) ---------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_BA_Set_Max)( V(PCU_TgBOXAA) psBA0, V(CPCU_TgVEC) pvMax )
{
    TgGEOM_ASSERT_PARAM(TgTRUE != V(F_NaN)(pvMax));
    psBA0->m_vMax = *pvMax;
}


/* ---- V(tgGM_BA_Set_MinX) --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_BA_Set_MinX)( V(PCU_TgBOXAA) psBA0, const TYPE fMinX )
{
    TgGEOM_ASSERT_PARAM(TgTRUE != F(tgPM_NAN)(fMinX));
    psBA0->m_vMin.m.x = fMinX;
}


/* ---- V(tgGM_BA_Set_MinY) --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_BA_Set_MinY)( V(PCU_TgBOXAA) psBA0, const TYPE fMinY )
{
    TgGEOM_ASSERT_PARAM(TgTRUE != F(tgPM_NAN)(fMinY));
    psBA0->m_vMin.m.y = fMinY;
}


/* ---- V(tgGM_BA_Set_MinZ) --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_BA_Set_MinZ)( V(PCU_TgBOXAA) psBA0, const TYPE fMinZ )
{
    TgGEOM_ASSERT_PARAM(TgTRUE != F(tgPM_NAN)(fMinZ));
    psBA0->m_vMin.m.z = fMinZ;
}


/* ---- V(tgGM_BA_Set_MaxX) --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_BA_Set_MaxX)( V(PCU_TgBOXAA) psBA0, const TYPE fMaxX )
{
    TgGEOM_ASSERT_PARAM(TgTRUE != F(tgPM_NAN)(fMaxX));
    psBA0->m_vMax.m.x = fMaxX;
}


/* ---- V(tgGM_BA_Set_MaxY) --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_BA_Set_MaxY)( V(PCU_TgBOXAA) psBA0, const TYPE fMaxY )
{
    TgGEOM_ASSERT_PARAM(TgTRUE != F(tgPM_NAN)(fMaxY));
    psBA0->m_vMax.m.y = fMaxY;
}


/* ---- V(tgGM_BA_Set_MaxZ) --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_BA_Set_MaxZ)( V(PCU_TgBOXAA) psBA0, const TYPE fMaxZ )
{
    TgGEOM_ASSERT_PARAM(TgTRUE != F(tgPM_NAN)(fMaxZ));
    psBA0->m_vMax.m.z = fMaxZ;
}


/* ---- V(tgGM_BA_Query_Min) -------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(CP_TgVEC) V(tgGM_BA_Query_Min)( V(CPCU_TgBOXAA) psBA0 )
{
    return (&psBA0->m_vMin);
}


/* ---- V(tgGM_BA_Query_Max) -------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(CP_TgVEC) V(tgGM_BA_Query_Max)( V(CPCU_TgBOXAA)psBA0 )
{
    return (&psBA0->m_vMax);
}


/* ---- V(tgGM_BA_Query_MinX) ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TYPE V(tgGM_BA_Query_MinX)( V(CPCU_TgBOXAA) psBA0 )
{
    return (psBA0->m_vMin.m.x);
}


/* ---- V(tgGM_BA_Query_MinY) ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TYPE V(tgGM_BA_Query_MinY)( V(CPCU_TgBOXAA) psBA0 )
{
    return (psBA0->m_vMin.m.y);
}


/* ---- V(tgGM_BA_Query_MinZ) ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TYPE V(tgGM_BA_Query_MinZ)( V(CPCU_TgBOXAA) psBA0 )
{
    return (psBA0->m_vMin.m.z);
}


/* ---- V(tgGM_BA_Query_MaxX) ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TYPE V(tgGM_BA_Query_MaxX)( V(CPCU_TgBOXAA) psBA0 )
{
    return (psBA0->m_vMax.m.x);
}


/* ---- V(tgGM_BA_Query_MaxY) ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TYPE V(tgGM_BA_Query_MaxY)( V(CPCU_TgBOXAA) psBA0 )
{
    return (psBA0->m_vMax.m.y);
}


/* ---- V(tgGM_BA_Query_MaxZ) ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TYPE V(tgGM_BA_Query_MaxZ)( V(CPCU_TgBOXAA) psBA0 )
{
    return (psBA0->m_vMax.m.z);
}


/* ---- V(tgGM_BA_Query_SizeX) ------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TYPE V(tgGM_BA_Query_SizeX)( V(CPCU_TgBOXAA) psBA0 )
{
    return (psBA0->m_vMax.m.x - psBA0->m_vMin.m.x);
}


/* ---- V(tgGM_BA_Query_SizeY) ------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TYPE V(tgGM_BA_Query_SizeY)( V(CPCU_TgBOXAA) psBA0 )
{
    return (psBA0->m_vMax.m.y - psBA0->m_vMin.m.y);
}


/* ---- V(tgGM_BA_Query_SizeZ) ------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TYPE V(tgGM_BA_Query_SizeZ)( V(CPCU_TgBOXAA) psBA0 )
{
    return (psBA0->m_vMax.m.z - psBA0->m_vMin.m.z);
}