VectorValue* CPropHelper::CreateAngle3 (PropItemVec& items, shared_str key, Fvector* val, float mn, float mx, float inc, int decim) { VectorValue* V = (VectorValue*) AppendValue (items,key,xr_new<VectorValue>(val,mn,mx,inc,decim),PROP_VECTOR); V->OnAfterEditEvent.bind (this,&CPropHelper::FvectorRDOnAfterEdit); V->OnBeforeEditEvent.bind (this,&CPropHelper::FvectorRDOnBeforeEdit); V->Owner()->OnDrawTextEvent.bind(this,&CPropHelper::FvectorRDOnDraw); return V; }
Value* NumberValue::operation(Value& v, Expression::Operator_e e) { NumberValue* num = dynamic_cast<NumberValue*>(&v); if(num) { if(isComparison(e)) { bool result=basicOperation<bool,double>(this->number,e,num->number); return new BooleanValue(result); } else { double result=basicOperation<double,double>(this->number,e,num->number); return new NumberValue(result); } } VectorValue* vec = dynamic_cast<VectorValue*>(&v); if(vec) { if(e==Expression::Concatenate) { QList<Value*> r=vec->getChildren(); r.prepend(this); return new VectorValue(r); } else { //operations between scalars and vectors are commutative e.g. // [1,2,3]-1 is the same as 1 - [1,2,3] return Value::operation(vec,e,this); } } return Value::operation(v,e); }
void ValueTraits<VectorValue>::Lerp(const VectorValue& v0, const VectorValue& v1, float t, VectorValue* result) { SkASSERT(v0.size() == v1.size()); result->resize(v0.size()); for (size_t i = 0; i < v0.size(); ++i) { ValueTraits<ScalarValue>::Lerp(v0[i], v1[i], t, &(*result)[i]); } }
SkColor ValueTraits<VectorValue>::As<SkColor>(const VectorValue& v) { // best effort to turn this into a color const auto r = v.size() > 0 ? v[0] : 0, g = v.size() > 1 ? v[1] : 0, b = v.size() > 2 ? v[2] : 0, a = v.size() > 3 ? v[3] : 1; return SkColorSetARGB(SkScalarRoundToInt(SkTPin(a, 0.0f, 1.0f) * 255), SkScalarRoundToInt(SkTPin(r, 0.0f, 1.0f) * 255), SkScalarRoundToInt(SkTPin(g, 0.0f, 1.0f) * 255), SkScalarRoundToInt(SkTPin(b, 0.0f, 1.0f) * 255)); }
SkColor ValueTraits<VectorValue>::As<SkColor>(const VectorValue& v) { // best effort to turn this into a color const auto r = v.size() > 0 ? v[0] : 0, g = v.size() > 1 ? v[1] : 0, b = v.size() > 2 ? v[2] : 0, a = v.size() > 3 ? v[3] : 1; return SkColorSetARGB(SkTPin<SkScalar>(a, 0, 1) * 255, SkTPin<SkScalar>(r, 0, 1) * 255, SkTPin<SkScalar>(g, 0, 1) * 255, SkTPin<SkScalar>(b, 0, 1) * 255); }
void Client::Receive() { SocketMessage msg; try { msg = FetchMessage(); } catch (Exception& e) { if (e.ErrorNumber()==11000) // client has been disconnected throw Exception(__PRETTY_FUNCTION__, "Some other socket asked for this client's disconnection. Obtemperating...", Fatal); } if (msg.GetKey()==MASTER_DISCONNECT) { throw Exception(__PRETTY_FUNCTION__, "Master disconnected!", Fatal); } else if (msg.GetKey()==OTHER_CLIENT_DELETED) { throw Exception(__PRETTY_FUNCTION__, "Some other socket asked for this client's disconnection. Obtemperating...", Fatal); } else if (msg.GetKey()==GET_CLIENT_TYPE) { Send(SocketMessage(CLIENT_TYPE, static_cast<int>(GetType()))); } else if (msg.GetKey()==PING_CLIENT) { std::ostringstream os; os << "Pong. My name is " << GetSocketId() << " and I feel fine, thank you!"; Send(SocketMessage(PING_ANSWER, os.str())); PrintInfo("Got a ping, answering..."); } else if (msg.GetKey()==CLIENTS_LIST) { VectorValue vals = msg.GetVectorValue(); int i = 0; std::ostringstream o; o << "List of members on the socket:\n\t"; for (VectorValue::const_iterator v=vals.begin(); v!=vals.end(); v++, i++) { if (i!=0) o << ", "; o << *v; } PrintInfo(o.str()); } else { ParseMessage(msg); } }
void upper_tether_force_function(VectorValue<double>& F, const TensorValue<double>& /*FF*/, const libMesh::Point& X, const libMesh::Point& s, Elem* const /*elem*/, const vector<NumericVector<double>*>& /*system_data*/, double /*time*/, void* /*ctx*/) { if (s(0) > 5.0 && s(0) < 10.0) { F.zero(); } else { F = kappa_s * (s - X); } return; } // upper_tether_force_function
// Tether (penalty) force function for the thin beam. void beam_tether_force_function(VectorValue<double>& F, const TensorValue<double>& /*FF*/, const libMesh::Point& X, const libMesh::Point& s, Elem* const /*elem*/, const vector<NumericVector<double>*>& /*system_data*/, double /*time*/, void* /*ctx*/) { const double r = sqrt((s(0) - 0) * (s(0) - 0)); if (r <= fixed_L) { F = kappa_s * (s - X); } else { F.zero(); } return; } // beam_tether_force_function
void beam_tether_force_function(VectorValue<double>& F, const TensorValue<double>& /*FF*/, const libMesh::Point& X, const libMesh::Point& s, Elem* const /*elem*/, const unsigned short int side, const vector<NumericVector<double>*>& /*system_data*/, double /*time*/, void* /*ctx*/) { if (side == 1 || side == 3) { F = beam_kappa_s * (s - X); } else { F.zero(); } return; } // beam_tether_force_function
SkPoint ValueTraits<VectorValue>::As<SkPoint>(const VectorValue& vec) { // best effort to turn this into a point const auto x = vec.size() > 0 ? vec[0] : 0, y = vec.size() > 1 ? vec[1] : 0; return SkPoint::Make(x, y); }
bool ValueTraits<VectorValue>::CanLerp(const VectorValue& v1, const VectorValue& v2) { return v1.size() == v2.size(); }
size_t ValueTraits<VectorValue>::Cardinality(const VectorValue& vec) { return vec.size(); }
bool Attributes::setValueFromRawString(const AttributeName_t& aName, const std::string& aValue) { if (isAttributeExist(aName)) { return false; } StringValue TmpStrValue(aValue); switch (TmpStrValue.guessTypeConversion()) { case Value::DOUBLE : { double TmpVal; if (!TmpStrValue.toDouble(TmpVal)) { return false; } m_Data[aName].reset(new DoubleValue(TmpVal)); break; } case Value::INTEGER : { long TmpVal; if (!TmpStrValue.toInteger(TmpVal)) { return false; } m_Data[aName].reset(new IntegerValue(TmpVal)); break; } case Value::BOOLEAN : { bool TmpVal; if (!TmpStrValue.toBoolean(TmpVal)) { return false; } m_Data[aName].reset(new BooleanValue(TmpVal)); break; } case Value::STRING : { m_Data[aName].reset(new StringValue(aValue)); break; } case Value::VECTOR : { VectorValue TmpVal; if (!TmpStrValue.toVectorValue(TmpVal)) { return false; } m_Data[aName].reset(TmpVal.clone()); break; } case Value::MATRIX : { MatrixValue TmpVal; if (!TmpStrValue.toMatrixValue(TmpVal)) { return false; } m_Data[aName].reset(TmpVal.clone()); break; } case Value::MAP : { MapValue TmpVal; if (!TmpStrValue.toMapValue(TmpVal)) { return false; } m_Data[aName].reset(TmpVal.clone()); break; } case Value::TREE : { TreeValue TmpVal; if (!TmpStrValue.toTreeValue(TmpVal)) { return false; } m_Data[aName].reset(TmpVal.clone()); break; } case Value::NULLL : { NullValue TmpVal; if (!TmpStrValue.toNullValue(TmpVal)) { return false; } m_Data[aName].reset(TmpVal.clone()); break; } default : return false; } return true; }