//=================================================================
//
// Copyright (c) Microsoft Corporation 1999 - All Rights Reserved.
//
//=================================================================

//-----------------------------------------------------------------------------
//
// Creates the "off" edge, for which only x is iterated.
//
// _CREATEOTHEREDGE_FN_NAME_    Name of the create edge function
// _GOURAUD_                    Define this to interpolate the intensity along the edge.
// _AFFINE_                     Define this to use affine texture mapping along the edge.
// _PERSPECTIVE_                Define this to use perspective texture mapping along the edge.
// _ZBUFFER_                    Define this to interpolate the z-values along the edge.
//
//-----------------------------------------------------------------------------

void _CREATEOTHEREDGE_FN_NAME_(int iTop, int iBottom)
{
    assert(g_grdRenderData.gvVertices[iBottom].y >= g_grdRenderData.gvVertices[iTop].y);

	g_grdRenderData.geOtherEdge.y  = Ceil28_4NonNeg(g_grdRenderData.gvVertices[iTop].y);

	g_grdRenderData.geOtherEdge.cy =
            Ceil28_4NonNeg(g_grdRenderData.gvVertices[iBottom].y) - g_grdRenderData.geOtherEdge.y;

	if(g_grdRenderData.geOtherEdge.cy)
	{
		long dN = g_grdRenderData.gvVertices[iBottom].y - g_grdRenderData.gvVertices[iTop].y;
		long dM = g_grdRenderData.gvVertices[iBottom].x - g_grdRenderData.gvVertices[iTop].x;
	
		long InitialNum = dM*((g_grdRenderData.geOtherEdge.y<<intSHIFT28_4) -
                              g_grdRenderData.gvVertices[iTop].y) +
                          dN*g_grdRenderData.gvVertices[iTop].x -
                          1 +
                          (dN<<intSHIFT28_4);

		FloorQuoRem(InitialNum,
                    (dN<<intSHIFT28_4),
                    g_grdRenderData.geOtherEdge.x,
                    g_grdRenderData.geOtherEdge.xError);

	    if(g_grdRenderData.geOtherEdge.cy > 1)
	    {
            if (dM >= 0)
            {
                if (dM < dN)
                {
                    g_grdRenderData.geOtherEdge.xStep = 0;
                    g_grdRenderData.geOtherEdge.xNum = dM << intSHIFT28_4;
                    goto Done;
                }
                else if (dM < (dN << 1))
                {
                    g_grdRenderData.geOtherEdge.xStep = 1;
                    g_grdRenderData.geOtherEdge.xNum = (dM - dN) << intSHIFT28_4;
                    goto Done;
                }
            }
            else
            {
                if ((dM + dN) >= 0)
                {
                    g_grdRenderData.geOtherEdge.xStep = -1;
                    g_grdRenderData.geOtherEdge.xNum = (dM + dN) << intSHIFT28_4;
                    goto Done;
                }
                else if ((dM + (dN << 1)) >= 0)
                {
                    g_grdRenderData.geOtherEdge.xStep = -2;
                    g_grdRenderData.geOtherEdge.xNum = (dM + (dN << 1)) << intSHIFT28_4;
                    goto Done;
                }
            }

		    FloorQuoRem((dM<<intSHIFT28_4),
                        (dN<<intSHIFT28_4),
                        g_grdRenderData.geOtherEdge.xStep,
                        g_grdRenderData.geOtherEdge.xNum);
Done:
		    g_grdRenderData.geOtherEdge.xDenom = dN<<intSHIFT28_4;

            // bias so we can test for 0
            g_grdRenderData.geOtherEdge.xError -= g_grdRenderData.geOtherEdge.xDenom;
        }
    }
}

