Exemple #1
0
void path_recalculate(unsigned pathid)
{
    path* const pth = pathstructarray[pathid];
    if (!pth) return;
    pth->total_length = 0;
    pth->pointoffset.clear();
    if (!pth->pointarray.size()) return;

    const size_t pc = pth->pointarray.size();
    const path_point& start = pth->closed ? pth->pointarray[pc-1] : pth->pointarray[0];
    const path_point& end  =  pth->closed ? pth->pointarray[0] : pth->pointarray[pc-1];
    //const path_point& beforestart  =  pth->closed ? pth->pointarray[pc-2] : pth->pointarray[0];
    //const path_point& afterend  =  pth->closed ? pth->pointarray[1] : pth->pointarray[pc-1];
    double minx=DBL_MAX,miny=DBL_MAX,maxx=-DBL_MAX,maxy=-DBL_MAX;
    for (size_t i = 0; i < pc; i++)
    {
        const double len =
            (pth->smooth) ?
            //blen(i==0 ? &beforestart : (i==1 ? &start : &pth->pointarray[i-2]), i==0 ? &start : &pth->pointarray[i-1], &pth->pointarray[i])
            //blen(&pth->pointarray[i], i==pc-1 ? &end : &pth->pointarray[i+1], i==pc-2 ? &afterend : (i==pc-1 ? &end : &pth->pointarray[i+2]))
            blen(i==0 ? &start : &pth->pointarray[i-1], &pth->pointarray[i], i+1==pc ? &end : &pth->pointarray[i+1])
            //blen((i==0 || i==1) ? &start : &pth->pointarray[i-2], (i==0) ? &start : &pth->pointarray[i-1], i+1==pc ? &end : &pth->pointarray[i])
            :
            llen(i==0 ? &start : &pth->pointarray[i-1], &pth->pointarray[i]);
        pth->pointarray[i].length = len;
        pth->total_length += len;

        minx = pth->pointarray[i].x<minx ? pth->pointarray[i].x : minx;
        miny = pth->pointarray[i].y<miny ? pth->pointarray[i].y : miny;
        maxx = pth->pointarray[i].x>maxx ? pth->pointarray[i].x : maxx;
        maxy = pth->pointarray[i].y>maxy ? pth->pointarray[i].y : maxy;
    }

    pth->centerx = minx + (maxx-minx)/2;
    pth->centery = miny + (maxy-miny)/2;

    double position = 0;
    for (size_t i = 0; i < pc; i++)
    {
        //if (pth->pointarray[i].length) {
        pth->pointoffset[position/pth->total_length] = i;
        position += pth->pointarray[i].length;
        //std::cout << "Position: " << position << " i: " << i << " length: " << pth->pointarray[i].length << std::endl;
        //}
    }
    //std::cout << "size of pointoffset: " << pth->pointoffset.size() << std::endl;
    //for (ppi_t i = pth->pointoffset.begin(); i != pth->pointoffset.end(); i++) std::cout << i->first << "=>" << i->second << std::endl;
}
Exemple #2
0
void
debug(const char *fmt, ...)
{
	va_list args;
	char *fmt2;

	va_start(args, fmt);

	fmt2 = malloc(strlen(PACKAGE) + 4 + llen(getpid()) + strlen(fmt) + 1);
	if (fmt2 != NULL) {
		sprintf(fmt2, "%s[%lu]: %s", PACKAGE,
			(unsigned long) getpid(), fmt);
		vsyslog(PACKAGE_FACILITY | LOG_DEBUG, fmt2, args);
		free(fmt2);
	} else {
		vsyslog(PACKAGE_FACILITY | LOG_DEBUG, fmt, args);
	}

	va_end(args);
}