Skip to content

Mark triangulation classes as final #27894

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/matplotlib/_tri.pyi
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
# This is a private module implemented in C++
# As such these type stubs are overly generic, but here to allow these types
# as return types for public methods
from typing import Any
from typing import Any, final

@final
class TrapezoidMapTriFinder:
def __init__(self, *args, **kwargs) -> None: ...
def find_many(self, *args, **kwargs) -> Any: ...
def get_tree_stats(self, *args, **kwargs) -> Any: ...
def initialize(self, *args, **kwargs) -> Any: ...
def print_tree(self, *args, **kwargs) -> Any: ...

@final
class TriContourGenerator:
def __init__(self, *args, **kwargs) -> None: ...
def create_contour(self, *args, **kwargs) -> Any: ...
def create_filled_contour(self, *args, **kwargs) -> Any: ...

@final
class Triangulation:
def __init__(self, *args, **kwargs) -> None: ...
def calculate_plane_coefficients(self, *args, **kwargs) -> Any: ...
Expand Down
28 changes: 14 additions & 14 deletions src/tri/_tri.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ namespace py = pybind11;
/* An edge of a triangle consisting of an triangle index in the range 0 to
* ntri-1 and an edge index in the range 0 to 2. Edge i goes from the
* triangle's point i to point (i+1)%3. */
struct TriEdge
struct TriEdge final
{
TriEdge();
TriEdge(int tri_, int edge_);
Expand Down Expand Up @@ -111,7 +111,7 @@ struct XY
};

// 3D point with x,y,z coordinates.
struct XYZ
struct XYZ final
{
XYZ(const double& x_, const double& y_, const double& z_);
XYZ cross(const XYZ& other) const;
Expand All @@ -123,7 +123,7 @@ struct XYZ
};

// 2D bounding box, which may be empty.
class BoundingBox
class BoundingBox final
{
public:
BoundingBox();
Expand All @@ -138,7 +138,7 @@ class BoundingBox
/* A single line of a contour, which may be a closed line loop or an open line
* strip. Identical adjacent points are avoided using push_back(), and a closed
* line loop should also not have identical first and last points. */
class ContourLine : public std::vector<XY>
class ContourLine final : public std::vector<XY>
{
public:
ContourLine();
Expand All @@ -157,7 +157,7 @@ void write_contour(const Contour& contour);

/* Triangulation with npoints points and ntri triangles. Derived fields are
* calculated when they are first needed. */
class Triangulation
class Triangulation final
{
public:
typedef py::array_t<double, py::array::c_style | py::array::forcecast> CoordinateArray;
Expand Down Expand Up @@ -254,7 +254,7 @@ class Triangulation

private:
// An edge of a triangulation, composed of start and end point indices.
struct Edge
struct Edge final
{
Edge() : start(-1), end(-1) {}
Edge(int start_, int end_) : start(start_), end(end_) {}
Expand All @@ -267,7 +267,7 @@ class Triangulation
/* An edge of a boundary of a triangulation, composed of a boundary index
* and an edge index within that boundary. Used to index into the
* boundaries collection to obtain the corresponding TriEdge. */
struct BoundaryEdge
struct BoundaryEdge final
{
BoundaryEdge() : boundary(-1), edge(-1) {}
BoundaryEdge(int boundary_, int edge_)
Expand Down Expand Up @@ -328,7 +328,7 @@ class Triangulation


// Contour generator for a triangulation.
class TriContourGenerator
class TriContourGenerator final
{
public:
typedef Triangulation::CoordinateArray CoordinateArray;
Expand Down Expand Up @@ -508,7 +508,7 @@ class TriContourGenerator
* colinear points but only in the simplest of cases. No explicit testing of
* the validity of the triangulation is performed as this is a computationally
* more complex task than the trifinding itself. */
class TrapezoidMapTriFinder
class TrapezoidMapTriFinder final
{
public:
typedef Triangulation::CoordinateArray CoordinateArray;
Expand Down Expand Up @@ -551,7 +551,7 @@ class TrapezoidMapTriFinder
/* A Point consists of x,y coordinates as well as the index of a triangle
* associated with the point, so that a search at this point's coordinates
* can return a valid triangle index. */
struct Point : XY
struct Point final : XY
{
Point() : XY(), tri(-1) {}
Point(const double& x, const double& y) : XY(x,y), tri(-1) {}
Expand All @@ -565,7 +565,7 @@ class TrapezoidMapTriFinder
* the Edge which are used to map from trapezoid to triangle index. Also
* stores pointers to the 3rd points of the below and above triangles,
* which are only used to disambiguate triangles with colinear points. */
struct Edge
struct Edge final
{
Edge(const Point* left_,
const Point* right_,
Expand Down Expand Up @@ -608,7 +608,7 @@ class TrapezoidMapTriFinder
class Node; // Forward declaration.

// Helper structure used by TrapezoidMapTriFinder::get_tree_stats.
struct NodeStats
struct NodeStats final
{
NodeStats()
: node_count(0), trapezoid_count(0), max_parent_count(0),
Expand All @@ -632,7 +632,7 @@ class TrapezoidMapTriFinder
* The parent collection acts as a reference count to the number of times
* a Node occurs in the search tree. When the parent count is reduced to
* zero a Node can be safely deleted. */
class Node
class Node final
{
public:
Node(const Point* point, Node* left, Node* right);// Type_XNode.
Expand Down Expand Up @@ -717,7 +717,7 @@ class TrapezoidMapTriFinder
* To obtain the index of the triangle corresponding to a particular
* Trapezoid, use the Edge member variables below.triangle_above or
* above.triangle_below. */
struct Trapezoid
struct Trapezoid final
{
Trapezoid(const Point* left_,
const Point* right_,
Expand Down
6 changes: 3 additions & 3 deletions src/tri/_tri_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using namespace pybind11::literals;

PYBIND11_MODULE(_tri, m) {
py::class_<Triangulation>(m, "Triangulation")
py::class_<Triangulation>(m, "Triangulation", py::is_final())
.def(py::init<const Triangulation::CoordinateArray&,
const Triangulation::CoordinateArray&,
const Triangulation::TriangleArray&,
Expand All @@ -30,7 +30,7 @@ PYBIND11_MODULE(_tri, m) {
.def("set_mask", &Triangulation::set_mask,
"Set or clear the mask array.");

py::class_<TriContourGenerator>(m, "TriContourGenerator")
py::class_<TriContourGenerator>(m, "TriContourGenerator", py::is_final())
.def(py::init<Triangulation&,
const TriContourGenerator::CoordinateArray&>(),
"triangulation"_a,
Expand All @@ -43,7 +43,7 @@ PYBIND11_MODULE(_tri, m) {
.def("create_filled_contour", &TriContourGenerator::create_filled_contour,
"Create and return a filled contour.");

py::class_<TrapezoidMapTriFinder>(m, "TrapezoidMapTriFinder")
py::class_<TrapezoidMapTriFinder>(m, "TrapezoidMapTriFinder", py::is_final())
.def(py::init<Triangulation&>(),
"triangulation"_a,
"Create a new C++ TrapezoidMapTriFinder object.\n"
Expand Down