static void expandSelectionToGranularity(Frame* frame, int x, int y, TextGranularity granularity, bool isInputMode)
{
    ASSERT(frame);
    ASSERT(frame->selection());

    VisibleSelection selection;
    if (x < 0 || y < 0) {
        if (!isInputMode)
            return; // Invalid request

        // Input mode based selection, use the current selection as the selection point.
        ASSERT(frame->selection()->selectionType() != VisibleSelection::NoSelection);
        selection = frame->selection()->selection();
    } else {
        VisiblePosition pointLocation(frame->visiblePositionForPoint(WebCore::IntPoint(x, y)));
        selection = VisibleSelection(pointLocation, pointLocation);
    }

    if (!(selection.start().anchorNode() && selection.start().anchorNode()->isTextNode()))
        return;

    selection.expandUsingGranularity(granularity);
    RefPtr<Range> newRange = selection.toNormalizedRange();
    if (!newRange)
        return;
    ExceptionCode ec = 0;
    if (newRange->collapsed(ec))
        return;
    RefPtr<Range> oldRange = frame->selection()->selection().toNormalizedRange();
    EAffinity affinity = frame->selection()->affinity();
    if (isInputMode && !frame->editor()->client()->shouldChangeSelectedRange(oldRange.get(), newRange.get(), affinity, false))
        return;
    frame->selection()->setSelectedRange(newRange.get(), affinity, true);
}
Ejemplo n.º 2
0
Node *pointLocation(Node *v, double *pt,int D){
  
  //if (!v) v=root;

  if ( ( v->left == NULL) && (v->right == NULL) ) 
    return v;

  if (    pt[v->orientation] < v->pt[ v->orientation] )
    return ( (v->left) ? pointLocation(v->left,pt,D) : v);
  else if (    pt[v->orientation] > v->pt[v->orientation]  ) 
    return ( (v->right) ? pointLocation(v->right,pt,D): v);
  else {
    //What we have is pt[v->orientation] == v->pt[v->orientation] 
    Node *vl = ( (v->left)? pointLocation(v->left,pt,D) : v);
    Node *vr = ( (v->right)? pointLocation(v->right,pt,D) : v);
    if ( calcdistance(vl->pt,pt,D) < calcdistance(vr->pt,pt,D) )
      return vl;
    else
      return vr;
  }
}
Ejemplo n.º 3
0
void SwDoor::parsePointInfo(QPointF &inp_p) {
    State state = pointLocation(inp_p);

    // we are storing prev point to prevent losing of info and to have all info for normal working (stored and next after stored points)
    switch (state) {
    case CHANGE: {
        if( !moveDoorLine(inp_p, L_) || !moveDoorLine(inp_p, U_) )
            setNewStoredPoint(prev_p_, inp_p);

        break;
    }
    case L_CHANGE:
    {
        if( !moveDoorLine(inp_p, L_) )
            setNewStoredPoint(prev_p_, inp_p);

        break;
    }
    case U_CHANGE:
    {
        if( !moveDoorLine(inp_p, U_) )
            setNewStoredPoint(prev_p_, inp_p);

        break;
    }
    case INSIDE:
    {
        break;
    }

    }
    prev_p_ = inp_p;

    //mechanism of storing points after some number of inputs even if door was closed
    if (t_++ >= tlim_) setNewStoredPoint(prev_p_, inp_p);
}
Ejemplo n.º 4
0
    virtual void onDraw(SkCanvas* canvas) {
        if (!fInitialized) {
            make_bitmap();
            fInitialized = true;
        }
        canvas->clear(0xFF101010);
        SkPaint checkPaint;
        checkPaint.setColor(0xFF202020);
        for (int y = 0; y < HEIGHT; y += 16) {
          for (int x = 0; x < WIDTH; x += 16) {
            canvas->save();
            canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
            canvas->drawRect(SkRect::MakeXYWH(8, 0, 8, 8), checkPaint);
            canvas->drawRect(SkRect::MakeXYWH(0, 8, 8, 8), checkPaint);
            canvas->restore();
          }
        }
        SkPoint3 pointLocation(0, 0, SkIntToScalar(10));
        SkScalar azimuthRad = SkDegreesToRadians(SkIntToScalar(225));
        SkScalar elevationRad = SkDegreesToRadians(SkIntToScalar(5));
        SkPoint3 distantDirection(SkScalarMul(SkScalarCos(azimuthRad), SkScalarCos(elevationRad)),
                                  SkScalarMul(SkScalarSin(azimuthRad), SkScalarCos(elevationRad)),
                                  SkScalarSin(elevationRad));
        SkPoint3 spotLocation(SkIntToScalar(-10), SkIntToScalar(-10), SkIntToScalar(20));
        SkPoint3 spotTarget(SkIntToScalar(40), SkIntToScalar(40), 0);
        SkScalar spotExponent = SK_Scalar1;
        SkScalar cutoffAngle = SkIntToScalar(15);
        SkScalar kd = SkIntToScalar(2);
        SkScalar ks = SkIntToScalar(1);
        SkScalar shininess = SkIntToScalar(8);
        SkScalar surfaceScale = SkIntToScalar(1);
        SkColor white(0xFFFFFFFF);
        SkPaint paint;

        SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(20, 10, 60, 65));

        int y = 0;
        for (int i = 0; i < 2; i++) {
            const SkImageFilter::CropRect* cr = (i == 0) ? NULL : &cropRect;
            paint.setImageFilter(SkLightingImageFilter::CreatePointLitDiffuse(pointLocation, white, surfaceScale, kd, NULL, cr))->unref();
            drawClippedBitmap(canvas, paint, 0, y);

            paint.setImageFilter(SkLightingImageFilter::CreateDistantLitDiffuse(distantDirection, white, surfaceScale, kd, NULL, cr))->unref();
            drawClippedBitmap(canvas, paint, 110, y);

            paint.setImageFilter(SkLightingImageFilter::CreateSpotLitDiffuse(spotLocation, spotTarget, spotExponent, cutoffAngle, white, surfaceScale, kd, NULL, cr))->unref();
            drawClippedBitmap(canvas, paint, 220, y);

            y += 110;

            paint.setImageFilter(SkLightingImageFilter::CreatePointLitSpecular(pointLocation, white, surfaceScale, ks, shininess, NULL, cr))->unref();
            drawClippedBitmap(canvas, paint, 0, y);

            paint.setImageFilter(SkLightingImageFilter::CreateDistantLitSpecular(distantDirection, white, surfaceScale, ks, shininess, NULL, cr))->unref();
            drawClippedBitmap(canvas, paint, 110, y);

            paint.setImageFilter(SkLightingImageFilter::CreateSpotLitSpecular(spotLocation, spotTarget, spotExponent, cutoffAngle, white, surfaceScale, ks, shininess, NULL, cr))->unref();
            drawClippedBitmap(canvas, paint, 220, y);

            y += 110;
        }
    }
