Skip to content

Geometry Basics refactor #219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 126 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
126 commits
Select commit Hold shift + click to select a range
80b89e3
update MetaMesh
ffreyer Aug 30, 2024
1aa721e
add MultiFace type
ffreyer Aug 31, 2024
b08b6f9
update Mesh & MultiFace types
ffreyer Aug 31, 2024
d51280a
update Mesh & MetaMesh utils
ffreyer Aug 31, 2024
f08b120
add MultiFace remapping code
ffreyer Aug 31, 2024
ced6283
prototype MultiFace Rect -> Mesh pipeline
ffreyer Aug 31, 2024
c8c9a8f
generalize MultiFace getindex to Integer
ffreyer Aug 31, 2024
a1e3137
remove add_meta, pop_meta
ffreyer Aug 31, 2024
d89af0e
update merge for MultiFace and views
ffreyer Aug 31, 2024
5577748
add AbstractVertexFace and AbstractMultiFace
ffreyer Sep 2, 2024
8ccba36
split up mesh() for better usability
ffreyer Sep 2, 2024
3461f82
minor fixes
ffreyer Sep 2, 2024
d6fd0d0
add views to Mesh constructors
ffreyer Sep 2, 2024
8975fb1
add `mesh()` method for converting facetype of mesh
ffreyer Sep 2, 2024
4d8d731
switch back to "normals"
ffreyer Sep 2, 2024
59cd70b
fix missing normals rename
ffreyer Sep 2, 2024
8aa215c
add back point/normal/uv-type kwargs
ffreyer Sep 2, 2024
fc37dc1
consider face views in face decompose
ffreyer Sep 2, 2024
d562ab2
add mesh(mesh; attribs...) & improve dispatch safety
ffreyer Sep 2, 2024
08aedf8
fix normals(), cleanup tests
ffreyer Sep 2, 2024
e594800
add mesh constructor tests + fixes
ffreyer Sep 2, 2024
74e4304
deprecate normals for normal as vertex attribute name
ffreyer Sep 4, 2024
ad567dc
make NormalFace and NormalUVFace types again
ffreyer Sep 4, 2024
20eab7d
cleanup tests & normals vs normal
ffreyer Sep 4, 2024
35ddd36
let ci run
ffreyer Sep 4, 2024
d20c615
remove views aware face decomposition
ffreyer Sep 4, 2024
4774ed4
fix rect index order
ffreyer Sep 4, 2024
c1d9f85
fix MultiFace remapping with OffsetIntegers
ffreyer Sep 4, 2024
0bfe393
add moreMultiFace utils
ffreyer Sep 4, 2024
78cabce
Merge branch 'sd/simple-mesh' into ff/refactor
ffreyer Sep 5, 2024
ab6d803
restore decompose(FaceType, faces, views)
ffreyer Sep 5, 2024
813b3e9
Merge branch 'sd/simple-mesh' into ff/refactor
ffreyer Sep 5, 2024
5dd9650
Merge branch 'sd/simple-mesh' into ff/refactor
ffreyer Sep 5, 2024
0adac8b
Merge branch 'sd/simple-mesh' into ff/refactor
ffreyer Sep 5, 2024
00faf55
allow MultiFace -> LineFace conversion
ffreyer Sep 6, 2024
698ec9f
Merge branch 'sd/simple-mesh' into ff/refactor
ffreyer Sep 6, 2024
2b49fb5
define Rect3 faces counterclockwise
ffreyer Sep 6, 2024
ab78ad3
Merge branch 'sd/simple-mesh' into ff/refactor
ffreyer Sep 6, 2024
d218d6d
add more convenience types
ffreyer Sep 6, 2024
e5cf804
filter nothing attributes
ffreyer Sep 6, 2024
4e4ca8a
drop Base.Pairs for 1.6 compat
ffreyer Sep 6, 2024
e7f12c1
Add depwarn in hasproperty too
ffreyer Sep 9, 2024
055d708
improve MultiFace show
ffreyer Sep 10, 2024
ad03f93
update Pyramid
ffreyer Sep 10, 2024
3620842
update Cylinder
ffreyer Sep 10, 2024
86629b9
add MultiFace decompose
ffreyer Sep 10, 2024
334d897
fix Cylinder tests
ffreyer Sep 10, 2024
6944269
make OffsetInteger printing copyable
ffreyer Sep 10, 2024
883b3e1
update tests for Rect3 and normal gen
ffreyer Sep 10, 2024
7474624
fix remaining tests
ffreyer Sep 10, 2024
e5abc38
fix incorrect vertex index counter
ffreyer Sep 10, 2024
4f0bd49
simplify merge of mixed Face types
ffreyer Sep 10, 2024
5da6c02
test merge(meshes)
ffreyer Sep 10, 2024
90d4794
prototype swapping from MultiFace to FaceViews
ffreyer Sep 10, 2024
b9a0f7e
treat views in vertex index remapping + some fixes
ffreyer Sep 10, 2024
13b9881
fix face type change
ffreyer Sep 10, 2024
aef6ea2
clean up AbstractVertexFace
ffreyer Sep 11, 2024
24c0c00
extend FaceView interface
ffreyer Sep 11, 2024
50451e2
update Cylinder, Pyramids
ffreyer Sep 11, 2024
db6edb5
declutter NgonFace prints
ffreyer Sep 12, 2024
e8d48d0
update tests
ffreyer Sep 12, 2024
5ef74ff
cleanup some test_broken
ffreyer Sep 12, 2024
5aa7fa6
switch to Dict
ffreyer Sep 12, 2024
615af26
fix tests
ffreyer Sep 12, 2024
84bb1d7
remove shorthands
ffreyer Sep 12, 2024
18fff4a
export vertex_attributes and FaceView
ffreyer Sep 12, 2024
7736e84
add center point to Circle to avoid shallow triangles
ffreyer Sep 12, 2024
2015cf2
make untesselated rect vertices counter-clockwise
ffreyer Sep 12, 2024
24e6bfb
fix tests
ffreyer Sep 12, 2024
81e5ce5
fix Cylinder face windig direction
ffreyer Sep 13, 2024
355ee01
add `face_normals()` helepr function
ffreyer Sep 13, 2024
9c039c6
cleanup face_normals and normals a bit more
ffreyer Sep 13, 2024
00af22e
update tests for Cylinder
ffreyer Sep 13, 2024
075dc44
rename connectivity -> faces
ffreyer Sep 13, 2024
6d3384f
update docs (meshes, primitives, decompose, Point, Vec, Mat)
ffreyer Sep 13, 2024
6c38a0d
add/update docstrings
ffreyer Sep 13, 2024
c3bb4b2
add quick test for face_normals()
ffreyer Sep 13, 2024
bfaed13
fix TetrahedronFace conversions
ffreyer Sep 14, 2024
51a008d
restore volume functions
ffreyer Sep 14, 2024
ad90d81
fix tests
ffreyer Sep 14, 2024
05c036b
add some Polygon tests
ffreyer Sep 14, 2024
e76dee1
test Pyramids
ffreyer Sep 14, 2024
4ea085b
test TetrahedronFace decomposition
ffreyer Sep 14, 2024
1c06df4
test and improve Mesh validation
ffreyer Sep 14, 2024
8d17e14
test Mesh inteface functions
ffreyer Sep 14, 2024
0757e58
test decompose with views
ffreyer Sep 14, 2024
728d349
test and fix matrix det, inv, transpose, mat*vec
ffreyer Sep 14, 2024
d679449
fix tests
ffreyer Sep 14, 2024
d39d1dc
cleanup normal gen and export face_normals
ffreyer Sep 14, 2024
6402d75
add util for splitting meshes by views
ffreyer Sep 15, 2024
033de56
fix missing dot in range .+ idx
ffreyer Sep 15, 2024
293a154
improve performance of merge
ffreyer Sep 16, 2024
e9c83ec
fix tests
ffreyer Sep 16, 2024
5491a72
improve GeoInterface conversion performance
ffreyer Sep 16, 2024
fae59cd
switch back to NamedTuple for performance
ffreyer Sep 16, 2024
92f79b4
cleanup merge(meshes)
ffreyer Sep 16, 2024
cb1ad71
test clear_faceviews with mesh.views
ffreyer Sep 16, 2024
5066c8a
fix missing import in docs examples
ffreyer Sep 18, 2024
61759f4
add convert for arrays of meshes
ffreyer Sep 18, 2024
18ad6f0
add function for removing duplicate faces
ffreyer Sep 18, 2024
81488f9
update normal gen tests + fixes
ffreyer Sep 18, 2024
1f0f270
remove time piracy
ffreyer Sep 18, 2024
7fc8760
bring back shorthand types
ffreyer Sep 19, 2024
da91216
restrict type in meshes to error earlier
ffreyer Sep 19, 2024
e084c6a
update precompiles
ffreyer Sep 19, 2024
652b8a7
autoconvert point dim in merge(meshes) instead of restricitng type
ffreyer Sep 19, 2024
d47f511
add compat entry
ffreyer Sep 19, 2024
211209c
ignore unused PrecompileTools in 1.6, 1.7
ffreyer Sep 19, 2024
11d7593
bring back old precompiles
ffreyer Sep 19, 2024
81d5bfe
add convert target to orthogonal_vector
ffreyer Sep 19, 2024
e12e85b
revert triangulation changes of Circle
ffreyer Sep 19, 2024
12eb1c5
revert to using StaticArrays
ffreyer Sep 19, 2024
af27647
avoid some invalidations (and fix get)
ffreyer Sep 26, 2024
d90ca22
fix stale instances due to AbstractVector
ffreyer Sep 26, 2024
b9cb8c2
use string interpolation in error to avoid invalidation from string *
ffreyer Sep 26, 2024
b33f82d
fix test
ffreyer Sep 26, 2024
82dd5ce
export clear_faceviews & update FaceView docstring
ffreyer Oct 9, 2024
5da7aa8
update type docstring
ffreyer Oct 10, 2024
44de3f4
add notes about views
ffreyer Oct 10, 2024
a0a6a84
update Mesh docs
ffreyer Oct 10, 2024
69dc746
add FaceView ref to Mesh docstring
ffreyer Oct 10, 2024
275a41c
add brief section about extending decompose
ffreyer Oct 11, 2024
4109645
derive Point eltype when dimension is given
ffreyer Oct 14, 2024
7edf0fa
reuse docstring
ffreyer Oct 16, 2024
a04d5ed
fix docs?
ffreyer Oct 16, 2024
a1bac27
fix docs??
ffreyer Oct 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix Cylinder tests
  • Loading branch information
