View Single Post
Old 13th July 2006, 21:00   #257
jheriko
Forum King
 
jheriko's Avatar
 
Join Date: Aug 2002
Location: a twist in the fabric of space
Posts: 2,150
Send a message via ICQ to jheriko
Quote:
Originally posted by The Earthquaker
Anybody could they say why the code is so unefficient...
I am going to start from the bottom up rather than the top down so that you can fully comprehend the totality of your failure.

1.) Cache some multiplies to remove per point muls:

//frame
rlw=halfx/w; rlh=halfy/h;
opt=2*n*sqd;

//point
x=if(above(i,rej1),if(above(i,0.5),if(above(i,0.5+rej1),-rlw,(i-0.5)*opt*halfx-rlw),rlw),i*opt*halfx-rlw);
y=if(above(i,rej1),if(above(i,0.5),if(above(i,0.5+rej1),(i+rej2-1)*opt*halfy*2-rlh,rlh),(i-rej1)*opt*halfy*2-rlh),-rlh);

2.) Don't use points to draw lines when there is a line tool available. The 'lines' superscope option enables a c++/asm line drawing routine, this is orders of magnitude faster than any evallib routine...

// innit
n=4;
halfx=100; halfy=50;

// frame
rlw=halfx/w; rlh=halfy/h;
c=0;

//point
x=if(c%2,rlw,-rlw);
y=if(above(c,1),rlh,-rlh);
c=c+1;

3.) Make it do what its supposed to, notice how the rectangle resizes in a crazy way when you resize the window, you need aspect ratio correction.

// innit
n=4;
halfx=100; halfy=50;

// frame
asp=h/w;
rlw=halfx/w;
rlh=halfy/h;
c=0;

//point
x=if(c%2,rlw,-rlw);
y=if(above(c,1),rlh,-rlh);
c=c+1;

-- Jheriko

'Everything around us can be represented and understood through numbers'
jheriko is offline   Reply With Quote