diff --git a/.gitignore b/.gitignore index e99e7df..c6bd77f 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,4 @@ rel/example_project *.swp test.app.config variables-ct* +_build/ diff --git a/Makefile b/Makefile index e2ffca5..15dcfe9 100644 --- a/Makefile +++ b/Makefile @@ -1,43 +1,38 @@ -REBAR = $(shell command -v rebar || echo ./rebar) -DEPS_PLT=./.deps_plt -DEPS=erts kernel stdlib +REBAR3_URL=https://s3.amazonaws.com/rebar3/rebar3 -.PHONY: all compile test qc clean get-deps build-plt dialyze +ifeq ($(wildcard rebar3),rebar3) + REBAR3 = $(CURDIR)/rebar3 +endif -all: compile +REBAR3 ?= $(shell test -e `which rebar3` 2>/dev/null && which rebar3 || echo "./rebar3") -deps: - @$(REBAR) get-deps - @$(REBAR) compile +ifeq ($(REBAR3),) + REBAR3 = $(CURDIR)/rebar3 +endif -compile: - @$(REBAR) compile +.PHONY: deps build dialyzer xref doc publish -#test: compile -# @ERL_AFLAGS="-config test/erlquad_tests.app.config" $(REBAR) eunit skip_deps=true +all: build + +build: $(REBAR3) + @$(REBAR3) compile + +$(REBAR3): + wget $(REBAR3_URL) || curl -Lo rebar3 $(REBAR3_URL) + @chmod a+x rebar3 clean: - @$(REBAR) clean - -get-deps: - @$(REBAR) get-deps - -$(DEPS_PLT): - @echo Building $(DEPS_PLT) - dialyzer --build_plt \ - --output_plt $(DEPS_PLT) \ - --apps $(DEPS) -#-r deps \ - -dialyze: compile $(DEPS_PLT) - dialyzer --fullpath \ - --src src \ - -Wunmatched_returns \ - -Werror_handling \ - -Wrace_conditions \ - -Wunderspecs \ - -r ebin \ - --plt $(DEPS_PLT) + @$(REBAR3) clean + +dialyzer: + @$(REBAR3) dialyzer xref: - @$(REBAR) xref + @$(REBAR3) xref + +doc: build + ./scripts/hackish_inject_version_in_docs.sh + ./scripts/hackish_make_docs.sh + +publish: + @$(REBAR3) as publish hex publish diff --git a/README.md b/README.md index 150e574..2def1df 100644 --- a/README.md +++ b/README.md @@ -4,12 +4,13 @@ Copyright (c) 2016 Guilherme Andrade -__Version:__ 1.1.0 +__Version:__ 1.1.1 __Authors:__ Guilherme Andrade ([`erlquad(at)gandrade(dot)net`](mailto:erlquad(at)gandrade(dot)net)). `erlquad`: A simple Erlang quadtree implementation + --------- `erlquad` is a straightforward Erlang implementation of [quadtrees](https://en.wikipedia.org/wiki/Quadtree), supporting both bounding-box outlines as well as precise coordinates for small enough objects. @@ -63,7 +64,6 @@ erlquad:objects_all(Q2), % [#big_square{...}, #tiny_circle{...}, #tiny_circle{.. erlquad:objects_deep_all(Q2), % [[], [[#big_square{...}, [[], [], ...]], [[[], ...[]]]]] ``` - Define 'COMPILE_NATIVE_ERLQUAD' (e.g. "rebar compile -DCOMPILE_NATIVE_ERLQUAD") for HiPE compilation. diff --git a/VERSION b/VERSION deleted file mode 100644 index 9084fa2..0000000 --- a/VERSION +++ /dev/null @@ -1 +0,0 @@ -1.1.0 diff --git a/doc/utf8/README.md b/doc/README.md similarity index 99% rename from doc/utf8/README.md rename to doc/README.md index 2754cfd..7bd00c1 100644 --- a/doc/utf8/README.md +++ b/doc/README.md @@ -4,11 +4,12 @@ Copyright (c) 2016 Guilherme Andrade -__Version:__ 1.1.0 +__Version:__ 1.1.1 __Authors:__ Guilherme Andrade ([`erlquad(at)gandrade(dot)net`](mailto:erlquad(at)gandrade(dot)net)). `erlquad`: A simple Erlang quadtree implementation + --------- `erlquad` is a straightforward Erlang implementation of [quadtrees](https://en.wikipedia.org/wiki/Quadtree), supporting both bounding-box outlines as well as precise coordinates for small enough objects. diff --git a/doc/edoc-info b/doc/edoc-info index 2c1d591..0efd98c 100644 --- a/doc/edoc-info +++ b/doc/edoc-info @@ -1,3 +1,3 @@ %% encoding: UTF-8 -{packages,[]}. +{application,erlquad}. {modules,[erlquad]}. diff --git a/doc/erlquad.html b/doc/erlquad.html index 3b2f05b..30270c6 100644 --- a/doc/erlquad.html +++ b/doc/erlquad.html @@ -24,7 +24,7 @@

