-
-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libformfactor is A C++ library for the efficient computation of scattering form factors of arbitrary polyhedra according to Wuttke, J. Appl. Cryst. 54, 580-587 (2021). Homepage: <https://jugit.fz-juelich.de/mlz/libformfactor/>
- Loading branch information
1 parent
c3e62e5
commit 5f02daa
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
class Libformfactor < Formula | ||
desc "C++ library for the efficient computation of scattering form factors" | ||
homepage "https://jugit.fz-juelich.de/mlz/libformfactor" | ||
url "https://jugit.fz-juelich.de/mlz/libformfactor/-/archive/v0.3.1/libformfactor-v0.3.1.tar.bz2" | ||
sha256 "fc629a3e843e920b250393b0072f6673e26783b0776e8f08523534875950f298" | ||
license "GPL-3.0-or-later" | ||
|
||
depends_on "cmake" => :build | ||
depends_on "libheinz" | ||
|
||
def install | ||
system "cmake", "-S", ".", "-B", "build", | ||
"-DLibHeinz_DIR=#{Formula["libheinz"].opt_prefix}/cmake", | ||
*std_cmake_args | ||
system "cmake", "--build", "build" | ||
system "cmake", "--install", "build" | ||
end | ||
|
||
test do | ||
(testpath/"fftest.cpp").write <<~CPP | ||
#include <ff/Face.h> | ||
#include <ff/Prism.h> | ||
#include <ff/Polyhedron.h> | ||
#include <cmath> // abs | ||
bool CHECK_NEAR(const double value, const double expected, const double tol) | ||
{ | ||
return std::abs(value - expected) <= tol; | ||
} | ||
bool test_asPolyhedron_prism() | ||
{ | ||
ff::Prism prism(false, 1, {{-0.5, -0.5, 0}, {-0.5, 0.5, 0}, {0.5, 0.5, 0}, {0.5, -0.5, 0}}); | ||
ff::Polyhedron* polyhedron = prism.asPolyhedron(); | ||
const bool test0 = (polyhedron->faces().size() == 6); | ||
const bool test1 = CHECK_NEAR(polyhedron->vertices()[4].z(), 0.5, 1E-13); | ||
const bool test2 = CHECK_NEAR(polyhedron->vertices()[5].z(), 0.5, 1E-13); | ||
const bool test3 = CHECK_NEAR(polyhedron->vertices()[6].z(), 0.5, 1E-13); | ||
const bool test4 = CHECK_NEAR(polyhedron->vertices()[7].z(), 0.5, 1E-13); | ||
return test0 && test1 && test2 && test3 && test4; | ||
} | ||
bool test_faceCenter_CenteredRectangle() | ||
{ | ||
// FaceCenter:CenteredRectangle | ||
ff::Face face({{-0.5, -1.4, 0}, {-0.5, 1.4, 0}, {0.5, 1.4, 0}, {0.5, -1.4, 0}}, true); | ||
const R3 center = face.center_of_polygon(); | ||
const bool test1 = std::abs(center.x()) <= 1e-13; | ||
const bool test2 = std::abs(center.y()) <= 1e-13; | ||
const bool test3 = std::abs(center.z()) <= 1e-13; | ||
return test1 && test2 && test3; | ||
} | ||
int main() | ||
{ | ||
const bool all_tests = test_asPolyhedron_prism() && test_faceCenter_CenteredRectangle(); | ||
return all_tests? 0 : 1; | ||
} | ||
CPP | ||
|
||
system ENV.cxx, "-std=c++17", "fftest.cpp", "-I#{include}", "-L#{lib}", "-lformfactor", "-o", "fftest" | ||
system "./fftest" | ||
end | ||
end |