SUB(sort_y) //==================================================================
$len = ARRSIZE($corr)
FOR($a=1, $a < ($len-2), 2)
$min = $corr[$a]
$ind = $a
FOR($b=$a+2, $b < $len, 2)
INC($iter)
IF($corr[$b] < $min)
$min = $corr[$b]
$ind = $b
END_IF
END_CYC
$X = $corr[$ind-1]
$Y = $corr[$ind]
//LOGWRITE("$min = ", $min, " ", $X, " - ", $Y)
$corr[$ind-1] = $corr[$a-1]
$corr[$ind] = $corr[$a]
$corr[$a-1] = $X
$corr[$a] = $Y
INC($rearrangement)
END_CYC
END_SUB
SUB(sort_x, $st, $en) //========================================================
//LOGWRITE("sort_x. $st/$en ", $st, "/", $en)
IF($st ! $en)
FOR($a=$st, $a < $en, 2)
$min = $corr[$a]
$ind = $a
FOR($b=$a+2, $b <= $en, 2)
INC($iter)
IF($corr[$b] < $min)
$min = $corr[$b]
$ind = $b
END_IF
END_CYC
$X = $corr[$ind]
$Y = $corr[$ind+1]
//LOGWRITE("$min = ", $min, " ", $X, " - ", $Y)
$corr[$ind] = $corr[$a]
$corr[$ind+1] = $corr[$a+1]
$corr[$a] = $X
$corr[$a+1] = $Y
INC($rearrangement)
END_CYC
END_IF
END_SUB
SUB(sort_yx) //================================================================
// сортируем по X, пары с одинаковым Y (с допуском limit_y) len_equal_y
$start = 0
$end = 0
$old = $corr[1]
FOR($i=3, $i < $len, 2)
INC($iter)
IF(ABS($corr[$i] - $old) <= $limit_y)
$old = $corr[$i]
$end = $i - 1
ELSE
$old = $corr[$i]
sort_x($start, $end)
$start = $i - 1
$end = $i - 1
END_IF
END_CYC
sort_x($start, $end)
END_SUB
//==============================================================================
UNDEFINE($ARR_SCAN)
GETSCREEN
FOR($Varr=1, $Varr < 30)
SCANPICTURE($corr, 0,0, $_xmax,$_ymax, STRCONCAT($Varr, ".bmp"))
WAITMS(5)
END_CYC
$limit_y = 0 // допуск по y когда считаются в одном ряду
sort_y()
sort_yx()
$scan_size = ARRSIZE($corr)
FOR($ARR_NUM=$scan_size-2, $ARR_NUM >= 0, -2)
$X = $corr[$ARR_NUM]
$Y = $corr[$ARR_NUM+1]
LCLICK($X + 3, $Y + 3)
WAITMS(100)
END_CYC