Ejemplo n.º 1
0
int
AATree<Etype>::Remove( const Etype & X, BinaryNode<Etype> * & T )
{
    static int ItemFound = 0;
    static BinaryNode<Etype> *DeletePtr = NullNode;
    static BinaryNode<Etype> *LastPtr;

    if( T != NullNode )
    {
        // Step 1: Search down the tree and set LastPtr and DeletePtr
        LastPtr = T;
        if( X < T->Element )
            Remove( X, T->Left );
        else
        {
            DeletePtr = T;
            Remove( X, T->Right );
        }

        // Step 2: If at the bottom of the tree and
        //         X is present, we remove it

        if( T == LastPtr )
        {
            if( DeletePtr != NullNode && X == DeletePtr->Element )
            {
                DeletePtr->Element = T->Element;
                DeletePtr = NullNode;
                T = T->Right;
                delete LastPtr;
                ItemFound = 1;
            }
            else
                ItemFound = 0;
        }

        // Step 3: Otherwise, we are not at the bottom; rebalance
        else
            if( T->Left->Level < T->Level - 1 ||
                T->Right->Level < T->Level - 1 )
            {
                if( T->Right->Level > --T->Level )
                    T->Right->Level = T->Level;

                Skew( T );
                Skew( T->Right );
                Skew( T->Right->Right );
                Split( T );
                Split( T->Right );
            }
    }

    DeletePtr = NullNode;
    return ItemFound;
}
Ejemplo n.º 2
0
/* START: fig12_38.txt */
        AATree
        Remove( ElementType Item, AATree T )
        {
            static Position DeletePtr, LastPtr;

            if( T != NullNode )
            {
                /* Step 1: Search down tree */
                /*         set LastPtr and DeletePtr */
                LastPtr = T;
                if( Item < T->Element )
                    T->Left = Remove( Item, T->Left );
                else
                {
                    DeletePtr = T;
                    T->Right = Remove( Item, T->Right );
                }

                /* Step 2: If at the bottom of the tree and */
                /*         item is present, we remove it */
                if( T == LastPtr )
                {
                    if( DeletePtr != NullNode &&
                             Item == DeletePtr->Element )
                    {
                        DeletePtr->Element = T->Element;
                        DeletePtr = NullNode;
                        T = T->Right;
                        free( LastPtr );
                    }
                }

                /* Step 3: Otherwise, we are not at the bottom; */
                /*         rebalance */
                else
                    if( T->Left->Level < T->Level - 1 ||
                        T->Right->Level < T->Level - 1 )
                    {
                        if( T->Right->Level > --T->Level )
                            T->Right->Level = T->Level;
                        T = Skew( T );
                        T->Right = Skew( T->Right );
                        T->Right->Right = Skew( T->Right->Right );
                        T = Split( T );
                        T->Right = Split( T->Right );
                    }
            }
            return T;
        }
Ejemplo n.º 3
0
/* START: fig12_36.txt */
        AATree
        Insert( ElementType Item, AATree T )
        {
            if( T == NullNode )
            {
                /* Create and return a one-node tree */
                T = malloc( sizeof( struct AANode ) );
                if( T == NULL )
                    FatalError( "Out of space!!!" );
                else
                {
                    T->Element = Item; T->Level = 1;
                    T->Left = T->Right = NullNode;
                }
            }
            else
            if( Item < T->Element )
                T->Left = Insert( Item, T->Left );
            else
            if( Item > T->Element )
                T->Right = Insert( Item, T->Right );

            /* Otherwise it's a duplicate; do nothing */

            T = Skew( T );
            T = Split( T );
            return T;
        }
Ejemplo n.º 4
0
vec2 Line_GetNormal(line_t *l)
{
	vec2 n;

	n = l->v[1] - l->v[0];
	n = Skew(n);
	n = Normalize(n);

	return n;
}
Ejemplo n.º 5
0
int main()
{
	int Error(0);

	glm::mat4 Matrix(1);

	glm::vec3 Scale;
	glm::quat Orientation;
	glm::vec3 Translation;
	glm::vec3 Skew(1);
	glm::vec4 Perspective(1);

	glm::decompose(Matrix, Scale, Orientation, Translation, Skew, Perspective);

	return Error;
}
Ejemplo n.º 6
0
int
AATree<Etype>::Insert( const Etype & X, BinaryNode<Etype> * & T )
{
    if( T == NullNode )
    {
        T = new BinaryNode<Etype>( X, NullNode, NullNode );
        return 1;
    }
    else if( X < T->Element )
        Insert( X, T->Left );
    else if( T->Element < X )
        Insert( X, T->Right );
    else
        return 0;

    Skew( T );
    Split( T );
    return 1;
}