Exemple #1
0
source_t *nearest_source(node_t *tree, double x, double y) {
    source_t *nearest = NULL;
    double dist;
    box_t interest;

    dist = dblmin(tree->box.xmax - tree->box.xmin, tree->box.ymax - tree->box.ymin) / 100.0;
    interest.xmin = x - dist;
    interest.ymin = y - dist;
    interest.xmax = x + dist;
    interest.ymax = y + dist;
    clip_box(&interest, &tree->box);
    dist = dist * dist;

    if (debug) {
        printf("nearest_source: \n");
        printf("  target (%0.2f, %0.2f)\n", x, y);
        printf("  interest (%0.4f, %0.4f) (%0.4f, %0.4f)\n", 
                interest.xmin, interest.ymin, interest.xmax, interest.ymax);
    }

    nearer_source(tree, tree, x, y, &interest, &nearest, &dist);

    if (debug)
        printf("\n");

    return nearest;
}
Exemple #2
0
void GetHSV(double r, double g, double b, double& h, double& s, double& v)
{
	v=dblmax(r, dblmax(g, b));
	double d=v-dblmin(r, dblmin(g, b));
	if(d==0.0) {s=0.0; h=0.0; /*std::cerr << "Error in HSV conversion\n";*/ return;}
	s=d/v;
	if(r==v)
	{
		if(g>=b)
			h = 0.167 * (g-b)/d;
		else
			h = 0.167 * (g-b)/d + 1.0;
	}
	if(g==v) h = 0.167 * (b-r)/d + 0.333;
	if(b==v) h = 0.167 * (r-g)/d + 0.667;
	v/=255.0;
}
Exemple #3
0
void clip_box(box_t *b, box_t *bounds) {
    b->xmin = dblmax(b->xmin, bounds->xmin);
    b->ymin = dblmax(b->ymin, bounds->ymin);
    b->xmax = dblmin(b->xmax, bounds->xmax);
    b->ymax = dblmin(b->ymax, bounds->ymax);
}