TextPosition_false

TextPosition, incorrect version

function getDir(self: Ref) : Int function getYDirAdj(self: Ref) : Int function getXDirAdj(self: Ref): Int function getHeightDir(self: Ref) : Int function getWidthDirAdj(self: Ref) : Int define return(x) { assert !returned returned := true res := x } function sgn(i: Int) : Int ensures i > 0 ==> result == 1 ensures i == 0 ==> result == 0 ensures i < 0 ==> result == -1 function abs(i: Int) : Int { i < 0 ? -i : i } method compare(o1: Ref, o2: Ref) returns (res: Int) requires rel(o2, 0) == rel(o1, 1) && rel(o1, 2) == rel(o1, 0) && rel(o2, 2) == rel(o2, 1) ensures ((rel(res, 0) > 0) && rel(res, 1) > 0) ==> (rel(res, 2) > 0) { var returned : Bool returned := false var retval : Int retval := 0; /* Only compare text that is in the same direction. */ if (getDir(o1) < getDir(o2)) { return(-1) }elseif (getDir(o1) > getDir(o2)) { return(1) }else{ // Get the text direction adjusted coordinates var x1 : Int x1 := getXDirAdj(o1); var x2 : Int x2 := getXDirAdj(o2); var pos1YBottom : Int pos1YBottom := getYDirAdj(o1); var pos2YBottom : Int pos2YBottom := getYDirAdj(o2); // note that the coordinates have been adjusted so 0,0 is in upper left var pos1YTop : Int pos1YTop := pos1YBottom - getHeightDir(o1); var pos2YTop : Int pos2YTop := pos2YBottom - getHeightDir(o2); var yDifference : Int yDifference := abs(pos1YBottom-pos2YBottom) //we will do a simple tolerance comparison. if( yDifference < 1 || (pos2YBottom >= pos1YTop && pos2YBottom <= pos1YBottom) || (pos1YBottom >= pos2YTop && pos1YBottom <= pos2YBottom)) { if( x1 < x2 ) { retval := -1; } else { if( x1 > x2 ) { retval := 1; } else { retval := 0; } } } elseif( pos1YBottom < pos2YBottom ) { retval := -1; } else { return(1) } if (!returned) { return(retval) } } assert returned }