graphicsdeviceinterface/gdi/tgdi/TLINEDDA.CPP
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <e32test.h>
       
    17 #include "TTYPES.H"
       
    18 
       
    19 TestLine::TestLine(const TPoint& aStart,const TPoint& aFinish, CTTypes* aTest):
       
    20 	iStart(aStart),
       
    21 	iFinish(aFinish),
       
    22 	iTest(aTest)
       
    23 	{}
       
    24 
       
    25 /** 
       
    26 	TestLine::Test
       
    27 	
       
    28 	Method to test the functionality within the TLinearDDA class (Linear Digital Differential Analyser)
       
    29 	Called from the TTypes test script
       
    30 */
       
    31 void TestLine::Test()
       
    32 	{
       
    33 	iLine.Construct(iStart,iFinish);
       
    34 	TestSingleStep();
       
    35 	iLine.Construct(iStart,iFinish);
       
    36 	TestSingleScanLine();
       
    37 	iLine.Construct(iStart,iFinish);
       
    38 	TestNextStep();
       
    39 	iLine.Construct(iStart,iFinish);
       
    40 	TestJumpToXCoord();
       
    41 	iLine.Construct(iStart,iFinish);
       
    42 	TestJumpToYCoord();
       
    43 	iLine.Construct(iStart,iFinish);
       
    44 	TestJumpToRect();
       
    45 	}
       
    46 
       
    47 /** 
       
    48 	TestLine::TestSingleStep
       
    49 	
       
    50 	Iterate through a line of pixels & confirm the final call to SingleStep rests on the last pixel
       
    51 */
       
    52 void TestLine::TestSingleStep()
       
    53 	{
       
    54 	TPoint point;
       
    55 	while(!iLine.SingleStep(point))
       
    56 		{
       
    57 		iTest->TEST((point.iX>=iStart.iX && point.iX<=iFinish.iX) || (point.iX<=iStart.iX && point.iX>=iFinish.iX));
       
    58 		iTest->TEST((point.iY>=iStart.iY && point.iY<=iFinish.iY) || (point.iY<=iStart.iY && point.iY>=iFinish.iY));
       
    59 		}
       
    60 	iTest->TEST(point==iFinish);
       
    61 	}
       
    62 
       
    63 /** 
       
    64 	TestLine::TestSingleScanLine
       
    65 	
       
    66 	Iterate through each scaline & confirm successive scan lines are concatenated. 
       
    67 	Confirm the last scanline holds the endppoint that was specified during construction of TLinearDDA
       
    68 */
       
    69 void TestLine::TestSingleScanLine()
       
    70 	{
       
    71 	TPoint point1,point2;
       
    72 	if(!iLine.SingleScanline(point1,point2))
       
    73 		iTest->TEST(point1==iStart);
       
    74 	TInt lastycoord=point1.iY;
       
    75 	while(!iLine.SingleScanline(point1,point2))
       
    76 		{
       
    77 		iTest->TEST((point1.iX>=iStart.iX && point1.iX<=iFinish.iX) || (point1.iX<=iStart.iX && point1.iX>=iFinish.iX));
       
    78 		iTest->TEST((point1.iY>=iStart.iY && point1.iY<=iFinish.iY) || (point1.iY<=iStart.iY && point1.iY>=iFinish.iY));
       
    79 		iTest->TEST((point2.iX>=iStart.iX && point2.iX<=iFinish.iX) || (point2.iX<=iStart.iX && point2.iX>=iFinish.iX));
       
    80 		iTest->TEST(point1.iY==point2.iY);
       
    81 		iTest->TEST(Abs(point1.iY-lastycoord)==1);
       
    82 		lastycoord=point1.iY;
       
    83 		}
       
    84 	iTest->TEST(point2==iFinish);
       
    85 	}
       
    86 
       
    87 /** 
       
    88 	TestLine::TestNextStep
       
    89 	
       
    90 	Iterate trhough a the start position of each scanline & confirm they are concatenated. 
       
    91 	Confirm the last scanline holds the endpoint specified during TLinearDDA construction (iFinish)
       
    92 */
       
    93 void TestLine::TestNextStep()
       
    94 	{
       
    95 	TPoint point,oldpoint;
       
    96 	iLine.NextStep(oldpoint);
       
    97 	iTest->TEST(oldpoint==iStart);
       
    98 	while(!iLine.NextStep(point))
       
    99 		{
       
   100 		iTest->TEST((point.iX>=iStart.iX && point.iX<=iFinish.iX) || (point.iX<=iStart.iX && point.iX>=iFinish.iX));
       
   101 		iTest->TEST((point.iY>=iStart.iY && point.iY<=iFinish.iY) || (point.iY<=iStart.iY && point.iY>=iFinish.iY));
       
   102 		iTest->TEST(Abs(point.iY-oldpoint.iY)==1);
       
   103 		oldpoint=point;
       
   104 		}
       
   105 	iTest->TEST(point==iFinish);
       
   106 	}
       
   107 
       
   108 /** 
       
   109 	TestLine::TestJumpToRect
       
   110 	
       
   111 	Test the JumpToRect functionality, confirming that the start of the clipping rectangle is correctly detected (note we iterate through SingleStep to find the position exactly)
       
   112 */
       
   113 void TestLine::TestJumpToRect()
       
   114 	{
       
   115 	TPoint midpoint=iStart+iFinish;
       
   116 	midpoint.iX>>=1;
       
   117 	midpoint.iY>>=1;
       
   118 	TSize rsize(Abs(iStart.iX-iFinish.iX),Abs(iStart.iY-iFinish.iY));
       
   119 	TRect rect(TPoint(iFinish.iX-(rsize.iWidth>>1),iFinish.iY-(rsize.iHeight>>1)),rsize);
       
   120 	TRect largerect(TPoint(iFinish.iX-(rsize.iWidth<<1),iFinish.iY-(rsize.iHeight<<1)),TSize(rsize.iWidth<<2,rsize.iHeight<<2));
       
   121 	TRect offsetrect(rect);
       
   122 	offsetrect.Move(iStart-iFinish);
       
   123 	if(iFinish.iX>iStart.iX)
       
   124 		offsetrect.Move(TPoint(-(rsize.iWidth>>2),0));
       
   125 	else
       
   126 		offsetrect.Move(TPoint(rsize.iWidth>>2,0));
       
   127 	if(iFinish.iY>iStart.iY)
       
   128 		offsetrect.Move(TPoint(0,(rsize.iHeight>>1)+4));
       
   129 	else
       
   130 		offsetrect.Move(TPoint(0,-(rsize.iHeight>>1)-4));
       
   131 	TPoint intersect,point;
       
   132 	TLinearDDA line;
       
   133 	iLine.JumpToRect(rect);
       
   134 	iLine.SingleStep(intersect);
       
   135 	line.Construct(iStart,iFinish);
       
   136 	while(!line.SingleStep(point))
       
   137 		if(point==intersect)
       
   138 			break;
       
   139 	iTest->TEST(point==intersect);
       
   140 	while(!iLine.SingleStep(intersect))
       
   141 		{
       
   142 		line.SingleStep(point);
       
   143 		iTest->TEST(point==intersect);
       
   144 		}
       
   145 	line.SingleStep(point);
       
   146 	iTest->TEST(point==intersect);
       
   147 	iTest->TEST(intersect==iFinish);
       
   148 	iLine.Construct(iStart,iFinish);
       
   149 	iLine.JumpToRect(largerect);
       
   150 	iLine.SingleStep(point);
       
   151 	iTest->TEST(Abs(point.iX-iStart.iX)<=1);
       
   152 	iTest->TEST(Abs(point.iY-iStart.iY)<=1);
       
   153 	iLine.Construct(iStart,iFinish);
       
   154 	iLine.JumpToRect(offsetrect);
       
   155 	iLine.SingleStep(point);
       
   156 	if(rsize.iWidth>rsize.iHeight)
       
   157 		iTest->TEST(point==iStart);
       
   158 	else
       
   159 		iTest->TEST(Min(Abs(point.iY-offsetrect.iTl.iY),Abs(point.iY-offsetrect.iBr.iY))==1);
       
   160 	}
       
   161 
       
   162 /** 
       
   163 	TestLine::TestJumpToXCoord
       
   164 	
       
   165 	Test the JumpToXCoord functionailty, confirming the positions by SingleStep calls
       
   166 */
       
   167 void TestLine::TestJumpToXCoord()
       
   168 	{
       
   169 	TInt xc1=(iStart.iX+iFinish.iX)>>1;
       
   170 	TInt xc2=iStart.iX;
       
   171 	TInt xc3=iFinish.iX;
       
   172 	TInt xc4=Min(iStart.iX,iFinish.iX)-Abs(xc1);
       
   173 	TInt xc5=Max(iStart.iX,iFinish.iX)+Abs(xc1);
       
   174 	TInt y=0;
       
   175 	TPoint intersect,point;
       
   176 	TLinearDDA line;
       
   177 	iLine.JumpToXCoord(xc1,y);
       
   178 	line.Construct(iStart,iFinish);
       
   179 	while(!line.SingleStep(point))
       
   180 		if(point.iX==xc1)
       
   181 			break;
       
   182 	iTest->TEST(y==point.iY);
       
   183 	while(!iLine.SingleStep(point))
       
   184 		{
       
   185 		line.SingleStep(intersect);
       
   186 		iTest->TEST(point.iX==intersect.iX);
       
   187 		iTest->TEST(point.iY==intersect.iY);
       
   188 		}
       
   189 	TBool done=line.SingleStep(intersect);
       
   190 	iTest->TEST(done);
       
   191 	iLine.Construct(iStart,iFinish);
       
   192 	iLine.JumpToXCoord(xc2,y);
       
   193 	iTest->TEST(y==iStart.iY);
       
   194 	iLine.Construct(iStart,iFinish);
       
   195 	iLine.JumpToXCoord(xc3,y);
       
   196 	iLine.SingleStep(point);
       
   197 	iTest->TEST(point.iX==xc3);
       
   198 	iLine.Construct(iStart,iFinish);
       
   199 	iLine.JumpToXCoord(xc4,y);
       
   200 	iLine.Construct(iStart,iFinish);
       
   201 	iLine.JumpToXCoord(xc5,y);
       
   202 	}
       
   203 
       
   204 /** 
       
   205 	TestLine::TestJumpToYCoord
       
   206 	
       
   207 	Test the JumpToYCoord functionailty, confirming the positions by SingleStep calls
       
   208 */
       
   209 void TestLine::TestJumpToYCoord()
       
   210 	{
       
   211 	TInt yc1=(iStart.iY+iFinish.iY)>>1;
       
   212 	TInt yc2=iStart.iY;
       
   213 	TInt yc3=iFinish.iY;
       
   214 	TInt yc4=Min(iStart.iY,iFinish.iY)-Abs(yc1);
       
   215 	TInt yc5=Max(iStart.iY,iFinish.iY)+Abs(yc1);
       
   216 	TInt x=0;
       
   217 	TPoint intersect,point;
       
   218 	TLinearDDA line;
       
   219 	iLine.JumpToYCoord(x,yc1);
       
   220 	line.Construct(iStart,iFinish);
       
   221 	while(!line.SingleStep(point))
       
   222 		if(point.iY==yc1)
       
   223 			break;
       
   224 	iTest->TEST(TPoint(x,yc1)==point);
       
   225 	while(!iLine.SingleStep(point))
       
   226 		{
       
   227 		line.SingleStep(intersect);
       
   228 		iTest->TEST(point==intersect);
       
   229 		}
       
   230 	TBool done=line.SingleStep(intersect);
       
   231 	iTest->TEST(done);
       
   232 	iLine.Construct(iStart,iFinish);
       
   233 	iLine.JumpToYCoord(x,yc2);
       
   234 	iTest->TEST(x==iStart.iX);
       
   235 	iLine.Construct(iStart,iFinish);
       
   236 	iLine.JumpToYCoord(x,yc3);
       
   237 	iLine.SingleStep(point);
       
   238 	iTest->TEST(point.iY==yc3);
       
   239 	iLine.Construct(iStart,iFinish);
       
   240 	iLine.JumpToYCoord(x,yc4);
       
   241 	iLine.Construct(iStart,iFinish);
       
   242 	iLine.JumpToYCoord(x,yc5);
       
   243 	}
       
   244