Skip to content

Commit

Permalink
build based on 854b036
Browse files Browse the repository at this point in the history
  • Loading branch information
Documenter.jl committed Feb 12, 2024
1 parent a4f0c54 commit 68a111b
Show file tree
Hide file tree
Showing 36 changed files with 230 additions and 134 deletions.
2 changes: 1 addition & 1 deletion dev/.documenter-siteinfo.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"documenter":{"julia_version":"1.10.0","generation_timestamp":"2024-02-07T03:37:14","documenter_version":"1.2.1"}}
{"documenter":{"julia_version":"1.10.0","generation_timestamp":"2024-02-12T20:46:21","documenter_version":"1.2.1"}}
138 changes: 74 additions & 64 deletions dev/api/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dev/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dev/search_index.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions dev/source/GeometryOps/index.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dev/source/methods/angles/index.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dev/source/methods/area/index.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dev/source/methods/barycentric/index.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dev/source/methods/bools/index.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dev/source/methods/centroid/index.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dev/source/methods/clipping/clipping_processor/index.html

Large diffs are not rendered by default.

85 changes: 85 additions & 0 deletions dev/source/methods/clipping/cut/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>Polygon cutting · GeometryOps.jl</title><meta name="title" content="Polygon cutting · GeometryOps.jl"/><meta property="og:title" content="Polygon cutting · GeometryOps.jl"/><meta property="twitter:title" content="Polygon cutting · GeometryOps.jl"/><meta name="description" content="Documentation for GeometryOps.jl."/><meta property="og:description" content="Documentation for GeometryOps.jl."/><meta property="twitter:description" content="Documentation for GeometryOps.jl."/><meta property="og:url" content="https://asinghvi17.github.io/GeometryOps.jl/source/methods/clipping/cut/"/><meta property="twitter:url" content="https://asinghvi17.github.io/GeometryOps.jl/source/methods/clipping/cut/"/><link rel="canonical" href="https://asinghvi17.github.io/GeometryOps.jl/source/methods/clipping/cut/"/><script data-outdated-warner src="../../../../assets/warner.js"></script><link href="https://cdnjs.cloudflare.com/ajax/libs/lato-font/3.0.0/css/lato-font.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/juliamono/0.050/juliamono.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/fontawesome.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/solid.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/brands.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.8/katex.min.css" rel="stylesheet" type="text/css"/><script>documenterBaseURL="../../../.."</script><script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js" data-main="../../../../assets/documenter.js"></script><script src="../../../../search_index.js"></script><script src="../../../../siteinfo.js"></script><script src="../../../../../versions.js"></script><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../../../../assets/themes/documenter-dark.css" data-theme-name="documenter-dark" data-theme-primary-dark/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../../../../assets/themes/documenter-light.css" data-theme-name="documenter-light" data-theme-primary/><script src="../../../../assets/themeswap.js"></script></head><body><div id="documenter"><nav class="docs-sidebar"><a class="docs-logo" href="../../../../"><img src="../../../../assets/logo.png" alt="GeometryOps.jl logo"/></a><div class="docs-package-name"><span class="docs-autofit"><a href="../../../../">GeometryOps.jl</a></span></div><button class="docs-search-query input is-rounded is-small is-clickable my-2 mx-auto py-1 px-2" id="documenter-search-query">Search docs (Ctrl + /)</button><ul class="docs-menu"><li><a class="tocitem" href="../../../../">Home</a></li><li><a class="tocitem" href="../../../../api/">API Reference</a></li><li><span class="tocitem">Source code</span><ul><li><a class="tocitem" href="../../../GeometryOps/">GeometryOps.jl</a></li><li><a class="tocitem" href="../../../primitives/">Primitive functions</a></li><li><a class="tocitem" href="../../../utils/">Utility functions</a></li><li><a class="tocitem" href="../../angles/">Angles</a></li><li><a class="tocitem" href="../../area/">Area and signed area</a></li><li><a class="tocitem" href="../../barycentric/">Barycentric coordinates</a></li><li><a class="tocitem" href="../../bools/">Boolean conditions</a></li><li><a class="tocitem" href="../../centroid/">Centroid</a></li><li><a class="tocitem" href="../../distance/">Distance and signed distance</a></li><li><a class="tocitem" href="../../equals/">Equals</a></li><li><a class="tocitem" href="../../polygonize/">Polygonizing raster data</a></li><li><a class="tocitem" href="../clipping_processor/">Polygon clipping helpers</a></li><li class="is-active"><a class="tocitem" href>Polygon cutting</a><ul class="internal"><li><a class="tocitem" href="#What-is-cut?"><span>What is cut?</span></a></li><li><a class="tocitem" href="#Implementation"><span>Implementation</span></a></li></ul></li><li><a class="tocitem" href="../difference/">Difference Polygon Clipping</a></li><li><a class="tocitem" href="../intersection/">Intersection</a></li><li><a class="tocitem" href="../union/">Union Polygon Clipping</a></li><li><a class="tocitem" href="../../geom_relations/contains/">Contains</a></li><li><a class="tocitem" href="../../geom_relations/coveredby/">CoveredBy</a></li><li><a class="tocitem" href="../../geom_relations/covers/">Covers</a></li><li><a class="tocitem" href="../../geom_relations/crosses/">Crossing checks</a></li><li><a class="tocitem" href="../../geom_relations/disjoint/">Disjoint</a></li><li><a class="tocitem" href="../../geom_relations/geom_geom_processors/">Line-curve interaction</a></li><li><a class="tocitem" href="../../geom_relations/intersects/">Intersection checks</a></li><li><a class="tocitem" href="../../geom_relations/overlaps/">Overlaps</a></li><li><a class="tocitem" href="../../geom_relations/touches/">Touches</a></li><li><a class="tocitem" href="../../geom_relations/within/">Within</a></li><li><a class="tocitem" href="../../../transformations/extent/">Extent embedding</a></li><li><a class="tocitem" href="../../../transformations/flip/">Coordinate flipping</a></li><li><a class="tocitem" href="../../../transformations/reproject/">Geometry reprojection</a></li><li><a class="tocitem" href="../../../transformations/simplify/">Geometry simplification</a></li><li><a class="tocitem" href="../../../transformations/transform/">Pointwise transformation</a></li><li><a class="tocitem" href="../../../transformations/tuples/">Tuple conversion</a></li></ul></li></ul><div class="docs-version-selector field has-addons"><div class="control"><span class="docs-label button is-static is-size-7">Version</span></div><div class="docs-selector control is-expanded"><div class="select is-fullwidth is-size-7"><select id="documenter-version-selector"></select></div></div></div></nav><div class="docs-main"><header class="docs-navbar"><a class="docs-sidebar-button docs-navbar-link fa-solid fa-bars is-hidden-desktop" id="documenter-sidebar-button" href="#"></a><nav class="breadcrumb"><ul class="is-hidden-mobile"><li><a class="is-disabled">Source code</a></li><li class="is-active"><a href>Polygon cutting</a></li></ul><ul class="is-hidden-tablet"><li class="is-active"><a href>Polygon cutting</a></li></ul></nav><div class="docs-right"><a class="docs-navbar-link" href="https://github.com/asinghvi17/GeometryOps.jl/blob/main/docs/src/source/methods/clipping/cut.md#" title="Edit source on GitHub"><span class="docs-icon fa-solid"></span></a><a class="docs-settings-button docs-navbar-link fa-solid fa-gear" id="documenter-settings-button" href="#" title="Settings"></a><a class="docs-article-toggle-button fa-solid fa-chevron-up" id="documenter-article-toggle-button" href="javascript:;" title="Collapse all docstrings"></a></div></header><article class="content" id="documenter-page"><h1 id="Polygon-cutting"><a class="docs-heading-anchor" href="#Polygon-cutting">Polygon cutting</a><a id="Polygon-cutting-1"></a><a class="docs-heading-anchor-permalink" href="#Polygon-cutting" title="Permalink"></a></h1><pre><code class="language-julia hljs">export cut</code></pre><h2 id="What-is-cut?"><a class="docs-heading-anchor" href="#What-is-cut?">What is cut?</a><a id="What-is-cut?-1"></a><a class="docs-heading-anchor-permalink" href="#What-is-cut?" title="Permalink"></a></h2><p>The cut function cuts a polygon through a line segment. This is inspired by functions such as Matlab&#39;s <a href="https://www.mathworks.com/matlabcentral/fileexchange/24449-cutpolygon"><code>cutpolygon</code></a> function.</p><p>To provide an example, consider the following polygon and line:</p><pre><code class="language-julia hljs">import GeoInterface as GI, GeometryOps as GO
using CairoMakie
using Makie

