r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[!REBOL2 Releases] Discuss 2.x releases

BrianH
29-Apr-2010
[1547]
But yes, good point :)
Steeve
29-Apr-2010
[1548x2]
No I want a default comparison scheme for pairs (even if it is not 
the one I think is the most usefull) . Error bombings are of no use
What about the comparison of euclidean distances of 2 coordinates 
?
BrianH
29-Apr-2010
[1550]
Bring it up with Carl for R3, or suggest it in CureCode. This is 
all a little off-topic for this group anyways - we should be in Core.
Graham
29-Apr-2010
[1551x2]
I'll try sorting ..
You can't use sort !

sort 10x10 11x11
ChristianE
29-Apr-2010
[1553x2]
Use SORT/COMPARE if the default sort order doesn't word for your 
pairs.
sort [10x10 11x11]
Graham
29-Apr-2010
[1555]
oh yeah ...
ChristianE
29-Apr-2010
[1556]
SORT takes a block
Graham
29-Apr-2010
[1557x2]
sort uses the x coordinate
should have a sort/y :)
ChristianE
29-Apr-2010
[1559x2]
sort/compare pairs func [a b] [all [a/2 < b/2]]
uses the Y coord. Use whatever sorting scheme you like.
Graham
29-Apr-2010
[1561]
yeah .... I had sort/reverse
ChristianE
29-Apr-2010
[1562]
ALL [...] is of course wrong
Graham
29-Apr-2010
[1563]
too early in the morning ... not awake yet
ChristianE
29-Apr-2010
[1564x6]
func [a b] [a/2 < b/2] would have been better
Wait, I somewhere have a handy COMPARE function for writing custom 
sort functions ...
Ok, here it is:
compare: func [

    "Returns -1, 0 or 1 if the first value is lesser, equal, greater 
    than the second value."
    a b /else "Return NONE when equal (useful to chain COMPARE)"
][
    case [a < b -1 a > b 1 else [none] true 0]
]
sort/custom some-pairs func [a b] [compare/else a/2 b/2 compare a/1 
a/2]
That would stable sort Y first, then X for a/y = b/y. Just for exemple's 
sake.
Graham
29-Apr-2010
[1570x4]
I'd suggest that pair1 > pair2 if the sum of its parts are larger 
than pair2
is a pair is greater if it is further from 0x0
as the crow flies along the co-ordinate axis
but that could mean 100x0 = 0x100 :(
Sunanda
29-Apr-2010
[1574]
or [1x-2  = -2x1] :))
Graham
29-Apr-2010
[1575]
Christian, I am just compairing two pairs :)
ChristianE
29-Apr-2010
[1576]
: )   Ok, I see! And that's where SORT 10x10 11x11 came from ;-)
Graham
29-Apr-2010
[1577]
Just a simple issue!  .... I have an image and I want to see if I 
need to enlarge it or not to fit into my box
ChristianE
29-Apr-2010
[1578x2]
INSIDE? p1 p2
Maybe that's of use?
Graham
29-Apr-2010
[1580x3]
that I didn't know
I'll try that one
how about 
100x0 = 0x100 => true
but 100x0 == 0x100 => false
ChristianE
29-Apr-2010
[1583x2]
And don't overlook OUTSIDE? p1 p2

Are you suggesting a default sort order for pair here?
because

R2>> 100x0 = 0x100
R2== false
R2>> 100x0 == 0x100
R2== false
Graham
29-Apr-2010
[1585x4]
yes, just a suggestioni
so, this means -100x0 = 100x0 = 0x100
= 0x-100
probably break too much code
ChristianE
29-Apr-2010
[1589]
I don't think you can come up with a default here. What if your PAIR! 
is talking width x length ? Than camparing would probably be (width1 
* height1) < (width2 * height2). It really depends on what you use 
pairs for ...
Tomc
29-Apr-2010
[1590x3]
CE for your compare    cmp: func [a b][ sign? a - b]
pairs can be used in more ways than any one of us will come up with 
and will have different premises as to what sort means. let it error 
right away so we know we have to be more specific in our code
CE if your compare function returns -1 0 or 1 then the resulting 
sort will be a stable sort.
ChristianE
29-Apr-2010
[1593x2]
sign?: func [

    {Returns sign of number as 1, 0, or -1 (to use as multiplier).}
    number [number! money! time!]
][

    either positive? number [1] [either negative? number [-1] [0]]
]
I don't remember exactly, but COMPARE should be a little bit faster 
and has the advantage of being to able to return NONE if desired
Graham
29-Apr-2010
[1595x2]
If we can't think of all the possibilities, perhaps we can specify 
some default behaviours which we can over ride with custom sorts 
or whatever
I don't need to see an error all the time :)