Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:49:16

0001 // name=scanvasTest ; gcc $name.cc -std=c++11 -I.. -lstdc++ -Wsign-compare -o /tmp/$name && VERBOSE=1 /tmp/$name
0002 #include "scanvas.h"
0003 
0004 void test_draw_int()
0005 {
0006     printf("//[test_draw_int\n"); 
0007 
0008     int xscale = 5 ; 
0009     int yscale = 3 ; 
0010     int width = 10 ; 
0011     int height = 5 ; 
0012 
0013     scanvas* c = new scanvas(width,height,xscale,yscale); 
0014 
0015     for(int ix=0 ; ix < width ;  ix++ )
0016     for(int iy=0 ; iy < height ; iy++ )
0017     {
0018         for(int dx=0 ; dx < xscale ; dx++)
0019         for(int dy=0 ; dy < yscale ; dy++)
0020         {
0021             c->draw(ix,iy,dx,dy, dx);
0022         }
0023     } 
0024     c->print(); 
0025     printf("//]test_draw_int\n"); 
0026 }
0027 
0028 void test_draw_txt()
0029 {
0030     printf("//test_draw_txt\n");
0031  
0032     int xscale = 5 ; 
0033     int yscale = 3 ; 
0034     int width = 10 ; 
0035     int height = 5 ; 
0036 
0037     scanvas* c = new scanvas(width,height,xscale,yscale); 
0038 
0039     for(int ix=0 ; ix < width ;  ix++ )
0040     for(int iy=0 ; iy < height ; iy++ )
0041     {
0042         int dx = 0 ; 
0043         for(int dy=0 ; dy < yscale ; dy++)
0044         {
0045             c->draw(ix,iy,dx,dy, "txt01");  
0046         }
0047     } 
0048     c->print(); 
0049 }
0050 
0051 void test_format_float()
0052 {
0053     printf("//test_format_float\n");
0054     float offset = 5e6 ; 
0055 
0056     char tmp[16] ;
0057     for( float val=0.f ; val < 10.f ; val+= 0.50001f )
0058     {
0059         int len = sprintf(tmp, "%7.2f", val + offset );
0060         bool expect = len == int(strlen(tmp)) ; 
0061         printf("//test_format_float  tmp:%s  len:%d  expect:%d offset %g  \n", tmp, len, expect, offset ); 
0062     }
0063 }
0064 
0065 void test_draw_float()
0066 {
0067     printf("//test_draw_float\n");
0068 
0069     int xscale = 8 ; 
0070     int yscale = 3 ; 
0071     int width = 10 ; 
0072     int height = 5 ; 
0073 
0074     scanvas* c = new scanvas(width,height,xscale,yscale); 
0075 
0076     for(int ix=0 ; ix < width ;  ix++ )
0077     for(int iy=0 ; iy < height ; iy++ )
0078     {
0079         int dx = 0 ; 
0080         for(int dy=0 ; dy < yscale ; dy++)
0081         {
0082             float val = float(dy) + 0.5f ; 
0083             c->drawf(ix,iy,dx,dy, val );  
0084         }
0085     } 
0086     c->print(); 
0087 }
0088 
0089 void test_resize()
0090 {
0091     printf("//test_resize\n");
0092 
0093     int xscale = 5 ; 
0094     int yscale = 3 ; 
0095     int width = 10 ; 
0096     int height = 5 ; 
0097 
0098     scanvas* c = new scanvas(width,height,xscale,yscale); 
0099     c->drawtest(); 
0100     c->print(); 
0101 
0102     c->resize(width*2, height*2) ; 
0103     c->drawtest(); 
0104     c->print(); 
0105 
0106     c->resize(width, height) ; 
0107     c->drawtest(); 
0108     c->print(); 
0109 }
0110 
0111 int main(int argc, char** argv)
0112 {
0113     test_draw_int(); 
0114     test_draw_txt(); 
0115     test_format_float(); 
0116     test_draw_float(); 
0117 
0118     test_resize();  
0119 
0120 
0121     return 0 ; 
0122 }
0123