Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 0 additions & 49 deletions src/DistRoutines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,31 +372,6 @@ double DIST2_ImageNonOrtho(const double* a1, const double* a2,
/** Return the minimum orthorhombic imaged distance^2 between coordinates a1
* and a2.
*/
double DIST2_ImageOrtho(const double* a1, const double* a2, Box const& box)
{
// If box lengths are zero no imaging possible
if (box.Param(Box::X)==0.0 || box.Param(Box::Y)==0.0 || box.Param(Box::Z)==0.0) return -1.0;
double x = a1[0] - a2[0];
double y = a1[1] - a2[1];
double z = a1[2] - a2[2];
// Get rid of sign info
if (x<0) x=-x;
if (y<0) y=-y;
if (z<0) z=-z;
// Get rid of multiples of box lengths
while (x > box.Param(Box::X)) x = x - box.Param(Box::X);
while (y > box.Param(Box::Y)) y = y - box.Param(Box::Y);
while (z > box.Param(Box::Z)) z = z - box.Param(Box::Z);
// Find shortest distance in periodic reference
double D = box.Param(Box::X) - x;
if (D < x) x = D;
D = box.Param(Box::Y) - y;
if (D < y) y = D;
D = box.Param(Box::Z) - z;
if (D < z) z = D;

return (x*x + y*y + z*z);
}

/** Return the minimum orthorhombic imaged distance^2 between coordinates a1
* and a2.
Expand All @@ -408,15 +383,6 @@ double DIST2_ImageOrtho(Vec3 const& a1, Vec3 const& a2, Box const& box) {
// Frame::DIST2_NoImage()
/** Return distance^2 between coordinates in a1 and a2.
*/
double DIST2_NoImage(const double* a1, const double* a2) {
double x = a1[0] - a2[0];
double y = a1[1] - a2[1];
double z = a1[2] - a2[2];
//double D = x*x + y*y + z*z;
//fprintf(stdout,"Mask1=%8.3f %8.3f %8.3f Mask2=%8.3f %8.3f %8.3f D=%8.3f\n",
// a1[0],a1[1],a1[2],a2[0],a2[1],a2[2],D);
return (x*x + y*y + z*z);
}

/// \return Distance squared, no imaging.
double DIST2_NoImage( Vec3 const& a1, Vec3 const& a2 ) {
Expand All @@ -431,21 +397,6 @@ double DIST_NoImage( Vec3 const& a1, Vec3 const& a2 ) {
}

/** \return Distance squared using either minimum-image convention or no imaging. */
double DIST2(ImageOption::Type itype, const double* a1, const double* a2, Box const& box) {
/* if (imagingEnabled) {
if (is_ortho)
return DIST2_ImageOrtho(a1, a2, box);
else
return DIST2_ImageNonOrtho(a1, a2, box.UnitCell(), box.FracCell());
} else
return DIST2_NoImage(a1, a2);*/
if (itype == ImageOption::NO_IMAGE)
return DIST2_NoImage(a1, a2);
else if (itype == ImageOption::ORTHO)
return DIST2_ImageOrtho(a1, a2, box);
else // NONORTHO
return DIST2_ImageNonOrtho(a1, a2, box.UnitCell(), box.FracCell());
}

/** \return Distance squared using either minimum-image convention or no imaging. */
double DIST2(ImageOption::Type itype, Vec3 const& a1, Vec3 const& a2, Box const& box) {
Expand Down
52 changes: 46 additions & 6 deletions src/DistRoutines.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#ifndef INC_DISTROUTINES_H
#define INC_DISTROUTINES_H
class Vec3;
class Matrix_3x3;
class Box;
#include <cmath>
#include "Box.h"
#include "ImageOption.h"
/*! \file DistRoutines.h
\brief A collection of routines used to calculate distance.
Expand All @@ -21,19 +20,60 @@ double DIST2_ImageNonOrtho(Vec3 const&, Vec3 const&, Matrix_3x3 const&, Matrix_3
double DIST2_ImageNonOrtho(const double*, const double*, Matrix_3x3 const&, Matrix_3x3 const&);

/// \return Distance squared, X-aligned and orthogonal imaging.
double DIST2_ImageOrtho(const double*, const double*, Box const&);
inline double DIST2_ImageOrtho(const double* a1, const double* a2,
Box const& box)
{
const double boxX = box.Param(Box::X);
const double boxY = box.Param(Box::Y);
const double boxZ = box.Param(Box::Z);

if (boxX == 0.0 || boxY == 0.0 || boxZ == 0.0)
return -1.0;

double x = std::fabs(a1[0] - a2[0]);
double y = std::fabs(a1[1] - a2[1]);
double z = std::fabs(a1[2] - a2[2]);

while (x > boxX) x -= boxX;
while (y > boxY) y -= boxY;
while (z > boxZ) z -= boxZ;

double D = boxX - x;
if (D < x) x = D;
D = boxY - y;
if (D < y) y = D;
D = boxZ - z;
if (D < z) z = D;

return x*x + y*y + z*z;
}
/// \return Distance squared, X-aligned and orthogonal imaging.
double DIST2_ImageOrtho(Vec3 const&, Vec3 const&, Box const&);

/// \return Distance squared, no imaging.
double DIST2_NoImage(const double*, const double*);
inline double DIST2_NoImage(const double* a1, const double* a2)
{
const double x = a1[0] - a2[0];
const double y = a1[1] - a2[1];
const double z = a1[2] - a2[2];
return x*x + y*y + z*z;
}
/// \return Distance squared, no imaging
double DIST2_NoImage( Vec3 const&, Vec3 const& );
/// \return Distance, no imaging.
double DIST_NoImage( Vec3 const&, Vec3 const& );

/// \return Distance squared using minimum-image convention or no imaging.
double DIST2(ImageOption::Type, const double*, const double*, Box const&);
inline double DIST2(ImageOption::Type itype, const double* a1,
const double* a2, Box const& box)
{
if (itype == ImageOption::NO_IMAGE)
return DIST2_NoImage(a1, a2);
else if (itype == ImageOption::ORTHO)
return DIST2_ImageOrtho(a1, a2, box);
else
return DIST2_ImageNonOrtho(a1, a2, box.UnitCell(), box.FracCell());
}
// \return Distance squared using minimum-image convention or no imaging.
double DIST2(ImageOption::Type, Vec3 const&, Vec3 const&, Box const&);
// \return Distance using minimum-image convention or no imaging.
Expand Down
Loading