@@ -1,16 +1,20 @@
//! Display-only tangent joins: which edges the shaded view leaves out because the two faces meet
//! across them with one tangent plane (G1), and which it must keep because they are a crease or
//! an authored split.
//! Display-only smooth joins: which edges the shaded view leaves out because they lie inside one
//! smooth surface (the two faces meet with one tangent plane and one curvature across the edge,
//! G2), and which it must keep because they are a crease or an authored split. A join that is
//! only tangent (G1: a fillet's boundary, a plane tangent to a cylinder) is a feature line and is
//! drawn.
//!
//! One rule for every surface: at stations along the edge, each face's outward normal i s
//! evaluated on its exact surface ([`Face::parameters`]) at the edge's exact pcurve in that face
//! (the use's own pcurve, so a seam a face meets itself across is the same test with its two
//! pcurves), turned by the side the shell uses the face on. The edge is smooth when the normals
//! agree within [`ANGLE`] at every station, and a crease when they differ by more anywhere. The
//! flags are display-only: the edge keeps its identity and stays pickable, its faces stay apart
//! (pieces of one surface are [`crate::topo::seam_flags`]'s business), and unknown geometry
//! (a station that does not evaluate) keeps its existing presentation.
use solidcraft_geom ::brep ::eval ::SurfaceEval ;
//! One rule for every surface: at stations along the edge, each face's outward normal and it s
//! normal curvature across the edge are evaluated on its exact surface ([`Face::parameters`]) at
//! the edge's exact pcurve in that face (the use's own pcurve, so a seam a face meets itself
//! across is the same test with its two pcurves), turned by the side the shell uses the face on.
//! The edge is smooth when the normals agree within [`ANGLE`] and the curvatures within [`BEND`]
//! at every station; it is a crease where the normals differ by more than the
//! evaluation can account for anywhere (a crease far too small to see is both). Smoothness is
//! display-only: the edge keeps its identity, stays pickable and stays in the wireframe, and its
//! faces stay apart (pieces of one surface are [`crate::topo::seam_flags`]'s business). Unknown
//! geometry (a station that does not evaluate) keeps its existing presentation.
use solidcraft_geom ::brep ::eval ::{ CurveEval , SurfaceEval } ;
use solidcraft_geom ::brep ::{ Brep , Loop , Shell } ;
use solidcraft_geom ::{ Mesh , Vec3 } ;
@@ -27,20 +31,39 @@ const STATIONS: usize = 8;
/// degree. Shading is the visible trace of a join: across a crease of angle θ the lit intensity
/// jumps by at most about θ of its range, and half a degree (0.0087) is under 1%, below the
/// 1– 2% step the eye tells apart on a smooth gradient. So a join this close to tangent shows no
/// line in the shading, and drawing one would only show how the surface was cut into faces
/// (a thread's flank piec es, a sweep's spans). Exact tangency (fillets, analytic seams) reads
/// 1e-12 or so, far inside it; real creases a model means are degrees.
/// line in the shading. Exact tangency (fillets, analytic seams) reads 1e-12 or so, far inside
/// it; real creas es a model means are degrees. Tangency alone does not hide an edge ([`BEND`]).
const ANGLE : f64 = 0.5 * std ::f64 ::consts ::PI / 180.0 ;
/// Largest difference of the two faces' normal curvatures across an edge, relative to the
/// larger one (or to 1 / the edge's length where both are flatter), that still counts as one
/// smooth surface (G2): [`ANGLE`], the same visibility criterion as for the normals. Continued
/// past the edge, two faces whose curvatures differ by Δκ turn their normals apart by Δκ per
/// mm; the bound keeps that under [`ANGLE`] over one radius of curvature (Δκ / κ) and over the
/// edge's own length (Δκ L), so the join leaves no visible kink in reflections either. A join
/// that is only tangent (G1) is a feature line and stays drawn: a fillet meets its plane with a
/// jump from 0 to 1 / radius (a relative difference of 1), a cylinder meets a tangent plane the
/// same way. Pieces of one surface pass: exact pieces agree to rounding, and a modelled thread's
/// flank pieces (spans of one sweep) differ by at most 0.0046 (measured, the thread test).
const BEND : f64 = ANGLE ;
/// Below this sine of the angle between ∂S/∂u and ∂S/∂v the normal is undefined (a pole, an
/// apex): such a station says nothing.
const DEGENERATE : f64 = 1e-9 ;
/// Angle, in radians, that rounding alone can put between two unit normals evaluated in double
/// precision on exactly one tangent plane.
const ROUNDOFF : f64 = 1e-12 ;
/// What the stations along one edge say.
#[ derive(Clone, Copy, Debug, PartialEq) ]
enum Join {
Smooth ,
Crease ,
Unknown ,
/// What the stations along one edge say. The two verdicts are separate: a join can be too
/// close to tangent to show in the shading (`smooth`) and still be a measured crease
/// (`crease`) — a real edge between two surfaces, kept pickable and apart even where a coarse
/// fit takes its faces for one surface ([`crate::topo::seam_flags`]).
#[ derive(Clone, Copy, Debug, Default, PartialEq) ]
struct Join {
/// Every station's normals agree within [`ANGLE`] and its curvatures across within [`BEND`].
smooth : bool ,
/// Some station's normals differ by more than the evaluation can account for: the pcurve
/// points lie some distance off the edge's curve (measured at the station), and over that
/// distance a normal turns by at most the distance times the surface's largest curvature.
crease : bool ,
}
pub ( crate ) fn flags ( body : & Body , mesh : & Mesh ) -> ( Vec < bool > , Vec < bool > ) {
@@ -77,53 +100,117 @@ fn face_evals(record: &Brep) -> Vec<Option<FaceEval>> {
. collect ( )
}
/// The outward unit normal of `face` at `uv`; `Some(None)` where the normal is undefined there.
fn normal ( face : & FaceEval , uv : [ f64 ; 2 ] ) -> Option < Option < Vec3 > > {
let ( p , su , sv ) = face . surface . derivs ( uv [ 0 ] , uv [ 1 ] ) ? ;
if ! p . is_finite ( ) | | ! su . is_finite ( ) | | ! sv . is_finite ( ) {
/// A face at a station: its point, outward unit normal, first and second derivatives, and a
/// bound on its curvature.
struct Station {
point : Vec3 ,
normal : Vec3 ,
su : Vec3 ,
sv : Vec3 ,
/// `(S_uu, S_uv, S_vv)`; `None` where the surface has none (a revolution).
second : Option < ( Vec3 , Vec3 , Vec3 ) > ,
/// The larger principal curvature's size, 1/mm (`None`: no second derivatives, so a crease
/// cannot be told from evaluation error).
curvature : Option < f64 > ,
}
impl Station {
/// The normal curvature in the tangent direction `w`, 1/mm, signed by the outward normal:
/// II(w) / I(w), with `w` written in (u, v) by its projection on the tangent plane.
fn across ( & self , w : Vec3 ) -> Option < f64 > {
let ( suu , suv , svv ) = self . second ? ;
let ( e , f , g ) = ( self . su . dot ( self . su ) , self . su . dot ( self . sv ) , self . sv . dot ( self . sv ) ) ;
let det = e * g - f * f ;
let ( wu , wv ) = ( self . su . dot ( w ) , self . sv . dot ( w ) ) ;
let ( a , b ) = ( ( g * wu - f * wv ) / det , ( e * wv - f * wu ) / det ) ;
let first = e * a * a + 2. * f * a * b + g * b * b ;
let ( l , m , n ) = ( suu . dot ( self . normal ) , suv . dot ( self . normal ) , svv . dot ( self . normal ) ) ;
let k = ( l * a * a + 2. * m * a * b + n * b * b ) / first ;
( det > 0. & & first > 0. & & k . is_finite ( ) ) . then_some ( k )
}
}
/// `face` at `uv`; `Some(None)` where the normal is undefined there, `None` where it does not
/// evaluate.
fn station ( face : & FaceEval , uv : [ f64 ; 2 ] ) -> Option < Option < Station > > {
let ( point , su , sv ) = face . surface . derivs ( uv [ 0 ] , uv [ 1 ] ) ? ;
if ! point . is_finite ( ) | | ! su . is_finite ( ) | | ! sv . is_finite ( ) {
return None ;
}
let n = su . cross ( sv ) ;
if ! ( n . len ( ) > DEGENERATE * su . len ( ) * sv . len ( ) ) {
return Some ( None ) ;
}
Some ( n . normalized ( ) . map ( | n | n * face . side ) )
let Some ( unit ) = n . normalized ( ) else { return Some ( None ) } ;
let second = face . surface . second ( uv [ 0 ] , uv [ 1 ] ) . filter ( | ( a , b , c ) | a . is_finite ( ) & & b . is_finite ( ) & & c . is_finite ( ) ) ;
// The principal curvatures, from the shape operator I⁻¹ II: H ± √(H² − K).
let curvature = second . and_then ( | ( suu , suv , svv ) | {
let ( e , f , g ) = ( su . dot ( su ) , su . dot ( sv ) , sv . dot ( sv ) ) ;
let ( l , m , n ) = ( suu . dot ( unit ) , suv . dot ( unit ) , svv . dot ( unit ) ) ;
let det = e * g - f * f ;
let mean = ( e * n - 2. * f * m + g * l ) / ( 2. * det ) ;
let gauss = ( l * n - m * m ) / det ;
let most = mean . abs ( ) + ( mean * mean - gauss ) . max ( 0. ) . sqrt ( ) ;
( det > 0. & & most . is_finite ( ) ) . then_some ( most )
} ) ;
Some ( Some ( Station { point , normal : unit * face . side , su , sv , second , curvature } ) )
}
/// How the two uses of edge `e` meet: their faces' outward normals compared at [`STATIONS`]
/// stations, each through its own pcurve.
fn join ( record : & Brep , faces : & [ Option < FaceEval > ] , e : usize , work : & mut usize ) -> Join {
let Some ( edge ) = record . edges . get ( e ) else { return Join ::Unknown } ;
let [ a , b ] = edge . uses . as_slice ( ) else { return Join ::Unknown } ;
fn join ( record : & Brep , faces : & [ Option < FaceEval > ] , e : usize , length : f64 , work : & mut usize ) -> Join {
let unknown = Join ::default ( ) ;
let Some ( edge ) = record . edges . get ( e ) else { return unknown } ;
let [ a , b ] = edge . uses . as_slice ( ) else { return unknown } ;
let side = | u : & solidcraft_geom ::brep ::EdgeUseRef | {
let face = faces . get ( u . face as usize ) ? . as_ref ( ) ? ;
let Loop ::Edges { edges } = record . faces . get ( u . face as usize ) ? . loops . get ( u . r#loop as usize ) ? else { return None } ;
let used = edges . get ( u . position as usize ) ? ;
( used . edge as usize = = e ) . then_some ( ( face , & used . pcurve ) )
} ;
let ( Some ( ( fa , pa ) ) , Some ( ( fb , pb ) ) ) = ( side ( a ) , side ( b ) ) else { return Join ::Unknown } ;
let ( Some ( ( fa , pa ) ) , Some ( ( fb , pb ) ) ) = ( side ( a ) , side ( b ) ) else { return unknown } ;
let [ t0 , t1 ] = edge . interval ;
if ! ( t0 . is_finite ( ) & & t1 . is_finite ( ) & & t0 < t1 ) {
return Join ::Unknown ;
if ! ( t0 . is_finite ( ) & & t1 . is_finite ( ) & & t0 < t1 & & edge . tolerance . is_finite ( ) & & edge . tolerance > = 0. ) {
return unknown ;
}
let mut measured = false ;
let curve = CurveEval ::new ( edge . parameters ( ) ) . ok ( ) ;
let ( mut measured , mut smooth , mut crease ) = ( false , true , false ) ;
for k in 0 .. STATIONS {
let Some ( left ) = work . checked_sub ( 2 ) else { return Join ::Unknown } ;
let Some ( left ) = work . checked_sub ( 2 ) else { return unknown } ;
* work = left ;
let t = t0 + ( t1 - t0 ) * ( k as f64 + 0.5 ) / STATIONS as f64 ;
let ( Some ( ua ) , Some ( ub ) ) = ( pa . eval ( t ) , pb . eval ( t ) ) else { return Join ::Unknown } ;
let ( Some ( na ) , Some ( nb ) ) = ( normal ( fa , ua ) , normal ( fb , ub ) ) else { return Join ::Unknown } ;
let ( Some ( na ) , Some ( nb ) ) = ( na , nb ) else { continue } ;
let angle = na . cross ( nb ) . len ( ) . atan2 ( na . dot ( nb ) ) ;
let ( Some ( ua ) , Some ( ub ) ) = ( pa . eval ( t ) , pb . eval ( t ) ) else { return unknown } ;
let ( Some ( sa ) , Some ( sb ) ) = ( station ( fa , ua ) , station ( fb , ub ) ) else { return unknown } ;
let ( Some ( sa ) , Some ( sb ) ) = ( sa , sb ) else { continue } ;
let angle = sa . normal . cross ( sb . normal ) . len ( ) . atan2 ( sa . normal . dot ( sb . normal ) ) ;
if ! angle . is_finite ( ) {
return Join ::Unknown ;
}
if angle > ANGLE {
return Join ::Crease ;
return unknown ;
}
measured = true ;
smooth & = angle < = ANGLE & & same_bend ( & sa , & sb , curve . as_ref ( ) . and_then ( | c | c . derivs ( t ) ) . map ( | d | d . 1 ) , length ) ;
// How far each evaluated point lies off the edge, measured on the edge's own curve
// (its tolerance where the curve does not evaluate).
let off = match curve . as_ref ( ) . and_then ( | c | c . point ( t ) ) . filter ( | c | c . is_finite ( ) ) {
Some ( c ) = > sa . point . dist ( c ) . max ( sb . point . dist ( c ) ) . max ( sa . point . dist ( sb . point ) ) ,
None = > edge . tolerance ,
} ;
if let ( Some ( ka ) , Some ( kb ) ) = ( sa . curvature , sb . curvature ) {
crease | = angle > off * ( ka + kb ) + ROUNDOFF ;
}
crease | = angle > ANGLE ;
}
if measured { Join ::Smooth } else { Join ::Unknown }
if measured { Join { smooth , crease } } else { unknown }
}
/// Do the two faces bend alike across the edge at a station (G2 there): their normal
/// curvatures in the direction across the edge (in the tangent plane, square to the edge's
/// tangent `along`) within [`BEND`] of the larger, or of 1 / `length` where both are flatter
/// than that? Unknown (no tangent, no second derivatives) is no.
fn same_bend ( a : & Station , b : & Station , along : Option < Vec3 > , length : f64 ) -> bool {
let Some ( w ) = along . and_then ( | t | a . normal . cross ( t ) . normalized ( ) ) else { return false } ;
let ( Some ( ka ) , Some ( kb ) ) = ( a . across ( w ) , b . across ( w ) ) else { return false } ;
let scale = ka . abs ( ) . max ( kb . abs ( ) ) . max ( 1. / length ) ;
( ka - kb ) . abs ( ) < = BEND * scale
}
/// Does the mesh's edge `e` bound the faces the record's edge `e` is used by? A mesh that says
@@ -164,11 +251,13 @@ fn classify(body: &Body, mesh: &Mesh, mut work: usize) -> (Vec<bool>, Vec<bool>)
} else if ! same_faces ( & rec , mesh , current ) {
None
} else {
match join ( & rec , & faces , current , & mut work ) {
Join ::Smooth = > smooth . get_mut ( current ) ,
Join ::Crease = > sharp . get_mut ( current ) ,
Join ::Unknown = > None ,
let length : f64 = line . windows ( 2 ) . map ( | w | if let [ a , b ] = w { a . dist ( * b ) } else { 0. } ) . sum ( ) ;
let Join { smooth : tangent , crease } =
if length > 0. & & length . is_finite ( ) { join ( & rec , & faces , current , length , & mut work ) } else { Join ::default ( ) } ;
if let ( true , Some ( flag ) ) = ( tangent , smooth . get_mut ( current ) ) {
* flag = true ;
}
crease . then ( | | sharp . get_mut ( current ) ) . flatten ( )
} ;
if let Some ( flag ) = flag {
* flag = true ;
@@ -239,6 +328,7 @@ mod tests {
for ( index , ( line , smooth ) ) in mesh . edges . iter ( ) . zip ( & mesh . smooth_edges ) . enumerate ( ) {
let vertical = ( line . first ( ) . unwrap ( ) . z - line . last ( ) . unwrap ( ) . z ) . abs ( ) > 2.9 ;
assert_eq! ( * smooth , vertical ) ;
assert! ( ! ( vertical & & mesh . sharp_edges [ index ] ) , " a tangent join is measured as no crease " ) ;
if ! vertical {
assert! ( mesh . shaded_edge_visible ( index ) ) ;
}
@@ -293,15 +383,20 @@ mod tests {
#[ test ]
fn a_crease_over_half_a_degree_is_visible_and_one_under_it_is_not ( ) {
let ( _ , mesh , crease ) = creased ( 1.0 ) ;
assert_eq! ( mesh . smooth_edges . iter ( ) . filter ( | f | * * f ) . count ( ) , 7 ) ;
// The crease's other end bends differently too: only six joins are one smooth surface.
assert_eq! ( mesh . smooth_edges . iter ( ) . filter ( | f | * * f ) . count ( ) , 6 ) ;
assert! ( ! mesh . smooth_edges [ crease ] ) ;
assert! ( mesh . sharp_edges [ crease ] ) ;
assert! ( mesh . shaded_edge_visible ( crease ) ) ;
assert! ( mesh . edge_pickable ( crease ) ) ;
let ( _ , mesh , crease ) = creased ( 0.2 ) ;
assert_eq! ( mesh . smooth_edges . iter ( ) . filter ( | f | * * f ) . count ( ) , 8 ) ;
assert! ( ! mesh . shaded_edge_visible ( crease ) ) ;
assert! ( mesh . edge_pickable ( crease ) , " a smooth join is only left undrawn " ) ;
// Too small to see, but measured: not drawn in the shading, still a real edge.
for degrees in [ 0.2 , 1e-4 ] {
let ( _ , mesh , crease ) = creased ( degrees ) ;
assert_eq ! ( mesh . smooth_edges . iter ( ) . filter ( | f | * * f ) . count ( ) , 8 , " {degrees} " ) ;
assert! ( mesh . sharp_edges [ crease ] , " {degrees} " ) ;
assert! ( ! mesh . shaded_edge_visible ( crease ) , " {degrees} " ) ;
assert! ( mesh . edge_visible ( crease ) & & mesh . edge_pickable ( crease ) , " {degrees}: a smooth join is only left undrawn " ) ;
}
}
#[ test ]
@@ -322,19 +417,11 @@ mod tests {
}
}
/// The edges of a body's mesh by how the shaded view draws them: (smooth, crease, neither).
fn census ( body : & Body ) -> ( usize , usize , usize ) {
let mesh = body . mesh ( & crate ::MeshTolerance ::chord ( 0.02 ) ) . unwrap ( ) ;
let smooth = mesh . smooth_edges . iter ( ) . filter ( | f | * * f ) . count ( ) ;
let sharp = mesh . sharp_edges . iter ( ) . filter ( | f | * * f ) . count ( ) ;
assert! ( mesh . smooth_edges . iter ( ) . zip ( & mesh . sharp_edges ) . all ( | ( a , b ) | ! ( * a & & * b ) ) ) ;
( smooth , sharp , mesh . edges . len ( ) - smooth - sharp )
}
#[ test ]
fn a_spheres_and_a_cylinders_seams_are_smooth_and_their_rims_creases ( ) {
let sphere = crate ::sphere ( Vec3 ::ZERO , 10. ) . unwrap ( ) ;
let ( smooth , sharp , _ ) = census ( & sphere ) ;
let mesh = sphere . mesh ( & crate ::MeshTolerance ::chord ( 0.02 ) ) . unwrap ( ) ;
let ( smooth , sharp ) = ( mesh . smooth_edges . iter ( ) . filter ( | f | * * f ) . count ( ) , mesh . sharp_edges . iter ( ) . filter ( | f | * * f ) . count ( ) ) ;
assert! ( smooth > = 1 & & sharp = = 0 , " sphere: {smooth} smooth, {sharp} creases " ) ;
let cylinder = crate ::cylinder ( Vec3 ::ZERO , Vec3 ::Z , 8. , 20. ) . unwrap ( ) ;
let mesh = cylinder . mesh ( & crate ::MeshTolerance ::chord ( 0.02 ) ) . unwrap ( ) ;
@@ -346,9 +433,10 @@ mod tests {
}
/// A box with its top edges and one upright edge rounded: every round meets its faces and
/// its neighbours tangentially, so none of those joins is drawn; the box's own edges are.
/// its neighbours tangentially (G1, not G2), so each of those joins is a drawn feature line
/// but no crease; the box's own edges and the miters are creases.
#[ test ]
fn a_filleted_boxs_tangent_joins_are_smooth_and_its_corners_creases ( ) {
fn a_filleted_boxs_tangent_joins_are_drawn_and_its_corners_creases ( ) {
let block = crate ::box_solid ( Vec3 ::ZERO , Vec3 ::new ( 20. , 20. , 10. ) ) . unwrap ( ) ;
let picks = [ Vec3 ::new ( 10. , 0. , 10. ) , Vec3 ::new ( 20. , 10. , 10. ) , Vec3 ::new ( 10. , 20. , 10. ) , Vec3 ::new ( 0. , 10. , 10. ) , Vec3 ::new ( 20. , 20. , 5. ) ] ;
let rounded = crate ::fillet ( & block , & picks , 3. ) . unwrap ( ) ;
@@ -361,21 +449,56 @@ mod tests {
let bottom = line . iter ( ) . all ( | p | p . z . abs ( ) < 1e-6 ) ;
let square_upright = corner ( a ) & & corner ( b ) & & ( a . z - b . z ) . abs ( ) > 1. ;
let miter = ( corner ( a ) & & ( b . z - 10. ) . abs ( ) < 1e-6 ) | | ( corner ( b ) & & ( a . z - 10. ) . abs ( ) < 1e-6 ) ;
if bottom | | square_upright | | miter {
assert! ( mesh . sharp_edges [ i ] & & mesh . shaded_edge_visible ( i ) , " edge {i} {line:?} i s a crease " ) ;
} else {
assert! ( mesh . smooth_edges [ i ] & & ! mesh . shaded_edge_visible ( i ) , " edge {i} {:?}..{:?} is a tangent join " , line . first ( ) , line . last ( ) ) ;
assert! ( mesh . edge_pickable ( i ) , " edge {i} stays pickable " ) ;
}
assert! ( ! mesh . smooth_edges [ i ] & & mesh . shaded_edge_visible ( i ) & & mesh . edge_pickable ( i ) , " edge {i} {a:?}..{b:?} is drawn " ) ;
assert_eq ! ( mesh . sharp_edges [ i ] , bottom | | square_upright | | miter , " edge {i} {a:?}..{b:?}: only the box's edge s are creases " ) ;
}
}
/// A plane tangent to a cylinder (a D-shaped prism): one tangent plane, but the curvature
/// jumps from 0 to 1 / radius, so the join is drawn.
#[ test ]
fn a_plane_tangent_to_a_cylinder_is_drawn ( ) {
let ( a , b , c , d ) = ( Vec2 ::new ( - 5. , - 5. ) , Vec2 ::new ( 5. , - 5. ) , Vec2 ::new ( 5. , 5. ) , Vec2 ::new ( - 5. , 5. ) ) ;
let outer = Loop2 {
segs : vec ! [
Seg2 ::Line { a , b } ,
Seg2 ::Arc { center : Vec2 ::new ( 5. , 0. ) , radius : 5. , start : - std ::f64 ::consts ::FRAC_PI_2 , sweep : std ::f64 ::consts ::PI } ,
Seg2 ::Line { a : c , b : d } ,
Seg2 ::Line { a : d , b : a } ,
] ,
} ;
let body = crate ::extrude ( & Plane ::XY , & [ Region2 { outer , holes : vec ! [ ] } ] , 0. , 3. ) . unwrap ( ) . remove ( 0 ) ;
let mesh = body . mesh ( & crate ::MeshTolerance ::chord ( 0.02 ) ) . unwrap ( ) ;
let joins : Vec < usize > = ( 0 .. mesh . edges . len ( ) )
. filter ( | & i | {
let line = & mesh . edges [ i ] ;
line . first ( )
. zip ( line . last ( ) )
. is_some_and ( | ( p , q ) | ( p . x - 5. ) . abs ( ) < 1e-6 & & ( p . y . abs ( ) - 5. ) . abs ( ) < 1e-6 & & ( p . z - q . z ) . abs ( ) > 2.9 )
} )
. collect ( ) ;
assert_eq! ( joins . len ( ) , 2 , " {:?} " , mesh . edges . iter ( ) . map ( | l | ( l . first ( ) , l . last ( ) ) ) . collect ::< Vec < _ > > ( ) ) ;
for i in joins {
assert! ( ! mesh . smooth_edges [ i ] & & ! mesh . sharp_edges [ i ] , " edge {i}: tangent, not curvature continuous, no crease " ) ;
assert! ( mesh . shaded_edge_visible ( i ) & & mesh . edge_pickable ( i ) ) ;
}
}
#[ test ]
fn a_degenerate_normal_says_nothing ( ) {
let face = FaceEval { surface : SurfaceEval ::new ( & Surface ::Sphere { frame : solidcraft_geom ::brep ::Frame { origin : [ 0. ; 3 ] , x_axis : [ 1. , 0. , 0. ] , y_axis : [ 0. , 1. , 0. ] } , radius : 2. } ) . unwrap ( ) , side : 1. } ;
assert_eq! ( normal ( & face , [ 0.3 , std ::f64 ::consts ::FRAC_PI_2 ] ) , Some ( None ) , " the pole " ) ;
let n = normal ( & face , [ 0. , 0. ] ) . unwrap ( ) . unwrap ( ) ;
assert! ( ( n - Vec3 ::X ) . len ( ) < 1e-12 , " {n:?} " ) ;
assert_eq! ( normal ( & face , [ f64 ::NAN , 0. ] ) , None ) ;
let face = FaceEval {
surface : SurfaceEval ::new ( & Surface ::Sphere {
frame : solidcraft_geom ::brep ::Frame { origin : [ 0. ; 3 ] , x_axis : [ 1. , 0. , 0. ] , y_axis : [ 0. , 1. , 0. ] } ,
radius : 2. ,
} )
. unwrap ( ) ,
side : 1. ,
} ;
assert! ( matches! ( station ( & face , [ 0.3 , std ::f64 ::consts ::FRAC_PI_2 ] ) , Some ( None ) ) , " the pole " ) ;
let at = station ( & face , [ 0. , 0. ] ) . unwrap ( ) . unwrap ( ) ;
assert! ( ( at . normal - Vec3 ::X ) . len ( ) < 1e-12 , " {:?} " , at . normal ) ;
// A sphere's normal curvature is 1 / radius in every direction.
assert! ( at . curvature . is_some_and ( | k | ( k - 0.5 ) . abs ( ) < 1e-9 ) , " {:?} " , at . curvature ) ;
assert! ( station ( & face , [ f64 ::NAN , 0. ] ) . is_none ( ) ) ;
}
}