Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

website update

  • Loading branch information...
commit e81846a8925ac645eaf66950623747383f0428ed 1 parent dc406a0
@gka gka authored
Showing with 13,717 additions and 3 deletions.
  1. +1 −0  _layouts/default.html
  2. +29 −0 blog/index.html
  3. +34 −0 docs/src/kartograph/__init__.html
  4. +858 −0 docs/src/kartograph/cartogram.html
  5. +183 −0 docs/src/kartograph/cli.html
  6. +94 −0 docs/src/kartograph/errors.html
  7. +114 −0 docs/src/kartograph/filter.html
  8. +50 −0 docs/src/kartograph/geometry/__init__.html
  9. +195 −0 docs/src/kartograph/geometry/bbox.html
  10. +279 −0 docs/src/kartograph/geometry/geometry.html
  11. +519 −0 docs/src/kartograph/geometry/line.html
  12. +141 −0 docs/src/kartograph/geometry/point.html
  13. +625 −0 docs/src/kartograph/geometry/polygon.html
  14. +196 −0 docs/src/kartograph/geometry/utils.html
  15. +250 −0 docs/src/kartograph/geometry/view.html
  16. +326 −0 docs/src/kartograph/kartograph.html
  17. +68 −0 docs/src/kartograph/layersource/__init__.html
  18. +55 −0 docs/src/kartograph/layersource/layersource.html
  19. +2,669 −0 docs/src/kartograph/layersource/shapefile.html
  20. +513 −0 docs/src/kartograph/layersource/shplayer.html
  21. +1,227 −0 docs/src/kartograph/map.html
  22. +329 −0 docs/src/kartograph/maplayer.html
  23. +533 −0 docs/src/kartograph/options.html
  24. +219 −0 docs/src/kartograph/proj/__init__.html
  25. +432 −0 docs/src/kartograph/proj/base.html
  26. +320 −0 docs/src/kartograph/proj/conic.html
  27. +426 −0 docs/src/kartograph/proj/cylindrical.html
  28. +1,014 −0 docs/src/kartograph/proj/pseudocylindrical.html
  29. +100 −0 docs/src/kartograph/renderer/__init__.html
  30. +272 −0 docs/src/kartograph/renderer/kml.html
  31. +538 −0 docs/src/kartograph/renderer/svg.html
  32. +85 −0 docs/src/kartograph/simplify/__init__.html
  33. +108 −0 docs/src/kartograph/simplify/distance.html
  34. +221 −0 docs/src/kartograph/simplify/douglas_peucker.html
  35. +133 −0 docs/src/kartograph/simplify/mpoint.html
  36. +152 −0 docs/src/kartograph/simplify/unify.html
  37. +218 −0 docs/src/kartograph/simplify/visvalingam.html
  38. +186 −0 docs/src/pycco.css
  39. BIN  img/logo-small.png
  40. +3 −3 showcase/italia/map-italy.yaml
  41. +2 −0  showcase/italia/tmp.svg
View
1  _layouts/default.html
@@ -38,6 +38,7 @@
<li{% if page.url == "/index.html" %} class="active" {% endif %}><a href="/">Hello Kartograph</a></li>
<li{% if page.url contains "/showcase/" %} class="active" {% endif %}><a href="/showcase/">Showcase</a></li>
<li{% if page.url contains "/about/" %} class="active" {% endif %}><a href="/about/">How does it work?</a></li>
+ <!-- <li{% if page.url contains "blog.kartograph.org" %} class="active" {% endif %}><a href="blog.kartograph.org">Blog</a></li> -->
<li><a target="_blank" href="http://github.com/kartograph/">Fork on Github</a></li>
<li><a target="_blank" href="http://twitter.com/#!/kartographjs/">Say Hi on Twitter</a></li>
</ul>
View
29 blog/index.html
@@ -0,0 +1,29 @@
+---
+title: Blog
+layout: default
+headline: Get it running
+tagline: Three steps to your map
+scripts: [jquery, '/js/jquery.min.js']
+---
+
+<div class="row k-howto">
+ <div class="span1 k-big-number"><span>1</span></div>
+ <div class="span5">
+ <p>The first step is to create the SVG map you need using the Python library that comes with Kartograph. Alternativly you can look through existing maps. In the future, there even might be a web service that helps you to generate SVG maps without coding.</p>
+ <p>The next step is to set up your map</p>
+ <pre class="prettyprint">
+ var map = $K.map('#mymap');
+ </pre>
+ </div>
+</div>
+
+<div class="row">
+ <div class="span1 k-big-number"><span>2</span></div>
+ <div class="span5">
+ <p>The first step is to create the SVG map you need using the Python library that comes with Kartograph. Alternativly you can look through existing maps. In the future, there even might be a web service that helps you to generate SVG maps without coding.</p>
+ <p>The next step is to set up your map</p>
+ <code>
+ var map = $K.map('#mymap');
+ </code>
+ </div>
+</div>
View
34 docs/src/kartograph/__init__.html
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
+ <title>__init__.py</title>
+ <link rel="stylesheet" href="../pycco.css">
+</head>
+<body>
+<div id="background"></div>
+<div id='container'>
+ <div class='section'>
+ <div class='docs'><h1>__init__.py</h1></div>
+ </div>
+ <div class='clearall'>
+ <div class='section' id='section-0'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-0'>#</a>
+ </div>
+
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre><span class="kn">from</span> <span class="nn">kartograph</span> <span class="kn">import</span> <span class="n">Kartograph</span>
+<span class="kn">from</span> <span class="nn">kartograph</span> <span class="kn">import</span> <span class="n">verbose</span>
+<span class="kn">from</span> <span class="nn">map</span> <span class="kn">import</span> <span class="n">projections</span>
+
+<span class="n">__all__</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;Kartograph&#39;</span><span class="p">,</span> <span class="s">&#39;projections&#39;</span><span class="p">,</span> <span class="s">&#39;verbose&#39;</span><span class="p">]</span>
+
+</pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+</div>
+</body>
View
858 docs/src/kartograph/cartogram.html
@@ -0,0 +1,858 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
+ <title>cartogram.py</title>
+ <link rel="stylesheet" href="../pycco.css">
+</head>
+<body>
+<div id="background"></div>
+<div id='container'>
+ <div class='section'>
+ <div class='docs'><h1>cartogram.py</h1></div>
+ </div>
+ <div class='clearall'>
+ <div class='section' id='section-0'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-0'>#</a>
+ </div>
+ <p>computes a circle cartogram for a given svg map + data file</p>
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-1'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-1'>#</a>
+ </div>
+
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-2'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-2'>#</a>
+ </div>
+
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre><span class="k">class</span> <span class="nc">Cartogram</span><span class="p">:</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-3'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-3'>#</a>
+ </div>
+
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="k">def</span> <span class="nf">generate</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">svg_src</span><span class="p">,</span> <span class="n">attr</span><span class="p">,</span> <span class="n">csv_src</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
+ <span class="n">regions</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">load_regions_from_svg</span><span class="p">(</span><span class="n">svg_src</span><span class="p">,</span> <span class="n">attr</span><span class="p">)</span>
+ <span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">load_csv</span><span class="p">(</span><span class="n">csv_src</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>
+ <span class="n">circles</span> <span class="o">=</span> <span class="p">[]</span>
+ <span class="k">for</span> <span class="nb">id</span> <span class="ow">in</span> <span class="n">regions</span><span class="p">:</span>
+ <span class="n">cx</span><span class="p">,</span> <span class="n">cy</span> <span class="o">=</span> <span class="n">regions</span><span class="p">[</span><span class="nb">id</span><span class="p">]</span>
+ <span class="n">val</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="nb">id</span><span class="p">]</span>
+ <span class="n">circles</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">Circle</span><span class="p">(</span><span class="n">cx</span><span class="p">,</span> <span class="n">cy</span><span class="p">,</span> <span class="nb">id</span><span class="p">,</span> <span class="n">val</span><span class="p">))</span>
+
+ <span class="bp">self</span><span class="o">.</span><span class="n">attr</span> <span class="o">=</span> <span class="n">attr</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">key</span> <span class="o">=</span> <span class="n">value</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">circles</span> <span class="o">=</span> <span class="n">circles</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">compute_radii</span><span class="p">()</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">layout</span><span class="p">(</span><span class="mi">700</span><span class="p">)</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">rescale</span><span class="p">()</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">correct</span><span class="p">()</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">layout</span><span class="p">(</span><span class="mi">200</span><span class="p">,</span> <span class="bp">True</span><span class="p">)</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">rescale</span><span class="p">()</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">correct</span><span class="p">()</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">layout</span><span class="p">(</span><span class="mi">100</span><span class="p">,</span> <span class="bp">False</span><span class="p">)</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">rescale</span><span class="p">()</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">correct</span><span class="p">()</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">to_svg</span><span class="p">()</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-4'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-4'>#</a>
+ </div>
+
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="k">def</span> <span class="nf">load_regions_from_svg</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">url</span><span class="p">,</span> <span class="n">attr</span><span class="p">):</span>
+ <span class="kn">import</span> <span class="nn">svg</span> <span class="kn">as</span> <span class="nn">svgdoc</span>
+ <span class="n">svg</span> <span class="o">=</span> <span class="n">svgdoc</span><span class="o">.</span><span class="n">Document</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">url</span><span class="p">)</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">svg</span> <span class="o">=</span> <span class="n">svg</span>
+ <span class="n">g</span> <span class="o">=</span> <span class="n">svg</span><span class="o">.</span><span class="n">doc</span><span class="o">.</span><span class="n">getElementsByTagName</span><span class="p">(</span><span class="s">&#39;g&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
+ <span class="n">coords</span> <span class="o">=</span> <span class="p">{}</span>
+ <span class="k">for</span> <span class="n">path</span> <span class="ow">in</span> <span class="n">g</span><span class="o">.</span><span class="n">getElementsByTagName</span><span class="p">(</span><span class="s">&#39;path&#39;</span><span class="p">):</span>
+ <span class="n">path_str</span> <span class="o">=</span> <span class="n">path</span><span class="o">.</span><span class="n">getAttribte</span><span class="p">(</span><span class="s">&#39;d&#39;</span><span class="p">)</span>
+ <span class="nb">id</span> <span class="o">=</span> <span class="n">path</span><span class="o">.</span><span class="n">getAttribte</span><span class="p">(</span><span class="s">&#39;data-&#39;</span> <span class="o">+</span> <span class="n">attr</span><span class="p">)</span>
+ <span class="n">poly</span> <span class="o">=</span> <span class="n">restore_poly_from_path_str</span><span class="p">(</span><span class="n">path_str</span><span class="p">)</span>
+ <span class="n">coords</span><span class="p">[</span><span class="nb">id</span><span class="p">]</span> <span class="o">=</span> <span class="n">poly</span><span class="o">.</span><span class="n">center</span><span class="p">()</span>
+ <span class="k">return</span> <span class="n">coords</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-5'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-5'>#</a>
+ </div>
+
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="k">def</span> <span class="nf">load_csv</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">url</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="s">&#39;id&#39;</span><span class="p">,</span> <span class="n">value</span><span class="o">=</span><span class="s">&#39;val&#39;</span><span class="p">):</span>
+ <span class="kn">import</span> <span class="nn">csv</span>
+ <span class="n">doc</span> <span class="o">=</span> <span class="n">csv</span><span class="o">.</span><span class="n">reader</span><span class="p">(</span><span class="nb">open</span><span class="p">(</span><span class="n">url</span><span class="p">),</span> <span class="n">dialect</span><span class="o">=</span><span class="s">&#39;excel-tab&#39;</span><span class="p">)</span>
+ <span class="n">head</span> <span class="o">=</span> <span class="bp">None</span>
+ <span class="n">data</span> <span class="o">=</span> <span class="p">{}</span>
+ <span class="k">for</span> <span class="n">row</span> <span class="ow">in</span> <span class="n">doc</span><span class="p">:</span>
+ <span class="k">if</span> <span class="ow">not</span> <span class="n">head</span><span class="p">:</span>
+ <span class="n">head</span> <span class="o">=</span> <span class="n">row</span>
+ <span class="k">print</span> <span class="n">head</span>
+ <span class="k">else</span><span class="p">:</span>
+ <span class="nb">id</span> <span class="o">=</span> <span class="n">row</span><span class="p">[</span><span class="n">head</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">key</span><span class="p">)]</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
+ <span class="n">val</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">row</span><span class="p">[</span><span class="n">head</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">value</span><span class="p">)])</span>
+ <span class="n">data</span><span class="p">[</span><span class="nb">id</span><span class="p">]</span> <span class="o">=</span> <span class="n">val</span>
+ <span class="k">return</span> <span class="n">data</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-6'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-6'>#</a>
+ </div>
+
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="k">def</span> <span class="nf">compute_radii</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+ <span class="kn">import</span> <span class="nn">sys</span><span class="o">,</span> <span class="nn">math</span>
+ <span class="n">minv</span> <span class="o">=</span> <span class="mi">0</span>
+ <span class="n">maxv</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">maxint</span> <span class="o">*</span> <span class="o">-</span><span class="mi">1</span>
+ <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">circles</span><span class="p">:</span>
+ <span class="n">minv</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="n">minv</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">value</span><span class="p">)</span>
+ <span class="n">maxv</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">maxv</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">value</span><span class="p">)</span>
+
+ <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">circles</span><span class="p">:</span>
+ <span class="n">c</span><span class="o">.</span><span class="n">r</span> <span class="o">=</span> <span class="n">math</span><span class="o">.</span><span class="n">pow</span><span class="p">((</span><span class="n">c</span><span class="o">.</span><span class="n">value</span> <span class="o">-</span> <span class="n">minv</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="n">maxv</span> <span class="o">-</span> <span class="n">minv</span><span class="p">),</span> <span class="mf">0.50</span><span class="p">)</span> <span class="o">*</span> <span class="mi">60</span>
+ <span class="n">c</span><span class="o">.</span><span class="n">weight</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">value</span> <span class="o">/</span> <span class="n">maxv</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-7'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-7'>#</a>
+ </div>
+
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="k">def</span> <span class="nf">layout</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">steps</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span> <span class="n">correct</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
+ <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">steps</span><span class="p">):</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-8'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-8'>#</a>
+ </div>
+ <p>if i % 100 == 0:
+ self.toSVG()</p>
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="bp">self</span><span class="o">.</span><span class="n">layout_step</span><span class="p">(</span><span class="n">correct</span><span class="p">)</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-9'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-9'>#</a>
+ </div>
+
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="k">def</span> <span class="nf">layout_step</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">correct</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
+ <span class="kn">import</span> <span class="nn">math</span>
+ <span class="n">pad</span> <span class="o">=</span> <span class="mi">0</span>
+
+ <span class="k">if</span> <span class="n">correct</span><span class="p">:</span>
+ <span class="k">for</span> <span class="n">C</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">circles</span><span class="p">:</span>
+ <span class="n">v</span> <span class="o">=</span> <span class="n">Vector</span><span class="p">(</span><span class="n">C</span><span class="o">.</span><span class="n">ox</span> <span class="o">-</span> <span class="n">C</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">C</span><span class="o">.</span><span class="n">oy</span> <span class="o">-</span> <span class="n">C</span><span class="o">.</span><span class="n">y</span><span class="p">)</span>
+ <span class="n">v</span><span class="o">.</span><span class="n">normalize</span><span class="p">()</span>
+ <span class="n">v</span><span class="o">.</span><span class="n">resize</span><span class="p">(</span><span class="mf">0.5</span><span class="p">)</span>
+ <span class="n">C</span><span class="o">.</span><span class="n">_move</span><span class="p">(</span><span class="n">v</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">v</span><span class="o">.</span><span class="n">y</span><span class="p">)</span>
+
+ <span class="k">for</span> <span class="n">A</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">circles</span><span class="p">:</span>
+ <span class="k">for</span> <span class="n">B</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">circles</span><span class="p">:</span>
+ <span class="k">if</span> <span class="n">A</span> <span class="o">!=</span> <span class="n">B</span><span class="p">:</span>
+ <span class="n">radsq</span> <span class="o">=</span> <span class="p">(</span><span class="n">A</span><span class="o">.</span><span class="n">r</span> <span class="o">+</span> <span class="n">B</span><span class="o">.</span><span class="n">r</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="n">A</span><span class="o">.</span><span class="n">r</span> <span class="o">+</span> <span class="n">B</span><span class="o">.</span><span class="n">r</span><span class="p">)</span>
+ <span class="n">d</span> <span class="o">=</span> <span class="n">A</span><span class="o">.</span><span class="n">sqdist</span><span class="p">(</span><span class="n">B</span><span class="p">)</span>
+ <span class="k">if</span> <span class="n">radsq</span> <span class="o">+</span> <span class="n">pad</span> <span class="o">&gt;</span> <span class="n">d</span><span class="p">:</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-10'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-10'>#</a>
+ </div>
+ <p>move circles away from each other</p>
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="n">v</span> <span class="o">=</span> <span class="n">Vector</span><span class="p">(</span><span class="n">B</span><span class="o">.</span><span class="n">x</span> <span class="o">-</span> <span class="n">A</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">B</span><span class="o">.</span><span class="n">y</span> <span class="o">-</span> <span class="n">A</span><span class="o">.</span><span class="n">y</span><span class="p">)</span>
+ <span class="n">v</span><span class="o">.</span><span class="n">normalize</span><span class="p">()</span>
+ <span class="n">m</span> <span class="o">=</span> <span class="p">(</span><span class="n">math</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">radsq</span><span class="p">)</span> <span class="o">-</span> <span class="n">math</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">d</span><span class="p">))</span> <span class="o">*</span> <span class="mf">0.25</span>
+ <span class="n">v</span><span class="o">.</span><span class="n">resize</span><span class="p">(</span><span class="n">m</span><span class="p">)</span>
+ <span class="n">A</span><span class="o">.</span><span class="n">_move</span><span class="p">(</span><span class="n">v</span><span class="o">.</span><span class="n">x</span> <span class="o">*</span> <span class="o">-</span><span class="mi">1</span> <span class="o">*</span> <span class="n">B</span><span class="o">.</span><span class="n">weight</span><span class="p">,</span> <span class="n">v</span><span class="o">.</span><span class="n">y</span> <span class="o">*</span> <span class="o">-</span><span class="mi">1</span> <span class="o">*</span> <span class="n">B</span><span class="o">.</span><span class="n">weight</span><span class="p">)</span>
+ <span class="n">B</span><span class="o">.</span><span class="n">_move</span><span class="p">(</span><span class="n">v</span><span class="o">.</span><span class="n">x</span> <span class="o">*</span> <span class="n">A</span><span class="o">.</span><span class="n">weight</span><span class="p">,</span> <span class="n">v</span><span class="o">.</span><span class="n">y</span> <span class="o">*</span> <span class="n">A</span><span class="o">.</span><span class="n">weight</span><span class="p">)</span>
+
+ <span class="k">for</span> <span class="n">C</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">circles</span><span class="p">:</span>
+ <span class="n">C</span><span class="o">.</span><span class="n">move</span><span class="p">()</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-11'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-11'>#</a>
+ </div>
+
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="k">def</span> <span class="nf">rescale</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+ <span class="kn">from</span> <span class="nn">geometry</span> <span class="kn">import</span> <span class="n">BBox</span><span class="p">,</span> <span class="n">View</span>
+ <span class="n">svg</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">svg</span>
+ <span class="n">svg_view</span> <span class="o">=</span> <span class="n">svg</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
+ <span class="n">vh</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">svg_view</span><span class="p">[</span><span class="s">&#39;h&#39;</span><span class="p">])</span>
+ <span class="n">vw</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">svg_view</span><span class="p">[</span><span class="s">&#39;w&#39;</span><span class="p">])</span>
+
+ <span class="n">bbox</span> <span class="o">=</span> <span class="n">BBox</span><span class="p">()</span>
+ <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">circles</span><span class="p">:</span>
+ <span class="n">r</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">r</span>
+ <span class="n">bbox</span><span class="o">.</span><span class="n">update</span><span class="p">((</span><span class="n">c</span><span class="o">.</span><span class="n">x</span> <span class="o">+</span> <span class="n">r</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">y</span> <span class="o">+</span> <span class="n">r</span><span class="p">))</span>
+ <span class="n">bbox</span><span class="o">.</span><span class="n">update</span><span class="p">((</span><span class="n">c</span><span class="o">.</span><span class="n">x</span> <span class="o">+</span> <span class="n">r</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">y</span> <span class="o">-</span> <span class="n">r</span><span class="p">))</span>
+ <span class="n">bbox</span><span class="o">.</span><span class="n">update</span><span class="p">((</span><span class="n">c</span><span class="o">.</span><span class="n">x</span> <span class="o">-</span> <span class="n">r</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">y</span> <span class="o">+</span> <span class="n">r</span><span class="p">))</span>
+ <span class="n">bbox</span><span class="o">.</span><span class="n">update</span><span class="p">((</span><span class="n">c</span><span class="o">.</span><span class="n">x</span> <span class="o">-</span> <span class="n">r</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">y</span> <span class="o">-</span> <span class="n">r</span><span class="p">))</span>
+
+ <span class="n">view</span> <span class="o">=</span> <span class="n">View</span><span class="p">(</span><span class="n">bbox</span><span class="p">,</span> <span class="n">vw</span><span class="p">,</span> <span class="n">vh</span><span class="p">)</span>
+ <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">circles</span><span class="p">:</span>
+ <span class="n">c</span><span class="o">.</span><span class="n">r</span> <span class="o">*=</span> <span class="n">view</span><span class="o">.</span><span class="n">scale</span>
+ <span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">view</span><span class="o">.</span><span class="n">project</span><span class="p">((</span><span class="n">c</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">y</span><span class="p">))</span>
+ <span class="n">c</span><span class="o">.</span><span class="n">x</span> <span class="o">=</span> <span class="n">x</span>
+ <span class="n">c</span><span class="o">.</span><span class="n">y</span> <span class="o">=</span> <span class="n">y</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-12'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-12'>#</a>
+ </div>
+
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="k">def</span> <span class="nf">correct</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+ <span class="k">for</span> <span class="n">A</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">circles</span><span class="p">:</span>
+ <span class="n">intersects</span> <span class="o">=</span> <span class="bp">False</span>
+ <span class="k">for</span> <span class="n">B</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">circles</span><span class="p">:</span>
+ <span class="k">if</span> <span class="n">A</span> <span class="o">!=</span> <span class="n">B</span><span class="p">:</span>
+ <span class="n">radsq</span> <span class="o">=</span> <span class="p">(</span><span class="n">A</span><span class="o">.</span><span class="n">r</span> <span class="o">+</span> <span class="n">B</span><span class="o">.</span><span class="n">r</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="n">A</span><span class="o">.</span><span class="n">r</span> <span class="o">+</span> <span class="n">B</span><span class="o">.</span><span class="n">r</span><span class="p">)</span>
+ <span class="n">d</span> <span class="o">=</span> <span class="n">A</span><span class="o">.</span><span class="n">sqdist_o</span><span class="p">(</span><span class="n">B</span><span class="p">)</span>
+ <span class="k">if</span> <span class="n">radsq</span> <span class="o">&gt;</span> <span class="n">d</span><span class="p">:</span>
+ <span class="n">intersects</span> <span class="o">=</span> <span class="bp">True</span>
+ <span class="k">break</span>
+ <span class="k">if</span> <span class="ow">not</span> <span class="n">intersects</span><span class="p">:</span>
+ <span class="n">A</span><span class="o">.</span><span class="n">x</span> <span class="o">=</span> <span class="n">A</span><span class="o">.</span><span class="n">ox</span>
+ <span class="n">A</span><span class="o">.</span><span class="n">y</span> <span class="o">=</span> <span class="n">A</span><span class="o">.</span><span class="n">oy</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-13'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-13'>#</a>
+ </div>
+
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="k">def</span> <span class="nf">to_svg</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+ <span class="n">svg</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">svg</span>
+
+ <span class="n">g</span> <span class="o">=</span> <span class="n">svg</span><span class="o">.</span><span class="n">node</span><span class="p">(</span><span class="s">&#39;g&#39;</span><span class="p">,</span> <span class="n">svg</span><span class="o">.</span><span class="n">root</span><span class="p">,</span> <span class="nb">id</span><span class="o">=</span><span class="s">&quot;cartogram&quot;</span><span class="p">,</span> <span class="n">fill</span><span class="o">=</span><span class="s">&quot;red&quot;</span><span class="p">,</span> <span class="n">fill_opacity</span><span class="o">=</span><span class="s">&quot;0.5&quot;</span><span class="p">)</span>
+
+ <span class="k">for</span> <span class="n">circle</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">circles</span><span class="p">:</span>
+ <span class="n">c</span> <span class="o">=</span> <span class="n">svg</span><span class="o">.</span><span class="n">node</span><span class="p">(</span><span class="s">&#39;circle&#39;</span><span class="p">,</span> <span class="n">g</span><span class="p">,</span> <span class="n">cx</span><span class="o">=</span><span class="n">circle</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">cy</span><span class="o">=</span><span class="n">circle</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="n">r</span><span class="o">=</span><span class="n">circle</span><span class="o">.</span><span class="n">r</span><span class="p">)</span>
+ <span class="n">c</span><span class="o">.</span><span class="n">setAttribute</span><span class="p">(</span><span class="s">&#39;data-&#39;</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">attr</span><span class="p">,</span> <span class="n">circle</span><span class="o">.</span><span class="n">id</span><span class="p">)</span>
+ <span class="n">c</span><span class="o">.</span><span class="n">setAttribute</span><span class="p">(</span><span class="s">&#39;data-&#39;</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">key</span><span class="o">.</span><span class="n">lower</span><span class="p">(),</span> <span class="n">circle</span><span class="o">.</span><span class="n">value</span><span class="p">)</span>
+ <span class="n">g</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">c</span><span class="p">)</span>
+
+ <span class="n">svg</span><span class="o">.</span><span class="n">preview</span><span class="p">()</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-14'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-14'>#</a>
+ </div>
+ <p>svg.save('cartogram.svg')</p>
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-15'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-15'>#</a>
+ </div>
+
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre><span class="k">class</span> <span class="nc">Circle</span><span class="p">:</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-16'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-16'>#</a>
+ </div>
+
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="nb">id</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">x</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ox</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">y</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">oy</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">y</span><span class="p">)</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">id</span> <span class="o">=</span> <span class="nb">id</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">dx</span> <span class="o">=</span> <span class="mi">0</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">dy</span> <span class="o">=</span> <span class="mi">0</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-17'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-17'>#</a>
+ </div>
+
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="k">def</span> <span class="nf">_move</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">):</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">dx</span> <span class="o">+=</span> <span class="n">x</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">dy</span> <span class="o">+=</span> <span class="n">y</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-18'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-18'>#</a>
+ </div>
+
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="k">def</span> <span class="nf">move</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">x</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dx</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">y</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dy</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">dx</span> <span class="o">=</span> <span class="mi">0</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">dy</span> <span class="o">=</span> <span class="mi">0</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-19'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-19'>#</a>
+ </div>
+
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+ <span class="k">return</span> <span class="s">&#39;&lt;Circle x=</span><span class="si">%.1f</span><span class="s">, y=</span><span class="si">%.1f</span><span class="s">, id=</span><span class="si">%s</span><span class="s">, val=</span><span class="si">%f</span><span class="s"> &gt;&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">id</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">value</span><span class="p">)</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-20'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-20'>#</a>
+ </div>
+
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="k">def</span> <span class="nf">sqdist</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">circ</span><span class="p">):</span>
+ <span class="n">dx</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">x</span> <span class="o">-</span> <span class="n">circ</span><span class="o">.</span><span class="n">x</span>
+ <span class="n">dy</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">y</span> <span class="o">-</span> <span class="n">circ</span><span class="o">.</span><span class="n">y</span>
+ <span class="k">return</span> <span class="n">dx</span> <span class="o">*</span> <span class="n">dx</span> <span class="o">+</span> <span class="n">dy</span> <span class="o">*</span> <span class="n">dy</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-21'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-21'>#</a>
+ </div>
+ <p>been too lazy to code this myself, instead I took code from here
+http://www.kokkugia.com/wiki/index.php5?title=Python_vector_class</p>
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="k">def</span> <span class="nf">sqdist_o</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">circ</span><span class="p">):</span>
+ <span class="n">dx</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ox</span> <span class="o">-</span> <span class="n">circ</span><span class="o">.</span><span class="n">x</span>
+ <span class="n">dy</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">oy</span> <span class="o">-</span> <span class="n">circ</span><span class="o">.</span><span class="n">y</span>
+ <span class="k">return</span> <span class="n">dx</span> <span class="o">*</span> <span class="n">dx</span> <span class="o">+</span> <span class="n">dy</span> <span class="o">*</span> <span class="n">dy</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-22'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-22'>#</a>
+ </div>
+
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-23'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-23'>#</a>
+ </div>
+
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre><span class="k">class</span> <span class="nc">Vector</span><span class="p">:</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-24'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-24'>#</a>
+ </div>
+ <p>Class properties</p>
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">):</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">x</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">y</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">y</span><span class="p">)</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-25'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-25'>#</a>
+ </div>
+ <p>represent as a string</p>
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+ <span class="k">return</span> <span class="s">&#39;Vector(</span><span class="si">%s</span><span class="s">, </span><span class="si">%s</span><span class="s">)&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">y</span><span class="p">)</span>
+
+ <span class="sd">&#39;&#39;&#39;</span>
+<span class="sd"> Class Methods / Behaviours</span>
+<span class="sd"> &#39;&#39;&#39;</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-26'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-26'>#</a>
+ </div>
+
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="k">def</span> <span class="nf">zero</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">x</span> <span class="o">=</span> <span class="mf">0.0</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">y</span> <span class="o">=</span> <span class="mf">0.0</span>
+ <span class="k">return</span> <span class="bp">self</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-27'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-27'>#</a>
+ </div>
+
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="k">def</span> <span class="nf">clone</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+ <span class="k">return</span> <span class="n">Vector</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">y</span><span class="p">)</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-28'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-28'>#</a>
+ </div>
+
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="k">def</span> <span class="nf">normalize</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+ <span class="kn">from</span> <span class="nn">math</span> <span class="kn">import</span> <span class="n">sqrt</span>
+ <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">x</span> <span class="o">==</span> <span class="mi">0</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">y</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
+ <span class="k">return</span> <span class="bp">self</span>
+ <span class="n">norm</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="mf">1.0</span> <span class="o">/</span> <span class="n">sqrt</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">x</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">x</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">y</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">y</span><span class="p">))</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">x</span> <span class="o">*=</span> <span class="n">norm</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">y</span> <span class="o">*=</span> <span class="n">norm</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-29'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-29'>#</a>
+ </div>
+ <p>self.z *= norm</p>
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="k">return</span> <span class="bp">self</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-30'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-30'>#</a>
+ </div>
+
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="k">def</span> <span class="nf">invert</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">x</span> <span class="o">=</span> <span class="o">-</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">x</span><span class="p">)</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">y</span> <span class="o">=</span> <span class="o">-</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">y</span><span class="p">)</span>
+ <span class="k">return</span> <span class="bp">self</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-31'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-31'>#</a>
+ </div>
+
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="k">def</span> <span class="nf">resize</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sizeFactor</span><span class="p">):</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">normalize</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">scale</span><span class="p">(</span><span class="n">sizeFactor</span><span class="p">)</span>
+ <span class="k">return</span> <span class="bp">self</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-32'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-32'>#</a>
+ </div>
+
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="k">def</span> <span class="nf">minus</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">t</span><span class="p">):</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">x</span> <span class="o">-=</span> <span class="n">t</span><span class="o">.</span><span class="n">x</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">y</span> <span class="o">-=</span> <span class="n">t</span><span class="o">.</span><span class="n">y</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-33'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-33'>#</a>
+ </div>
+ <p>self.z -= t.z</p>
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="k">return</span> <span class="bp">self</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-34'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-34'>#</a>
+ </div>
+
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="k">def</span> <span class="nf">plus</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">t</span><span class="p">):</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">x</span> <span class="o">+=</span> <span class="n">t</span><span class="o">.</span><span class="n">x</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">y</span> <span class="o">+=</span> <span class="n">t</span><span class="o">.</span><span class="n">y</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-35'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-35'>#</a>
+ </div>
+ <p>self.z += t.z</p>
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="k">return</span> <span class="bp">self</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-36'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-36'>#</a>
+ </div>
+
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="k">def</span> <span class="nf">roundToInt</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">x</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">x</span><span class="p">)</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">y</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">y</span><span class="p">)</span>
+ <span class="k">return</span> <span class="bp">self</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-37'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-37'>#</a>
+ </div>
+ <p>Returns the squared length of this vector.</p>
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="k">def</span> <span class="nf">lengthSquared</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+ <span class="k">return</span> <span class="nb">float</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">x</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">x</span><span class="p">)</span> <span class="o">+</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">y</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">y</span><span class="p">))</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-38'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-38'>#</a>
+ </div>
+ <p>Returns the length of this vector.</p>
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="k">def</span> <span class="nf">length</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+ <span class="kn">from</span> <span class="nn">math</span> <span class="kn">import</span> <span class="n">sqrt</span>
+ <span class="k">return</span> <span class="nb">float</span><span class="p">(</span><span class="n">sqrt</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">x</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">x</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">y</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">y</span><span class="p">))</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-39'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-39'>#</a>
+ </div>
+ <p>Computes the dot product of this vector and vector v2</p>
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="k">def</span> <span class="nf">dot</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">v2</span><span class="p">):</span>
+ <span class="k">return</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">x</span> <span class="o">*</span> <span class="n">v2</span><span class="o">.</span><span class="n">x</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">y</span> <span class="o">*</span> <span class="n">v2</span><span class="o">.</span><span class="n">y</span><span class="p">)</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-40'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-40'>#</a>
+ </div>
+ <p>Linearly interpolates between vectors v1 and v2 and returns the result point = (1-alpha)<em>v1 + alpha</em>v2.</p>
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="k">def</span> <span class="nf">interpolate</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">v2</span><span class="p">,</span> <span class="n">alpha</span><span class="p">):</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">x</span> <span class="o">=</span> <span class="nb">float</span><span class="p">((</span><span class="mi">1</span> <span class="o">-</span> <span class="n">alpha</span><span class="p">)</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">x</span> <span class="o">+</span> <span class="n">alpha</span> <span class="o">*</span> <span class="n">v2</span><span class="o">.</span><span class="n">x</span><span class="p">)</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">y</span> <span class="o">=</span> <span class="nb">float</span><span class="p">((</span><span class="mi">1</span> <span class="o">-</span> <span class="n">alpha</span><span class="p">)</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">y</span> <span class="o">+</span> <span class="n">alpha</span> <span class="o">*</span> <span class="n">v2</span><span class="o">.</span><span class="n">y</span><span class="p">)</span>
+ <span class="k">return</span> <span class="n">Vector</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">y</span><span class="p">)</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-41'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-41'>#</a>
+ </div>
+ <p>Returns the angle in radians between this vector and the vector parameter;
+the return value is constrained to the range [0,PI].</p>
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="k">def</span> <span class="nf">angle</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">v2</span><span class="p">):</span>
+ <span class="kn">from</span> <span class="nn">math</span> <span class="kn">import</span> <span class="n">acos</span>
+ <span class="n">vDot</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">v2</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">length</span><span class="p">()</span> <span class="o">*</span> <span class="n">v2</span><span class="o">.</span><span class="n">length</span><span class="p">())</span>
+ <span class="k">if</span> <span class="n">vDot</span> <span class="o">&lt;</span> <span class="o">-</span><span class="mf">1.0</span><span class="p">:</span>
+ <span class="n">vDot</span> <span class="o">=</span> <span class="o">-</span><span class="mf">1.0</span>
+ <span class="k">if</span> <span class="n">vDot</span> <span class="o">&gt;</span> <span class="mf">1.0</span><span class="p">:</span>
+ <span class="n">vDot</span> <span class="o">=</span> <span class="mf">1.0</span>
+ <span class="k">return</span> <span class="nb">float</span><span class="p">(</span><span class="n">acos</span><span class="p">(</span><span class="n">vDot</span><span class="p">))</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-42'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-42'>#</a>
+ </div>
+ <p>Limits this vector to a given size.
+NODEBOX USERS: name should change as 'size' and 'scale' are reserved words in Nodebox!</p>
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="k">def</span> <span class="nf">limit</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">size</span><span class="p">):</span>
+ <span class="k">if</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">length</span><span class="p">()</span> <span class="o">&gt;</span> <span class="n">size</span><span class="p">):</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">normalize</span><span class="p">()</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">scale</span><span class="p">(</span><span class="n">size</span><span class="p">)</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-43'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-43'>#</a>
+ </div>
+ <p>Point Methods
+Returns the square of the distance between this tuple and tuple t1.</p>
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="k">def</span> <span class="nf">distanceSquared</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">t1</span><span class="p">):</span>
+ <span class="n">dx</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">x</span> <span class="o">-</span> <span class="n">t1</span><span class="o">.</span><span class="n">x</span>
+ <span class="n">dy</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">y</span> <span class="o">-</span> <span class="n">t1</span><span class="o">.</span><span class="n">y</span>
+ <span class="k">return</span> <span class="p">(</span><span class="n">dx</span> <span class="o">*</span> <span class="n">dx</span> <span class="o">+</span> <span class="n">dy</span> <span class="o">*</span> <span class="n">dy</span><span class="p">)</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-44'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-44'>#</a>
+ </div>
+ <p>NODEBOX USERS: name should change as 'scale' is reserved word in Nodebox!</p>
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="k">def</span> <span class="nf">scale</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">s</span><span class="p">):</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">x</span> <span class="o">*=</span> <span class="n">s</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">y</span> <span class="o">*=</span> <span class="n">s</span>
+ <span class="k">return</span> <span class="bp">self</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-45'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-45'>#</a>
+ </div>
+ <p>NODEBOX USERS: name should change as 'translate' is reserved word in Nodebox!</p>
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="k">def</span> <span class="nf">translate</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">vec</span><span class="p">):</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">plus</span><span class="p">(</span><span class="n">vec</span><span class="p">)</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-46'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-46'>#</a>
+ </div>
+
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="k">def</span> <span class="nf">distance</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">pt</span><span class="p">):</span>
+ <span class="kn">from</span> <span class="nn">math</span> <span class="kn">import</span> <span class="n">sqrt</span>
+ <span class="n">dx</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">x</span> <span class="o">-</span> <span class="n">pt</span><span class="o">.</span><span class="n">x</span>
+ <span class="n">dy</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">y</span> <span class="o">-</span> <span class="n">pt</span><span class="o">.</span><span class="n">y</span>
+ <span class="k">return</span> <span class="nb">float</span><span class="p">(</span><span class="n">sqrt</span><span class="p">(</span><span class="n">dx</span> <span class="o">*</span> <span class="n">dx</span> <span class="o">+</span> <span class="n">dy</span> <span class="o">*</span> <span class="n">dy</span><span class="p">))</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-47'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-47'>#</a>
+ </div>
+ <p>restores a list of polygons from a SVG path string</p>
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre><span class="k">def</span> <span class="nf">restore_poly_from_path_str</span><span class="p">(</span><span class="n">path_str</span><span class="p">):</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-48'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-48'>#</a>
+ </div>
+
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="n">contours</span> <span class="o">=</span> <span class="n">path_str</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;Z&#39;</span><span class="p">)</span> <span class="c"># last contour may be empty</span>
+ <span class="kn">from</span> <span class="nn">Polygon</span> <span class="kn">import</span> <span class="n">Polygon</span> <span class="k">as</span> <span class="n">Poly</span>
+ <span class="n">poly</span> <span class="o">=</span> <span class="n">Poly</span><span class="p">()</span>
+ <span class="k">for</span> <span class="n">c_str</span> <span class="ow">in</span> <span class="n">contours</span><span class="p">:</span>
+ <span class="k">if</span> <span class="n">c_str</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span> <span class="o">!=</span> <span class="s">&quot;&quot;</span><span class="p">:</span>
+ <span class="n">pts_str</span> <span class="o">=</span> <span class="n">c_str</span><span class="o">.</span><span class="n">strip</span><span class="p">()[</span><span class="mi">1</span><span class="p">:]</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&quot;L&quot;</span><span class="p">)</span>
+ <span class="n">pts</span> <span class="o">=</span> <span class="p">[]</span>
+ <span class="k">for</span> <span class="n">pt_str</span> <span class="ow">in</span> <span class="n">pts_str</span><span class="p">:</span>
+ <span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="nb">map</span><span class="p">(</span><span class="nb">float</span><span class="p">,</span> <span class="n">pt_str</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;,&#39;</span><span class="p">))</span>
+ <span class="n">pts</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">))</span>
+ <span class="n">poly</span><span class="o">.</span><span class="n">addContour</span><span class="p">(</span><span class="n">pts</span><span class="p">,</span> <span class="n">is_clockwise</span><span class="p">(</span><span class="n">pts</span><span class="p">))</span>
+ <span class="k">return</span> <span class="n">poly</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-49'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-49'>#</a>
+ </div>
+ <p>returns true if a given polygon is in clockwise order</p>
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre><span class="k">def</span> <span class="nf">is_clockwise</span><span class="p">(</span><span class="n">pts</span><span class="p">):</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-50'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-50'>#</a>
+ </div>
+
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="n">s</span> <span class="o">=</span> <span class="mi">0</span>
+ <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">pts</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">):</span>
+ <span class="k">if</span> <span class="s">&#39;x&#39;</span> <span class="ow">in</span> <span class="n">pts</span><span class="p">[</span><span class="n">i</span><span class="p">]:</span>
+ <span class="n">x1</span> <span class="o">=</span> <span class="n">pts</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">x</span>
+ <span class="n">y1</span> <span class="o">=</span> <span class="n">pts</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">y</span>
+ <span class="n">x2</span> <span class="o">=</span> <span class="n">pts</span><span class="p">[</span><span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">x</span>
+ <span class="n">y2</span> <span class="o">=</span> <span class="n">pts</span><span class="p">[</span><span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">y</span>
+ <span class="k">else</span><span class="p">:</span>
+ <span class="n">x1</span><span class="p">,</span> <span class="n">y1</span> <span class="o">=</span> <span class="n">pts</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
+ <span class="n">x2</span><span class="p">,</span> <span class="n">y2</span> <span class="o">=</span> <span class="n">pts</span><span class="p">[</span><span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]</span>
+ <span class="n">s</span> <span class="o">+=</span> <span class="p">(</span><span class="n">x2</span> <span class="o">-</span> <span class="n">x1</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="n">y2</span> <span class="o">+</span> <span class="n">y1</span><span class="p">)</span>
+ <span class="k">return</span> <span class="n">s</span> <span class="o">&gt;=</span> <span class="mi">0</span>
+
+</pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+</div>
+</body>
View
183 docs/src/kartograph/cli.html
@@ -0,0 +1,183 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
+ <title>cli.py</title>
+ <link rel="stylesheet" href="../pycco.css">
+</head>
+<body>
+<div id="background"></div>
+<div id='container'>
+ <div class='section'>
+ <div class='docs'><h1>cli.py</h1></div>
+ </div>
+ <div class='clearall'>
+ <div class='section' id='section-0'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-0'>#</a>
+ </div>
+ <p>command line interface for kartograph</p>
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre><span class="kn">import</span> <span class="nn">argparse</span>
+<span class="kn">import</span> <span class="nn">os.path</span>
+<span class="kn">from</span> <span class="nn">options</span> <span class="kn">import</span> <span class="n">read_map_descriptor</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-1'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-1'>#</a>
+ </div>
+
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre><span class="k">class</span> <span class="nc">bcolors</span><span class="p">:</span>
+ <span class="n">HEADER</span> <span class="o">=</span> <span class="s">&#39;</span><span class="se">\033</span><span class="s">[95m&#39;</span>
+ <span class="n">OKBLUE</span> <span class="o">=</span> <span class="s">&#39;</span><span class="se">\033</span><span class="s">[94m&#39;</span>
+ <span class="n">OKGREEN</span> <span class="o">=</span> <span class="s">&#39;</span><span class="se">\033</span><span class="s">[92m&#39;</span>
+ <span class="n">WARNING</span> <span class="o">=</span> <span class="s">&#39;</span><span class="se">\033</span><span class="s">[93m&#39;</span>
+ <span class="n">FAIL</span> <span class="o">=</span> <span class="s">&#39;</span><span class="se">\033</span><span class="s">[91m&#39;</span>
+ <span class="n">ENDC</span> <span class="o">=</span> <span class="s">&#39;</span><span class="se">\033</span><span class="s">[0m&#39;</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-2'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-2'>#</a>
+ </div>
+
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="k">def</span> <span class="nf">disable</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">HEADER</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">OKBLUE</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">OKGREEN</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">WARNING</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">FAIL</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
+ <span class="bp">self</span><span class="o">.</span><span class="n">ENDC</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
+
+<span class="n">parser</span> <span class="o">=</span> <span class="n">argparse</span><span class="o">.</span><span class="n">ArgumentParser</span><span class="p">(</span><span class="n">prog</span><span class="o">=</span><span class="s">&#39;kartograph&#39;</span><span class="p">,</span> <span class="n">description</span><span class="o">=</span><span class="s">&#39;generating svg maps from shapefiles&#39;</span><span class="p">)</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-3'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-3'>#</a>
+ </div>
+ <p>subparsers = parser.add_subparsers(help='sub-command help')</p>
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-4'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-4'>#</a>
+ </div>
+ <p>parser_svg = subparsers.add_parser('svg', help='generates svg map')</p>
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre><span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s">&#39;config&#39;</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="n">argparse</span><span class="o">.</span><span class="n">FileType</span><span class="p">(</span><span class="s">&#39;r&#39;</span><span class="p">),</span> <span class="n">help</span><span class="o">=</span><span class="s">&#39;the configuration for the map. accepts json and yaml.&#39;</span><span class="p">)</span>
+<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s">&#39;--output&#39;</span><span class="p">,</span> <span class="s">&#39;-o&#39;</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s">&#39;FILE&#39;</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="n">argparse</span><span class="o">.</span><span class="n">FileType</span><span class="p">(</span><span class="s">&#39;w&#39;</span><span class="p">),</span> <span class="n">help</span><span class="o">=</span><span class="s">&#39;the file in which the map will be stored&#39;</span><span class="p">)</span>
+<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s">&#39;--verbose&#39;</span><span class="p">,</span> <span class="s">&#39;-v&#39;</span><span class="p">,</span> <span class="n">nargs</span><span class="o">=</span><span class="s">&#39;?&#39;</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s">&#39;&#39;</span><span class="p">,</span> <span class="n">const</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s">&#39;verbose mode&#39;</span><span class="p">)</span>
+<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s">&#39;--format&#39;</span><span class="p">,</span> <span class="s">&#39;-f&#39;</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s">&#39;svg|kml&#39;</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s">&#39;output format, if not specified it will be guessed from output filename or default to svg&#39;</span><span class="p">)</span>
+<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s">&#39;--preview&#39;</span><span class="p">,</span> <span class="s">&#39;-p&#39;</span><span class="p">,</span> <span class="n">nargs</span><span class="o">=</span><span class="s">&#39;?&#39;</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s">&#39;&#39;</span><span class="p">,</span> <span class="n">const</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s">&#39;opens the generated svg for preview&#39;</span><span class="p">)</span>
+
+<span class="kn">from</span> <span class="nn">kartograph</span> <span class="kn">import</span> <span class="n">Kartograph</span>
+<span class="kn">import</span> <span class="nn">time</span>
+<span class="kn">import</span> <span class="nn">sys</span>
+<span class="kn">import</span> <span class="nn">os</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-5'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-5'>#</a>
+ </div>
+
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre><span class="k">def</span> <span class="nf">render_map</span><span class="p">(</span><span class="n">args</span><span class="p">):</span>
+ <span class="n">cfg</span> <span class="o">=</span> <span class="n">read_map_descriptor</span><span class="p">(</span><span class="n">args</span><span class="o">.</span><span class="n">config</span><span class="p">)</span>
+ <span class="n">K</span> <span class="o">=</span> <span class="n">Kartograph</span><span class="p">()</span>
+ <span class="k">if</span> <span class="n">args</span><span class="o">.</span><span class="n">format</span><span class="p">:</span>
+ <span class="n">format</span> <span class="o">=</span> <span class="n">args</span><span class="o">.</span><span class="n">format</span>
+ <span class="k">elif</span> <span class="n">args</span><span class="o">.</span><span class="n">output</span><span class="p">:</span>
+ <span class="n">format</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">splitext</span><span class="p">(</span><span class="n">args</span><span class="o">.</span><span class="n">output</span><span class="o">.</span><span class="n">name</span><span class="p">)[</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">:]</span>
+ <span class="k">else</span><span class="p">:</span>
+ <span class="n">format</span> <span class="o">=</span> <span class="s">&#39;svg&#39;</span>
+ <span class="k">try</span><span class="p">:</span></pre></div>
+ </div>
+ </div>
+ <div class='clearall'></div>
+ <div class='section' id='section-6'>
+ <div class='docs'>
+ <div class='octowrap'>
+ <a class='octothorpe' href='#section-6'>#</a>
+ </div>
+ <p>generate the map</p>
+ </div>
+ <div class='code'>
+ <div class="highlight"><pre> <span class="n">K</span><span class="o">.</span><span class="n">generate</span><span class="p">(</span><span class="n">cfg</span><span class="p">,</span> <span class="n">args</span><span class="o">.</span><span class="n">output</span><span class="p">,</span> <span class="n">verbose</span><span class="o">=</span><span class="n">args</span><span class="o">.</span><span class="n">verbose</span><span class="p">,</span> <span class="n">preview</span><span class="o">=</span><span class="n">args</span><span class="o">.</span><span class="n">preview</span><span class="p">,</span> <span class="n">format</span><span class="o">=</span><span class="n">format</span><span class="p">)</span>
+
+ <span class="k">except</span> <span class="ne">Exception</span><span class="p">,</span> <span class="n">e</span><span class="p">:</span>
+ <span class="kn">import</span> <span class="nn">traceback</span>
+ <span class="n">ignore_path_len</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">__file__</span><span class="p">)</span> <span class="o">-</span> <span class="mi">7</span>
+ <span class="n">exc</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">exc_info</span><span class="p">()</span>
+ <span class="k">for</span> <span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="n">line</span><span class="p">,</span> <span class="n">func</span><span class="p">,</span> <span class="n">code</span><span class="p">)</span> <span class="ow">in</span> <span class="n">traceback</