src/ui/scenic/lib/input/tests/coordinate_transform_test.cc
// In this test we set up a view, apply a ClipSpaceTransform scale to the camera as well as a
// translation on the view holder, and confirm that the delivered coordinates are correctly
// transformed.
//
// Below are ASCII diagrams showing the scene setup.
// Each character is a point on a surface, the top left point representing (0,0)
// and the bottom right (5,5).
// Note that the notated X,Y coordinate system is the screen coordinate system. The view's
// coordinate system has its origin at corner '1'.
//
// Scene pre-transformation (1,2,3,4 denote the corners of the view):
// Note that the view's coordinate system is the same as the screen coordinate system.
//   X ->
// Y 1 O O O O 2 - - - -
// | O O O O O O - - - -
// v O O O O O O - - - -
//   O O O O O O - - - -
//   O O O O O O - - - -
//   4 O O O O 3 - - - -
//   - - - - - - - - - -
//   - - - - - - - - - -
//   - - - - - - - - - -
//   - - - - - - - - - -
//
// Scene after post-clip space transform, pre-translation:
// 1   O   O   O   O   2
//
// O   O   O   O   O   O
//
// O   O   O   O   O   O
//           - - - - - - - - - -
// O   O   O - O - O - O - - - -
//           - - - - - - - - - -
// O   O   O - O - O - O - - - -
//           - - - - - - - - - -
// 4   O   O - O - O - 3 - - - -
//           - - - - - - - - - -
//           - - - - - - - - - -
//           - - - - - - - - - -
//           - - - - - - - - - -
//
// Scene after post-clip space transform, post-translation:
// Size of view is effectively 10x10, translated by (1,1).
// 1   O   O   O   O   2
//
// O   O   O   O   O   O
//       A - - - D - - - - -
// O   O - O - O - O - O - -
//       - - - - - - - - - -
// O   O - O - O - O - O - -
//       U - - - M - - - - -
// O   O - O - O - O - O - -
//       - - - - - - - - - -
// 4   O - O - O - O - 3 - -
//       - - - - - - - - - -
//       - - - - - - - - - -
//
// A - Add event
// D - Down event
// M - Move event
// U - Up event
In this test we set up a view, apply a ClipSpaceTransform scale to the camera as well as a
translation on the view holder, and confirm that the delivered coordinates are correctly
transformed.

Below are ASCII diagrams showing the scene setup.
Each character is a point on a surface, the top left point representing (0,0)
and the bottom right (5,5).
Note that the notated X,Y coordinate system is the screen coordinate system. The view's
coordinate system has its origin at corner '1'.

Scene pre-transformation (1,2,3,4 denote the corners of the view):
Note that the view's coordinate system is the same as the screen coordinate system.

Scene after post-clip space transform, pre-translation:
1   O   O   O   O   2





Scene after post-clip space transform, post-translation:
Size of view is effectively 10x10, translated by (1,1).




