Skip to content

Commit 8db9df4

Browse files
authored
Merge pull request #18 from JuliaGeometry/sd/finish
Finish this up to work with everything
2 parents a70d501 + dcf902d commit 8db9df4

18 files changed

+2261
-366
lines changed

.appveyor.yml

Lines changed: 0 additions & 31 deletions
This file was deleted.

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
language: julia
33
os:
44
- linux
5-
- osx
65
julia:
7-
- 1.1
6+
- 1.3
87
- nightly
98
matrix:
109
allow_failures:

Project.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ authors = ["SimonDanisch <[email protected]>"]
44
version = "0.1.3"
55

66
[deps]
7+
IterTools = "c8e1da08-722c-5040-9ed9-7db0dc04731e"
8+
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
79
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
810
StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
911
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
1012

1113
[compat]
12-
julia = "1.1"
13-
StructArrays = "0.3,0.4"
1414
StaticArrays = "0.12,0.1"
15+
StructArrays = "0.3,0.4"
1516
Tables = "0.2, 1"
17+
julia = "1.1"
1618

1719
[extras]
1820
Query = "1a8c2f83-1ff3-5112-b086-8aa67b057ba1"

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
# GeometryBasics.jl
88

9-
Basic Geometry Types.
9+
Basic Geometry Types.
1010
This package aimes to offer a standard set of Geometry types, which easily work with metadata, query frameworks on geometries and different memory layouts.
1111
The aim is to create a solid basis for Graphics/Plotting, finite elements analysis, Geo applications, and general geometry manipulations - while offering a julian API, that still allows performant C-interop.
1212

@@ -238,5 +238,3 @@ end
238238

