-
Notifications
You must be signed in to change notification settings - Fork 0
/
term.go
60 lines (45 loc) · 1.41 KB
/
term.go
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
// Copyright 2016 The Chromium Authors, 2018 Elco Industrie Automation GmbH. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package cassowary
var _ EquationMember = &Term{}
type Term struct {
variable *Variable
coefficient float64
}
func NewTerm(v *Variable, c float64) *Term {
return &Term{
v,
c,
}
}
func (term *Term) Value() float64 {
return term.coefficient * term.variable.Value
}
func (term *Term) IsConstant() bool {
return false
}
func (term *Term) asExpression() *Expression {
return NewExpression([]*Term{NewTerm(term.variable, term.coefficient)}, 0.0)
}
func (term *Term) Add(member EquationMember) *Expression {
return term.asExpression().Add(member)
}
func (term *Term) Sub(member EquationMember) *Expression {
return term.asExpression().Sub(member)
}
func (term *Term) Div(member EquationMember) *Expression {
return term.asExpression().Div(member)
}
func (term *Term) Mult(member EquationMember) *Expression {
return term.asExpression().Mult(member)
}
func (term *Term) GreaterThanOrEqualTo(m EquationMember) *Constraint {
return term.asExpression().GreaterThanOrEqualTo(m)
}
func (term *Term) LessThanOrEqualTo(m EquationMember) *Constraint {
return term.asExpression().LessThanOrEqualTo(m)
}
func (term *Term) Equals(member EquationMember) *Constraint {
return term.asExpression().createConstraint(member, EqualTo)
}