coordinates()

erlquad_node()

-

erlquad_node() = #erlquad_node{}

+

erlquad_node() = #erlquad_node{split_x = number(), split_y = number(), children = {erlquad_node(), erlquad_node(), erlquad_node(), erlquad_node()} | undefined, bucket = [term()]}

fold_fun()

@@ -110,6 +110,6 @@

objects_fold/3


-

Generated by EDoc, Apr 23 2016, 21:57:16.

+

Generated by EDoc, Apr 30 2017, 18:52:11.

diff --git a/doc/erlquad.md b/doc/erlquad.md index 692d079..28f6aa4 100644 --- a/doc/erlquad.md +++ b/doc/erlquad.md @@ -5,8 +5,6 @@ * [Function Index](#index) * [Function Details](#functions) - - ## Data Types ## @@ -17,7 +15,6 @@ ### box() ### -

 box() = {Left::number(), Bottom::number(), Right::number(), Top::number()}
 
@@ -25,11 +22,9 @@ box() = {Left::number(), Bottom::number(), Right::number(), Top::number()} - ### coordinates() ### -

 coordinates() = {X::number(), Y::number()}
 
@@ -37,23 +32,19 @@ coordinates() = {X::number(), Y::number()} - ### erlquad_node() ### -

-erlquad_node() = #erlquad_node{}
+erlquad_node() = #erlquad_node{split_x = number(), split_y = number(), children = {erlquad_node(), erlquad_node(), erlquad_node(), erlquad_node()} | undefined, bucket = [term()]}
 
- ### fold_fun() ### -

 fold_fun() = fun((Object::term(), Acc::term()) -> NewAcc::term())
 
@@ -61,11 +52,9 @@ fold_fun() = fun((Object::term(), Acc::term()) -> NewAcc::term()) - ### object_outline_fun() ### -

 object_outline_fun() = fun((Object::term()) -> outline())
 
@@ -73,11 +62,9 @@ object_outline_fun() = fun((Object::term()) -> outlin - ### outline() ### -

 outline() = box() | coordinates()
 
@@ -85,16 +72,13 @@ outline() = box() | coordina - ### predicate() ### -

 predicate() = fun((Object::term()) -> boolean())
 
- ## Function Index ## @@ -111,129 +95,89 @@ predicate() = fun((Object::term()) -> boolean()) ### area_query/5 ### -

 area_query(Left::number(), Bottom::number(), Right::number(), Top::number(), QNode::erlquad_node()) -> Objects::[term()]
 
- -

- - +
### area_query_any/6 ### -

 area_query_any(Predicate::predicate(), Left::number(), Bottom::number(), Right::number(), Top::number(), QNode::erlquad_node()) -> boolean()
 
- -

- - +
### area_query_deep/5 ### -

 area_query_deep(Left::number(), Bottom::number(), Right::number(), Top::number(), QNode::erlquad_node()) -> DeepObjectList::[term(), ...]
 
- -

- - +
### area_query_fold/7 ### -

 area_query_fold(FoldFun::fold_fun(), FoldAcc0::term(), Left::number(), Bottom::number(), Right::number(), Top::number(), QNode::erlquad_node()) -> FoldAccN::term()
 
- -

- - +
### new/5 ### -

 new(Left::number(), Bottom::number(), Right::number(), Top::number(), Depth::non_neg_integer()) -> erlquad_node()
 
- -

- - +
### objects_add/3 ### -

 objects_add(Objects::[term()], GetOutlineFun::object_outline_fun(), QNode::erlquad_node()) -> erlquad_node()
 
- -

- - +
### objects_all/1 ### -

 objects_all(QNode::erlquad_node()) -> Objects::[term()]
 
- -

- - +
### objects_any/2 ### -

 objects_any(Precicate::predicate(), QNode::erlquad_node()) -> boolean()
 
- -

- - +
### objects_deep_all/1 ### -

 objects_deep_all(QNode::erlquad_node()) -> ObjectsDeepList::[term(), ...]
 
- -

- - +
### objects_fold/3 ### -

 objects_fold(FoldFun::fold_fun(), FoldAcc0::term(), QNode::erlquad_node()) -> FoldAccN::term()
 
- -

- - +
diff --git a/doc/index.html b/doc/index.html index 047b9dc..ae39160 100644 --- a/doc/index.html +++ b/doc/index.html @@ -1,7 +1,7 @@ -Overview +The erlquad application diff --git a/doc/modules-frame.html b/doc/modules-frame.html index 37f6337..3df22fc 100644 --- a/doc/modules-frame.html +++ b/doc/modules-frame.html @@ -1,7 +1,7 @@ -Overview +The erlquad application diff --git a/doc/overview-summary.html b/doc/overview-summary.html index ddcf948..f5c42c6 100644 --- a/doc/overview-summary.html +++ b/doc/overview-summary.html @@ -9,7 +9,7 @@

erlquad

Copyright © 2016 Guilherme Andrade

-

Version: 1.1.0

+

Version: 1.1.1

Authors: Guilherme Andrade (erlquad(at)gandrade(dot)net).

erlquad: A simple Erlang quadtree implementation

@@ -69,6 +69,6 @@

erlquad


-

Generated by EDoc, Apr 23 2016, 21:57:16.

+

Generated by EDoc, Apr 30 2017, 18:52:11.

diff --git a/doc/overview.edoc b/doc/overview.edoc index 7e32270..2530066 100644 --- a/doc/overview.edoc +++ b/doc/overview.edoc @@ -1,6 +1,6 @@ @author Guilherme Andrade @copyright 2016 Guilherme Andrade -@version 1.1.0 +@version 1.1.1 @title erlquad @doc `erlquad': A simple Erlang quadtree implementation diff --git a/doc/packages-frame.html b/doc/packages-frame.html deleted file mode 100644 index 4193cbe..0000000 --- a/doc/packages-frame.html +++ /dev/null @@ -1,11 +0,0 @@ - - - -Overview - - - -

Packages

-
- - \ No newline at end of file diff --git a/doc/stylesheet.css b/doc/stylesheet.css index e426a90..ab170c0 100644 --- a/doc/stylesheet.css +++ b/doc/stylesheet.css @@ -27,10 +27,10 @@ div.spec { margin-left: 2em; background-color: #eeeeee; } -a.module,a.package { +a.module { text-decoration:none } -a.module:hover,a.package:hover { +a.module:hover { background-color: #eeeeee; } ul.definitions { diff --git a/overview.edoc b/overview.edoc new file mode 100644 index 0000000..2530066 --- /dev/null +++ b/overview.edoc @@ -0,0 +1,59 @@ +@author Guilherme Andrade +@copyright 2016 Guilherme Andrade +@version 1.1.1 +@title erlquad +@doc `erlquad': A simple Erlang quadtree implementation + +
+ +`erlquad' is a straightforward Erlang implementation of quadtrees, supporting both bounding-box outlines as well as precise coordinates for small enough objects. + +It exposes functions for fetching, folding and any'ing (with boolean predicate) particular areas of interest as well as all contained objects. Deeplist versions of fetching methods are also included for when there's no need to concatenate the intermediate results and thus avoid the overhead of doing so. + +Buckets have unlimited capacity and depth is fixed on initialization. + +
+Object1 = #big_square{ x = 1000, y = 750,  side = 10 },
+Object2 = #tiny_circle{ x = 3000, y = 1000 },
+Object3 = #tiny_circle{ x = 3000, y = 2000 },
+
+GetOutline = fun (#tiny_circle{ x = X, y = Y }) ->
+                    {X, Y};
+                 (#big_square{ x = X, y = Y, side = S }) ->
+                    {X - S/2, Y - S/2, X + S/2, Y + S/2}
+             end,
+
+IsSquare = fun (#tiny_circle{}) -> false;
+               (#big_square{})  -> true
+           end,
+
+CountCirclesFold = fun (#tiny_circle{}, Acc) -> Acc + 1;
+                       (#big_square{}, Acc)  -> Acc
+                   end,
+
+Q1 = erlquad:new(0, 0, 4000, 3000, 3), % Left, Bottom, Right, Top, Depth
+Q2 = erlquad:objects_add([Object1, Object2, Object3], GetOutline, Q1),
+
+erlquad:area_query(0, 0, 1999, 2999, Q2),       % [#big_square{...}]
+erlquad:area_query(2000, 0, 3999, 2999, Q2),    % [#tiny_circle{...}, #tiny_circle{...}]
+erlquad:area_query(0, 0, 3999, 2999, Q2),       % [#big_square{...}, #tiny_circle{...}, #tiny_circle{...}]
+
+erlquad:area_query_deep(0, 0, 3999, 2999, Q2),  % [[], [[#big_square{...}, [[], [], ...]], [[[], ...[]]]]]
+
+erlquad:area_query_any(IsSquare, 0, 0, 1999, 1499, Q2),       % true
+erlquad:area_query_any(IsSquare, 2000, 1500, 3999, 2999, Q2), % false
+
+erlquad:area_query_fold(CountCirclesFold, 0, 2000, 0, 3999, 2999, Q2), % 2
+erlquad:area_query_fold(CountCirclesFold, 0, 2000, 0, 3999, 1499, Q2), % 1
+erlquad:area_query_fold(CountCirclesFold, 0, 2000, 0, 3999, 749, Q2),  % 0
+
+erlquad:objects_any(IsSquare, Q2), % true
+
+erlquad:objects_fold(CountCirclesFold, 0, Q2), % 2
+
+erlquad:objects_all(Q2), % [#big_square{...}, #tiny_circle{...}, #tiny_circle{...}]
+
+erlquad:objects_deep_all(Q2), % [[], [[#big_square{...}, [[], [], ...]], [[[], ...[]]]]]
+
+ +Define 'COMPILE_NATIVE_ERLQUAD' (e.g. "rebar compile -DCOMPILE_NATIVE_ERLQUAD") for HiPE compilation. diff --git a/package.exs b/package.exs deleted file mode 100644 index 3a5e953..0000000 --- a/package.exs +++ /dev/null @@ -1,19 +0,0 @@ -defmodule erlquad.Mixfile do - use Mix.Project - - @version File.read!("VERSION") |> String.strip - - def project do - [app: :erlquad, - version: @version, - description: "Erlang quadtree" - package: package] - end - - defp package do - [files: ~w(src rebar.config README.md LICENSE), - contributors: ["Guilherme Andrade"], - licenses: ["MIT"], - links: %{"GitHub" => "https://github.com/g-andrade/erlquad"}] - end -end diff --git a/rebar.config b/rebar.config index fd81abc..ae69d99 100644 --- a/rebar.config +++ b/rebar.config @@ -1,32 +1,42 @@ % vim: set ft=erlang expandtab softtabstop=4 shiftwidth=4: -{erl_opts, [ - warn_export_all, - warn_export_vars, - warn_missing_spec, - warn_obsolete_guard, - warn_shadow_vars, - warn_unused_import, - warnings_as_errors - ]}. +{erl_opts, + [%bin_opt_info, + debug_info, + warn_export_all, + warn_export_vars, + warn_missing_spec, + warn_obsolete_guards, + warn_shadow_vars, + warn_unused_import, + warnings_as_errors]}. -{deps_dir, "deps"}. -{deps, [ - %{edown, ".*", {git, "git://github.com/esl/edown.git", {tag, "0.4"}}} - ]}. +{xref_checks, + [undefined_function_calls, + undefined_functions, + locals_not_used, + exports_not_used, + deprecated_function_calls, + deprecated_functions]}. -{edoc_opts, [ - %[{doclet, edown_doclet}] - ]}. +{dialyzer, + [{plt_include_all_deps, true}, + {warnings, + [unmatched_returns, + error_handling, + race_conditions, + underspecs + ]} + ]}. -{xref_checks, [ - undefined_function_calls, - undefined_functions, - locals_not_used, - exports_not_used, - deprecated_function_calls, - deprecated_functions - ]}. - -{eunit_opts, [verbose, {skip_deps, true}]}. -{eunit_exclude_deps, true}. {cover_enabled, true}. + +{profiles, + [{generate_documentation, + [{deps, + [{edown, ".*", {git, "https://github.com/uwiger/edown.git", {tag, "0.8.1"}}}]}, + {edoc_opts, [{doclet, edown_doclet}]} + ]}, + {publish, + [{plugins, [rebar3_hex]}]} + ] +}. diff --git a/rebar.lock b/rebar.lock new file mode 100644 index 0000000..57afcca --- /dev/null +++ b/rebar.lock @@ -0,0 +1 @@ +[]. diff --git a/scripts/hackish_inject_version_in_docs.sh b/scripts/hackish_inject_version_in_docs.sh new file mode 100755 index 0000000..b36b7dc --- /dev/null +++ b/scripts/hackish_inject_version_in_docs.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +set -ex + +VERSION=$(./scripts/version_from_git.sh) +perl -pi -e "s/^\@version .+$/\@version ${VERSION}/g" overview.edoc diff --git a/scripts/hackish_make_docs.sh b/scripts/hackish_make_docs.sh new file mode 100755 index 0000000..cac155d --- /dev/null +++ b/scripts/hackish_make_docs.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +# sigh..... +rebar3 as generate_documentation compile +mkdir -p _build/generate_documentation/lib/erlquad/doc/ +cp -p overview.edoc _build/generate_documentation/lib/erlquad/doc/ +erl -pa _build/generate_documentation/lib/*/ebin -noshell -run edoc_run application "erlquad" +erl -pa _build/generate_documentation/lib/*/ebin -noshell -run edoc_run application "erlquad" '[{doclet, edown_doclet}, {top_level_readme, {"README.md", "https://github.com/g-andrade/erlquad", "master"}}]' +rm -rf doc +mv _build/generate_documentation/lib/erlquad/doc ./ +sed -i -e 's/^\(---------\)$/\n\1/g' README.md diff --git a/scripts/requirements.txt b/scripts/requirements.txt new file mode 100644 index 0000000..d8dc22d --- /dev/null +++ b/scripts/requirements.txt @@ -0,0 +1 @@ +parse diff --git a/scripts/version_from_git.py b/scripts/version_from_git.py new file mode 100755 index 0000000..672381c --- /dev/null +++ b/scripts/version_from_git.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python +import parse +import sys + +git_head = parse.parse('ref: {}', sys.argv[1])[0].strip() +tag_description = sys.argv[2].strip() + +head_parts = git_head.split('/') +if len(head_parts) > 2: + if head_parts[-2] in ['release', 'hotfix', 'support']: + print head_parts[-1] + elif len(head_parts) == 3 and head_parts[-1] in ['master']: + tag_description_parts = tag_description.split('-') + (major, minor, fix) = parse.parse('{:d}.{:d}.{:d}', tag_description_parts[0]) + print '%d.%d.%d' % (major, minor, fix) + else: + print tag_description +else: + print tag_description diff --git a/scripts/version_from_git.sh b/scripts/version_from_git.sh new file mode 100755 index 0000000..6ea8a61 --- /dev/null +++ b/scripts/version_from_git.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +set -ex + +GIT_HEAD=$(cat .git/HEAD) +TAG_DESCRIPTION=$(git describe --tags) +./scripts/version_from_git.py "$GIT_HEAD" "$TAG_DESCRIPTION" diff --git a/src/erlquad.app.src b/src/erlquad.app.src index 4cd17ad..e31f2a8 100644 --- a/src/erlquad.app.src +++ b/src/erlquad.app.src @@ -1,14 +1,15 @@ {application, erlquad, - [ - {description, "Erlang quadtree"}, + [{description, "Quadtrees for Erlang"}, {vsn, git}, - {modules, [ - erlquad - ]}, {registered, []}, - {applications, [ - kernel, - stdlib - ]}, - {env, []} + {applications, + [kernel, + stdlib + ]}, + {env,[]}, + {modules, []}, + + {maintainers, ["Guilherme Andrade"]}, + {licenses, ["MIT"]}, + {links, [{"Github", "https://github.com/g-andrade/erlquad"}]} ]}.