Ejemplo n.º 1
0
ECL_H3_API void ECL_H3_CALL polyfill(ICodeContext *_ctx, bool &__isAllResult, size32_t &__lenResult, void *&__result, size32_t countBoundary, const byte **boundary, uint32_t resolution)
{
    //  Check for special case when points exceed 180 degrees (longtitude)
    //   - https://github.com/uber/h3/issues/210
    GeoCoord *poly = static_cast<GeoCoord *>(rtlCalloc(countBoundary, sizeof(GeoCoord)));
    GeoCoord *wPoly = static_cast<GeoCoord *>(rtlCalloc(countBoundary, sizeof(GeoCoord)));
    GeoCoord *ePoly = static_cast<GeoCoord *>(rtlCalloc(countBoundary, sizeof(GeoCoord)));
    double west = 0;
    double east = 0;
    for (int i = 0; i < countBoundary; ++i)
    {
        const GeoCoord *row = (GeoCoord *)boundary[i];
        double lat = ::degsToRads(row->lat);
        double lon = ::degsToRads(row->lon);
        poly[i].lat = lat;
        poly[i].lon = lon;
        wPoly[i].lat = lat;
        wPoly[i].lon = lon > 0 ? 0 : lon;
        ePoly[i].lat = lat;
        ePoly[i].lon = lon <= 0 ? 0 : lon;

        if (i == 0)
            west = east = row->lon;
        else if (west > row->lon)
            west = lon;
        else if (east < row->lon)
            east = lon;
    }
    if (east - west >= 180)
    {
        GeoPolygon wPolygon, ePolygon;
        int wMaxBuff = initPolygon(wPoly, countBoundary, resolution, wPolygon);
        int eMaxBuff = initPolygon(ePoly, countBoundary, resolution, ePolygon);
        H3Index *buff = static_cast<H3Index *>(rtlCalloc(wMaxBuff + eMaxBuff, sizeof(H3Index)));
        ::polyfill(&wPolygon, resolution, buff);
        ::polyfill(&ePolygon, resolution, buff + wMaxBuff);
        toSetOf(__isAllResult, __lenResult, __result, buff, wMaxBuff + eMaxBuff);
    }
    else
    {
        GeoPolygon polygon;
        int maxBuff = initPolygon(poly, countBoundary, resolution, polygon);
        H3Index *buff = static_cast<H3Index *>(rtlCalloc(maxBuff, sizeof(H3Index)));
        ::polyfill(&polygon, resolution, buff);
        toSetOf(__isAllResult, __lenResult, __result, buff, maxBuff);
    }
    rtlFree(ePoly);
    rtlFree(wPoly);
    rtlFree(poly);
}
Ejemplo n.º 2
0
static LWPolygon *makePolygon(LWPolygon *poly)
{
   LWPolygon *newPoly=NULL;
   if(newPoly = malloc(sizeof(LWPolygon)))
      if(poly)
      {
         newPoly->npoints=poly->npoints;
         newPoly->surface=poly->surface;
         newPoly->plist = calloc(sizeof(pntID),newPoly->npoints);
         if(newPoly->plist)
         {
            int i;
            for(i=0; i<newPoly->npoints; i++)
               newPoly->plist[i] = poly->plist[i];
         }
         else
         {
            free(newPoly);
            return NULL;
         }


      }
      else
         initPolygon(newPoly);
   return newPoly;
}
Ejemplo n.º 3
0
/*
 * Let us pre-render the tiles. Either we've a Custom Image as
 * background or we use the drawRect  to fill the background and
 * last we put the number on it
 */
void PiecesTable::slotCustomImage( const QString& _str ) {
    QString str = _str;


    /* couldn't load image fall back to plain tiles*/
    QImage img = QImage(str);
    QPixmap pix;
    if(img.isNull())
        str = QString::null;
    else{
        img = img.smoothScale( width(),height() );
        pix.convertFromImage( img );
    }

    /* initialize base point */
    uint image=0;

    /* clear the old tiles */
    clear();

    /* used variables */
    int cols = numCols();
    int rows = numRows();
    int cellW   = cellWidth();
    int cellH   = cellHeight();
    int x2      = cellW-1;
    int y2      = cellH-1;
    bool empty  = str.isEmpty();
    double bw      = empty ? 0.9 : 0.98;
    int	x_offset = cellW - int(cellW * bw);	// 10% should be enough
    int	y_offset = cellH - int(cellH * bw);

    /* border polygon calculation*/
    initPolygon(cellW, cellH, x_offset, y_offset );

    /* avoid crashes with isNull() pixmap later */
    if ( cellW == 0 || cellH == 0 ) {
        _pixmap.resize( 0 );
        return;
    }

    /* make it bold and bigger */
    QFont f = font();
    f.setPixelSize(18);
    f.setBold( TRUE );

    /* for every tile */
    for(int row = 0; row < rows; ++row ) {
        for(int col= 0; col < cols; ++col) {
            QPixmap *pip = new QPixmap(cellW, cellH );
            QPainter *p = new QPainter(pip );
            p->setFont( f );

            /* draw the tradional tile  or a part of the pixmap*/
            if(empty) {
                p->setBrush(_colors[image]);
                p->setPen(NoPen);
                p->drawRect(0,0,cellW,cellH);
            }else
                p->drawPixmap(0, 0, pix,col*cellW, row*cellH, cellW, cellH );

            // draw borders
            if (height() > 40) {
                p->setBrush(_colors[image].light(130));
                p->drawPolygon(light_border);

                p->setBrush(_colors[image].dark(130));
                p->drawPolygon(dark_border);
            }

            // draw number
            p->setPen(black);
            p->drawText(0, 0, x2, y2, AlignHCenter | AlignVCenter, QString::number(image+1));

            delete p;
            _pixmap[image++] =  pip;
        }
    }
    _image = str;
}