src/ui/scenic/lib/input/tests/coordinate_transform_test.cc
// This test verifies that rotation is handled correctly when events are delivered to clients.
//
// 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'.
//
// View pre-transformation (1,2,3,4 denote corners of 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 - - - -
//   - - - - - - - - - -
//   - - - - - - - - - -
//   - - - - - - - - - -
//   - - - - - - - - - -
//
// View post-transformation:
//   X ->
// Y 4A O O O O 1D- - - -
// | 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 - - - -
//   3U O O O O 2M- - - -
//   -  - - - - - - - - -
//   -  - - - - - - - - -
//   -  - - - - - - - - -
//   -  - - - - - - - - -
//
// A - Add event
// D - Down event
// M - Move event
// U - Up event
This test verifies that rotation is handled correctly when events are delivered to clients.
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'.

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




This test verifies that rotation is handled correctly when events are delivered to clients . 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 ' . View pre - transformation ( 1 2 3 4 denote corners of view ) : Note that the view ' s coordinate system is the same as the screen coordinate system .
TEST_F(CoordinateTransformTest, Rotated) {
  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);
    view_holder.SetAnchor(2.5, 2.5, 0);
    const auto rotation_quaternion = glm::angleAxis(glm::pi<float>() / 2, glm::vec3(0, 0, 1));
    view_holder.SetRotation(rotation_quaternion.x, rotation_quaternion.y, rotation_quaternion.z,
                            rotation_quaternion.w);
    RequestToPresent(session);
  }
  SessionWrapper client = CreateClient("view_1", 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, 0.5, 4.5));
    EXPECT_TRUE(events[2].is_pointer());
    EXPECT_TRUE(PointerMatches(events[2].pointer(), 1u, PointerEventPhase::DOWN, 0.5, 0.5));
    EXPECT_TRUE(events[3].is_pointer());
    EXPECT_TRUE(PointerMatches(events[3].pointer(), 1u, PointerEventPhase::MOVE, 4.5, 0.5));
    EXPECT_TRUE(events[4].is_pointer());
    EXPECT_TRUE(PointerMatches(events[4].pointer(), 1u, PointerEventPhase::UP, 4.5, 4.5));
  }
}
TEST_F ( CoordinateTransformTest , Rotated ) { 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 ) ; view_holder . SetAnchor ( 2.5 , 2.5 , 0 ) ; const auto rotation_quaternion = glm :: angleAxis ( glm :: pi < float > ( ) / 2 , glm :: vec3 ( 0 , 0 , 1 ) ) ; view_holder . SetRotation ( rotation_quaternion . x , rotation_quaternion . y , rotation_quaternion . z , rotation_quaternion . w ) ; 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 , 0.5 , 4.5 ) ) ; EXPECT_TRUE ( events [ 2 ] . is_pointer ( ) ) ; EXPECT_TRUE ( PointerMatches ( events [ 2 ] . pointer ( ) , 1u , PointerEventPhase :: DOWN , 0.5 , 0.5 ) ) ; EXPECT_TRUE ( events [ 3 ] . is_pointer ( ) ) ; EXPECT_TRUE ( PointerMatches ( events [ 3 ] . pointer ( ) , 1u , PointerEventPhase :: MOVE , 4.5 , 0.5 ) ) ; EXPECT_TRUE ( events [ 4 ] . is_pointer ( ) ) ; EXPECT_TRUE ( PointerMatches ( events [ 4 ] . pointer ( ) , 1u , PointerEventPhase :: UP , 4.5 , 4.5 ) ) ; } }
This test verifies that rotation is handled correctly when events are delivered to clients.
This test verifies that rotation is handled correctly when events are delivered to clients .
// Rotate the view holder 90 degrees counter-clockwise around the z-axis (which points into // screen, so the rotation appears clockwise). // 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 global coordinate space. /*device id*/ /*pointer id*/ // Received events should be in the coordinate space of the view.