poly = GI.Polygon([[(0.0, 0.0), (10.0, 0.0), (10.0, 10.0), (0.0, 10.0), (0.0, 0.0)]])
line = GI.Line([(5.0, -5.0), (5.0, 15.0)])
cut_polys = GO.cut(poly, line)

f, a, p1 = Makie.poly(collect(GI.getpoint(cut_polys[1])); color = :blue)
Makie.poly!(collect(GI.getpoint(cut_polys[2])); color = :orange)
Makie.lines!(GI.getpoint(line); color = :black)
f</code></pre><h2 id="Implementation"><a class="docs-heading-anchor" href="#Implementation">Implementation</a><a id="Implementation-1"></a><a class="docs-heading-anchor-permalink" href="#Implementation" title="Permalink"></a></h2><p>This function depends on polygon clipping helper function and is inspired by the Greiner-Hormann clipping algorithm used elsewhere in this library. The inspiration came from <a href="https://stackoverflow.com/questions/3623703/how-can-i-split-a-polygon-by-a-line">this</a> Stack Overflow discussion.</p><pre><code class="language-julia hljs">&quot;&quot;&quot;
cut(geom, line, [T::Type])

Return given geom cut by given line as a list of geometries of the same type as the input
geom. Return the original geometry as only list element if none are found. Line must cut
fully through given geometry or the original geometry will be returned.

