Revisit Point interface

Issue #959 new
Jan Blechta created an issue

There is Point.x(), Point.__getitem__ and Point.array() for reading and Point.__setitem__ for writing. __(gs)etitem__ are implemented by us, which is prone to bugs and non-standard behaviour.

Implement correct buffer interface for Point to simplify the interface and implementation. Possible interface:

class Point(inherits):
    @property
    def _array_view():
     "Writable view into data."
         # implementation in Pybind11, possibly with help of Eigen
         pass

    __getitem__ = _array_view.__getitem__
    __setitem__ = _array_view.__setitem__

Then interface of Point p can do only this:

p = Point(1, 2, 3)
print(p[0], p[:])

# full slice is view
coords = p[:]
coords *= 0
assert all(p == 0)

# partial slice is also view
coords = p[0:1]
coords[:] = 1
assert p[0] == 1

# indexing by single index gives (of course immutable) float
coords = p[0]
coords = 2
assert p[0] != 2

# take copy explicitly
numpy.array(p[:])
numpy.array(p)  # or maybe this

and not anything else.

On C++ side all the unnecessary methods can be removed too.

Comments (0)

  1. Log in to comment