Skip to content

Commit

Permalink
Fixed|libdeng2|OperatorRule: Broken Double operator, added clamped
Browse files Browse the repository at this point in the history
The Half and Double operators are now used when dividing/multiplying
by 2.
  • Loading branch information
skyjake committed Jun 20, 2013
1 parent 175cbaa commit 1cf1ad1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
33 changes: 30 additions & 3 deletions doomsday/libdeng2/include/de/widgets/operatorrule.h
Expand Up @@ -61,6 +61,14 @@ class DENG2_PUBLIC OperatorRule : public Rule
return *refless(new OperatorRule(Minimum, left, right));
}

static OperatorRule &floor(Rule const &unary) {
return *refless(new OperatorRule(Floor, unary));
}

static OperatorRule &clamped(Rule const &value, Rule const &low, Rule const &high) {
return OperatorRule::minimum(OperatorRule::maximum(value, low), high);
}

protected:
~OperatorRule();

Expand Down Expand Up @@ -102,6 +110,24 @@ inline OperatorRule &operator - (Rule const &left, Rule const &right) {
return *refless(new OperatorRule(OperatorRule::Subtract, left, right));
}

inline OperatorRule &operator * (int left, Rule const &right) {
if(left == 2) {
return *refless(new OperatorRule(OperatorRule::Double, right));
}
return *refless(new OperatorRule(OperatorRule::Multiply, Const(left), right));
}

inline OperatorRule &operator * (Rule const &left, int right) {
if(right == 2) {
return *refless(new OperatorRule(OperatorRule::Double, left));
}
return *refless(new OperatorRule(OperatorRule::Multiply, left, Constf(right)));
}

inline OperatorRule &operator * (float left, Rule const &right) {
return *refless(new OperatorRule(OperatorRule::Multiply, Constf(left), right));
}

inline OperatorRule &operator * (Rule const &left, float right) {
return *refless(new OperatorRule(OperatorRule::Multiply, left, Constf(right)));
}
Expand All @@ -111,9 +137,10 @@ inline OperatorRule &operator * (Rule const &left, Rule const &right) {
}

inline OperatorRule &operator / (Rule const &left, int right) {
return *refless(new OperatorRule(OperatorRule::Floor,
*refless(new OperatorRule(OperatorRule::Divide,
left, Const(right)))));
if(right == 2) {
return OperatorRule::floor(*refless(new OperatorRule(OperatorRule::Half, left)));
}
return OperatorRule::floor(*refless(new OperatorRule(OperatorRule::Divide, left, Const(right))));
}

inline OperatorRule &operator / (Rule const &left, float right) {
Expand Down
1 change: 1 addition & 0 deletions doomsday/libdeng2/src/widgets/operatorrule.cpp
Expand Up @@ -68,6 +68,7 @@ void OperatorRule::update()

case Double:
v = leftValue * 2;
break;

case Sum:
v = leftValue + rightValue;
Expand Down

0 comments on commit 1cf1ad1

Please sign in to comment.