# Example

```jldoctest
import GeoInterface as GI, GeometryOps as GO

poly = GI.Polygon([[(0.0, 0.0), (10.0, 0.0), (10.0, 10.0), (0.0, 10.0), (0.0, 0.0)]])
line = GI.Line([(5.0, -5.0), (5.0, 15.0)])
cut_polys = GO.cut(poly, line)
GI.coordinates.(cut_polys)</code></pre><p>output</p><pre><code class="language-julia hljs">2-element Vector{Vector{Vector{Vector{Float64}}}}:
[[[0.0, 0.0], [5.0, 0.0], [5.0, 10.0], [0.0, 10.0], [0.0, 0.0]]]
[[[5.0, 0.0], [10.0, 0.0], [10.0, 10.0], [5.0, 10.0], [5.0, 0.0]]]
```
&quot;&quot;&quot;
cut(geom, line, ::Type{T} = Float64) where {T &lt;: AbstractFloat} =
_cut(T, GI.trait(geom), geom, GI.trait(line), line)

#= Cut a given polygon by given line. Add polygon holes back into resulting pieces if there
are any holes. =#
function _cut(::Type{T}, ::GI.PolygonTrait, poly, ::GI.LineTrait, line) where T
ext_poly = GI.getexterior(poly)
poly_list, intr_list = _build_a_list(T, ext_poly, line)
n_intr_pts = length(intr_list)</code></pre><p>If an impossible number of intersection points, return original polygon</p><pre><code class="language-julia hljs"> if n_intr_pts &lt; 2 || isodd(n_intr_pts)
return [tuples(poly)]
end</code></pre><p>Cut polygon by line</p><pre><code class="language-julia hljs"> cut_coords = _cut(T, ext_poly, poly_list, intr_list, n_intr_pts)</code></pre><p>Close coords and create polygons</p><pre><code class="language-julia hljs"> for c in cut_coords
push!(c, c[1])
end
cut_polys = [GI.Polygon([c]) for c in cut_coords]</code></pre><p>Add original polygon holes back in</p><pre><code class="language-julia hljs"> _add_holes_to_polys!(T, cut_polys, GI.gethole(poly))
return cut_polys
end</code></pre><p>Many types aren&#39;t implemented</p><pre><code class="language-julia hljs">function _cut(_, trait::GI.AbstractTrait, geom, line)
@assert(
false,
&quot;Cutting of $trait isn&#39;t implemented yet.&quot;,
)
return nothing
end

