Skip to content

Commit

Permalink
feat: point set indexing (#148)
Browse files Browse the repository at this point in the history
* feat: add __getitem__ for point set

* feat: add indexing for point set
  • Loading branch information
vishwa2710 authored Sep 17, 2024
1 parent 1cbb8e5 commit 3f0d2b2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ inline void OpenSpaceToolkitMathematicsPy_Geometry_2D_Object_PointSet(pybind11::
},
keep_alive<0, 1>()
) // Keep vector alive while iterator is used
.def(
"__getitem__",
[](const PointSet& aPointSet, size_t index) -> Point
{
if (index >= aPointSet.getSize())
{
throw std::out_of_range("Index out of range");
}
auto it = aPointSet.begin();
std::advance(it, index);
return *it;
}
)

;
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ inline void OpenSpaceToolkitMathematicsPy_Geometry_3D_Object_PointSet(pybind11::
},
keep_alive<0, 1>()
) // Keep vector alive while iterator is used
.def(
"__getitem__",
[](const PointSet& aPointSet, size_t index) -> Point
{
if (index >= aPointSet.getSize())
{
throw std::out_of_range("Index out of range");
}
auto it = aPointSet.begin();
std::advance(it, index);
return *it;
}
)

;
}
5 changes: 3 additions & 2 deletions bindings/python/test/geometry/d2/object/test_point_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

from collections.abc import Iterator, Iterable

import pytest

import ostk.mathematics as mathematics


Expand Down Expand Up @@ -93,6 +91,9 @@ def test_iter_success(self, point_set: PointSet):
assert isinstance(iter(point_set), Iterator)
assert isinstance(iter(point_set), Iterable)

def test_get_item_success(self, point_set: PointSet):
assert point_set[0] is not None

# def test_is_near_success(self):

# def test_get_point_closest_to_success(self):
Expand Down
3 changes: 3 additions & 0 deletions bindings/python/test/geometry/d3/object/test_point_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ def test_iter_success(self, point_set: PointSet):
assert isinstance(iter(point_set), Iterator)
assert isinstance(iter(point_set), Iterable)

def test_get_item_success(self, point_set: PointSet):
assert point_set[0] is not None

# def test_is_near_success(self):

# def test_get_point_closest_to_success(self):
Expand Down

0 comments on commit 3f0d2b2

Please sign in to comment.