4242// Standard headers.
4343#include < cstddef>
4444#include < limits>
45+ #include < vector>
4546
4647using namespace foundation ;
4748using namespace std ;
@@ -68,8 +69,8 @@ TEST_SUITE(Foundation_Math_BezierCurveIntersector)
6869 typedef RayInfo<ValueType, 3 > RayInfoType;
6970 typedef BezierCurveIntersector<BezierCurveType> BezierCurveIntersectorType;
7071
71- const size_t ImageWidth = 500 ;
72- const size_t ImageHeight = 500 ;
72+ const size_t ImageWidth = 512 ;
73+ const size_t ImageHeight = 512 ;
7374
7475 const ValueType RcpImageWidth = ValueType (1.0 ) / ImageWidth;
7576 const ValueType RcpImageHeight = ValueType (1.0 ) / ImageHeight;
@@ -82,7 +83,7 @@ TEST_SUITE(Foundation_Math_BezierCurveIntersector)
8283 {
8384 Color3f color (0 .0f );
8485
85- // Compute the coordinates of the center of the pixel.
86+ // Compute the normalized coordinates of the center of the pixel in [-1,1]^2 .
8687 const ValueType pix_x = (ValueType (2.0 ) * x + ValueType (1.0 )) * RcpImageWidth - ValueType (1.0 );
8788 const ValueType pix_y = ValueType (1.0 ) - (ValueType (2.0 ) * y + ValueType (1.0 )) * RcpImageHeight;
8889
@@ -283,7 +284,7 @@ TEST_SUITE(Foundation_Math_BezierCurveIntersector)
283284 // Check continuity across connected Bezier curves.
284285 //
285286
286- TEST_CASE (RenderMultipleBezier1Curves )
287+ TEST_CASE (RenderTwoConnectedBezier1Curves )
287288 {
288289 const Vector3f ControlPoints1[] = { Vector3f (-0 .5f , -0 .5f , 0 .0f ), Vector3f (0 .0f , 0 .0f , 0 .0f ) };
289290 const Vector3f ControlPoints2[] = { Vector3f (0 .0f , 0 .0f , 0 .0f ), Vector3f (0 .5f , 0 .5f , 0 .0f ) };
@@ -293,10 +294,10 @@ TEST_SUITE(Foundation_Math_BezierCurveIntersector)
293294 BezierCurve1f (ControlPoints2, 0 .06f )
294295 };
295296
296- render_curves_to_image (Curves, countof (Curves), " unit tests/outputs/test_beziercurveintersector_multiplebezier1curves .png" , false );
297+ render_curves_to_image (Curves, countof (Curves), " unit tests/outputs/test_beziercurveintersector_twoconnectedbezier1curves .png" , false );
297298 }
298299
299- TEST_CASE (RenderMultipleBezier1Curves_VariableWidth )
300+ TEST_CASE (RenderTwoConnectedBezier1Curves_VariableWidth )
300301 {
301302 const Vector3f ControlPoints1[] = { Vector3f (-0 .5f , -0 .5f , 0 .0f ), Vector3f (0 .0f , 0 .0f , 0 .0f ) };
302303 const Vector3f ControlPoints2[] = { Vector3f (0 .0f , 0 .0f , 0 .0f ), Vector3f (0 .5f , 0 .5f , 0 .0f ) };
@@ -308,10 +309,10 @@ TEST_SUITE(Foundation_Math_BezierCurveIntersector)
308309 BezierCurve1f (ControlPoints2, Widths2)
309310 };
310311
311- render_curves_to_image (Curves, countof (Curves), " unit tests/outputs/test_beziercurveintersector_multiplebezier1curves_variablewidth .png" , false );
312+ render_curves_to_image (Curves, countof (Curves), " unit tests/outputs/test_beziercurveintersector_twoconnectedbezier1curves_variablewidth .png" , false );
312313 }
313314
314- TEST_CASE (RenderMultipleBezier2Curves )
315+ TEST_CASE (RenderTwoConnectedBezier2Curves )
315316 {
316317 const Vector3f ControlPoints1[] = { Vector3f (-0 .7f , 0 .0f , 0 .0f ), Vector3f (-0 .4f , 0 .5f , 0 .0f ), Vector3f (0 .0f , 0 .0f , 0 .0f ) };
317318 const Vector3f ControlPoints2[] = { Vector3f (0 .0f , 0 .0f , 0 .0f ), Vector3f (0 .4f , -0 .5f , 0 .0f ), Vector3f (0 .7f , 0 .0f , 0 .0f ) };
@@ -321,10 +322,10 @@ TEST_SUITE(Foundation_Math_BezierCurveIntersector)
321322 BezierCurve2f (ControlPoints2, 0 .06f )
322323 };
323324
324- render_curves_to_image (Curves, countof (Curves), " unit tests/outputs/test_beziercurveintersector_multiplebezier2curves .png" , false );
325+ render_curves_to_image (Curves, countof (Curves), " unit tests/outputs/test_beziercurveintersector_twoconnectedbezier2curves .png" , false );
325326 }
326327
327- TEST_CASE (RenderMultipleBezier2Curves_VariableWidth )
328+ TEST_CASE (RenderTwoConnectedBezier2Curves_VariableWidth )
328329 {
329330 const Vector3f ControlPoints1[] = { Vector3f (-0 .7f , 0 .0f , 0 .0f ), Vector3f (-0 .4f , 0 .5f , 0 .0f ), Vector3f (0 .0f , 0 .0f , 0 .0f ) };
330331 const Vector3f ControlPoints2[] = { Vector3f (0 .0f , 0 .0f , 0 .0f ), Vector3f (0 .4f , -0 .5f , 0 .0f ), Vector3f (0 .7f , 0 .0f , 0 .0f ) };
@@ -335,10 +336,10 @@ TEST_SUITE(Foundation_Math_BezierCurveIntersector)
335336 BezierCurve2f (ControlPoints2, Widths)
336337 };
337338
338- render_curves_to_image (Curves, countof (Curves), " unit tests/outputs/test_beziercurveintersector_multiplebezier2curves_variablewidth .png" , false );
339+ render_curves_to_image (Curves, countof (Curves), " unit tests/outputs/test_beziercurveintersector_twoconnectedbezier2curves_variablewidth .png" , false );
339340 }
340341
341- TEST_CASE (RenderMultipleBezier3Curves )
342+ TEST_CASE (RenderTwoConnectedBezier3Curves )
342343 {
343344 const Vector3f ControlPoints1[] = { Vector3f (-0 .7f , 0 .0f , 0 .0f ), Vector3f (-0 .2f , 0 .5f , 0 .0f ), Vector3f (-0 .5f , -0 .5f , 0 .0f ), Vector3f (0 .0f , 0 .0f , 0 .0f ) };
344345 const Vector3f ControlPoints2[] = { Vector3f (0 .0f , 0 .0f , 0 .0f ), Vector3f (0 .5f , 0 .5f , 0 .0f ), Vector3f (0 .2f , -0 .5f , 0 .0f ), Vector3f (0 .7f , 0 .0f , 0 .0f ) };
@@ -348,10 +349,10 @@ TEST_SUITE(Foundation_Math_BezierCurveIntersector)
348349 BezierCurve3f (ControlPoints2, 0 .06f )
349350 };
350351
351- render_curves_to_image (Curves, countof (Curves), " unit tests/outputs/test_beziercurveintersector_multiplebezier3curves .png" , false );
352+ render_curves_to_image (Curves, countof (Curves), " unit tests/outputs/test_beziercurveintersector_twoconnectedbezier3curves .png" , false );
352353 }
353354
354- TEST_CASE (RenderMultipleBezier3Curves_VariableWidth )
355+ TEST_CASE (RenderTwoConnectedBezier3Curves_VariableWidth )
355356 {
356357 const Vector3f ControlPoints1[] = { Vector3f (-0 .7f , 0 .0f , 0 .0f ), Vector3f (-0 .2f , 0 .5f , 0 .0f ), Vector3f (-0 .5f , -0 .5f , 0 .0f ), Vector3f (0 .0f , 0 .0f , 0 .0f ) };
357358 const Vector3f ControlPoints2[] = { Vector3f (0 .0f , 0 .0f , 0 .0f ), Vector3f (0 .5f , 0 .5f , 0 .0f ), Vector3f (0 .2f , -0 .5f , 0 .0f ), Vector3f (0 .7f , 0 .0f , 0 .0f ) };
@@ -362,7 +363,47 @@ TEST_SUITE(Foundation_Math_BezierCurveIntersector)
362363 BezierCurve3f (ControlPoints2, Widths)
363364 };
364365
365- render_curves_to_image (Curves, countof (Curves), " unit tests/outputs/test_beziercurveintersector_multiplebezier3curves_variablewidth.png" , false );
366+ render_curves_to_image (Curves, countof (Curves), " unit tests/outputs/test_beziercurveintersector_twoconnectedbezier3curves_variablewidth.png" , false );
367+ }
368+
369+ TEST_CASE (RenderMultipleBezier3Curves)
370+ {
371+ const Vector3f ControlPoints[] =
372+ {
373+ Vector3f (-0 .827751f , -0 .269373f , 0 .0f ),
374+ Vector3f (-0 .614035f , 0 .557196f , 0 .0f ),
375+ Vector3f (-0 .298246f , -0 .505535f , 0 .0f ),
376+ Vector3f (-0 .094099f , 0 .586716f , 0 .0f ),
377+ Vector3f ( 0 .199362f , -0 .173432f , 0 .0f ),
378+ Vector3f ( 0 .416268f , 0 .704797f , 0 .0f ),
379+ Vector3f ( 0 .642743f , -0 .682657f , 0 .0f ),
380+ Vector3f ( 0 .897927f , 0 .468635f , 0 .0f )
381+ };
382+
383+ //
384+ // Create a new set of control points by adding midpoints between every other pairs
385+ // of control points. See http://stackoverflow.com/a/3516110/393756 for details.
386+ //
387+
388+ vector<Vector3f> new_points;
389+
390+ for (size_t i = 0 ; i < countof (ControlPoints); ++i)
391+ {
392+ new_points.push_back (ControlPoints[i]);
393+
394+ if (i > 0 && i % 2 == 0 && i + 1 < countof (ControlPoints))
395+ {
396+ // Add a midpoint.
397+ new_points.push_back (0 .5f * (ControlPoints[i] + ControlPoints[i + 1 ]));
398+ }
399+ }
400+
401+ vector<BezierCurve3f> curves;
402+
403+ for (size_t i = 0 , e = new_points.size (); i + 3 < e; i += 3 )
404+ curves.push_back (BezierCurve3f (&new_points[i], 0 .05f ));
405+
406+ render_curves_to_image (&curves[0 ], curves.size (), " unit tests/outputs/test_beziercurveintersector_multiplebezier3curves.png" , false );
366407 }
367408
368409
0 commit comments