Skip to content

Commit eb0d567

Browse files
authored
Merge pull request #40 from JuliaGeometry/improvements
improve tests and interfaces
2 parents 62371e8 + da1000d commit eb0d567

File tree

5 files changed

+36
-7
lines changed

5 files changed

+36
-7
lines changed

src/GeometryBasics.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module GeometryBasics
2929
export OffsetInteger, ZeroIndex, OneIndex, GLIndex
3030
export FaceView, SimpleFaceView
3131
export AbstractPoint, PointMeta, PointWithUV
32+
export PolygonMeta, MultiPointMeta
3233
export decompose, coordinates, faces, normals, decompose_uv, decompose_normals, texturecoordinates
3334
export Tesselation, pointmeta, Normal, UV, UVW
3435
export GLTriangleFace, GLNormalMesh3D, GLPlainTriangleMesh, GLUVMesh3D, GLUVNormalMesh3D

src/basic_types.jl

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ end
165165
Base.show(io::IO, x::LineP) = print(io, "Line(", x[1], " => ", x[2], ")")
166166

167167
"""
168+
LineString(points::AbstractVector{<:AbstractPoint})
169+
168170
A LineString is a geometry of connected line segments
169171
"""
170172
struct LineString{
@@ -177,6 +179,7 @@ end
177179

178180
coordinates(x::LineString) = x.points
179181

182+
Base.copy(x::LineString) = LineString(copy(x.points))
180183
Base.size(x::LineString) = size(coordinates(x))
181184
Base.getindex(x::LineString, i) = getindex(coordinates(x), i)
182185

@@ -231,6 +234,12 @@ function LineString(points::AbstractVector{<: AbstractPoint}, indices::AbstractV
231234
return LineString(points, faces)
232235
end
233236

237+
238+
"""
239+
Polygon(exterior::AbstractVector{<:Point})
240+
Polygon(exterior::AbstractVector{<:Point}, interiors::Vector{<:AbstractVector{<:AbstractPoint}})
241+
242+
"""
234243
struct Polygon{
235244
Dim, T <: Real,
236245
P <: AbstractPoint{Dim, T},
@@ -241,6 +250,8 @@ struct Polygon{
241250
interiors::V
242251
end
243252

253+
Base.copy(x::Polygon) = Polygon(copy(x.exterior), copy(x.interiors))
254+
244255
Base.:(==)(a::Polygon, b::Polygon) = (a.exterior == b.exterior) && (a.interiors == b.interiors)
245256

246257
function Polygon(exterior::E, interiors::AbstractVector{E}) where E <: AbstractVector{LineP{Dim, T, P}} where {Dim, T, P}
@@ -261,7 +272,9 @@ function Polygon(exterior::AbstractVector{P}, faces::AbstractVector{<: LineFace}
261272
return Polygon(LineString(exterior, faces))
262273
end
263274

264-
275+
"""
276+
MultiPolygon(polygons::AbstractPolygon)
277+
"""
265278
struct MultiPolygon{
266279
Dim, T <: Real,
267280
Element <: AbstractPolygon{Dim, T},
@@ -294,11 +307,17 @@ end
294307
Base.getindex(ms::MultiLineString, i) = ms.linestrings[i]
295308
Base.size(ms::MultiLineString) = size(ms.linestrings)
296309

310+
311+
"""
312+
MultiPoint(points::AbstractVector{AbstractPoint})
313+
314+
A collection of points
315+
"""
297316
struct MultiPoint{
298317
Dim, T <: Real,
299-
Element <: AbstractPoint{Dim, T},
300-
A <: AbstractVector{Element}
301-
} <: AbstractVector{Element}
318+
P <: AbstractPoint{Dim, T},
319+
A <: AbstractVector{P}
320+
} <: AbstractVector{P}
302321

303322
points::A
304323
end

src/geometry_primitives.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ end
1414
1515
Triangulate an N-Face into a tuple of triangular faces.
1616
"""
17-
@generated function convert_simplex(::Type{TriangleFace{T}}, f::NgonFace{N}) where {T, N}
18-
3 <= N || error("decompose not implented for N <= 3 yet. N: $N")# other wise degenerate
17+
@generated function convert_simplex(::Type{TriangleFace{T}}, f::Union{SimplexFace{N}, NgonFace{N}}) where {T, N}
18+
3 <= N || error("decompose not implemented for N <= 3 yet. N: $N")# other wise degenerate
1919
v = Expr(:tuple)
2020
for i = 3:N
2121
push!(v.args, :(TriangleFace{T}(f[1], f[$(i-1)], f[$i])))
@@ -28,7 +28,7 @@ end
2828
2929
Extract all line segments in a Face.
3030
"""
31-
@generated function convert_simplex(::Type{LineFace{T}}, f::NgonFace{N}) where {T, N}
31+
@generated function convert_simplex(::Type{LineFace{T}}, f::Union{SimplexFace{N}, NgonFace{N}}) where {T, N}
3232
2 <= N || error("decompose not implented for N <= 2 yet. N: $N")# other wise degenerate
3333

3434
v = Expr(:tuple)

src/metadata.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ macro meta_type(name, mainfield, supertype, params...)
113113
return MT(obj, nt)
114114
end
115115

116+
function Base.propertynames(::$MetaName{$(params...), Typ, Names, Types}) where {$(params...), Typ, Names, Types}
117+
return ($field, Names...)
118+
end
119+
116120
function StructArrays.staticschema(::Type{$MetaName{$(params...), Typ, Names, Types}}) where {$(params...), Typ, Names, Types}
117121
NamedTuple{($field, Names...), Base.tuple_type_cons(Typ, Types)}
118122
end
@@ -137,3 +141,7 @@ Base.getindex(x::NgonFaceMeta, idx::Int) = getindex(metafree(x), idx)
137141
Base.getindex(x::SimplexFaceMeta, idx::Int) = getindex(metafree(x), idx)
138142

139143
@meta_type(Polygon, polygon, AbstractPolygon, N, T)
144+
145+
@meta_type(MultiPoint, points, AbstractVector, P)
146+
Base.getindex(x::MultiPointMeta, idx::Int) = getindex(metafree(x), idx)
147+
Base.size(x::MultiPointMeta) = size(metafree(x))

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ using LinearAlgebra
8383
pm = GeometryBasics.PointMeta(1.1, 2.2; a=1, b=2)
8484
@test meta(pm) === (a=1, b=2)
8585
@test metafree(pm) === p
86+
@test propertynames(pm) == (:position, :a, :b)
8687
end
8788
end
8889

0 commit comments

Comments
 (0)