bool copy_block(Tile* tiles, const Block* block) { const p2i& p = block->position; int xp = (p.x - START_X + SQUARE_SIZE / 2) / SQUARE_SIZE; int yp = (p.y - START_Y + SQUARE_SIZE / 2) / SQUARE_SIZE; if (is_block_available(tiles, xp, yp)) { for (int i = 0; i < 4; ++i) { int cx = xp + MARK_STEPS[i * 2]; int cy = yp + MARK_STEPS[i * 2 + 1]; uint32_t idx = get_tiles_index(cx, cy); Tile& t = tiles[idx]; t.state.set(BIT_MARKED); t.color = block->colors[i]; PointList list; check(tiles, cx, cy, -1, list, true); list.add(cx, cy); if (list.size() > 2) { //LOG << "connected"; t.state.set(BIT_COHERENT); for (size_t j = 0; j < list.size(); ++j) { const p2i& p = list.get(j); //LOG << j << " = " << p.x << " " << p.y; set_state(tiles, p.x, p.y, BIT_COHERENT); } } } determineEdges(tiles); return true; } else { //LOG << "Block is not available"; } return false; }
bool CollisionManager::isIntersectsPointPolygon(ICollisionHull* point, ICollisionHull* polygon) { PointCollisionHull* pointCH = dynamic_cast<PointCollisionHull*>(point); PoligonCollisionHull* poligonCH = dynamic_cast<PoligonCollisionHull*>(polygon); Vector3 position = pointCH->getPosition(); PointList points = poligonCH->getPoints(); int i0, i1; float A, B, C, D; Vector3 P0, P1; for(int i = 0; i < points.size(); i++) { i0 = i; i1 = (i == (points.size() - 1)) ? 0 : i + 1; P0 = points[i0]; P1 = points[i1]; A = P0._y - P1._y; B = P1._x - P0._x; C = (P0._x * P1._y) - (P1._x * P0._y); D = (A * position._x) + (B * position._y) + C; if(D > 0) { return false; } } return true; }
void computePlanes(const PointList& front, const PointList& back, Polytope::PlaneList& planeList) { for(unsigned int i=0;i<front.size();++i) { unsigned int i_1 = (i+1)%front.size(); // do the mod to wrap the index round back to the start. if (!(front[i].first & front[i_1].first)) { planeList.push_back(Plane(front[i].second,front[i_1].second,back[i].second)); } } }
void ColoredPolygon::UpdatePoints(const PointList &points) { _dots.resize(points.size()); for (uint i = 0; i < points.size(); ++i) { _dots[i].pos = points[i]; } CalcWidthAndHeight(); GenerateTriangles(); _dotUnderCursor.clear(); _selectedDots.clear(); InitCorners(); }
void writeSQL(Site_2 site, PointList polygon, char* outdir) { std::cout << "INSERT INTO " << outdir << " (geom, id) VALUES ("; std::cout << "'POLYGON (("; for (int i = 0; i < polygon.size(); i++) { Point_2 p = polygon.at(i); std::cout << p.x() << " " << p.y(); if (i < polygon.size() - 1) { std::cout << ", "; } } std::cout << "))', " << site.id() << ");" << std::endl; }
void handleDual(Hyperbola_segment_2 hs, std::vector<PointList>& polylines) { std::cerr << "hyperbola segment" << std::endl; //hs.draw(str); PointList p; hs.generate_points(p); std::cerr << "# hyperbola points: " << p.size() << std::endl; PointList points; points.insert(points.end(), p.begin(), p.end()); polylines.push_back(points); for (unsigned int i = 0; i < p.size() - 1; i++) { Segment_2 seg(p[i], p[i+1]); // doing nothing here } }
void draw_hand_trace(sf::RenderWindow& window, const PointList& pointList, const sf::Color& color, const float depthScale) { if (pointList.size() < 2) { return; } const float thickness = 4; auto it = pointList.begin(); astra::Vector2i previousPoint = *it; while (it != pointList.end()) { const astra::Vector2i currentPoint = *it; ++it; const sf::Vector2f p1((previousPoint.x + .5f) * depthScale, (previousPoint.y + .5f) * depthScale); const sf::Vector2f p2((currentPoint.x + .5f) * depthScale, (currentPoint.y + .5f) * depthScale); previousPoint = currentPoint; window.draw(sfLine(p1, p2, color, thickness)); } }
void Dataset<D, ELEM_TYPE>::load(const PointList& newPoints) { // Pre-allocate memory in one sys call m_points.reserve(m_points.size() + newPoints.size()); // Append given points to end of current point list m_points.insert(m_points.end(), newPoints.begin(), newPoints.end()); }
ColoredPolygon::ColoredPolygon(const PointList &points) { _dots.resize(points.size()); for (uint i = 0; i < points.size(); ++i) { _dots[i].pos = points[i]; } CalcWidthAndHeight(); GenerateTriangles(); _mouseDown = false; _dotUnderCursor.clear(); _selectedDots.clear(); _debugDraw = false; InitCorners(); _color = 0xFFFFFFFF; }
BucketKDTreeNode<D, ELEM_TYPE>::BucketKDTreeNode( BucketKDTreeNode<D, ELEM_TYPE>* parent, const PointList& points) : m_parent(parent), m_totalPoints(points.size()), m_isLeaf(true), m_points(points), m_leftChild(NULL), m_rightChild(NULL), m_cuttingDimension(0), m_cuttingValue(0) { }
void copyPointListToVertexList(const PointList& in,VertexList& out) { out.reserve(in.size()); for(PointList::const_iterator itr=in.begin(); itr!=in.end(); ++itr) { out.push_back(itr->second); } }
// compute the volume between the front and back polygons of the occluder/hole. float computePolytopeVolume(const PointList& front, const PointList& back) { float volume = 0.0f; Vec3 frontStart = front[0].second; Vec3 backStart = back[0].second; for(unsigned int i=1;i<front.size()-1;++i) { volume += computeVolume(frontStart, front[i].second, front[i+1].second, backStart, back[i].second, back[i+1].second); } return volume; }
// clip the convex hull 'in' to plane to generate a clipped convex hull 'out' // return true if points remain after clipping. unsigned int clip(const Plane& plane,const PointList& in, PointList& out,unsigned int planeMask) { std::vector<float> distance; distance.reserve(in.size()); for(PointList::const_iterator itr=in.begin(); itr!=in.end(); ++itr) { distance.push_back(plane.distance(itr->second)); } out.clear(); for(unsigned int i=0;i<in.size();++i) { unsigned int i_1 = (i+1)%in.size(); // do the mod to wrap the index round back to the start. if (distance[i]>=0.0f) { out.push_back(in[i]); if (distance[i_1]<0.0f) { unsigned int mask = (in[i].first & in[i_1].first) | planeMask; float r = distance[i_1]/(distance[i_1]-distance[i]); out.push_back(Point(mask,in[i].second*r+in[i_1].second*(1.0f-r))); } } else if (distance[i_1]>0.0f) { unsigned int mask = (in[i].first & in[i_1].first) | planeMask; float r = distance[i_1]/(distance[i_1]-distance[i]); out.push_back(Point(mask,in[i].second*r+in[i_1].second*(1.0f-r))); } } return out.size(); }
void writeWKT(Site_2 site, PointList polygon, char* outdir) { // open an output file for storing the WKT std::stringstream s; s << outdir << "/" << site.id() << ".wkt"; std::string polygonFileName = s.str(); std::cerr << "filename: " << polygonFileName << std::endl; std::ofstream file; file.open(polygonFileName.c_str()); // write WKT file file << "POLYGON (("; for (int i = 0; i < polygon.size(); i++) { Point_2 p = polygon.at(i); file << p.x() << " " << p.y(); if (i < polygon.size() - 1) { file << ", "; } } file << "))"; file.close(); }
void handleDual(Hyperbola_ray_2 hr, Iso_rectangle_2 crect, std::vector<PointList>& polylines) { std::cerr << "hyperbola ray" << std::endl; // hr.draw(str); PointList p; hr.generate_points(p); PointList points; points.insert(points.end(), p.begin(), p.end()); polylines.push_back(points); for (unsigned int i = 0; i < p.size() - 1; i++) { Segment_2 seg(p[i], p[i+1]); // doing nothing here } }
boost::optional<Point> fastFilterPointList( const PointList& pointList, std::vector<Point>& newPointList) const { assert(!pointList.empty()); newPointList.reserve(pointList.size() - 1); std::copy( ++pointList.begin(), pointList.end(), std::back_inserter(newPointList) ); return boost::optional<Point>(pointList.front()); } // fastFilterFunctorList
void writeGeoJSON(Site_2 site, PointList polygon, char* outdir) { // open an output file for storing the WKT std::stringstream s; s << outdir << "/" << site.id() << ".geojson"; std::string polygonFileName = s.str(); std::cerr << "filename: " << polygonFileName << std::endl; std::ofstream file; file.open(polygonFileName.c_str()); // write data file << "{\"type\":\"Polygon\",\"coordinates\":[["; for (int i = 0; i < polygon.size(); i++) { Point_2 p = polygon.at(i); file << "[" << p.x() << ", " << p.y() << "]"; if (i < polygon.size() - 1) { file << ", "; } } file << "]]}"; file.close(); }
//----------------------------------------------------------------------------- void CGDrawContext::drawPolygon (const PointList& polygonPointList, const CDrawStyle drawStyle) { if (polygonPointList.size () == 0) return; CGContextRef context = beginCGContext (true, getDrawMode ().integralMode ()); if (context) { CGPathDrawingMode m; switch (drawStyle) { case kDrawFilled : m = kCGPathFill; break; case kDrawFilledAndStroked : m = kCGPathFillStroke; break; default : m = kCGPathStroke; break; } applyLineStyle (context); CGContextBeginPath (context); CGPoint p = CGPointFromCPoint(polygonPointList[0]); if (getDrawMode ().integralMode ()) p = pixelAlligned (p); CGContextMoveToPoint (context, p.x, p.y); for (uint32_t i = 1; i < polygonPointList.size (); i++) { p = CGPointFromCPoint (polygonPointList[i]); if (getDrawMode ().integralMode ()) p = pixelAlligned (p); CGContextAddLineToPoint (context, p.x, p.y); } CGContextDrawPath (context, m); releaseCGContext (context); } }
//----------------------------------------------------------------------------- void D2DDrawContext::drawPolygon (const PointList& polygonPointList, const CDrawStyle drawStyle) { if (renderTarget == 0 || polygonPointList.size () == 0) return; D2DApplyClip ac (this); if (ac.isEmpty ()) return; D2DGraphicsPath path; path.beginSubpath (polygonPointList[0]); for (uint32_t i = 1; i < polygonPointList.size (); ++i) { path.addLine (polygonPointList[i]); } if (drawStyle == kDrawFilled || drawStyle == kDrawFilledAndStroked) { drawGraphicsPath (&path, kPathFilled); } if (drawStyle == kDrawStroked || drawStyle == kDrawFilledAndStroked) { drawGraphicsPath (&path, kPathStroked); } }
void Init() { gInterList.clear(); GenerateConvex(gN,200,Point2D(200,200),gP); GenerateConvex(gM,200,Point2D(350,200),gQ); Point2D point; int i, j; for( i = 0 ; i < gN ; i++ ) for( j = 0 ; j < gM ; j++ ) { if( SegInterSeg(gP[i],gP[Next(i,gN)],gQ[j],gQ[Next(j,gM)],point) ) printf("(%d,%d)\n",i,j); } ConvexInterConvex(gP,gN,gQ,gM,gInterList); printf("%d\n",gInterList.size()); }
Node<Key, T> buildNode( const typename NodeTypes<Key, T>::ValueList& valueList, const PointList& pointList) { minLength_ = pointList.size(); Node<Key, T> result; { util::ThreadPoolRunner runner(threadPool_); doBuildNode<Key, T>( valueList, pointList, maxDepth_, false, State(), result); } return result; }
void Surface::MultiBlit ( const Surface &surf, const PointList &p, const RectList &r, const Surf::BlitFX &fx ) { int ir, rsize = r.size(); int ip, psize = p.size(); for( ir=0, ip=0; ir!=rsize && ip!=psize; ++ir, ++ip ) { if (!r[ir]) continue; Pos ps = p[ip]; Rect rc = r[ir]; Blit( ps.x, ps.y , surf, rc, fx ); } }
void IndexPseudoPyramidTree::rebuild() { // Store old points to re-insert into structure PointList oldPoints = points; // Clear all data from structure points.clear(); pointSums.clear(); hashMap.clear(); // Insert non-marked pooints into structure incrementally for (unsigned int i = 0; (i < oldPoints.size()); i++) { // Only insert point if its old index has NOT been marked as empty if (std::find(emptyElementIndices.begin(), emptyElementIndices.end(), i) == emptyElementIndices.end()) insert(oldPoints[i]); } // Now clear the marked elements list emptyElementIndices.clear(); }
// clip the convex hull 'in' to planeList to generate a clipped convex hull 'out' // return true if points remain after clipping. unsigned int clip(const Polytope::PlaneList& planeList,const VertexList& vin,PointList& out) { PointList in; copyVertexListToPointList(vin,in); unsigned int planeMask = 0x1; for(Polytope::PlaneList::const_iterator itr=planeList.begin(); itr!=planeList.end(); ++itr) { if (!clip(*itr,in,out,planeMask)) return false; in.swap(out); planeMask <<= 1; } in.swap(out); return out.size(); }
void modify_geometry(int obj, Scene& scene, GeometryList& out) { PointList* points = out.writable_points(obj); const unsigned n = points->size(); // Transform points: if (swap) { // POW for (unsigned i = 0; i < n; i++) { Vector3& v = (*points)[i]; if (clamp_black) { if (v.x <= 0.0f) v.x = 0; else v.x = pow(v.x, log.x); if (v.y <= 0.0f) v.y = 0; else v.y = pow(v.y, log.y); if (v.z <= 0.0f) v.z = 0; else v.z = pow(v.z, log.z); } else { v.x = (v.x > 0.0f) ? pow(v.x, log.x) : -pow(-v.x, log.x); v.y = (v.y > 0.0f) ? pow(v.y, log.y) : -pow(-v.y, log.y); v.z = (v.z > 0.0f) ? pow(v.z, log.z) : -pow(-v.z, log.z); } } } else { // LOG for (unsigned i = 0; i < n; i++) { Vector3& v = (*points)[i]; v.x = pow(log.x, v.x) - 1.0f; v.y = pow(log.y, v.y) - 1.0f; v.z = pow(log.z, v.z) - 1.0f; } } }
int main() { PointList points; // Generate points points.resize(sc_pointCount); for (unsigned int i = 0; i < points.size(); ++i) { points[i] = Point( rand()%(maxCoordinate*2) - maxCoordinate, rand()%(maxCoordinate*2) - maxCoordinate); } findClosestPoints(points, sc_numPointsToFind); // Print out results for (unsigned int i = 0; i < sc_numPointsToFind; ++i) { Point& point = points[i]; std::cout << "(" << point.x << "," << point.y << ") "; } return 0; }
// Finlds numPoints elements closest to zero and rearranges them to the // beginning of |points| void findClosestPoints(PointList& points, int numPoints) { int startPos = 0; int endPos = points.size() - 1; // Value to use for sorting, all smaller values go to left, all // bigger ones go to right int value = points[0].distance; while(startPos != numPoints) { const int pos = SortOut(points, value, startPos, endPos); std::cout << "( " << startPos << " - " << endPos << " )" << std::endl; if (pos > numPoints) { endPos = pos - 1; value = points[endPos].distance; } else if (pos < numPoints) { startPos = pos + 1; value = points[startPos].distance; } else { // pos == numPoints return; } } }
// ============================================================================ // Draw points and curves // ============================================================================ void CBezierWnd::Draw() { // Draw control point handles and labels for ( PointSetIt i = m_Points.begin(); i != m_Points.end(); ++i ) { DrawHandle( *i ); DrawLabel( *i ); } if ( m_Points.size() < 3) return; // Draw curve PointList lPoints; for ( PointSetIt i = m_Points.begin(); i != m_Points.end(); ++i ) lPoints.push_back( *i ); CPoint2D p2DStart = *m_Points.begin(); float fStep = 1.f / ( 10.f * ( float ) lPoints.size() ); for ( float i = 0.f; i <= 1.f; i+= fStep ) { CPoint2D p2D = GetBezierPoint( lPoints, i ); DrawLine( p2DStart, p2D ); p2DStart = p2D; } DrawLine( p2DStart, lPoints.back() ); // Draw control polygon if ( m_bDrawPoly ) { PointSetIt i = m_Points.begin(), iPrev = i++; do { DrawLine( *iPrev, *i ); iPrev = i++; } while ( i != m_Points.end() ); } }
bool CollisionManager::isIntersectsCirclePolygon(ICollisionHull* circle, ICollisionHull* polygon) { CircleCollisionHull* circleCH = dynamic_cast<CircleCollisionHull*>(circle); PoligonCollisionHull* poligonCH = dynamic_cast<PoligonCollisionHull*>(polygon); Vector3 position = circleCH->getPosition(); float radius = circleCH->getRadius(); PointList points = poligonCH->getPoints(); Vector3 dv; float distance; for(int i = 0; i < points.size(); i++) { dv = position - points[i]; distance = dv.length(); if(distance <= radius) { return true; } } return false; }
//----------------------------------------------------------------------------- void GdiplusDrawContext::drawPolygon (const PointList& polygonPointList, const CDrawStyle drawStyle) { if (polygonPointList.size () == 0) return; GdiplusDrawScope drawScope (pGraphics, currentState.clipRect, getCurrentTransform ()); Gdiplus::PointF points[30]; Gdiplus::PointF* polyPoints; bool allocated = false; if (polygonPointList.size () > 30) { polyPoints = new Gdiplus::PointF[polygonPointList.size ()]; allocated = true; } else polyPoints = points; for (uint32_t i = 0; i < polygonPointList.size (); i++) { polyPoints[i].X = (Gdiplus::REAL)(polygonPointList[i].x); polyPoints[i].Y = (Gdiplus::REAL)(polygonPointList[i].y); } if (drawStyle == kDrawFilled || drawStyle == kDrawFilledAndStroked) pGraphics->FillPolygon (pBrush, polyPoints, static_cast<INT> (polygonPointList.size ())); if (drawStyle == kDrawFilledAndStroked || drawStyle == kDrawStroked) { pGraphics->TranslateTransform (0.5f, 0.5f); pGraphics->DrawPolygon (pPen, polyPoints, static_cast<INT> (polygonPointList.size ())); pGraphics->TranslateTransform (-0.5f, -0.5f); } if (allocated) delete[] polyPoints; }