This is an automated email from the ASF dual-hosted git repository. mattjuntunen pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-geometry.git
commit 92c44343cd6a80ea35d9be4cc466934e1dd9e335 Author: Andreas Goß <andreas.goss1...@gmail.com> AuthorDate: Wed Jul 19 20:16:44 2023 +0200 GEOMETRY-144 Delete hull module --- commons-geometry-hull/CONTRIBUTING.md | 115 ----- commons-geometry-hull/LICENSE | 201 -------- commons-geometry-hull/NOTICE | 6 - commons-geometry-hull/README.md | 105 ----- commons-geometry-hull/pom.xml | 97 ---- .../commons/geometry/hull/ConvexHullGenerator.java | 42 -- .../twod/AbstractConvexHullGenerator2D.java | 130 ------ .../hull/euclidean/twod/AklToussaintHeuristic.java | 163 ------- .../hull/euclidean/twod/ConvexHullGenerator2D.java | 32 -- .../hull/euclidean/twod/MonotoneChain.java | 162 ------- .../geometry/hull/euclidean/twod/package-info.java | 25 - .../apache/commons/geometry/hull/package-info.java | 24 - .../src/site/resources/profile.jacoco | 17 - commons-geometry-hull/src/site/site.xml | 41 -- .../geometry/hull/DocumentationExamplesTest.java | 76 ---- .../euclidean/twod/AklToussaintHeuristicTest.java | 38 -- .../hull/euclidean/twod/ConvexHull2DTest.java | 177 ------- .../twod/ConvexHullGenerator2DAbstractTest.java | 506 --------------------- .../hull/euclidean/twod/MonotoneChainTest.java | 57 --- pom.xml | 1 - 20 files changed, 2015 deletions(-) diff --git a/commons-geometry-hull/CONTRIBUTING.md b/commons-geometry-hull/CONTRIBUTING.md deleted file mode 100644 index 457bbfc4..00000000 --- a/commons-geometry-hull/CONTRIBUTING.md +++ /dev/null @@ -1,115 +0,0 @@ -<!--- - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---> -<!--- - +======================================================================+ - |**** ****| - |**** THIS FILE IS GENERATED BY THE COMMONS BUILD PLUGIN ****| - |**** DO NOT EDIT DIRECTLY ****| - |**** ****| - +======================================================================+ - | TEMPLATE FILE: contributing-md-template.md | - | commons-build-plugin/trunk/src/main/resources/commons-xdoc-templates | - +======================================================================+ - | | - | 1) Re-generate using: mvn commons-build:contributing-md | - | | - | 2) Set the following properties in the component's pom: | - | - commons.jira.id (required, alphabetic, upper case) | - | | - | 3) Example Properties | - | | - | <properties> | - | <commons.jira.id>MATH</commons.jira.id> | - | </properties> | - | | - +======================================================================+ ----> -Contributing to Apache Commons Geometry Hull -====================== - -You have found a bug or you have an idea for a cool new feature? Contributing code is a great way to give something back to -the open source community. Before you dig right into the code there are a few guidelines that we need contributors to -follow so that we can have a chance of keeping on top of things. - -Getting Started ---------------- - -+ Make sure you have a [JIRA account](https://issues.apache.org/jira/). -+ Make sure you have a [GitHub account](https://github.com/signup/free). -+ If you're planning to implement a new feature it makes sense to discuss your changes on the [dev list](https://commons.apache.org/mail-lists.html) first. This way you can make sure you're not wasting your time on something that isn't considered to be in Apache Commons Geometry Hull's scope. -+ Submit a [Jira Ticket][jira] for your issue, assuming one does not already exist. - + Clearly describe the issue including steps to reproduce when it is a bug. - + Make sure you fill in the earliest version that you know has the issue. -+ Find the corresponding [repository on GitHub](https://github.com/apache/?query=commons-), -[fork](https://help.github.com/articles/fork-a-repo/) and check out your forked repository. - -Making Changes --------------- - -+ Create a _topic branch_ for your isolated work. - * Usually you should base your branch on the `master` or `trunk` branch. - * A good topic branch name can be the JIRA bug id plus a keyword, e.g. `GEOMETRY-123-InputStream`. - * If you have submitted multiple JIRA issues, try to maintain separate branches and pull requests. -+ Make commits of logical units. - * Make sure your commit messages are meaningful and in the proper format. Your commit message should contain the key of the JIRA issue. - * e.g. `GEOMETRY-123: Close input stream earlier` -+ Respect the original code style: - + Only use spaces for indentation. - + Create minimal diffs - disable _On Save_ actions like _Reformat Source Code_ or _Organize Imports_. If you feel the source code should be reformatted create a separate PR for this change first. - + Check for unnecessary whitespace with `git diff` -- check before committing. -+ Make sure you have added the necessary tests for your changes, typically in `src/test/java`. -+ Run all the tests with `mvn clean verify` to assure nothing else was accidentally broken. - -Making Trivial Changes ----------------------- - -The JIRA tickets are used to generate the changelog for the next release. - -For changes of a trivial nature to comments and documentation, it is not always necessary to create a new ticket in JIRA. -In this case, it is appropriate to start the first line of a commit with '(doc)' instead of a ticket number. - - -Submitting Changes ------------------- - -+ Sign and submit the Apache [Contributor License Agreement][cla] if you haven't already. - * Note that small patches & typical bug fixes do not require a CLA as - clause 5 of the [Apache License](https://www.apache.org/licenses/LICENSE-2.0.html#contributions) - covers them. -+ Push your changes to a topic branch in your fork of the repository. -+ Submit a _Pull Request_ to the corresponding repository in the `apache` organization. - * Verify _Files Changed_ shows only your intended changes and does not - include additional files like `target/*.class` -+ Update your JIRA ticket and include a link to the pull request in the ticket. - -If you prefer to not use GitHub, then you can instead use -`git format-patch` (or `svn diff`) and attach the patch file to the JIRA issue. - - -Additional Resources --------------------- - -+ [Contributing patches](https://commons.apache.org/patches.html) -+ [Apache Commons Geometry Hull JIRA project page][jira] -+ [Contributor License Agreement][cla] -+ [General GitHub documentation](https://help.github.com/) -+ [GitHub pull request documentation](https://help.github.com/articles/creating-a-pull-request/) -+ [Apache Commons Twitter Account](https://twitter.com/ApacheCommons) -+ `#apache-commons` IRC channel on `irc.freenode.net` - -[cla]:https://www.apache.org/licenses/#clas -[jira]:https://issues.apache.org/jira/browse/GEOMETRY diff --git a/commons-geometry-hull/LICENSE b/commons-geometry-hull/LICENSE deleted file mode 100644 index 261eeb9e..00000000 --- a/commons-geometry-hull/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/commons-geometry-hull/NOTICE b/commons-geometry-hull/NOTICE deleted file mode 100644 index 2d5c7e1a..00000000 --- a/commons-geometry-hull/NOTICE +++ /dev/null @@ -1,6 +0,0 @@ -Apache Commons Geometry -Copyright 2022 The Apache Software Foundation - -This product includes software developed at -The Apache Software Foundation (http://www.apache.org/). - diff --git a/commons-geometry-hull/README.md b/commons-geometry-hull/README.md deleted file mode 100644 index aa080ff5..00000000 --- a/commons-geometry-hull/README.md +++ /dev/null @@ -1,105 +0,0 @@ -<!--- - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---> -<!--- - +======================================================================+ - |**** ****| - |**** THIS FILE IS GENERATED BY THE COMMONS BUILD PLUGIN ****| - |**** DO NOT EDIT DIRECTLY ****| - |**** ****| - +======================================================================+ - | TEMPLATE FILE: readme-md-template.md | - | commons-build-plugin/trunk/src/main/resources/commons-xdoc-templates | - +======================================================================+ - | | - | 1) Re-generate using: mvn commons-build:readme-md | - | | - | 2) Set the following properties in the component's pom: | - | - commons.componentid (required, alphabetic, lower case) | - | - commons.release.version (required) | - | | - | 3) Example Properties | - | | - | <properties> | - | <commons.componentid>math</commons.componentid> | - | <commons.release.version>1.2</commons.release.version> | - | </properties> | - | | - +======================================================================+ ----> -Apache Commons Geometry Hull -=================== - -[](https://github.com/apache/commons-geometry/actions/workflows/maven.yml) -[](https://app.codecov.io/gh/apache/commons-geometry) -[](https://maven-badges.herokuapp.com/maven-central/org.apache.commons/commons-geometry-hull/) -[](http://www.apache.org/licenses/LICENSE-2.0.html) - -Algorithms for computing convex hulls. - -Documentation -------------- - -More information can be found on the [Apache Commons Geometry Hull homepage](https://commons.apache.org/proper/commons-geometry). -The [JavaDoc](https://commons.apache.org/proper/commons-geometry/javadocs/api-release) can be browsed. -Questions related to the usage of Apache Commons Geometry Hull should be posted to the [user mailing list][ml]. - -Where can I get the latest release? ------------------------------------ -You can download source and binaries from our [download page](https://commons.apache.org/proper/commons-geometry/download_geometry.cgi). - -Alternatively, you can pull it from the central Maven repositories: - -```xml -<dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-geometry-hull</artifactId> - <version>1.1-SNAPSHOT</version> -</dependency> -``` - -Contributing ------------- - -We accept Pull Requests via GitHub. The [developer mailing list][ml] is the main channel of communication for contributors. -There are some guidelines which will make applying PRs easier for us: -+ No tabs! Please use spaces for indentation. -+ Respect the code style. -+ Create minimal diffs - disable on save actions like reformat source code or organize imports. If you feel the source code should be reformatted create a separate PR for this change. -+ Provide JUnit tests for your changes and make sure your changes don't break any existing tests by running ```mvn```. - -If you plan to contribute on a regular basis, please consider filing a [contributor license agreement](https://www.apache.org/licenses/#clas). -You can learn more about contributing via GitHub in our [contribution guidelines](CONTRIBUTING.md). - -License -------- -This code is under the [Apache Licence v2](https://www.apache.org/licenses/LICENSE-2.0). - -See the `NOTICE` file for required notices and attributions. - -Donations ---------- -You like Apache Commons Geometry Hull? Then [donate back to the ASF](https://www.apache.org/foundation/contributing.html) to support the development. - -Additional Resources --------------------- - -+ [Apache Commons Homepage](https://commons.apache.org/) -+ [Apache Issue Tracker (JIRA)](https://issues.apache.org/jira/browse/GEOMETRY) -+ [Apache Commons Twitter Account](https://twitter.com/ApacheCommons) -+ `#apache-commons` IRC channel on `irc.freenode.org` - -[ml]:https://commons.apache.org/mail-lists.html diff --git a/commons-geometry-hull/pom.xml b/commons-geometry-hull/pom.xml deleted file mode 100644 index 931abfb0..00000000 --- a/commons-geometry-hull/pom.xml +++ /dev/null @@ -1,97 +0,0 @@ -<?xml version="1.0"?> -<!-- - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---> -<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" - xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.apache.commons</groupId> - <artifactId>commons-geometry-parent</artifactId> - <version>1.1-SNAPSHOT</version> - </parent> - - <artifactId>commons-geometry-hull</artifactId> - <name>Apache Commons Geometry Hull</name> - - <description>Algorithms for computing convex hulls.</description> - - <properties> - <!-- OSGi --> - <commons.osgi.symbolicName>org.apache.commons.geometry.hull</commons.osgi.symbolicName> - <commons.osgi.export>org.apache.commons.geometry.hull.*</commons.osgi.export> - <!-- Java 9+ --> - <commons.module.name>org.apache.commons.geometry.hull</commons.module.name> - <!-- Workaround to avoid duplicating config files. --> - <geometry.parent.dir>${basedir}/..</geometry.parent.dir> - <geometry.jira.component>hull</geometry.jira.component> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-geometry-core</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-geometry-euclidean</artifactId> - <version>${project.version}</version> - </dependency> - - <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-geometry-core</artifactId> - <version>${project.version}</version> - <classifier>tests</classifier> - <type>test-jar</type> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-geometry-euclidean</artifactId> - <version>${project.version}</version> - <classifier>tests</classifier> - <type>test-jar</type> - <scope>test</scope> - </dependency> - - <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-rng-client-api</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-rng-simple</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-rng-sampling</artifactId> - <scope>test</scope> - </dependency> - <!-- testing --> - <dependency> - <groupId>org.junit.jupiter</groupId> - <artifactId>junit-jupiter</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - -</project> diff --git a/commons-geometry-hull/src/main/java/org/apache/commons/geometry/hull/ConvexHullGenerator.java b/commons-geometry-hull/src/main/java/org/apache/commons/geometry/hull/ConvexHullGenerator.java deleted file mode 100644 index 7724ee8c..00000000 --- a/commons-geometry-hull/src/main/java/org/apache/commons/geometry/hull/ConvexHullGenerator.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.geometry.hull; - -import java.util.Collection; - -import org.apache.commons.geometry.core.ConvexHull; -import org.apache.commons.geometry.core.Point; - -/** - * Interface for convex hull generators. - * - * @param <P> Type of the {@link Point} - * - * @see <a href="http://en.wikipedia.org/wiki/Convex_hull">Convex Hull (Wikipedia)</a> - * @see <a href="http://mathworld.wolfram.com/ConvexHull.html">Convex Hull (MathWorld)</a> - */ -public interface ConvexHullGenerator<P extends Point<P>> { - /** - * Build a convex hull from the set of input points. - * - * @param points the set of input points - * @return the convex hull - * @throws IllegalStateException if generator fails to generate a convex hull for - * the given set of input points - */ - ConvexHull<P> generate(Collection<P> points); -} diff --git a/commons-geometry-hull/src/main/java/org/apache/commons/geometry/hull/euclidean/twod/AbstractConvexHullGenerator2D.java b/commons-geometry-hull/src/main/java/org/apache/commons/geometry/hull/euclidean/twod/AbstractConvexHullGenerator2D.java deleted file mode 100644 index 45649d98..00000000 --- a/commons-geometry-hull/src/main/java/org/apache/commons/geometry/hull/euclidean/twod/AbstractConvexHullGenerator2D.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.geometry.hull.euclidean.twod; - -import java.util.Collection; -import java.util.Iterator; - -import org.apache.commons.geometry.euclidean.twod.Vector2D; -import org.apache.commons.numbers.core.Precision; - -/** - * Abstract base class for convex hull generators in the two-dimensional Euclidean space. - */ -abstract class AbstractConvexHullGenerator2D implements ConvexHullGenerator2D { - - /** Precision context used to compare floating point numbers. */ - private final Precision.DoubleEquivalence precision; - - /** - * Indicates if collinear points on the hull shall be present in the output. - * If {@code false}, only the extreme points are added to the hull. - */ - private final boolean includeCollinearPoints; - - /** - * Simple constructor. - * - * @param includeCollinearPoints indicates if collinear points on the hull shall be - * added as hull vertices - * @param precision precision context used to compare floating point numbers - */ - protected AbstractConvexHullGenerator2D(final boolean includeCollinearPoints, - final Precision.DoubleEquivalence precision) { - this.includeCollinearPoints = includeCollinearPoints; - this.precision = precision; - } - - /** Get the object used to determine floating point equality for this region. - * @return the floating point precision context for the instance - */ - public Precision.DoubleEquivalence getPrecision() { - return precision; - } - - /** - * Returns if collinear points on the hull will be added as hull vertices. - * @return {@code true} if collinear points are added as hull vertices, or {@code false} - * if only extreme points are present. - */ - public boolean isIncludeCollinearPoints() { - return includeCollinearPoints; - } - - /** {@inheritDoc} */ - @Override - public ConvexHull2D generate(final Collection<Vector2D> points) { - Collection<Vector2D> hullVertices; - if (points.size() < 2) { - hullVertices = points; - } else { - hullVertices = findHullVertices(points); - } - - if (!isConvex(hullVertices)) { - throw new IllegalStateException("Convex hull algorithm failed to generate solution"); - } - - return new ConvexHull2D(hullVertices, precision); - } - - /** - * Find the convex hull vertices from the set of input points. - * @param points the set of input points - * @return the convex hull vertices in CCW winding - */ - protected abstract Collection<Vector2D> findHullVertices(Collection<Vector2D> points); - - /** Return true if the given vertices define a convex hull. - * @param vertices the hull vertices - * @return {@code true} if the vertices form a convex hull, {@code false} otherwise - */ - private boolean isConvex(final Collection<Vector2D> vertices) { - final int size = vertices.size(); - - if (size < 3) { - // 1 or 2 points always define a convex set - return true; - } - - final Iterator<Vector2D> it = vertices.iterator(); - - Vector2D p1 = it.next(); - Vector2D p2 = it.next(); - Vector2D p3; - - Vector2D v1; - Vector2D v2; - - while (it.hasNext()) { - p3 = it.next(); - - v1 = p1.vectorTo(p2); - v2 = p2.vectorTo(p3); - - // negative signed areas mean a clockwise winding - if (precision.compare(v1.signedArea(v2), 0.0) < 0) { - return false; - } - - p1 = p2; - p2 = p3; - } - - return true; - } -} diff --git a/commons-geometry-hull/src/main/java/org/apache/commons/geometry/hull/euclidean/twod/AklToussaintHeuristic.java b/commons-geometry-hull/src/main/java/org/apache/commons/geometry/hull/euclidean/twod/AklToussaintHeuristic.java deleted file mode 100644 index 15be6624..00000000 --- a/commons-geometry-hull/src/main/java/org/apache/commons/geometry/hull/euclidean/twod/AklToussaintHeuristic.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.geometry.hull.euclidean.twod; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.apache.commons.geometry.euclidean.twod.Vector2D; - -/** - * A simple heuristic to improve the performance of convex hull algorithms. - * <p> - * The heuristic is based on the idea of a convex quadrilateral, which is formed by - * four points with the lowest and highest x / y coordinates. Any point that lies inside - * this quadrilateral can not be part of the convex hull and can thus be safely discarded - * before generating the convex hull itself. - * <p> - * The complexity of the operation is O(n), and may greatly improve the time it takes to - * construct the convex hull afterwards, depending on the point distribution. - * - * @see <a href="http://en.wikipedia.org/wiki/Convex_hull_algorithms#Akl-Toussaint_heuristic"> - * Akl-Toussaint heuristic (Wikipedia)</a> - */ -public final class AklToussaintHeuristic { - - /** Hide utility constructor. */ - private AklToussaintHeuristic() { - } - - /** - * Returns a point set that is reduced by all points for which it is safe to assume - * that they are not part of the convex hull. - * - * @param points the original point set - * @return a reduced point set, useful as input for convex hull algorithms - */ - public static Collection<Vector2D> reducePoints(final Collection<Vector2D> points) { - - // find the leftmost point - int size = 0; - Vector2D minX = null; - Vector2D maxX = null; - Vector2D minY = null; - Vector2D maxY = null; - for (final Vector2D p : points) { - if (minX == null || p.getX() < minX.getX()) { - minX = p; - } - if (maxX == null || p.getX() > maxX.getX()) { - maxX = p; - } - if (minY == null || p.getY() < minY.getY()) { - minY = p; - } - if (maxY == null || p.getY() > maxY.getY()) { - maxY = p; - } - size++; - } - - if (size < 4) { - return points; - } - - final List<Vector2D> quadrilateral = buildQuadrilateral(minY, maxX, maxY, minX); - // if the quadrilateral is not well formed, e.g. only 2 points, do not attempt to reduce - if (quadrilateral.size() < 3) { - return points; - } - - final List<Vector2D> reducedPoints = new ArrayList<>(quadrilateral); - for (final Vector2D p : points) { - // check all points if they are within the quadrilateral - // in which case they can not be part of the convex hull - if (!insideQuadrilateral(p, quadrilateral)) { - reducedPoints.add(p); - } - } - - return reducedPoints; - } - - /** - * Build the convex quadrilateral with the found corner points (with min/max x/y coordinates). - * - * @param points the respective points with min/max x/y coordinate - * @return the quadrilateral - */ - private static List<Vector2D> buildQuadrilateral(final Vector2D... points) { - final List<Vector2D> quadrilateral = new ArrayList<>(); - for (final Vector2D p : points) { - if (!quadrilateral.contains(p)) { - quadrilateral.add(p); - } - } - return quadrilateral; - } - - /** - * Checks if the given point is located within the convex quadrilateral. - * @param point the point to check - * @param quadrilateralPoints the convex quadrilateral, represented by 4 points - * @return {@code true} if the point is inside the quadrilateral, {@code false} otherwise - */ - private static boolean insideQuadrilateral(final Vector2D point, - final List<? extends Vector2D> quadrilateralPoints) { - - Vector2D v1 = quadrilateralPoints.get(0); - Vector2D v2 = quadrilateralPoints.get(1); - - if (point.equals(v1) || point.equals(v2)) { - return true; - } - - // get the location of the point relative to the first two vertices - final double last = signedAreaPoints(v1, v2, point); - final int size = quadrilateralPoints.size(); - // loop through the rest of the vertices - for (int i = 1; i < size; i++) { - v1 = v2; - v2 = quadrilateralPoints.get((i + 1) == size ? 0 : i + 1); - - if (point.equals(v2)) { - return true; - } - - // do side of line test: multiply the last location with this location - // if they are the same sign then the operation will yield a positive result - // -x * -y = +xy, x * y = +xy, -x * y = -xy, x * -y = -xy - if (last * signedAreaPoints(v1, v2, point) < 0) { - return false; - } - } - return true; - } - - /** Compute the signed area of the parallelogram formed by vectors between the given points. The first - * vector points from {@code p0} to {@code p1} and the second from {@code p0} to {@code p3}. - * @param p0 first point - * @param p1 second point - * @param p2 third point - * @return signed area of parallelogram formed by vectors between the given points - */ - private static double signedAreaPoints(final Vector2D p0, final Vector2D p1, final Vector2D p2) { - return p0.vectorTo(p1).signedArea(p0.vectorTo(p2)); - } - -} diff --git a/commons-geometry-hull/src/main/java/org/apache/commons/geometry/hull/euclidean/twod/ConvexHullGenerator2D.java b/commons-geometry-hull/src/main/java/org/apache/commons/geometry/hull/euclidean/twod/ConvexHullGenerator2D.java deleted file mode 100644 index bd8caa70..00000000 --- a/commons-geometry-hull/src/main/java/org/apache/commons/geometry/hull/euclidean/twod/ConvexHullGenerator2D.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.geometry.hull.euclidean.twod; - -import java.util.Collection; - -import org.apache.commons.geometry.euclidean.twod.Vector2D; -import org.apache.commons.geometry.hull.ConvexHullGenerator; - -/** - * Interface for convex hull generators in the two-dimensional Euclidean space. - */ -public interface ConvexHullGenerator2D extends ConvexHullGenerator<Vector2D> { - - /** {@inheritDoc} */ - @Override - ConvexHull2D generate(Collection<Vector2D> points); -} diff --git a/commons-geometry-hull/src/main/java/org/apache/commons/geometry/hull/euclidean/twod/MonotoneChain.java b/commons-geometry-hull/src/main/java/org/apache/commons/geometry/hull/euclidean/twod/MonotoneChain.java deleted file mode 100644 index b5217277..00000000 --- a/commons-geometry-hull/src/main/java/org/apache/commons/geometry/hull/euclidean/twod/MonotoneChain.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.geometry.hull.euclidean.twod; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.apache.commons.geometry.euclidean.twod.Lines; -import org.apache.commons.geometry.euclidean.twod.Vector2D; -import org.apache.commons.numbers.core.Precision; - -/** - * Implements Andrew's monotone chain method to generate the convex hull of a finite set of - * points in the two-dimensional Euclidean space. - * <p> - * The runtime complexity is O(n log n), with n being the number of input points. If the - * point set is already sorted (by x-coordinate), the runtime complexity is O(n). - * <p> - * The implementation is not sensitive to collinear points on the hull. The parameter - * {@code includeCollinearPoints} allows to control the behavior with regard to collinear points. - * If {@code true}, all points on the boundary of the hull will be added to the hull vertices, - * otherwise only the extreme points will be present. By default, collinear points are not added - * as hull vertices. - * <p> - * - * @see <a href="http://en.wikibooks.org/wiki/Algorithm_Implementation/Geometry/Convex_hull/Monotone_chain"> - * Andrew's monotone chain algorithm (Wikibooks)</a> - */ -public class MonotoneChain extends AbstractConvexHullGenerator2D { - - /** Create a new instance that only includes extreme points as hull vertices. - * @param precision precision context used to compare floating point numbers - */ - public MonotoneChain(final Precision.DoubleEquivalence precision) { - this(false, precision); - } - - /** Create a new instance with the given parameters. - * @param includeCollinearPoints whether collinear points shall be added as hull vertices - * @param precision precision context used to compare floating point numbers - */ - public MonotoneChain(final boolean includeCollinearPoints, final Precision.DoubleEquivalence precision) { - super(includeCollinearPoints, precision); - } - - /** {@inheritDoc} */ - @Override - public Collection<Vector2D> findHullVertices(final Collection<Vector2D> points) { - - final List<Vector2D> pointsSortedByXAxis = new ArrayList<>(points); - - // sort the points in increasing order on the x-axis - pointsSortedByXAxis.sort((o1, o2) -> { - final Precision.DoubleEquivalence precision = getPrecision(); - // need to take the tolerance value into account, otherwise collinear points - // will not be handled correctly when building the upper/lower hull - final int cmp = precision.compare(o1.getX(), o2.getX()); - if (cmp == 0) { - return precision.compare(o1.getY(), o2.getY()); - } else { - return cmp; - } - }); - - // build lower hull - final List<Vector2D> lowerHull = new ArrayList<>(); - for (final Vector2D p : pointsSortedByXAxis) { - updateHull(p, lowerHull); - } - - // build upper hull - final List<Vector2D> upperHull = new ArrayList<>(); - for (int idx = pointsSortedByXAxis.size() - 1; idx >= 0; idx--) { - final Vector2D p = pointsSortedByXAxis.get(idx); - updateHull(p, upperHull); - } - - // concatenate the lower and upper hulls - // the last point of each list is omitted as it is repeated at the beginning of the other list - final List<Vector2D> hullVertices = new ArrayList<>(lowerHull.size() + upperHull.size() - 2); - for (int idx = 0; idx < lowerHull.size() - 1; idx++) { - hullVertices.add(lowerHull.get(idx)); - } - for (int idx = 0; idx < upperHull.size() - 1; idx++) { - hullVertices.add(upperHull.get(idx)); - } - - // special case: if the lower and upper hull may contain only 1 point if all are identical - if (hullVertices.isEmpty() && !lowerHull.isEmpty()) { - hullVertices.add(lowerHull.get(0)); - } - - return hullVertices; - } - - /** - * Update the partial hull with the current point. - * - * @param point the current point - * @param hull the partial hull - */ - private void updateHull(final Vector2D point, final List<Vector2D> hull) { - final Precision.DoubleEquivalence precision = getPrecision(); - - if (hull.size() == 1) { - // ensure that we do not add an identical point - final Vector2D p1 = hull.get(0); - if (p1.eq(point, precision)) { - return; - } - } - - while (hull.size() >= 2) { - final int size = hull.size(); - final Vector2D p1 = hull.get(size - 2); - final Vector2D p2 = hull.get(size - 1); - - final double offset = Lines.fromPoints(p1, p2, precision).offset(point); - if (precision.eqZero(offset)) { - // the point is collinear to the line (p1, p2) - - final double distanceToCurrent = p1.distance(point); - if (precision.eqZero(distanceToCurrent) || precision.eqZero(p2.distance(point))) { - // the point is assumed to be identical to either p1 or p2 - return; - } - - final double distanceToLast = p1.distance(p2); - if (isIncludeCollinearPoints()) { - final int index = distanceToCurrent < distanceToLast ? size - 1 : size; - hull.add(index, point); - } else { - if (distanceToCurrent > distanceToLast) { - hull.remove(size - 1); - hull.add(point); - } - } - return; - } else if (offset > 0) { - hull.remove(size - 1); - } else { - break; - } - } - hull.add(point); - } -} diff --git a/commons-geometry-hull/src/main/java/org/apache/commons/geometry/hull/euclidean/twod/package-info.java b/commons-geometry-hull/src/main/java/org/apache/commons/geometry/hull/euclidean/twod/package-info.java deleted file mode 100644 index ca9ae62d..00000000 --- a/commons-geometry-hull/src/main/java/org/apache/commons/geometry/hull/euclidean/twod/package-info.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * - * <p> - * This package provides algorithms to generate the convex hull - * for a set of points in an two-dimensional Euclidean space. - * </p> - * - */ -package org.apache.commons.geometry.hull.euclidean.twod; diff --git a/commons-geometry-hull/src/main/java/org/apache/commons/geometry/hull/package-info.java b/commons-geometry-hull/src/main/java/org/apache/commons/geometry/hull/package-info.java deleted file mode 100644 index c52c08ce..00000000 --- a/commons-geometry-hull/src/main/java/org/apache/commons/geometry/hull/package-info.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * - * <p> - * This package provides interfaces and classes related to the convex hull problem. - * </p> - * - */ -package org.apache.commons.geometry.hull; diff --git a/commons-geometry-hull/src/site/resources/profile.jacoco b/commons-geometry-hull/src/site/resources/profile.jacoco deleted file mode 100644 index a12755f3..00000000 --- a/commons-geometry-hull/src/site/resources/profile.jacoco +++ /dev/null @@ -1,17 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ----------------------------------------------------------------------------- -# -# Empty file used to automatically trigger JaCoCo profile from commons parent pom diff --git a/commons-geometry-hull/src/site/site.xml b/commons-geometry-hull/src/site/site.xml deleted file mode 100644 index 54b485f5..00000000 --- a/commons-geometry-hull/src/site/site.xml +++ /dev/null @@ -1,41 +0,0 @@ -<?xml version="1.0" encoding="ISO-8859-1"?> -<!-- - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---> -<project name="Geometry"> - <bannerRight> - <name>Apache Commons Geometry</name> - <!-- Use a full URL allows a correct banner for the modules. --> - <src>https://commons.apache.org/proper/commons-geometry/images/commons_geometry.small.png</src> - <href>https://commons.apache.org/proper/commons-geometry/index.html</href> - </bannerRight> - - <body> - <menu name="Geometry"> - <item name="Overview" href="/index.html"/> - <item name="Latest API docs (development)" - href="apidocs/index.html"/> - <!-- <item name="Javadoc (1.0 release)" - href="https://commons.apache.org/geometry/commons-geometry-hull/javadocs/api-1.0/index.html"/> --> - </menu> - - <head> - <![CDATA[<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> - </script>]]> - </head> - - </body> -</project> diff --git a/commons-geometry-hull/src/test/java/org/apache/commons/geometry/hull/DocumentationExamplesTest.java b/commons-geometry-hull/src/test/java/org/apache/commons/geometry/hull/DocumentationExamplesTest.java deleted file mode 100644 index 6a00f918..00000000 --- a/commons-geometry-hull/src/test/java/org/apache/commons/geometry/hull/DocumentationExamplesTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.geometry.hull; - -import java.util.Arrays; -import java.util.List; - -import org.apache.commons.geometry.euclidean.EuclideanTestUtils; -import org.apache.commons.geometry.euclidean.twod.ConvexArea; -import org.apache.commons.geometry.euclidean.twod.Vector2D; -import org.apache.commons.geometry.hull.euclidean.twod.ConvexHull2D; -import org.apache.commons.geometry.hull.euclidean.twod.MonotoneChain; -import org.apache.commons.numbers.core.Precision; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -/** This class contains code listed as examples in the user guide and other documentation. - * If any portion of this code changes, the corresponding examples in the documentation <em>must</em> be updated. - */ -class DocumentationExamplesTest { - - private static final double TEST_EPS = 1e-15; - - @Test - void testMonotoneChainExample() { - final Precision.DoubleEquivalence precision = Precision.doubleEquivalenceOfEpsilon(1e-10); - - // create a list of input points for the algorithm - final List<Vector2D> pts = Arrays.asList( - Vector2D.ZERO, - Vector2D.of(0.5, 0.5), - Vector2D.of(0, 0.5), - Vector2D.of(0, 1), - Vector2D.of(0.25, 0.1), - Vector2D.of(1, 0), - Vector2D.of(1, 1), - Vector2D.of(0.75, 0.9) - ); - - // create an instance of the monotone chain convex hull generator - final MonotoneChain mc = new MonotoneChain(precision); - - // compute the convex hull - final ConvexHull2D hull = mc.generate(pts); - - // list the vertices from the input that were used in the hull - final List<Vector2D> vertices = hull.getVertices(); // [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0)] - - // get the hull as a region - final ConvexArea region = hull.getRegion(); - final boolean containsAll = pts.stream().allMatch(region::contains); // true - region contains all input points - - // --- - Assertions.assertEquals(4, vertices.size()); - EuclideanTestUtils.assertCoordinatesEqual(Vector2D.ZERO, vertices.get(0), TEST_EPS); - EuclideanTestUtils.assertCoordinatesEqual(Vector2D.of(1, 0), vertices.get(1), TEST_EPS); - EuclideanTestUtils.assertCoordinatesEqual(Vector2D.of(1, 1), vertices.get(2), TEST_EPS); - EuclideanTestUtils.assertCoordinatesEqual(Vector2D.of(0, 1), vertices.get(3), TEST_EPS); - - Assertions.assertTrue(containsAll); - } -} diff --git a/commons-geometry-hull/src/test/java/org/apache/commons/geometry/hull/euclidean/twod/AklToussaintHeuristicTest.java b/commons-geometry-hull/src/test/java/org/apache/commons/geometry/hull/euclidean/twod/AklToussaintHeuristicTest.java deleted file mode 100644 index 0f08c8d3..00000000 --- a/commons-geometry-hull/src/test/java/org/apache/commons/geometry/hull/euclidean/twod/AklToussaintHeuristicTest.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.geometry.hull.euclidean.twod; - -import java.util.Collection; - -import org.apache.commons.geometry.euclidean.twod.Vector2D; - -/** - * Test class for AklToussaintHeuristic. - */ -class AklToussaintHeuristicTest extends ConvexHullGenerator2DAbstractTest { - - @Override - protected ConvexHullGenerator2D createConvexHullGenerator(final boolean includeCollinearPoints) { - return new MonotoneChain(includeCollinearPoints, TEST_PRECISION); - } - - @Override - protected Collection<Vector2D> reducePoints(final Collection<Vector2D> points) { - return AklToussaintHeuristic.reducePoints(points); - } - -} diff --git a/commons-geometry-hull/src/test/java/org/apache/commons/geometry/hull/euclidean/twod/ConvexHull2DTest.java b/commons-geometry-hull/src/test/java/org/apache/commons/geometry/hull/euclidean/twod/ConvexHull2DTest.java deleted file mode 100644 index 85ad53c4..00000000 --- a/commons-geometry-hull/src/test/java/org/apache/commons/geometry/hull/euclidean/twod/ConvexHull2DTest.java +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.geometry.hull.euclidean.twod; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import org.apache.commons.geometry.core.GeometryTestUtils; -import org.apache.commons.geometry.euclidean.EuclideanTestUtils; -import org.apache.commons.geometry.euclidean.twod.Vector2D; -import org.apache.commons.geometry.euclidean.twod.path.LinePath; -import org.apache.commons.numbers.core.Precision; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -class ConvexHull2DTest { - - private static final double TEST_EPS = 1e-10; - - private static final Precision.DoubleEquivalence TEST_PRECISION = - Precision.doubleEquivalenceOfEpsilon(TEST_EPS); - - @Test - void testProperties_noPoints() { - // act - final ConvexHull2D hull = new ConvexHull2D(Collections.emptyList(), TEST_PRECISION); - - // assert - Assertions.assertEquals(0, hull.getVertices().size()); - - final LinePath path = hull.getPath(); - Assertions.assertEquals(0, path.getElements().size()); - - final List<Vector2D> pathVertices = path.getVertexSequence(); - Assertions.assertEquals(0, pathVertices.size()); - - Assertions.assertNull(hull.getRegion()); - } - - @Test - void testProperties_singlePoint() { - // arrange - final List<Vector2D> vertices = Collections.singletonList(Vector2D.Unit.PLUS_X); - - // act - final ConvexHull2D hull = new ConvexHull2D(vertices, TEST_PRECISION); - - // assert - Assertions.assertEquals(vertices, hull.getVertices()); - - final LinePath path = hull.getPath(); - Assertions.assertEquals(0, path.getElements().size()); - - final List<Vector2D> pathVertices = path.getVertexSequence(); - Assertions.assertEquals(0, pathVertices.size()); - - Assertions.assertNull(hull.getRegion()); - } - - @Test - void testProperties_twoPoints() { - // arrange - final List<Vector2D> vertices = Arrays.asList(Vector2D.Unit.PLUS_X, Vector2D.Unit.PLUS_Y); - - // act - final ConvexHull2D hull = new ConvexHull2D(vertices, TEST_PRECISION); - - // assert - Assertions.assertEquals(vertices, hull.getVertices()); - - final LinePath path = hull.getPath(); - Assertions.assertEquals(1, path.getElements().size()); - - final List<Vector2D> pathVertices = path.getVertexSequence(); - Assertions.assertEquals(2, pathVertices.size()); - EuclideanTestUtils.assertCoordinatesEqual(Vector2D.Unit.PLUS_X, pathVertices.get(0), TEST_EPS); - EuclideanTestUtils.assertCoordinatesEqual(Vector2D.Unit.PLUS_Y, pathVertices.get(1), TEST_EPS); - - Assertions.assertNull(hull.getRegion()); - } - - @Test - void testProperties_threePoints() { - // arrange - final List<Vector2D> vertices = Arrays.asList(Vector2D.ZERO, Vector2D.Unit.PLUS_X, Vector2D.Unit.PLUS_Y); - - // act - final ConvexHull2D hull = new ConvexHull2D(vertices, TEST_PRECISION); - - // assert - Assertions.assertEquals(vertices, hull.getVertices()); - - final LinePath path = hull.getPath(); - Assertions.assertEquals(3, path.getElements().size()); - - final List<Vector2D> pathVertices = path.getVertexSequence(); - Assertions.assertEquals(4, pathVertices.size()); - EuclideanTestUtils.assertCoordinatesEqual(Vector2D.ZERO, pathVertices.get(0), TEST_EPS); - EuclideanTestUtils.assertCoordinatesEqual(Vector2D.Unit.PLUS_X, pathVertices.get(1), TEST_EPS); - EuclideanTestUtils.assertCoordinatesEqual(Vector2D.Unit.PLUS_Y, pathVertices.get(2), TEST_EPS); - EuclideanTestUtils.assertCoordinatesEqual(Vector2D.ZERO, pathVertices.get(3), TEST_EPS); - - Assertions.assertEquals(0.5, hull.getRegion().getSize(), TEST_EPS); - } - - @Test - void testProperties_fourPoints() { - // arrange - final List<Vector2D> vertices = Arrays.asList(Vector2D.ZERO, Vector2D.Unit.PLUS_X, - Vector2D.of(1, 1), Vector2D.Unit.PLUS_Y); - - // act - final ConvexHull2D hull = new ConvexHull2D(vertices, TEST_PRECISION); - - // assert - Assertions.assertEquals(vertices, hull.getVertices()); - - final LinePath path = hull.getPath(); - Assertions.assertEquals(4, path.getElements().size()); - - final List<Vector2D> pathVertices = path.getVertexSequence(); - Assertions.assertEquals(5, pathVertices.size()); - EuclideanTestUtils.assertCoordinatesEqual(Vector2D.ZERO, pathVertices.get(0), TEST_EPS); - EuclideanTestUtils.assertCoordinatesEqual(Vector2D.Unit.PLUS_X, pathVertices.get(1), TEST_EPS); - EuclideanTestUtils.assertCoordinatesEqual(Vector2D.of(1, 1), pathVertices.get(2), TEST_EPS); - EuclideanTestUtils.assertCoordinatesEqual(Vector2D.Unit.PLUS_Y, pathVertices.get(3), TEST_EPS); - EuclideanTestUtils.assertCoordinatesEqual(Vector2D.ZERO, pathVertices.get(4), TEST_EPS); - - Assertions.assertEquals(1.0, hull.getRegion().getSize(), TEST_EPS); - } - - @Test - void testVertexListCannotBeModified() { - // arrange - final List<Vector2D> vertices = new ArrayList<>(); - vertices.add(Vector2D.Unit.PLUS_X); - - final ConvexHull2D hull = new ConvexHull2D(vertices, TEST_PRECISION); - - // act - final List<Vector2D> hullVertices = hull.getVertices(); - - // assert - Assertions.assertNotSame(vertices, hullVertices); - - Assertions.assertThrows(UnsupportedOperationException.class, () -> hullVertices.add(Vector2D.Unit.PLUS_Y)); - } - - @Test - void testToString() { - // arrange - final List<Vector2D> vertices = Collections.singletonList(Vector2D.Unit.PLUS_X); - final ConvexHull2D hull = new ConvexHull2D(vertices, TEST_PRECISION); - - // act - final String str = hull.toString(); - - // assert - GeometryTestUtils.assertContains("ConvexHull2D[vertices= [(1", str); - } -} diff --git a/commons-geometry-hull/src/test/java/org/apache/commons/geometry/hull/euclidean/twod/ConvexHullGenerator2DAbstractTest.java b/commons-geometry-hull/src/test/java/org/apache/commons/geometry/hull/euclidean/twod/ConvexHullGenerator2DAbstractTest.java deleted file mode 100644 index 280cb538..00000000 --- a/commons-geometry-hull/src/test/java/org/apache/commons/geometry/hull/euclidean/twod/ConvexHullGenerator2DAbstractTest.java +++ /dev/null @@ -1,506 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.geometry.hull.euclidean.twod; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import org.apache.commons.geometry.core.Region; -import org.apache.commons.geometry.core.RegionLocation; -import org.apache.commons.geometry.euclidean.twod.ConvexArea; -import org.apache.commons.geometry.euclidean.twod.Vector2D; -import org.apache.commons.numbers.core.Precision; -import org.apache.commons.numbers.core.Sum; -import org.apache.commons.rng.UniformRandomProvider; -import org.apache.commons.rng.simple.RandomSource; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -/** - * Abstract base test class for 2D convex hull generators. - */ -public abstract class ConvexHullGenerator2DAbstractTest { - - protected static final double TEST_EPS = 1e-10; - - protected static final Precision.DoubleEquivalence TEST_PRECISION = - Precision.doubleEquivalenceOfEpsilon(TEST_EPS); - - protected ConvexHullGenerator2D generator; - - protected UniformRandomProvider random; - - protected abstract ConvexHullGenerator2D createConvexHullGenerator(boolean includeCollinearPoints); - - protected Collection<Vector2D> reducePoints(final Collection<Vector2D> points) { - // do nothing by default, may be overridden by other tests - return points; - } - - @BeforeEach - public void setUp() { - // by default, do not include collinear points - generator = createConvexHullGenerator(false); - random = RandomSource.XO_SHI_RO_256_PP.create(10); - } - - // ------------------------------------------------------------------------------ - - @Test - void testEmpty() { - // act - final ConvexHull2D hull = generator.generate(Collections.emptyList()); - - // assert - Assertions.assertEquals(0, hull.getVertices().size()); - Assertions.assertEquals(0, hull.getPath().getElements().size()); - Assertions.assertNull(hull.getRegion()); - } - - @Test - void testOnePoint() { - // arrange - final List<Vector2D> points = createRandomPoints(1); - - // act - final ConvexHull2D hull = generator.generate(points); - - // assert - Assertions.assertEquals(1, hull.getVertices().size()); - Assertions.assertEquals(0, hull.getPath().getElements().size()); - Assertions.assertNull(hull.getRegion()); - } - - @Test - void testTwoPoints() { - // arrange - final List<Vector2D> points = createRandomPoints(2); - - // act - final ConvexHull2D hull = generator.generate(points); - - // assert - Assertions.assertEquals(2, hull.getVertices().size()); - Assertions.assertEquals(1, hull.getPath().getElements().size()); - Assertions.assertNull(hull.getRegion()); - } - - @Test - void testAllIdentical() { - // arrange - final Collection<Vector2D> points = new ArrayList<>(); - points.add(Vector2D.of(1, 1)); - points.add(Vector2D.of(1, 1)); - points.add(Vector2D.of(1, 1)); - points.add(Vector2D.of(1, 1)); - - // act - final ConvexHull2D hull = generator.generate(points); - - // assert - Assertions.assertEquals(1, hull.getVertices().size()); - Assertions.assertEquals(0, hull.getPath().getElements().size()); - Assertions.assertNull(hull.getRegion()); - } - - @Test - void testConvexHull() { - // execute 100 random variations - for (int i = 0; i < 100; i++) { - // randomize the size from 4 to 100 - final int size = (int) Math.floor(random.nextDouble() * 96.0 + 4.0); - - final List<Vector2D> points = createRandomPoints(size); - - // act - final ConvexHull2D hull = generator.generate(reducePoints(points)); - - // assert - checkConvexHull(points, hull); - } - } - - @Test - void testCollinearPoints() { - // arrange - final Collection<Vector2D> points = new ArrayList<>(); - points.add(Vector2D.of(1, 1)); - points.add(Vector2D.of(2, 2)); - points.add(Vector2D.of(2, 4)); - points.add(Vector2D.of(4, 1)); - points.add(Vector2D.of(10, 1)); - - // act - final ConvexHull2D hull = generator.generate(points); - - // assert - checkConvexHull(points, hull); - } - - @Test - void testCollinearPointsReverse() { - // arrange - final Collection<Vector2D> points = new ArrayList<>(); - points.add(Vector2D.of(1, 1)); - points.add(Vector2D.of(2, 2)); - points.add(Vector2D.of(2, 4)); - points.add(Vector2D.of(10, 1)); - points.add(Vector2D.of(4, 1)); - - // act - final ConvexHull2D hull = generator.generate(points); - - // assert - checkConvexHull(points, hull); - } - - @Test - void testCollinearPointsIncluded() { - // arrange - final Collection<Vector2D> points = new ArrayList<>(); - points.add(Vector2D.of(1, 1)); - points.add(Vector2D.of(2, 2)); - points.add(Vector2D.of(2, 4)); - points.add(Vector2D.of(4, 1)); - points.add(Vector2D.of(10, 1)); - - // act - final ConvexHull2D hull = createConvexHullGenerator(true).generate(points); - - // assert - checkConvexHull(points, hull, true); - } - - @Test - void testCollinearPointsIncludedReverse() { - // arrange - final Collection<Vector2D> points = new ArrayList<>(); - points.add(Vector2D.of(1, 1)); - points.add(Vector2D.of(2, 2)); - points.add(Vector2D.of(2, 4)); - points.add(Vector2D.of(10, 1)); - points.add(Vector2D.of(4, 1)); - - // act - final ConvexHull2D hull = createConvexHullGenerator(true).generate(points); - - // assert - checkConvexHull(points, hull, true); - } - - @Test - void testIdenticalPoints() { - // arrange - final Collection<Vector2D> points = new ArrayList<>(); - points.add(Vector2D.of(1, 1)); - points.add(Vector2D.of(2, 2)); - points.add(Vector2D.of(2, 4)); - points.add(Vector2D.of(4, 1)); - points.add(Vector2D.of(1, 1)); - - // act - final ConvexHull2D hull = generator.generate(points); - - // assert - checkConvexHull(points, hull); - } - - @Test - void testIdenticalPoints2() { - // arrange - final Collection<Vector2D> points = new ArrayList<>(); - points.add(Vector2D.of(1, 1)); - points.add(Vector2D.of(2, 2)); - points.add(Vector2D.of(2, 4)); - points.add(Vector2D.of(4, 1)); - points.add(Vector2D.of(1, 1)); - - // act - final ConvexHull2D hull = createConvexHullGenerator(true).generate(points); - - // assert - checkConvexHull(points, hull, true); - } - - @Test - void testClosePoints() { - // arrange - final Collection<Vector2D> points = new ArrayList<>(); - points.add(Vector2D.of(1, 1)); - points.add(Vector2D.of(2, 2)); - points.add(Vector2D.of(2, 4)); - points.add(Vector2D.of(4, 1)); - points.add(Vector2D.of(1.00001, 1)); - - // act - final ConvexHull2D hull = generator.generate(points); - - // assert - checkConvexHull(points, hull); - } - - @Test - void testCollinearPointOnExistingBoundary() { - // --- arrange - // MATH-1135: check that collinear points on the hull are handled correctly - // when only a minimal hull shall be constructed - final Collection<Vector2D> points = new ArrayList<>(); - points.add(Vector2D.of(7.3152, 34.7472)); - points.add(Vector2D.of(6.400799999999997, 34.747199999999985)); - points.add(Vector2D.of(5.486399999999997, 34.7472)); - points.add(Vector2D.of(4.876799999999999, 34.7472)); - points.add(Vector2D.of(4.876799999999999, 34.1376)); - points.add(Vector2D.of(4.876799999999999, 30.48)); - points.add(Vector2D.of(6.0959999999999965, 30.48)); - points.add(Vector2D.of(6.0959999999999965, 34.1376)); - points.add(Vector2D.of(7.315199999999996, 34.1376)); - points.add(Vector2D.of(7.3152, 30.48)); - - // --- act - final ConvexHull2D hull = createConvexHullGenerator(false).generate(points); - - // --- assert - checkConvexHull(points, hull); - } - - @Test - void testCollinearPointsInAnyOrder_threeCollinearPoints() { - // --- arrange - // MATH-1148: collinear points on the hull might be in any order - // make sure that they are processed in the proper order - // for each algorithm. - - final List<Vector2D> points = new ArrayList<>(); - points.add(Vector2D.of(16.078200000000184, -36.52519999989808)); - points.add(Vector2D.of(19.164300000000186, -36.52519999989808)); - points.add(Vector2D.of(19.1643, -25.28136477910407)); - points.add(Vector2D.of(19.1643, -17.678400000004157)); - - // --- act/assert - ConvexHull2D hull = createConvexHullGenerator(false).generate(points); - checkConvexHull(points, hull); - - hull = createConvexHullGenerator(true).generate(points); - checkConvexHull(points, hull, true); - } - - @Test - void testCollinearPointsInAnyOrder_multipleCollinearPoints() { - // --- arrange - // MATH-1148: collinear points on the hull might be in any order - // make sure that they are processed in the proper order - // for each algorithm. - - final List<Vector2D> points = new ArrayList<>(); - points.add(Vector2D.of(0, -29.959696875)); - points.add(Vector2D.of(0, -31.621809375)); - points.add(Vector2D.of(0, -28.435696875)); - points.add(Vector2D.of(0, -33.145809375)); - points.add(Vector2D.of(3.048, -33.145809375)); - points.add(Vector2D.of(3.048, -31.621809375)); - points.add(Vector2D.of(3.048, -29.959696875)); - points.add(Vector2D.of(4.572, -33.145809375)); - points.add(Vector2D.of(4.572, -28.435696875)); - - // --- act/assert - ConvexHull2D hull = createConvexHullGenerator(false).generate(points); - checkConvexHull(points, hull); - - hull = createConvexHullGenerator(true).generate(points); - checkConvexHull(points, hull, true); - } - - @Test - void testIssue1123() { - // arrange - final List<Vector2D> points = new ArrayList<>(); - - final int[][] data = { - {-11, -1}, {-11, 0}, {-11, 1}, - {-10, -3}, {-10, -2}, {-10, -1}, {-10, 0}, {-10, 1}, - {-10, 2}, {-10, 3}, {-9, -4}, {-9, -3}, {-9, -2}, - {-9, -1}, {-9, 0}, {-9, 1}, {-9, 2}, {-9, 3}, - {-9, 4}, {-8, -5}, {-8, -4}, {-8, -3}, {-8, -2}, - {-8, -1}, {-8, 0}, {-8, 1}, {-8, 2}, {-8, 3}, - {-8, 4}, {-8, 5}, {-7, -6}, {-7, -5}, {-7, -4}, - {-7, -3}, {-7, -2}, {-7, -1}, {-7, 0}, {-7, 1}, - {-7, 2}, {-7, 3}, {-7, 4}, {-7, 5}, {-7, 6}, - {-6, -7}, {-6, -6}, {-6, -5}, {-6, -4}, {-6, -3}, - {-6, -2}, {-6, -1}, {-6, 0}, {-6, 1}, {-6, 2}, - {-6, 3}, {-6, 4}, {-6, 5}, {-6, 6}, {-6, 7}, - {-5, -7}, {-5, -6}, {-5, -5}, {-5, -4}, {-5, -3}, - {-5, -2}, {-5, 4}, {-5, 5}, {-5, 6}, {-5, 7}, - {-4, -7}, {-4, -6}, {-4, -5}, {-4, -4}, {-4, -3}, - {-4, -2}, {-4, 4}, {-4, 5}, {-4, 6}, {-4, 7}, - {-3, -8}, {-3, -7}, {-3, -6}, {-3, -5}, {-3, -4}, - {-3, -3}, {-3, -2}, {-3, 4}, {-3, 5}, {-3, 6}, - {-3, 7}, {-3, 8}, {-2, -8}, {-2, -7}, {-2, -6}, - {-2, -5}, {-2, -4}, {-2, -3}, {-2, -2}, {-2, 4}, - {-2, 5}, {-2, 6}, {-2, 7}, {-2, 8}, {-1, -8}, - {-1, -7}, {-1, -6}, {-1, -5}, {-1, -4}, {-1, -3}, - {-1, -2}, {-1, 4}, {-1, 5}, {-1, 6}, {-1, 7}, - {-1, 8}, {0, -8}, {0, -7}, {0, -6}, {0, -5}, - {0, -4}, {0, -3}, {0, -2}, {0, 4}, {0, 5}, {0, 6}, - {0, 7}, {0, 8}, {1, -8}, {1, -7}, {1, -6}, {1, -5}, - {1, -4}, {1, -3}, {1, -2}, {1, -1}, {1, 0}, {1, 1}, - {1, 2}, {1, 3}, {1, 4}, {1, 5}, {1, 6}, {1, 7}, - {1, 8}, {2, -8}, {2, -7}, {2, -6}, {2, -5}, - {2, -4}, {2, -3}, {2, -2}, {2, -1}, {2, 0}, {2, 1}, - {2, 2}, {2, 3}, {2, 4}, {2, 5}, {2, 6}, {2, 7}, - {2, 8}, {3, -8}, {3, -7}, {3, -6}, {3, -5}, - {3, -4}, {3, -3}, {3, -2}, {3, -1}, {3, 0}, {3, 1}, - {3, 2}, {3, 3}, {3, 4}, {3, 5}, {3, 6}, {3, 7}, - {3, 8}, {4, -7}, {4, -6}, {4, -5}, {4, -4}, - {4, -3}, {4, -2}, {4, -1}, {4, 0}, {4, 1}, {4, 2}, - {4, 3}, {4, 4}, {4, 5}, {4, 6}, {4, 7}, {5, -7}, - {5, -6}, {5, -5}, {5, -4}, {5, -3}, {5, -2}, - {5, -1}, {5, 0}, {5, 1}, {5, 2}, {5, 3}, {5, 4}, - {5, 5}, {5, 6}, {5, 7}, {6, -7}, {6, -6}, {6, -5}, - {6, -4}, {6, -3}, {6, -2}, {6, -1}, {6, 0}, {6, 1}, - {6, 2}, {6, 3}, {6, 4}, {6, 5}, {6, 6}, {6, 7}, - {7, -6}, {7, -5}, {7, -4}, {7, -3}, {7, -2}, - {7, -1}, {7, 0}, {7, 1}, {7, 2}, {7, 3}, {7, 4}, - {7, 5}, {7, 6}, {8, -5}, {8, -4}, {8, -3}, {8, -2}, - {8, -1}, {8, 0}, {8, 1}, {8, 2}, {8, 3}, {8, 4}, - {8, 5}, {9, -4}, {9, -3}, {9, -2}, {9, -1}, {9, 0}, - {9, 1}, {9, 2}, {9, 3}, {9, 4}, {10, -3}, {10, -2}, - {10, -1}, {10, 0}, {10, 1}, {10, 2}, {10, 3}, - {11, -1}, {11, 0}, {11, 1} - }; - - for (final int[] line : data) { - points.add(Vector2D.of(line[0], line[1])); - } - - final Vector2D[] referenceHull = { - Vector2D.of(-11.0, -1.0), - Vector2D.of(-10.0, -3.0), - Vector2D.of(-6.0, -7.0), - Vector2D.of(-3.0, -8.0), - Vector2D.of(3.0, -8.0), - Vector2D.of(6.0, -7.0), - Vector2D.of(10.0, -3.0), - Vector2D.of(11.0, -1.0), - Vector2D.of(11.0, 1.0), - Vector2D.of(10.0, 3.0), - Vector2D.of(6.0, 7.0), - Vector2D.of(3.0, 8.0), - Vector2D.of(-3.0, 8.0), - Vector2D.of(-6.0, 7.0), - Vector2D.of(-10.0, 3.0), - Vector2D.of(-11.0, 1.0), - }; - - // act - final ConvexHull2D convHull = generator.generate(points); - final Region<Vector2D> hullRegion = convHull.getRegion(); - - // assert - Assertions.assertEquals(274.0, hullRegion.getSize(), 1.0e-12); - double perimeter = 0; - for (int i = 0; i < referenceHull.length; ++i) { - perimeter += referenceHull[i].distance( - referenceHull[(i + 1) % referenceHull.length]); - } - Assertions.assertEquals(perimeter, hullRegion.getBoundarySize(), 1.0e-12); - - for (final Vector2D vector2D : referenceHull) { - Assertions.assertEquals(RegionLocation.BOUNDARY, hullRegion.classify(vector2D)); - } - - } - - // ------------------------------------------------------------------------------ - - protected final List<Vector2D> createRandomPoints(final int size) { - // create the cloud container - final List<Vector2D> points = new ArrayList<>(size); - // fill the cloud with a random distribution of points - for (int i = 0; i < size; i++) { - points.add(Vector2D.of(random.nextDouble() * 2.0 - 1.0, random.nextDouble() * 2.0 - 1.0)); - } - return points; - } - - protected final void checkConvexHull(final Collection<Vector2D> points, final ConvexHull2D hull) { - checkConvexHull(points, hull, false); - } - - protected final void checkConvexHull(final Collection<Vector2D> points, final ConvexHull2D hull, - final boolean includesCollinearPoints) { - Assertions.assertNotNull(hull); - Assertions.assertTrue(isConvex(hull, includesCollinearPoints)); - checkPointsInsideHullRegion(points, hull, includesCollinearPoints); - } - - // verify that the constructed hull is really convex - protected final boolean isConvex(final ConvexHull2D hull, final boolean includesCollinearPoints) { - - final List<Vector2D> points = hull.getVertices(); - int sign = 0; - final int size = points.size(); - - for (int i = 0; i < size; i++) { - final Vector2D p1 = points.get(i == 0 ? size - 1 : i - 1); - final Vector2D p2 = points.get(i); - final Vector2D p3 = points.get(i == size - 1 ? 0 : i + 1); - - final Vector2D d1 = p2.subtract(p1); - final Vector2D d2 = p3.subtract(p2); - - Assertions.assertTrue(d1.norm() > 1e-10); - Assertions.assertTrue(d2.norm() > 1e-10); - - final double cross = Sum.create() - .addProduct(d1.getX(), d2.getY()) - .addProduct(-d1.getY(), d2.getX()).getAsDouble(); - final int cmp = Precision.compareTo(cross, 0.0, TEST_EPS); - - if (sign != 0 && cmp != sign) { - if (!includesCollinearPoints || cmp != 0) { - // in case of collinear points the cross product will be zero - return false; - } - } - - sign = cmp; - } - - return true; - } - - // verify that all points are inside the convex hull region - protected final void checkPointsInsideHullRegion(final Collection<? extends Vector2D> points, - final ConvexHull2D hull, - final boolean includesCollinearPoints) { - - final Collection<Vector2D> hullVertices = hull.getVertices(); - final ConvexArea region = hull.getRegion(); - - for (final Vector2D p : points) { - final RegionLocation location = region.classify(p); - Assertions.assertNotEquals(RegionLocation.OUTSIDE, location); - - if (location == RegionLocation.BOUNDARY && includesCollinearPoints) { - Assertions.assertTrue(hullVertices.contains(p)); - } - } - } -} diff --git a/commons-geometry-hull/src/test/java/org/apache/commons/geometry/hull/euclidean/twod/MonotoneChainTest.java b/commons-geometry-hull/src/test/java/org/apache/commons/geometry/hull/euclidean/twod/MonotoneChainTest.java deleted file mode 100644 index 004a57fa..00000000 --- a/commons-geometry-hull/src/test/java/org/apache/commons/geometry/hull/euclidean/twod/MonotoneChainTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.geometry.hull.euclidean.twod; - -import java.util.ArrayList; -import java.util.Collection; - -import org.apache.commons.geometry.euclidean.twod.Vector2D; -import org.apache.commons.numbers.core.Precision; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -/** - * Test class for MonotoneChain. - */ -class MonotoneChainTest extends ConvexHullGenerator2DAbstractTest { - - @Override - protected ConvexHullGenerator2D createConvexHullGenerator(final boolean includeCollinearPoints) { - return new MonotoneChain(includeCollinearPoints, TEST_PRECISION); - } - - // ------------------------------------------------------------------------------ - - @Test - void testConvergenceException() { - // arrange - final Collection<Vector2D> points = new ArrayList<>(); - - points.add(Vector2D.of(1, 1)); - points.add(Vector2D.of(1, 5)); - points.add(Vector2D.of(0, 7)); - points.add(Vector2D.of(1, 10)); - points.add(Vector2D.of(1, 20)); - points.add(Vector2D.of(20, 20)); - points.add(Vector2D.of(20, 40)); - points.add(Vector2D.of(40, 1)); - - // act/assert - Assertions.assertThrows(IllegalStateException.class, - () -> new MonotoneChain(true, Precision.doubleEquivalenceOfEpsilon(1)).generate(points)); - } -} diff --git a/pom.xml b/pom.xml index 78c8d532..4929d018 100644 --- a/pom.xml +++ b/pom.xml @@ -101,7 +101,6 @@ <module>commons-geometry-core</module> <module>commons-geometry-euclidean</module> <module>commons-geometry-spherical</module> - <module>commons-geometry-hull</module> <module>commons-geometry-enclosing</module> <module>commons-geometry-io-core</module> <module>commons-geometry-io-euclidean</module>