Re: Error Type Check Error
- Posted by Mike <vulcan at wi?.co?nz> Nov 21, 2007
- 508 views
CK, In set_line() you are adding a floating point value with each iteration in the loop. I think you already know what this means, hehehe... What I would do is drop the end pixel from the loop but set it directly afterwards outside the loop - No problemo! Mike c.k.lester wrote: > > I'm getting a type check error when I should not be. Run this code and let > me know if you have problems, too... > > Eventually, it will say "X ERROR = 1000", but 1000 is a valid X value!!!!!! > > The type() below has become verbose for debugging purposes... :) > > }}} <eucode>include get.e > > sequence map > integer map_size > > map_size = 1000 > > map = repeat(0,map_size) -- a row of map_size columns > map = repeat(map,map_size) -- map_size rows > > type map_point(sequence s) > integer good > good = (1=1) > if length(s) != 2 then > puts(1,"LENGTH ERROR!\n") > good = (1=2) > end if > if s[1] > map_size then > puts(1,"X ERROR = ") > ?s[1] > ?map_size > good = (1=2) > end if > if s[2] > map_size then > puts(1,"Y ERROR = ") > ?s[2] > ?map_size > good = (1=2) > end if > return good > end type > > procedure set_point( map_point xy, integer depth ) > map[xy[2]][xy[1]] = depth > end procedure > > procedure set_line( map_point start_point, map_point end_point, integer depth > ) > integer x, y, c > sequence stemp, slope, point > > if start_point[1] > end_point[1] then > -- make sure the leftmost point (lowest x value) is first > stemp = start_point > start_point = end_point > end_point = stemp > end if > x = start_point[1]-end_point[1] -- -4 > y = start_point[2]-end_point[2] -- -1 > > if x < 0 then > x = -x > y = -y > end if > > if x < y then > slope = {x/y,1} > c = y > else > slope = {1,y/x} > c = x > end if > point = start_point > set_point( point, -600 ) > for t=1 to c do > point = point + slope > set_point( point, -600 ) > end for > end procedure > > procedure plot_big_line() > integer y, jump > sequence last_point, plot_point, orig_point > > y = rand( map_size ) > orig_point = {1,y} > last_point = orig_point > > set_point( last_point , -600 ) > > for t=2 to 1000 do > jump = rand(5) > if rand(2) = 1 then > y += jump > else > y -= jump > end if > if y < 1 then > y = 1 > end if > if y > map_size then > y = map_size > end if > plot_point = {t,y} > if jump = 1 then > set_point( plot_point, -600 ) > else > set_line(last_point,plot_point,-600) > end if > last_point = plot_point > end for > > printf(1,"Plotted from (%d,%d) to (%d,%d)\n",orig_point & last_point) > > end procedure > > procedure main() > integer key > > key = 'Y' > while find(key,"Yy") do > plot_big_line() > puts(1,"\tPress 'Y' to do it again.\n") > key = wait_key() > end while > > end procedure > > main()</eucode> {{{