0
7
0
10
4
83
43
13
13
| ... | ... |
@@ -1240,48 +1240,53 @@ |
| 1240 | 1240 |
typedef typename Digraph::template NodeMap<bool> ReachedMap; |
| 1241 | 1241 |
|
| 1242 | 1242 |
/// \brief Instantiates a \ref ReachedMap. |
| 1243 | 1243 |
/// |
| 1244 | 1244 |
/// This function instantiates a \ref ReachedMap. |
| 1245 | 1245 |
/// \param digraph is the digraph, to which |
| 1246 | 1246 |
/// we would like to define the \ref ReachedMap. |
| 1247 | 1247 |
static ReachedMap *createReachedMap(const Digraph &digraph) {
|
| 1248 | 1248 |
return new ReachedMap(digraph); |
| 1249 | 1249 |
} |
| 1250 | 1250 |
|
| 1251 | 1251 |
}; |
| 1252 | 1252 |
|
| 1253 | 1253 |
/// \ingroup search |
| 1254 | 1254 |
/// |
| 1255 | 1255 |
/// \brief %BFS algorithm class with visitor interface. |
| 1256 | 1256 |
/// |
| 1257 | 1257 |
/// This class provides an efficient implementation of the %BFS algorithm |
| 1258 | 1258 |
/// with visitor interface. |
| 1259 | 1259 |
/// |
| 1260 | 1260 |
/// The %BfsVisit class provides an alternative interface to the Bfs |
| 1261 | 1261 |
/// class. It works with callback mechanism, the BfsVisit object calls |
| 1262 | 1262 |
/// the member functions of the \c Visitor class on every BFS event. |
| 1263 | 1263 |
/// |
| 1264 |
/// This interface of the BFS algorithm should be used in special cases |
|
| 1265 |
/// when extra actions have to be performed in connection with certain |
|
| 1266 |
/// events of the BFS algorithm. Otherwise consider to use Bfs or bfs() |
|
| 1267 |
/// instead. |
|
| 1268 |
/// |
|
| 1264 | 1269 |
/// \tparam _Digraph The type of the digraph the algorithm runs on. |
| 1265 | 1270 |
/// The default value is |
| 1266 | 1271 |
/// \ref ListDigraph. The value of _Digraph is not used directly by |
| 1267 | 1272 |
/// \ref BfsVisit, it is only passed to \ref BfsVisitDefaultTraits. |
| 1268 | 1273 |
/// \tparam _Visitor The Visitor type that is used by the algorithm. |
| 1269 | 1274 |
/// \ref BfsVisitor "BfsVisitor<_Digraph>" is an empty visitor, which |
| 1270 | 1275 |
/// does not observe the BFS events. If you want to observe the BFS |
| 1271 | 1276 |
/// events, you should implement your own visitor class. |
| 1272 | 1277 |
/// \tparam _Traits Traits class to set various data types used by the |
| 1273 | 1278 |
/// algorithm. The default traits class is |
| 1274 | 1279 |
/// \ref BfsVisitDefaultTraits "BfsVisitDefaultTraits<_Digraph>". |
| 1275 | 1280 |
/// See \ref BfsVisitDefaultTraits for the documentation of |
| 1276 | 1281 |
/// a BFS visit traits class. |
| 1277 | 1282 |
#ifdef DOXYGEN |
| 1278 | 1283 |
template <typename _Digraph, typename _Visitor, typename _Traits> |
| 1279 | 1284 |
#else |
| 1280 | 1285 |
template <typename _Digraph = ListDigraph, |
| 1281 | 1286 |
typename _Visitor = BfsVisitor<_Digraph>, |
| 1282 | 1287 |
typename _Traits = BfsDefaultTraits<_Digraph> > |
| 1283 | 1288 |
#endif |
| 1284 | 1289 |
class BfsVisit {
|
| 1285 | 1290 |
public: |
| 1286 | 1291 |
|
| 1287 | 1292 |
/// \brief \ref Exception for uninitialized parameters. |
| ... | ... |
@@ -38,95 +38,98 @@ |
| 38 | 38 |
/// \brief BaseDigraph to BaseGraph extender |
| 39 | 39 |
template <typename Base> |
| 40 | 40 |
class UndirDigraphExtender : public Base {
|
| 41 | 41 |
|
| 42 | 42 |
public: |
| 43 | 43 |
|
| 44 | 44 |
typedef Base Parent; |
| 45 | 45 |
typedef typename Parent::Arc Edge; |
| 46 | 46 |
typedef typename Parent::Node Node; |
| 47 | 47 |
|
| 48 | 48 |
typedef True UndirectedTag; |
| 49 | 49 |
|
| 50 | 50 |
class Arc : public Edge {
|
| 51 | 51 |
friend class UndirDigraphExtender; |
| 52 | 52 |
|
| 53 | 53 |
protected: |
| 54 | 54 |
bool forward; |
| 55 | 55 |
|
| 56 | 56 |
Arc(const Edge &ue, bool _forward) : |
| 57 | 57 |
Edge(ue), forward(_forward) {}
|
| 58 | 58 |
|
| 59 | 59 |
public: |
| 60 | 60 |
Arc() {}
|
| 61 | 61 |
|
| 62 |
// |
|
| 62 |
// Invalid arc constructor |
|
| 63 | 63 |
Arc(Invalid i) : Edge(i), forward(true) {}
|
| 64 | 64 |
|
| 65 | 65 |
bool operator==(const Arc &that) const {
|
| 66 | 66 |
return forward==that.forward && Edge(*this)==Edge(that); |
| 67 | 67 |
} |
| 68 | 68 |
bool operator!=(const Arc &that) const {
|
| 69 | 69 |
return forward!=that.forward || Edge(*this)!=Edge(that); |
| 70 | 70 |
} |
| 71 | 71 |
bool operator<(const Arc &that) const {
|
| 72 | 72 |
return forward<that.forward || |
| 73 | 73 |
(!(that.forward<forward) && Edge(*this)<Edge(that)); |
| 74 | 74 |
} |
| 75 | 75 |
}; |
| 76 | 76 |
|
| 77 |
/// First node of the edge |
|
| 78 |
Node u(const Edge &e) const {
|
|
| 79 |
return Parent::source(e); |
|
| 80 |
} |
|
| 77 | 81 |
|
| 78 |
|
|
| 79 |
using Parent::source; |
|
| 80 |
|
|
| 81 |
/// Source of the given Arc. |
|
| 82 |
/// Source of the given arc |
|
| 82 | 83 |
Node source(const Arc &e) const {
|
| 83 | 84 |
return e.forward ? Parent::source(e) : Parent::target(e); |
| 84 | 85 |
} |
| 85 | 86 |
|
| 86 |
|
|
| 87 |
/// Second node of the edge |
|
| 88 |
Node v(const Edge &e) const {
|
|
| 89 |
return Parent::target(e); |
|
| 90 |
} |
|
| 87 | 91 |
|
| 88 |
/// Target of the given |
|
| 92 |
/// Target of the given arc |
|
| 89 | 93 |
Node target(const Arc &e) const {
|
| 90 | 94 |
return e.forward ? Parent::target(e) : Parent::source(e); |
| 91 | 95 |
} |
| 92 | 96 |
|
| 93 | 97 |
/// \brief Directed arc from an edge. |
| 94 | 98 |
/// |
| 95 |
/// Returns a directed arc corresponding to the specified Edge. |
|
| 96 |
/// If the given bool is true the given edge and the |
|
| 97 |
/// returned arc have the same source node. |
|
| 98 |
static Arc direct(const Edge &ue, bool d) {
|
|
| 99 |
|
|
| 99 |
/// Returns a directed arc corresponding to the specified edge. |
|
| 100 |
/// If the given bool is true, the first node of the given edge and |
|
| 101 |
/// the source node of the returned arc are the same. |
|
| 102 |
static Arc direct(const Edge &e, bool d) {
|
|
| 103 |
return Arc(e, d); |
|
| 100 | 104 |
} |
| 101 | 105 |
|
| 102 |
/// Returns whether the given directed arc is same orientation as the |
|
| 103 |
/// corresponding edge. |
|
| 106 |
/// Returns whether the given directed arc has the same orientation |
|
| 107 |
/// as the corresponding edge. |
|
| 104 | 108 |
/// |
| 105 | 109 |
/// \todo reference to the corresponding point of the undirected digraph |
| 106 | 110 |
/// concept. "What does the direction of an edge mean?" |
| 107 |
static bool direction(const Arc &e) { return e.forward; }
|
|
| 108 |
|
|
| 111 |
static bool direction(const Arc &a) { return a.forward; }
|
|
| 109 | 112 |
|
| 110 | 113 |
using Parent::first; |
| 111 | 114 |
using Parent::next; |
| 112 | 115 |
|
| 113 | 116 |
void first(Arc &e) const {
|
| 114 | 117 |
Parent::first(e); |
| 115 | 118 |
e.forward=true; |
| 116 | 119 |
} |
| 117 | 120 |
|
| 118 | 121 |
void next(Arc &e) const {
|
| 119 | 122 |
if( e.forward ) {
|
| 120 | 123 |
e.forward = false; |
| 121 | 124 |
} |
| 122 | 125 |
else {
|
| 123 | 126 |
Parent::next(e); |
| 124 | 127 |
e.forward = true; |
| 125 | 128 |
} |
| 126 | 129 |
} |
| 127 | 130 |
|
| 128 | 131 |
void firstOut(Arc &e, const Node &n) const {
|
| 129 | 132 |
Parent::firstIn(e,n); |
| 130 | 133 |
if( Edge(e) != INVALID ) {
|
| 131 | 134 |
e.forward = false; |
| 132 | 135 |
} |
| ... | ... |
@@ -208,49 +211,48 @@ |
| 208 | 211 |
int id(const Node &n) const {
|
| 209 | 212 |
return Parent::id(n); |
| 210 | 213 |
} |
| 211 | 214 |
|
| 212 | 215 |
int id(const Edge &e) const {
|
| 213 | 216 |
return Parent::id(e); |
| 214 | 217 |
} |
| 215 | 218 |
|
| 216 | 219 |
int id(const Arc &e) const {
|
| 217 | 220 |
return 2 * Parent::id(e) + int(e.forward); |
| 218 | 221 |
} |
| 219 | 222 |
|
| 220 | 223 |
int maxNodeId() const {
|
| 221 | 224 |
return Parent::maxNodeId(); |
| 222 | 225 |
} |
| 223 | 226 |
|
| 224 | 227 |
int maxArcId() const {
|
| 225 | 228 |
return 2 * Parent::maxArcId() + 1; |
| 226 | 229 |
} |
| 227 | 230 |
|
| 228 | 231 |
int maxEdgeId() const {
|
| 229 | 232 |
return Parent::maxArcId(); |
| 230 | 233 |
} |
| 231 | 234 |
|
| 232 |
|
|
| 233 | 235 |
int arcNum() const {
|
| 234 | 236 |
return 2 * Parent::arcNum(); |
| 235 | 237 |
} |
| 236 | 238 |
|
| 237 | 239 |
int edgeNum() const {
|
| 238 | 240 |
return Parent::arcNum(); |
| 239 | 241 |
} |
| 240 | 242 |
|
| 241 | 243 |
Arc findArc(Node s, Node t, Arc p = INVALID) const {
|
| 242 | 244 |
if (p == INVALID) {
|
| 243 | 245 |
Edge arc = Parent::findArc(s, t); |
| 244 | 246 |
if (arc != INVALID) return direct(arc, true); |
| 245 | 247 |
arc = Parent::findArc(t, s); |
| 246 | 248 |
if (arc != INVALID) return direct(arc, false); |
| 247 | 249 |
} else if (direction(p)) {
|
| 248 | 250 |
Edge arc = Parent::findArc(s, t, p); |
| 249 | 251 |
if (arc != INVALID) return direct(arc, true); |
| 250 | 252 |
arc = Parent::findArc(t, s); |
| 251 | 253 |
if (arc != INVALID) return direct(arc, false); |
| 252 | 254 |
} else {
|
| 253 | 255 |
Edge arc = Parent::findArc(t, s, p); |
| 254 | 256 |
if (arc != INVALID) return direct(arc, false); |
| 255 | 257 |
} |
| 256 | 258 |
return INVALID; |
| ... | ... |
@@ -1187,48 +1187,53 @@ |
| 1187 | 1187 |
typedef typename Digraph::template NodeMap<bool> ReachedMap; |
| 1188 | 1188 |
|
| 1189 | 1189 |
/// \brief Instantiates a \ref ReachedMap. |
| 1190 | 1190 |
/// |
| 1191 | 1191 |
/// This function instantiates a \ref ReachedMap. |
| 1192 | 1192 |
/// \param digraph is the digraph, to which |
| 1193 | 1193 |
/// we would like to define the \ref ReachedMap. |
| 1194 | 1194 |
static ReachedMap *createReachedMap(const Digraph &digraph) {
|
| 1195 | 1195 |
return new ReachedMap(digraph); |
| 1196 | 1196 |
} |
| 1197 | 1197 |
|
| 1198 | 1198 |
}; |
| 1199 | 1199 |
|
| 1200 | 1200 |
/// \ingroup search |
| 1201 | 1201 |
/// |
| 1202 | 1202 |
/// \brief %DFS algorithm class with visitor interface. |
| 1203 | 1203 |
/// |
| 1204 | 1204 |
/// This class provides an efficient implementation of the %DFS algorithm |
| 1205 | 1205 |
/// with visitor interface. |
| 1206 | 1206 |
/// |
| 1207 | 1207 |
/// The %DfsVisit class provides an alternative interface to the Dfs |
| 1208 | 1208 |
/// class. It works with callback mechanism, the DfsVisit object calls |
| 1209 | 1209 |
/// the member functions of the \c Visitor class on every DFS event. |
| 1210 | 1210 |
/// |
| 1211 |
/// This interface of the DFS algorithm should be used in special cases |
|
| 1212 |
/// when extra actions have to be performed in connection with certain |
|
| 1213 |
/// events of the DFS algorithm. Otherwise consider to use Dfs or dfs() |
|
| 1214 |
/// instead. |
|
| 1215 |
/// |
|
| 1211 | 1216 |
/// \tparam _Digraph The type of the digraph the algorithm runs on. |
| 1212 | 1217 |
/// The default value is |
| 1213 | 1218 |
/// \ref ListDigraph. The value of _Digraph is not used directly by |
| 1214 | 1219 |
/// \ref DfsVisit, it is only passed to \ref DfsVisitDefaultTraits. |
| 1215 | 1220 |
/// \tparam _Visitor The Visitor type that is used by the algorithm. |
| 1216 | 1221 |
/// \ref DfsVisitor "DfsVisitor<_Digraph>" is an empty visitor, which |
| 1217 | 1222 |
/// does not observe the DFS events. If you want to observe the DFS |
| 1218 | 1223 |
/// events, you should implement your own visitor class. |
| 1219 | 1224 |
/// \tparam _Traits Traits class to set various data types used by the |
| 1220 | 1225 |
/// algorithm. The default traits class is |
| 1221 | 1226 |
/// \ref DfsVisitDefaultTraits "DfsVisitDefaultTraits<_Digraph>". |
| 1222 | 1227 |
/// See \ref DfsVisitDefaultTraits for the documentation of |
| 1223 | 1228 |
/// a DFS visit traits class. |
| 1224 | 1229 |
#ifdef DOXYGEN |
| 1225 | 1230 |
template <typename _Digraph, typename _Visitor, typename _Traits> |
| 1226 | 1231 |
#else |
| 1227 | 1232 |
template <typename _Digraph = ListDigraph, |
| 1228 | 1233 |
typename _Visitor = DfsVisitor<_Digraph>, |
| 1229 | 1234 |
typename _Traits = DfsDefaultTraits<_Digraph> > |
| 1230 | 1235 |
#endif |
| 1231 | 1236 |
class DfsVisit {
|
| 1232 | 1237 |
public: |
| 1233 | 1238 |
|
| 1234 | 1239 |
/// \brief \ref Exception for uninitialized parameters. |
| ... | ... |
@@ -1046,75 +1046,77 @@ |
| 1046 | 1046 |
} |
| 1047 | 1047 |
}; |
| 1048 | 1048 |
|
| 1049 | 1049 |
/// Default traits class used by \ref DijkstraWizard |
| 1050 | 1050 |
|
| 1051 | 1051 |
/// To make it easier to use Dijkstra algorithm |
| 1052 | 1052 |
/// we have created a wizard class. |
| 1053 | 1053 |
/// This \ref DijkstraWizard class needs default traits, |
| 1054 | 1054 |
/// as well as the \ref Dijkstra class. |
| 1055 | 1055 |
/// The \ref DijkstraWizardBase is a class to be the default traits of the |
| 1056 | 1056 |
/// \ref DijkstraWizard class. |
| 1057 | 1057 |
/// \todo More named parameters are required... |
| 1058 | 1058 |
template<class GR,class LM> |
| 1059 | 1059 |
class DijkstraWizardBase : public DijkstraWizardDefaultTraits<GR,LM> |
| 1060 | 1060 |
{
|
| 1061 | 1061 |
typedef DijkstraWizardDefaultTraits<GR,LM> Base; |
| 1062 | 1062 |
protected: |
| 1063 | 1063 |
//The type of the nodes in the digraph. |
| 1064 | 1064 |
typedef typename Base::Digraph::Node Node; |
| 1065 | 1065 |
|
| 1066 | 1066 |
//Pointer to the digraph the algorithm runs on. |
| 1067 | 1067 |
void *_g; |
| 1068 | 1068 |
//Pointer to the length map |
| 1069 | 1069 |
void *_length; |
| 1070 |
//Pointer to the map of processed nodes. |
|
| 1071 |
void *_processed; |
|
| 1070 | 1072 |
//Pointer to the map of predecessors arcs. |
| 1071 | 1073 |
void *_pred; |
| 1072 | 1074 |
//Pointer to the map of distances. |
| 1073 | 1075 |
void *_dist; |
| 1074 | 1076 |
//Pointer to the source node. |
| 1075 | 1077 |
Node _source; |
| 1076 | 1078 |
|
| 1077 | 1079 |
public: |
| 1078 | 1080 |
/// Constructor. |
| 1079 | 1081 |
|
| 1080 | 1082 |
/// This constructor does not require parameters, therefore it initiates |
| 1081 | 1083 |
/// all of the attributes to default values (0, INVALID). |
| 1082 |
DijkstraWizardBase() : _g(0), _length(0), _pred(0), |
|
| 1084 |
DijkstraWizardBase() : _g(0), _length(0), _processed(0), _pred(0), |
|
| 1083 | 1085 |
_dist(0), _source(INVALID) {}
|
| 1084 | 1086 |
|
| 1085 | 1087 |
/// Constructor. |
| 1086 | 1088 |
|
| 1087 | 1089 |
/// This constructor requires some parameters, |
| 1088 | 1090 |
/// listed in the parameters list. |
| 1089 | 1091 |
/// Others are initiated to 0. |
| 1090 | 1092 |
/// \param g The digraph the algorithm runs on. |
| 1091 | 1093 |
/// \param l The length map. |
| 1092 | 1094 |
/// \param s The source node. |
| 1093 | 1095 |
DijkstraWizardBase(const GR &g,const LM &l, Node s=INVALID) : |
| 1094 | 1096 |
_g(reinterpret_cast<void*>(const_cast<GR*>(&g))), |
| 1095 | 1097 |
_length(reinterpret_cast<void*>(const_cast<LM*>(&l))), |
| 1096 |
_pred(0), _dist(0), _source(s) {}
|
|
| 1098 |
_processed(0), _pred(0), _dist(0), _source(s) {}
|
|
| 1097 | 1099 |
|
| 1098 | 1100 |
}; |
| 1099 | 1101 |
|
| 1100 | 1102 |
/// Auxiliary class for the function type interface of Dijkstra algorithm. |
| 1101 | 1103 |
|
| 1102 | 1104 |
/// This auxiliary class is created to implement the function type |
| 1103 | 1105 |
/// interface of \ref Dijkstra algorithm. It uses the functions and features |
| 1104 | 1106 |
/// of the plain \ref Dijkstra, but it is much simpler to use it. |
| 1105 | 1107 |
/// It should only be used through the \ref dijkstra() function, which makes |
| 1106 | 1108 |
/// it easier to use the algorithm. |
| 1107 | 1109 |
/// |
| 1108 | 1110 |
/// Simplicity means that the way to change the types defined |
| 1109 | 1111 |
/// in the traits class is based on functions that returns the new class |
| 1110 | 1112 |
/// and not on templatable built-in classes. |
| 1111 | 1113 |
/// When using the plain \ref Dijkstra |
| 1112 | 1114 |
/// the new class with the modified type comes from |
| 1113 | 1115 |
/// the original class by using the :: |
| 1114 | 1116 |
/// operator. In the case of \ref DijkstraWizard only |
| 1115 | 1117 |
/// a function have to be called, and it will |
| 1116 | 1118 |
/// return the needed class. |
| 1117 | 1119 |
/// |
| 1118 | 1120 |
/// It does not have own \ref run() method. When its \ref run() method |
| 1119 | 1121 |
/// is called, it initiates a plain \ref Dijkstra object, and calls the |
| 1120 | 1122 |
/// \ref Dijkstra::run() method of it. |
| ... | ... |
@@ -1151,50 +1153,54 @@ |
| 1151 | 1153 |
DijkstraWizard() : TR() {}
|
| 1152 | 1154 |
|
| 1153 | 1155 |
/// Constructor that requires parameters. |
| 1154 | 1156 |
|
| 1155 | 1157 |
/// Constructor that requires parameters. |
| 1156 | 1158 |
/// These parameters will be the default values for the traits class. |
| 1157 | 1159 |
DijkstraWizard(const Digraph &g,const LengthMap &l, Node s=INVALID) : |
| 1158 | 1160 |
TR(g,l,s) {}
|
| 1159 | 1161 |
|
| 1160 | 1162 |
///Copy constructor |
| 1161 | 1163 |
DijkstraWizard(const TR &b) : TR(b) {}
|
| 1162 | 1164 |
|
| 1163 | 1165 |
~DijkstraWizard() {}
|
| 1164 | 1166 |
|
| 1165 | 1167 |
///Runs Dijkstra algorithm from a source node. |
| 1166 | 1168 |
|
| 1167 | 1169 |
///Runs Dijkstra algorithm from a source node. |
| 1168 | 1170 |
///The node can be given with the \ref source() function. |
| 1169 | 1171 |
void run() |
| 1170 | 1172 |
{
|
| 1171 | 1173 |
if(Base::_source==INVALID) throw UninitializedParameter(); |
| 1172 | 1174 |
Dijkstra<Digraph,LengthMap,TR> |
| 1173 | 1175 |
dij(*reinterpret_cast<const Digraph*>(Base::_g), |
| 1174 | 1176 |
*reinterpret_cast<const LengthMap*>(Base::_length)); |
| 1175 |
if(Base::_pred) dij.predMap(*reinterpret_cast<PredMap*>(Base::_pred)); |
|
| 1176 |
if(Base::_dist) dij.distMap(*reinterpret_cast<DistMap*>(Base::_dist)); |
|
| 1177 |
if(Base::_processed) |
|
| 1178 |
dij.processedMap(*reinterpret_cast<ProcessedMap*>(Base::_processed)); |
|
| 1179 |
if(Base::_pred) |
|
| 1180 |
dij.predMap(*reinterpret_cast<PredMap*>(Base::_pred)); |
|
| 1181 |
if(Base::_dist) |
|
| 1182 |
dij.distMap(*reinterpret_cast<DistMap*>(Base::_dist)); |
|
| 1177 | 1183 |
dij.run(Base::_source); |
| 1178 | 1184 |
} |
| 1179 | 1185 |
|
| 1180 | 1186 |
///Runs Dijkstra algorithm from the given node. |
| 1181 | 1187 |
|
| 1182 | 1188 |
///Runs Dijkstra algorithm from the given node. |
| 1183 | 1189 |
///\param s is the given source. |
| 1184 | 1190 |
void run(Node s) |
| 1185 | 1191 |
{
|
| 1186 | 1192 |
Base::_source=s; |
| 1187 | 1193 |
run(); |
| 1188 | 1194 |
} |
| 1189 | 1195 |
|
| 1190 | 1196 |
/// Sets the source node, from which the Dijkstra algorithm runs. |
| 1191 | 1197 |
|
| 1192 | 1198 |
/// Sets the source node, from which the Dijkstra algorithm runs. |
| 1193 | 1199 |
/// \param s is the source node. |
| 1194 | 1200 |
DijkstraWizard<TR> &source(Node s) |
| 1195 | 1201 |
{
|
| 1196 | 1202 |
Base::_source=s; |
| 1197 | 1203 |
return *this; |
| 1198 | 1204 |
} |
| 1199 | 1205 |
|
| 1200 | 1206 |
template<class T> |
| ... | ... |
@@ -7,65 +7,64 @@ |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#ifndef LEMON_DIM2_H |
| 20 | 20 |
#define LEMON_DIM2_H |
| 21 | 21 |
|
| 22 | 22 |
#include <iostream> |
| 23 | 23 |
|
| 24 | 24 |
///\ingroup misc |
| 25 | 25 |
///\file |
| 26 | 26 |
///\brief A simple two dimensional vector and a bounding box implementation |
| 27 | 27 |
/// |
| 28 | 28 |
/// The class \ref lemon::dim2::Point "dim2::Point" implements |
| 29 | 29 |
/// a two dimensional vector with the usual operations. |
| 30 | 30 |
/// |
| 31 |
/// The class \ref lemon::dim2::BoundingBox "dim2::BoundingBox" |
|
| 32 |
/// can be used to determine |
|
| 31 |
/// The class \ref lemon::dim2::Box "dim2::Box" can be used to determine |
|
| 33 | 32 |
/// the rectangular bounding box of a set of |
| 34 | 33 |
/// \ref lemon::dim2::Point "dim2::Point"'s. |
| 35 | 34 |
|
| 36 | 35 |
namespace lemon {
|
| 37 | 36 |
|
| 38 | 37 |
///Tools for handling two dimensional coordinates |
| 39 | 38 |
|
| 40 | 39 |
///This namespace is a storage of several |
| 41 | 40 |
///tools for handling two dimensional coordinates |
| 42 | 41 |
namespace dim2 {
|
| 43 | 42 |
|
| 44 | 43 |
/// \addtogroup misc |
| 45 | 44 |
/// @{
|
| 46 | 45 |
|
| 47 |
/// |
|
| 46 |
/// Two dimensional vector (plain vector) |
|
| 48 | 47 |
|
| 49 | 48 |
/// A simple two dimensional vector (plain vector) implementation |
| 50 | 49 |
/// with the usual vector operations. |
| 51 | 50 |
template<typename T> |
| 52 | 51 |
class Point {
|
| 53 | 52 |
|
| 54 | 53 |
public: |
| 55 | 54 |
|
| 56 | 55 |
typedef T Value; |
| 57 | 56 |
|
| 58 | 57 |
///First coordinate |
| 59 | 58 |
T x; |
| 60 | 59 |
///Second coordinate |
| 61 | 60 |
T y; |
| 62 | 61 |
|
| 63 | 62 |
///Default constructor |
| 64 | 63 |
Point() {}
|
| 65 | 64 |
|
| 66 | 65 |
///Construct an instance from coordinates |
| 67 | 66 |
Point(T a, T b) : x(a), y(b) { }
|
| 68 | 67 |
|
| 69 | 68 |
///Returns the dimension of the vector (i.e. returns 2). |
| 70 | 69 |
|
| 71 | 70 |
///The dimension of the vector. |
| ... | ... |
@@ -239,321 +238,362 @@ |
| 239 | 238 |
///Rotate by 180 degrees |
| 240 | 239 |
|
| 241 | 240 |
///Returns the parameter rotated by 180 degrees. |
| 242 | 241 |
///\relates Point |
| 243 | 242 |
/// |
| 244 | 243 |
template<typename T> |
| 245 | 244 |
inline Point<T> rot180(const Point<T> &z) |
| 246 | 245 |
{
|
| 247 | 246 |
return Point<T>(-z.x,-z.y); |
| 248 | 247 |
} |
| 249 | 248 |
|
| 250 | 249 |
///Rotate by 270 degrees |
| 251 | 250 |
|
| 252 | 251 |
///Returns the parameter rotated by 90 degrees in negative direction. |
| 253 | 252 |
///\relates Point |
| 254 | 253 |
/// |
| 255 | 254 |
template<typename T> |
| 256 | 255 |
inline Point<T> rot270(const Point<T> &z) |
| 257 | 256 |
{
|
| 258 | 257 |
return Point<T>(z.y,-z.x); |
| 259 | 258 |
} |
| 260 | 259 |
|
| 261 | 260 |
|
| 262 | 261 |
|
| 263 |
|
|
| 262 |
/// Bounding box of plain vectors (\ref Point points). |
|
| 264 | 263 |
|
| 265 |
/// A class to calculate or store the bounding box of plain vectors. |
|
| 266 |
/// |
|
| 264 |
/// A class to calculate or store the bounding box of plain vectors |
|
| 265 |
/// (\ref Point points). |
|
| 267 | 266 |
template<typename T> |
| 268 |
|
|
| 267 |
class Box {
|
|
| 269 | 268 |
Point<T> _bottom_left, _top_right; |
| 270 | 269 |
bool _empty; |
| 271 | 270 |
public: |
| 272 | 271 |
|
| 273 |
///Default constructor: creates an empty bounding box |
|
| 274 |
BoundingBox() { _empty = true; }
|
|
| 272 |
///Default constructor: creates an empty box |
|
| 273 |
Box() { _empty = true; }
|
|
| 275 | 274 |
|
| 276 |
///Construct an instance from one point |
|
| 277 |
BoundingBox(Point<T> a) {
|
|
| 275 |
///Construct a box from one point |
|
| 276 |
Box(Point<T> a) {
|
|
| 278 | 277 |
_bottom_left = _top_right = a; |
| 279 | 278 |
_empty = false; |
| 280 | 279 |
} |
| 281 | 280 |
|
| 282 |
///Construct |
|
| 281 |
///Construct a box from two points |
|
| 283 | 282 |
|
| 284 |
///Construct |
|
| 283 |
///Construct a box from two points. |
|
| 285 | 284 |
///\param a The bottom left corner. |
| 286 | 285 |
///\param b The top right corner. |
| 287 | 286 |
///\warning The coordinates of the bottom left corner must be no more |
| 288 | 287 |
///than those of the top right one. |
| 289 |
|
|
| 288 |
Box(Point<T> a,Point<T> b) |
|
| 290 | 289 |
{
|
| 291 | 290 |
_bottom_left = a; |
| 292 | 291 |
_top_right = b; |
| 293 | 292 |
_empty = false; |
| 294 | 293 |
} |
| 295 | 294 |
|
| 296 |
///Construct |
|
| 295 |
///Construct a box from four numbers |
|
| 297 | 296 |
|
| 298 |
///Construct |
|
| 297 |
///Construct a box from four numbers. |
|
| 299 | 298 |
///\param l The left side of the box. |
| 300 | 299 |
///\param b The bottom of the box. |
| 301 | 300 |
///\param r The right side of the box. |
| 302 | 301 |
///\param t The top of the box. |
| 303 | 302 |
///\warning The left side must be no more than the right side and |
| 304 | 303 |
///bottom must be no more than the top. |
| 305 |
|
|
| 304 |
Box(T l,T b,T r,T t) |
|
| 306 | 305 |
{
|
| 307 | 306 |
_bottom_left=Point<T>(l,b); |
| 308 | 307 |
_top_right=Point<T>(r,t); |
| 309 | 308 |
_empty = false; |
| 310 | 309 |
} |
| 311 | 310 |
|
| 312 |
///Return \c true if the |
|
| 311 |
///Return \c true if the box is empty. |
|
| 313 | 312 |
|
| 314 |
///Return \c true if the |
|
| 313 |
///Return \c true if the box is empty (i.e. return \c false |
|
| 315 | 314 |
///if at least one point was added to the box or the coordinates of |
| 316 | 315 |
///the box were set). |
| 317 | 316 |
/// |
| 318 |
///The coordinates of an empty |
|
| 317 |
///The coordinates of an empty box are not defined. |
|
| 319 | 318 |
bool empty() const {
|
| 320 | 319 |
return _empty; |
| 321 | 320 |
} |
| 322 | 321 |
|
| 323 |
///Make the |
|
| 322 |
///Make the box empty |
|
| 324 | 323 |
void clear() {
|
| 325 | 324 |
_empty = true; |
| 326 | 325 |
} |
| 327 | 326 |
|
| 328 | 327 |
///Give back the bottom left corner of the box |
| 329 | 328 |
|
| 330 | 329 |
///Give back the bottom left corner of the box. |
| 331 |
///If the |
|
| 330 |
///If the box is empty, then the return value is not defined. |
|
| 332 | 331 |
Point<T> bottomLeft() const {
|
| 333 | 332 |
return _bottom_left; |
| 334 | 333 |
} |
| 335 | 334 |
|
| 336 | 335 |
///Set the bottom left corner of the box |
| 337 | 336 |
|
| 338 | 337 |
///Set the bottom left corner of the box. |
| 339 | 338 |
///\pre The box must not be empty. |
| 340 | 339 |
void bottomLeft(Point<T> p) {
|
| 341 | 340 |
_bottom_left = p; |
| 342 | 341 |
} |
| 343 | 342 |
|
| 344 | 343 |
///Give back the top right corner of the box |
| 345 | 344 |
|
| 346 | 345 |
///Give back the top right corner of the box. |
| 347 |
///If the |
|
| 346 |
///If the box is empty, then the return value is not defined. |
|
| 348 | 347 |
Point<T> topRight() const {
|
| 349 | 348 |
return _top_right; |
| 350 | 349 |
} |
| 351 | 350 |
|
| 352 | 351 |
///Set the top right corner of the box |
| 353 | 352 |
|
| 354 | 353 |
///Set the top right corner of the box. |
| 355 | 354 |
///\pre The box must not be empty. |
| 356 | 355 |
void topRight(Point<T> p) {
|
| 357 | 356 |
_top_right = p; |
| 358 | 357 |
} |
| 359 | 358 |
|
| 360 | 359 |
///Give back the bottom right corner of the box |
| 361 | 360 |
|
| 362 | 361 |
///Give back the bottom right corner of the box. |
| 363 |
///If the |
|
| 362 |
///If the box is empty, then the return value is not defined. |
|
| 364 | 363 |
Point<T> bottomRight() const {
|
| 365 | 364 |
return Point<T>(_top_right.x,_bottom_left.y); |
| 366 | 365 |
} |
| 367 | 366 |
|
| 368 | 367 |
///Set the bottom right corner of the box |
| 369 | 368 |
|
| 370 | 369 |
///Set the bottom right corner of the box. |
| 371 | 370 |
///\pre The box must not be empty. |
| 372 | 371 |
void bottomRight(Point<T> p) {
|
| 373 | 372 |
_top_right.x = p.x; |
| 374 | 373 |
_bottom_left.y = p.y; |
| 375 | 374 |
} |
| 376 | 375 |
|
| 377 | 376 |
///Give back the top left corner of the box |
| 378 | 377 |
|
| 379 | 378 |
///Give back the top left corner of the box. |
| 380 |
///If the |
|
| 379 |
///If the box is empty, then the return value is not defined. |
|
| 381 | 380 |
Point<T> topLeft() const {
|
| 382 | 381 |
return Point<T>(_bottom_left.x,_top_right.y); |
| 383 | 382 |
} |
| 384 | 383 |
|
| 385 | 384 |
///Set the top left corner of the box |
| 386 | 385 |
|
| 387 | 386 |
///Set the top left corner of the box. |
| 388 | 387 |
///\pre The box must not be empty. |
| 389 | 388 |
void topLeft(Point<T> p) {
|
| 390 | 389 |
_top_right.y = p.y; |
| 391 | 390 |
_bottom_left.x = p.x; |
| 392 | 391 |
} |
| 393 | 392 |
|
| 394 | 393 |
///Give back the bottom of the box |
| 395 | 394 |
|
| 396 | 395 |
///Give back the bottom of the box. |
| 397 |
///If the |
|
| 396 |
///If the box is empty, then the return value is not defined. |
|
| 398 | 397 |
T bottom() const {
|
| 399 | 398 |
return _bottom_left.y; |
| 400 | 399 |
} |
| 401 | 400 |
|
| 402 | 401 |
///Set the bottom of the box |
| 403 | 402 |
|
| 404 | 403 |
///Set the bottom of the box. |
| 405 | 404 |
///\pre The box must not be empty. |
| 406 | 405 |
void bottom(T t) {
|
| 407 | 406 |
_bottom_left.y = t; |
| 408 | 407 |
} |
| 409 | 408 |
|
| 410 | 409 |
///Give back the top of the box |
| 411 | 410 |
|
| 412 | 411 |
///Give back the top of the box. |
| 413 |
///If the |
|
| 412 |
///If the box is empty, then the return value is not defined. |
|
| 414 | 413 |
T top() const {
|
| 415 | 414 |
return _top_right.y; |
| 416 | 415 |
} |
| 417 | 416 |
|
| 418 | 417 |
///Set the top of the box |
| 419 | 418 |
|
| 420 | 419 |
///Set the top of the box. |
| 421 | 420 |
///\pre The box must not be empty. |
| 422 | 421 |
void top(T t) {
|
| 423 | 422 |
_top_right.y = t; |
| 424 | 423 |
} |
| 425 | 424 |
|
| 426 | 425 |
///Give back the left side of the box |
| 427 | 426 |
|
| 428 | 427 |
///Give back the left side of the box. |
| 429 |
///If the |
|
| 428 |
///If the box is empty, then the return value is not defined. |
|
| 430 | 429 |
T left() const {
|
| 431 | 430 |
return _bottom_left.x; |
| 432 | 431 |
} |
| 433 | 432 |
|
| 434 | 433 |
///Set the left side of the box |
| 435 | 434 |
|
| 436 | 435 |
///Set the left side of the box. |
| 437 | 436 |
///\pre The box must not be empty. |
| 438 | 437 |
void left(T t) {
|
| 439 | 438 |
_bottom_left.x = t; |
| 440 | 439 |
} |
| 441 | 440 |
|
| 442 | 441 |
/// Give back the right side of the box |
| 443 | 442 |
|
| 444 | 443 |
/// Give back the right side of the box. |
| 445 |
///If the |
|
| 444 |
///If the box is empty, then the return value is not defined. |
|
| 446 | 445 |
T right() const {
|
| 447 | 446 |
return _top_right.x; |
| 448 | 447 |
} |
| 449 | 448 |
|
| 450 | 449 |
///Set the right side of the box |
| 451 | 450 |
|
| 452 | 451 |
///Set the right side of the box. |
| 453 | 452 |
///\pre The box must not be empty. |
| 454 | 453 |
void right(T t) {
|
| 455 | 454 |
_top_right.x = t; |
| 456 | 455 |
} |
| 457 | 456 |
|
| 458 | 457 |
///Give back the height of the box |
| 459 | 458 |
|
| 460 | 459 |
///Give back the height of the box. |
| 461 |
///If the |
|
| 460 |
///If the box is empty, then the return value is not defined. |
|
| 462 | 461 |
T height() const {
|
| 463 | 462 |
return _top_right.y-_bottom_left.y; |
| 464 | 463 |
} |
| 465 | 464 |
|
| 466 | 465 |
///Give back the width of the box |
| 467 | 466 |
|
| 468 | 467 |
///Give back the width of the box. |
| 469 |
///If the |
|
| 468 |
///If the box is empty, then the return value is not defined. |
|
| 470 | 469 |
T width() const {
|
| 471 | 470 |
return _top_right.x-_bottom_left.x; |
| 472 | 471 |
} |
| 473 | 472 |
|
| 474 |
///Checks whether a point is inside |
|
| 473 |
///Checks whether a point is inside the box |
|
| 475 | 474 |
bool inside(const Point<T>& u) const {
|
| 476 | 475 |
if (_empty) |
| 477 | 476 |
return false; |
| 478 | 477 |
else {
|
| 479 | 478 |
return ( (u.x-_bottom_left.x)*(_top_right.x-u.x) >= 0 && |
| 480 | 479 |
(u.y-_bottom_left.y)*(_top_right.y-u.y) >= 0 ); |
| 481 | 480 |
} |
| 482 | 481 |
} |
| 483 | 482 |
|
| 484 |
///Increments |
|
| 483 |
///Increments the box with a point |
|
| 485 | 484 |
|
| 486 |
///Increments |
|
| 485 |
///Increments the box with a point. |
|
| 487 | 486 |
/// |
| 488 |
|
|
| 487 |
Box& add(const Point<T>& u){
|
|
| 489 | 488 |
if (_empty) {
|
| 490 | 489 |
_bottom_left = _top_right = u; |
| 491 | 490 |
_empty = false; |
| 492 | 491 |
} |
| 493 | 492 |
else {
|
| 494 | 493 |
if (_bottom_left.x > u.x) _bottom_left.x = u.x; |
| 495 | 494 |
if (_bottom_left.y > u.y) _bottom_left.y = u.y; |
| 496 | 495 |
if (_top_right.x < u.x) _top_right.x = u.x; |
| 497 | 496 |
if (_top_right.y < u.y) _top_right.y = u.y; |
| 498 | 497 |
} |
| 499 | 498 |
return *this; |
| 500 | 499 |
} |
| 501 | 500 |
|
| 502 |
///Increments |
|
| 501 |
///Increments the box to contain another box |
|
| 503 | 502 |
|
| 504 |
///Increments |
|
| 503 |
///Increments the box to contain another box. |
|
| 505 | 504 |
/// |
| 506 |
|
|
| 505 |
Box& add(const Box &u){
|
|
| 507 | 506 |
if ( !u.empty() ){
|
| 508 | 507 |
add(u._bottom_left); |
| 509 | 508 |
add(u._top_right); |
| 510 | 509 |
} |
| 511 | 510 |
return *this; |
| 512 | 511 |
} |
| 513 | 512 |
|
| 514 |
///Intersection of two |
|
| 513 |
///Intersection of two boxes |
|
| 515 | 514 |
|
| 516 |
///Intersection of two |
|
| 515 |
///Intersection of two boxes. |
|
| 517 | 516 |
/// |
| 518 |
BoundingBox operator&(const BoundingBox& u) const {
|
|
| 519 |
BoundingBox b; |
|
| 517 |
Box operator&(const Box& u) const {
|
|
| 518 |
Box b; |
|
| 520 | 519 |
if (_empty || u._empty) {
|
| 521 | 520 |
b._empty = true; |
| 522 | 521 |
} else {
|
| 523 | 522 |
b._bottom_left.x = std::max(_bottom_left.x, u._bottom_left.x); |
| 524 | 523 |
b._bottom_left.y = std::max(_bottom_left.y, u._bottom_left.y); |
| 525 | 524 |
b._top_right.x = std::min(_top_right.x, u._top_right.x); |
| 526 | 525 |
b._top_right.y = std::min(_top_right.y, u._top_right.y); |
| 527 | 526 |
b._empty = b._bottom_left.x > b._top_right.x || |
| 528 | 527 |
b._bottom_left.y > b._top_right.y; |
| 529 | 528 |
} |
| 530 | 529 |
return b; |
| 531 | 530 |
} |
| 532 | 531 |
|
| 533 |
|
|
| 532 |
};//class Box |
|
| 534 | 533 |
|
| 535 | 534 |
|
| 535 |
///Read a box from a stream |
|
| 536 |
|
|
| 537 |
///Read a box from a stream. |
|
| 538 |
///\relates Box |
|
| 539 |
template<typename T> |
|
| 540 |
inline std::istream& operator>>(std::istream &is, Box<T>& b) {
|
|
| 541 |
char c; |
|
| 542 |
Point<T> p; |
|
| 543 |
if (is >> c) {
|
|
| 544 |
if (c != '(') is.putback(c);
|
|
| 545 |
} else {
|
|
| 546 |
is.clear(); |
|
| 547 |
} |
|
| 548 |
if (!(is >> p)) return is; |
|
| 549 |
b.bottomLeft(p); |
|
| 550 |
if (is >> c) {
|
|
| 551 |
if (c != ',') is.putback(c); |
|
| 552 |
} else {
|
|
| 553 |
is.clear(); |
|
| 554 |
} |
|
| 555 |
if (!(is >> p)) return is; |
|
| 556 |
b.topRight(p); |
|
| 557 |
if (is >> c) {
|
|
| 558 |
if (c != ')') is.putback(c); |
|
| 559 |
} else {
|
|
| 560 |
is.clear(); |
|
| 561 |
} |
|
| 562 |
return is; |
|
| 563 |
} |
|
| 564 |
|
|
| 565 |
///Write a box to a stream |
|
| 566 |
|
|
| 567 |
///Write a box to a stream. |
|
| 568 |
///\relates Box |
|
| 569 |
template<typename T> |
|
| 570 |
inline std::ostream& operator<<(std::ostream &os, const Box<T>& b) |
|
| 571 |
{
|
|
| 572 |
os << "(" << b.bottomLeft() << "," << b.topRight() << ")";
|
|
| 573 |
return os; |
|
| 574 |
} |
|
| 575 |
|
|
| 536 | 576 |
///Map of x-coordinates of a \ref Point "Point"-map |
| 537 | 577 |
|
| 538 | 578 |
///\ingroup maps |
| 539 | 579 |
///Map of x-coordinates of a \ref Point "Point"-map. |
| 540 | 580 |
/// |
| 541 | 581 |
template<class M> |
| 542 | 582 |
class XMap |
| 543 | 583 |
{
|
| 544 | 584 |
M& _map; |
| 545 | 585 |
public: |
| 546 | 586 |
|
| 547 | 587 |
typedef typename M::Value::Value Value; |
| 548 | 588 |
typedef typename M::Key Key; |
| 549 | 589 |
///\e |
| 550 | 590 |
XMap(M& map) : _map(map) {}
|
| 551 | 591 |
Value operator[](Key k) const {return _map[k].x;}
|
| 552 | 592 |
void set(Key k,Value v) {_map.set(k,typename M::Value(v,_map[k].y));}
|
| 553 | 593 |
}; |
| 554 | 594 |
|
| 555 | 595 |
///Returns an \ref XMap class |
| 556 | 596 |
|
| 557 | 597 |
///This function just returns an \ref XMap class. |
| 558 | 598 |
/// |
| 559 | 599 |
///\ingroup maps |
| ... | ... |
@@ -704,82 +704,82 @@ |
| 704 | 704 |
} |
| 705 | 705 |
|
| 706 | 706 |
if (_autoArcWidthScale) {
|
| 707 | 707 |
double max_w=0; |
| 708 | 708 |
for(ArcIt e(g);e!=INVALID;++e) |
| 709 | 709 |
max_w=std::max(double(_arcWidths[e]),max_w); |
| 710 | 710 |
//\todo better 'epsilon' would be nice here. |
| 711 | 711 |
if(max_w>EPSILON) {
|
| 712 | 712 |
_arcWidthScale/=max_w; |
| 713 | 713 |
} |
| 714 | 714 |
} |
| 715 | 715 |
|
| 716 | 716 |
if (_autoNodeScale) {
|
| 717 | 717 |
double max_s=0; |
| 718 | 718 |
for(NodeIt n(g);n!=INVALID;++n) |
| 719 | 719 |
max_s=std::max(double(_nodeSizes[n]),max_s); |
| 720 | 720 |
//\todo better 'epsilon' would be nice here. |
| 721 | 721 |
if(max_s>EPSILON) {
|
| 722 | 722 |
_nodeScale/=max_s; |
| 723 | 723 |
} |
| 724 | 724 |
} |
| 725 | 725 |
|
| 726 | 726 |
double diag_len = 1; |
| 727 | 727 |
if(!(_absoluteNodeSizes&&_absoluteArcWidths)) {
|
| 728 |
dim2:: |
|
| 728 |
dim2::Box<double> bb; |
|
| 729 | 729 |
for(NodeIt n(g);n!=INVALID;++n) bb.add(mycoords[n]); |
| 730 | 730 |
if (bb.empty()) {
|
| 731 |
bb = dim2:: |
|
| 731 |
bb = dim2::Box<double>(dim2::Point<double>(0,0)); |
|
| 732 | 732 |
} |
| 733 | 733 |
diag_len = std::sqrt((bb.bottomLeft()-bb.topRight()).normSquare()); |
| 734 | 734 |
if(diag_len<EPSILON) diag_len = 1; |
| 735 | 735 |
if(!_absoluteNodeSizes) _nodeScale*=diag_len; |
| 736 | 736 |
if(!_absoluteArcWidths) _arcWidthScale*=diag_len; |
| 737 | 737 |
} |
| 738 | 738 |
|
| 739 |
dim2:: |
|
| 739 |
dim2::Box<double> bb; |
|
| 740 | 740 |
for(NodeIt n(g);n!=INVALID;++n) {
|
| 741 | 741 |
double ns=_nodeSizes[n]*_nodeScale; |
| 742 | 742 |
dim2::Point<double> p(ns,ns); |
| 743 | 743 |
switch(_nodeShapes[n]) {
|
| 744 | 744 |
case CIRCLE: |
| 745 | 745 |
case SQUARE: |
| 746 | 746 |
case DIAMOND: |
| 747 | 747 |
bb.add(p+mycoords[n]); |
| 748 | 748 |
bb.add(-p+mycoords[n]); |
| 749 | 749 |
break; |
| 750 | 750 |
case MALE: |
| 751 | 751 |
bb.add(-p+mycoords[n]); |
| 752 | 752 |
bb.add(dim2::Point<double>(1.5*ns,1.5*std::sqrt(3.0)*ns)+mycoords[n]); |
| 753 | 753 |
break; |
| 754 | 754 |
case FEMALE: |
| 755 | 755 |
bb.add(p+mycoords[n]); |
| 756 | 756 |
bb.add(dim2::Point<double>(-ns,-3.01*ns)+mycoords[n]); |
| 757 | 757 |
break; |
| 758 | 758 |
} |
| 759 | 759 |
} |
| 760 | 760 |
if (bb.empty()) {
|
| 761 |
bb = dim2:: |
|
| 761 |
bb = dim2::Box<double>(dim2::Point<double>(0,0)); |
|
| 762 | 762 |
} |
| 763 | 763 |
|
| 764 | 764 |
if(_scaleToA4) |
| 765 | 765 |
os <<"%%BoundingBox: 0 0 596 842\n%%DocumentPaperSizes: a4\n"; |
| 766 | 766 |
else {
|
| 767 | 767 |
if(_preScale) {
|
| 768 | 768 |
//Rescale so that BoundingBox won't be neither to big nor too small. |
| 769 | 769 |
while(bb.height()*_scale>1000||bb.width()*_scale>1000) _scale/=10; |
| 770 | 770 |
while(bb.height()*_scale<100||bb.width()*_scale<100) _scale*=10; |
| 771 | 771 |
} |
| 772 | 772 |
|
| 773 | 773 |
os << "%%BoundingBox: " |
| 774 | 774 |
<< int(floor(bb.left() * _scale - _xBorder)) << ' ' |
| 775 | 775 |
<< int(floor(bb.bottom() * _scale - _yBorder)) << ' ' |
| 776 | 776 |
<< int(ceil(bb.right() * _scale + _xBorder)) << ' ' |
| 777 | 777 |
<< int(ceil(bb.top() * _scale + _yBorder)) << '\n'; |
| 778 | 778 |
} |
| 779 | 779 |
|
| 780 | 780 |
os << "%%EndComments\n"; |
| 781 | 781 |
|
| 782 | 782 |
//x1 y1 x2 y2 x3 y3 cr cg cb w |
| 783 | 783 |
os << "/lb { setlinewidth setrgbcolor newpath moveto\n"
|
| 784 | 784 |
<< " 4 2 roll 1 index 1 index curveto stroke } bind def\n"; |
| 785 | 785 |
os << "/l { setlinewidth setrgbcolor newpath moveto lineto stroke }"
|
| ... | ... |
@@ -29,59 +29,59 @@ |
| 29 | 29 |
|
| 30 | 30 |
Point p; |
| 31 | 31 |
check(p.size()==2, "Wrong dim2::Point initialization."); |
| 32 | 32 |
|
| 33 | 33 |
Point a(1,2); |
| 34 | 34 |
Point b(3,4); |
| 35 | 35 |
check(a[0]==1 && a[1]==2, "Wrong dim2::Point initialization."); |
| 36 | 36 |
|
| 37 | 37 |
p = a+b; |
| 38 | 38 |
check(p.x==4 && p.y==6, "Wrong dim2::Point addition."); |
| 39 | 39 |
|
| 40 | 40 |
p = a-b; |
| 41 | 41 |
check(p.x==-2 && p.y==-2, "Wrong dim2::Point subtraction."); |
| 42 | 42 |
|
| 43 | 43 |
check(a.normSquare()==5,"Wrong dim2::Point norm calculation."); |
| 44 | 44 |
check(a*b==11, "Wrong dim2::Point scalar product."); |
| 45 | 45 |
|
| 46 | 46 |
int l=2; |
| 47 | 47 |
p = a*l; |
| 48 | 48 |
check(p.x==2 && p.y==4, "Wrong dim2::Point multiplication by a scalar."); |
| 49 | 49 |
|
| 50 | 50 |
p = b/l; |
| 51 | 51 |
check(p.x==1 && p.y==2, "Wrong dim2::Point division by a scalar."); |
| 52 | 52 |
|
| 53 |
typedef dim2::BoundingBox<int> BB; |
|
| 54 |
BB box1; |
|
| 55 |
|
|
| 53 |
typedef dim2::Box<int> Box; |
|
| 54 |
Box box1; |
|
| 55 |
check(box1.empty(), "Wrong empty() in dim2::Box."); |
|
| 56 | 56 |
|
| 57 | 57 |
box1.add(a); |
| 58 |
check(!box1.empty(), "Wrong empty() in dim2:: |
|
| 58 |
check(!box1.empty(), "Wrong empty() in dim2::Box."); |
|
| 59 | 59 |
box1.add(b); |
| 60 | 60 |
|
| 61 | 61 |
check(box1.left()==1 && box1.bottom()==2 && |
| 62 | 62 |
box1.right()==3 && box1.top()==4, |
| 63 |
"Wrong addition of points to dim2:: |
|
| 63 |
"Wrong addition of points to dim2::Box."); |
|
| 64 | 64 |
|
| 65 |
check(box1.inside(Point(2,3)), "Wrong inside() in dim2::BoundingBox."); |
|
| 66 |
check(box1.inside(Point(1,3)), "Wrong inside() in dim2::BoundingBox."); |
|
| 67 |
check( |
|
| 65 |
check(box1.inside(Point(2,3)), "Wrong inside() in dim2::Box."); |
|
| 66 |
check(box1.inside(Point(1,3)), "Wrong inside() in dim2::Box."); |
|
| 67 |
check(!box1.inside(Point(0,3)), "Wrong inside() in dim2::Box."); |
|
| 68 | 68 |
|
| 69 |
BB box2(Point(2,2)); |
|
| 70 |
check(!box2.empty(), "Wrong empty() in dim2::BoundingBox."); |
|
| 69 |
Box box2(Point(2,2)); |
|
| 70 |
check(!box2.empty(), "Wrong empty() in dim2::Box."); |
|
| 71 | 71 |
|
| 72 | 72 |
box2.bottomLeft(Point(2,0)); |
| 73 | 73 |
box2.topRight(Point(5,3)); |
| 74 |
|
|
| 74 |
Box box3 = box1 & box2; |
|
| 75 | 75 |
check(!box3.empty() && |
| 76 | 76 |
box3.left()==2 && box3.bottom()==2 && |
| 77 | 77 |
box3.right()==3 && box3.top()==3, |
| 78 |
"Wrong intersection of two dim2:: |
|
| 78 |
"Wrong intersection of two dim2::Box objects."); |
|
| 79 | 79 |
|
| 80 | 80 |
box1.add(box2); |
| 81 | 81 |
check(!box1.empty() && |
| 82 | 82 |
box1.left()==1 && box1.bottom()==0 && |
| 83 | 83 |
box1.right()==5 && box1.top()==4, |
| 84 |
"Wrong addition of two dim2:: |
|
| 84 |
"Wrong addition of two dim2::Box objects."); |
|
| 85 | 85 |
|
| 86 | 86 |
return 0; |
| 87 | 87 |
} |
0 comments (0 inline)