Merging from trunk
[ardour.git] / libs / cassowary / ClBug0.cc
1 // $Id$
2
3 #include <cassowary/Cl.h>
4
5 /* This bug fixed --02/15/99 gjb
6    Replaced the parallel vectors for edit constraints
7    (the errorPlus..., errorMinus..., prevEditConstants vectors)
8    with a ClEditInfo class that is the Value of the _editVarMap map.
9    
10    Later I realized that I need to go to a _editVars list so that
11    multiple edits on the same variable that nest are handled properly.
12    --09/19/99 gjb
13 */
14
15 int main()
16 {
17   ClSimplexSolver solver;
18
19   ClVariable x("x",7);
20   ClVariable y("y",8);
21   ClVariable z("z",9);
22
23   solver
24     .AddStay(x)
25     .AddStay(y)
26     .AddStay(z);
27
28   try {
29     solver.AddEditVar(x);
30     solver.AddEditVar(y);
31     solver.AddEditVar(z);
32     solver.BeginEdit();
33     
34     solver.SuggestValue(x,1);
35     solver.SuggestValue(z,2);
36     
37     solver.RemoveEditVar(y);
38
39     solver.SuggestValue(x,3);
40     solver.SuggestValue(z,4);
41
42     solver.EndEdit();
43     
44   } catch (ExCLError &e) {
45     cerr << e.description() << endl;
46   }
47
48   cout << x << endl << y << endl << z <<endl;
49
50 }
51
52 #if 0 /* Message below */
53  From: "Michael Kaufmann" <Michael.Kaufmann@ubs.com> 
54  To: <noth@cs.washington.edu> 
55  Subject: bugreport 
56  Date: Thu, 1 Oct 1998 11:40:55 +0200 
57  Message-Id: <000001bded1f$973a2060$230e1fac@itc_mk.sbcs.swissbank.com> 
58  Mime-Version: 1.0 
59  Content-Type: text/plain; 
60        charset="iso-8859-1" 
61  Content-Transfer-Encoding: 7bit 
62  X-Priority: 3 (Normal) 
63  X-Msmail-Priority: Normal 
64  X-Mailer: Microsoft Outlook 8.5, Build 4.71.2173.0 
65  Importance: Normal 
66  X-Mimeole: Produced By Microsoft MimeOLE V4.72.2106.4 
67   
68  Dear Mr Noth, 
69   
70  I am currently working with the Java implementation of Cassowary and found 
71  the following bug: 
72   
73  If I Add several editConstraints, remove some of them again later and 
74  perform a 'ClSimplexSolver.SuggestValue()', the indices of 
75  'ClConstraintAndIndex' in the variable 'cai' are sometimes wrong (see 
76  ClSimplexSolver.SuggestValue(ClVariable v, double x), the 3rd line). This is 
77  because if you remove an element from a 'java.util.Vector', and the element 
78  is somewhere in the middle of the Vector, the indices of the Vector change. 
79  (see java.util.Vector.removeElementAt(int index): 
80   
81      public final synchronized void removeElementAt(int index) { 
82        if (index >= elementCount) { 
83            throw new ArrayIndexOutOfBoundsException(index + " >= " + 
84                                                     elementCount); 
85        } 
86        else if (index < 0) { 
87            throw new ArrayIndexOutOfBoundsException(index); 
88        } 
89        int j = elementCount - index - 1; 
90        if (j > 0) { 
91            System.arraycopy(elementData, index + 1, elementData, index, j); 
92        } 
93        elementCount--; 
94        elementData[elementCount] = null; /* to let gc do its work */ 
95      } 
96   
97   
98  My workaround now is, that everytime when I remove an EditVariable from the 
99  Solver, I have to remove all the EditVariables and Add then the ones again, 
100  that I do not want to remove. 
101   
102 #endif