Does the CD predicate syntax support the mod operator?
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