Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
andriiheonia committed Dec 21, 2024
1 parent d407e9e commit bfe2fe4
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 32 deletions.
5 changes: 3 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ <h3><a name="ex2" class="anchor" href="#ex2"><span class="octicon octicon-link">

<!-- Example 3 -->
<h3><a name="ex3" class="anchor" href="#ex3"><span class="octicon octicon-link"></span>Multiple Shapes</a></h3>
<p>If you want to get hulls of a point set that looks like a multipolygon, then you need to call <code>hull</code> function for each subset (for each polygon). In this example we use LukaszKrawczyk's <a href="https://github.com/LukaszKrawczyk/clustering" target="_blank">density based clustering library</a> (but you can use any other implementation) to split one large point set to several groups, after that we get hulls for each one:</p>
<p>If you want to get hulls of a point set that looks like a multipolygon, then you need to call <code>hull</code> function for each subset (for each polygon). In this example we use <a href="https://github.com/LukaszKrawczyk/clustering" target="_blank">density based clustering library</a> (but you can use any other implementation) to split one large point set to several groups, after that we get hulls for each one:</p>
<pre><code>var clusters,
dbscan = new DBSCAN(),
pointset = [[14, 18], [22, 19], [23, 20], ...];
Expand Down Expand Up @@ -346,7 +346,8 @@ <h3><a name="ex5" class="anchor" href="#ex5"><span class="octicon octicon-link">
</div>
<footer>
<div class="inner">
&copy; 2014-2024 Andrii Heonia
<p>This page was generated by <a href="https://pages.github.com">GitHub Pages</a> using the Architect theme by <a href="https://twitter.com/jasonlong">Jason Long</a>.</p>
<p>The examples above use open source libraries, their licenses are available by following <a href="https://andriiheonia.github.io/hull/javascripts/NOTICE">this URL</a>.</p>
</div>
</footer>
<script>
Expand Down
50 changes: 50 additions & 0 deletions javascripts/NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
This page uses third-party open source libraries, their licenses are provided below:

-----

The MIT License

Copyright © 2013 Abeja Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the “Software”), to deal in the
Software without restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

The software is provided “as is”, without warranty of any kind, express or
implied, including but not limited to the warranties of merchantability, fitness
for a particular purpose and noninfringement. In no event shall the authors or
copyright holders be liable for any claim, damages or other liability, whether
in an action of contract, tort or otherwise, arising from, out of or in
connection with the software or the use or other dealings in the software.

-----

Copyright (c) 2010-2013, Vladimir Agafonkin
Copyright (c) 2010-2011, CloudMade
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are
permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of
conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list
of conditions and the following disclaimer in the documentation and/or other materials
provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 changes: 14 additions & 30 deletions javascripts/hull.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,25 @@
/* hull.js bundle for examples page */
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.hull = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
function _cross(o, a, b) {
return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]);
function _ccw(p1, p2, p3) {
return (p2[0] - p1[0]) * (p3[1] - p1[1]) - (p2[1] - p1[1]) * (p3[0] - p1[0]) <= 0;
}

function _upperTangent(pointset) {
const lower = [];
for (let l = 0; l < pointset.length; l++) {
while (lower.length >= 2 && (_cross(lower[lower.length - 2], lower[lower.length - 1], pointset[l]) <= 0)) {
lower.pop();
function _tangent(pointset) {
const res = [];
for (let t = 0; t < pointset.length; t++) {
while (res.length > 1 && _ccw(res[res.length - 2], res[res.length - 1], pointset[t])) {
res.pop();
}
lower.push(pointset[l]);
res.push(pointset[t]);
}
lower.pop();
return lower;
}

function _lowerTangent(pointset) {
const reversed = pointset.reverse(),
upper = [];
for (let u = 0; u < reversed.length; u++) {
while (upper.length >= 2 && (_cross(upper[upper.length - 2], upper[upper.length - 1], reversed[u]) <= 0)) {
upper.pop();
}
upper.push(reversed[u]);
}
upper.pop();
return upper;
res.pop();
return res;
}

// pointset has to be sorted by X
function convex(pointset) {
const upper = _upperTangent(pointset),
lower = _lowerTangent(pointset);
const upper = _tangent(pointset),
lower = _tangent(pointset.reverse());
const convex = lower.concat(upper);
convex.push(pointset[0]);
return convex;
Expand Down Expand Up @@ -164,11 +152,7 @@

module.exports = grid;
},{}],4:[function(require,module,exports){
/*
(c) 2014-2024, Andrii Heonia
Hull.js is a JavaScript library that builds concave hull by set of points.
https://github.com/andriiheonia/hull
*/
/* The license text can be found in the LICENSE file */

'use strict';

Expand Down

0 comments on commit bfe2fe4

Please sign in to comment.