void copyCoordinates(Coordinates& dst, const Coordinates& src) { assert(dst.size() >= src.size()); for (Coordinates::size_type i = 0; i < src.size(); ++i) { dst[i] = src[i]; } }
bool Clipping::clipCurve(Object *obj){ auto& coords = obj->getNCoords(); Coordinates newPath; bool prevInside = true; Coordinate prev; for(unsigned int i = 0; i < coords.size(); i++){ if(clipPoint(coords[i])){ if(!prevInside){ clipLine(prev, coords[i]); newPath.push_back(prev); } newPath.push_back(coords[i]); prevInside = true; }else{ if(prevInside && newPath.size() != 0){ clipLine(prev, coords[i]); newPath.push_back(coords[i]); } prevInside = false; } prev = coords[i]; } if(newPath.size() == 0) return false; obj->setNCoord(newPath); return true; }
void Clipping::clipBottom(Coordinates& input, Coordinates& output){ if(output.size() > 0) output.clear(); if(input.size() == 0) return; double clipY = m_w->minY; input.push_back(input[0]); for(unsigned int i = 0; i < input.size()-1; i++){ Coordinate c0 = input[i]; Coordinate c1 = input[i+1]; //Caso 1: out -> out if(c0.y < clipY && c1.y < clipY){} //Caso 2: in -> in if(c0.y >= clipY && c1.y >= clipY) output.push_back(c1); double y = clipY; double m = (c1.x-c0.x)/(c1.y-c0.y); double x = m * (y-c0.y) + c0.x; //Caso 3: in -> out if(c0.y >= clipY && c1.y < clipY) output.emplace_back(x,y); //Caso 4: out -> in if(c0.y < clipY && c1.y >= clipY){ output.emplace_back(x,y); output.push_back(c1); } } }
void Clipping::clipRight(Coordinates& input, Coordinates& output){ if(output.size() > 0) output.clear(); if(input.size() == 0) return; double clipX = m_w->maxX; input.push_back(input[0]); for(unsigned int i = 0; i < input.size()-1; i++){ Coordinate c0 = input[i]; Coordinate c1 = input[i+1]; //Caso 1: out -> out if(c0.x >= clipX && c1.x >= clipX){} //Caso 2: in -> in if(c0.x < clipX && c1.x < clipX) output.push_back(c1); double x = clipX; double m = (c1.y-c0.y)/(c1.x-c0.x); double y = m * (x-c0.x) + c0.y; //Caso 3: in -> out if(c0.x < clipX && c1.x >= clipX) output.emplace_back(x,y); //Caso 4: out -> in if(c0.x >= clipX && c1.x < clipX){ output.emplace_back(x,y); output.push_back(c1); } } }
BezierCurve::BezierCurve(const Coordinates& coords) { if (coords.size() < 4 || (coords.size() - 4) % 3 != 0) { throw CGException("A bezier curve must be defined with 4, 7, 10, 13, 16, ... coordinates"); } addCoordinate(coords); regeneratePath(0.1); }
void CrossJoinArray::composeOutCoordinates(Coordinates const &left, Coordinates const& rightLeftover, Coordinates& out) const { assert(left.size() == nLeftDims); assert(rightLeftover.size() == nRightDims - nJoinDims); assert(out.size() == desc.getDimensions().size()); memcpy(&out[0], &left[0], nLeftDims*sizeof(Coordinate)); memcpy(&out[left.size()], &rightLeftover[0], (nRightDims-nJoinDims)*sizeof(Coordinate)); }
/// Converts geometry. void fillVertices(const Coordinates &coordinates) { vertices_.reserve(coordinates.size() * 3); for (std::size_t i = 0; i < coordinates.size(); ++i) { const utymap::GeoCoordinate coordinate = coordinates[i]; vertices_.push_back(coordinate.longitude); vertices_.push_back(coordinate.latitude); vertices_.push_back(eleProvider_ == nullptr ? 0 : eleProvider_->getElevation(quadKey_, coordinate)); } }
int main(int argc, char *argv[]) { int rows = SIZE; int cols = SIZE; bool fullyrand = true; BenchTimer timer; Coordinates coords; Values values; if(fullyrand) { Coordinates pool; pool.reserve(cols*NBPERROW); std::cerr << "fill pool" << "\n"; for (int i=0; i<cols*NBPERROW; ) { // DynamicSparseMatrix<int> stencil(SIZE,SIZE); Vector2i ij(ei_random<int>(0,rows-1),ei_random<int>(0,cols-1)); // if(stencil.coeffRef(ij.x(), ij.y())==0) { // stencil.coeffRef(ij.x(), ij.y()) = 1; pool.push_back(ij); } ++i; } std::cerr << "pool ok" << "\n"; int n = cols*NBPERROW*KK; coords.reserve(n); values.reserve(n); for (int i=0; i<n; ++i) { int i = ei_random<int>(0,pool.size()); coords.push_back(pool[i]); values.push_back(ei_random<Scalar>()); } } else { for (int j=0; j<cols; ++j) for (int i=0; i<NBPERROW; ++i) { coords.push_back(Vector2i(ei_random<int>(0,rows-1),j)); values.push_back(ei_random<Scalar>()); } } std::cout << "nnz = " << coords.size() << "\n"; CHECK_MEM // dense matrices #ifdef DENSEMATRIX { BENCH(setrand_eigen_dense(coords,values);) std::cout << "Eigen Dense\t" << timer.value() << "\n"; }
void Coordinates_test:: t_readonly() { Coordinates c; QCOMPARE(c.size(), 0u); QCOMPARE(c.count(), 0); QVERIFY(c.isEmpty()); c << 1.0 << -2.0; QCOMPARE(c.size(), 2u); QCOMPARE(c.count(), 2); QVERIFY(!c.isEmpty()); }//t_readonly
void CrossJoinArray::decomposeLeftCoordinates(Coordinates const& left, Coordinates& hashKey) const { assert(left.size() == nLeftDims); assert(hashKey.size() == nJoinDims); for (size_t i =0; i<nLeftDims; i++) { if(leftJoinDims[i]!=-1) { hashKey[leftJoinDims[i]] = left[i]; } } }
int CubicSpline<DT>::calculate(const Coordinates &xs, const Coordinates &ys, DT yp1, DT ypn) { MustBeTrue(xs.size() == ys.size()); MustBeTrue((npoints_= xs.size()) > 0); xs_ = xs; ys_ = ys; yp1_ = yp1; ypn_ = ypn; ypps_.resize(npoints_+1); calculate(); return(0); }
void Viewport::drawPolygon(Object* obj){ auto coords = obj->getNCoords(); Coordinates nCoords; if(coords.size() == 1){// Usuario quer um ponto? drawPoint(obj); return; }else if(coords.size() == 2){// Usuario quer uma linha? drawLine(obj); return; } transformCoordinates(coords, nCoords); prepareContext(obj); cairo_move_to(m_cairo, nCoords[0].x, nCoords[0].y); for(unsigned int i = 0; i<nCoords.size(); i++) cairo_line_to(m_cairo, nCoords[i].x, nCoords[i].y); cairo_close_path(m_cairo); Polygon* p = (Polygon*) obj; if(p->filled()){ cairo_stroke_preserve(m_cairo); cairo_fill(m_cairo); }else cairo_stroke(m_cairo); }
SplitArray::SplitArray(ArrayDesc const& desc, const boost::shared_array<char>& src, Coordinates const& from, Coordinates const& till, shared_ptr<Query>const& query) : DelegateArray(desc, shared_ptr<Array>(), true), _startingChunk(from), _from(from), _till(till), _size(from.size()), _src(src), _empty(false) { assert(query); _query = query; desc.getChunkPositionFor(_startingChunk); Dimensions const& dims = desc.getDimensions(); for (size_t i = 0, n = dims.size(); i < n; i++) { _size[i] = _till[i] - _from[i] + 1; if (_size[i] == 0) { _empty = true; } if (_till[i] > dims[i].getEndMax()) { _till[i] = dims[i].getEndMax(); } } }
void Coordinates_test:: t_convert() { Coordinates c; c << 1.0 << 3.0; QCOMPARE(c.data()[1], 3.0); coordT *c2= c.data(); const coordT *c3= c.data(); QCOMPARE(c2, c3); std::vector<coordT> vc= c.toStdVector(); QCOMPARE(vc.size(), c.size()); for(size_t k= vc.size(); k--; ){ QCOMPARE(vc[k], c[k]); } QList<coordT> qc= c.toQList(); QCOMPARE(qc.count(), c.count()); for(int k= qc.count(); k--; ){ QCOMPARE(qc[k], c[k]); } Coordinates c4; c4= std::vector<double>(2, 0.0); QCOMPARE(c4.back(), 0.0); Coordinates c5(std::vector<double>(2, 0.0)); QCOMPARE(c4.size(), c5.size()); QVERIFY(c4==c5); }//t_convert
Fleissner::Fleissner(const Coordinates &key, const uint32_t grid_dim, const bool clockwise) { Coordinates coords(key); setGridDimension(grid_dim); const uint32_t key_size = key.size(); const uint32_t mask_size_approuved = key_size * 4; if (mask_size_approuved != (grid_dim * grid_dim)) { throw BadKeyLength("Your key have to be square following the dimension you provided.", mask_size_approuved); } // If the rotation coordinates exist, then the mask is not valid. // Mask rotations 270, 180, 90 degrees to check. coords.reserve(mask_size_approuved); std::set<Cell> rotation; if (clockwise) { for (const auto &xy : key) { rotationExists(rotation, xy.second, grid_dim - 1 - xy.first); } } else { for (const auto &xy : key) { rotationExists(rotation, grid_dim - 1 - xy.second, xy.first); } } coords.insert(coords.end(), rotation.begin(), rotation.end()); rotation.clear(); for (const auto &xy : key) { rotationExists(rotation, grid_dim - 1 - xy.first, grid_dim - 1 - xy.second); } coords.insert(coords.end(), rotation.begin(), rotation.end()); rotation.clear(); if (clockwise) { for (const auto &xy : key) { rotationExists(rotation, grid_dim - 1 - xy.second, xy.first); } } else { for (const auto &xy : key) { rotationExists(rotation, xy.second, grid_dim - 1 - xy.first); } } coords.insert(coords.end(), rotation.begin(), rotation.end()); this->key = coords; }
inline int64_t getCatalogHash(Coordinates const& pos, int64_t error) { int64_t hash = 0; for (size_t i = 0, n = pos.size(); i < n; i++) { hash *= HASH_MULTIPLIER; hash ^= pos[i]/error; } return hash; }
inline bool isNeighbor(Coordinates const& from, Coordinates const& till, int64_t error) { for (size_t i = 0, n = from.size(); i < n; i++) { if (abs(till[i] - from[i]) > error) { return false; } } return true; }
SplineCurve::SplineCurve(const Coordinates& coords) { if (coords.size() < 4) { throw CGException("A spline curve must have at least 4 coordinates"); } addCoordinate(coords); regeneratePath(0.1); }
void CrossJoinArray::decomposeOutCoordinates(Coordinates const& out, Coordinates& left, Coordinates& hashKey, Coordinates& rightLeftover) const { assert(out.size() == desc.getDimensions().size()); assert(left.size() == nLeftDims); assert(rightLeftover.size() == nRightDims-nJoinDims); assert(hashKey.size() == nJoinDims); left.assign(out.begin(), out.begin()+nLeftDims); rightLeftover.assign(out.begin()+nLeftDims, out.end()); for (size_t i =0; i<nLeftDims; i++) { if(leftJoinDims[i]!=-1) { hashKey[leftJoinDims[i]] = out[i]; } } }
void Array::getOriginalPosition(std::vector<Value>& origCoords, Coordinates const& intCoords, const boost::shared_ptr<Query>& query) const { size_t nDims = intCoords.size(); origCoords.resize(nDims); ArrayDesc const& desc = getArrayDesc(); for (size_t i = 0; i < nDims; i++) { origCoords[i] = desc.getOriginalCoordinate(i, intCoords[i], query); } }
inline void ConstRLEChunk::pos2coord(uint32_t const& pos, Coordinates& coord) const { uint32_t currentPos = pos; for (int i = (int) coord.size(); --i >= 0;) { coord[i] = _firstPosition[i] + (currentPos % _chunkIntervals[i]); currentPos /= _chunkIntervals[i]; } }
inline uint32_t ConstRLEChunk::coord2pos(Coordinates const& coord) const { uint32_t pos = 0; for (size_t i = 0, n = coord.size(); i < n; i++) { pos *= _chunkIntervals[i]; pos += coord[i] - _firstPosition[i]; } return pos; }
void CrossJoinArray::decomposeRightCoordinates(Coordinates const& right, Coordinates& hashKey, Coordinates &rightLeftover) const { assert(hashKey.size() == nJoinDims); assert(rightLeftover.size() == nRightDims - nJoinDims); assert(right.size() == nRightDims); size_t k=0; size_t j=0; for(size_t i=0; i<nRightDims; i++) { if(rightJoinDims[i]!=-1) { hashKey[k++]=right[i]; } else { rightLeftover[j++]=right[i]; } } }
void SubArray::addChunksToSet(Coordinates outChunkCoords, size_t dim) { //if we are not aligned, then each input chunk can contribute to up to 2^nDims output chunks //therefore, the recursion for(size_t i= (dim == 0 ? 0 : dim -1), n = outChunkCoords.size(); i<n; i++) { if (outChunkCoords[i]<dims[i].getStartMin() || outChunkCoords[i]>dims[i].getEndMax()) { return; } } if(aligned || dim == outChunkCoords.size()) { _chunkSet.insert(outChunkCoords); } else { addChunksToSet(outChunkCoords, dim+1); outChunkCoords[dim]+=dims[dim].getChunkInterval(); addChunksToSet(outChunkCoords, dim+1); } }
void Viewport::drawCurve(Object* obj){ auto coords = obj->getNCoords(); Coordinates nCoords; transformCoordinates(coords, nCoords); prepareContext(obj); cairo_move_to(m_cairo, nCoords[0].x, nCoords[0].y); for(unsigned int i = 0; i<nCoords.size(); i++) cairo_line_to(m_cairo, nCoords[i].x, nCoords[i].y); cairo_stroke(m_cairo); }
void visitElement(const utymap::entities::Element& element, const Coordinates& coordinates) { // convert tags std::vector<const char*> ctags; tagStrings_.reserve(element.tags.size() * 2); ctags.reserve(element.tags.size() * 2); for (auto i = 0; i < element.tags.size(); ++i) { const utymap::entities::Tag& tag = element.tags[i]; tagStrings_.push_back(stringTable_.getString(tag.key)); tagStrings_.push_back(stringTable_.getString(tag.value)); ctags.push_back(tagStrings_[tagStrings_.size() - 2].c_str()); ctags.push_back(tagStrings_[tagStrings_.size() - 1].c_str()); } // convert geometry std::vector<double> coords; coords.reserve(coordinates.size() * 2); for (auto i = 0; i < coordinates.size(); ++i) { const utymap::GeoCoordinate coordinate = coordinates[i]; coords.push_back(coordinate.longitude); coords.push_back(coordinate.latitude); } // convert style utymap::mapcss::Style style = styleProvider_.forElement(element, levelOfDetail_); std::vector<const char*> cstyles; tagStrings_.reserve(style.declarations.size() * 2); cstyles.reserve(style.declarations.size()); for (const auto pair : style.declarations) { styleStrings_.push_back(stringTable_.getString(pair.first)); styleStrings_.push_back(*pair.second->value()); cstyles.push_back(styleStrings_[styleStrings_.size() - 2].c_str()); cstyles.push_back(styleStrings_[styleStrings_.size() - 1].c_str()); } elementCallback_(element.id, ctags.data(), ctags.size(), coords.data(), coords.size(), cstyles.data(), cstyles.size()); tagStrings_.clear(); styleStrings_.clear(); }
bool MapJoinArray::mapPosition(Coordinates& pos) const { boost::shared_ptr<Query> query(_query.lock()); for (size_t i = 0, n = pos.size(); i < n; i++) { Coordinate c = rightDesc.getOrdinalCoordinate(i, leftDesc.getOriginalCoordinate(i, pos[i], query), cmTest, query); if (c < MIN_COORDINATE) { return false; } pos[i] = c; } return true; }
/// Returns a new coordinate matrix containing the result of /// subtracting the coordinates with \p coordinates. Coordinates Coordinates::subtract(const Coordinates &coordinates) const { int size = qMin(this->size(), coordinates.size()); Coordinates result(size); for(int i = 0; i < size; i++){ const Point3 &a = position(i); const Point3 &b = coordinates.position(i); result.setPosition(i, a - b); } return result; }
Coordinates ConstChunk::getLowBoundary(bool withOverlap) const { boost::shared_ptr<ConstChunkIterator> i = getConstIterator(ConstChunkIterator::IGNORE_EMPTY_CELLS | (withOverlap ? 0 : ConstChunkIterator::IGNORE_OVERLAPS)); Coordinates low = getLastPosition(withOverlap); size_t nDims = low.size(); while (!i->end()) { Coordinates const& pos = i->getPosition(); for (size_t j = 0; j < nDims; j++) { if (pos[j] < low[j]) { low[j] = pos[j]; } } ++(*i); } return low; }
bool Clipping::SutherlandHodgmanPolygonClip(Object* p){ auto input = p->getNCoords(); Coordinates tmp; Coordinates output; clipLeft(input, tmp); clipRight(tmp, output); clipTop(output, tmp); clipBottom(tmp, output); if(output.size() == 0) return false; p->setNCoord(output); return true; }