Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS Common - Geometry 3D - Rectangle.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_RT_Reset) ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_RT_Reset)( V(PCU_TgRECTANGLE) psRT0 )
{
    psRT0->m_vOrigin = V(FS_SETP)( MKL(0.0), MKL(0.0), MKL(0.0) );
    psRT0->m_avEdge[0] = V(FS_SETV)( MKL(0.0), MKL(0.0), MKL(0.0) );
    psRT0->m_avEdge[1] = V(FS_SETV)( MKL(0.0), MKL(0.0), MKL(0.0) );
    psRT0->m_vNormal = V(FS_SETV)( MKL(0.0), MKL(0.0), MKL(0.0) );
}


/* ---- V(tgGM_RT_Is_Valid) --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgBOOL V(tgGM_RT_Is_Valid)( V(CPCU_TgRECTANGLE) psRT1 )
{
    /* V(C_TgVEC)                          vNormal = V(F_CX)( psRT1->m_avEdge + 0, psRT1->m_avEdge + 1 ); */

    if (TgTRUE != V(F_Is_Point_Valid)( &psRT1->m_vOrigin ))
    {
        return (TgFALSE);
    };

    if (TgTRUE != V(F_Is_Vector_Valid)( psRT1->m_avEdge + 0 ))
    {
        return (TgFALSE);
    };

    if (TgTRUE != V(F_Is_Vector_Valid)( psRT1->m_avEdge + 1 ))
    {
        return (TgFALSE);
    };

    if ((V(F_LSQ)( psRT1->m_avEdge + 0 ) <= F( KTgEPS )))
    {
        return (TgFALSE);
    };

    if ((V(F_LSQ)( &psRT1->m_vNormal ) <= F(KTgEPS)))
    {
        return (TgFALSE);
    };

    if (V(F_LSQ)( psRT1->m_avEdge + 1 ) <= F( KTgEPS ))
    {
        return (TgFALSE);
    };

    if (TgTRUE != F(tgCM_NR0)(V(F_DOT)( psRT1->m_avEdge + 0, psRT1->m_avEdge + 1 )))
    {
        return (TgFALSE);
    };
    return (TgTRUE);
}


