test/convex_polygon_test.cpp
// Helper for a polygon that is expected to split into 2 pieces
Helper for a polygon that is expected to split into 2 pieces
Helper for a polygon that is expected to split into 2 pieces
void SplitHelper(MutableConvexPolygon<>&& polygon,
                 const HalfSpace3& half_space,
                 MutableConvexPolygon<>& neg_side,
                 MutableConvexPolygon<>& pos_side) {
  auto info = polygon.GetSplitInfo(half_space);
  ASSERT_TRUE(info.ShouldEmitNegativeChild());
  ASSERT_TRUE(info.ShouldEmitPositiveChild());
  std::pair<ConvexPolygon<>, ConvexPolygon<>> children =
    ConvexPolygon<>::CreateSplitChildren(std::move(polygon).GetRValueKey(),
                                         std::move(info));
  neg_side = std::move(children.first);
  pos_side = std::move(children.second);
  ASSERT_GE(neg_side.vertex_count(), 3);
  EXPECT_TRUE(half_space.IsCoincident(neg_side.vertex(
          neg_side.vertex_count() - 2)));
  EXPECT_TRUE(half_space.IsCoincident(neg_side.vertex(
          neg_side.vertex_count() - 1)));
  for (size_t i = 0; i < neg_side.vertex_count() - 2; ++i) {
    EXPECT_FALSE(half_space.IsCoincident(neg_side.vertex(i)));
  }
  ASSERT_GE(pos_side.vertex_count(), 3);
  EXPECT_TRUE(half_space.IsCoincident(pos_side.vertex(0)));
  EXPECT_TRUE(half_space.IsCoincident(pos_side.vertex(
          pos_side.vertex_count() - 1)));
  for (size_t i = 1; i < pos_side.vertex_count() - 1; ++i) {
    EXPECT_FALSE(half_space.IsCoincident(pos_side.vertex(i)));
  }
  for (const ConvexPolygon<>* output : {&neg_side, &pos_side}) {
    for (size_t i = 0; i < output->vertex_count(); ++i) {
      PluckerLine expected_line(
          output->vertex(i), output->vertex((i + 1) % output->vertex_count()));
      EXPECT_EQ(output->const_edge(i).line(), expected_line);
      EXPECT_TRUE(
          output->const_edge(i).line().d().IsSameDir(expected_line.d()));
    }
  }
}
void SplitHelper ( MutableConvexPolygon < > && polygon , const HalfSpace3 & half_space , MutableConvexPolygon < > & neg_side , MutableConvexPolygon < > & pos_side ) { auto info = polygon . GetSplitInfo ( half_space ) ; ASSERT_TRUE ( info . ShouldEmitNegativeChild ( ) ) ; ASSERT_TRUE ( info . ShouldEmitPositiveChild ( ) ) ; std :: pair < ConvexPolygon < > , ConvexPolygon < > > children = ConvexPolygon < > :: CreateSplitChildren ( std :: move ( polygon ) . GetRValueKey ( ) , std :: move ( info ) ) ; neg_side = std :: move ( children . first ) ; pos_side = std :: move ( children . second ) ; ASSERT_GE ( neg_side . vertex_count ( ) , 3 ) ; EXPECT_TRUE ( half_space . IsCoincident ( neg_side . vertex ( neg_side . vertex_count ( ) - 2 ) ) ) ; EXPECT_TRUE ( half_space . IsCoincident ( neg_side . vertex ( neg_side . vertex_count ( ) - 1 ) ) ) ; for ( size_t i = 0 ; i < neg_side . vertex_count ( ) - 2 ; ++ i ) { EXPECT_FALSE ( half_space . IsCoincident ( neg_side . vertex ( i ) ) ) ; } ASSERT_GE ( pos_side . vertex_count ( ) , 3 ) ; EXPECT_TRUE ( half_space . IsCoincident ( pos_side . vertex ( 0 ) ) ) ; EXPECT_TRUE ( half_space . IsCoincident ( pos_side . vertex ( pos_side . vertex_count ( ) - 1 ) ) ) ; for ( size_t i = 1 ; i < pos_side . vertex_count ( ) - 1 ; ++ i ) { EXPECT_FALSE ( half_space . IsCoincident ( pos_side . vertex ( i ) ) ) ; } for ( const ConvexPolygon < > * output : { & neg_side , & pos_side } ) { for ( size_t i = 0 ; i < output -> vertex_count ( ) ; ++ i ) { PluckerLine expected_line ( output -> vertex ( i ) , output -> vertex ( ( i + 1 ) % output -> vertex_count ( ) ) ) ; EXPECT_EQ ( output -> const_edge ( i ) . line ( ) , expected_line ) ; EXPECT_TRUE ( output -> const_edge ( i ) . line ( ) . d ( ) . IsSameDir ( expected_line . d ( ) ) ) ; } } }
Helper for a polygon that is expected to split into 2 pieces
Helper for a polygon that is expected to split into 2 pieces