src/ui/scenic/lib/flatland/tests/flatland_unittest.cc
// Test that changing geometric transform properties affects the global matrix of child Transforms.
Test that changing geometric transform properties affects the global matrix of child Transforms.
Test that changing geometric transform properties affects the global matrix of child Transforms .
TEST_F(FlatlandTest, SetGeometricTransformProperties) {
  Flatland parent = CreateFlatland();
  Flatland child = CreateFlatland();
  const ContentId kLinkId1 = 1;
  fidl::InterfacePtr<ContentLink> content_link;
  fidl::InterfacePtr<GraphLink> graph_link;
  CreateLink(&parent, &child, kLinkId1, &content_link, &graph_link);
  RunLoopUntilIdle();
  const TransformId kId1 = 1;
  const TransformId kId2 = 2;
  parent.CreateTransform(kId1);
  parent.CreateTransform(kId2);
  parent.SetRootTransform(kId1);
  parent.AddChild(kId1, kId2);
  parent.SetContentOnTransform(kLinkId1, kId2);
  PRESENT(parent, true);
  auto data = ProcessMainLoop(parent.GetRoot());
  EXPECT_MATRIX(data.topology_data, data.matrix_vector, child.GetRoot(), glm::mat3());
  parent.SetScale(kId2, {2.f, 3.f});
  parent.SetTranslation(kId1, {1.f, 2.f});
  PRESENT(parent, true);
  glm::mat3 expected_matrix = glm::mat3();
  expected_matrix = glm::translate(expected_matrix, {1.f, 2.f});
  expected_matrix = glm::scale(expected_matrix, {2.f, 3.f});
  data = ProcessMainLoop(parent.GetRoot());
  EXPECT_MATRIX(data.topology_data, data.matrix_vector, child.GetRoot(), expected_matrix);
  parent.SetOrientation(kId1, Orientation::CCW_90_DEGREES);
  parent.SetScale(kId1, {4.f, 5.f});
  parent.SetTranslation(kId2, {6.f, 7.f});
  parent.SetOrientation(kId2, Orientation::CCW_270_DEGREES);
  PRESENT(parent, true);
  expected_matrix = glm::mat3();
  expected_matrix = glm::translate(expected_matrix, {1.f, 2.f});
  expected_matrix = glm::rotate(expected_matrix, GetOrientationAngle(Orientation::CCW_90_DEGREES));
  expected_matrix = glm::scale(expected_matrix, {4.f, 5.f});
  expected_matrix = glm::translate(expected_matrix, {6.f, 7.f});
  expected_matrix = glm::rotate(expected_matrix, GetOrientationAngle(Orientation::CCW_270_DEGREES));
  expected_matrix = glm::scale(expected_matrix, {2.f, 3.f});
  data = ProcessMainLoop(parent.GetRoot());
  EXPECT_MATRIX(data.topology_data, data.matrix_vector, child.GetRoot(), expected_matrix);
  parent.ReleaseTransform(kId2);
  PRESENT(parent, true);
  data = ProcessMainLoop(parent.GetRoot());
  EXPECT_MATRIX(data.topology_data, data.matrix_vector, child.GetRoot(), expected_matrix);
}
TEST_F ( FlatlandTest , SetGeometricTransformProperties ) { Flatland parent = CreateFlatland ( ) ; Flatland child = CreateFlatland ( ) ; const ContentId kLinkId1 = 1 ; fidl :: InterfacePtr < ContentLink > content_link ; fidl :: InterfacePtr < GraphLink > graph_link ; CreateLink ( & parent , & child , kLinkId1 , & content_link , & graph_link ) ; RunLoopUntilIdle ( ) ; const TransformId kId1 = 1 ; const TransformId kId2 = 2 ; parent . CreateTransform ( kId1 ) ; parent . CreateTransform ( kId2 ) ; parent . SetRootTransform ( kId1 ) ; parent . AddChild ( kId1 , kId2 ) ; parent . SetContentOnTransform ( kLinkId1 , kId2 ) ; PRESENT ( parent , true ) ; auto data = ProcessMainLoop ( parent . GetRoot ( ) ) ; EXPECT_MATRIX ( data . topology_data , data . matrix_vector , child . GetRoot ( ) , glm :: mat3 ( ) ) ; parent . SetScale ( kId2 , { 2.f , 3.f } ) ; parent . SetTranslation ( kId1 , { 1.f , 2.f } ) ; PRESENT ( parent , true ) ; glm :: mat3 expected_matrix = glm :: mat3 ( ) ; expected_matrix = glm :: translate ( expected_matrix , { 1.f , 2.f } ) ; expected_matrix = glm :: scale ( expected_matrix , { 2.f , 3.f } ) ; data = ProcessMainLoop ( parent . GetRoot ( ) ) ; EXPECT_MATRIX ( data . topology_data , data . matrix_vector , child . GetRoot ( ) , expected_matrix ) ; parent . SetOrientation ( kId1 , Orientation :: CCW_90_DEGREES ) ; parent . SetScale ( kId1 , { 4.f , 5.f } ) ; parent . SetTranslation ( kId2 , { 6.f , 7.f } ) ; parent . SetOrientation ( kId2 , Orientation :: CCW_270_DEGREES ) ; PRESENT ( parent , true ) ; expected_matrix = glm :: mat3 ( ) ; expected_matrix = glm :: translate ( expected_matrix , { 1.f , 2.f } ) ; expected_matrix = glm :: rotate ( expected_matrix , GetOrientationAngle ( Orientation :: CCW_90_DEGREES ) ) ; expected_matrix = glm :: scale ( expected_matrix , { 4.f , 5.f } ) ; expected_matrix = glm :: translate ( expected_matrix , { 6.f , 7.f } ) ; expected_matrix = glm :: rotate ( expected_matrix , GetOrientationAngle ( Orientation :: CCW_270_DEGREES ) ) ; expected_matrix = glm :: scale ( expected_matrix , { 2.f , 3.f } ) ; data = ProcessMainLoop ( parent . GetRoot ( ) ) ; EXPECT_MATRIX ( data . topology_data , data . matrix_vector , child . GetRoot ( ) , expected_matrix ) ; parent . ReleaseTransform ( kId2 ) ; PRESENT ( parent , true ) ; data = ProcessMainLoop ( parent . GetRoot ( ) ) ; EXPECT_MATRIX ( data . topology_data , data . matrix_vector , child . GetRoot ( ) , expected_matrix ) ; }
Test that changing geometric transform properties affects the global matrix of child Transforms.
Test that changing geometric transform properties affects the global matrix of child Transforms .
// Create two Transforms in the parent to ensure properties cascade down children. // With no properties set, the child root has an identity transform. // Set up one property per transform. Set up kId2 before kId1 to ensure the hierarchy is used. // The operations should be applied in the following order: // - Translation on kId1 // - Scale on kId2 // Fill out the remaining properties on both transforms. // The operations should be applied in the following order: // - Translation on kId1 // - Orientation on kId1 // - Scale on kId1 // - Translation on kId2 // - Orientation on kId2 // - Scale on kId2 // Ensure releasing one of the intermediate transforms does not clean up the matrix data since // it is still referenced in an active chain of Transforms.