{"id":37016285,"url":"https://github.com/menecats/polybool-java","last_synced_at":"2026-01-14T01:50:00.157Z","repository":{"id":144528902,"uuid":"322125168","full_name":"Menecats/polybool-java","owner":"Menecats","description":"Java port of https://github.com/velipso/polybooljs. Boolean operations on polygons (union, intersection, difference, xor)","archived":false,"fork":false,"pushed_at":"2025-08-22T06:30:36.000Z","size":92,"stargazers_count":24,"open_issues_count":0,"forks_count":6,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-22T08:41:27.826Z","etag":null,"topics":["geojson","polybool","polygon-boolean","polygon-clipping","polygon-intersection","polygon-union"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Menecats.png","metadata":{"files":{"readme":"README.MD","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-12-16T23:16:34.000Z","updated_at":"2025-08-22T06:30:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"f79ab02b-46ad-4524-aab8-df8b6e53d7e1","html_url":"https://github.com/Menecats/polybool-java","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/Menecats/polybool-java","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Menecats%2Fpolybool-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Menecats%2Fpolybool-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Menecats%2Fpolybool-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Menecats%2Fpolybool-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Menecats","download_url":"https://codeload.github.com/Menecats/polybool-java/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Menecats%2Fpolybool-java/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28408691,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T00:40:43.272Z","status":"ssl_error","status_checked_at":"2026-01-14T00:40:42.636Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["geojson","polybool","polygon-boolean","polygon-clipping","polygon-intersection","polygon-union"],"created_at":"2026-01-14T01:49:59.444Z","updated_at":"2026-01-14T01:50:00.150Z","avatar_url":"https://github.com/Menecats.png","language":"Java","readme":"# polybool-java\n\nJava port of [https://github.com/velipso/polybooljs](https://github.com/velipso/polybooljs).\n\n⚠️ **Note**: The original project is now maintained at [https://github.com/velipso/polybool](https://github.com/velipso/polybool).  \n\nBoolean operations on polygons (union, intersection, difference, xor).\n\n# Features\n\n1. Clips polygons for all boolean operations\n2. Removes unnecessary vertices\n3. Handles segments that are coincident (overlap perfectly, share vertices, one inside the other,  \n   etc)\n4. Uses formulas that take floating point irregularities into account (via configurable epsilon)\n5. Provides an API for constructing efficient sequences of operations\n6. Support for GeoJSON `\"Polygon\"` and `\"MultiPolygon\"` types (experimental)\n\n# Ports\n\nBelow is a list of known ports of PolyBool into different programming languages and environments.  \nIf you are looking for the most up-to-date list, please always refer to the main project.\n\n- [🧭 Typescript (current/original implementation) by @velipso](https://github.com/velipso/polybool)\n- [🧭 Javascript (legacy/original implementation) by @velipso](https://github.com/velipso/polybooljs)\n- [Flutter/Dart port by @mohammedX6](https://github.com/mohammedX6/poly_bool_dart)\n- [Java port by @the3deers](https://github.com/the3deers/polybool-java)\n- [Kotlin port by @StefanOltmann](https://github.com/StefanOltmann/polybool-kotlin)\n- [.NET port by @idormenco](https://github.com/idormenco/PolyBool.Net)\n- [Python port by @KaivnD](https://github.com/KaivnD/pypolybool)\n- [Roblox (Luau/Typescript) port by @codyduong](https://github.com/codyduong/rbxts-polybool)\n- ⚠️ This list may not always be up-to-date. For the latest maintained list, please check the [main project’s README](https://github.com/velipso/polybool/blob/main/README.md#ports).\n\n# Installing\n\nTo use polybool-java, you need to use the following Maven dependency:\n\n```xml\n\u003c!-- Maven --\u003e\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.menecats\u003c/groupId\u003e\n    \u003cartifactId\u003epolybool-java\u003c/artifactId\u003e\n    \u003cversion\u003e1.0.1\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n```groovy\n// Gradle (Groovy)\nimplementation 'com.menecats:polybool-java:1.0.1'\n```\n\nor download jars from Maven repository (or via quick links on\nthe [Release page](https://github.com/Menecats/polybool-java/releases))\n\n# Example\n\n```java \nimport com.menecats.polybool.Epsilon;\nimport com.menecats.polybool.PolyBool;\nimport com.menecats.polybool.models.Polygon;\n\nimport static com.menecats.polybool.helpers.PolyBoolHelper.*;\n\npublic class PolyBoolExample {\n    public static void main(String[] args) {\n        Epsilon eps = epsilon();\n  \n        Polygon intersection = PolyBool.intersect(  \n                eps,  \n                polygon(  \n                        region(  \n                                point(50, 50),  \n                                point(150, 150),  \n                                point(190, 50)  \n                        ),  \n                        region(  \n                                point(130, 50),  \n                                point(290, 150),  \n                                point(290, 50)  \n                        )  \n                ),  \n                polygon(  \n                        region(  \n                                point(110, 20),\n                                point(110, 110),\n                                point(20, 20)\n                        ),\n                        region(\n                                point(130, 170),\n                                point(130, 20),\n                                point(260, 20),\n                                point(260, 170)\n                        )\n                )\n        );\n\n        System.out.println(intersection);\n        // Polygon { inverted: false, regions: [\n        //     [[50.0, 50.0], [110.0, 50.0], [110.0, 110.0]],\n        //     [[178.0, 80.0], [130.0, 50.0], [130.0, 130.0], [150.0, 150.0]],\n        //     [[178.0, 80.0], [190.0, 50.0], [260.0, 50.0], [260.0, 131.25]]\n        // ]}\n    }\n}\n```\n\n![PolyBool Example](https://github.com/voidqk/polybooljs/raw/master/example.png)\n\n## Basic Usage\n\n```java\nEpsilon eps=new Epsilon();\n\n        Polygon poly=PolyBool.union(eps,poly1,poly2);\n        Polygon poly=PolyBool.intersect(eps,poly1,poly2);\n        Polygon poly=PolyBool.difference(eps,poly1,poly2); // poly1 - poly2\n        Polygon poly=PolyBool.differenceRev(eps,poly1,poly2); // poly2 - poly1\n        Polygon poly=PolyBool.xor(eps,poly1,poly2);\n```  \n\nWhere `poly1`, `poly2`, and the return value are `Polygon` objects.\n\n# GeoJSON (experimental)\n\nThere are also functions for converting between the native polygon format and  \n[GeoJSON](https://tools.ietf.org/html/rfc7946).\n\nNote: These functions are currently **experimental**, and I'm hoping users can provide feedback.  \nPlease comment in [this issue on GitHub](https://github.com/voidqk/polybooljs/issues/7) -- including  \nletting me know if it's working as expected. I don't use GeoJSON, but I thought I would take a  \ncrack at conversion functions.\n\nUse the following functions:\n\n```java  \nGeometry\u003c?\u003e geojson = PolyBool.polygonToGeoJSON(poly);  \nPolygon poly = PolyBool.polygonFromGeoJSON(geojson);  \n```  \n\nOnly `\"Polygon\"` and `\"MultiPolygon\"` types are supported.\n\n# Core API\n\n```java\nEpsilon eps=new Epsilon();\n\n        Segments segments=PolyBool.segments(eps,polygon);\n        Combined combined=PolyBool.combine(eps,segments1,segments2);\n\n        Segments segments=PolyBool.selectUnion(combined);\n        Segments segments=PolyBool.selectIntersect(combined);\n        Segments segments=PolyBool.selectDifference(combined);\n        Segments segments=PolyBool.selectDifferenceRev(combined);\n        Segments segments=PolyBool.selectXor(combined);\n\n        Polygon polygon=PolyBool.polygon(eps,segments);  \n```    \n\nDepending on your needs, it might be more efficient to construct your own sequence of operations  \nusing the lower-level API. Note that `PolyBool.union`, `PolyBool.intersect`, etc, are just thin  \nwrappers for convenience.\n\nThere are three types of objects you will encounter in the core API:\n\n1. Polygons (discussed above, this is a list of regions and an `inverted` flag)\n2. Segments\n3. Combined Segments\n\nThe basic flow chart of the API is:\n\n![PolyBool API Flow Chart](https://github.com/voidqk/polybooljs/raw/master/flowchart.png)\n\nYou start by converting Polygons to Segments using `PolyBool.segments(eps, poly)`.\n\nYou convert Segments to Combined Segments using `PolyBool.combine(eps, seg1, seg2)`.\n\nYou select the resulting Segments from the Combined Segments using one of the selection operators  \n`PolyBool.selectUnion(combined)`, `PolyBool.selectIntersect(combined)`, etc. These selection  \nfunctions return Segments.\n\nOnce you're done, you convert the Segments back to Polygons using `PolyBool.polygon(eps, segments)`.\n\nEach transition is costly, so you want to navigate wisely. The selection transition is the least  \ncostly.\n\n## Advanced Example 1\n\nSuppose you wanted to union a list of polygons together. The naive way to do it would be:\n\n```java  \n// works but not efficient\n\nPolygon result = polygons[0];\nfor (int i = 1; i \u003c polygons.length; i++)  \n    result = PolyBool.union(eps, result, polygons[i]);  \n  \nreturn result;  \n```  \n\nInstead, it's more efficient to use the core API directly, like this:\n\n```java\n// works AND efficient  \nSegments segments=PolyBool.segments(eps,polygons[0]);\n        for(int i=1;i\u003cpolygons.length;i++){\n        Segments seg2=PolyBool.segments(eps,polygons[i]);\n        Combined comb=PolyBool.combine(eps,segments,seg2);\n        segments=PolyBool.selectUnion(comb);\n        }\n        return PolyBool.polygon(eps,segments);  \n```  \n\n## Advanced Example 2\n\nSuppose you want to calculate all operations on two polygons. The naive way to do it would be:\n\n```java  \n// works but not efficient\nMap\u003cString, Polygon\u003e ops = new HashMap\u003c\u003e();\n\nops.put(\"union\",         PolyBool.union        (eps, poly1, poly2));\nops.put(\"intersect\",     PolyBool.intersect    (eps, poly1, poly2));\nops.put(\"difference\",    PolyBool.difference   (eps, poly1, poly2));\nops.put(\"differenceRev\", PolyBool.differenceRev(eps, poly1, poly2));\nops.put(\"xor\",           PolyBool.xor          (eps, poly1, poly2));\n\nreturn operations;\n```  \n\nInstead, it's more efficient to use the core API directly, like this:\n\n```java  \n// works AND efficient  \nSegments seg1 = PolyBool.segments(eps, poly1);\nSegments seg2 = PolyBool.segments(eps, poly2);\nCombined comb = PolyBool.combine(eps, seg1, seg2);  \n\nMap\u003cString, Polygon\u003e ops= new HashMap\u003c\u003e();\n\nops.put(\"union\",         PolyBool.polygon(eps, PolyBool.selectUnion        (eps, poly1, poly2)));\nops.put(\"intersect\",     PolyBool.polygon(eps, PolyBool.selectIntersect    (eps, poly1, poly2)));\nops.put(\"difference\",    PolyBool.polygon(eps, PolyBool.selectDifference   (eps, poly1, poly2)));\nops.put(\"differenceRev\", PolyBool.polygon(eps, PolyBool.selectDifferenceRev(eps, poly1, poly2)));\nops.put(\"xor\",           PolyBool.polygon(eps, PolyBool.selectXor          (eps, poly1, poly2)));\n\nreturn ops;\n```  \n\n## Advanced Example 3\n\nAs an added bonus, just going from Polygon to Segments and back performs simplification on the  \npolygon.\n\nSuppose you have garbage polygon data and just want to clean it up. The naive way to do it would  \nbe:\n\n```java\n// union the polygon with nothing in order to clean up the data  \n// works but not efficient  \nPolygon cleaned=PolyBool.union(eps,polygon,new Polygon());  \n```  \n\nInstead, skip the combination and selection phase:\n\n```java\n// works AND efficient  \nPolygon cleaned=PolyBool.polygon(eps,PolyBool.segments(eps,polygon));\n```  \n\n# Epsilon\n\nDue to the beauty of floating point reality, floating point calculations are not exactly perfect.  \nThis is a problem when trying to detect whether lines are on top of each other, or if vertices are  \nexactly the same.\n\nNormally you would expect this to work:\n\n```java\nif(A==B){\n        /* A and B are equal */;\n        }else{\n        /* A and B are not equal */;\n        }\n```  \n\nBut for inexact floating point math, instead we use:\n\n```java\nif(Math.abs(A-B)\u003cepsilon){\n        /* A and B are equal */;\n        }else{\n        /* A and B are not equal */;\n        }\n```  \n\nYou can set the epsilon while you invoke polybool functions by creating an `Epsilon` instance\n\n```java\nEpsilon eps=new Epsilon();\n\n        PolyBool.segments(eps,poly);\n```\n\nYou can specify a custom epsilon value while you instantiate an `Epsilon` object or you can change it on an existing one\n\n```java\nEpsilon eps=new Epsilon(myCustomEpsilonValue);\n\n        eps.epsilon(anotherCustomEpsilonValue);\n\n        PolyBool.segments(eps,poly);\n```\n\nThe default epsilon value is `0.0000000001 (1e-10)`.\n\nIf your polygons are really really large or really really tiny, then you will probably have to come  \nup with your own epsilon value -- otherwise, the default should be fine.\n\nIf `PolyBool` detects that your epsilon is too small or too large, it will throw an error:\n\n```  \nPolyBool: Zero-length segment detected; your epsilon is probably too small or too large  \n```\n\n## Experimental Epsilon changes\n\nThere is an `ExperimentalEpsilon` class that implements some experimantal changes from the\nPR [#8](https://github.com/velipso/polybooljs/pull/8) that aims to fix some bugs, but is not fully tested.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmenecats%2Fpolybool-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmenecats%2Fpolybool-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmenecats%2Fpolybool-java/lists"}