float convert_numeric(const variant& node) { if(node.is_int()) { return clamp<int>(node.as_int32(), 0, 255) / 255.0f; } else if(node.is_float()) { return clamp<float>(node.as_float(), 0.0f, 1.0f); } else if(node.is_string()) { return convert_string_to_number(node.as_string()); } ASSERT_LOG(false, "attribute of Color value was expected to be numeric type."); return 1.0f; }
bool color_from_basic_string(const std::string& colstr, Color* color) { float value[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; auto buf = split(colstr, ",| |;"); if(buf.size() == 0) { return false; } unsigned n = 0; for(auto& s : buf) { value[n] = convert_string_to_number(s); if(++n >= 4) { break; } } *color = Color(value[0], value[1], value[2], value[3]); return true; }
bool color_from_hsv_string(const std::string& colstr, Color* color) { if(colstr.empty()) { return false; } if(colstr.size() > 5 && colstr.substr(0,4) == "hsv(") { float hsv_col[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; auto buf = split(colstr, ",| |;"); unsigned n = 0; for(auto& s : buf) { hsv_col[n] = convert_string_to_number(s); if(++n >= 4) { break; } } *color = Color::from_hsv(hsv_col[0], hsv_col[1], hsv_col[2], hsv_col[3]); return true; } return false; }
/* {{{ proto double floor(double number) Returns the next lowest integer value from the number */ void php3_floor(INTERNAL_FUNCTION_PARAMETERS) { pval *value; TLS_VARS; if (ARG_COUNT(ht)!=1||getParameters(ht,1,&value)==FAILURE) { WRONG_PARAM_COUNT; } if (value->type == IS_STRING) { convert_string_to_number(value); } if (value->type == IS_DOUBLE) { RETURN_DOUBLE(floor(value->value.dval)); } else if (value->type == IS_LONG) { RETURN_LONG(value->value.lval); } RETURN_FALSE; }
/* {{{ proto int round(double number) Returns the rounded value of the number */ void php3_round(INTERNAL_FUNCTION_PARAMETERS) { pval *value; TLS_VARS; if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &value) == FAILURE) { WRONG_PARAM_COUNT; } if (value->type == IS_STRING) { convert_string_to_number(value); } if (value->type == IS_DOUBLE) { double d; d=rint(value->value.dval); if(d==0.0) d=0.0; /* workaround for rint() returning -0 instead of 0 */ RETURN_DOUBLE(d); } if (value->type == IS_LONG) { RETURN_DOUBLE((double)value->value.lval); } RETURN_FALSE; }