File: draw_polygon_with_holes_2.cpp

package info (click to toggle)
cgal 6.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 144,952 kB
  • sloc: cpp: 811,597; ansic: 208,576; sh: 493; python: 411; makefile: 286; javascript: 174
file content (46 lines) | stat: -rw-r--r-- 1,122 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*! \file draw_polygon_with_holes_2.cpp
 */

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polygon_2.h>
#include <CGAL/Polygon_with_holes_2.h>
#include <CGAL/draw_polygon_with_holes_2.h>

using K=CGAL::Exact_predicates_inexact_constructions_kernel;
using Point_2=K::Point_2;
using Polygon_2=CGAL::Polygon_2<K>;
using Polygon_with_holes_2=CGAL::Polygon_with_holes_2<K>;

Polygon_2 triangle(double x, double y)
{ // Create a triangle (x, y)
  Polygon_2 P;
  P.push_back(Point_2(x, y));
  P.push_back(Point_2(x+0.5, y+1));
  P.push_back(Point_2(x+1, y));
  return P;
}

Polygon_2 rectangle(double l)
{   // Create a rectangle with given side length.
  Polygon_2 P;
  P.push_back(Point_2(0, 0));
  P.push_back(Point_2(l, 0));
  P.push_back(Point_2(l, l));
  P.push_back(Point_2(0, l));
  return P;
}

int main()
{
  // Create a large rectangle A, with 3 triangle holes
  Polygon_with_holes_2 A(rectangle(4));
  Polygon_2 H1(triangle(1, 1));
  Polygon_2 H2(triangle(2, 1));
  Polygon_2 H3(triangle(1.5, 2));
  A.add_hole(H1);
  A.add_hole(H2);
  A.add_hole(H3);
  CGAL::draw(A);

  return 0;
}