ENH: vector mag(), magSqr() methods - complementary to dist(), distSqr()

ENH: use direct access to pointHit as point(), use dist(), distSqr()

- if the pointHit has already been checked for hit(), can/should
  simply use point() noexcept access subsequently to avoid redundant
  checks. Using vector distSqr() methods provides a minor optimization
  (no itermediate temporary), but can also make for clearer code.

ENH: copy construct pointIndexHit with different index

- symmetric with constructing from a pointHit with an index

STYLE: prefer pointHit point() instead of rawPoint()
This commit is contained in:
Mark Olesen
2022-11-01 12:15:08 +01:00
committed by Andrew Heather
parent 5ec435aca3
commit 27c2cdc040
112 changed files with 669 additions and 674 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -1570,14 +1570,14 @@ Foam::pointIndexHit Foam::dynamicIndexedOctree<Type>::findLine
(
octantBb,
treeVec,
hitInfo.rawPoint()
hitInfo.point()
)
);
if (verbose)
{
Pout<< "iter:" << i
<< " at current:" << hitInfo.rawPoint()
<< " at current:" << hitInfo.point()
<< " (perturbed:" << startPoint << ")" << endl
<< " node:" << nodeI
<< " octant:" << octant
@ -1612,7 +1612,7 @@ Foam::pointIndexHit Foam::dynamicIndexedOctree<Type>::findLine
break;
}
if (hitFaceID == 0 || hitInfo.rawPoint() == treeEnd)
if (hitFaceID == 0 || hitInfo.point() == treeEnd)
{
// endpoint inside the tree. Return miss.
break;
@ -1625,7 +1625,7 @@ Foam::pointIndexHit Foam::dynamicIndexedOctree<Type>::findLine
(
octantBb,
hitFaceID,
hitInfo.rawPoint(),
hitInfo.point(),
false // push outside of octantBb
)
);
@ -1634,7 +1634,7 @@ Foam::pointIndexHit Foam::dynamicIndexedOctree<Type>::findLine
{
Pout<< " iter:" << i
<< " hit face:" << faceString(hitFaceID)
<< " at:" << hitInfo.rawPoint() << nl
<< " at:" << hitInfo.point() << nl
<< " node:" << nodeI
<< " octant:" << octant
<< " bb:" << subBbox(nodeI, octant) << nl
@ -1665,10 +1665,10 @@ Foam::pointIndexHit Foam::dynamicIndexedOctree<Type>::findLine
if (verbose)
{
const treeBoundBox octantBb(subBbox(nodeI, octant));
Pout<< " walked for point:" << hitInfo.rawPoint() << endl
Pout<< " walked for point:" << hitInfo.point() << endl
<< " to neighbour node:" << nodeI
<< " octant:" << octant
<< " face:" << faceString(octantBb.faceBits(hitInfo.rawPoint()))
<< " face:" << faceString(octantBb.faceBits(hitInfo.point()))
<< " of octantBb:" << octantBb << endl
<< endl;
}

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -84,16 +85,7 @@ bool Foam::dynamicTreeDataPoint::overlaps
const scalar radiusSqr
) const
{
const point& p = points_[index];
const scalar distSqr = magSqr(p - centre);
if (distSqr <= radiusSqr)
{
return true;
}
return false;
return (centre.distSqr(points_[index]) <= radiusSqr);
}
@ -113,7 +105,7 @@ void Foam::dynamicTreeDataPoint::findNearest
const point& pt = points_[index];
scalar distSqr = magSqr(pt - sample);
const scalar distSqr = sample.distSqr(pt);
if (distSqr < nearestDistSqr)
{
@ -137,7 +129,7 @@ void Foam::dynamicTreeDataPoint::findNearest
) const
{
// Best so far
scalar nearestDistSqr = magSqr(linePoint - nearestPoint);
scalar nearestDistSqr = linePoint.distSqr(nearestPoint);
forAll(indices, i)
{
@ -155,7 +147,7 @@ void Foam::dynamicTreeDataPoint::findNearest
{
nearestDistSqr = distSqr;
minIndex = index;
linePoint = pHit.rawPoint();
linePoint = pHit.point();
nearestPoint = shapePt;
{

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2019 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -1597,14 +1597,14 @@ Foam::pointIndexHit Foam::indexedOctree<Type>::findLine
(
octantBb,
treeVec,
hitInfo.rawPoint()
hitInfo.point()
)
);
if (verbose)
{
Pout<< "iter:" << i
<< " at current:" << hitInfo.rawPoint()
<< " at current:" << hitInfo.point()
<< " (perturbed:" << startPoint << ")" << endl
<< " node:" << nodeI
<< " octant:" << octant
@ -1641,7 +1641,7 @@ Foam::pointIndexHit Foam::indexedOctree<Type>::findLine
break;
}
if (hitFaceID == 0 || hitInfo.rawPoint() == treeEnd)
if (hitFaceID == 0 || hitInfo.point() == treeEnd)
{
// endpoint inside the tree. Return miss.
break;
@ -1654,7 +1654,7 @@ Foam::pointIndexHit Foam::indexedOctree<Type>::findLine
(
octantBb,
hitFaceID,
hitInfo.rawPoint(),
hitInfo.point(),
false // push outside of octantBb
)
);
@ -1663,7 +1663,7 @@ Foam::pointIndexHit Foam::indexedOctree<Type>::findLine
{
Pout<< " iter:" << i
<< " hit face:" << faceString(hitFaceID)
<< " at:" << hitInfo.rawPoint() << nl
<< " at:" << hitInfo.point() << nl
<< " node:" << nodeI
<< " octant:" << octant
<< " bb:" << subBbox(nodeI, octant) << nl
@ -1694,10 +1694,10 @@ Foam::pointIndexHit Foam::indexedOctree<Type>::findLine
if (verbose)
{
const treeBoundBox octantBb(subBbox(nodeI, octant));
Pout<< " walked for point:" << hitInfo.rawPoint() << endl
Pout<< " walked for point:" << hitInfo.point() << endl
<< " to neighbour node:" << nodeI
<< " octant:" << octant
<< " face:" << faceString(octantBb.faceBits(hitInfo.rawPoint()))
<< " face:" << faceString(octantBb.faceBits(hitInfo.point()))
<< " of octantBb:" << octantBb << endl
<< endl;
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -210,13 +210,15 @@ void Foam::treeDataCell::findNearestOp::operator()
{
label index = indices[i];
label celli = shape.cellLabels()[index];
scalar distSqr = magSqr(sample - shape.mesh().cellCentres()[celli]);
const point& pt = shape.mesh().cellCentres()[celli];
scalar distSqr = sample.distSqr(pt);
if (distSqr < nearestDistSqr)
{
nearestDistSqr = distSqr;
minIndex = index;
nearestPoint = shape.mesh().cellCentres()[celli];
nearestPoint = pt;
}
}
}
@ -300,7 +302,7 @@ bool Foam::treeDataCell::findIntersectOp::operator()
// since using half_ray AND zero tolerance. (note that tolerance
// is used to look behind us)
minDistSqr = sqr(inter.distance());
intersectionPoint = inter.hitPoint();
intersectionPoint = inter.point();
hasMin = true;
}
}

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -198,7 +199,7 @@ void Foam::treeDataEdge::findNearestOp::operator()
{
nearestDistSqr = distSqr;
minIndex = index;
nearestPoint = nearHit.rawPoint();
nearestPoint = nearHit.point();
}
}
}
@ -218,7 +219,7 @@ void Foam::treeDataEdge::findNearestOp::operator()
const treeDataEdge& shape = tree_.shapes();
// Best so far
scalar nearestDistSqr = magSqr(linePoint - nearestPoint);
scalar nearestDistSqr = linePoint.distSqr(nearestPoint);
for (const label index : indices)
{

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -128,7 +128,7 @@ bool Foam::treeDataPoint::overlaps
const scalar radiusSqr
) const
{
return (magSqr(shapePoint(index) - centre) <= radiusSqr);
return (centre.distSqr(shapePoint(index)) <= radiusSqr);
}
@ -148,7 +148,7 @@ void Foam::treeDataPoint::findNearestOp::operator()
{
const point& pt = shape.shapePoint(index);
const scalar distSqr = magSqr(pt - sample);
const scalar distSqr = sample.distSqr(pt);
if (distSqr < nearestDistSqr)
{
@ -177,7 +177,7 @@ void Foam::treeDataPoint::findNearestOp::operator()
scalar nearestDistSqr = GREAT;
if (minIndex >= 0)
{
nearestDistSqr = magSqr(linePoint - nearestPoint);
nearestDistSqr = linePoint.distSqr(nearestPoint);
}
for (const label index : indices)
@ -194,7 +194,7 @@ void Foam::treeDataPoint::findNearestOp::operator()
{
nearestDistSqr = distSqr;
minIndex = index;
linePoint = pHit.rawPoint();
linePoint = pHit.point();
nearestPoint = shapePt;
{