Example #1
0
int InverseElementTransformation::FindClosestPhysPoint(
   const Vector& pt, const IntegrationRule &ir)
{
   MFEM_VERIFY(T != NULL, "invalid ElementTransformation");
   MFEM_VERIFY(pt.Size() == T->GetSpaceDim(), "invalid point");

   DenseMatrix physPts;
   T->Transform(ir, physPts);

   // Initialize distance and index of closest point
   int minIndex = -1;
   double minDist = std::numeric_limits<double>::max();

   // Check all integration points in ir
   const int npts = ir.GetNPoints();
   for (int i = 0; i < npts; ++i)
   {
      double dist = pt.DistanceTo(physPts.GetColumn(i));
      if (dist < minDist)
      {
         minDist = dist;
         minIndex = i;
      }
   }
   return minIndex;
}
Example #2
0
Vector<PlatformTimeRanges> MediaSource::activeRanges() const
{
    Vector<PlatformTimeRanges> activeRanges;
    for (auto& sourceBuffer : *m_activeSourceBuffers)
        activeRanges.append(sourceBuffer->buffered()->ranges());
    return activeRanges;
}
Example #3
0
Vector<T> GaussSeidel<T>::operator()(const BandedMatrix<T>& aMatrix, const Vector<T>& bVector) const
{
  Vector<T> solution(bVector), r(bVector.size());//   x = b;
  LpNorm<2, T> norm;
  T alpha, errv=1;
  int it;

  r = bVector - aMatrix*solution; // r = b - A*x;
  it = 0; // it = 1;
  while(errv > iterative::TOLERANCE)// while(norm(r) > 1e-7)
  {
    for(int i=0; i<bVector.size(); ++i)//   for i = 1:1:max(size(b))
    {
      // Multiply solution by aMatrix row
      T proj = 0;
      int start = std::max(0, static_cast<int>(i) - static_cast<int>(aMatrix.lowerBands()) );
      int size = std::min(aMatrix.cols(), static_cast<int>(i) + aMatrix.upperBands() + 1);
      for(int j = start; j < size; j++)
      {
        proj += (*(aMatrix.getPtr(i, j)) ) * solution[j];
      }
      // solution[i] = (bVector[i] - aMatrix.getRow(i)*solution + aMatrix.get(i,i)*solution[i])/aMatrix.get(i,i); //     x(i) = (b(i) - dot(A(i,:),x) + A(i,i)*x(i))/A(i,i);
      solution[i] = (bVector[i] - proj + aMatrix.get(i,i)*solution[i])/aMatrix.get(i,i);
    } //   end
    r = bVector - aMatrix*solution; //   r = b - A*x;
    errv = norm(r); //   errv(it) = norm(r);
    it++; //   it = it + 1;
  }// end

  std::cout << "Iterations: " << it << '\n';

  return solution;
}
Example #4
0
bool Model::SetVertexBuffers(const Vector<SharedPtr<VertexBuffer> >& buffers, const PODVector<unsigned>& morphRangeStarts,
    const PODVector<unsigned>& morphRangeCounts)
{
    for (unsigned i = 0; i < buffers.Size(); ++i)
    {
        if (!buffers[i])
        {
            URHO3D_LOGERROR("Null model vertex buffers specified");
            return false;
        }
        if (!buffers[i]->IsShadowed())
        {
            URHO3D_LOGERROR("Model vertex buffers must be shadowed");
            return false;
        }
    }

    vertexBuffers_ = buffers;
    morphRangeStarts_.Resize(buffers.Size());
    morphRangeCounts_.Resize(buffers.Size());

    // If morph ranges are not specified for buffers, assume to be zero
    for (unsigned i = 0; i < buffers.Size(); ++i)
    {
        morphRangeStarts_[i] = i < morphRangeStarts.Size() ? morphRangeStarts[i] : 0;
        morphRangeCounts_[i] = i < morphRangeCounts.Size() ? morphRangeCounts[i] : 0;
    }

    return true;
}
Example #5
0
int EventHub::getKeycodeState(int32_t deviceId, int code) const
{
    AutoMutex _l(mLock);
    device_t* device = getDevice(deviceId);
    if (device == NULL || device->layoutMap == NULL) return -1;
    
    Vector<int32_t> scanCodes;
    device->layoutMap->findScancodes(code, &scanCodes);
    
    uint8_t key_bitmask[(KEY_MAX+7)/8];
    memset(key_bitmask, 0, sizeof(key_bitmask));
    if (ioctl(mFDs[id_to_index(device->id)].fd,
               EVIOCGKEY(sizeof(key_bitmask)), key_bitmask) >= 0) {
        #if 0
        for (size_t i=0; i<=KEY_MAX; i++) {
            LOGI("(Scan code %d: down=%d)", i, test_bit(i, key_bitmask));
        }
        #endif
        const size_t N = scanCodes.size();
        for (size_t i=0; i<N && i<=KEY_MAX; i++) {
            int32_t sc = scanCodes.itemAt(i);
            //LOGI("Code %d: down=%d", sc, test_bit(sc, key_bitmask));
            if (sc >= 0 && sc <= KEY_MAX && test_bit(sc, key_bitmask)) {
                return 1;
            }
        }
    }
    
    return 0;
}
Example #6
0
void setCookiesFromDOM(const NetworkStorageSession& session, const URL& firstParty, const URL& url, const String& value)
{
    SoupCookieJar* jar = cookieJarForSession(session);
    if (!jar)
        return;

    GUniquePtr<SoupURI> origin = url.createSoupURI();
    GUniquePtr<SoupURI> firstPartyURI = firstParty.createSoupURI();

    // Get existing cookies for this origin.
    GSList* existingCookies = soup_cookie_jar_get_cookie_list(jar, origin.get(), TRUE);

    Vector<String> cookies;
    value.split('\n', cookies);
    const size_t cookiesCount = cookies.size();
    for (size_t i = 0; i < cookiesCount; ++i) {
        GUniquePtr<SoupCookie> cookie(soup_cookie_parse(cookies[i].utf8().data(), origin.get()));
        if (!cookie)
            continue;

        // Make sure the cookie is not httpOnly since such cookies should not be set from JavaScript.
        if (soup_cookie_get_http_only(cookie.get()))
            continue;

        // Make sure we do not overwrite httpOnly cookies from JavaScript.
        if (httpOnlyCookieExists(existingCookies, soup_cookie_get_name(cookie.get()), soup_cookie_get_path(cookie.get())))
            continue;

        soup_cookie_jar_add_cookie_with_first_party(jar, firstPartyURI.get(), cookie.release());
    }

    soup_cookies_free(existingCookies);
}
Example #7
0
bool Portal::_get(const StringName &p_name, Variant &r_ret) const {

	if (p_name == "shape") {
		Vector<Point2> points = get_shape();
		PoolVector<float> dst_coords;
		dst_coords.resize(points.size() * 2);

		for (int i = 0; i < points.size(); i++) {

			dst_coords.set(i * 2 + 0, points[i].x);
			dst_coords.set(i * 2 + 1, points[i].y);
		}

		r_ret = dst_coords;
	} else if (p_name == "enabled") {
		r_ret = is_enabled();
	} else if (p_name == "disable_distance") {
		r_ret = get_disable_distance();
	} else if (p_name == "disabled_color") {
		r_ret = get_disabled_color();
	} else if (p_name == "connect_range") {
		r_ret = get_connect_range();
	} else
		return false;
	return true;
}
Example #8
0
bool AABB::intersects(Ray ray, double &dist) {
    double distance[6] = {-1, -1, -1, -1, -1, -1};

    distance[0] = (start.getX() - ray.origin.getX()) / ray.direction.getX();
    distance[3] = (end.getX() - ray.origin.getX()) / ray.direction.getX();

    distance[1] = (start.getY() - ray.origin.getY()) / ray.direction.getY();
    distance[4] = (end.getY() - ray.origin.getY()) / ray.direction.getY();

    distance[2] = (start.getZ() - ray.origin.getZ()) / ray.direction.getZ();
    distance[5] = (end.getZ() - ray.origin.getZ()) / ray.direction.getZ();

    int closestFace = -1;
    dist = 0;

    for (int i = 0; i < 6; i++) {
        Vector rayToBox = ray.origin + ray.direction * distance[i];
        if (
            (rayToBox.getX() > start.getX() - EPSILON) &&
            (rayToBox.getX() < end.getX() + EPSILON) &&
            (rayToBox.getY() > start.getY() - EPSILON) &&
            (rayToBox.getY() < end.getY() + EPSILON) &&
            (rayToBox.getZ() > start.getZ() - EPSILON) &&
            (rayToBox.getZ() < end.getZ() + EPSILON)
        ) {
            if (((closestFace == -1) || distance[i] < dist) && distance[i] > EPSILON) {
                closestFace = i;
                dist = distance[i];
            }
        }
    }
    return (closestFace != -1);
}
void DocumentThreadableLoader::makeCrossOriginAccessRequestWithPreflight(const ResourceRequest& request)
{
    ResourceRequest preflightRequest(request.url());
    preflightRequest.removeCredentials();
    preflightRequest.setHTTPOrigin(m_document->securityOrigin()->toString());
    preflightRequest.setAllowCookies(m_options.allowCredentials);
    preflightRequest.setHTTPMethod("OPTIONS");
    preflightRequest.setHTTPHeaderField("Access-Control-Request-Method", request.httpMethod());

    const HTTPHeaderMap& requestHeaderFields = request.httpHeaderFields();

    if (requestHeaderFields.size() > 0) {
        Vector<UChar> headerBuffer;
        HTTPHeaderMap::const_iterator it = requestHeaderFields.begin();
        append(headerBuffer, it->first);
        ++it;

        HTTPHeaderMap::const_iterator end = requestHeaderFields.end();
        for (; it != end; ++it) {
            headerBuffer.append(',');
            headerBuffer.append(' ');
            append(headerBuffer, it->first);
        }

        preflightRequest.setHTTPHeaderField("Access-Control-Request-Headers", String::adopt(headerBuffer));
    }

    loadRequest(preflightRequest, DoSecurityCheck);
}
TEST(AnimationKeyframeEffectModel, ZeroKeyframes)
{
    AnimatableValueKeyframeEffectModel* effect = AnimatableValueKeyframeEffectModel::create(AnimatableValueKeyframeVector());
    Vector<RefPtr<Interpolation>> values;
    effect->sample(0, 0.5, duration, values);
    EXPECT_TRUE(values.isEmpty());
}
// FIXME: Re-enable this test once compositing of CompositeAdd is supported.
TEST(AnimationKeyframeEffectModel, DISABLED_DependsOnUnderlyingValue)
{
    AnimatableValueKeyframeVector keyframes(3);
    keyframes[0] = AnimatableValueKeyframe::create();
    keyframes[0]->setOffset(0.0);
    keyframes[0]->setPropertyValue(CSSPropertyLeft, pixelAnimatableValue(1.0).get());
    keyframes[0]->setComposite(EffectModel::CompositeAdd);
    keyframes[1] = AnimatableValueKeyframe::create();
    keyframes[1]->setOffset(0.5);
    keyframes[1]->setPropertyValue(CSSPropertyLeft, pixelAnimatableValue(1.0).get());
    keyframes[2] = AnimatableValueKeyframe::create();
    keyframes[2]->setOffset(1.0);
    keyframes[2]->setPropertyValue(CSSPropertyLeft, pixelAnimatableValue(1.0).get());

    AnimatableValueKeyframeEffectModel* effect = AnimatableValueKeyframeEffectModel::create(keyframes);
    Vector<RefPtr<Interpolation>> values;
    effect->sample(0, 0, duration, values);
    EXPECT_TRUE(values.at(0));
    effect->sample(0, 0.1, duration, values);
    EXPECT_TRUE(values.at(0));
    effect->sample(0, 0.25, duration, values);
    EXPECT_TRUE(values.at(0));
    effect->sample(0, 0.4, duration, values);
    EXPECT_TRUE(values.at(0));
    effect->sample(0, 0.5, duration, values);
    EXPECT_FALSE(values.at(0));
    effect->sample(0, 0.6, duration, values);
    EXPECT_FALSE(values.at(0));
    effect->sample(0, 0.75, duration, values);
    EXPECT_FALSE(values.at(0));
    effect->sample(0, 0.8, duration, values);
    EXPECT_FALSE(values.at(0));
    effect->sample(0, 1, duration, values);
    EXPECT_FALSE(values.at(0));
}
Example #12
0
void SceneEditor3D::HandleUpdate(StringHash eventType, VariantMap& eventData)
{
    Vector<Node*> editNodes;
    if (selectedNode_.NotNull())
        editNodes.Push(selectedNode_);
    gizmo3D_->Update(editNodes);
}
Example #13
0
void QTMovieTask::fireTaskClients()
{
    Vector<QTMovieTaskClient*> clients;
    copyToVector(m_taskList, clients);
    for (Vector<QTMovieTaskClient*>::iterator i = clients.begin(); i != clients.end(); ++i)
        (*i)->task();
}
Example #14
0
ExprVector EntityBase::FaceGetNormalExprs(void) {
    ExprVector r;
    if(type == FACE_NORMAL_PT) {
        Vector v = Vector::From(numNormal.vx, numNormal.vy, numNormal.vz);
        r = ExprVector::From(v.WithMagnitude(1));
    } else if(type == FACE_XPROD) {
        ExprVector vc = ExprVector::From(param[0], param[1], param[2]);
        ExprVector vn =
            ExprVector::From(numNormal.vx, numNormal.vy, numNormal.vz);
        r = vc.Cross(vn);
        r = r.WithMagnitude(Expr::From(1.0));
    } else if(type == FACE_N_ROT_TRANS) {
        // The numerical normal vector gets the rotation; the numerical
        // normal has magnitude one, and the rotation doesn't change that,
        // so there's no need to fix it up.
        r = ExprVector::From(numNormal.vx, numNormal.vy, numNormal.vz);
        ExprQuaternion q =
            ExprQuaternion::From(param[3], param[4], param[5], param[6]);
        r = q.Rotate(r);
    } else if(type == FACE_N_TRANS) {
        r = ExprVector::From(numNormal.vx, numNormal.vy, numNormal.vz);
    } else if(type == FACE_N_ROT_AA) {
        r = ExprVector::From(numNormal.vx, numNormal.vy, numNormal.vz);
        ExprQuaternion q = GetAxisAngleQuaternionExprs(3);
        r = q.Rotate(r);
    } else oops();
    return r;
}
bool ClientCartesianController::setDOF(const Vector &newDof, Vector &curDof)
{
    if (!connected)
        return false;

    Bottle command, reply;
    command.addVocab(IKINCARTCTRL_VOCAB_CMD_SET);
    command.addVocab(IKINCARTCTRL_VOCAB_OPT_DOF);
    Bottle &dofPart=command.addList();

    for (size_t i=0; i<newDof.length(); i++)
        dofPart.addInt((int)newDof[i]);

    if (!portRpc.write(command,reply))
    {
        yError("unable to get reply from server!");
        return false;
    }

    if (reply.get(0).asVocab()==IKINCARTCTRL_VOCAB_REP_ACK)
    {        
        if (Bottle *dofPart=reply.get(1).asList())
        {                        
            curDof.resize(dofPart->size());

            for (size_t i=0; i<curDof.length(); i++)
                curDof[i]=dofPart->get(i).asDouble();

            return true;
        }
    }

    return false;
}
Example #16
0
//=========================================================
// Tracking Hornet hit something
//=========================================================
void CHornet :: TrackTouch ( CBaseEntity *pOther )
{
	if ( pOther->edict() == pev->owner || pOther->pev->modelindex == pev->modelindex )
	{// bumped into the guy that shot it.
		pev->solid = SOLID_NOT;
		return;
	}

	if ( IRelationship( pOther ) <= R_NO )
	{
		// hit something we don't want to hurt, so turn around.
		Vector vecVelocity = GetAbsVelocity();

		vecVelocity = vecVelocity.Normalize();

		vecVelocity.x *= -1;
		vecVelocity.y *= -1;

		SetAbsVelocity( vecVelocity );

		SetAbsOrigin( GetAbsOrigin() + GetAbsVelocity() * 4 ); // bounce the hornet off a bit.
		SetAbsVelocity( GetAbsVelocity() * m_flFlySpeed );

		return;
	}

	DieTouch( pOther );
}
bool ClientCartesianController::setRestWeights(const Vector &newRestWeights,
                                               Vector &curRestWeights)
{
    if (!connected)
        return false;

    Bottle command, reply;
    command.addVocab(IKINCARTCTRL_VOCAB_CMD_SET);
    command.addVocab(IKINCARTCTRL_VOCAB_OPT_REST_WEIGHTS);
    Bottle &restPart=command.addList();

    for (size_t i=0; i<newRestWeights.length(); i++)
        restPart.addDouble(newRestWeights[i]);

    if (!portRpc.write(command,reply))
    {
        yError("unable to get reply from server!");
        return false;
    }

    if (reply.get(0).asVocab()==IKINCARTCTRL_VOCAB_REP_ACK)
    {        
        if (Bottle *restPart=reply.get(1).asList())
        {                        
            curRestWeights.resize(restPart->size());

            for (size_t i=0; i<curRestWeights.length(); i++)
                curRestWeights[i]=restPart->get(i).asDouble();

            return true;
        }
    }

    return false;
}
Example #18
0
void SurfacePool::notifyBuffersComposited(const Vector<TileBuffer*>& tileBuffers)
{
    if (!m_hasFenceExtension)
        return;

#if BLACKBERRY_PLATFORM_GRAPHICS_EGL
    Platform::MutexLocker locker(&m_mutex);

    EGLDisplay display = Platform::Graphics::eglDisplay();

    // The EGL_KHR_fence_sync spec is nice enough to specify that the sync object
    // is not actually deleted until everyone has stopped using it.
    for (std::set<void*>::const_iterator it = m_garbage.begin(); it != m_garbage.end(); ++it)
        eglDestroySyncKHR(display, *it);
    m_garbage.clear();

    // If we didn't blit anything, we don't need to create a new fence.
    if (tileBuffers.isEmpty())
        return;

    // Create a new fence and assign to the tiles that were blit. Invalidate any previous
    // fence that may be active among these tiles and add its sync object to the garbage set
    // for later destruction to make sure it doesn't leak.
    RefPtr<Fence> fence = Fence::create(eglCreateSyncKHR(display, EGL_SYNC_FENCE_KHR, 0));
    for (unsigned int i = 0; i < tileBuffers.size(); ++i) {
        if (EGLSyncKHR platformSync = tileBuffers[i]->fence()->takePlatformSync())
            m_garbage.insert(platformSync);

        tileBuffers[i]->setFence(fence);
    }
#endif
}
Example #19
0
bool Portal::_set(const StringName &p_name, const Variant &p_value) {

	if (p_name == "shape") {
		PoolVector<float> src_coords = p_value;
		Vector<Point2> points;
		int src_coords_size = src_coords.size();
		ERR_FAIL_COND_V(src_coords_size % 2, false);
		points.resize(src_coords_size / 2);
		for (int i = 0; i < points.size(); i++) {

			points[i].x = src_coords[i * 2 + 0];
			points[i].y = src_coords[i * 2 + 1];
			set_shape(points);
		}
	} else if (p_name == "enabled") {
		set_enabled(p_value);
	} else if (p_name == "disable_distance") {
		set_disable_distance(p_value);
	} else if (p_name == "disabled_color") {
		set_disabled_color(p_value);
	} else if (p_name == "connect_range") {
		set_connect_range(p_value);
	} else
		return false;

	return true;
}
Example #20
0
bool LinearRegression::FitLinearModel(Matrix & X, Vector & y){
    Matrix Xt;
    Xt.Transpose(X);

    Matrix XtX;
    XtX.Product(Xt, X);
    if (!this->chol.TryDecompose(XtX))
        return false;
    chol.Decompose(XtX);
    chol.Invert();
    this->XtXinv = chol.inv;

    Vector tmp = y;
    tmp.Product(Xt, y);
    this->B.Product(this->XtXinv, tmp); // beta = (XtX)^{-1} Xt Y

    this->predict.Product(X, this->B);
    this->residuals = y;
    this->residuals.Subtract(this->predict);

    this->sigma2 = 0.0;
    for (int i = 0; i < this->residuals.Length(); i++){
        sigma2 += (this->residuals[i]) * (this->residuals[i]);
    }
    sigma2 /= y.Length(); // MLE estimates of sigma2

    this->covB = this->XtXinv;
    this->covB.Multiply(sigma2);
    return true;
}; 
Example #21
0
double Angle::compute(const Vector& v1,const Vector& v2,Vector& d1,Vector& d2)const{
    const double dp(dotProduct(v1,v2));
    const Vector& dp_dv1(v2);
    const Vector& dp_dv2(v1);
    const double sv1(v1.modulo2());
    const double sv2(v2.modulo2());
    const Vector dsv1_dv1(2*v1);
    const Vector dsv2_dv2(2*v2);
    const double nn(1.0/sqrt(sv1*sv2));
    const Vector dnn_dv1(-0.5*nn/sv1*dsv1_dv1);
    const Vector dnn_dv2(-0.5*nn/sv2*dsv2_dv2);

    const double dpnn(dp*nn);

    if(dpnn>=1.0-epsilon){
      d1=Vector(0.0,0.0,0.0);
      d2=Vector(0.0,0.0,0.0);
      return 0.0;
    }
    if(dpnn<=-1.0+epsilon){
      d1=Vector(0.0,0.0,0.0);
      d2=Vector(0.0,0.0,0.0);
      return pi;
    }
    const Vector ddpnn_dv1(dp*dnn_dv1+dp_dv1*nn);
    const Vector ddpnn_dv2(dp*dnn_dv2+dp_dv2*nn);

    const double x(-1.0/sqrt(1-dpnn*dpnn));

    d1=x*ddpnn_dv1;
    d2=x*ddpnn_dv2;


    return std::acos(dpnn);
}
Example #22
0
Vector<ParsedCookie*> CookieParser::parse(const String& cookies)
{
    unsigned cookieStart, cookieEnd = 0;
    double curTime = currentTime();
    Vector<ParsedCookie*, 4> parsedCookies;

    unsigned cookiesLength = cookies.length();
    if (!cookiesLength) // Code below doesn't handle this case
        return parsedCookies;

    // Iterate over the header to parse all the cookies.
    while (cookieEnd <= cookiesLength) {
        cookieStart = cookieEnd;
        
        // Find a cookie separator.
        while (cookieEnd <= cookiesLength && !isCookieHeaderSeparator(cookies[cookieEnd]))
            cookieEnd++;

        // Detect an empty cookie and go to the next one.
        if (cookieStart == cookieEnd) {
            ++cookieEnd;
            continue;
        }

        if (cookieEnd < cookiesLength && isCookieHeaderSeparator(cookies[cookieEnd]))
            ++cookieEnd;

        ParsedCookie* cookie = parseOneCookie(cookies, cookieStart, cookieEnd - 1, curTime);
        if (cookie)
            parsedCookies.append(cookie);
    }
    return parsedCookies;
}
void ExportTemplateManager::_uninstall_template_confirm() {

	DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
	Error err = d->change_dir(EditorSettings::get_singleton()->get_templates_dir());

	ERR_FAIL_COND(err != OK);

	err = d->change_dir(to_remove);

	ERR_FAIL_COND(err != OK);

	Vector<String> files;

	d->list_dir_begin();

	bool isdir;
	String c = d->get_next(&isdir);
	while (c != String()) {
		if (!isdir) {
			files.push_back(c);
		}
		c = d->get_next(&isdir);
	}

	d->list_dir_end();

	for (int i = 0; i < files.size(); i++) {
		d->remove(files[i]);
	}

	d->change_dir("..");
	d->remove(to_remove);

	_update_template_list();
}
bool ClientCartesianController::getJointsVelocities(Vector &qdot)
{
    if (!connected)
        return false;

    Bottle command, reply;
    command.addVocab(IKINCARTCTRL_VOCAB_CMD_GET);
    command.addVocab(IKINCARTCTRL_VOCAB_OPT_QDOT);

    if (!portRpc.write(command,reply))
    {
        yError("unable to get reply from server!");
        return false;
    }

    if (reply.get(0).asVocab()==IKINCARTCTRL_VOCAB_REP_ACK)
    {
        if (Bottle *qdotPart=reply.get(1).asList())
        {
            qdot.resize(qdotPart->size());

            for (size_t i=0; i<qdot.length(); i++)
                qdot[i]=qdotPart->get(i).asDouble();

            return true;
        }
    }

    return false;
}
Example #25
0
/*
 * Inspect the known devices to determine whether physical keys exist for the given
 * framework-domain key codes.
 */
bool EventHub::hasKeys(size_t numCodes, int32_t* keyCodes, uint8_t* outFlags) {
    for (size_t codeIndex = 0; codeIndex < numCodes; codeIndex++) {
        outFlags[codeIndex] = 0;

        // check each available hardware device for support for this keycode
        Vector<int32_t> scanCodes;
        for (int n = 0; (n < mFDCount) && (outFlags[codeIndex] == 0); n++) {
            if (mDevices[n]) {
                status_t err = mDevices[n]->layoutMap->findScancodes(keyCodes[codeIndex], &scanCodes);
                if (!err) {
                    // check the possible scan codes identified by the layout map against the
                    // map of codes actually emitted by the driver
                    for (size_t sc = 0; sc < scanCodes.size(); sc++) {
                        if (test_bit(scanCodes[sc], mDevices[n]->keyBitmask)) {
                            outFlags[codeIndex] = 1;
                            break;
                        }
                    }
                }
            }
        }
    }

    return true;
}
bool ClientCartesianController::goToPoseSync(const Vector &xd, const Vector &od, const double t)
{
    if (!connected || (xd.length()<3) || (od.length()<4))
        return false;

    Bottle command, reply;
    command.addVocab(IKINCARTCTRL_VOCAB_CMD_GO);
    command.addVocab(IKINCARTCTRL_VOCAB_VAL_POSE_FULL);
    command.addDouble(t);
    Bottle &xdesPart=command.addList();

    for (int i=0; i<3; i++)
        xdesPart.addDouble(xd[i]);

    for (int i=0; i<4; i++)
        xdesPart.addDouble(od[i]);

    if (!portRpc.write(command,reply))
    {
        yError("unable to get reply from server!");
        return false;
    }

    return (reply.get(0).asVocab()==IKINCARTCTRL_VOCAB_REP_ACK);
}
Example #27
0
    size_t find(const K& key) const
    {
        size_t start = 0;
        size_t end = allKeys.size();

        size_t result = 0;

        while (start < end)
        {
            result = (end + start) / 2;

            if (key == allKeys[result])
            {
                return result;
            }
            else if (end - start == 1)
            {
                break;
            }

            if (key < allKeys[result])
            {
                end = result;
            }
            else if (key > allKeys[result])
            {
                start = result;
            }
        }

        return allKeys.size();
    }
