src/ui/scenic/lib/gfx/tests/hittest_global_unittest.cc
TEST_F(SingleSessionHitTestTest, ViewClipping) {
  // Create our tokens for View/ViewHolder creation.
  auto [view_token, view_holder_token] = scenic::ViewTokenPair::New();

  CustomSession sess = CreateRootSession(1024, 768);
  {
    enum : uint32_t {
      kViewId = 15,
      kViewHolderId,
      kShapeNodeId,
      kRectId,
    };

    const int32_t pane_width = layer_width();
    const int32_t pane_height = 0.25 * layer_height();

    sess.Apply(scenic::NewCreateViewHolderCmd(kViewHolderId, std::move(view_holder_token),
                                              "MyViewHolder"));
    sess.Apply(scenic::NewCreateViewCmd(kViewId, std::move(view_token), "MyView"));

    // Set the bounding box on the view holder.
    const float bbox_min[3] = {0.f, 0.f, -2.f};
    const float bbox_max[3] = {layer_width() / 2, layer_height(), 1.f};
    const float inset_min[3] = {0, 0, 0};
    const float inset_max[3] = {0, 0, 0};
    sess.Apply(
        scenic::NewSetViewPropertiesCmd(kViewHolderId, bbox_min, bbox_max, inset_min, inset_max));

    // Create shape node and apply rectangle
    sess.Apply(scenic::NewCreateShapeNodeCmd(kShapeNodeId));
    sess.Apply(scenic::NewCreateRectangleCmd(kRectId, pane_width, pane_height));
    sess.Apply(scenic::NewSetShapeCmd(kShapeNodeId, kRectId));
    sess.Apply(scenic::NewSetTranslationCmd(
        kShapeNodeId, (float[3]){0.5f * pane_width, 0.5f * layer_height(), 0.f}));

    sess.Apply(scenic::NewAddChildCmd(kSceneId, kViewHolderId));
    sess.Apply(scenic::NewAddChildCmd(kViewId, kShapeNodeId));
  }

  // Perform two hit tests on either side of the display.
  {
    // First hit test should intersect the view's bounding box.
    TestHitAccumulator<ViewHit> accumulator;
    layer_stack()->HitTest(input::CreateScreenPerpendicularRay(5, layer_height() / 2),
                           &accumulator);
    EXPECT_EQ(accumulator.hits().size(), 1u) << "Should see a hit on the rectangle";
  }
  {
    // Second hit test should completely miss the view's bounding box.
    TestHitAccumulator<ViewHit> accumulator;
    layer_stack()->HitTest(
        input::CreateScreenPerpendicularRay(layer_width() / 2 + 50, layer_height() / 2),
        &accumulator);
    EXPECT_EQ(accumulator.hits().size(), 0u)
        << "Should see no hits since its outside the view bounds";
  }
}
// This unit test checks to make sure that geometry that is a child of
// a view is not hit by a hit-test ray if the intersection point
// with the ray lies outside of the view's bounding box.
//
// The setup is that there is a view which covers the left half of the
// display with a rectangle that goes across the entire width of the
// display from left to right, and thus extends beyond the bounds of
// its view. Two hit tests are performed on the rectangle, one inside
// the view bounds and one without. The total number of hits is then
// checked to make sure they are what we would expect.
//
// This is an ASCII representation of what the test looks like:
//
// VVVVVVVV
// rrrrrrrrrrrrrrr
// rrrrrrrrrrrrrrr
// VVVVVVVV
//
// Where "V" represents the view boundary and "r" is the extent
// of the rectangle.
This unit test checks to make sure that geometry that is a child of
a view is not hit by a hit-test ray if the intersection point
with the ray lies outside of the view's bounding box.

The setup is that there is a view which covers the left half of the
display with a rectangle that goes across the entire width of the
display from left to right, and thus extends beyond the bounds of
its view. Two hit tests are performed on the rectangle, one inside
the view bounds and one without. The total number of hits is then
checked to make sure they are what we would expect.

This is an ASCII representation of what the test looks like.




