File: poly_io.cc

package info (click to toggle)
clippoly 0.11-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,124 kB
  • sloc: cpp: 2,207; ansic: 1,504; makefile: 48; sh: 9
file content (187 lines) | stat: -rw-r--r-- 3,599 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
//    nclip: a polygon clip library

//    Copyright (C) 1993  University of Twente

//    klamer@mi.el.utwente.nl

//    This library is free software; you can redistribute it and/or
//    modify it under the terms of the GNU Library General Public
//    License as published by the Free Software Foundation; either
//    version 2 of the License, or (at your option) any later version.

//    This library is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//    Library General Public License for more details.

//    You should have received a copy of the GNU Library General Public
//    License along with this library; if not, write to the Free
//    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

// Revision 1.5  2005/02/28 17:21:12  klamer
// Changed to have g++ 3.2.3 run silently using g++ -ansi -pedantic -Wall -Wno-unused -Wno-reorder.
// Change use of (libg++) String to ANSI C++ string.
//
// Revision 1.1  1992/12/07  10:46:35  klamer
// Initial revision
//

#ifdef __GNUG__
#pragma implementation
#endif

#include	<string>
#include	<iostream>

#include	<error.h>

#include	<poly.h>
#include	<primitives.h>
#include	<posadder.h>

#include	<graphmat.h>
//#include	"poly3node.h"
//#include	"poly3.h"
//#include	"poly2.h"

#include	"poly_io.h"

using namespace std;

Poly 	*
read_poly( istream &in )
{
	Point	p;
	
	in >> p;
	
	Poly	*new_poly = new Poly( p );
	
	while( in >> p )
		new_poly->add( p );

	string	magic;
	
	in.clear();
	in >> magic;
	
	if (magic != POLY_MAGIC)
		error_at_line(1, 0, __FILE__, __LINE__,
			      "read_poly: wrong magic (%s)", magic.c_str());
		
	return new_poly;
}
		
istream &
operator>>(istream &in, Point &p)
{
	double	x, y;
	
	in >> x >> y;

	if (!in)	// Failure?
		return in;
	
	p = Point(x,y);

	return in;
}

std::ostream	&
operator<<(std::ostream &out, const PolyPList &pl)
{
	PolyPListIter	iter(pl);
	
	while(iter())
		out << *iter.val();
		
	return out;
}

std::ostream &
operator<<(std::ostream &out, const Poly &poly)
{
	ConstPolyIter	iter(poly);
	
	while(iter())
		out << (iter.point());

	out << POLY_MAGIC << endl;
			
	return out;
}

std::ostream &
operator<<(std::ostream &out, const PolyNode &poly)
{
	out << poly.p << "next: " << poly.next << " prev: " << poly.prev 
		<< " link: " << poly._link << " state: " 
		<< poly.edgestate() 
		<< " parent: " << (void *) poly._parent_poly << endl;
	
	return out;
}

std::ostream &
operator<<(std::ostream &out, const Point &p)
{
	out << p.x() << '\t' << p.y() << endl;
	
	return out;
}

std::ostream &
operator<<(std::ostream &out, enum LogicStates state)
{
	switch(state)
	{case UnKnown:
		out << "UnKnown";
		break;
	case True:
		out << "True";
		break;
	case False:
		out << "False";
		break;
	case TrueFalse:
		out << "TrueFalse";
		break;
	default:
		error_at_line(0, 0, __FILE__, __LINE__, "Unknown value in LogicStates: %d", (int)state);
		out << (int)state;
	}
	
	return out;
}

std::ostream &
operator<<(std::ostream &out, enum EdgeState state)
{
	switch(state)
	{case Unknown:
		out << "Unknown";
		break;
	case None:
		out << "None";
		break;
	case Shared:
		out << "Shared";
		break;
	case Inside:
		out << "Inside";
		break;
	default:
		error_at_line(0, 0, __FILE__, __LINE__, "Unknown value in LogicStates: %d", (int)state);
		out << (int)state;
	}
	
	return out;
}

std::ostream &
operator<<(std::ostream&out, const hvec3_t &v)
{
	out << v_x(v) << ", " << v_y(v) << ", " << v_z(v) << ", " << v_w(v);

	return out;
}