/* ---- V(tgGM_RT_Support_Point) ---------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(TgVEC) V(tgGM_RT_Support_Point)( V(CPCU_TgRECTANGLE) psRT1, V(CPCU_TgVEC) pvDN )
{
    const TYPE                          fAx_E0 = V(F_DOT)( pvDN, psRT1->m_avEdge + 0 );
    const TYPE                          fAx_E1 = V(F_DOT)( pvDN, psRT1->m_avEdge + 1 );
    const TYPE                          fE0 = F(tgPM_FSEL)( fAx_E0, MKL(1.0), MKL(0.0) );
    const TYPE                          fE1 = F(tgPM_FSEL)( fAx_E1, MKL(1.0), MKL(0.0) );
    V(C_TgVEC)                          tvE0 = V(F_MUL_SV)( fE0, psRT1->m_avEdge + 0 );
    V(C_TgVEC)                          tvE1 = V(F_MUL_SV)( fE1, psRT1->m_avEdge + 1 );
    V(C_TgVEC)                          tvB0 = V(F_ADD)( &tvE0, &tvE1 );

    TgGEOM_ASSERT_PARAM(TgTRUE == V(tgGM_RT_Is_Valid)(psRT1) && TgTRUE == V(F_Is_Vector_Valid)(pvDN));

    return (V(F_ADD)( &psRT1->m_vOrigin, &tvB0) );
}


/* ---- V(tgGM_RT_Area) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TYPE V(tgGM_RT_Area)( V(CPCU_TgRECTANGLE) psRT1 )
{
    V(C_TgVEC)                          vX0 = V(F_CX)( psRT1->m_avEdge + 0, psRT1->m_avEdge + 1 );

    TgGEOM_ASSERT_PARAM(TgTRUE == V(tgGM_RT_Is_Valid)(psRT1));

    return (V(F_LEN)( &vX0) );
}


/* ---- V(tgGM_RT_BA) --------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_RT_BA)( V(PCU_TgBOXAA) psBA0, V(CPCU_TgRECTANGLE) psRT1 )
{
    V(C_TgVEC)                          vX0 = V(F_ADD)( &psRT1->m_vOrigin, psRT1->m_avEdge + 0 );
    V(C_TgVEC)                          tvX1 = V(F_ADD)( &psRT1->m_vOrigin, psRT1->m_avEdge + 1 );
    V(C_TgVEC)                          tvX2 = V(F_ADD)( psRT1->m_avEdge + 0, psRT1->m_avEdge + 1 );
    V(C_TgVEC)                          tvX3 = V(F_ADD)( &psRT1->m_vOrigin, &tvX2 );

    TgGEOM_ASSERT_PARAM(TgTRUE == V(tgGM_RT_Is_Valid)(psRT1));

    V(tgGM_BA_Init_PT)( psBA0, &psRT1->m_vOrigin );
    V(tgGM_BA_Union_PT)( psBA0, &vX0 );
    V(tgGM_BA_Union_PT)( psBA0, &tvX1 );
    V(tgGM_BA_Union_PT)( psBA0, &tvX3 );
}


/* ---- V(tgGM_RT_Sweep_BA) --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_RT_Sweep_BA)( V(PCU_TgBOXAA) psBA0, V(CPCU_TgRECTANGLE) psRT1, V(CPCU_TgVEC) pvDT )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(tgGM_RT_Is_Valid)(psRT1) && TgTRUE == V(F_Is_Vector_Valid)(pvDT));

    V(tgGM_RT_BA)( psBA0, psRT1 );
    V(tgGM_BA_Sweep)( psBA0, pvDT );
}


/* ---- V(tgGM_RT_Project) ---------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_RT_Project)( PCU_TYPE ptyMin, PCU_TYPE ptyMax, V(CPCU_TgRECTANGLE) psRT1, V(CPCU_TgVEC) pvDN )
{
    const TYPE                          fAx_E0 = V(F_DOT)( pvDN, psRT1->m_avEdge + 0 );
    const TYPE                          fAx_E1 = V(F_DOT)( pvDN, psRT1->m_avEdge + 1 );
    const TYPE                          fK0 = V(F_DOT)( pvDN, &psRT1->m_vOrigin );

    TgGEOM_ASSERT_PARAM(TgTRUE == V(tgGM_RT_Is_Valid)(psRT1) && TgTRUE == V(F_Is_Vector_Valid)(pvDN));

    *ptyMin = fK0;
    *ptyMax = fK0;

    *ptyMin += F(tgPM_FSEL)( fAx_E0, MKL(0.0), fAx_E0 );
    *ptyMax += F(tgPM_FSEL)( fAx_E0, fAx_E0, MKL(0.0) );
    *ptyMin += F(tgPM_FSEL)( fAx_E1, MKL(0.0), fAx_E1 );
    *ptyMax += F(tgPM_FSEL)( fAx_E1, fAx_E1, MKL(0.0) );
}


/* ---- V(tgGM_RT_Is_Contained) ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgBOOL V(tgGM_RT_Is_Contained)( V(CPCU_TgRECTANGLE) psRT1, V(CPCU_TgVEC) pvS0 )
{
    const TYPE                          fE0_E0 = V(F_LSQ)( psRT1->m_avEdge + 0 );
    const TYPE                          fE1_E1 = V(F_LSQ)( psRT1->m_avEdge + 1 );
    V(C_TgVEC)                          vDS = V(F_SUB)( pvS0, &psRT1->m_vOrigin );
    const TYPE                          fDS_E0 = V(F_DOT)( &vDS, psRT1->m_avEdge + 0 );
    const TYPE                          fDS_E1 = V(F_DOT)( &vDS, psRT1->m_avEdge + 1 );

    TgGEOM_ASSERT_PARAM(TgTRUE == V(tgGM_RT_Is_Valid)(psRT1) && TgTRUE == V(F_Is_Point_Valid)( pvS0 ));

    return (fDS_E0 >= MKL(0.0) && fDS_E1 >= MKL(0.0) && fDS_E0 <= fE0_E0 && fDS_E1 <= fE1_E1 ? TgTRUE : TgFALSE);
}


/* ---- V(tgGM_RT_TX) --------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_RT_TX)( V(PCU_TgRECTANGLE) psRT0, M34(CPCU_TgMAT) pxM0 )
{
    TgGEOM_ASSERT_PARAM(TgTRUE != M34(F_NaN)(pxM0));

    psRT0->m_avEdge[0] = M34(F_TX_V)( pxM0, psRT0->m_avEdge + 0 );
    psRT0->m_avEdge[1] = M34(F_TX_V)( pxM0, psRT0->m_avEdge + 1 );
    psRT0->m_vNormal = M34(F_TX_V)( pxM0, &psRT0->m_vNormal );
    psRT0->m_vOrigin = M34(F_TX_P)( pxM0, &psRT0->m_vOrigin );
}


/* ---- V(tgGM_RT_Copy_TX) ---------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_RT_Copy_TX)( V(PCU_TgRECTANGLE) psRT0, V(CPCU_TgRECTANGLE) psRT1, M34(CPCU_TgMAT) pxM0 )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(tgGM_RT_Is_Valid)(psRT1) && !M34(F_NaN)(pxM0));

    psRT0->m_avEdge[0] = M34(F_TX_V)( pxM0, psRT1->m_avEdge + 0 );
    psRT0->m_avEdge[1] = M34(F_TX_V)( pxM0, psRT1->m_avEdge + 1 );
    psRT0->m_vNormal = M34(F_TX_V)( pxM0, &psRT1->m_vNormal );
    psRT0->m_vOrigin = M34(F_TX_P)( pxM0, &psRT1->m_vOrigin );
}


/* ---- V(tgGM_RT_Init_SEN) --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_RT_Init_SEN)( V(PCU_TgRECTANGLE) psRT0, V(CPCU_TgVEC) pvOrigin, V(CPCU_TgVEC) pvEdge0, V(CPCU_TgVEC) pvEdge1, V(CPCU_TgVEC) pvNormal )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Point_Valid)(pvOrigin) && TgTRUE == V(F_Is_Vector_Valid)(pvNormal));
    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Vector_Valid)(pvEdge0) && TgTRUE == V(F_Is_Vector_Valid)(pvEdge1));

    psRT0->m_vOrigin = *pvOrigin;
    psRT0->m_avEdge[0] = *pvEdge0;
    psRT0->m_avEdge[1] = *pvEdge1;
    psRT0->m_vNormal = *pvNormal;
}


/* ---- V(tgGM_RT_Init_SE) ---------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_RT_Init_SE)( V(PCU_TgRECTANGLE) psRT0, V(CPCU_TgVEC) pvOrigin, V(CPCU_TgVEC) pvEdge0, V(CPCU_TgVEC) pvEdge1 )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Vector_Valid)(pvEdge0) && TgTRUE == V(F_Is_Vector_Valid)(pvEdge1));
    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Point_Valid)(pvOrigin));

    psRT0->m_vOrigin = *pvOrigin;
    psRT0->m_avEdge[0] = *pvEdge0;
    psRT0->m_avEdge[1] = *pvEdge1;
    psRT0->m_vNormal = V(F_UCX)( pvEdge0, pvEdge1 );
}


/* ---- V(tgGM_RT_Copy) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_RT_Copy)( V(PCU_TgRECTANGLE) psRT0, V(CPCU_TgRECTANGLE) psRT1 )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(tgGM_RT_Is_Valid)(psRT1));
    memcpy( psRT0, psRT1, sizeof( V(TgRECTANGLE) ) );
}


/* ---- V(tgGM_RT_Set_Origin) ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_RT_Set_Origin)( V(PCU_TgRECTANGLE) psRT0, V(CPCU_TgVEC) pvOrigin )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Point_Valid)(pvOrigin));
    psRT0->m_vOrigin = *pvOrigin;
}


/* ---- V(tgGM_RT_Set_Edge_0) ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_RT_Set_Edge_0)( V(PCU_TgRECTANGLE) psRT0, V(CPCU_TgVEC) pvEdge0 )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Vector_Valid)(pvEdge0));

    psRT0->m_avEdge[0] = *pvEdge0;
    psRT0->m_vNormal = V(F_UCX)( pvEdge0, psRT0->m_avEdge + 1 );
}


/* ---- V(tgGM_RT_Set_Edge_1) ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_RT_Set_Edge_1)( V(PCU_TgRECTANGLE) psRT0, V(CPCU_TgVEC) pvEdge1 )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(F_Is_Vector_Valid)(pvEdge1));

    psRT0->m_avEdge[1] = *pvEdge1;
    psRT0->m_vNormal = V(F_UCX)( psRT0->m_avEdge + 0, pvEdge1 );
}


/* ---- V(tgGM_RT_Query_Origin) ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(CP_TgVEC) V(tgGM_RT_Query_Origin)( V(CPCU_TgRECTANGLE) psRT1 )
{
    return (&psRT1->m_vOrigin);
}


/* ---- V(tgGM_RT_Query_Edge_0) ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(CP_TgVEC) V(tgGM_RT_Query_Edge_0)( V(CPCU_TgRECTANGLE) psRT1 )
{
    return (psRT1->m_avEdge + 0);
}


/* ---- V(tgGM_RT_Query_Edge_1) ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(CP_TgVEC) V(tgGM_RT_Query_Edge_1)( V(CPCU_TgRECTANGLE) psRT1 )
{
    return (psRT1->m_avEdge + 1);
}


/* ---- V(tgGM_RT_Query_Normal) ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(CP_TgVEC) V(tgGM_RT_Query_Normal)( V(CPCU_TgRECTANGLE) psRT1 )
{
    return (&psRT1->m_vNormal);
}


/* ---- V(tgGM_RT_Query_Point_0) ---------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(CP_TgVEC) V(tgGM_RT_Query_Point_0)( V(CPCU_TgRECTANGLE) psRT1 )
{
    return (&psRT1->m_vOrigin);
}


/* ---- V(tgGM_RT_Query_Point_1) ---------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(TgVEC) V(tgGM_RT_Query_Point_1)( V(CPCU_TgRECTANGLE) psRT1 )
{
    return (V(F_ADD)( &psRT1->m_vOrigin, psRT1->m_avEdge + 0) );
}


/* ---- V(tgGM_RT_Query_Point_2) ---------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(TgVEC) V(tgGM_RT_Query_Point_2)( V(CPCU_TgRECTANGLE) psRT1 )
{
    return (V(F_ADD)( &psRT1->m_vOrigin, psRT1->m_avEdge + 1) );
}


/* ---- V(tgGM_RT_Query_Point_3) ---------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(TgVEC) V(tgGM_RT_Query_Point_3)( V(CPCU_TgRECTANGLE) psRT1 )
{
    V(C_TgVEC)                          vX0 = V(F_ADD)( psRT1->m_avEdge + 0, psRT1->m_avEdge + 1 );

    return (V(F_ADD)( &psRT1->m_vOrigin, &vX0) );
}


#if defined(TgCOMPILE_NATIVE_VECTOR)

/* ---- V(tgGM_RT_M_TX) ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_RT_M_TX)( V(PCU_TgRECTANGLE) psRT0, M34(CPCU_TgMAT) pxM0 )
{
    TgGEOM_ASSERT_PARAM(TgTRUE != M34(F_NaN)( pxM0 ));

    psRT0->m_vOrigin.m_mData = M34(M_TX_P)( pxM0, psRT0->m_vOrigin.m_mData );
    psRT0->m_avEdge[0].m_mData = M34(M_TX_V)( pxM0, psRT0->m_avEdge[0].m_mData );
    psRT0->m_avEdge[1].m_mData = M34(M_TX_V)( pxM0, psRT0->m_avEdge[1].m_mData );
    psRT0->m_vNormal.m_mData = M34(M_TX_V)( pxM0, psRT0->m_vNormal.m_mData );
}


/* ---- V(tgGM_RT_Copy_M_TX) -------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID V(tgGM_RT_Copy_M_TX)( V(PCU_TgRECTANGLE) psRT0, V(CPCU_TgRECTANGLE) psRT1, M34(CPCU_TgMAT) pxM0 )
{
    TgGEOM_ASSERT_PARAM(TgTRUE == V(tgGM_RT_Is_Valid)( psRT1 ) && TgTRUE != M34(F_NaN)( pxM0 ));

    psRT0->m_vOrigin.m_mData = M34(M_TX_P)( pxM0, psRT1->m_vOrigin.m_mData );
    psRT0->m_avEdge[0].m_mData = M34(M_TX_V)( pxM0, psRT1->m_avEdge[0].m_mData );
    psRT0->m_avEdge[1].m_mData = M34(M_TX_V)( pxM0, psRT1->m_avEdge[1].m_mData );
    psRT0->m_vNormal.m_mData = M34(M_TX_V)( pxM0, psRT1->m_vNormal.m_mData );
}

/*# defined(TgCOMPILE_NATIVE_VECTOR) */
#endif