std::tuple<float, point> line::distance(const point &p) const { float A = p.x() - origin().x(); float B = p.y() - origin().y(); float C = target().x() - origin().x(); float D = target().y() - origin().y(); float dot = A * C + B * D; float len_sq = C * C + D * D; float param = dot / len_sq; float xx, yy; if (param < 0 || (origin().x() == target().x() && origin().y() == origin().x())) { xx = origin().x(); yy = origin().y(); } else if (param > 1) { xx = target().x(); yy = target().y(); } else { xx = origin().x() + param * C; yy = origin().y() + param * D; } float dx = p.x() - xx; float dy = p.y() - yy; return std::make_tuple(sqrt(dx * dx + dy * dy), point(xx, yy)); }
bool map::contains(point<2> p) const { return p.x() >= min_x && p.x() <= max_x && p.y() >= min_y && p.y() <= max_y; }
/** * @brief scChunkManager::boundingRect * @param Center * @param width * @return imaginary rectangle containing the set of chunks that matter * * Creates a rectangle whose attributes describe which chunks need to be * paid attention to (i.e. top left is the top left most chunk, bottom right * is the bottom right most chunk) */ QRect scChunkManager::boundingRect(point Center, measure_type width) const { coord_type xTileMin = std::floor((Center.x() - width) / chunkWidth); coord_type xTileMax = std::ceil((Center.x() + width) / chunkWidth); coord_type yTileMin = std::floor((Center.y() - width) / chunkWidth); coord_type yTileMax = std::ceil((Center.y() + width) / chunkWidth); return QRect(QPoint(xTileMin, yTileMax), QPoint(xTileMax, yTileMin)); }
/// \brief Constructs a rect on position (top_left.x, top_left.y), with /// size bottom_right.x - top_left.x + 1 as width and /// bottom_right.y - top_left.x + 1 as height constexpr rect( point< position_type > const& top_left, point< position_type > const& bottom_right ): top_left_(top_left), size_( bottom_right.x() - top_left.x() + 1, bottom_right.y() - top_left.y() + 1 ){}
bool operator()(const point &p1, const point &p2) { if (p1.x() < p2.x()) return true; if (p1.x() != p2.x()) return false; if (p1.y() < p2.y()) return true; return false; }
bool lowerleft(const point<2>& p1, const point<2>& p2) { if (p1.y() < p2.y()) return true; if (p1.y() > p2.y()) return false; if (p1.x() < p2.x()) return true; if (p1.x() > p2.x()) return false; return false; // p1 == p2 }
constexpr bool contains( rect< PositionType, SizeType > const& rect, point< DataType > const& point ){ return point.x() >= rect.left() && point.y() >= rect.top() && point.x() < rect.right() && point.y() < rect.bottom(); }
llint movecount(point a,point b,point c,int n,int m) { if(cross(a-b,c-b)==0)return 0; int x1=min(a.x(),min(b.x(),c.x())); int x2=max(a.x(),max(b.x(),c.x())); int y1=min(a.y(),min(b.y(),c.y())); int y2=max(a.y(),max(b.y(),c.y())); //cerr<<"###"<<a<<" "<<b<<" "<<c<<endl; if(x2-x1>=n||y2-y1>=m)return 0; return (n-x2+x1)*(m-y2+y1); }
bool Foam::octreeDataBoundBox::findTightest ( const label index, const point& sample, treeBoundBox& tightest ) const { // Get furthest away vertex point myNear, myFar; allBb_[index].calcExtremities(sample, myNear, myFar); const point dist = myFar - sample; scalar myFarDist = mag(dist); point tightestNear, tightestFar; tightest.calcExtremities(sample, tightestNear, tightestFar); scalar tightestFarDist = mag(tightestFar - sample); if (tightestFarDist < myFarDist) { // Keep current tightest. return false; } else { // Construct bb around sample and myFar const point dist2(fabs(dist.x()), fabs(dist.y()), fabs(dist.z())); tightest.min() = sample - dist2; tightest.max() = sample + dist2; return true; } }
scalar arakawaKonorStripesTracerField::tracerAt ( const point& p, const Time& t ) const { scalar x = p.x() - xOffset; if (mag(x) <= wavelength / 2) { if (p.z() >= z1Start - 1 && p.z() <= z1End - 1) { return -rho0*Foam::sin(2*M_PI*x/wavelength); } else if (p.z() >= z2Start - 1 && p.z() <= z2End - 1) { return rho0*Foam::sin(2*M_PI*x/wavelength); } else { return 0; } } else { return 0; } }
QRect scChunkManager::tileIndexToBounds(point loc, measure_type chunkWidth) { coord_type left = loc.x() * chunkWidth; coord_type up = (loc.y()) * chunkWidth; //+1 is b/c QRect assums boundries don't overlap when they do. Causes issues w/ //deposit placement. return QRect(left, up, chunkWidth + 1, chunkWidth + 1); }
bool Foam::treeLeaf<Foam::octreeDataTriSurface>::findNearest ( const octreeDataTriSurface& shapes, const point& sample, treeBoundBox& tightest, label& tightestI, scalar& tightestDist ) const { // Some aliases const treeBoundBoxList& allBb = shapes.allBb(); point& min = tightest.min(); point& max = tightest.max(); point nearest; bool changed = false; forAll(indices_, i) { label faceI = indices_[i]; // Quick rejection test. if (tightest.overlaps(allBb[faceI])) { // Full calculation scalar dist = shapes.calcNearest(faceI, sample, nearest); if (dist < tightestDist) { // Update bb (centered around sample, span is dist) min.x() = sample.x() - dist; min.y() = sample.y() - dist; min.z() = sample.z() - dist; max.x() = sample.x() + dist; max.y() = sample.y() + dist; max.z() = sample.z() + dist; tightestI = faceI; tightestDist = dist; changed = true; } } }
Foam::point Foam::scaleSearchableSurface::inverseTransform(const point &p) const { return point ( p.x()/scale_.x(), p.y()/scale_.y(), p.z()/scale_.z() ); }
void draw_text ( point origin, std::string text ) { XDrawString ( m_display, m_window_id, m_gc, origin.x(), origin.y(), text.c_str(), text.size() ); }
point horizontalVelocityField::initialPositionOf ( const point& p, const Time& t ) const { const dimensionedScalar z("z", dimLength, p.z()); if (z.value() <= z1.value()) { return p; } else if (z.value() <= z2.value()) { return point(p.x() - (u0*sqr(Foam::sin(0.5*M_PI*(z-z1)/(z2-z1)))*t).value(), p.y(), p.z()); } else { return point(p.x() - u0.value()*t.value(), p.y(), p.z()); } }
forAll(order, sortI) { label pointI = order[sortI]; // Convert to scalar precision const point pt ( scalar(d[pointI].x()), scalar(d[pointI].y()), scalar(d[pointI].z()) ); sortedTol[sortI] = 2*mergeTol*(mag(pt.x())+mag(pt.y())+mag(pt.z())); }
std::string stringify(point p) { std::stringstream ss; ss << "#<point:"; ss << " x="; ss << p.x(); ss << " y="; ss << p.y(); ss << " z="; ss << p.z(); ss << ">"; return ss.str(); }
/////////////////////////////////////////////////////////////////////////// // constructor from 2 points // if p1=p2 then creates a vertical line at p1.x! line<2>::line(const point<2>& p1, const point<2>& p2) { if (p1.x() == p2.x()) { // vertical line 1.x=k a = 1; b = c = 0; d = -p1.x(); } else { b = 1; a = -(p1.y() - p2.y()) / (p1.x() - p2.x()); // slope d = -(a * p1.x()) - (b * p1.y()); c = 0; } }
static point< T > top_left (const point< T >& p1, const point< T >& p2) { return point< T > (std::min< T > (p1.x (), p2.x ()), std::min< T > (p1.y (), p2.y ())); }
bool in_range(point p, point min, point max) { return (min.x() <= p.x() && p.x() <= max.x() && min.y() <= p.y() && p.y() <= max.y() && min.z() <= p.z() && p.z() <= max.z()); }
/////////////////////////////////////////////////////////////////////////// // constructor from point and slope line<2>::line(const point<2>& p, double slope) { a = -slope; b = 1; d = -(a * p.x()) - (b * p.y()); c = 0; }
//! Point where the top and right edges meet point< T > top_right () const { return point< T > (br_.x (), tl_.y ()); }
bool lineRefinement::intersectsObject(const boundBox& bb) const { //- check if the cube contains start point or end point const scalar l = bb.max().x() - bb.min().x(); const point min = bb.min() - l * vector(SMALL, SMALL, SMALL); const point max = bb.max() + l * vector(SMALL, SMALL, SMALL); //- check for intersections of line with the cube faces const vector v(p1_ - p0_); if( mag(v.x()) > SMALL ) { if( ((p0_.x() < min.x()) && (p1_.x() < min.x())) || ((p0_.x() > max.x()) && (p1_.x() > max.x())) ) return false; { //- x-min face const vector n(-1, 0, 0); const scalar t = (n & (min - p0_)) / (n & v); const point i = p0_ + t * v; if( (t > -SMALL) && (t < (1.0+SMALL)) ) if( (i.y() > min.y()) && (i.y() < max.y()) && (i.z() > min.z()) && (i.z() < max.z()) ) return true; } { //- x-max face const vector n(1, 0, 0); const scalar t = (n & (max - p0_)) / (n & v); const point i = p0_ + t * v; if( (t > -SMALL) && (t < (1.0+SMALL)) ) if( (i.y() > min.y()) && (i.y() < max.y()) && (i.z() > min.z()) && (i.z() < max.z()) ) return true; } } if( mag(v.y()) > SMALL) { if( ((p0_.y() < min.y()) && (p1_.y() < min.y())) || ((p0_.y() > max.y()) && (p1_.y() > max.y())) ) return false; { //- y-min face const vector n(0, -1, 0); const scalar t = (n & (min - p0_)) / (n & v); const point i = p0_ + t * v; if( (t > -SMALL) && (t < (1.0+SMALL)) ) if( (i.x() > min.x()) && (i.x() < max.x()) && (i.z() > min.z()) && (i.z() < max.z()) ) return true; } { //- y-max face const vector n(0, 1, 0); const scalar t = (n & (max - p0_)) / (n & v); const point i = p0_ + t * v; if( (t > -SMALL) && (t < (1.0+SMALL)) ) if( (i.x() > min.x()) && (i.x() < max.x()) && (i.z() > min.z()) && (i.z() < max.z()) ) return true; } } if( mag(v.z()) > SMALL ) { if( ((p0_.z() < min.z()) && (p1_.z() < min.z())) || ((p0_.z() > max.z()) && (p1_.z() > max.z())) ) return false; { //- z-min face const vector n(0, 0, -1); const scalar t = (n & (min - p0_)) / (n & v); const point i = p0_ + t * v; if( (t > -SMALL) && (t < (1.0+SMALL)) && (i.x() > min.x()) && (i.x() < max.x()) && (i.y() > min.y()) && (i.y() < max.y()) ) return true; } { //- z-min face const vector n(0, 0, 1); const scalar t = (n & (max - p0_)) / (n & v); const point i = p0_ + t * v; if( (t > -SMALL) && (t < (1.0+SMALL)) && (i.x() > min.x()) && (i.x() < max.x()) && (i.y() > min.y()) && (i.y() < max.y()) ) return true; } } if( (p0_.x() > min.x()) && (p0_.x() < max.x()) && (p0_.y() > min.y()) && (p0_.y() < max.y()) && (p0_.z() > min.z()) && (p0_.z() < max.z()) ) return true; return false; }
bool SetCursorPos(point const& p) { return ::SetCursorPos(p.x(), p.y()) == TRUE; }
//! Point where the bottom and left edges meet point< T > bottom_left () const { return point< T > (tl_.x (), br_.y ()); }
void Foam::coupledPolyPatch::writeOBJ(Ostream& os, const point& pt) { os << "v " << pt.x() << ' ' << pt.y() << ' ' << pt.z() << endl; }
/// \brief Constructs a rect on position (0, 0), with size /// bottom_right.x + 1 as width and bottom_right.y + 1 as height constexpr rect(point< position_type > const& bottom_right): size_(bottom_right.x() + 1, bottom_right.y() + 1) {}
/*! The return value is guaranteed to be non-negative. */ T width () const { return br_.x () - tl_.x (); }
void Foam::surfaceIntersection::writeOBJ(const point& pt, Ostream& os) { os << "v " << pt.x() << ' ' << pt.y() << ' ' << pt.z() << endl; }
static point< T > bottom_right (const point< T >& p1, const point< T >& p2) { return point< T > (std::max< T > (p1.x (), p2.x ()), std::max< T > (p1.y (), p2.y ())); }