• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Does the CD predicate syntax support the mod operator?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Does the CD predicate syntax support the mod operator?


  • Subject: Does the CD predicate syntax support the mod operator?
  • From: Scott Ellsworth <email@hidden>
  • Date: Tue, 17 May 2005 17:35:49 -0700

Hi, all.

I am trying to convert a nasty critter involving a mod, an abs, and a few comparisons into a clean predicate. Before sinking a lot of time into it, is there an official comment on whether CD will handle the mod operator well?

I want to write a predicate that will retrieve all hexes within a distance of $DISTANCE of the hexagon at $ROW and $COLUMN, in hex count space, not euclidean space.

The algorithm for this is somewhat painful:

    int originNormCol = 2*origin.col+2;
    int originNormRow = 4*origin.row+4;
    if (origin.col % 2 == 0) originNormRow += 2;
    int destinationNormCol = 2*destination.col+2;
    int destinationNormRow = 4*destination.row+4;
    if (destination.col % 2 == 0) destinationNormRow += 2;
    int deltaNormCol = abs(originNormCol-destinationNormCol);
    int deltaNormRow = abs(originNormRow-destinationNormRow);
    if (deltaNormCol>deltaNormRow){
        return deltaNormCol/2;
    } else {
        return (deltaNormCol + deltaNormRow)/4;
    }

I see two ways to approach this:

1. Add the normRow and normCol co-ordinates, even though they are redundant, to my model, then adjust setRow and setCol to also call setNormRow and setNormCol. The predicate becomes easy - a subtraction, an abs, and an if - at the cost of duplicated data that might become inconsistent. I will have to do this if % is not a supported operation.

2. Write a really hairy predicate that unwraps the above algorithm. This will require %, abs, and an exciting set of conditions.

Is there a third option out there?

On a related note, how common is denormalization? I already see another case where I will end up with redundant data - the hex number string 0302 has thus far been best expressed as a string, but now it appears it should be expressed as an absolute row and column integer.

Scott
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: NSBezierPath question?
  • Next by Date: Figuring out which values are selected in an NSTableView
  • Previous by thread: NSBezierPath question?
  • Next by thread: Figuring out which values are selected in an NSTableView
  • Index(es):
    • Date
    • Thread