-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCL.java
136 lines (104 loc) · 4.4 KB
/
CL.java
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
// $Id$
//
// Cassowary Incremental Constraint Solver
// Original Smalltalk Implementation by Alan Borning
// This Java Implementation by Greg J. Badros, <[email protected]>
// http://www.cs.washington.edu/homes/gjb
// (C) 1998, 1999 Greg J. Badros and Alan Borning
// See ../LICENSE for legal details regarding this software
//
// CL.java
// The enumerations from ClLinearInequality,
// and `global' functions that we want easy to access
package EDU.Washington.grad.gjb.cassowary;
public class CL {
protected final static boolean fDebugOn = false;
public static boolean fTraceOn = false; //true;
protected final static boolean fTraceAdded = false;
protected final static boolean fGC = false;
protected static void debugprint(String s)
{ System.err.println(s); }
protected static void traceprint(String s)
{ System.err.println(s); }
protected static void fnenterprint(String s)
{ System.err.println("* " + s); }
protected static void fnexitprint(String s)
{ System.err.println("- " + s); }
protected void assert(boolean f,String description) throws ExCLInternalError
{
if (!f) {
throw new ExCLInternalError("Assertion failed:" + description);
}
}
protected void assert(boolean f) throws ExCLInternalError
{
if (!f) {
throw new ExCLInternalError("Assertion failed");
}
}
public static final byte GEQ = 1;
public static final byte LEQ = 2;
public static ClLinearExpression Plus(ClLinearExpression e1, ClLinearExpression e2)
{ return e1.plus(e2); }
public static ClLinearExpression Plus(ClLinearExpression e1, double e2)
{ return e1.plus(new ClLinearExpression(e2)); }
public static ClLinearExpression Plus(double e1, ClLinearExpression e2)
{ return (new ClLinearExpression(e1)).plus(e2); }
public static ClLinearExpression Plus(ClVariable e1, ClLinearExpression e2)
{ return (new ClLinearExpression(e1)).plus(e2); }
public static ClLinearExpression Plus(ClLinearExpression e1, ClVariable e2)
{ return e1.plus(new ClLinearExpression(e2)); }
public static ClLinearExpression Plus(ClVariable e1, double e2)
{ return (new ClLinearExpression(e1)).plus(new ClLinearExpression(e2)); }
public static ClLinearExpression Plus(double e1, ClVariable e2)
{ return (new ClLinearExpression(e1)).plus(new ClLinearExpression(e2)); }
public static ClLinearExpression Minus(ClLinearExpression e1, ClLinearExpression e2)
{ return e1.minus(e2); }
public static ClLinearExpression Minus(double e1, ClLinearExpression e2)
{ return (new ClLinearExpression(e1)).minus(e2); }
public static ClLinearExpression Minus(ClLinearExpression e1, double e2)
{ return e1.minus(new ClLinearExpression(e2)); }
public static ClLinearExpression Times(ClLinearExpression e1, ClLinearExpression e2)
throws ExCLNonlinearExpression
{ return e1.times(e2); }
public static ClLinearExpression Times(ClLinearExpression e1, ClVariable e2)
throws ExCLNonlinearExpression
{ return e1.times(new ClLinearExpression(e2)); }
public static ClLinearExpression Times(ClVariable e1, ClLinearExpression e2)
throws ExCLNonlinearExpression
{ return (new ClLinearExpression(e1)).times(e2); }
public static ClLinearExpression Times(ClLinearExpression e1, double e2)
throws ExCLNonlinearExpression
{ return e1.times(new ClLinearExpression(e2)); }
public static ClLinearExpression Times(double e1, ClLinearExpression e2)
throws ExCLNonlinearExpression
{ return (new ClLinearExpression(e1)).times(e2); }
public static ClLinearExpression Times(double n, ClVariable clv)
throws ExCLNonlinearExpression
{ return (new ClLinearExpression(clv,n)); }
public static ClLinearExpression Times( ClVariable clv, double n)
throws ExCLNonlinearExpression
{ return (new ClLinearExpression(clv,n)); }
public static ClLinearExpression Divide(ClLinearExpression e1, ClLinearExpression e2)
throws ExCLNonlinearExpression
{ return e1.divide(e2); }
public static boolean approx(double a, double b)
{
double epsilon = 1.0e-8;
if (a == 0.0) {
return (Math.abs(b) < epsilon);
} else if (b == 0.0) {
return (Math.abs(a) < epsilon);
} else {
return (Math.abs(a-b) < Math.abs(a) * epsilon);
}
}
public static boolean approx(ClVariable clv, double b)
{
return approx(clv.value(),b);
}
static boolean approx(double a, ClVariable clv)
{
return approx(a,clv.value());
}
}