Skip to content

Commit

Permalink
libformfactor 0.3.1 (new formula)
Browse files Browse the repository at this point in the history
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
AlQuemist authored and chenrui333 committed Dec 25, 2024
1 parent c3e62e5 commit 5f02daa
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions Formula/lib/libformfactor.rb
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

0 comments on commit 5f02daa

Please sign in to comment.