Skip to content

Commit

Permalink
Merge pull request #15 from LiorSinai/refactor/structure
Browse files Browse the repository at this point in the history
Refactor/structure
  • Loading branch information
LiorSinai authored Jan 18, 2025
2 parents 25e0957 + c61362a commit 31b2c51
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PolygonAlgorithms"
uuid = "32a0d02f-32d9-4438-b5ed-3a2932b48f96"
authors = ["Lior Sinai <[email protected]>"]
version = "0.3.1"
version = "0.3.2"

[compat]
julia = "1"
Expand Down
5 changes: 3 additions & 2 deletions src/PolygonAlgorithms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import Base: contains, insert!, iterate, merge!, push!, ==
import Base: length, show

include("definitions.jl")
include("utils.jl")
include("orientation.jl")
include("linked_list.jl")
include("point_set.jl")
include("data_structures/linked_list.jl")
include("data_structures/point_set.jl")

include("bounds.jl")
include("convex_hull.jl")
Expand Down
File renamed without changes.
File renamed without changes.
35 changes: 11 additions & 24 deletions src/definitions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,16 @@ function Base.getindex(line::Line2D, ind::Int)
ind == 1 ? line.a : ind == 2 ? line.b : line.c
end

function points_to_matrix(v::Vector{<:Point2D{T}}) where {T}
X = Matrix{T}(undef, 2, length(v))
for i in 1:length(v)
X[1, i] = v[i][1]
X[2, i] = v[i][2]
end
X
end
"""
line_from_segment(segment)
function matrix_to_points(m::AbstractMatrix{T}) where {T}
N = size(m, 1)
points = NTuple{N,T}[]
for col in eachcol(m)
push!(points, tuple(col...))
end
points
Equation of line is `ax + by = c`.
"""
function line_from_segment(segment::Segment2D)
a = segment[1][2] - segment[2][2]
b = segment[2][1] - segment[1][1]
c = a * segment[1][1] + b * segment[1][2]
Line2D(a, b, c)
end

### basic operations on points
Expand All @@ -50,23 +44,16 @@ translate(points::Vector{<:Point2D}, t::Point2D) = [(p[1] + t[1], p[2] + t[2]) f
Rotate a set of points `θ` radians about `p0`.
"""
function rotate(points::Vector{<:Point2D}, θ::Float64)
function rotate(points::Vector{<:Point2D}, θ::AbstractFloat)
s = sin(θ)
c = cos(θ)
[(p[1] * c - p[2] * s, p[1] * s + p[2] * c) for p in points]
end

rotate(points::Vector{<:Point2D}, θ::Float64, p0::Point2D) =
rotate(points::Vector{<:Point2D}, θ::AbstractFloat, p0::Point2D) =
translate(rotate(translate(points, (-p0[1], -p0[2])), θ), p0)

x_coords(points::Polygon2D) = [p[1] for p in points]
x_coords(points::Polygon2D, idxs::AbstractVector{Int}) = [p[1] for p in points[idxs]]
y_coords(points::Polygon2D) = [p[2] for p in points]
y_coords(points::Polygon2D, idxs::AbstractVector{Int}) = [p[2] for p in points[idxs]]

function separate(f, v::Vector)
idxs = findall(f, v)
other_idxs = setdiff(eachindex(v), idxs)
(@view(v[idxs]), @view(v[other_idxs]))
end

12 changes: 0 additions & 12 deletions src/intersect.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,6 @@ function classify_intersection(segment::Segment2D, point::Point2D; atol::Abstrac
(at_start, at_end, along)
end

"""
line_from_segment(segment::Tuple{Point2D,Point2D})
Equation of line is `ax + by = c`.
"""
function line_from_segment(segment::Segment2D)
a = segment[1][2] - segment[2][2]
b = segment[2][1] - segment[1][1]
c = a * segment[1][1] + b * segment[1][2]
Line2D(a, b, c)
end

"""
intersect_geometry(line1::Line2D, line2::Line2D; atol=1e-6)
Expand Down
24 changes: 24 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function points_to_matrix(v::Vector{<:Point2D{T}}) where {T}
X = Matrix{T}(undef, 2, length(v))
for i in 1:length(v)
X[1, i] = v[i][1]
X[2, i] = v[i][2]
end
X
end

function matrix_to_points(m::AbstractMatrix{T}) where {T}
N = size(m, 1)
points = NTuple{N,T}[]
for col in eachcol(m)
push!(points, tuple(col...))
end
points
end

function separate(f, v::Vector)
idxs = findall(f, v)
other_idxs = setdiff(eachindex(v), idxs)
(@view(v[idxs]), @view(v[other_idxs]))
end

6 comments on commit 31b2c51

@LiorSinai
Copy link
Owner Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/123250

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.2 -m "<description of version>" 31b2c517f580d94c544ba74a486a9fd5b3b9f754
git push origin v0.3.2

Also, note the warning: Version 0.3.2 skips over 0.3.0
This can be safely ignored. However, if you want to fix this you can do so. Call register() again after making the fix. This will update the Pull request.

@LiorSinai
Copy link
Owner Author

Choose a reason for hiding this comment

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

@JuliaRegistrator register

Release notes:

  • internal refactoring
  • Point in polygon fixes:
    -- Repeated points throw the num_intersections count off, so skip them.
    -- Make the extremes less extreme, to make the rtol more likely.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request updated: JuliaRegistries/General/123250

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.2 -m "<description of version>" 31b2c517f580d94c544ba74a486a9fd5b3b9f754
git push origin v0.3.2

Also, note the warning: Version 0.3.2 skips over 0.3.1
This can be safely ignored. However, if you want to fix this you can do so. Call register() again after making the fix. This will update the Pull request.

@LiorSinai
Copy link
Owner Author

Choose a reason for hiding this comment

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

@JuliaRegistrator register

Release notes:

internal refactoring

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request updated: JuliaRegistries/General/123250

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.2 -m "<description of version>" 31b2c517f580d94c544ba74a486a9fd5b3b9f754
git push origin v0.3.2

Please sign in to comment.