summaryrefslogtreecommitdiff
path: root/libs/cassowary/ClBug2.cc
blob: 3a1e424259bca8e60e176a2407d59729c0af9995 (plain)
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
/* $Id$

From: "Anthony Beurive'" <beurive@labri.u-bordeaux.fr> 
Subject: cassowary 
To: gjb@cs.washington.edu 
Date: Tue, 9 Mar 1999 12:42:24 +0100 (CET) 

I believe there's a bug in cassowary.  It seems to be related to the 
previous one I encountered a while ago, concerning the removal of 
constraints. 
 
The three following examples may help you to track the bug, I hope. 
 
-------------------------------------------------------------------------------- 
#include "Cl.h" 
 
void main() 
{ 
  ClSimplexSolver *solver = new ClSimplexSolver(); 
  ClVariable *var = new ClVariable(); 
  ClStayConstraint *stcn = new ClStayConstraint(*var,ClsWeak(),1.0); 
 
  solver->AddConstraint(*stcn); 
  cout << *solver; 
  solver->RemoveConstraint(*stcn); 
  cout << *solver; 
} 
-------------------------------------------------------------------------------- 
This works fine. 
 
 
Now, the factor of the stay constraint is changed. 
-------------------------------------------------------------------------------- 
#include "Cl.h" 
 
void main() 
{ 
  ClSimplexSolver *solver = new ClSimplexSolver(); 
  ClVariable *var = new ClVariable(); 
  ClStayConstraint *stcn = new ClStayConstraint(*var,ClsWeak(),2.0); 
 
  solver->AddConstraint(*stcn); 
  cout << *solver; 
  solver->RemoveConstraint(*stcn); 
  cout << *solver; 
} 
-------------------------------------------------------------------------------- 
The result is: 
test2: ClSimplexSolver.cc:1199: void ClSimplexSolver::Optimize(class ClVariable): Assertion \
`pzRow != __null' failed. 
Aborted 
 
 
Now, the solver is created after the variable. 
-------------------------------------------------------------------------------- 
#include "Cl.h" 
 
void main() 
{ 
  ClVariable *var = new ClVariable(); 
  ClSimplexSolver *solver = new ClSimplexSolver(); 
  ClStayConstraint *stcn = new ClStayConstraint(*var,ClsWeak(),2.0); 
 
  solver->AddConstraint(*stcn); 
  cout << *solver; 
  solver->RemoveConstraint(*stcn); 
  cout << *solver; 
} 
-------------------------------------------------------------------------------- 
This works again. 
 
 
Can you reproduce the same results?  Maybe the cause is my c++ 
compiler (egcs-2.90.29 980515 (egcs-1.0.3 release)).  I don't know. 

*/

#include <cassowary/Cl.h>

void foo1() 
{ 
  ClSimplexSolver *solver = new ClSimplexSolver(); 
  ClVariable *var = new ClVariable(); 
  ClStayConstraint *stcn = new ClStayConstraint(*var,ClsWeak(),1.0); 
 
  solver->AddConstraint(*stcn); 
  cout << *solver; 
  solver->RemoveConstraint(*stcn); 
  cout << *solver; 
} 


void foo2() 
{ 
  ClSimplexSolver *solver = new ClSimplexSolver(); 
  ClVariable *var = new ClVariable(); 
  ClStayConstraint *stcn = new ClStayConstraint(*var,ClsWeak(),2.0); 
 
  solver->AddConstraint(*stcn); 
  cout << *solver; 
  solver->RemoveConstraint(*stcn); 
  cout << *solver; 
} 


void foo3() 
{ 
  ClVariable *var = new ClVariable(); 
  ClSimplexSolver *solver = new ClSimplexSolver(); 
  ClStayConstraint *stcn = new ClStayConstraint(*var,ClsWeak(),2.0); 
 
  solver->AddConstraint(*stcn); 
  cout << *solver; 
  solver->RemoveConstraint(*stcn); 
  cout << *solver; 
} 


int main()
{
  cerr << "Test1: " << endl;
  foo1();

  cerr << "\nTest2: " << endl;
  foo2();

  cerr << "\nTest3: " << endl;
  foo3();

}