Panda3D
 All Classes Functions Variables Enumerations
triangulator.I
1 // Filename: triangulator.I
2 // Created by: drose (18Jan07)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 ////////////////////////////////////////////////////////////////////
17 // Function: Triangulator::add_vertex
18 // Access: Published
19 // Description: Adds a new vertex to the vertex pool. Returns the
20 // vertex index number.
21 ////////////////////////////////////////////////////////////////////
22 INLINE int Triangulator::
23 add_vertex(double x, double y) {
24  return add_vertex(LPoint2d(x, y));
25 }
26 
27 ////////////////////////////////////////////////////////////////////
28 // Function: Triangulator::get_num_vertices
29 // Access: Published
30 // Description: Returns the number of vertices in the pool. Note
31 // that the Triangulator might append new vertices, in
32 // addition to those added by the user, if any of the
33 // polygon is self-intersecting, or if any of the holes
34 // intersect some part of the polygon edges.
35 ////////////////////////////////////////////////////////////////////
36 INLINE int Triangulator::
38  return _vertices.size();
39 }
40 
41 ////////////////////////////////////////////////////////////////////
42 // Function: Triangulator::get_vertex
43 // Access: Published
44 // Description: Returns the nth vertex.
45 ////////////////////////////////////////////////////////////////////
46 INLINE const LPoint2d &Triangulator::
47 get_vertex(int n) const {
48  nassertr(n >= 0 && n < (int)_vertices.size(), LPoint2d::zero());
49  return _vertices[n];
50 }
51 
52 ////////////////////////////////////////////////////////////////////
53 // Function: Triangulator::is_left_winding
54 // Access: Published
55 // Description: Returns true if the polygon vertices are listed in
56 // counterclockwise order, or false if they appear to be
57 // listed in clockwise order.
58 ////////////////////////////////////////////////////////////////////
59 INLINE bool Triangulator::
60 is_left_winding() const {
61  return check_left_winding(_polygon);
62 }
63 
64 ////////////////////////////////////////////////////////////////////
65 // Function: Triangulator::Triangle::Constructor
66 // Access: Private
67 // Description:
68 ////////////////////////////////////////////////////////////////////
69 INLINE Triangulator::Triangle::
70 Triangle(Triangulator *t, int v0, int v1, int v2) :
71  _v0(t->vert[v0].user_i),
72  _v1(t->vert[v1].user_i),
73  _v2(t->vert[v2].user_i)
74 {
75 }
76 
77 ////////////////////////////////////////////////////////////////////
78 // Function: Triangulator::segment_t::Default Constructor
79 // Access: Private
80 // Description:
81 ////////////////////////////////////////////////////////////////////
82 INLINE Triangulator::segment_t::
83 segment_t() {
84 }
85 
86 ////////////////////////////////////////////////////////////////////
87 // Function: Triangulator::segment_t::Constructor
88 // Access: Private
89 // Description:
90 ////////////////////////////////////////////////////////////////////
91 INLINE Triangulator::segment_t::
92 segment_t(Triangulator *t, int v0_i, int v1_i, int prev, int next) :
93  is_inserted(false),
94  root0(0), root1(0),
95  next(next),
96  prev(prev),
97  v0_i(v0_i)
98 {
99  v0.x = t->_vertices[v0_i][0];
100  v0.y = t->_vertices[v0_i][1];
101 
102  v1.x = t->_vertices[v1_i][0];
103  v1.y = t->_vertices[v1_i][1];
104 }
bool is_left_winding() const
Returns true if the polygon vertices are listed in counterclockwise order, or false if they appear to...
Definition: triangulator.I:60
static const LPoint2d & zero()
Returns a zero-length point.
Definition: lpoint2.h:543
int get_num_vertices() const
Returns the number of vertices in the pool.
Definition: triangulator.I:37
This is a two-component point in space.
Definition: lpoint2.h:411
This class can triangulate a convex or concave polygon, even one with holes.
Definition: triangulator.h:37
const LPoint2d & get_vertex(int n) const
Returns the nth vertex.
Definition: triangulator.I:47
int add_vertex(const LPoint2d &point)
Adds a new vertex to the vertex pool.