SuperCard Shell Essentials

 

Point list to coordinate list

Page history last edited by DCS 3 yrs ago

Point list to coordinate list

 

Convert comma delimited coordinate list to comma/cr delimited list... one point per line.

 

In the Perl substitution below, the regular expression ([^,]*),([^,]*,?), matches zero or more characters except comma, a comma, zero or more characters except comma, followed optionally by another comma.

The enclosing parens store the matching string in positional variables $1 & $2.

The replacement side, /$1,2\r/g, replaces the string matching the regular expression with positional variable $1, a comma, positional variable $2, and a cr.

'g' specifies that every matching occurrence should be replaced.

 

function pointsToXYcr p --p = comma delimited point list
put "perl -pe 's/([^,]*,[^,]*),?/$1r/g' <<<[[p]]" into cmd
--swap every other comma with a cr, requiring digits between
--to eliminate trailing cr, add ' | perl -pe chomp' after cmd
return shell(merge(cmd))
end pointsToXYcr

 

A more strict version...

Expects numeric values, negative and/or floating point

 

The Perl regular expression, (\-?\d*\.?\d*), specifies an optional leading negative sign followed by zero or more digits, an optional decimal point, and lastly another zero or more digits.

The replacement side, is identical to the example above.

 

function pointsToXYcr p --p = comma delimited point list
put "perl -pe 's/(-?d*.?d*),(-?d*.?d*),?/$1,$2r/g' <<<[[p]]" into cmd
--swap every other comma with a cr, requiring digits between
--to eliminate trailing cr, add ' | perl -pe chomp' after cmd
return shell(merge(cmd))
end pointsToXYcr

 

Given a comma delimited coordinate list, return the 4 points which define the bounding rect, one point per line

function boundsPoints p --p = comma delimited point list
put "`" into bq
put "_coords=[[bq]]perl -pe 's/(-?d*.?d*),(-?d*.?d*),?/$1,$2n/g' <<<[[p]][[bq]] ;" into cmd
put "sort -sn -t ',' -k 1 <<<`$_coords` | sed 1q  ; "after cmd
--line 1 min x coordinate
put "sort -sn -t ',' -k 2 <<<`$_coords` | sed 1q  ; "after cmd
--line 2 min y coordinate
put "sort -snr -t ',' -k 1 <<<`$_coords` | sed 1q ; "after cmd
--line 3 max x coordinate
put "sort -snr -t ',' -k 2 <<<`$_coords` | sed 1q ; "after cmd
--line 4 max y coordinate
return shell(merge(cmd))
end boundsPoints

Comments (0)

You don't have permission to comment on this page.