Skip to content

Commit

Permalink
cleanup normal gen and export face_normals
Browse files Browse the repository at this point in the history
  • Loading branch information
ffreyer committed Sep 14, 2024
1 parent d679449 commit d39d1dc
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/GeometryBasics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export AbstractFace, TriangleFace, QuadFace, GLTriangleFace
export OffsetInteger, ZeroIndex, OneIndex, GLIndex
export decompose, coordinates, faces, normals, decompose_uv, decompose_normals,
texturecoordinates, vertex_attributes
export face_normals
export Tesselation, Normal, UV, UVW
export AbstractMesh, Mesh, MetaMesh, FaceView

Expand Down
16 changes: 2 additions & 14 deletions src/geometry_primitives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,6 @@ function normals(vertices::AbstractVector{Point{3,T}}, faces::AbstractVector{F};
return normals(vertices, faces, normaltype)
end

function normals(primitive::GeometryPrimitive{3, T}; normaltype=Vec{3,T}) where {T}
return normals(coordinates(primitive), faces(primitive), normaltype)
end

function normals(vertices::AbstractVector{<:Point{3}}, faces::AbstractVector{F},
::Type{NormalType}) where {F<:NgonFace,NormalType}

Expand All @@ -185,17 +181,9 @@ end
"""
face_normals(positions::Vector{Point3{T}}, faces::Vector{<: NgonFace}[, target_type = Vec3{T}])
Compute vertex normals from the given `positions` and `faces`.
This runs through all faces, computing a face normal each and adding it to every
involved vertex. The direction of the face normal is based on winding direction
and assumed counter-clockwise faces. At the end the summed face normals are
normalized again to produce a vertex normal.
Compute face normals from the given `positions` and `faces` and returns an
appropriate `FaceView`.
"""
function face_normals(primitive::GeometryPrimitive{3, T}; normaltype = Vec{3, T}) where {T}
return face_normals(coordinates(primitive), faces(primitive), normaltype)
end

function face_normals(
positions::AbstractVector{<:Point3{T}}, fs::AbstractVector{<: AbstractFace};
normaltype = Vec3{T}) where {T}
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ end
@testset "Face normals" begin
r = Rect3f(Point3f(0), Vec3f(1))
ns = normals(r)
@test GeometryBasics.face_normals(r) == ns
@test GeometryBasics.face_normals(coordinates(r), faces(r)) == ns
end

@testset "Tests from GeometryTypes" begin
Expand Down

0 comments on commit d39d1dc

Please sign in to comment.