Skip to content

Commit 3018e54

Browse files
committed
don't consider faces equal under cyclic permutation by default
1 parent 14f3ce4 commit 3018e54

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

src/basic_types.jl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function Base.show(io::IO, x::NgonFace{N, T}) where {N, T}
8282
end
8383

8484
# two faces are the same if they match or they just cycle indices
85-
function Base.:(==)(f1::FT, f2::FT) where {N, FT <: AbstractFace{N}}
85+
function cyclic_equal(f1::FT, f2::FT) where {N, FT <: AbstractFace{N}}
8686
_, min_i1 = findmin(f1.data)
8787
_, min_i2 = findmin(f2.data)
8888
@inbounds for i in 1:N
@@ -92,7 +92,7 @@ function Base.:(==)(f1::FT, f2::FT) where {N, FT <: AbstractFace{N}}
9292
end
9393
return true
9494
end
95-
function Base.hash(f::AbstractFace{N}, h::UInt) where {N}
95+
function cyclic_hash(f::AbstractFace{N}, h::UInt = hash(0)) where {N}
9696
_, min_i = findmin(f.data)
9797
@inbounds for i in min_i:N
9898
h = hash(f[i], h)
@@ -102,17 +102,16 @@ function Base.hash(f::AbstractFace{N}, h::UInt) where {N}
102102
end
103103
return h
104104
end
105-
Base.isequal(f1::AbstractFace, f2::AbstractFace) = ==(f1, f2)
106105

107106
# Fastpaths
108-
Base.:(==)(f1::FT, f2::FT) where {FT <: AbstractFace{2}} = minmax(f1.data...) == minmax(f2.data...)
109-
Base.hash(f::AbstractFace{2}, h::UInt) = hash(minmax(f.data...), h)
107+
cyclic_equal(f1::FT, f2::FT) where {FT <: AbstractFace{2}} = minmax(f1.data...) == minmax(f2.data...)
108+
cyclic_hash(f::AbstractFace{2}, h::UInt = hash(0)) = hash(minmax(f.data...), h)
110109

111-
function Base.:(==)(f1::FT, f2::FT) where {FT <: AbstractFace{3}}
110+
function cyclic_equal(f1::FT, f2::FT) where {FT <: AbstractFace{3}}
112111
return (f1.data == f2.data) || (f1.data == (f2[2], f2[3], f2[1])) ||
113112
(f1.data == (f2[3], f2[1], f2[2]))
114113
end
115-
function Base.hash(f::AbstractFace{3}, h::UInt)
114+
function cyclic_hash(f::AbstractFace{3}, h::UInt = hash(0))
116115
if f[1] < f[2]
117116
if f[1] < f[3]
118117
return hash(f.data, h)

src/meshes.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,9 +468,9 @@ end
468468
Uses a Dict to remove duplicates from the given `faces`.
469469
"""
470470
function remove_duplicates(fs::AbstractVector{FT}) where {FT <: AbstractFace}
471-
hashmap = Dict{FT, Nothing}()
472-
foreach(k -> setindex!(hashmap, nothing, k), fs)
473-
return collect(keys(hashmap))
471+
hashmap = Dict{UInt64, FT}()
472+
foreach(f -> hashmap[cyclic_hash(f)] = f, fs)
473+
return collect(values(hashmap))
474474
end
475475

476476

test/geometrytypes.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,13 @@ end
290290
f = QuadFace(3, 4, 7, 8)
291291
@test data[f] == ("3", "4", "7", "8")
292292

293-
@test hash(f) != hash(QuadFace(1,2,3,4))
294-
@test hash(f) == hash(QuadFace(3,4,7,8))
293+
@test GeometryBasics.cyclic_hash(f) != GeometryBasics.cyclic_hash(QuadFace(1,2,3,4))
294+
@test GeometryBasics.cyclic_hash(f) == GeometryBasics.cyclic_hash(QuadFace(3,4,7,8))
295295
# cyclic permutation does not change the face
296-
@test hash(f) == hash(QuadFace(7,8,3,4))
297-
@test hash(GLTriangleFace(1,2,3)) == hash(GLTriangleFace(1,2,3))
298-
@test hash(GLTriangleFace(1,2,3)) == hash(GLTriangleFace(2,3,1))
299-
@test hash(GLTriangleFace(1,2,3)) == hash(GLTriangleFace(3,1,2))
296+
@test GeometryBasics.cyclic_hash(f) == GeometryBasics.cyclic_hash(QuadFace(7,8,3,4))
297+
@test GeometryBasics.cyclic_hash(GLTriangleFace(1,2,3)) == GeometryBasics.cyclic_hash(GLTriangleFace(1,2,3))
298+
@test GeometryBasics.cyclic_hash(GLTriangleFace(1,2,3)) == GeometryBasics.cyclic_hash(GLTriangleFace(2,3,1))
299+
@test GeometryBasics.cyclic_hash(GLTriangleFace(1,2,3)) == GeometryBasics.cyclic_hash(GLTriangleFace(3,1,2))
300300
end
301301

302302
@testset "FaceView" begin

0 commit comments

Comments
 (0)