Ejemplo n.º 5
0
//
// The top-level function for running a query on the k-D tree.
//
void run_queries( Node *pVertex, double *model, int M, int D, 
		  double *closest_pt, double *distance, short ReturnType) {
  
  int i,j;
  double min_distance, *pt;
  Node *LL, *cur, *leaf, *tmp;
  
  pt= (double*)malloc(sizeof(double)*D);
  
  for (i=0; i < M; i++) {
    
#ifdef DEBUG_RUN_QUERIES
    mexPrintf("Running Query (%d/%d) (value: ",
	      i+1, M);
    for (j=0; j < D ; j++)
      mexPrintf(" %f", model[ M*j+i]);
    mexPrintf(" )\n");
#endif
    
    for (j=0; j < D; j++) 
      pt[j]=model[M*j+i];
    
    leaf=pointLocation(pVertex,pt,D);
    min_distance=calcdistance(leaf->pt, pt,D )+0.001;

    LL=rangeQuery(pVertex,min_distance,pt,D);

    if (!LL) {
      if (ReturnType == RETURN_INDEX) 
	closest_pt[i] = -1;
      else{
	for (j=0; j< D; j++)
	  closest_pt[j*M+i]=-1;
      }
      mexPrintf("Null LL\n");
    } 
    else {
      distance[i]=calcdistance(LL->pt, pt,D);
      if (ReturnType == RETURN_INDEX) 
	closest_pt[i] = LL->index;
      else {
	for (j=0; j < D; j++) 
	  closest_pt[j*M+i] = LL->pt[j];
      }
      cur=LL;
      while (cur){
	if ( calcdistance(cur->pt, pt,D) <= distance[i] ) {
	  if (ReturnType == RETURN_INDEX) 
	    closest_pt[i] = cur->index;
	  else {
	    for (j=0; j < D; j++) 
	      closest_pt[j*M+i] = cur->pt[j];
	  }
	  distance[i]=calcdistance(cur->pt, pt,D);
	}
	tmp=cur;
	cur=cur->right;
	free(tmp->pt);
	free(tmp);
      }
    }

#ifdef DEBUG_RUN_QUERIES
    mexPrintf("Distance to closest point is %f\n",distance[i]);
#endif

  }
  free(pt);
}
Ejemplo n.º 6
0
    virtual void onDraw(SkCanvas* canvas) {
        if (!fInitialized) {
            fCheckerboard.allocN32Pixels(64, 64);
            SkCanvas checkerboardCanvas(fCheckerboard);
            sk_tool_utils::draw_checkerboard(&checkerboardCanvas, 0xFFA0A0A0, 0xFF404040, 8);

            this->make_gradient_circle(64, 64);
            fInitialized = true;
        }
        canvas->clear(SK_ColorBLACK);

        SkAutoTUnref<SkImageFilter> gradient(SkBitmapSource::Create(fGradientCircle));
        SkAutoTUnref<SkImageFilter> checkerboard(SkBitmapSource::Create(fCheckerboard));
        SkAutoTUnref<SkShader> noise(SkPerlinNoiseShader::CreateFractalNoise(
            SkDoubleToScalar(0.1), SkDoubleToScalar(0.05), 1, 0));

        SkPoint3 pointLocation(0, 0, SkIntToScalar(10));
        SkPoint3 spotLocation(SkIntToScalar(-10), SkIntToScalar(-10), SkIntToScalar(20));
        SkPoint3 spotTarget(SkIntToScalar(40), SkIntToScalar(40), 0);
        SkScalar spotExponent = SK_Scalar1;
        SkScalar cutoffAngle = SkIntToScalar(15);
        SkScalar kd = SkIntToScalar(2);
        SkScalar surfaceScale = SkIntToScalar(1);
        SkColor white(0xFFFFFFFF);
        SkMatrix resizeMatrix;
        resizeMatrix.setScale(RESIZE_FACTOR, RESIZE_FACTOR);

        SkImageFilter* filters[] = {
            SkBlurImageFilter::Create(SkIntToScalar(4), SkIntToScalar(4)),
            SkDropShadowImageFilter::Create(SkIntToScalar(5), SkIntToScalar(10),
                SkIntToScalar(3), SkIntToScalar(3), SK_ColorYELLOW,
                SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode),
            SkDisplacementMapEffect::Create(SkDisplacementMapEffect::kR_ChannelSelectorType,
                                            SkDisplacementMapEffect::kR_ChannelSelectorType,
                                            SkIntToScalar(12),
                                            gradient.get(),
                                            checkerboard.get()),
            SkDilateImageFilter::Create(1, 1, checkerboard.get()),
            SkErodeImageFilter::Create(1, 1, checkerboard.get()),
            SkOffsetImageFilter::Create(SkIntToScalar(32), 0),
            SkImageFilter::CreateMatrixFilter(resizeMatrix, kNone_SkFilterQuality),
            SkRectShaderImageFilter::Create(noise),
            SkLightingImageFilter::CreatePointLitDiffuse(pointLocation, white, surfaceScale, kd),
            SkLightingImageFilter::CreateSpotLitDiffuse(spotLocation, spotTarget, spotExponent,
                                                        cutoffAngle, white, surfaceScale, kd),
        };

        SkVector scales[] = {
            SkVector::Make(SkScalarInvert(2), SkScalarInvert(2)),
            SkVector::Make(SkIntToScalar(1), SkIntToScalar(1)),
            SkVector::Make(SkIntToScalar(1), SkIntToScalar(2)),
            SkVector::Make(SkIntToScalar(2), SkIntToScalar(1)),
            SkVector::Make(SkIntToScalar(2), SkIntToScalar(2)),
        };

        SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64));
        SkScalar margin = SkIntToScalar(16);
        SkRect bounds = r;
        bounds.outset(margin, margin);

        for (size_t j = 0; j < SK_ARRAY_COUNT(scales); ++j) {
            canvas->save();
            for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) {
                SkPaint paint;
                paint.setColor(SK_ColorBLUE);
                paint.setImageFilter(filters[i]);
                paint.setAntiAlias(true);
                canvas->save();
                canvas->scale(scales[j].fX, scales[j].fY);
                if (5 == i) {
                    canvas->translate(SkIntToScalar(-32), 0);
                } else if (6 == i) {
                    canvas->scale(SkScalarInvert(RESIZE_FACTOR),
                                  SkScalarInvert(RESIZE_FACTOR));
                }
                canvas->drawCircle(r.centerX(), r.centerY(),
                                   SkScalarDiv(r.width()*2, SkIntToScalar(5)), paint);
                canvas->restore();
                canvas->translate(r.width() * scales[j].fX + margin, 0);
            }
            canvas->restore();
            canvas->translate(0, r.height() * scales[j].fY + margin);
        }

        for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) {
            filters[i]->unref();
        }
    }