Exemplo n.º 1
0
int main ()
{
  // Construct P - a bounded rectangle that contains a rectangular hole.
  Polygon_2 outP;
  Polygon_2 holesP[1];

  outP.push_back (Point_2 (-3, -5));  outP.push_back (Point_2 (3, -5));
  outP.push_back (Point_2 (3, 5));    outP.push_back (Point_2 (-3, 5));
  holesP[0].push_back (Point_2 (-1, -3));
  holesP[0].push_back (Point_2 (-1, 3));
  holesP[0].push_back (Point_2 (1, 3));
  holesP[0].push_back (Point_2 (1, -3));

  Polygon_with_holes_2  P (outP, holesP, holesP + 1);
  std::cout << "P = "; print_polygon_with_holes (P);

  // Construct Q - a bounded rectangle that contains a rectangular hole.
  Polygon_2 outQ;
  Polygon_2 holesQ[1];

  outQ.push_back (Point_2 (-5, -3));  outQ.push_back (Point_2 (5, -3));
  outQ.push_back (Point_2 (5, 3));    outQ.push_back (Point_2 (-5, 3));
  holesQ[0].push_back (Point_2 (-3, -1));
  holesQ[0].push_back (Point_2 (-3, 1));
  holesQ[0].push_back (Point_2 (3, 1));
  holesQ[0].push_back (Point_2 (3, -1));

  Polygon_with_holes_2  Q (outQ, holesQ, holesQ + 1);
  std::cout << "Q = "; print_polygon_with_holes (Q);

  // Compute the symmetric difference of P and Q.
  Pwh_list_2 symmR;
  Pwh_list_2::const_iterator it;

  CGAL::symmetric_difference (P, Q, std::back_inserter(symmR));

  std::cout << "The symmetric difference:" << std::endl;
  for (it = symmR.begin(); it != symmR.end(); ++it) {
    std::cout << "--> ";
    print_polygon_with_holes (*it);
  }

  return 0;
}
Exemplo n.º 2
0
Polygon_2 CPElement::intersection_with_support(const Polygon_2& P) const
{
  static log4cplus::Logger logger = Logger("intersection_with_support");

  typedef std::list<Bso_polygon_with_holes_2>                   Pwh_list_2;
  Pwh_list_2                  intR;
  Pwh_list_2::const_iterator  it;

  CGAL::intersection(change_kernel<Bso_kernel>(P), change_kernel<Bso_kernel>(support()), std::back_inserter(intR));

  if (intR.size() > 1) {
    LOG4CPLUS_WARN(logger, "intersection yielded more than one component");
  }
  Polygon_with_holes_2 pwh = to_common(*intR.begin());
  if (pwh.holes_begin() != pwh.holes_end()) {
    LOG4CPLUS_WARN(logger, "intersection yielded holes");
  }
  return pwh.outer_boundary();
}