void CSVGAnimateColor:: animate(double t) { if (getAttributeName() == "fill") { CSVGColor fromColor, toColor; svg_.decodeColorString(getFrom(), fromColor); svg_.decodeColorString(getTo (), toColor ); CRGBA c = fromColor.rgba()*(1 - t) + toColor.rgba()*t; getParent()->setFillColor(c); svg_.redraw(); } else if (getAttributeName() == "stroke") { CSVGColor fromColor, toColor; svg_.decodeColorString(getFrom(), fromColor); svg_.decodeColorString(getTo (), toColor ); CRGBA c = fromColor.rgba()*(1 - t) + toColor.rgba()*t; getParent()->setStrokeColor(c); svg_.redraw(); } }
/** * Converts string to (@p direction = @c UTF8_TO) and from * (@p direction = @c UTF8_FROM) UTF-8. * * Since Elektra provides portability for key names and string values between * different codesets, you should use this helper in your backend to convert * to and from universal UTF-8 strings, when storing key names, values and * comments. * * Broken locales in applications can cause problems too. Make sure to load * the environment locales in your application using * @code setlocale (LC_ALL, ""); * @endcode * * Otherwise kdbbUTF8Engine and this plugin will quit * with error when non-ascii characters appear. * * Binary values are not effected. * * If iconv() or nl_langinfo() is not available on your system, or if iconv() * this plugin can't be used. * * @param direction must be @c UTF8_TO (convert from current non-UTF-8 to * UTF-8) or @c UTF8_FROM (convert from UTF-8 to current non-UTF-8) * @param string before the call: the string to be converted; after the call: * reallocated to carry the converted string * @param inputOutputByteSize before the call: the size of the string including * leading NULL; after the call: the size of the converted string including * leading NULL * @retval 0 on success * @retval -1 on failure * @ingroup backendhelper * */ int kdbbUTF8Engine (Plugin * handle, int direction, char ** string, size_t * inputOutputByteSize) { /* Current solution is not very complete. * Iconv might well be available when a usable nl_langinfo is not. * In this case we it should be possible to determine charset through other means * See http://www.cl.cam.ac.uk/~mgk25/unicode.html#activate for more info on a possible solution */ char * converted = 0; char *readCursor, *writeCursor; size_t bufferSize; iconv_t converter; if (!*inputOutputByteSize) return 0; if (!kdbbNeedsUTF8Conversion (handle)) return 0; if (direction == UTF8_TO) converter = iconv_open (getTo (handle), getFrom (handle)); else converter = iconv_open (getFrom (handle), getTo (handle)); if (converter == (iconv_t) (-1)) return -1; /* work with worst case, when all chars are wide */ bufferSize = *inputOutputByteSize * 4; converted = elektraMalloc (bufferSize); if (!converted) return -1; readCursor = *string; writeCursor = converted; /* On some systems and with libiconv, arg1 is const char **. * ICONV_CONST is defined by configure if the system needs this */ if (iconv (converter, &readCursor, inputOutputByteSize, &writeCursor, &bufferSize) == (size_t) (-1)) { elektraFree (converted); iconv_close (converter); return -1; } /* calculate the UTF-8 string byte size, that will be returned */ *inputOutputByteSize = writeCursor - converted; /* store the current kdbbDecoded string for future free */ readCursor = *string; /* allocate an optimal size area to store the converted string */ *string = elektraMalloc (*inputOutputByteSize); /* copy all that matters for returning */ memcpy (*string, converted, *inputOutputByteSize); /* release memory used by passed string */ elektraFree (readCursor); /* release buffer memory */ elektraFree (converted); /* release the conversor engine */ iconv_close (converter); return 0; }
int elektraIconvSet (Plugin * handle, KeySet * returned, Key * parentKey) { Key * cur; if (!kdbbNeedsUTF8Conversion (handle)) return 0; ksRewind (returned); while ((cur = ksNext (returned)) != 0) { if (keyIsString (cur)) { /* String or similar type of value */ size_t convertedDataSize = keyGetValueSize (cur); char * convertedData = elektraMalloc (convertedDataSize); memcpy (convertedData, keyString (cur), keyGetValueSize (cur)); if (kdbbUTF8Engine (handle, UTF8_TO, &convertedData, &convertedDataSize)) { ELEKTRA_SET_ERRORF (46, parentKey, "Could not convert string %s, got result %s," " encoding settings are from %s to %s (but swapped for write)", keyString (cur), convertedData, getFrom (handle), getTo (handle)); elektraFree (convertedData); return -1; } keySetString (cur, convertedData); elektraFree (convertedData); } const Key * meta = keyGetMeta (cur, "comment"); if (meta) { /* String or similar type of value */ size_t convertedDataSize = keyGetValueSize (meta); char * convertedData = elektraMalloc (convertedDataSize); memcpy (convertedData, keyString (meta), keyGetValueSize (meta)); if (kdbbUTF8Engine (handle, UTF8_TO, &convertedData, &convertedDataSize)) { ELEKTRA_SET_ERRORF (46, parentKey, "Could not convert string %s, got result %s," " encodings settings are from %s to %s (but swapped for write)", keyString (meta), convertedData, getFrom (handle), getTo (handle)); elektraFree (convertedData); return -1; } keySetMeta (cur, "comment", convertedData); elektraFree (convertedData); } } return 1; /* success */ }
void ImplAlignandum::shuffle( unsigned int num_iterations, Position window_size) { if (window_size == 0) window_size = getLength(); Position first_from = getFrom(); for (unsigned x = 0; x < num_iterations; ++x) { Position i,j; Position to = getTo(); while (to > first_from ) { Position from = to - window_size; if (from < 0) { from = 0; window_size = to; } for (i = to - 1; i >= from; --i) { j = to - getRandomPosition(window_size) - 1; swap( i, j ); } to -= window_size; } } }
StateMachineNode* AnimationStateMachine::next() { // 入ってきたノードに遷移するビヘイビアを探す. IZ_ASSERT(m_fromBehaviour != nullptr); auto from = m_fromBehaviour->getFrom(); IZ_ASSERT(from != nullptr); auto item = m_behaviours.GetTop(); while (item) { auto behaviour = item->GetData(); auto to = behaviour->getTo(); if (from == to) { return behaviour; } item = item->GetNext(); } IZ_ASSERT(IZ_FALSE); return nullptr; }
bool Move::isEquivalent(Move const& m) const { if(m.getTo()==getTo() && m.getFrom()==getFrom() && m.getSpecial()==getSpecial()) { return true; } return false; }
btVector3 tgRodInfo::getConnectionPoint(const btVector3& referencePoint, const btVector3& destinationPoint, const double rotation) const { if (referencePoint == destinationPoint) { throw std::invalid_argument("Destination point is the reference point."); } // Find the closest point on the radius from the referencePoint const btVector3 cylinderAxis = (getTo() - getFrom()).normalize(); const btVector3 cylinderAxis2 = (getTo() - getFrom()).normalize(); // Vector from reference point to destination point const btVector3 refToDest = (referencePoint - destinationPoint).normalize(); // Find a vector perpendicular to both the cylinder axis and refToDest btVector3 rotationAxis = cylinderAxis.cross(refToDest); // Handle a vector crossed with itself if (rotationAxis.length() == 0.0) { btScalar a = cylinderAxis[0]; btScalar b = cylinderAxis[1]; btScalar c = cylinderAxis[2]; // Find an arbitrary perpendicular vector rotationAxis = btVector3(b - c, -a, a).normalize(); } const btVector3 directional = cylinderAxis.rotate(rotationAxis, -M_PI / 2.0).normalize(); // Apply one additional rotation so we can end up anywhere we // want on the radius of the rod // When added to any point along the cylinder axis, this will take you // to the surface in the direction of the destinationPoint const btVector3 surfaceVector = directional.rotate(cylinderAxis2, rotation).normalize() * m_config.radius; // Return the the surface point closest to the reference point in the // direction of the destination point. return referencePoint + surfaceVector; }
PVRTVec3 SimpleCamera::getTarget() const { PVRTVec3 vTarget = getTo(); vTarget.x += m_vPosition.x; vTarget.y += m_vPosition.y; vTarget.z += m_vPosition.z; return vTarget; }
std::string MapExpr::toString() { std::string ret = "{"; for (size_t i = 0; i < mapSize(); ++i) { if (i > 0) ret.push_back(','); ret.append(getFrom(i)->toString()+"->"+getTo(i)->toString()); } ret.push_back('}'); return ret; }
string Move::toString() const { string s = ""; int i = getSpecial(); if(i==PIECE_QUEEN) s="Q"; else if(i==PIECE_KNIGHT) s="N"; else if(i==PIECE_ROOK) s="R"; else if(i==PIECE_BISHOP) s="B"; return (Int2Sq(getFrom()) + Int2Sq(getTo()) + s); }
int RootOperationData::copyAttr(const std::string& name, Element & attr) const { if (name == SERIALNO_ATTR) { attr = getSerialno(); return 0; } if (name == REFNO_ATTR) { attr = getRefno(); return 0; } if (name == FROM_ATTR) { attr = getFrom(); return 0; } if (name == TO_ATTR) { attr = getTo(); return 0; } if (name == SECONDS_ATTR) { attr = getSeconds(); return 0; } if (name == FUTURE_SECONDS_ATTR) { attr = getFutureSeconds(); return 0; } if (name == ARGS_ATTR) { attr = getArgsAsList(); return 0; } return RootData::copyAttr(name, attr); }
void MapExpr::print(FILE* file, int indent) const { fprintf(file, "%*sMapExpr:\n", indent, ""); fprintf(file, "%*sfromTyp: %s", indent + 2, "", getFromTyp()->toString().c_str()); fprintf(file, "%*stoTyp: %s", indent + 2, "", getToTyp()->toString().c_str()); for (size_t i = 0; i < mapSize(); i++) { fprintf(file, "%*sfrom#%d: \n", indent + 2, "", (int)i); getFrom(i)->print(file, indent + 4); fprintf(file, "%*sto#%d: \n", indent + 2, "", (int)i); getTo(i)->print(file, indent + 4); } }
tgBulletSpringCable* tgBasicActuatorInfo::createTgBulletSpringCable() { //std::cout << "tgBasicActuatorInfo::createMuscle2P()" << std::endl; //std::cout << " getFromRigidInfo(): " << getFromRigidInfo() << std::endl; //std::cout << " getFromRigidInfo(): " << getFromRigidInfo()->getRigidInfoGroup() << std::endl; // @todo: need to check somewhere that the rigid bodies have been set... btRigidBody* fromBody = getFromRigidBody(); btRigidBody* toBody = getToRigidBody(); btVector3 from = getFromRigidInfo()->getConnectionPoint(getFrom(), getTo(), m_config.rotation); btVector3 to = getToRigidInfo()->getConnectionPoint(getTo(), getFrom(), m_config.rotation); std::vector<tgBulletSpringCableAnchor*> anchorList; tgBulletSpringCableAnchor* anchor1 = new tgBulletSpringCableAnchor(fromBody, from); anchorList.push_back(anchor1); tgBulletSpringCableAnchor* anchor2 = new tgBulletSpringCableAnchor(toBody, to); anchorList.push_back(anchor2); return new tgBulletSpringCable(anchorList, m_config.stiffness, m_config.damping, m_config.pretension); }
bool Move::operator<(Move const& m) const { int sp = getSpecial(); int msp = m.getSpecial(); if(sp==PIECE_KNIGHT || sp==PIECE_ROOK || sp==PIECE_BISHOP || msp==PIECE_QUEEN || msp==PIECE_KING || msp==PIECE_PAWN) { return true; } else if(sp==PIECE_QUEEN || sp==PIECE_KING || sp==PIECE_PAWN || msp==PIECE_KNIGHT || msp==PIECE_ROOK || msp==PIECE_BISHOP) { return false; } int c = getCapturedPiece(); int mc = m.getCapturedPiece(); int cap = CapturedPiecePriority[c]; int mcap = CapturedPiecePriority[mc]; if(cap<mcap) { return true; } else if(cap>mcap) { return false; } else { int mov = MovingPiecePriority[c][getMovingPiece()]; int mmov = MovingPiecePriority[mc][m.getMovingPiece()]; if(mov<mmov) { return true; } else if(mmov>mov) { return false; } else { if(ToPriority[getTo()]<ToPriority[m.getTo()]) { return true; } else return false; } } return false; }
int main(){ char line[128]; int k; FILE *fp = fopen("testgraph.txt", "r"); for(k=0; k < 2; k++){ // 2 ---> should be number of lines from file. fgets(line, sizeof(line), fp); int busslinje = getLinje(line); char *bussfran = getFrom(line); char *busstill = getTo(line); int busstid = getWeight(line); printf("LINE: %d\nFROM:%s\nTO:%s\nTIME: %d\n\n", busslinje+1, bussfran, busstill, busstid-1); } return 0; }
void Search::saveSettings(QSettings *config) { config->setValue("mailbox", mailbox() ); config->setValue("name", name() ); config->setValue("from", getFrom() ); config->setValue("to", getTo() ); config->setValue("subject", getSubject() ); config->setValue("body", getBody() ); config->setValue("status", status() ); if ( !getBeforeDate().isNull() ) { config->setValue("datebefore", getBeforeDate().toString() ); } else { config->setValue("datebefore", "" ); } if ( !getAfterDate().isNull() ) { config->setValue("dateafter", getAfterDate().toString() ); } else { config->setValue("dateafter", "" ); } }
/** * Checks if UTF-8 conversion is needed in current context. * if nl_langinfo() is not available, no conversion is ever needed. * If iconv usage is disabled there is no need to check if we need to convert. * Furthermore, some systems have nl_langinfo(), but lacks ability to get * CODESET through it. * Look at the comments by the kdbbUTF8Engine() function for more information. * * @return 0 if not needed * @return anything else if needed * @ingroup backendhelper */ int kdbbNeedsUTF8Conversion (Plugin * handle) { return strcmp (getFrom (handle), getTo (handle)); }
std::set<btVector3> tgRodInfo::getContainedNodes() const { std::set<btVector3> contained; contained.insert(getFrom()); contained.insert(getTo()); return contained; }
bool Move::isNullMove() const { if (getTo() == 0 && getFrom() == 0) return true; return false; }
Bitset Move::getbit135() const { return getPos2Bit(getturn135(getTo())) | getPos2Bit(getturn135(getFrom())); }
Bitset Move::getbit90() const { return getPos2Bit(getturn90(getTo())) | getPos2Bit(getturn90(getFrom())); }
//comparison - to sort ranges bool operator<(const DistrValue& v) const { if(getFrom() == v.getFrom() ) return getTo() < v.getTo(); return getFrom() < v.getFrom(); }
int elektraIconvGet (Plugin * handle, KeySet * returned, Key * parentKey) { Key * cur; ksRewind (returned); if (!strcmp (keyName (parentKey), "system/elektra/modules/iconv")) { KeySet * pluginConfig = ksNew (30, keyNew ("system/elektra/modules/iconv", KEY_VALUE, "iconv plugin waits for your orders", KEY_END), keyNew ("system/elektra/modules/iconv/exports", KEY_END), keyNew ("system/elektra/modules/iconv/exports/get", KEY_FUNC, elektraIconvGet, KEY_END), keyNew ("system/elektra/modules/iconv/exports/set", KEY_FUNC, elektraIconvSet, KEY_END), #include "readme_iconv.c" keyNew ("system/elektra/modules/iconv/infos/version", KEY_VALUE, PLUGINVERSION, KEY_END), KS_END); ksAppend (returned, pluginConfig); ksDel (pluginConfig); return 1; } if (!kdbbNeedsUTF8Conversion (handle)) return 0; while ((cur = ksNext (returned)) != 0) { if (keyIsString (cur)) { /* String or similar type of value */ size_t convertedDataSize = keyGetValueSize (cur); char * convertedData = elektraMalloc (convertedDataSize); memcpy (convertedData, keyString (cur), keyGetValueSize (cur)); if (kdbbUTF8Engine (handle, UTF8_FROM, &convertedData, &convertedDataSize)) { ELEKTRA_SET_ERRORF (46, parentKey, "Could not convert string %s, got result %s, encoding settings are from %s to %s", keyString (cur), convertedData, getFrom (handle), getTo (handle)); elektraFree (convertedData); return -1; } keySetString (cur, convertedData); elektraFree (convertedData); } const Key * meta = keyGetMeta (cur, "comment"); if (meta) { /* String or similar type of value */ size_t convertedDataSize = keyGetValueSize (meta); char * convertedData = elektraMalloc (convertedDataSize); memcpy (convertedData, keyString (meta), keyGetValueSize (meta)); if (kdbbUTF8Engine (handle, UTF8_FROM, &convertedData, &convertedDataSize)) { ELEKTRA_SET_ERRORF (46, parentKey, "Could not convert string %s, got result %s, encoding settings are from %s to %s", keyString (meta), convertedData, getFrom (handle), getTo (handle)); elektraFree (convertedData); return -1; } keySetMeta (cur, "comment", convertedData); elektraFree (convertedData); } } return 1; /* success */ }
void SimpleCamera::MoveBack() { PVRTVec3 vTo = getTo().normalized(); m_vVelocity -=vTo*m_fMoveSpeed; }
void SimpleCamera::MoveForward() { PVRTVec3 vTo = getTo().normalized(); m_vVelocity +=vTo*m_fMoveSpeed; }