ffreyer committed Sep 10, 2024
commit 334d897ac405d9f6de678d35d9511224996476f3
2 changes: 1 addition & 1 deletion src/GeometryBasics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export uv_mesh, normal_mesh, uv_normal_mesh

export height, origin, radius, width, widths
export HyperSphere, Circle, Sphere
export Cylinder, Cylinder2, Cylinder3, Pyramid, extremity
export Cylinder, Pyramid, extremity
export HyperRectangle, Rect, Rect2, Rect3, Recti, Rect2i, Rect3i, Rectf, Rect2f, Rect3f, Rectd, Rect2d, Rect3d
export before, during, meets, overlaps, intersects, finishes
export centered, direction, area, volume, update
Expand Down
2 changes: 2 additions & 0 deletions src/basic_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ function Base.show(io::IO, ::MIME"text/plain", f::MultiFace)
show(io, getfield(f, :faces))
end

Base.:(==)(f1::MultiFace, f2::MultiFace) = getfield(f1, :faces) == getfield(f2, :faces)

@propagate_inbounds Base.getindex(x::Polytope, i::Integer) = coordinates(x)[i]
@propagate_inbounds Base.iterate(x::Polytope) = iterate(coordinates(x))
@propagate_inbounds Base.iterate(x::Polytope, i) = iterate(coordinates(x), i)
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function decompose(::Type{F}, primitive::AbstractGeometry) where {F<:AbstractVer
return nothing
end
end
return collect_with_eltype(F, f)
return decompose(F, f)
end

function decompose(::Type{F}, f::AbstractVector) where {F<:AbstractVertexFace}
Expand Down
96 changes: 43 additions & 53 deletions test/geometrytypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,11 @@ using Test, GeometryBasics

@testset "Cylinder" begin
@testset "constructors" begin
o, extr, r = Point2f(1, 2), Point2f(3, 4), 5.0f0
s = Cylinder(o, extr, r)
@test typeof(s) == Cylinder{2,Float32}
@test typeof(s) == Cylinder2{Float32}
@test origin(s) == o
@test extremity(s) == extr
@test radius(s) == r
#@test abs(height(s)- norm([1,2]-[3,4]))<1e-5
h = norm(o - extr)
@test isapprox(height(s), h)
#@test norm(direction(s) - Point{2,Float32}([2,2]./norm([1,2]-[3,4])))<1e-5
@test isapprox(direction(s), Point2f(2, 2) ./ h)
v1 = rand(Point{3,Float64})
v2 = rand(Point{3,Float64})
R = rand()
s = Cylinder(v1, v2, R)
@test typeof(s) == Cylinder{3,Float64}
@test typeof(s) == Cylinder3{Float64}
@test typeof(s) == Cylinder{Float64}
@test origin(s) == v1
@test extremity(s) == v2
@test radius(s) == R
Expand All @@ -29,57 +16,60 @@ using Test, GeometryBasics
end

@testset "decompose" begin

m = GeometryBasics.normal_mesh(Sphere(Point3f(0), 1f0))
@test decompose_uv(m) isa Vector{Vec2f}

o, extr, r = Point2f(1, 2), Point2f(3, 4), 5.0f0
s = Cylinder(o, extr, r)
positions = Point{3,Float32}[(-0.7677671, 3.767767, 0.0),
(2.767767, 0.23223293, 0.0),
(0.23223293, 4.767767, 0.0),
(3.767767, 1.2322329, 0.0), (1.2322329, 5.767767, 0.0),
(4.767767, 2.232233, 0.0)]
@test decompose(Point3f, Tesselation(s, (2, 3))) ≈ positions

FT = TriangleFace{Int}
faces = FT[(1, 2, 4), (1, 4, 3), (3, 4, 6), (3, 6, 5)]
@test faces == decompose(FT, Tesselation(s, (2, 3)))

v1 = Point{3,Float64}(1, 2, 3)
v2 = Point{3,Float64}(4, 5, 6)
R = 5.0
s = Cylinder(v1, v2, R)
positions = Point{3,Float64}[(4.535533905932738, -1.5355339059327373, 3.0),
(7.535533905932738, 1.4644660940672627, 6.0),
(3.0412414523193148, 4.041241452319315,
-1.0824829046386295),
(6.041241452319315, 7.041241452319315,
1.9175170953613705),
(-2.535533905932737, 5.535533905932738,
2.9999999999999996),
(0.46446609406726314, 8.535533905932738, 6.0),
(-1.0412414523193152, -0.04124145231931431,
7.0824829046386295),
(1.9587585476806848, 2.9587585476806857,
10.08248290463863), (1, 2, 3), (4, 5, 6)]
positions = Point{3,Float64}[
(4.535533905932738, -1.5355339059327373, 3.0),
(3.0412414523193148, 4.041241452319315, -1.0824829046386295),
(-2.535533905932737, 5.535533905932738, 2.9999999999999996),
(-1.0412414523193152, -0.04124145231931431, 7.0824829046386295),
(7.535533905932738, 1.4644660940672627, 6.0),
(6.041241452319315, 7.041241452319315, 1.9175170953613705),
(0.46446609406726314, 8.535533905932738, 6.0),
(1.9587585476806848, 2.9587585476806857, 10.08248290463863),
(1, 2, 3),
(4, 5, 6)
]

@test decompose(Point3{Float64}, Tesselation(s, 8)) ≈ positions

faces = TriangleFace{Int}[(3, 2, 1), (4, 2, 3), (5, 4, 3), (6, 4, 5), (7, 6, 5),
(8, 6, 7), (1, 8, 7), (2, 8, 1), (3, 1, 9), (2, 4, 10),
(5, 3, 9), (4, 6, 10), (7, 5, 9), (6, 8, 10), (1, 7, 9),
(8, 2, 10)]
@test faces == decompose(TriangleFace{Int}, Tesselation(s, 8))
_faces = [
MultiFace(position = TriangleFace(9, 1, 2), normal = TriangleFace(5, 5, 5)),
MultiFace(position = TriangleFace(9, 2, 3), normal = TriangleFace(5, 5, 5)),
MultiFace(position = TriangleFace(9, 3, 4), normal = TriangleFace(5, 5, 5)),
MultiFace(position = TriangleFace(9, 4, 1), normal = TriangleFace(5, 5, 5)),
MultiFace(position = TriangleFace(1, 5, 6), normal = TriangleFace(1, 1, 2)),
MultiFace(position = TriangleFace(1, 6, 2), normal = TriangleFace(1, 2, 2)),
MultiFace(position = TriangleFace(2, 6, 7), normal = TriangleFace(2, 2, 3)),
MultiFace(position = TriangleFace(2, 7, 3), normal = TriangleFace(2, 3, 3)),
MultiFace(position = TriangleFace(3, 7, 8), normal = TriangleFace(3, 3, 4)),
MultiFace(position = TriangleFace(3, 8, 4), normal = TriangleFace(3, 4, 4)),
MultiFace(position = TriangleFace(4, 8, 5), normal = TriangleFace(4, 4, 1)),
MultiFace(position = TriangleFace(4, 5, 1), normal = TriangleFace(4, 1, 1)),
MultiFace(position = TriangleFace(10, 5, 6), normal = TriangleFace(6, 6, 6)),
MultiFace(position = TriangleFace(10, 6, 7), normal = TriangleFace(6, 6, 6)),
MultiFace(position = TriangleFace(10, 7, 8), normal = TriangleFace(6, 6, 6)),
MultiFace(position = TriangleFace(10, 8, 5), normal = TriangleFace(6, 6, 6)),
]

@test _faces == decompose(TriangleFace{Int}, Tesselation(s, 8))

m = triangle_mesh(Tesselation(s, 8))
@test m === triangle_mesh(m)
@test GeometryBasics.faces(m) == faces
@test GeometryBasics.coordinates(m) ≈ positions
m = normal_mesh(s)# just test that it works without explicit resolution parameter
fs, maps = GeometryBasics.merge_vertex_indices(GeometryBasics.simplify_faces((:position,), _faces))
@test GeometryBasics.faces(m) == decompose(GLTriangleFace, fs)
@test GeometryBasics.coordinates(m) ≈ positions[maps[1]]

m = normal_mesh(s) # just test that it works without explicit resolution parameter
@test hasproperty(m, :position)
@test hasproperty(m, :normal)
@test length(m.position) == length(m.normal)
@test faces(m) isa AbstractVector{GLTriangleFace}

muv = uv_mesh(s)
@test Rect(Point.(texturecoordinates(muv))) == Rect2f(Vec2f(0), Vec2f(1.0))
@test !hasproperty(muv, :uv) # not defined yet
end
end

Expand Down