os/graphics/graphicsdeviceinterface/gdi/tgdi/TLINEDDA.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicsdeviceinterface/gdi/tgdi/TLINEDDA.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,244 @@
     1.4 +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include <e32test.h>
    1.20 +#include "TTYPES.H"
    1.21 +
    1.22 +TestLine::TestLine(const TPoint& aStart,const TPoint& aFinish, CTTypes* aTest):
    1.23 +	iStart(aStart),
    1.24 +	iFinish(aFinish),
    1.25 +	iTest(aTest)
    1.26 +	{}
    1.27 +
    1.28 +/** 
    1.29 +	TestLine::Test
    1.30 +	
    1.31 +	Method to test the functionality within the TLinearDDA class (Linear Digital Differential Analyser)
    1.32 +	Called from the TTypes test script
    1.33 +*/
    1.34 +void TestLine::Test()
    1.35 +	{
    1.36 +	iLine.Construct(iStart,iFinish);
    1.37 +	TestSingleStep();
    1.38 +	iLine.Construct(iStart,iFinish);
    1.39 +	TestSingleScanLine();
    1.40 +	iLine.Construct(iStart,iFinish);
    1.41 +	TestNextStep();
    1.42 +	iLine.Construct(iStart,iFinish);
    1.43 +	TestJumpToXCoord();
    1.44 +	iLine.Construct(iStart,iFinish);
    1.45 +	TestJumpToYCoord();
    1.46 +	iLine.Construct(iStart,iFinish);
    1.47 +	TestJumpToRect();
    1.48 +	}
    1.49 +
    1.50 +/** 
    1.51 +	TestLine::TestSingleStep
    1.52 +	
    1.53 +	Iterate through a line of pixels & confirm the final call to SingleStep rests on the last pixel
    1.54 +*/
    1.55 +void TestLine::TestSingleStep()
    1.56 +	{
    1.57 +	TPoint point;
    1.58 +	while(!iLine.SingleStep(point))
    1.59 +		{
    1.60 +		iTest->TEST((point.iX>=iStart.iX && point.iX<=iFinish.iX) || (point.iX<=iStart.iX && point.iX>=iFinish.iX));
    1.61 +		iTest->TEST((point.iY>=iStart.iY && point.iY<=iFinish.iY) || (point.iY<=iStart.iY && point.iY>=iFinish.iY));
    1.62 +		}
    1.63 +	iTest->TEST(point==iFinish);
    1.64 +	}
    1.65 +
    1.66 +/** 
    1.67 +	TestLine::TestSingleScanLine
    1.68 +	
    1.69 +	Iterate through each scaline & confirm successive scan lines are concatenated. 
    1.70 +	Confirm the last scanline holds the endppoint that was specified during construction of TLinearDDA
    1.71 +*/
    1.72 +void TestLine::TestSingleScanLine()
    1.73 +	{
    1.74 +	TPoint point1,point2;
    1.75 +	if(!iLine.SingleScanline(point1,point2))
    1.76 +		iTest->TEST(point1==iStart);
    1.77 +	TInt lastycoord=point1.iY;
    1.78 +	while(!iLine.SingleScanline(point1,point2))
    1.79 +		{
    1.80 +		iTest->TEST((point1.iX>=iStart.iX && point1.iX<=iFinish.iX) || (point1.iX<=iStart.iX && point1.iX>=iFinish.iX));
    1.81 +		iTest->TEST((point1.iY>=iStart.iY && point1.iY<=iFinish.iY) || (point1.iY<=iStart.iY && point1.iY>=iFinish.iY));
    1.82 +		iTest->TEST((point2.iX>=iStart.iX && point2.iX<=iFinish.iX) || (point2.iX<=iStart.iX && point2.iX>=iFinish.iX));
    1.83 +		iTest->TEST(point1.iY==point2.iY);
    1.84 +		iTest->TEST(Abs(point1.iY-lastycoord)==1);
    1.85 +		lastycoord=point1.iY;
    1.86 +		}
    1.87 +	iTest->TEST(point2==iFinish);
    1.88 +	}
    1.89 +
    1.90 +/** 
    1.91 +	TestLine::TestNextStep
    1.92 +	
    1.93 +	Iterate trhough a the start position of each scanline & confirm they are concatenated. 
    1.94 +	Confirm the last scanline holds the endpoint specified during TLinearDDA construction (iFinish)
    1.95 +*/
    1.96 +void TestLine::TestNextStep()
    1.97 +	{
    1.98 +	TPoint point,oldpoint;
    1.99 +	iLine.NextStep(oldpoint);
   1.100 +	iTest->TEST(oldpoint==iStart);
   1.101 +	while(!iLine.NextStep(point))
   1.102 +		{
   1.103 +		iTest->TEST((point.iX>=iStart.iX && point.iX<=iFinish.iX) || (point.iX<=iStart.iX && point.iX>=iFinish.iX));
   1.104 +		iTest->TEST((point.iY>=iStart.iY && point.iY<=iFinish.iY) || (point.iY<=iStart.iY && point.iY>=iFinish.iY));
   1.105 +		iTest->TEST(Abs(point.iY-oldpoint.iY)==1);
   1.106 +		oldpoint=point;
   1.107 +		}
   1.108 +	iTest->TEST(point==iFinish);
   1.109 +	}
   1.110 +
   1.111 +/** 
   1.112 +	TestLine::TestJumpToRect
   1.113 +	
   1.114 +	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)
   1.115 +*/
   1.116 +void TestLine::TestJumpToRect()
   1.117 +	{
   1.118 +	TPoint midpoint=iStart+iFinish;
   1.119 +	midpoint.iX>>=1;
   1.120 +	midpoint.iY>>=1;
   1.121 +	TSize rsize(Abs(iStart.iX-iFinish.iX),Abs(iStart.iY-iFinish.iY));
   1.122 +	TRect rect(TPoint(iFinish.iX-(rsize.iWidth>>1),iFinish.iY-(rsize.iHeight>>1)),rsize);
   1.123 +	TRect largerect(TPoint(iFinish.iX-(rsize.iWidth<<1),iFinish.iY-(rsize.iHeight<<1)),TSize(rsize.iWidth<<2,rsize.iHeight<<2));
   1.124 +	TRect offsetrect(rect);
   1.125 +	offsetrect.Move(iStart-iFinish);
   1.126 +	if(iFinish.iX>iStart.iX)
   1.127 +		offsetrect.Move(TPoint(-(rsize.iWidth>>2),0));
   1.128 +	else
   1.129 +		offsetrect.Move(TPoint(rsize.iWidth>>2,0));
   1.130 +	if(iFinish.iY>iStart.iY)
   1.131 +		offsetrect.Move(TPoint(0,(rsize.iHeight>>1)+4));
   1.132 +	else
   1.133 +		offsetrect.Move(TPoint(0,-(rsize.iHeight>>1)-4));
   1.134 +	TPoint intersect,point;
   1.135 +	TLinearDDA line;
   1.136 +	iLine.JumpToRect(rect);
   1.137 +	iLine.SingleStep(intersect);
   1.138 +	line.Construct(iStart,iFinish);
   1.139 +	while(!line.SingleStep(point))
   1.140 +		if(point==intersect)
   1.141 +			break;
   1.142 +	iTest->TEST(point==intersect);
   1.143 +	while(!iLine.SingleStep(intersect))
   1.144 +		{
   1.145 +		line.SingleStep(point);
   1.146 +		iTest->TEST(point==intersect);
   1.147 +		}
   1.148 +	line.SingleStep(point);
   1.149 +	iTest->TEST(point==intersect);
   1.150 +	iTest->TEST(intersect==iFinish);
   1.151 +	iLine.Construct(iStart,iFinish);
   1.152 +	iLine.JumpToRect(largerect);
   1.153 +	iLine.SingleStep(point);
   1.154 +	iTest->TEST(Abs(point.iX-iStart.iX)<=1);
   1.155 +	iTest->TEST(Abs(point.iY-iStart.iY)<=1);
   1.156 +	iLine.Construct(iStart,iFinish);
   1.157 +	iLine.JumpToRect(offsetrect);
   1.158 +	iLine.SingleStep(point);
   1.159 +	if(rsize.iWidth>rsize.iHeight)
   1.160 +		iTest->TEST(point==iStart);
   1.161 +	else
   1.162 +		iTest->TEST(Min(Abs(point.iY-offsetrect.iTl.iY),Abs(point.iY-offsetrect.iBr.iY))==1);
   1.163 +	}
   1.164 +
   1.165 +/** 
   1.166 +	TestLine::TestJumpToXCoord
   1.167 +	
   1.168 +	Test the JumpToXCoord functionailty, confirming the positions by SingleStep calls
   1.169 +*/
   1.170 +void TestLine::TestJumpToXCoord()
   1.171 +	{
   1.172 +	TInt xc1=(iStart.iX+iFinish.iX)>>1;
   1.173 +	TInt xc2=iStart.iX;
   1.174 +	TInt xc3=iFinish.iX;
   1.175 +	TInt xc4=Min(iStart.iX,iFinish.iX)-Abs(xc1);
   1.176 +	TInt xc5=Max(iStart.iX,iFinish.iX)+Abs(xc1);
   1.177 +	TInt y=0;
   1.178 +	TPoint intersect,point;
   1.179 +	TLinearDDA line;
   1.180 +	iLine.JumpToXCoord(xc1,y);
   1.181 +	line.Construct(iStart,iFinish);
   1.182 +	while(!line.SingleStep(point))
   1.183 +		if(point.iX==xc1)
   1.184 +			break;
   1.185 +	iTest->TEST(y==point.iY);
   1.186 +	while(!iLine.SingleStep(point))
   1.187 +		{
   1.188 +		line.SingleStep(intersect);
   1.189 +		iTest->TEST(point.iX==intersect.iX);
   1.190 +		iTest->TEST(point.iY==intersect.iY);
   1.191 +		}
   1.192 +	TBool done=line.SingleStep(intersect);
   1.193 +	iTest->TEST(done);
   1.194 +	iLine.Construct(iStart,iFinish);
   1.195 +	iLine.JumpToXCoord(xc2,y);
   1.196 +	iTest->TEST(y==iStart.iY);
   1.197 +	iLine.Construct(iStart,iFinish);
   1.198 +	iLine.JumpToXCoord(xc3,y);
   1.199 +	iLine.SingleStep(point);
   1.200 +	iTest->TEST(point.iX==xc3);
   1.201 +	iLine.Construct(iStart,iFinish);
   1.202 +	iLine.JumpToXCoord(xc4,y);
   1.203 +	iLine.Construct(iStart,iFinish);
   1.204 +	iLine.JumpToXCoord(xc5,y);
   1.205 +	}
   1.206 +
   1.207 +/** 
   1.208 +	TestLine::TestJumpToYCoord
   1.209 +	
   1.210 +	Test the JumpToYCoord functionailty, confirming the positions by SingleStep calls
   1.211 +*/
   1.212 +void TestLine::TestJumpToYCoord()
   1.213 +	{
   1.214 +	TInt yc1=(iStart.iY+iFinish.iY)>>1;
   1.215 +	TInt yc2=iStart.iY;
   1.216 +	TInt yc3=iFinish.iY;
   1.217 +	TInt yc4=Min(iStart.iY,iFinish.iY)-Abs(yc1);
   1.218 +	TInt yc5=Max(iStart.iY,iFinish.iY)+Abs(yc1);
   1.219 +	TInt x=0;
   1.220 +	TPoint intersect,point;
   1.221 +	TLinearDDA line;
   1.222 +	iLine.JumpToYCoord(x,yc1);
   1.223 +	line.Construct(iStart,iFinish);
   1.224 +	while(!line.SingleStep(point))
   1.225 +		if(point.iY==yc1)
   1.226 +			break;
   1.227 +	iTest->TEST(TPoint(x,yc1)==point);
   1.228 +	while(!iLine.SingleStep(point))
   1.229 +		{
   1.230 +		line.SingleStep(intersect);
   1.231 +		iTest->TEST(point==intersect);
   1.232 +		}
   1.233 +	TBool done=line.SingleStep(intersect);
   1.234 +	iTest->TEST(done);
   1.235 +	iLine.Construct(iStart,iFinish);
   1.236 +	iLine.JumpToYCoord(x,yc2);
   1.237 +	iTest->TEST(x==iStart.iX);
   1.238 +	iLine.Construct(iStart,iFinish);
   1.239 +	iLine.JumpToYCoord(x,yc3);
   1.240 +	iLine.SingleStep(point);
   1.241 +	iTest->TEST(point.iY==yc3);
   1.242 +	iLine.Construct(iStart,iFinish);
   1.243 +	iLine.JumpToYCoord(x,yc4);
   1.244 +	iLine.Construct(iStart,iFinish);
   1.245 +	iLine.JumpToYCoord(x,yc5);
   1.246 +	}
   1.247 +