diff --git a/examples/build_delaunay_triangulation.jl b/examples/build_delaunay_triangulation.jl index 54e53d4..568ca90 100644 --- a/examples/build_delaunay_triangulation.jl +++ b/examples/build_delaunay_triangulation.jl @@ -1,12 +1,11 @@ using Smesh # Create data points -# Note: the transpose + collect is just such that we can write the matrix in human readable -# form here -data_points = collect([0.0 0.0 - 1.0 0.0 - 1.0 1.0 - 0.0 1.0]') +coordinates_min = [0.0, 0.0] +coordinates_max = [1.0, 1.0] +n_points_x = 4 +n_points_y = 5 +data_points = mesh_basic(coordinates_min, coordinates_max, n_points_x, n_points_y) # Create triangulation vertices = build_delaunay_triangulation(data_points; verbose = true) diff --git a/examples/build_polygon_mesh.jl b/examples/build_polygon_mesh.jl index 86677ee..0762187 100644 --- a/examples/build_polygon_mesh.jl +++ b/examples/build_polygon_mesh.jl @@ -1,16 +1,11 @@ using Smesh # Create data points -corners = collect([0.0 0.0 - 1.0 0.0 - 1.0 1.0 - 0.0 1.0]') -# inner points (randomly generated) -# n_points = 10 -# data_points = rand(Float64, 2, n_points) -data_points = [0.110127 0.995047 0.636537 0.942174 0.22912 0.162025 0.616885 0.376891 0.475242 0.448486; - 0.554234 0.431985 0.540326 0.0252587 0.702442 0.379256 0.80191 0.237447 0.745391 0.868326] -data_points = hcat(data_points, corners) +coordinates_min = [0.0, 0.0] +coordinates_max = [1.0, 1.0] +n_points_x = 4 +n_points_y = 5 +data_points = mesh_basic(coordinates_min, coordinates_max, n_points_x, n_points_y) # Create triangulation vertices = build_delaunay_triangulation(data_points; verbose = false) diff --git a/src/Smesh.jl b/src/Smesh.jl index ca69eb0..8bbfb2d 100644 --- a/src/Smesh.jl +++ b/src/Smesh.jl @@ -4,6 +4,7 @@ using Preferences: @load_preference using smesh_jll: smesh_jll export build_delaunay_triangulation, delaunay_compute_neighbors, build_polygon_mesh, voronoi_compute_neighbors +export mesh_basic const libsmesh = @load_preference("libsmesh", smesh_jll.libsmesh) @@ -112,4 +113,6 @@ function voronoi_compute_neighbors(vertices, voronoi_vertices, voronoi_vertices_ return voronoi_neighbors end + +include("standard_meshes.jl") end # module Smesh diff --git a/src/standard_meshes.jl b/src/standard_meshes.jl new file mode 100644 index 0000000..26f65e5 --- /dev/null +++ b/src/standard_meshes.jl @@ -0,0 +1,25 @@ +function mesh_basic(coordinates_min, coordinates_max, n_points_x, n_points_y) + dx = (coordinates_max[1] - coordinates_min[1]) / n_points_x + dy = (coordinates_max[2] - coordinates_min[2]) / n_points_y + + points = Matrix{eltype(coordinates_min)}(undef, 2, n_points_x * n_points_y + + div(n_points_y - n_points_y % 2, 2)) + count = 1 + for j in 1:n_points_y + for i in 1:n_points_x + points[1, count] = coordinates_min[1] + (i - 1) * dx + points[2, count] = coordinates_min[2] + (j - 1) * dy + if j % 2 == 0 && i != 1 + points[1, count] -= 0.5dx + end + count += 1 + if j % 2 == 0 && i == n_points_x + points[1, count] = points[1, count - 1] + 0.5dx + points[2, count] = points[2, count - 1] + count += 1 + end + end + end + + return points +end