a
and b
.Returns:
# Require: `a isa SpriteContext and b isa SpriteContext`
redef fun compare(a, b)
do return a.as(SpriteContext).draw_order <=> b.as(SpriteContext).draw_order
lib/gamnit/flat/flat_core.nit:1763,2--1765,76
redef fun compare(a,b) do
if a.x == b.x and a.y == b.y then return 0
if a.x - center.x >= 0.0 and b.x - center.x < 0.0 then return -1
if a.x - center.x < 0.0 and b.x - center.x >= 0.0 then return 1
if a.x - center.x == 0.0 and b.x - center.x == 0.0 then
if a.y - center.y >= 0.0 or b.y - center.y >= 0.0 then
if a.y > b.y then return -1
return 1
end
if b.y > a.y then return -1
return 1
end
var det = (a.x - center.x) * (b.y - center.y) - (b.x - center.x) * (a.y - center.y)
if det > 0.0 then return 1
if det < 0.0 then return -1
var d1 = (a.x - center.x) * (a.x - center.x) + (a.y - center.y) * (a.y - center.y)
var d2 = (b.x - center.x) * (b.x - center.x) + (b.y - center.y) * (b.y - center.y)
if d1 > d2 then return -1
return 1
end
lib/geometry/polygon.nit:340,2--361,4
redef fun compare(a,b) do
if a.x == b.x and a.y == b.y then return 0
if a.x - center.x >= 0.0 and b.x - center.x < 0.0 then return 1
if a.x - center.x < 0.0 and b.x - center.x >= 0.0 then return -1
if a.x - center.x == 0.0 and b.x - center.x == 0 then
if a.y - center.y >= 0.0 or b.y - center.y >= 0.0 then
if a.y > b.y then return 1
return -1
end
if b.y > a.y then return 1
return -1
end
var det = (a.x - center.x) * (b.y - center.y) - (b.x - center.x) * (a.y - center.y)
if det > 0.0 then return -1
if det < 0.0 then return 1
var d1 = (a.x - center.x) * (a.x - center.x) + (a.y - center.y) * (a.y - center.y)
var d2 = (b.x - center.x) * (b.x - center.x) + (b.y - center.y) * (b.y - center.y)
if d1 > d2 then return 1
return -1
end
lib/geometry/polygon.nit:368,2--389,4
redef fun compare(a, b) do
return b.similarity <=> a.similarity
end
lib/vsm/vsm.nit:397,2--399,4
# See `MEntity::compare_mentity`
redef fun compare(o1, o2) do
return o1.mentity.mentity_kind_rank <=> o2.mentity.mentity_kind_rank
end
src/model/model_index.nit:591,2--594,4
redef fun compare(o1, o2) do return o2.mentity.visibility <=> o1.mentity.visibility
src/model/model_index.nit:603,2--84
# Compare two elements in an arbitrary total order.
#
# This function is mainly used to sort elements of the set in an coherent way.
#
# ~~~~
# var pos = new POSet[String]
# pos.add_chain(["A", "B", "C", "D", "E"])
# pos.add_chain(["A", "X", "C", "Y", "E"])
# var a = ["X", "C", "E", "A", "D"]
# pos.sort(a)
# assert a == ["E", "D", "C", "X", "A"]
# ~~~~
#
# POSet are not necessarily total orders because some distinct elements may be incomparable (neither greater or smaller).
# Therefore this method relies on arbitrary linear extension.
# This linear extension is a lawful total order (transitive, anti-symmetric, reflexive, and total), so can be used to compare the elements.
#
# The abstract behavior of the method is thus the following:
#
# ~~~~nitish
# if a == b then return 0
# if has_edge(b, a) then return -1
# if has_edge(a, b) then return 1
# return -1 or 1 # according to the linear extension.
# ~~~~
#
# Note that the linear extension is stable, unless a new node or a new edge is added.
redef fun compare(a, b)
do
var ae = self.elements[a]
var be = self.elements[b]
var res = ae.tos.length <=> be.tos.length
if res != 0 then return res
return elements[a].count <=> elements[b].count
end
lib/poset/poset.nit:288,2--322,4