#= Cutting algorithm inspired by Greiner and Hormann clipping algorithm. Returns coordinates
of cut geometry in Vector{Vector{Tuple}} format.

Note: degenerate cases where intersection points are vertices do not work right now. =#
function _cut(::Type{T}, geom, geom_list, intr_list, n_intr_pts) where T</code></pre><p>Sort and catagorize the intersection points</p><pre><code class="language-julia hljs"> sort!(intr_list, by = x -&gt; geom_list[x].fracs[2])
_flag_ent_exit!(geom, geom_list)</code></pre><p>Add first point to output list</p><pre><code class="language-julia hljs"> return_coords = [[geom_list[1].point]]
cross_backs = [(T(Inf),T(Inf))]
poly_idx = 1
n_polys = 1</code></pre><p>Walk around original polygon to find split polygons</p><pre><code class="language-julia hljs"> for (pt_idx, curr) in enumerate(geom_list)
if pt_idx &gt; 1
push!(return_coords[poly_idx], curr.point)
end
if curr.inter</code></pre><p>Find cross back point for current polygon</p><pre><code class="language-julia hljs"> intr_idx = findfirst(x -&gt; equals(curr.point, geom_list[x].point), intr_list)
cross_idx = intr_idx + (curr.ent_exit ? 1 : -1)
cross_idx = cross_idx &lt; 1 ? n_intr_pts : cross_idx
cross_idx = cross_idx &gt; n_intr_pts ? 1 : cross_idx
cross_backs[poly_idx] = geom_list[intr_list[cross_idx]].point</code></pre><p>Check if current point is a cross back point</p><pre><code class="language-julia hljs"> next_poly_idx = findfirst(x -&gt; equals(x, curr.point), cross_backs)
if isnothing(next_poly_idx)
push!(return_coords, [curr.point])
push!(cross_backs, curr.point)
n_polys += 1
poly_idx = n_polys
else
push!(return_coords[next_poly_idx], curr.point)
poly_idx = next_poly_idx
end
end
end
return return_coords
end</code></pre><hr/><p><em>This page was generated using <a href="https://github.com/fredrikekre/Literate.jl">Literate.jl</a>.</em></p></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../clipping_processor/">« Polygon clipping helpers</a><a class="docs-footer-nextpage" href="../difference/">Difference Polygon Clipping »</a><div class="flexbox-break"></div><p class="footer-message">Powered by <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> and the <a href="https://julialang.org/">Julia Programming Language</a>.</p></nav></div><div class="modal" id="documenter-settings"><div class="modal-background"></div><div class="modal-card"><header class="modal-card-head"><p class="modal-card-title">Settings</p><button class="delete"></button></header><section class="modal-card-body"><p><label class="label">Theme</label><div class="select"><select id="documenter-themepicker"><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option><option value="auto">Automatic (OS)</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 1.2.1 on <span class="colophon-date" title="Monday 12 February 2024 20:27">Monday 12 February 2024</span>. Using Julia version 1.10.0.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html>
Loading

0 comments on commit 68a111b

Please sign in to comment.