Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sqlite/blob/master/ext/rtree/util/randomshape.tcl # sqlite [Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `sqlite / ext / rtree / util / randomshape.tcl` 88 lines ยท 2615 bytes Raw Blame History 1 #!/usr/bin/tclsh 2 # 3 # This script generates a cluster of random polygons that are useful 4 # for testing the geopoly extension. 5 # 6 # Usage: 7 # 8 # tclsh randomshape.tcl | tee x.sql | sqlite3 >x.html 9 # 10 # The output files are x.sql and x.html. Run the above multiple times 11 # until an interesting "x.html" file is found, then use the "x.sql" inputs 12 # to construct test cases. 13 # 14 proc randomenclosure {cx cy p1 p2 p3 p4} { 15 set r 0 16 set pi 3.145926 17 set pi2 [expr {$pi*2}] 18 set x0 [expr {$cx + rand()*$p3 + $p4}] 19 set ans "\[\[$x0,$cy\]" 20 while {1} { 21 set r [expr {$r+$p1+$p2*rand()}] 22 if {$r>=$pi2} break 23 set m [expr {rand()*$p3 + $p4}] 24 set x [expr {$cx+$m*cos($r)}] 25 set y [expr {$cy+$m*sin($r)}] 26 append ans ",\[$x,$y\]" 27 } 28 append ans ",\[$x0,$cy\]\]" 29 return $ans 30 } 31 proc randomshape1 {} { 32 set cx [expr {100+int(rand()*800)}] 33 set cy [expr {100+int(rand()*600)}] 34 set p1 [expr {rand()*0.1}] 35 set p2 [expr {rand()*0.5+0.5}] 36 set p3 [expr {rand()*100+25}] 37 set p4 [expr {rand()*25}] 38 return [randomenclosure $cx $cy $p1 $p2 $p3 $p4] 39 } 40 proc randomshape1_sm {} { 41 set cx [expr {100+int(rand()*800)}] 42 set cy [expr {100+int(rand()*600)}] 43 set p1 [expr {rand()*0.1}] 44 set p2 [expr {rand()*0.5+0.5}] 45 set p3 [expr {rand()*10+25}] 46 set p4 [expr {rand()*5}] 47 return [randomenclosure $cx $cy $p1 $p2 $p3 $p4] 48 } 49 proc randomshape2 {} { 50 set cx [expr {400+int(rand()*200)}] 51 set cy [expr {300+int(rand()*200)}] 52 set p1 [expr {rand()*0.05}] 53 set p2 [expr {rand()*0.5+0.5}] 54 set p3 [expr {rand()*50+200}] 55 set p4 [expr {rand()*50+100}] 56 return [randomenclosure $cx $cy $p1 $p2 $p3 $p4] 57 } 58 proc randomcolor {} { 59 set n [expr {int(rand()*5)}] 60 return [lindex {red orange green blue purple} $n] 61 } 62 63 puts {.mode list --limits off} 64 puts {.print ''} 65 puts {.print ''} 66 puts {CREATE TABLE t1(poly,clr);} 67 puts {CREATE TABLE t2(poly,clr);} 68 for {set i 0} {$i<30} {incr i} { 69 puts "INSERT INTO t1(rowid,poly,clr)" 70 puts " VALUES($i,'[randomshape1]','[randomcolor]');" 71 } 72 for {set i 30} {$i<80} {incr i} { 73 puts "INSERT INTO t1(rowid,poly,clr)" 74 puts " VALUES($i,'[randomshape1_sm]','[randomcolor]');" 75 } 76 for {set i 100} {$i<105} {incr i} { 77 puts "INSERT INTO t2(rowid,poly,clr)" 78 puts " VALUES($i,'[randomshape2]','[randomcolor]');" 79 } 80 81 puts {DELETE FROM t1 WHERE geopoly_json(poly) IS NULL;} 82 puts {SELECT geopoly_svg(poly, 83 printf('style="fill:none;stroke:%s;stroke-width:1;"',clr)) 84 FROM t1;} 85 puts {SELECT geopoly_svg(poly, 86 printf('style="fill:none;stroke:%s;stroke-width:2;"',clr)) 87 FROM t2;} 88 puts {.print ''}