swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: More Swarm Beginner mistakes/questions


From: Ken Cline
Subject: Re: More Swarm Beginner mistakes/questions
Date: Tue, 2 Dec 1997 12:18:20 -0500 (EST)


On Mon, 1 Dec 1997, Paul Johnson wrote:

> Lesson 1.  Lists swallow objects and erase them.
> I was surprised that an object, called "current", turned up
> empty after I added this code:  

Like Rob, I've never seen this one.

> Lesson 2.  There are some funky problems that can happen if you choose
> swarm-official-names for things!  ...

Yup!  Unlike C++ and Java, objC doesn't support multiple
method signatures, AFAIK, however there may be a compiler
argument which tells it to ignore conflicting definitions.
Another alternative is use `id's wherever possible, but this
doesn't help you with the getX/getY conflict.

> Lesson 3. The Grid2d space for zoomRaster accepts only integers,
> right? so the drawSelfOn method would not work if the X and Y
> are doubles.  However, if I just cast them as ints, I get "rounded"
> output, right, so 14.544 is seen as 14 and the grid looks approximate?
> Right? 

Right. Technically the values are truncated and, one way or
another, this would happen, ie you can't draw something at
pixel 14.544.  BTW, if you want to round then one technique
would be to add 0.5 before casting to an int.

> Lesson 4. The lack of a matrix algebra/vector passing ability seems to be a
> problem for me.  If the ideal array were a ten dimensional thing, it would get
> really inconvenient to individually refer to coordinates.  I've gotten around
> some problems by passing in an object that contains such an array.  That
> works, until one object has to tell the other what its array is. The only
> way I can figure to pass them out is to write one method for each dimension 
> and
> give them one floating point number at a time. (Hence a method getPolX has to 
> be
> written that has "return ideal[0]" and a method getPolY has a "return 
> ideal[1]"
> and then the object that receives those messages converts them back into an
> array with newarray[0]=[thatobject getX] and newarray[1]=[thatobject getY].

`getX', `getY', etc. only make sense for about 3 dimensions,
ie x, y, and z.  If you are doing more than 3 dimensions then 
why not have a more general method:

    -(double) getCoordinate: (int) index {
       if ( index > DIMENSION ) 
          raiseEvent( InvalidArgument, "index > Dimension!\n" );
       return ideal[ index ];
    }

or possibly:

    -(BOOL) getCoordinates: (double []) dblArray 
                      From: (int) start To: (int) end {
       int i;

       if ( !dblArray ) {
          raiseEvent( WarningMessage, "dblArray is nil ?\n" );
          return FALSE;
       }

       if ( start > end ) {
          raiseEvent( WarningMessage, "start > end ?\n" );
          return FALSE;
       }

       if ( sizeof(dblArray) / sizeof( double ) <= end - start ) {
          raiseEvent( WarningMessage, "dblArray is too small?\n" );
          return FALSE;
       }

       for ( i = start; i <= end; i++ ) {
          dblArray[ i ] = ideal[ i ];
       }

       return TRUE;

    }

I haven't tested any of this, of course.  I hope this helps.


Ken.


PS: Personally, I prefer to make dblArray a `double *' 
instead of a `double []', but then you can't check the size.
Of course, checking the size isn't necessary so may want to
just take that out ayway.


_________________________________________________________
Ken Cline                             address@hidden
SAIC                                 VOICE (410) 571-0413
Annapolis, MD                          FAX (301) 261-8427





                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.
                  ==================================


reply via email to

[Prev in Thread] Current Thread [Next in Thread]