Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
skygering committed Jun 13, 2024
1 parent 0f9bca8 commit 494415f
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 18 deletions.
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ VoronoiCells = "e3e34ffb-84e9-5012-9490-92c94d0c60a4"
BenchmarkTools = "1"
CairoMakie = "0.12"
DataStructures = "0.18"
Extents = "0.1"
GeometryBasics = "0.4"
GeometryOps = "0.1.8"
Interpolations = "0.14, 0.15"
JLD2 = "0.4"
Makie = "0.19, 0.20, 0.21"
Measures = "0.3"
NCDatasets = "0.12, 0.13, 0.14"
NetCDF = "0.11"
NetCDF = "0.11, 0.12"
SplitApplyCombine = "1"
StaticArrays = "1"
Statistics = "1"
Expand Down
2 changes: 2 additions & 0 deletions src/floe_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ union_polys(p1, p2; kwargs...) = GO.union(p1, p2; target = GI.PolygonTrait(), fi
simplify_poly(p, tol) = GO.simplify(p; tol = tol)

make_polygon(coords::PolyVec) = GI.Polygon(GO.tuples(coords))
make_polygon(tuple_coords) = GI.Polygon(tuple_coords)
make_polygon(ring::GI.LinearRing) = GI.Polygon([ring])
make_multipolygon(coords::Vector{<:PolyVec}) = GI.MultiPolygon(GO.tuples(coords))
make_multipolygon(tuple_coords) = GI.MultiPolygon(tuple_coords)
make_multipolygon(polys::Vector{<:GI.Polygon}) = GI.MultiPolygon(polys)

"""
Expand Down
4 changes: 2 additions & 2 deletions src/physical_processes/coupling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ function generate_subfloe_points(
mc_y = zeros(FT, point_generator.npoints)
mc_in = fill(false, point_generator.npoints)
# Find bounding box
poly = GI.Polygon(GO.tuples(coords))
poly = make_polygon(GO.tuples(coords))
(xmin, xmax), (ymin, ymax) = GI.extent(poly)
Δx, Δy = xmax - xmin, ymax - ymin
while err > point_generator.err
Expand Down Expand Up @@ -324,7 +324,7 @@ function generate_subfloe_points(
end
x_sub_floe = repeat(x_interior_points, n_ypoints)
y_sub_floe = repeat(y_interior_points, inner = n_xpoints)
poly = GI.Polygon(GO.tuples(coords))
poly = make_polygon(GO.tuples(coords))
in_floe = [GO.coveredby((x_sub_floe[i], y_sub_floe[i]), poly) for i in eachindex(x_sub_floe)]

append!(xpoints, x_sub_floe[in_floe])
Expand Down
2 changes: 1 addition & 1 deletion src/physical_processes/fractures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ function determine_fractures(
)
# Determine if floe stresses are in or out of criteria allowable regions
update_criteria!(criteria, floes)
critical_poly = GI.Polygon(GO.tuples(criteria.vertices))
critical_poly = make_polygon(GO.tuples(criteria.vertices))
# If stresses are outside of criteria regions, we will fracture the floe
frac_idx = [!GO.coveredby(eigvals(s), critical_poly) for s in floes.stress]
frac_idx[floes.area .< min_floe_area] .= false
Expand Down
2 changes: 1 addition & 1 deletion src/physical_processes/simplification.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function smooth_floes!(
if length(floes.coords[i][1]) > simp_settings.max_vertices
poly_list = [simplify_poly(make_polygon(floes.coords[i]), simp_settings.tol)]
if !isempty(topography)
poly_list = diff_polys(GI.MultiPolygon(poly_list), GI.MultiPolygon(topography.coords); fix_multipoly = nothing)
poly_list = diff_polys(make_multipolygon(poly_list), make_multipolygon(topography.coords); fix_multipoly = nothing)
end
simp_poly =
if length(poly_list) == 1
Expand Down
2 changes: 1 addition & 1 deletion src/physical_processes/update_floe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function replace_floe!(
floe.height;
ρi = floe_settings.ρi,
)
floe.angles = GO.angles(GI.Polygon(floe.coords))
floe.angles = GO.angles(make_polygon(floe.coords))
floe.α = FT(0)
translate!(floe.coords, -floe.centroid[1], -floe.centroid[2])
floe.rmax = sqrt(maximum([sum(c.^2) for c in floe.coords[1]]))
Expand Down
2 changes: 1 addition & 1 deletion src/simulation_components/domain_and_grid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ struct TopographyElement{FT}<:AbstractDomainElement{FT}
throw(ArgumentError("Topography element maximum radius must be \
positive and non-zero."))
end
topo_poly = GI.Polygon(rmholes(coords))
topo_poly = make_polygon(rmholes(coords))
topo_poly = GO.ClosedRing()(topo_poly)
new{FT}(GI.coordinates(topo_poly), centroid, rmax)
end
Expand Down
11 changes: 3 additions & 8 deletions src/simulation_components/floe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ function Floe{FT}(
coords = find_poly_coords(floe)
coords = [orient_coords(coords[1])]
moment = _calc_moment_inertia(FT, floe, centroid, height; ρi = floe_settings.ρi)
angles = GO.angles(GI.Polygon(coords))
angles = GO.angles(make_polygon(coords))
translate!(coords, -centroid[1], -centroid[2])
rmax = sqrt(maximum([sum(c.^2) for c in coords[1]]))
status = Status()
Expand Down Expand Up @@ -430,7 +430,7 @@ function initialize_floe_field(
floe_polys = [make_polygon(valid_polyvec!(c)) for c in coords]
# Remove overlaps with topography
if !isempty(domain.topography)
floe_polys = GO.difference(make_multipolygon(floe_polys), make_multipolygon(domain.topography.coords); target = GI.PolygonTrait(),fix_multipoly = nothing)
floe_polys = diff_polys(make_multipolygon(floe_polys), make_multipolygon(domain.topography.coords))
end
# Turn polygons into floes
for p in floe_polys
Expand Down Expand Up @@ -511,7 +511,7 @@ function generate_voronoi_coords(
) where {FT <: AbstractFloat}
xpoints = Vector{FT}()
ypoints = Vector{FT}()
domain_poly = GI.MultiPolygon(GO.tuples(domain_coords))
domain_poly = make_multipolygon(GO.tuples(domain_coords))
area_frac = GO.area(domain_poly) / reduce(*, scale_fac)
# Increase the number of points based on availible percent of bounding box
npoints = ceil(Int, desired_points / area_frac)
Expand Down Expand Up @@ -651,11 +651,6 @@ function initialize_floe_field(
# Open water in cell
cell_init = make_polygon(rect_coords(xmin, xmin + collen, ymin, ymin + rowlen))
open_cell = intersect_polys(cell_init, open_water_mp)
# open_cell = if !isempty(domain.topography)
# diff_polys(open_cell_init, topography_poly)
# else
# [open_cell_init]
# end
open_cell_mpoly = make_multipolygon(open_cell)
open_coords = [GI.coordinates(c) for c in open_cell]
open_area = sum(GO.area, open_cell; init = 0.0)
Expand Down
2 changes: 0 additions & 2 deletions test/test_floe_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
@test !Subzero.hashole(poly_nohole)
@test Subzero.hashole(poly_hole1)
@test Subzero.hashole(poly_hole2)
# @test Subzero.hashole(multipoly_hole1)

# Test removing holes from polygons and multipolygons
@test [ext] == Subzero.rmholes([ext])
Expand All @@ -50,7 +49,6 @@
@test GO.equals(Subzero.rmholes(poly_nohole), poly_nohole)
@test GO.equals(Subzero.rmholes(poly_hole1), poly_nohole)
@test GO.equals(Subzero.rmholes(poly_hole2), poly_nohole)
# @test !Subzero.hashole(Subzero.rmholes(multipoly_hole1))

# Test translating coordinates and polygons
@test Subzero.translate([ext], 0.0, 0.0) == [ext]
Expand Down
2 changes: 1 addition & 1 deletion test/test_physical_processes/test_ridge_raft.jl
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@
PeriodicBoundary(East, grid),
PeriodicBoundary(West, grid),
)
boundary_poly = GO.UnionIntersectingPolygons()(GI.MultiPolygon([
boundary_poly = GO.UnionIntersectingPolygons()(Subzero.make_multipolygon([
collision_domain.north.coords, collision_domain.south.coords,
collision_domain.east.coords, collision_domain.west.coords]))

Expand Down

0 comments on commit 494415f

Please sign in to comment.