/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org \\ / A nd | Copyright (C) 2026 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License This file is part of OpenFOAM. OpenFOAM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. OpenFOAM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see . \*---------------------------------------------------------------------------*/ #include "boundSphere.H" // * * * * * * * * * * * * * * Private Constructors * * * * * * * * * * * * // inline Foam::boundSphere::boundSphere(const point& c, const scalar rSqr) : c_(c), rSqr_(rSqr) {} // * * * * * * * * * * * Private Static Member Functions * * * * * * * * * * // template inline Foam::boundSphere::PointUList Foam::boundSphere::pointUList(const PointList& ps) { return ps; } inline void Foam::boundSphere::sortBoundaryPis ( FixedList& boundaryPis ) { for (label iter = 0; iter < 3; ++ iter) { for (label i = 0; i < 3; ++ i) { if ( boundaryPis[i] == -1 ? true : boundaryPis[i + 1] == -1 ? false : boundaryPis[i] > boundaryPis[i + 1] ) { Swap(boundaryPis[i], boundaryPis[i + 1]); } } } } template inline void Foam::boundSphere::sortBoundaryPis ( FixedList& boundaryPis ) { for (label iter = 0; iter < 3; ++ iter) { for (label i = 0; i < 3; ++ i) { if ( boundaryPis[i].proci == -1 ? true : boundaryPis[i + 1].proci == -1 ? false : boundaryPis[i].proci > boundaryPis[i + 1].proci ? true : boundaryPis[i].proci < boundaryPis[i + 1].proci ? false : boundaryPis[i].elementi > boundaryPis[i + 1].elementi ) { Swap(boundaryPis[i], boundaryPis[i + 1]); } } } } // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // inline Foam::boundSphere::boundSphere() : c_(point::uniform(NaN)), rSqr_(-vGreat) {} inline Foam::boundSphere Foam::boundSphere::cr(const point& c, const scalar r) { return r < 0 ? boundSphere() : boundSphere(c, sqr(r)); } inline Foam::boundSphere Foam::boundSphere::cr(const Tuple2& cr) { return cr.second() < 0 ? boundSphere() : boundSphere(cr.first(), sqr(cr.second())); } inline Foam::boundSphere Foam::boundSphere::crSqr ( const point& c, const scalar rSqr ) { return rSqr < 0 ? boundSphere() : boundSphere(c, rSqr); } inline Foam::boundSphere Foam::boundSphere::crSqr ( const Tuple2& crSqr ) { return crSqr.second() < 0 ? boundSphere() : boundSphere(crSqr.first(), crSqr.second()); } // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // inline const Foam::point& Foam::boundSphere::c() const { return c_; } inline Foam::scalar Foam::boundSphere::rSqr() const { return rSqr_; } inline Foam::scalar Foam::boundSphere::r() const { return sqrt(rSqr_); } inline bool Foam::boundSphere::valid() const { return rSqr_ >= 0; } inline bool Foam::boundSphere::contains(const point& p) const { return valid() ? magSqr(p - c_) <= rSqr_ : false; } inline void Foam::boundSphere::inflate(const scalar s) { rSqr_ *= sqr(1 + s); } // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // inline bool Foam::boundSphere::overlap ( const boundSphere& a, const boundSphere& b ) { if (!a.valid() || !b.valid()) return false; return magSqr(a.c_ - b.c_) < sqr(a.r() + b.r()); } template inline Foam::boundSphere Foam::boundSphere::intersect ( const PointList& ps, const FixedList& pis, const label nPs ) { return implementation::intersect(pointUList(ps), pis, nPs); } template inline Foam::boundSphere Foam::boundSphere::trivial ( const PointList& ps, const FixedList& pis, const label nPs ) { FixedList boundaryPis({-1, -1, -1, -1}); return implementation::trivial(pointUList(ps), pis, nPs, boundaryPis); } template inline Foam::boundSphere Foam::boundSphere::trivial ( const PointList& ps, const FixedList& pis, const label nPs, FixedList& boundaryPis ) { return implementation::trivial(pointUList(ps), pis, nPs, boundaryPis); } template inline Foam::boundSphere Foam::boundSphere::bruteForce ( const PointList& ps ) { FixedList boundaryPis({-1, -1, -1, -1}); return implementation::bruteForce(pointUList(ps), boundaryPis); } template inline Foam::boundSphere Foam::boundSphere::bruteForce ( const PointList& ps, FixedList& boundaryPis ) { return implementation::bruteForce(pointUList(ps), boundaryPis); } template inline Foam::boundSphere Foam::boundSphere::local ( const PointList& ps ) { randomGenerator rndGen(0); FixedList boundaryPis({-1, -1, -1, -1}); return implementation::local(pointUList(ps), rndGen, boundaryPis); } template inline Foam::boundSphere Foam::boundSphere::local ( const PointList& ps, randomGenerator& rndGen ) { FixedList boundaryPis({-1, -1, -1, -1}); return implementation::local(pointUList(ps), rndGen, boundaryPis); } template inline Foam::boundSphere Foam::boundSphere::local ( const PointList& ps, FixedList& boundaryPis ) { randomGenerator rndGen(0); return implementation::local(pointUList(ps), rndGen, boundaryPis); } template inline Foam::boundSphere Foam::boundSphere::local ( const PointList& ps, randomGenerator& rndGen, FixedList& boundaryPis ) { return implementation::local(pointUList(ps), rndGen, boundaryPis); } template inline Foam::boundSphere Foam::boundSphere::global ( const PointList& ps, const bool strict ) { randomGenerator rndGen(0); FixedList, 4> boundaryPis; return implementation::global(pointUList(ps), rndGen, boundaryPis, strict); } template inline Foam::boundSphere Foam::boundSphere::global ( const PointList& ps, randomGenerator& rndGen, const bool strict ) { FixedList, 4> boundaryPis; return implementation::global(pointUList(ps), rndGen, boundaryPis, strict); } template inline Foam::boundSphere Foam::boundSphere::global ( const PointList& ps, FixedList, 4>& boundaryPis, const bool strict ) { randomGenerator rndGen(0); return implementation::global(pointUList(ps), rndGen, boundaryPis, strict); } template inline Foam::boundSphere Foam::boundSphere::global ( const PointList& ps, randomGenerator& rndGen, FixedList, 4>& boundaryPis, const bool strict ) { return implementation::global(pointUList(ps), rndGen, boundaryPis, strict); } // * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * // inline bool Foam::operator==(const boundSphere& a, const boundSphere& b) { return a.c_ == b.c_ && a.rSqr_ == b.rSqr_; } inline bool Foam::operator!=(const boundSphere& a, const boundSphere& b) { return !(a == b); } // ************************************************************************* //