Commit d12389e7 by Aaron Leung

Simplifying the numeric_value method slightly; no reason to return a reference.

parent c83420f6
...@@ -187,11 +187,11 @@ namespace Sass { ...@@ -187,11 +187,11 @@ namespace Sass {
Node invert(const vector<Token>& parameters, map<Token, Node>& bindings, Node_Factory& new_Node) { Node invert(const vector<Token>& parameters, map<Token, Node>& bindings, Node_Factory& new_Node) {
Node orig(bindings[parameters[0]]); Node orig(bindings[parameters[0]]);
if (orig.type() != Node::numeric_color) throw_eval_error("argument to invert must be a color", orig.line_number, orig.file_name); if (orig.type() != Node::numeric_color) throw_eval_error("argument to invert must be a color", orig.line_number, orig.file_name);
return Node(new_Node, orig.line_number, return new_Node(orig.path(), orig.line(),
255 - orig[0].numeric_value(), 255 - orig[0].numeric_value(),
255 - orig[1].numeric_value(), 255 - orig[1].numeric_value(),
255 - orig[2].numeric_value(), 255 - orig[2].numeric_value(),
orig[3].numeric_value()); orig[3].numeric_value());
} }
// Opacity Functions /////////////////////////////////////////////////// // Opacity Functions ///////////////////////////////////////////////////
...@@ -211,16 +211,19 @@ namespace Sass { ...@@ -211,16 +211,19 @@ namespace Sass {
Function_Descriptor fade_in_descriptor = Function_Descriptor fade_in_descriptor =
{ "fade_in", "$color", "$amount", 0 }; { "fade_in", "$color", "$amount", 0 };
Node opacify(const vector<Token>& parameters, map<Token, Node>& bindings, Node_Factory& new_Node) { Node opacify(const vector<Token>& parameters, map<Token, Node>& bindings, Node_Factory& new_Node) {
Node cpy(new_Node(bindings[parameters[0]])); Node color(bindings[parameters[0]]);
if (cpy.type() != Node::numeric_color || !bindings[parameters[1]].is_numeric()) {
throw_eval_error("arguments to opacify/fade_in must be a color and a numeric value", cpy.path(), cpy.line());
}
Node delta(bindings[parameters[1]]); Node delta(bindings[parameters[1]]);
if (delta.numeric_value() < 0 || delta.numeric_value() > 1) throw_eval_error("amount must be between 0 and 1 for opacify/fade-in", delta.path(), delta.line()); if (color.type() != Node::numeric_color || !delta.is_numeric()) {
cpy[3].numeric_value() += delta.numeric_value(); throw_eval_error("arguments to opacify/fade_in must be a color and a numeric value", color.path(), color.line());
if (cpy[3].numeric_value() > 1) cpy[3].numeric_value() = 1; }
if (cpy[3].numeric_value() < 0) cpy[3].numeric_value() = 0; if (delta.numeric_value() < 0 || delta.numeric_value() > 1) {
return cpy; throw_eval_error("amount must be between 0 and 1 for opacify/fade-in", delta.path(), delta.line());
}
double alpha = orig[3].numeric_value() + delta.numeric_value();
if (alpha > 1) alpha = 1;
else if (alpha < 0) alpha = 0;
return new_Node(orig.path(), orig.line(),
orig[0].numeric_value(), orig[1].numeric_value(), orig[2].numeric_value(), alpha);
} }
Function_Descriptor transparentize_descriptor = Function_Descriptor transparentize_descriptor =
...@@ -228,16 +231,19 @@ namespace Sass { ...@@ -228,16 +231,19 @@ namespace Sass {
Function_Descriptor fade_out_descriptor = Function_Descriptor fade_out_descriptor =
{ "fade_out", "$color", "$amount", 0 }; { "fade_out", "$color", "$amount", 0 };
Node transparentize(const vector<Token>& parameters, map<Token, Node>& bindings, Node_Factory& new_Node) { Node transparentize(const vector<Token>& parameters, map<Token, Node>& bindings, Node_Factory& new_Node) {
Node cpy(new_Node(bindings[parameters[0]])); Node color(bindings[parameters[0]]);
if (cpy.type() != Node::numeric_color || !bindings[parameters[1]].is_numeric()) {
throw_eval_error("arguments to transparentize/fade_out must be a color and a numeric value", cpy.path(), cpy.line());
}
Node delta(bindings[parameters[1]]); Node delta(bindings[parameters[1]]);
if (delta.numeric_value() < 0 || delta.numeric_value() > 1) throw_eval_error("amount must be between 0 and 1 for transparentize/fade-out", delta.path(), delta.line()); if (color.type() != Node::numeric_color || !delta.is_numeric()) {
cpy[3].numeric_value() -= delta.numeric_value(); throw_eval_error("arguments to transparentize/fade_out must be a color and a numeric value", orig.path(), orig.line());
if (cpy[3].numeric_value() > 1) cpy[3].numeric_value() = 1; }
if (cpy[3].numeric_value() < 0) cpy[3].numeric_value() = 0; if (delta.numeric_value() < 0 || delta.numeric_value() > 1) {
return cpy; throw_eval_error("amount must be between 0 and 1 for transparentize/fade-out", delta.path(), delta.line());
}
double alpha = orig[3].numeric_value() - delta.numeric_value();
if (alpha > 1) alpha = 1;
else if (alpha < 0) alpha = 0;
return new_Node(orig.path(), orig.line(),
orig[0].numeric_value(), orig[1].numeric_value(), orig[2].numeric_value(), alpha);
} }
// String Functions //////////////////////////////////////////////////// // String Functions ////////////////////////////////////////////////////
......
...@@ -213,7 +213,7 @@ namespace Sass { ...@@ -213,7 +213,7 @@ namespace Sass {
// Node_Impl method implementations // Node_Impl method implementations
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
double& Node_Impl::numeric_value() double Node_Impl::numeric_value()
{ {
switch (type) switch (type)
{ {
......
...@@ -178,7 +178,7 @@ namespace Sass { ...@@ -178,7 +178,7 @@ namespace Sass {
Node& operator+=(Node n); Node& operator+=(Node n);
bool& boolean_value() const; bool& boolean_value() const;
double& numeric_value() const; double numeric_value() const;
Token token() const; Token token() const;
Token unit() const; Token unit() const;
...@@ -272,7 +272,7 @@ namespace Sass { ...@@ -272,7 +272,7 @@ namespace Sass {
bool& boolean_value() bool& boolean_value()
{ return value.boolean; } { return value.boolean; }
double& numeric_value(); double numeric_value();
Token unit(); Token unit();
}; };
...@@ -323,7 +323,7 @@ namespace Sass { ...@@ -323,7 +323,7 @@ namespace Sass {
return *this; return *this;
} }
inline bool& Node::boolean_value() const { return ip_->boolean_value(); } inline bool& Node::boolean_value() const { return ip_->boolean_value(); }
inline double& Node::numeric_value() const { return ip_->numeric_value(); } inline double Node::numeric_value() const { return ip_->numeric_value(); }
inline Token Node::token() const { return ip_->value.token; } inline Token Node::token() const { return ip_->value.token; }
inline Token Node::unit() const { return ip_->unit(); } inline Token Node::unit() const { return ip_->unit(); }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment