Skip to content

Commit

Permalink
Merge pull request #14 from gridap/abstract_plane
Browse files Browse the repository at this point in the history
Define AbstractPlane
  • Loading branch information
pmartorell authored Aug 11, 2022
2 parents b514066 + b99c31a commit 9df3731
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/SimplexFaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ struct Tetrahedron{D,T}<:Face{3,D}
vertices::Tuple{Point{D,T},Point{D,T},Point{D,T},Point{D,T}}
end

struct Plane{D,T}
abstract type AbstractPlane{D,T} end

struct Plane{D,T} <: AbstractPlane{D,T}
origin::Point{D,T}
normal::VectorValue{D,T}
end

struct CartesianPlane{D,T}
struct CartesianPlane{D,T} <: AbstractPlane{D,T}
d::Int8
value::T
positive::Bool
Expand Down Expand Up @@ -60,6 +62,11 @@ function Base.zero(::Type{<:Plane{D,T}}) where {D,T}
Plane(zero(Point{D,T}),zero(Point{D,T}))
end

function origin(p::CartesianPlane{D,T}) where {D,T}
o = zero( Point{D,T} )
Point( Base.setindex(o.data,p.value,p.d) )
end

function Base.getindex(::Face)
@abstractmethod
end
Expand Down Expand Up @@ -539,7 +546,7 @@ end

# Compute planes

function bisector_plane(edge::Face{1,3},Π1::Plane,Π2::Plane)
function bisector_plane(edge::Face{1,3},Π1::AbstractPlane,Π2::AbstractPlane)
n1 = normal(Π1)
n2 = normal(Π2)
n1 n2 -1 || error("Edge too sharp")
Expand Down
23 changes: 23 additions & 0 deletions test/SimplexFacesTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ using STLCutters: distance
using STLCutters: projection
using STLCutters: measure
using STLCutters: normal
using STLCutters: origin
using STLCutters: signed_distance
using STLCutters: contains_projection
using STLCutters: voxel_intersection
using STLCutters: simplex_face
using STLCutters: min_height
using STLCutters: Plane
using STLCutters: CartesianPlane

# Face{1,2}

Expand Down Expand Up @@ -115,6 +117,17 @@ p = Point(0.0,0.0)

@test signed_distance(p,Π) -1/√2

x0 = Point(0.0,0.0)
d = 1
or = 1
Π = CartesianPlane(x0,d,or)
p = Point(1.0,1.0)

@test normal(Π) == VectorValue(1,0)
@test origin(Π) == Point(0,0)
@test signed_distance(p,Π) == 1


# Plane{3}

p1 = Point(0.0,1.0,0.0)
Expand All @@ -127,6 +140,16 @@ p = Point(0.0,0.0,0.0)

@test signed_distance(p,Π) 1/√3

x0 = Point(0.0,0.0,0.0)
d = 1
or = 1
Π = CartesianPlane(x0,d,or)
p = Point(1.0,1.0,1.0)

@test normal(Π) == VectorValue(1,0,0)
@test origin(Π) == Point(0,0,0)
@test signed_distance(p,Π) == 1

# Distance Point - Point

p1 = Point(0.0,0.0)
Expand Down

0 comments on commit 9df3731

Please sign in to comment.