3 * @brief PolyTope template implementation.
4 * @details Contains the inline implementations of `PolyTope` methods for
5 * half-space intersection bounding box and point containment testing.
7 * @note Qhull usage: `qhull Qt Qx Fn < points.txt > hull.txt`
8 * Points file format: First line: <num_points> <dim>
9 * Following lines: coordinates of each vertex
12#ifndef MONTECARLO_1_POLYTOPE_TPP
13#define MONTECARLO_1_POLYTOPE_TPP
16#include <algorithm> // For std::pow
17#include "../geometry.hpp"
18#include "integration_domain.hpp"
21namespace mc::domains {
24PolyTope<dim>::PolyTope(const std::vector<mc::geom::Point<dim>>& vertices,
25 const std::vector<std::array<double, dim>>& norms,
26 const std::vector<double>& offs)
31 if (normals.size() != offsets.size()) {
32 throw std::runtime_error(
33 "PolyTope: normals and offsets must have the same size.");
37 throw std::runtime_error(
38 "PolyTope: vertices list cannot be empty.");
43mc::geom::Bounds<dim> PolyTope<dim>::getBounds() const{
44 mc::geom::Bounds<dim> bounds;
45 for (int i = 0; i < dim; ++i) {
46 double max = vec[0][i];
47 double min = vec[0][i];
48 for (mc::geom::Point<dim> p: vec) {
49 if (p[i] > max) max = p[i];
50 if (p[i] < min) min = p[i];
52 bounds[i] = std::make_pair(min, max);
58double PolyTope<dim>::getBoxVolume() const {
59 mc::geom::Bounds<dim> bou = this->getBounds();
61 for (int i = 0; i <dim; ++i) {
62 vol *= (bou[i].second - bou[i].first);
68bool PolyTope<dim>::isInside(const mc::geom::Point<dim> &point) const {
69 const double tol = 1e-12; // Numerical tolerance for robust testing
70 for (size_t i = 0; i < normals.size(); ++i) {
72 // Compute dot product: normal_i · point
73 for (size_t k = 0; k < dim; ++k)
74 s += normals[i][k] * point[k];
76 // Check half-space inequality: n_i · x + offset_i ≤ 0
77 if (s > offsets[i] + tol)
78 return false; // Point violates this facet constraint
83} // namespace mc::domains
85#endif //MONTECARLO_1_POLYTOPE_TPP