mathtrio.blogg.se

Very downcast face
Very downcast face











very downcast face

This seems like the best method to me, since it has the least boilerplate and nothing exposed to the user but it still feels messy, especially in the "real" case where there might be multiple types that would all have to be specified: class Cell: public Polyhedron Typename std::enable_if::value, void>::typeĪnd then inheriting from a parent with a given typename: class Cell : public Polyhedron Template the whole Polyhedron class, replacing every instance of Polygon* with F* and checking that F is a base of Polygon: template I can't use unique_ptr easily because of the copy-constructor used in std::initializer_list constructors.

very downcast face

I don't want to use shared_ptr for performance purposes - I know they're good and friendly, but I'm creating millions of these Polygons and its easy to destroy them in the right place. From what I understand, these smart pointers retain type-awareness so that they can call the right destructor, but they might just store a reference to the destructor depending on implementation. Instead of storing std::vector I could store std::vector>. This seems sloppy to me, not easy to maintain, inefficient and prone to errors. In Cell::GetFaces() which currently just inherits from Polyhedron::GetPolygons() I could create a wrapper that copies the std::vector to a new vector std::vector. I'm looking for a better solution or feedback of which of these is recommended: I can think of two or three ways to achieve this. I want the interface to be transparent, so that this just works: cell->GetFaces()->Interpolate()

#VERY DOWNCAST FACE CODE#

The user of the code has to do something like: Face * temp_face = (Face*)cell->GetFaces() // Could use static_cast I can downcast it manually back to a Face* which works, but is not very clean. Later, I want to access the Face* stored in a Cell so that I can call Face::Interpolate(), but it has been stored as a Polygon* and thus has no member function Polygon::Interpolate(). I initialize a Cell with a vector of pointers to Face, which is handled by the base class Polyhedron constructor, which upcasts the Face* to Polygon*: Polyhedron::Polyhedron( std::initializer_list polygons ) I don't want to make these member functions virtual in the base class ( Polygon).

very downcast face

The Face class adds to the Polygon class with additional data and functions required for the science, like Face::Interpolate(). These 3 classes ( Cell, Face, Vertex) are derived respectively from some generic geometry classes ( Polyhedron, Polygon, Point) which implement some geometric routines like Polygon::CalculateArea(). I am writing a scientific code which needs to create 3-dimensional cells, defined by a set of faces, which are defined by a set of vertices.













Very downcast face