Skip to content

Algorithm + manifold and accelerator passthrough in clipping functions #273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: as/adaptivepredicates
Choose a base branch
from

Conversation

asinghvi17
Copy link
Member

@asinghvi17 asinghvi17 commented Mar 4, 2025

Spun out from #259
Parent: #275 (adaptive predicates)
Child PRs: #274 (trees)

  • Create a FosterHormannClipping(manifold, accelerator)algorithm - we can bikeshed the name
  • Pass the algorithm, manifold, and accelerator (will be used in Tree based acceleration for polygon clipping / boolean ops #274) all the way through to the base level methods which we can define different dispatches for.
  • Add a tracing error type TracingError that actually stores all the context including a_list and b_list, this way we can more effectively diagnose what's going on.

Copy link
Member Author

asinghvi17 commented Mar 4, 2025

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link
Member

@rafaqz rafaqz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but have to remove line breaks between methods of the same function 😆

struct DoubleSTRtree <: IntersectionAccelerator end
struct SingleNaturalTree <: IntersectionAccelerator end
struct DoubleNaturalTree <: IntersectionAccelerator end
struct ThinnedDoubleNaturalTree <: IntersectionAccelerator end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the only one with thinning?

Wondering if it can be a type parameter

"""
FosterHormannClipping{M <: Manifold, A <: Union{Nothing, Accelerator}} <: GeometryOpsCore.Algorithm{M}

A type that represents the Foster-Hormann clipping algorithm.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
A type that represents the Foster-Hormann clipping algorithm.
Applies the Foster-Hormann clipping algorithm.

Comment on lines +48 to +49


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

_cut(T, GI.trait(geom), geom, GI.trait(line), line; exact = True())
cut(geom, line, ::Type{T} = Float64) where {T <: AbstractFloat} = cut(FosterHormannClipping(), geom, line, T)
cut(m::Manifold, geom, line, ::Type{T} = Float64) where {T <: AbstractFloat} = cut(FosterHormannClipping(m), geom, line, T)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

) where {T<:AbstractFloat}
return _difference(
TraitTarget(target), T, GI.trait(geom_a), geom_a, GI.trait(geom_b), geom_b;
alg, TraitTarget(target), T, GI.trait(geom_a), geom_a, GI.trait(geom_b), geom_b;
exact = True(), kwargs...,
)
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

) where T
return UnionIntersectingPolygons(#=TODO: alg.manifold=#)(GI.MultiPolygon([poly_a, poly_b]))
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

return GI.MultiPolygon(res)
end
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

) where T
union(alg, poly_b, multipoly_a; target, fix_multipoly, kwargs...)
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

) where T
return GI.MultiPolygon(_union(alg, TraitTarget{GI.PolygonTrait}(), T, trait_a, multipoly_a, trait_b, multipoly_b; fix_multipoly, kwargs...))
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

@@ -526,6 +526,11 @@ function _point_filled_curve_orientation(
return iseven(k) ? out : in
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

@asinghvi17 asinghvi17 force-pushed the as/adaptivepredicates branch from f2d90a8 to 974a162 Compare March 9, 2025 02:45
@asinghvi17 asinghvi17 mentioned this pull request Mar 9, 2025
@asinghvi17 asinghvi17 force-pushed the as/adaptivepredicates branch from 974a162 to 5b0c4a1 Compare March 11, 2025 03:24
@asinghvi17 asinghvi17 force-pushed the as/adaptivepredicates branch from 5b0c4a1 to c36826d Compare April 3, 2025 20:10
asinghvi17 added a commit that referenced this pull request Apr 3, 2025
This was factored out of the "dev branch" #259 and contains the subset of changes that apply to GeometryOpsCore, for easier review.

Child PRs: #271 (TGGeometry) -> #275 (AdaptivePredicates) -> #273 (clipping algorithm type) -> #274 (trees)

- Use [StableTasks.jl](https://github.com/JuliaFolds2/StableTasks.jl) in apply and applyreduce - its type-stable tasks save us some allocations!
- Remove `Base.@assume_effects` on the low level functions, which caused issues on Julia v1.11 and was probably incorrect anyway
- Add an algorithm interface with an abstract supertype `Algorithm{M <: Manifold}`, as discussed in #247.  Also adds an abstract Operator supertype and some discussion in code comments, but no implementation or interface surface there yet.
- Split out `types.jl` into a directory `types` with a bunch of files in it, for ease of readability / docs / use.
- (out of context change): refactor CI a bit for cleanliness.


TODOs for later (not this PR):
- [ ] Add a `format` method that takes in an incompletely specified algorithm and some geometry as input, and returns a completely specified algorithm.  What does this mean?  Imagine I call `GO.intersection(FosterHormannClipping(), geom1, geom2)`.  That `FosterHormannClipping()` should get expanded to `FosterHormannClipping(AutoAlgorithm(), AutoAccelerator())`.  Then, `format` will take `format(alg, args...)` and:
  - get the `crstrait` of the two geometries, scan for incompatibilities, assign the correct manifold to the algorithm (maybe warn or emit debug info)
  - if no geometries available, get the manifold via `best_manifold(::Algorithm)`.
  - maybe inflate the accelerator by checking `npoint` and later preparations to see what's most efficient, maybe not - depends on what we want!
@asinghvi17 asinghvi17 force-pushed the as/adaptivepredicates branch from c36826d to 62187d6 Compare April 3, 2025 20:16
Not sure of name (too verbose, maybe Foster()?).  Intersection accelerators will come into the picture later (next PR) but we need them now to instantiate the struct.
Better than printing out since we can (A) check on it and (B) access the polygons as well as the a_list and b_list in Julia.  I have a few plot recipes for them but not sure if they are worth putting in a Makie extension...they would also be inaccessible there.  Maybe in GeoMakie?  Then we can make full use of customizations etc.
This is a shorter change list as a sampler, to show what needs to happen.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants