Code

Missed a win32 fix.
[inkscape.git] / src / libvpsc / constraint.cpp
1 /**
2  * \brief A constraint determines a minimum or exact spacing required between
3  * two variables.
4  *
5  * Authors:
6  *   Tim Dwyer <tgdwyer@gmail.com>
7  *
8  * Copyright (C) 2005 Authors
9  *
10  * Released under GNU LGPL.  Read the file 'COPYING' for more information.
11  */
13 #include "constraint.h"
14 #include <cassert>
15 namespace vpsc {
16 Constraint::Constraint(Variable *left, Variable *right, double gap, bool equality)
17 : left(left),
18   right(right),
19   gap(gap),
20   timeStamp(0),
21   active(false),
22   visited(false),
23   equality(equality)
24 {
25         left->out.push_back(this);
26         right->in.push_back(this);
27 }
28 Constraint::~Constraint() {
29         Constraints::iterator i;
30         for(i=left->out.begin(); i!=left->out.end(); i++) {
31                 if(*i==this) break;
32         }
33         left->out.erase(i);
34         for(i=right->in.begin(); i!=right->in.end(); i++) {
35                 if(*i==this) break;
36         }
37         right->in.erase(i);
38 }
39 std::ostream& operator <<(std::ostream &os, const Constraint &c)
40 {
41         if(&c==NULL) {
42                 os<<"NULL";
43         } else {
44                 const char *type=c.equality?"=":"<=";
45                 os<<*c.left<<"+"<<c.gap<<type<<*c.right<<"("<<c.slack()<<")"<<(c.active?"-active":"");
46         }
47         return os;
48 }
49 }