当前位置: 首页>>代码示例>>C++>>正文


C++ BoundingBox::generatePointInside方法代码示例

本文整理汇总了C++中BoundingBox::generatePointInside方法的典型用法代码示例。如果您正苦于以下问题:C++ BoundingBox::generatePointInside方法的具体用法?C++ BoundingBox::generatePointInside怎么用?C++ BoundingBox::generatePointInside使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BoundingBox的用法示例。


在下文中一共展示了BoundingBox::generatePointInside方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: invalid_argument

/**
 * Return a random point in a generic shape limited by a bounding box.
 * @param object an object in which the point is generated
 * @param rng a random number generator
 * @param box a box restricting the point's volume
 * @param maxAttempts number of attempts to find a suitable point
 * @return a point or none if maxAttempts was exceeded
 */
boost::optional<Kernel::V3D> bounded(const IObject &object,
                                     Kernel::PseudoRandomNumberGenerator &rng,
                                     const BoundingBox &box,
                                     size_t maxAttempts) {
  boost::optional<Kernel::V3D> point{boost::none};
  if (box.isNull()) {
    throw std::invalid_argument(
        "Invalid bounding box. Cannot generate random point.");
  }
  for (size_t attempts{0}; attempts < maxAttempts; ++attempts) {
    const double r1 = rng.nextValue();
    const double r2 = rng.nextValue();
    const double r3 = rng.nextValue();
    auto pt = box.generatePointInside(r1, r2, r3);
    if (object.isValid(pt)) {
      point = pt;
      break;
    }
  };
  return point;
}
开发者ID:mantidproject,项目名称:mantid,代码行数:29,代码来源:RandomPoint.cpp


注:本文中的BoundingBox::generatePointInside方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。