bool ClientCartesianController::askForPose(const Vector &q0, const Vector &xd,
                                           const Vector &od, Vector &xdhat,
                                           Vector &odhat, Vector &qdhat)
{
    if (!connected)
        return false;

    Bottle command, reply;
    Vector tg(xd.length()+od.length());
    for (size_t i=0; i<xd.length(); i++)
        tg[i]=xd[i];

    for (size_t i=0; i<od.length(); i++)
        tg[xd.length()+i]=od[i];

    command.addVocab(IKINCARTCTRL_VOCAB_CMD_ASK);
    addVectorOption(command,IKINCARTCTRL_VOCAB_OPT_XD,tg);
    addVectorOption(command,IKINCARTCTRL_VOCAB_OPT_Q,q0);
    addPoseOption(command,IKINCTRL_POSE_FULL);

    if (!portRpc.write(command,reply))
    {
        yError("unable to get reply from server!");
        return false;
    }

    return getDesiredOption(reply,xdhat,odhat,qdhat);
}
void GeolocationController::errorOccurred(GeolocationError* error)
{
    Vector<RefPtr<Geolocation> > observersVector;
    copyToVector(m_observers, observersVector);
    for (size_t i = 0; i < observersVector.size(); ++i)
        observersVector[i]->setError(error);
}
void FontCache::invalidate()
{
    if (!gClients) {
        ASSERT(!gFontPlatformDataCache);
        return;
    }

    if (gFontPlatformDataCache) {
        deleteAllValues(*gFontPlatformDataCache);
        delete gFontPlatformDataCache;
        gFontPlatformDataCache = new FontPlatformDataCache;
    }

    gGeneration++;

    Vector<RefPtr<FontSelector> > clients;
    size_t numClients = gClients->size();
    clients.reserveInitialCapacity(numClients);
    HashSet<FontSelector*>::iterator end = gClients->end();
    for (HashSet<FontSelector*>::iterator it = gClients->begin(); it != end; ++it)
        clients.append(*it);

    ASSERT(numClients == clients.size());
    for (size_t i = 0; i < numClients; ++i)
        clients[i]->fontCacheInvalidated();

    purgeInactiveFontData();
}