@@ -2766,4 +2766,127 @@ fn swizzle() {
27662766 let mut v4x = vec4f ( 2.0 , 2.0 , 2.0 , 2.0 ) ;
27672767 v4x. set_yxzw ( v4) ;
27682768 assert_eq ! ( v4x, vec4f( 7.0 , 8.0 , 5.0 , 3.0 ) ) ;
2769+ }
2770+
2771+ #[ test]
2772+ fn cone_vs_plane_test ( ) {
2773+ // use a simple plane at 0,0,0 +z
2774+ let x = Vec3f :: zero ( ) ;
2775+ let n = Vec3f :: unit_z ( ) ;
2776+
2777+ // behind
2778+ /*
2779+ +z
2780+ ^
2781+ |
2782+ --------------------- +x (0, 0, 0)
2783+ cp2 (5,-1)
2784+ cp1 (0,-5)
2785+ */
2786+
2787+ let cp1 = Vec3f :: new ( 0.0 , 0.0 , -5.0 ) ;
2788+ let cp2 = Vec3f :: new ( 5.0 , 0.0 , -1.0 ) ;
2789+ let r = 4.0 ;
2790+ let cv = normalize ( cp2-cp1) ;
2791+ let h = dist ( cp1, cp2) ;
2792+ assert_eq ! ( cone_vs_plane( cp1, cv, h, r, x, n) , Classification :: Behind ) ;
2793+
2794+ // infront
2795+ /*
2796+ +z
2797+ ^ cp2 (2,2)
2798+ | cp1 (1,1)
2799+ --------------------- +x (0, 0, 0)
2800+ */
2801+
2802+ let cp1 = Vec3f :: new ( 1.0 , 0.0 , 1.0 ) ;
2803+ let cp2 = Vec3f :: new ( 2.0 , 0.0 , 2.0 ) ;
2804+ let r = 0.5 ;
2805+ let cv = normalize ( cp2-cp1) ;
2806+ let h = dist ( cp1, cp2) ;
2807+ assert_eq ! ( cone_vs_plane( cp1, cv, h, r, x, n) , Classification :: Infront ) ;
2808+
2809+
2810+ // intersect fully through the line seg
2811+ /*
2812+ +z
2813+ ^ cp2 (5,5)
2814+ |
2815+ --------------------- +x (0, 0, 0)
2816+
2817+ cp1 (0,-1)
2818+ */
2819+
2820+ let cp1 = Vec3f :: new ( 0.0 , 0.0 , -1.0 ) ;
2821+ let cp2 = Vec3f :: new ( 5.0 , 0.0 , 5.0 ) ;
2822+ let r = 4.0 ;
2823+ let cv = normalize ( cp2-cp1) ;
2824+ let h = dist ( cp1, cp2) ;
2825+ assert_eq ! ( cone_vs_plane( cp1, cv, h, r, x, n) , Classification :: Intersects ) ;
2826+
2827+ // intersect the base on the right side
2828+ /*
2829+ +z
2830+ ^
2831+ |
2832+ --------------------- +x (0, 0, 0)
2833+ cp1 (5, -1)
2834+
2835+ cp2 (0,-5)
2836+ */
2837+
2838+ let cp1 = Vec3f :: new ( 5.0 , 0.0 , -1.0 ) ;
2839+ let cp2 = Vec3f :: new ( 0.0 , 0.0 , -5.0 ) ;
2840+ let r = 10.0 ;
2841+ let cv = normalize ( cp2-cp1) ;
2842+ let h = dist ( cp1, cp2) ;
2843+ assert_eq ! ( cone_vs_plane( cp1, cv, h, r, x, n) , Classification :: Intersects ) ;
2844+
2845+ // intersect the base on the left side
2846+ /*
2847+ +z
2848+ ^
2849+ |
2850+ --------------------- +x (0, 0, 0)
2851+ cp1 (5, -1)
2852+
2853+ cp1 (10,-5)
2854+ */
2855+
2856+ let cp1 = Vec3f :: new ( 5.0 , 0.0 , -1.0 ) ;
2857+ let cp2 = Vec3f :: new ( 10.0 , 0.0 , -5.0 ) ;
2858+ let r = 100.0 ;
2859+ let cv = normalize ( cp2-cp1) ;
2860+ let h = dist ( cp1, cp2) ;
2861+ assert_eq ! ( cone_vs_plane( cp1, cv, h, r, x, n) , Classification :: Intersects ) ;
2862+
2863+ // intersect the base on the right side
2864+ /*
2865+ cp2 (0,5)
2866+
2867+ cp1 (5, 1)
2868+ --------------------- +x (0, 0, 0)
2869+ */
2870+
2871+ let cp1 = Vec3f :: new ( 5.0 , 0.0 , 1.0 ) ;
2872+ let cp2 = Vec3f :: new ( 0.0 , 0.0 , 5.0 ) ;
2873+ let r = 10.0 ;
2874+ let cv = normalize ( cp2-cp1) ;
2875+ let h = dist ( cp1, cp2) ;
2876+ assert_eq ! ( cone_vs_plane( cp1, cv, h, r, x, n) , Classification :: Intersects ) ;
2877+
2878+ // intersect the base on the left side
2879+ /*
2880+ cp1 (10,5)
2881+
2882+ cp1 (5, 1)
2883+ --------------------- +x (0, 0, 0)
2884+ */
2885+
2886+ let cp1 = Vec3f :: new ( 5.0 , 0.0 , 1.0 ) ;
2887+ let cp2 = Vec3f :: new ( 10.0 , 0.0 , 5.0 ) ;
2888+ let r = 100.0 ;
2889+ let cv = normalize ( cp2-cp1) ;
2890+ let h = dist ( cp1, cp2) ;
2891+ assert_eq ! ( cone_vs_plane( cp1, cv, h, r, x, n) , Classification :: Intersects ) ;
27692892}
0 commit comments