Board index » delphi » What am I doing wrong?

What am I doing wrong?

Having trouble here .. Im making a polygon filler, and I'm having trouble
scanning the sides of it. I started coding optimized right at the begining, but
as probelms started to surface, i did it as simple as possible, using real's and
all, but it still wont work. So, I guess I'm doing something fundamentally
wrong. The rutine is included here.. Its supposed to be able to draw lines with
only one X pixel for every Y line. This -should- be simple.. argh!

I'd appreciate a fix for it, preforably -with- an explenaiton :)

-------- CUT --------

Procedure SwapInt(var a,b:Integer);
Var C : Integer;
Begin
     c:=a;
     a:=b;
     b:=c;
End;

Procedure ScanLine(x1,y1,x2,y2,c:Integer);
Var Step  : Real;
    Xcount: Real;
    Teller: Integer;
Begin
     If Y1=Y2 then Exit;
     If Y2<Y1 then
     Begin
      SwapInt(Y1,Y2);
      SwapInt(X1,X2);
     End;
     Step:=(X2-X1)/(Y2-Y1);
     XCount:=Step;
     For Teller:=Y1+1 to Y2 do
     Begin
      Mem[$a000:Round(XCount)+Teller*320]:=C;
      XCount:=XCount+Step;
     End;
End;
-------- CUT --------

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Kim Robert Blix  ( kb...@sn.no  &  http://home.sn.no/~kblix )

 "How do you shoot the devil in the back?"
 "What if you miss?" -Verbal Kint
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

 

Re:What am I doing wrong?


Kim Robert Blix <kb...@sn.no> wrote in article
<2bbb12d9.173...@news.sn.no>...

Quote

> Having trouble here .. Im making a polygon filler, and I'm having trouble
> scanning the sides of it. I started coding optimized right at the
begining, but
> as probelms started to surface, i did it as simple as possible, using
real's and
> all, but it still wont work. So, I guess I'm doing something
fundamentally
> wrong. The rutine is included here.. Its supposed to be able to draw
lines with
> only one X pixel for every Y line. This -should- be simple.. argh!

> I'd appreciate a fix for it, preforably -with- an explenaiton :)

> -------- CUT --------

> Procedure SwapInt(var a,b:Integer);
> Var C : Integer;
> Begin
>      c:=a;
>      a:=b;
>      b:=c;
> End;

> Procedure ScanLine(x1,y1,x2,y2,c:Integer);
> Var Step  : Real;
>     Xcount: Real;
>     Teller: Integer;
> Begin
>      If Y1=Y2 then Exit;
>      If Y2<Y1 then
>      Begin
>       SwapInt(Y1,Y2);
>       SwapInt(X1,X2);
>      End;
>      Step:=(X2-X1)/(Y2-Y1);
>      XCount:=Step;
>      For Teller:=Y1+1 to Y2 do
>      Begin
>       Mem[$a000:Round(XCount)+Teller*320]:=C;
>       XCount:=XCount+Step;
>      End;
> End;

Why are you starting xcount at step? Also use fixed point arithmetic.

ramiro

Re:What am I doing wrong?


"Ramiro " <ram...@dcccd.edu> once said:

Quote

>> Procedure SwapInt(var a,b:Integer);
>> Var C : Integer;
>> Begin
>>      c:=a;
>>      a:=b;
>>      b:=c;
>> End;

>> Procedure ScanLine(x1,y1,x2,y2,c:Integer);
>> Var Step  : Real;
>>     Xcount: Real;
>>     Teller: Integer;
>> Begin
>>      If Y1=Y2 then Exit;
>>      If Y2<Y1 then
>>      Begin
>>       SwapInt(Y1,Y2);
>>       SwapInt(X1,X2);
>>      End;
>>      Step:=(X2-X1)/(Y2-Y1);
>>      XCount:=Step;
>>      For Teller:=Y1+1 to Y2 do
>>      Begin
>>       Mem[$a000:Round(XCount)+Teller*320]:=C;
>>       XCount:=XCount+Step;
>>      End;
>> End;

>Why are you starting xcount at step? Also use fixed point arithmetic.

I start Xcount at step because the I -indended- to draw the first pixel outside
the loop.. I just forgot.. thats not the problem though. The problem is that the
line will just draw under certain conditions. If you do a

Repeat
        Line(random320,random200,random320,random200,random255);
until keypressed

then it should become obvious that it doesnt work. What do you mean by Fixed
point arithmetic" btw?

Quote
>ramiro

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Kim Robert Blix  ( kb...@sn.no  &  http://home.sn.no/~kblix )

 "How do you shoot the devil in the back?"
 "What if you miss?" -Verbal Kint
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Re:What am I doing wrong?


Re:What am I doing wrong?


Quote
>> Ramiro:
> >Why are you starting xcount at step? Also use fixed point arithmetic.
[...]
> Kim Robert Blix:
> then it should become obvious that it doesnt work. What do you mean by
Fixed
> point arithmetic" btw?

        Fixed point math is another way of doing floating point arithmethic
operations using INTEGERS (!). That's it.
        Why would we want to use Integers instead of a Real variable? Because
working with Reals is s-l-o-w, because Reals are 6-bytes long while
integers are 2-bytes long (thought they don't have the same decimal
accuracy) and sometimes you need the most speed possible. Fixed point math
can be applyied to other types, not only integers.

                                                Jaguar/Negative Edge

Re:What am I doing wrong?


Jaguar of Negative Edge wrote:

Quote

> >> Ramiro:
> > >Why are you starting xcount at step? Also use fixed point arithmetic.
> [...]
> > Kim Robert Blix:
> > then it should become obvious that it doesnt work. What do you mean by
> Fixed
> > point arithmetic" btw?

>         Fixed point math is another way of doing floating point arithmethic
> operations using INTEGERS (!). That's it.
>         Why would we want to use Integers instead of a Real variable? Because
> working with Reals is s-l-o-w, because Reals are 6-bytes long while
> integers are 2-bytes long (thought they don't have the same decimal
> accuracy) and sometimes you need the most speed possible. Fixed point math
> can be applyied to other types, not only integers.

>                                                 Jaguar/Negative Edge

How do you implement fixed point math without losing precision?
//jan

Re:What am I doing wrong?


Jaguar of Negative Edge wrote:

Quote

> >> Ramiro:
> > >Why are you starting xcount at step? Also use fixed point arithmetic.
> [...]
> > Kim Robert Blix:
> > then it should become obvious that it doesnt work. What do you mean by
> Fixed
> > point arithmetic" btw?

>         Fixed point math is another way of doing floating point arithmethic
> operations using INTEGERS (!). That's it.
>         Why would we want to use Integers instead of a Real variable? Because
> working with Reals is s-l-o-w, because Reals are 6-bytes long while
> integers are 2-bytes long (thought they don't have the same decimal
> accuracy) and sometimes you need the most speed possible. Fixed point math
> can be applyied to other types, not only integers.

>                                                 Jaguar/Negative EdgeHow do you implement fixed point math without lossing the

precison?
//jan

Re:What am I doing wrong?


Jaguar of Negative Edge wrote:

Quote

> >> Ramiro:
> > >Why are you starting xcount at step? Also use fixed point arithmetic.
> [...]
> > Kim Robert Blix:
> > then it should become obvious that it doesnt work. What do you mean by
> Fixed
> > point arithmetic" btw?

>         Fixed point math is another way of doing floating point arithmethic
> operations using INTEGERS (!). That's it.
>         Why would we want to use Integers instead of a Real variable? Because
> working with Reals is s-l-o-w, because Reals are 6-bytes long while
> integers are 2-bytes long (thought they don't have the same decimal
> accuracy) and sometimes you need the most speed possible. Fixed point math
> can be applyied to other types, not only integers.

>                                                 Jaguar/Negative EdgeHow do you implement fixed point math without lossing the

precison?
//jan

Re:What am I doing wrong?


--["Jaguar of Negative Edge" <jag...@correo.dnet.com.pe> was heard to
say]--

Quote
>>> Ramiro:
>> >Why are you starting xcount at step? Also use fixed point arithmetic.
>[...]
>> Kim Robert Blix:
>> then it should become obvious that it doesnt work. What do you mean by
>Fixed
>> point arithmetic" btw?
>    Fixed point math is another way of doing floating point arithmethic
>operations using INTEGERS (!). That's it.
>    Why would we want to use Integers instead of a Real variable? Because
>working with Reals is s-l-o-w, because Reals are 6-bytes long while
>integers are 2-bytes long (thought they don't have the same decimal
>accuracy) and sometimes you need the most speed possible. Fixed point math
>can be applyied to other types, not only integers.

oh dear.  Someone has never heard of the pentium processor and it's
fpu.  Nowadays you can run off a floating point calculation faster
than an integer calculation, (and after that, you can start pipelining
calculations and make then *really* fast).

MdP
Veteran of the Bermuda Exploration Venture 1991-1953

Re:What am I doing wrong?


Quote
Matt Parkins wrote:
> >working with Reals is s-l-o-w, because Reals are 6-bytes long while
> >integers are 2-bytes long

> oh dear.  Someone has never heard of the pentium processor and it's
> fpu.  Nowadays you can run off a floating point calculation faster
> than an integer calculation, (and after that, you can start pipelining
> calculations and make then *really* fast).

Are 6-byte reals handled by the FPU? I don't know. I would make a test
program, but I'm sure someone here already knows the answer.

In any case, one can't always count on a Pentium or an FPU being present
on the target machine.

AME

Re:What am I doing wrong?


"Jaguar of Negative Edge" <jag...@correo.dnet.com.pe> once said:

Quote
>>> Ramiro:
>> >Why are you starting xcount at step? Also use fixed point arithmetic.
>[...]
>> Kim Robert Blix:
>> then it should become obvious that it doesnt work. What do you mean by
>Fixed
>> point arithmetic" btw?

>    Fixed point math is another way of doing floating point arithmethic
>operations using INTEGERS (!). That's it.

ahhh.. Then say "fixed point" :) dont confuse me with arithmetic .. I dont even
know what that means.
If RAMIRO had the patience to read through my post before he replay'd he woulda
known that I have allready made a fast version. that is -not- the problem. I had
difficulties, so I recoded the rutine to be as "basic" and "friendly" as
possible, to figure out what the problems are . But I didnt. It still wont work.

Quote
>    Why would we want to use Integers instead of a Real variable? Because
>working with Reals is s-l-o-w, because Reals are 6-bytes long while
>integers are 2-bytes long (thought they don't have the same decimal
>accuracy) and sometimes you need the most speed possible. Fixed point math
>can be applyied to other types, not only integers.

I am prefectly aware of what fixed point is. Here is a newsflash for you though:
on a pentium, floatingpoint operations are faster then int's.

YES! I know -my- code would have been faster with ints, but the above code, that
I had problems with, where NOT meant to be fast. :)

