R Under development (unstable) (2025-06-04 r88278 ucrt) -- "Unsuffered Consequences" Copyright (C) 2025 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > > library( polarzonoid ) > > options( width=160 ) > > > # n # of arcs > # count # of reps > # tol # for the discrepancy > > # return TRUE or FALSE > testboundaryvalue <- function( n, count=1000, tol=5.e-13 ) + { + set.seed(0) + + bvalue = numeric(count) + + for( i in 1:count ) + { + arcmat = polarzonoid:::randomarcs( n ) + + p = boundaryfromarcs( arcmat, gapmin=-Inf ) + + bvalue[i] = polarzonoid:::boundaryfunction( p ) + } + + ran = range(bvalue) + cat( "n =", n, " bvalue range = ", ran, '\n', file=stderr() ) + + if( tol < max( abs(ran) ) ) + { + mask = tol < abs(bvalue) + + mess = sprintf( "ERR. testboundaryvalue(). n=%d. %d of %d boundary values are invalid.\n", + n, sum(mask), length(mask) ) + cat( mess, file=stderr() ) + + return(FALSE) + } + + return(TRUE) + } > > > # n number of arcs, this does not work if n==0 > # > # return TRUE or FALSE > > testboundarynormal <- function( n, count=1000, tol=5.e-12 ) + { + set.seed(0) + + delta = numeric(count) + + for( i in 1:count ) + { + arcmat = polarzonoid:::randomarcs( n ) + + p = boundaryfromarcs( arcmat, gapmin=-Inf ) + + # find normal using implicitization + normal_imp = polarzonoid:::boundarynormal( p ) + + # find normal using SVD + theta = polarzonoid:::endpointsfromarcs( arcmat ) + + normal_svd = polarzonoid:::supportingnormal( theta, p ) + + delta[i] = max( abs(normal_imp - normal_svd) ) + } + + maxdelta = max(delta) + + cat( "n =", n, " boundary normal max(delta) = ", maxdelta, '\n', file=stderr() ) + + + if( tol < maxdelta ) + { + mask = tol < delta + + mess = sprintf( "ERR. testboundarynormal(). n=%d. %d of %d boundary normals are invalid. max(delta)=%g\n", + n, sum(mask), length(mask), maxdelta ) + cat( mess, file=stderr() ) + + return(FALSE) + } + + return(TRUE) + } > > > if( ! testboundaryvalue(0,count=10) ) stop( "testboundaryvalue(0) failed !" ) n = 0 bvalue range = 0 0 > > if( ! testboundaryvalue(1) ) stop( "testboundaryvalue(1) failed !" ) n = 1 bvalue range = -1.110223e-15 1.221245e-15 > > if( ! testboundaryvalue(2) ) stop( "testboundaryvalue(2) failed !" ) n = 2 bvalue range = -4.551914e-15 3.663736e-15 > > if( ! testboundaryvalue(3,tol=5.e-12) ) stop( "testboundaryvalue(3) failed !" ) n = 3 bvalue range = -1.474376e-13 1.272316e-13 > > > > if( ! testboundarynormal(1) ) stop( "testboundarynormal(1) failed !" ) n = 1 boundary normal max(delta) = 1.174061e-14 > > if( ! testboundarynormal(2) ) stop( "testboundarynormal(2) failed !" ) n = 2 boundary normal max(delta) = 2.419176e-13 > > if( ! testboundarynormal(3,tol=5.e-10) ) stop( "testboundarynormal(3,tol=5.e-10) failed !" ) n = 3 boundary normal max(delta) = 7.588247e-11 > > > cat( "Passed all boundary tests !\n", file=stderr() ) Passed all boundary tests ! > > proc.time() user system elapsed 2.84 0.10 2.96