Skip to content

Make printed primal primitives easier to turn into C++ code. #1714

@BradWhitlock

Description

@BradWhitlock

It is a chore to translate primal primitive printed output into a C++ program. If I'm printing a set of points, vectors, planes, or polygons, it would be nice if there was a code() method that would write the object as valid (or closer to it) C++ code. This would make it easier to export problem data to short programs for debugging.

Example:

template <typename T, int NDIMS>
std::ostream& Vector<T, NDIMS>::code(std::ostream& os, int indentLevel = 0, const char *name = nullptr) const
{
  os << indent(indentLevel) << "axom::primal::Vector";
  os << "<" << cpp2conduit<T>::name << ", " << NDIMS << ">";
  if(name != nullptr) os << " " << name;
  os << "{";
  for(int dim = 0; dim < NDIMS - 1; ++dim)
  {
    os << std::setprecision(20) << static_cast<typename NonChar<T>::type>(m_components[dim]) << ",";
  }
  os << std::setprecision(20) << static_cast<typename NonChar<T>::type>(m_components[NDIMS - 1]) << "}";

  return os;
}
  • Make sure Point, Vector print enough precision
  • Enabled in non-device code
  • Handle Point, Vector, Plane, Polygon, BoundingBox
  • For some of these compound types, maybe use constructors that initialize arguments inline: Polygon<double,2>({{0.,1.},{2.,3.},{4.,5.}})
  • Bonus: Polyhedron, Curve, and others

Metadata

Metadata

Assignees

No one assigned

    Labels

    MIRIssues related to Axom's 'mir' componentReviewedmaintenanceIssues related to code maintenance

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions