Skip to content

Commit

Permalink
proper UMD bundling
Browse files Browse the repository at this point in the history
  • Loading branch information
elbywan committed Apr 1, 2017
1 parent a966df7 commit d8a775f
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 57 deletions.
30 changes: 17 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# | quadtree-lib | [![Build Status](https://travis-ci.org/elbywan/quadtree-lib.svg?branch=master)](https://travis-ci.org/elbywan/quadtree-lib) | [![Coverage Status](https://coveralls.io/repos/github/elbywan/quadtree-lib/badge.svg?branch=master)](https://coveralls.io/github/elbywan/quadtree-lib?branch=master) | [![npm version](https://badge.fury.io/js/quadtree-lib.svg)](https://www.npmjs.com/package/quadtree-lib)

<a href="http://elbywan.github.io/quadtree-lib/demo/collisions/collisions.html" target="_blank">
<img alt="quatree gif" src="assets/quadtree.gif" width="150px" align="left" style="margin-right: 25px"/>
<img alt="quatree gif" src="http://elbywan.github.io/quadtree-lib/assets/quadtree.gif" width="150px" align="left" style="margin-right: 25px"/>
</a>

Quadtree-lib is an easy to use, developer friendly quadtree library which
Expand All @@ -27,18 +27,6 @@ From the command line :

`npm install quadtree-lib` or `yarn add quadtree-lib`

Then :

```javascript
Quadtree = require("quadtree-lib")
```

Or eventually :

```html
<script src="path/to/quadtree-lib.min.js"></script>
```

### Using Bower

`bower install quadtree-lib`
Expand All @@ -63,6 +51,22 @@ gulp perf

## Usage

### Import

**This library is bundled in UMD format.**

Examples :

- Import using commonjs :
```javascript
Quadtree = require("quadtree-lib")
```

- Import globally with a script tag :
```html
<script src="path/to/quadtree-lib.min.js"></script>
```

### Init

First step is to initialize a new Quadtree object.
Expand Down
14 changes: 11 additions & 3 deletions build/js/quadtree.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions build/js/quadtree.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions build/js/quadtree.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions build/js/quadtree.min.js.map

Large diffs are not rendered by default.

Binary file added docs/demo/quadtree-raw.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/demo/quadtree.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions docs/demo/quadtree.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/demo/quadtree.min.js.map

Large diffs are not rendered by default.

37 changes: 24 additions & 13 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,25 @@ <h1 id="quadtree-lib">quadtree-lib</h1>
<p><strong>Quadtree-lib</strong> is an easy to use, developer friendly quadtree library
which contains many helper methods to add, remove, iterate, filter, simulate
collisions over 2d elements and more.</p>
<h2 id="the-quadtree-class-">The Quadtree class.</h2>




<h4 id="umd-bundling-related-code">UMD bundling related code</h4>


<div class='highlight'><pre>(<span class="hljs-function"><span class="hljs-params">(root, factory)</span> -&gt;</span>
<span class="hljs-keyword">if</span> <span class="hljs-keyword">typeof</span> define <span class="hljs-keyword">is</span> <span class="hljs-string">'function'</span> <span class="hljs-keyword">and</span> define.amd
define [], factory
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> <span class="hljs-keyword">typeof</span> exports <span class="hljs-keyword">is</span> <span class="hljs-string">'object'</span> <span class="hljs-keyword">and</span> <span class="hljs-built_in">module</span>.exports
<span class="hljs-built_in">module</span>.exports = factory()
<span class="hljs-keyword">else</span>
root[<span class="hljs-string">"Quadtree"</span>] = factory()
) @, <span class="hljs-function"><span class="hljs-params">()</span> -&gt;</span></pre></div>



<h2 id="the-quadtree-class">The Quadtree class</h2>



Expand All @@ -43,11 +61,11 @@ <h3 id="constructor">Constructor</h3>



<p>A quadtree constructor has 5 parameters :</p>
<p>The quadtree constructor accepts a single parameter object containing the following properties :</p>
<ul>
<li>x &amp; y coordinates which are always (0, 0) for the root tree.</li>
<li>its dimensions (width &amp; length), mandatory.</li>
<li>the maximum number of elements before the leaf ‘splits’ into subtrees. (defaults to 1)</li>
<li>width / length : dimensions of the quadtree. [ <em>mandatory</em> ]</li>
<li>maxElements : the maximum number of elements before the leaf ‘splits’ into subtrees. [ <em>defaults to 1</em> ]</li>
<li>x / y : these coordinates are used internally by the library to position subtrees. [ <em>internal use only</em> ]</li>
</ul>


Expand Down Expand Up @@ -487,7 +505,7 @@ <h3 id="exposed-methods">Exposed methods</h3>



<p>Opposite of filter</p>
<p>Opposite of filter.</p>


<div class='highlight'><pre> reject: <span class="hljs-function"><span class="hljs-params">(predicate)</span> -&gt;</span>
Expand Down Expand Up @@ -555,13 +573,6 @@ <h3 id="exposed-methods">Exposed methods</h3>
str</pre></div>



<p>Require export.</p>


<div class='highlight'><pre><span class="hljs-built_in">module</span>?.exports = Quadtree</pre></div>


<div class="fleur">h</div>
</div>
</div>
Expand Down
37 changes: 24 additions & 13 deletions docs/quadtree.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,25 @@ <h1 id="quadtree-lib">quadtree-lib</h1>
<p><strong>Quadtree-lib</strong> is an easy to use, developer friendly quadtree library
which contains many helper methods to add, remove, iterate, filter, simulate
collisions over 2d elements and more.</p>
<h2 id="the-quadtree-class-">The Quadtree class.</h2>




<h4 id="umd-bundling-related-code">UMD bundling related code</h4>


<div class='highlight'><pre>(<span class="hljs-function"><span class="hljs-params">(root, factory)</span> -&gt;</span>
<span class="hljs-keyword">if</span> <span class="hljs-keyword">typeof</span> define <span class="hljs-keyword">is</span> <span class="hljs-string">'function'</span> <span class="hljs-keyword">and</span> define.amd
define [], factory
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> <span class="hljs-keyword">typeof</span> exports <span class="hljs-keyword">is</span> <span class="hljs-string">'object'</span> <span class="hljs-keyword">and</span> <span class="hljs-built_in">module</span>.exports
<span class="hljs-built_in">module</span>.exports = factory()
<span class="hljs-keyword">else</span>
root[<span class="hljs-string">"Quadtree"</span>] = factory()
) @, <span class="hljs-function"><span class="hljs-params">()</span> -&gt;</span></pre></div>



<h2 id="the-quadtree-class">The Quadtree class</h2>



Expand All @@ -43,11 +61,11 @@ <h3 id="constructor">Constructor</h3>



<p>A quadtree constructor has 5 parameters :</p>
<p>The quadtree constructor accepts a single parameter object containing the following properties :</p>
<ul>
<li>x &amp; y coordinates which are always (0, 0) for the root tree.</li>
<li>its dimensions (width &amp; length), mandatory.</li>
<li>the maximum number of elements before the leaf ‘splits’ into subtrees. (defaults to 1)</li>
<li>width / length : dimensions of the quadtree. [ <em>mandatory</em> ]</li>
<li>maxElements : the maximum number of elements before the leaf ‘splits’ into subtrees. [ <em>defaults to 1</em> ]</li>
<li>x / y : these coordinates are used internally by the library to position subtrees. [ <em>internal use only</em> ]</li>
</ul>


Expand Down Expand Up @@ -487,7 +505,7 @@ <h3 id="exposed-methods">Exposed methods</h3>



<p>Opposite of filter</p>
<p>Opposite of filter.</p>


<div class='highlight'><pre> reject: <span class="hljs-function"><span class="hljs-params">(predicate)</span> -&gt;</span>
Expand Down Expand Up @@ -555,13 +573,6 @@ <h3 id="exposed-methods">Exposed methods</h3>
str</pre></div>



<p>Require export.</p>


<div class='highlight'><pre><span class="hljs-built_in">module</span>?.exports = Quadtree</pre></div>


<div class="fleur">h</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion gulpfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ del = require 'del'

paths =
src: ['src/**/*.coffee']
demo: ['demo/**/*', 'build/js/quadtree.min.js', 'build/js/quadtree.min.js.map']
demo: ['demo/**/*', 'build/js/quadtree.min.js', 'build/js/quadtree.min.js.map', 'assets/*']
test: ['test/*.coffee']
perf: ['test/perf/*.coffee']
docindex: ['docs/quadtree.html']
Expand Down
25 changes: 15 additions & 10 deletions src/quadtree.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,25 @@
# **Quadtree-lib** is an easy to use, developer friendly quadtree library
# which contains many helper methods to add, remove, iterate, filter, simulate
# collisions over 2d elements and more.
#
# The Quadtree class.

# #### UMD bundling related code
((root, factory) ->
if typeof define is 'function' and define.amd
define [], factory
else if typeof exports is 'object' and module.exports
module.exports = factory()
else
root["Quadtree"] = factory()
) @, () ->
# The Quadtree class
# -------------------
class Quadtree
# ### Constructor

# A quadtree constructor has 5 parameters :
# - x & y coordinates which are always (0, 0) for the root tree.
# - its dimensions (width & length), mandatory.
# - the maximum number of elements before the leaf 'splits' into subtrees. (defaults to 1)
# The quadtree constructor accepts a single parameter object containing the following properties :
# - width / length : dimensions of the quadtree. [ *mandatory* ]
# - maxElements : the maximum number of elements before the leaf 'splits' into subtrees. [ *defaults to 1* ]
# - x / y : these coordinates are used internally by the library to position subtrees. [ *internal use only* ]
constructor: ({@x, @y, @width, @height, @maxElements}) ->

# An error is thrown when the width & length are not passed as constructor arguments.
Expand Down Expand Up @@ -394,7 +403,3 @@ class Quadtree
if isParent then str += "#{indentation}└──┐\n"

str


# Require export.
module?.exports = Quadtree

0 comments on commit d8a775f

Please sign in to comment.