239239
end
240240
```
241-
242-

src/GeometryBasics.jl

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,58 @@
11
module GeometryBasics
22

3-
using StaticArrays, Tables, StructArrays
3+
using StaticArrays, Tables, StructArrays, IterTools, LinearAlgebra
44

5-
using Base: @propagate_inbounds
5+
using Base: @propagate_inbounds
66

7-
include("fixed_arrays.jl")
8-
include("basic_types.jl")
9-
include("metadata.jl")
10-
include("viewtypes.jl")
7+
include("fixed_arrays.jl")
8+
include("offsetintegers.jl")
9+
include("basic_types.jl")
10+
include("metadata.jl")
11+
include("viewtypes.jl")
12+
include("geometry_primitives.jl")
13+
include("rectangles.jl")
14+
include("triangulation.jl")
15+
include("meshes.jl")
16+
include("lines.jl")
17+
include("boundingboxes.jl")
18+
19+
export AbstractGeometry, GeometryPrimitive
20+
export Mat, Point, Vec
21+
export LineFace, Polytope, Line, NgonFace, convert_simplex
22+
export LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon
23+
export Simplex, connect, Triangle, NSimplex, Tetrahedron
24+
export QuadFace, metafree, coordinates, TetrahedronFace
25+
export TupleView, SimplexFace, Mesh, meta
26+
export Triangle, TriangleP
27+
export AbstractFace, TriangleFace, QuadFace, GLTriangleFace
28+
export OffsetInteger, ZeroIndex, OneIndex, GLIndex
29+
export FaceView, SimpleFaceView
30+
export AbstractPoint, PointMeta, PointWithUV
31+
export decompose, coordinates, faces, normals, decompose_uv, decompose_normals
32+
export GLTriangleFace, GLNormalMesh3D, GLPlainTriangleMesh, GLUVMesh3D, GLUVNormalMesh3D
33+
export AbstractMesh, Mesh, TriangleMesh
34+
export GLNormalMesh2D, PlainTriangleMesh
35+
36+
# all the different predefined mesh types
37+
# Note: meshes can contain arbitrary meta information,
38+
export AbstractMesh, TriangleMesh, PlainMesh, GLPlainMesh, GLPlainMesh2D, GLPlainMesh3D
39+
export UVMesh, GLUVMesh, GLUVMesh2D, GLUVMesh3D
40+
export NormalMesh, GLNormalMesh, GLNormalMesh2D, GLNormalMesh3D
41+
export NormalUVMesh, GLNormalUVMesh, GLNormalUVMesh2D, GLNormalUVMesh3D
42+
export NormalUVWMesh, GLNormalUVWMesh, GLNormalUVWMesh2D, GLNormalUVWMesh3D
43+
44+
# mesh creation functions
45+
export triangle_mesh, triangle_mesh, uv_mesh
46+
export uv_mesh, normal_mesh, uv_normal_mesh
47+
48+
export height, origin, radius, width, widths, xwidth, yheight
49+
export HyperSphere, Circle, Sphere
50+
export Cylinder, Cylinder2, Cylinder3, Pyramid, extremity
51+
export Rect, Rect2D, Rect3D, IRect, IRect2D, IRect3D, FRect, FRect2D, FRect3D
52+
export before, during, isinside, isoutside, meets, overlaps, intersects, finishes
53+
export centered, direction, area, update
54+
export max_dist_dim, max_euclidean, max_euclideansq, min_dist_dim, min_euclidean
55+
export min_euclideansq, minmax_dist_dim, minmax_euclidean, minmax_euclideansq
56+
export self_intersections, split_intersections
1157

1258
end # module

src/basic_types.jl

Lines changed: 62 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
"""
22
Abstract Geometry in R{Dim} with Number type T
33
"""
4-
abstract type AbstractGeometry{Dim, T <: Real} end
4+
abstract type AbstractGeometry{Dim, T <: Number} end
5+
abstract type GeometryPrimitive{Dim, T} <: AbstractGeometry{Dim, T} end
6+
Base.ndims(x::AbstractGeometry{Dim}) where Dim = Dim
57

68
"""
79
Geometry made of N connected points. Connected as one flat geometry, it makes a Ngon / Polygon.
@@ -18,32 +20,47 @@ abstract type AbstractNgonFace{N, T} <: AbstractFace{N, T} end
1820

1921
abstract type AbstractSimplex{Dim, N, T} <: StaticVector{Dim, T} end
2022

21-
@fixed_vector Point AbstractPoint
22-
23-
23+
"""
24+
coordinates(geometry)
25+
Returns the edges/vertices/coordinates of a geometry. Is allowed to return lazy iterators!
26+
Use `decompose(ConcretePointType, geometry)` to get `Vector{ConcretePointType}` with
27+
`ConcretePointType` to be something like `Point{3, Float32}`.
28+
"""
29+
function coordinates(points::AbstractVector{<:AbstractPoint})
30+
return points
31+
end
2432

33+
"""
34+
faces(geometry)
35+
Returns the face connections of a geometry. Is allowed to return lazy iterators!
36+
Use `decompose(ConcreteFaceType, geometry)` to get `Vector{ConcreteFaceType}` with
37+
`ConcreteFaceType` to be something like `TriangleFace{Int}`.
38+
"""
39+
function faces(f::AbstractVector{<:AbstractFace})
40+
return f
41+
end
2542

2643
"""
2744
Face index, connecting points to form a simplex
2845
"""
2946

3047
@fixed_vector SimplexFace AbstractSimplexFace
31-
const LineFace{T} = SimplexFace{2, T}
3248
const TetrahedronFace{T} = SimplexFace{4, T}
3349
Face(::Type{<: SimplexFace{N}}, ::Type{T}) where {N, T} = SimplexFace{N, T}
3450

35-
3651
"""
3752
Face index, connecting points to form an Ngon
3853
"""
3954

4055
@fixed_vector NgonFace AbstractNgonFace
56+
const LineFace{T} = NgonFace{2, T}
4157
const TriangleFace{T} = NgonFace{3, T}
4258
const QuadFace{T} = NgonFace{4, T}
4359

4460
Base.show(io::IO, x::TriangleFace{T}) where T = print(io, "TriangleFace(", join(x, ", "), ")")
4561

4662
Face(::Type{<: NgonFace{N}}, ::Type{T}) where {N, T} = NgonFace{N, T}
63+
Face(F::Type{NgonFace{N, FT}}, ::Type{T}) where {FT, N, T} = F
4764

4865
@propagate_inbounds Base.getindex(x::Polytope, i::Integer) = coordinates(x)[i]
4966
@propagate_inbounds Base.iterate(x::Polytope) = iterate(coordinates(x))
@@ -65,10 +82,11 @@ struct Ngon{
6582

6683
points::SVector{N, Point}
6784
end
85+
6886
const NNgon{N} = Ngon{Dim, T, N, P} where {Dim, T, P}
6987

7088
function (::Type{<: NNgon{N}})(points::Vararg{P, N}) where {P <: AbstractPoint{Dim, T}, N} where {Dim, T}
71-
Ngon{Dim, T, N, P}(SVector(points))
89+
return Ngon{Dim, T, N, P}(SVector(points))
7290
end
7391
Base.show(io::IO, x::NNgon{N}) where N = print(io, "Ngon{$N}(", join(x, ", "), ")")
7492

@@ -92,6 +110,10 @@ function Polytope(::Type{<: NNgon{N}}, P::Type{<: AbstractPoint{NDim, T}}) where
92110
Ngon{NDim, T, N, P}
93111
end
94112

113+
114+
const LineP{Dim, T, P <: AbstractPoint{Dim, T}} = Ngon{Dim, T, 2, P}
115+
const Line{Dim, T} = LineP{Dim, T, Point{Dim, T}}
116+
95117
# Simplex{D, T, 3} & Ngon{D, T, 3} are both representing a triangle.
96118
# Since Ngon is supposed to be flat and a triangle is flat, lets prefer Ngon
97119
# for triangle:
@@ -130,8 +152,6 @@ struct Simplex{
130152
end
131153

132154
const NSimplex{N} = Simplex{Dim, T, N, P} where {Dim, T, P}
133-
const LineP{Dim, T, P <: AbstractPoint{Dim, T}} = Simplex{Dim, T, 2, P}
134-
const Line{Dim, T} = LineP{Dim, T, Point{Dim, T}}
135155
const TetrahedronP{T, P <: AbstractPoint{3, T}} = Simplex{3, T, 4, P}
136156
const Tetrahedron{T} = TetrahedronP{T, Point{3, T}}
137157

@@ -293,56 +313,72 @@ Base.getindex(ms::MultiLineString, i) = ms.linestrings[i]
293313
Base.size(ms::MultiLineString) = size(ms.linestrings)
294314

295315
struct MultiPoint{
296-
Dim, T <: Real,
297-
Element <: AbstractPoint{Dim, T},
298-
A <: AbstractVector{Element}
299-
} <: AbstractVector{Element}
316+
Dim, T <: Real,
317+
Element <: AbstractPoint{Dim, T},
318+
A <: AbstractVector{Element}
319+
} <: AbstractVector{Element}
300320

301321
points::A
302322
end
303323

304324
function MultiPoint(points::AbstractVector{P}; kw...) where P <: AbstractPoint{Dim, T} where {Dim, T}
305-
MultiPoint(meta(points; kw...))
325+
return MultiPoint(meta(points; kw...))
306326
end
307327

308328
Base.getindex(mpt::MultiPoint, i) = mpt.points[i]
309329
Base.size(mpt::MultiPoint) = size(mpt.points)
310330

331+
"""
332+
AbstractMesh
333+
334+
An abstract mesh is a collection of Polytope elements (Simplices / Ngons).
335+
The connections are defined via faces(mesh), the coordinates of the elements are returned by
336+
coordinates(mesh). Arbitrary meta information can be attached per point or per face
337+
"""
338+
const AbstractMesh{Element} = AbstractVector{Element}
339+
340+
"""
341+
Mesh <: AbstractVector{Element}
342+
The conrecte AbstractMesh implementation
343+
"""
311344
struct Mesh{
312345
Dim, T <: Real,
313346
Element <: Polytope{Dim, T},
314347
V <: AbstractVector{Element}
315-
} <: AbstractVector{Element}
316-
317-
simplices::V
348+
} <: AbstractMesh{Element}
349+
simplices::V # usually a FaceView, to connect a set of points via a set of faces.
318350
end
319351

320-
Tables.schema(fw::Mesh) = Tables.schema(getfield(fw, :simplices))
352+
Tables.schema(mesh::Mesh) = Tables.schema(getfield(mesh, :simplices))
353+
354+
function Base.getproperty(mesh::Mesh, name::Symbol)
355+
return getproperty(getfield(mesh, :simplices), name)
356+
end
321357

322-
function Base.getproperty(x::Mesh, name::Symbol)
323-
getproperty(getfield(x, :simplices), name)
358+
function Base.propertynames(mesh::Mesh)
359+
return propertynames(getfield(mesh, :simplices))
324360
end
325361

326-
function Base.summary(io::IO, x::Mesh{Dim, T, Element}) where {Dim, T, Element}
362+
function Base.summary(io::IO, ::Mesh{Dim, T, Element}) where {Dim, T, Element}
327363
print(io, "Mesh{$Dim, $T, ")
328364
summary(io, Element)
329365
print(io, "}")
330366
end
331-
Base.size(x::Mesh) = size(getfield(x, :simplices))
332-
Base.getindex(x::Mesh, i::Integer) = getfield(x, :simplices)[i]
333367

368+
Base.size(mesh::Mesh) = size(getfield(mesh, :simplices))
369+
Base.getindex(mesh::Mesh, i::Integer) = getfield(mesh, :simplices)[i]
334370

335371
function Mesh(elements::AbstractVector{<: Polytope{Dim, T}}) where {Dim, T}
336-
Mesh{Dim, T, eltype(elements), typeof(elements)}(elements)
372+
return Mesh{Dim, T, eltype(elements), typeof(elements)}(elements)
337373
end
338374

339375
function Mesh(points::AbstractVector{<: AbstractPoint}, faces::AbstractVector{<: AbstractFace})
340-
Mesh(connect(points, faces))
376+
return Mesh(connect(points, faces))
341377
end
342378

343379
function Mesh(
344380
points::AbstractVector{<: AbstractPoint}, faces::AbstractVector{<: Integer},
345381
facetype = TriangleFace, skip = 1
346382
)
347-
Mesh(connect(points, connect(faces, facetype, skip)))
383+
return Mesh(connect(points, connect(faces, facetype, skip)))
348384
end

src/boundingboxes.jl

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
function Rect(geometry::AbstractArray{<: Point{N, T}}) where {N,T}
2+
return Rect{N,T}(geometry)
3+
end
4+
5+
"""
6+
Construct a HyperRectangle enclosing all points.
7+
"""
8+
function Rect{N1, T1}(geometry::AbstractArray{PT}) where {N1, T1, PT <: AbstractPoint}
9+
N2, T2 = length(PT), eltype(PT)
10+
@assert N1 >= N2
11+
vmin = Point{N2, T2}(typemax(T2))
12+
vmax = Point{N2, T2}(typemin(T2))
13+
for p in geometry
14+
vmin, vmax = minmax(p, vmin, vmax)
15+
end
16+
o = vmin
17+
w = vmax - vmin
18+
if N1 > N2
19+
z = zero(Vec{N1 - N2, T1})
20+
return Rect{N1, T1}(vcat(o, z), vcat(w, z))
21+
else
22+
return Rect{N1, T1}(o, w)
23+
end
24+
end
25+
26+
function Rect(primitive::GeometryPrimitive{N, T}) where {N, T}
27+
Rect{N, T}(primitive)
28+
end
29+
30+
function Rect{T}(primitive::GeometryPrimitive{N, T}) where {N, T}
31+
Rect{N, T}(primitive)
32+
end
33+
34+
function Rect{T}(a::Pyramid) where T
35+
w,h = a.width / T(2), a.length
36+
m = Vec{3,T}(a.middle)
37+
Rect{T}(m .- Vec{3,T}(w,w,0), m .+ Vec{3,T}(w, w, h))
38+
end
39+
40+
function Rect{T}(a::Sphere) where T
41+
mini, maxi = extrema(a)
42+
Rect{T}(mini, maxi .- mini)
43+
end
44+
45+
Rect{T}(a) where T = Rect{T}(coordinates(a))
46+
Rect{N, T}(a) where {N, T} = Rect{N, T}(coordinates(a))

0 commit comments

Comments
 (0)