This unit test checks to make sure that geometry that is a child of a view is not hit by a hit - test ray if the intersection point with the ray lies outside of the view ' s bounding box . The setup is that there is a view which covers the left half of the display with a rectangle that goes across the entire width of the display from left to right and thus extends beyond the bounds of its view . Two hit tests are performed on the rectangle one inside the view bounds and one without . The total number of hits is then checked to make sure they are what we would expect . This is an ASCII representation of what the test looks like .
TEST_F(SingleSessionHitTestTest, ViewClipping) {
  auto [view_token, view_holder_token] = scenic::ViewTokenPair::New();
  CustomSession sess = CreateRootSession(1024, 768);
  {
    enum : uint32_t {
      kViewId = 15,
      kViewHolderId,
      kShapeNodeId,
      kRectId,
    };
    const int32_t pane_width = layer_width();
    const int32_t pane_height = 0.25 * layer_height();
    sess.Apply(scenic::NewCreateViewHolderCmd(kViewHolderId, std::move(view_holder_token),
                                              "MyViewHolder"));
    sess.Apply(scenic::NewCreateViewCmd(kViewId, std::move(view_token), "MyView"));
    const float bbox_min[3] = {0.f, 0.f, -2.f};
    const float bbox_max[3] = {layer_width() / 2, layer_height(), 1.f};
    const float inset_min[3] = {0, 0, 0};
    const float inset_max[3] = {0, 0, 0};
    sess.Apply(
        scenic::NewSetViewPropertiesCmd(kViewHolderId, bbox_min, bbox_max, inset_min, inset_max));
    sess.Apply(scenic::NewCreateShapeNodeCmd(kShapeNodeId));
    sess.Apply(scenic::NewCreateRectangleCmd(kRectId, pane_width, pane_height));
    sess.Apply(scenic::NewSetShapeCmd(kShapeNodeId, kRectId));
    sess.Apply(scenic::NewSetTranslationCmd(
        kShapeNodeId, (float[3]){0.5f * pane_width, 0.5f * layer_height(), 0.f}));
    sess.Apply(scenic::NewAddChildCmd(kSceneId, kViewHolderId));
    sess.Apply(scenic::NewAddChildCmd(kViewId, kShapeNodeId));
  }
  {
    TestHitAccumulator<ViewHit> accumulator;
    layer_stack()->HitTest(input::CreateScreenPerpendicularRay(5, layer_height() / 2),
                           &accumulator);
    EXPECT_EQ(accumulator.hits().size(), 1u) << "Should see a hit on the rectangle";
  }
  {
    TestHitAccumulator<ViewHit> accumulator;
    layer_stack()->HitTest(
        input::CreateScreenPerpendicularRay(layer_width() / 2 + 50, layer_height() / 2),
        &accumulator);
    EXPECT_EQ(accumulator.hits().size(), 0u)
        << "Should see no hits since its outside the view bounds";
  }
}
TEST_F ( SingleSessionHitTestTest , ViewClipping ) { auto [ view_token , view_holder_token ] = scenic :: ViewTokenPair :: New ( ) ; CustomSession sess = CreateRootSession ( 1024 , 768 ) ; { enum : uint32_t { kViewId = 15 , kViewHolderId , kShapeNodeId , kRectId , } ; const int32_t pane_width = layer_width ( ) ; const int32_t pane_height = 0.25 * layer_height ( ) ; sess . Apply ( scenic :: NewCreateViewHolderCmd ( kViewHolderId , std :: move ( view_holder_token ) , " " ) ) ; sess . Apply ( scenic :: NewCreateViewCmd ( kViewId , std :: move ( view_token ) , " " ) ) ; const float bbox_min [ 3 ] = { 0.f , 0.f , -2.f } ; const float bbox_max [ 3 ] = { layer_width ( ) / 2 , layer_height ( ) , 1.f } ; const float inset_min [ 3 ] = { 0 , 0 , 0 } ; const float inset_max [ 3 ] = { 0 , 0 , 0 } ; sess . Apply ( scenic :: NewSetViewPropertiesCmd ( kViewHolderId , bbox_min , bbox_max , inset_min , inset_max ) ) ; sess . Apply ( scenic :: NewCreateShapeNodeCmd ( kShapeNodeId ) ) ; sess . Apply ( scenic :: NewCreateRectangleCmd ( kRectId , pane_width , pane_height ) ) ; sess . Apply ( scenic :: NewSetShapeCmd ( kShapeNodeId , kRectId ) ) ; sess . Apply ( scenic :: NewSetTranslationCmd ( kShapeNodeId , ( float [ 3 ] ) { 0.5f * pane_width , 0.5f * layer_height ( ) , 0.f } ) ) ; sess . Apply ( scenic :: NewAddChildCmd ( kSceneId , kViewHolderId ) ) ; sess . Apply ( scenic :: NewAddChildCmd ( kViewId , kShapeNodeId ) ) ; } { TestHitAccumulator < ViewHit > accumulator ; layer_stack ( ) -> HitTest ( input :: CreateScreenPerpendicularRay ( 5 , layer_height ( ) / 2 ) , & accumulator ) ; EXPECT_EQ ( accumulator . hits ( ) . size ( ) , 1u ) << " " ; } { TestHitAccumulator < ViewHit > accumulator ; layer_stack ( ) -> HitTest ( input :: CreateScreenPerpendicularRay ( layer_width ( ) / 2 + 50 , layer_height ( ) / 2 ) , & accumulator ) ; EXPECT_EQ ( accumulator . hits ( ) . size ( ) , 0u ) << " " ; } }
This unit test checks to make sure that geometry that is a child of
a view is not hit by a hit-test ray if the intersection point
with the ray lies outside of the view's bounding box.
This unit test checks to make sure that geometry that is a child of a view is not hit by a hit - test ray if the intersection point with the ray lies outside of the view ' s bounding box .
// Create our tokens for View/ViewHolder creation. // Set the bounding box on the view holder. // Create shape node and apply rectangle // Perform two hit tests on either side of the display. // First hit test should intersect the view's bounding box. // Second hit test should completely miss the view's bounding box.