How to improve this.
Author Message
How to improve this.

I've made a small program that arranges an array from smallest to
largest, it is used for polygon drawing.
Can this algoritm be made better?

And something else, I must be out of my mind, but I can't find out why
the little sub doesn't work. It prints nonsense. Normally I use shared
or global arrays which works fine in any case. I'd never dares to stuff
an array into a parameter.
I must be a complete idiot here! :-(

DEFINT A-Z

' Eight byte structure, nice for asm muls

TYPE Vertex
X   AS INTEGER
Y   AS INTEGER
Clr AS LONG                                    ' Nice 32 bit colors
END TYPE

CLS

Elements=9                                       ' Well that's enough
' to get the point :-)

DIM Polygon(1 TO Elements) AS Vertex

Polygon.Y(1)=10
Polygon.Y(2)=20

Polygon.Y(3)=100
Polygon.Y(4)=4

Polygon.Y(5)=50
Polygon.Y(6)=70

Polygon.Y(7)=34
Polygon.Y(8)=26

FOR N=1 TO Elements-1                            ' Go from left to right

FOR Nn=N TO 1 STEP -1                          ' And back
IF Polygon.Y(Nn)>Polygon.Y(Nn+1) THEN        ' Is it smaller?
SWAP Polygon.X(Nn),Polygon.X(Nn+1)         ' Swap vertexes
SWAP Polygon.Y(Nn),Polygon.Y(Nn+1)
SWAP Polygon.Clr(Nn),Polygon.Clr(Nn+1)
END IF
NEXT
NEXT

FOR N=1 TO Elements
PRINT Polygon.Y(N)                             ' Show 'em
NEXT

PRINT

OrderVertexes Elements,Polygon()                 ' Call function

SUB OrderVertexes(BYVAL Elements AS INTEGER,Polygon() AS Vertex)
' This should work!
FOR N=1 TO Elements
PRINT Polygon.X(N),Polygon.Y(N)              ' It prints nonsense,
NEXT                                           ' for some reason
END SUB                                          ' Polygon.X(N) =
Polygon.Y(N) !

Thu, 08 Aug 2002 03:00:00 GMT
How to improve this.

Most of your problem seems to stem from the positioning of the element values

Polygon(1).Y = 10
Polygon(2).Y = 20

____    _    ____      ____  _____
|  _ \  / \  / ___) __ | ___)(_   _) Don Schullian

|____//_/ \_\(____/\__/|_|     |_|    www.DASoftVSS.com
___________________________________   www.basicguru.com
Vertical Software Solutions

Quote:
>I've made a small program that arranges an array from smallest to
>largest, it is used for polygon drawing.
>Can this algoritm be made better?

>And something else, I must be out of my mind, but I can't find out why
>the little sub doesn't work. It prints nonsense. Normally I use shared
>or global arrays which works fine in any case. I'd never dares to stuff
>an array into a parameter.
>I must be a complete idiot here! :-(

>DEFINT A-Z

>' Eight byte structure, nice for asm muls

>TYPE Vertex
>  X   AS INTEGER
>  Y   AS INTEGER
>  Clr AS LONG                                    ' Nice 32 bit colors
>END TYPE

>CLS

>Elements=9                                       ' Well that's enough
>                                                 ' to get the point :-)

>DIM Polygon(1 TO Elements) AS Vertex

>Polygon.Y(1)=10
>Polygon.Y(2)=20

Fri, 09 Aug 2002 03:00:00 GMT
How to improve this.

Quote:
> And something else, I must be out of my mind, but I can't find out why
> the little sub doesn't work. It prints nonsense. Normally I use shared
> or global arrays which works fine in any case. I'd never dares to stuff
> an array into a parameter.

> TYPE Vertex
>   X   AS INTEGER
>   Y   AS INTEGER
>   Clr AS LONG                                    ' Nice 32 bit colors
> END TYPE

> DIM Polygon(1 TO Elements) AS Vertex

> Polygon.Y(1)=10

Your subscript handling is getting mixed up. You've declared an array
Polygon, with "Elements" elements of type Vertex. To access each element of
the array, you need to use a syntax such as:

Polygon(1).Y = 10

For 32-bit color, you probably also want to define Clr as an unsigned value
(DWORD) rather than a signed value (LONG).

Tue, 20 Aug 2002 03:00:00 GMT

 Page 1 of 1 [ 3 post ]

Relevant Pages