Quote
>                                            Jaguar/Negative Edge

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Kim Robert Blix  ( kb...@sn.no  &  http://home.sn.no/~kblix )

 "How do you shoot the devil in the back?"
 "What if you miss?" -Verbal Kint
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Re:What am I doing wrong?


Quote
Alan M. Evans wrote:

> Matt Parkins wrote:

> > >working with Reals is s-l-o-w, because Reals are 6-bytes long while
> > >integers are 2-bytes long

> > oh dear.  Someone has never heard of the pentium processor and it's
> > fpu.  Nowadays you can run off a floating point calculation faster
> > than an integer calculation,

This most definitely is not true of any Intel cpu, the Digital Alpha
cpu's, or the PowerPC cpu's.  If an operation can be done with integers
on those cpu's, it really pays to use integers if you have to do a lot
of math.

Quote
> (and after that, you can start pipelining calculations and make then *really* fast).

> Are 6-byte reals handled by the FPU? I don't know. I would make a test
> program, but I'm sure someone here already knows the answer.

Buried somewhere in the BP/TP manuals is a comment that all fpu
operations are done as extendeds.

Rob

Re:What am I doing wrong?


The unanswered question was how to use integers and avoid losing
precision.

The big real types keep 17-18 digist of precision. This should be enough
for anything but the most demanding scientific work.

Rick
Rick H...@aol.com

Re:What am I doing wrong?


Quote
Rob Stow <s...@sask.usask.ca> wrote:
>Alan M. Evans wrote:

>> Are 6-byte reals handled by the FPU? I don't know. I would make a test
>> program, but I'm sure someone here already knows the answer.

>Buried somewhere in the BP/TP manuals is a comment that all fpu
>operations are done as extendeds.

Yes, FPU operations are done as extended, but 6-byte reals
are not FPU variables.  The last time I looked at TP 6.0, BP
7.0, and TPW 1.5 RTLs, 6-byte reals were handle in software.

Page 293 of the BP 7.0 Language Guide states that 6-byte
real function results are returned in DX:BX:AX, page 294
continues by stating that 80x87 type results (single,
double, extended, comp) are returned in the co-processors
top-of-stack register ST(0).

I have't tested, but I would assume that when we mix FPU
types with Turbo's 6-byte real that the compiler invokes a
call to the appropriate system (or Windows Emulator
Interface) routine (FRealExt or FExtReal) to convert from
one form to the other.

    ...red

Re:What am I doing wrong?


ma...@gremlin.co.uk (Matt Parkins) once said:

Quote
>oh dear.  Someone has never heard of the pentium processor and it's
>fpu.  Nowadays you can run off a floating point calculation faster
>than an integer calculation, (and after that, you can start pipelining
>calculations and make then *really* fast).

You have to take full use of the P pipelining to make them faster then fixed
point in the first place.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Kim Robert Blix  ( kb...@sn.no  &  http://home.sn.no/~kblix )

 "How do you shoot the devil in the back?"
 "What if you miss?" -Verbal Kint
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Other Threads