/ Check-in [8f48991d]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add the randomshape.tcl test-case generator script to the util subdirectory of the rtree extension.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 8f48991dcbb01e21d065fbba7782a6d1aebaa8065841a70a76af1e5a21f18ea4
User & Date: drh 2018-09-06 14:01:56
Context
2018-09-06
16:20
Add an "ALTER TABLE RENAME COLUMN" command. Upgrade "ALTER TABLE RENAME TABLE" so that it modifies references to the renamed table embedded in SQL view and trigger definitions. check-in: 4da59983 user: dan tags: trunk
16:17
Merge latest trunk changes into this branch. Closed-Leaf check-in: 8a28a326 user: dan tags: alter-table-rename-column
14:01
Add the randomshape.tcl test-case generator script to the util subdirectory of the rtree extension. check-in: 8f48991d user: drh tags: trunk
11:14
Fix excess memory usage in the JSON parser of GEOPOLY. check-in: 9057e27e user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Added ext/rtree/util/randomshape.tcl.

            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 {.print '<html>'}
           64  +puts {.print '<svg width="1000" height="800" style="border:1px solid black">'}
           65  +puts {CREATE TABLE t1(poly,clr);}
           66  +puts {CREATE TABLE t2(poly,clr);}
           67  +for {set i 0} {$i<30} {incr i} {
           68  +  puts "INSERT INTO t1(rowid,poly,clr)"
           69  +  puts " VALUES($i,'[randomshape1]','[randomcolor]');"
           70  +}
           71  +for {set i 30} {$i<80} {incr i} {
           72  +  puts "INSERT INTO t1(rowid,poly,clr)"
           73  +  puts " VALUES($i,'[randomshape1_sm]','[randomcolor]');"
           74  +}
           75  +for {set i 100} {$i<105} {incr i} {
           76  +  puts "INSERT INTO t2(rowid,poly,clr)"
           77  +  puts " VALUES($i,'[randomshape2]','[randomcolor]');"
           78  +}
           79  +
           80  +puts {DELETE FROM t1 WHERE geopoly_json(poly) IS NULL;}
           81  +puts {SELECT geopoly_svg(poly,
           82  +   printf('style="fill:none;stroke:%s;stroke-width:1;"',clr))
           83  +  FROM t1;}
           84  +puts {SELECT geopoly_svg(poly,
           85  +   printf('style="fill:none;stroke:%s;stroke-width:2;"',clr))
           86  +  FROM t2;}
           87  +puts {.print '<svg>'}