In this test we set up a view apply a ClipSpaceTransform scale to the camera as well as a translation on the view holder and confirm that the delivered coordinates are correctly transformed . Below are ASCII diagrams showing the scene setup . Each character is a point on a surface the top left point representing ( 0 0 ) and the bottom right ( 5 5 ) . Note that the notated X Y coordinate system is the screen coordinate system . The view ' s coordinate system has its origin at corner ' 1 ' . Scene pre - transformation ( 1 2 3 4 denote the corners of the view ) : Note that the view ' s coordinate system is the same as the screen coordinate system . Scene after post - clip space transform pre - translation : 1 O O O O 2 Scene after post - clip space transform post - translation : Size of view is effectively 10x10 translated by ( 1 1 ) .
TEST_F(CoordinateTransformTest, ClipSpaceAndNodeTransformed) {
  auto [view_token, view_holder_token] = scenic::ViewTokenPair::New();
  auto [root_session, root_resources] = CreateScene();
  {
    scenic::Session* const session = root_session.session();
    scenic::Scene* const scene = &root_resources.scene;
    scenic::ViewHolder view_holder(session, std::move(view_holder_token), "view_holder");
    view_holder.SetViewProperties(k5x5x1);
    scene->AddChild(view_holder);
    root_resources.camera.SetClipSpaceTransform(0, 0,  2);
    view_holder.SetTranslation(1, 1, 0);
    RequestToPresent(session);
  }
  SessionWrapper client = CreateClient("view", std::move(view_token));
  {
    scenic::Session* session = root_session.session();
    PointerCommandGenerator pointer(root_resources.compositor.id(),  1,
                                     1, PointerEventType::TOUCH);
    session->Enqueue(pointer.Add(0.5, 0.5));
    session->Enqueue(pointer.Down(4.5, 0.5));
    session->Enqueue(pointer.Move(4.5, 4.5));
    session->Enqueue(pointer.Up(0.5, 4.5));
  }
  RunLoopUntilIdle();
  {  
    const std::vector<InputEvent>& events = client.events();
    EXPECT_EQ(events.size(), 5u);
    EXPECT_TRUE(events[0].is_pointer());
    EXPECT_TRUE(PointerMatches(events[0].pointer(), 1u, PointerEventPhase::ADD, 2.5 - 1, 2.5 - 1));
    EXPECT_TRUE(events[2].is_pointer());
    EXPECT_TRUE(PointerMatches(events[2].pointer(), 1u, PointerEventPhase::DOWN, 4.5 - 1, 2.5 - 1));
    EXPECT_TRUE(events[3].is_pointer());
    EXPECT_TRUE(PointerMatches(events[3].pointer(), 1u, PointerEventPhase::MOVE, 4.5 - 1, 4.5 - 1));
    EXPECT_TRUE(events[4].is_pointer());
    EXPECT_TRUE(PointerMatches(events[4].pointer(), 1u, PointerEventPhase::UP, 2.5 - 1, 4.5 - 1));
  }
}
TEST_F ( CoordinateTransformTest , ClipSpaceAndNodeTransformed ) { auto [ view_token , view_holder_token ] = scenic :: ViewTokenPair :: New ( ) ; auto [ root_session , root_resources ] = CreateScene ( ) ; { scenic :: Session * const session = root_session . session ( ) ; scenic :: Scene * const scene = & root_resources . scene ; scenic :: ViewHolder view_holder ( session , std :: move ( view_holder_token ) , " " ) ; view_holder . SetViewProperties ( k5x5x1 ) ; scene -> AddChild ( view_holder ) ; root_resources . camera . SetClipSpaceTransform ( 0 , 0 , 2 ) ; view_holder . SetTranslation ( 1 , 1 , 0 ) ; RequestToPresent ( session ) ; } SessionWrapper client = CreateClient ( " " , std :: move ( view_token ) ) ; { scenic :: Session * session = root_session . session ( ) ; PointerCommandGenerator pointer ( root_resources . compositor . id ( ) , 1 , 1 , PointerEventType :: TOUCH ) ; session -> Enqueue ( pointer . Add ( 0.5 , 0.5 ) ) ; session -> Enqueue ( pointer . Down ( 4.5 , 0.5 ) ) ; session -> Enqueue ( pointer . Move ( 4.5 , 4.5 ) ) ; session -> Enqueue ( pointer . Up ( 0.5 , 4.5 ) ) ; } RunLoopUntilIdle ( ) ; { const std :: vector < InputEvent > & events = client . events ( ) ; EXPECT_EQ ( events . size ( ) , 5u ) ; EXPECT_TRUE ( events [ 0 ] . is_pointer ( ) ) ; EXPECT_TRUE ( PointerMatches ( events [ 0 ] . pointer ( ) , 1u , PointerEventPhase :: ADD , 2.5 - 1 , 2.5 - 1 ) ) ; EXPECT_TRUE ( events [ 2 ] . is_pointer ( ) ) ; EXPECT_TRUE ( PointerMatches ( events [ 2 ] . pointer ( ) , 1u , PointerEventPhase :: DOWN , 4.5 - 1 , 2.5 - 1 ) ) ; EXPECT_TRUE ( events [ 3 ] . is_pointer ( ) ) ; EXPECT_TRUE ( PointerMatches ( events [ 3 ] . pointer ( ) , 1u , PointerEventPhase :: MOVE , 4.5 - 1 , 4.5 - 1 ) ) ; EXPECT_TRUE ( events [ 4 ] . is_pointer ( ) ) ; EXPECT_TRUE ( PointerMatches ( events [ 4 ] . pointer ( ) , 1u , PointerEventPhase :: UP , 2.5 - 1 , 4.5 - 1 ) ) ; } }
In this test we set up a view, apply a ClipSpaceTransform scale to the camera as well as a
translation on the view holder, and confirm that the delivered coordinates are correctly
transformed.
In this test we set up a view apply a ClipSpaceTransform scale to the camera as well as a translation on the view holder and confirm that the delivered coordinates are correctly transformed .
// Set the clip space transform to zoom in on the center of the screen. /*scale*/ // Translate view holder. // Client vends a View to the global scene. // Scene is now set up, send in the input. One event for where each corner of the view was // pre-transformation. Injected events are in the screen coordinate space. /*device id*/ /*pointer id*/ // Received events should be in the coordinate space of the view.