Skip to content
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

New python interface with documentation #34

Merged
merged 22 commits into from
Oct 21, 2021
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c70ef5d
Working on including documentation in the python library. Also refres…
MatteoRagni Oct 18, 2021
3032833
Completed base curve wrapping
MatteoRagni Oct 19, 2021
de542c3
:snake: Working on biarc wrapper
MatteoRagni Oct 19, 2021
dbacf64
:snake: A more python copy concept for Biarc
MatteoRagni Oct 19, 2021
acbdd9f
Merge branch 'bugfix/biarc_list_memory' into develop
MatteoRagni Oct 19, 2021
bd0bad3
:snake: revision of BiarcList wrapper (and Biarc)
MatteoRagni Oct 19, 2021
c01e629
:snake: G2lib has a __version__ attribute
MatteoRagni Oct 19, 2021
cccd831
:snake: refreshed wrapper for Circle Arc
MatteoRagni Oct 19, 2021
a62e41a
Merge remote-tracking branch 'upstream/develop' into develop
MatteoRagni Oct 20, 2021
72c33a7
:snake: minor fixes in biarc docs
MatteoRagni Oct 20, 2021
b139a0a
:snake: full remake of the LineSegment and PolyLine interfaces
MatteoRagni Oct 20, 2021
b9b1deb
:snake: full remake for Triangle2d wrapper
MatteoRagni Oct 20, 2021
f549d8b
:snake: full remake of the interface for Clothoids and ClothoidsList
MatteoRagni Oct 20, 2021
a2f4814
:snake: const correctness in trinagle2d
MatteoRagni Oct 20, 2021
7f78f5f
:snake: minor fix in clothoids
MatteoRagni Oct 20, 2021
b6dc95b
:snake: Reimporting some stuff from antemotion repository
MatteoRagni Oct 20, 2021
1a89bc6
:snake: Fixes an error in const requirements for ClothoidList::load
MatteoRagni Oct 20, 2021
e0b427d
Fixes a segmentation fault on ClothoidList::length for empty list
MatteoRagni Oct 20, 2021
2c72ff2
:snake: Several improvements to interface and vectorial version of me…
MatteoRagni Oct 21, 2021
c490850
git submodules now are CI complaint
MatteoRagni Oct 21, 2021
f3d9ca3
Fix to minor cmake stuff, that raise an error on some platform
MatteoRagni Oct 21, 2021
1223e24
:snake: Fixes segmentation fault on getXY for clothoidList and Biarc
MatteoRagni Oct 21, 2021
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
Prev Previous commit
Next Next commit
🐍 full remake for Triangle2d wrapper
  • Loading branch information
MatteoRagni committed Oct 20, 2021
commit b9b1deb91b492a3eb346898eff22bfd872618adc
342 changes: 299 additions & 43 deletions src_py/src/python-Triangle2D.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,27 @@
namespace G2lib {
namespace python {
void wrap_Triangle2D(py::module & m) {
py::class_<Triangle2D>(m, "Triangle2D")
py::class_<Triangle2D>(m, "Triangle2D",
R"S(
Class that manages a 2D Triangle. There are several possible
constructors for this class:

* constructor from a Triangle2D
* constructor from three points, s0, s1 and icurve
* constructor from raw data

for this last constructor:

:param float x1: **x** coordinate of the first point
:param float y1: **y** coordinate of the first point
:param float x2: **x** coordinate of the second point
:param float y2: **y** coordinate of the second point
:param float x3: **x** coordinate of the third point
:param float y3: **y** coordinate of the third point
:param float s0: s0 of this triangle on the curve
:param float s1: s1 of this triangle on the curve
:param int icurve: number of the trinagle on the curve
)S")
.def(py::init<>())
.def(py::init<const Triangle2D &>())
.def(py::init<real_type, real_type, real_type, real_type, real_type,
Expand All @@ -22,60 +42,296 @@ namespace G2lib {
return Triangle2D(std::get<0>(p0), std::get<1>(p0), std::get<0>(p1), std::get<1>(p1),
std::get<0>(p2), std::get<1>(p2), s0, s1, icurve);
}))
.def("build", [](Triangle2D * self, std::tuple<real_type, real_type> p0, std::tuple<real_type, real_type> p1,

.def("build", [](Triangle2D & self, std::tuple<real_type, real_type> p0, std::tuple<real_type, real_type> p1,
std::tuple<real_type, real_type> p2, real_type s0, real_type s1, int_type icurve) {
self->build(std::get<0>(p0), std::get<1>(p0), std::get<0>(p1), std::get<1>(p1),
self.build(std::get<0>(p0), std::get<1>(p0), std::get<0>(p1), std::get<1>(p1),
std::get<0>(p2), std::get<1>(p2), s0, s1, icurve);
})
.def("build", [](Triangle2D * self, real_type x0, real_type y0, real_type x1, real_type y1,
},
R"S(
Builds a triangle based on the passed points

:param Tuple[float, float] p0: first point of the triangle
:param Tuple[float, float] p1: second point of the triangle
:param Tuple[float, float] p2: third point of the triangle
:param float s0: s0 of the triangle
:param float s1: s1 of the triangle
:param int icurve: number of the trinagle on the curve
:return: nothing, works in place
:rtype: NoneType
)S")

.def("build", [](Triangle2D & self, real_type x0, real_type y0, real_type x1, real_type y1,
real_type x2, real_type y2, real_type s0, real_type s1, int_type icurve) {
self->build(x0, y0, x1, y1, x2, y2, s0, s1, icurve);
})
.def("Icurve", &Triangle2D::Icurve)
.def("x1", &Triangle2D::x1)
.def("y1", &Triangle2D::y1)
.def("x2", &Triangle2D::x2)
.def("y2", &Triangle2D::y2)
.def("x3", &Triangle2D::x3)
.def("y3", &Triangle2D::y3)
.def("S0", &Triangle2D::S0)
.def("S1", &Triangle2D::S1)
.def("translate", &Triangle2D::translate)
.def("rotate", &Triangle2D::rotate)
.def("scale", &Triangle2D::scale)
.def("bbox", [](Triangle2D * self) {
self.build(x0, y0, x1, y1, x2, y2, s0, s1, icurve);
},
R"S(
Builds a triangle based on the passed coordinates

:param float x1: **x** coordinate of the first point
:param float y1: **y** coordinate of the first point
:param float x2: **x** coordinate of the second point
:param float y2: **y** coordinate of the second point
:param float x3: **x** coordinate of the third point
:param float y3: **y** coordinate of the third point
:param float s0: s0 of this triangle on the curve
:param float s1: s1 of this triangle on the curve
:param int icurve: number of the trinagle on the curve
)S")

.def("Icurve", &Triangle2D::Icurve,
R"S(
Returns the number of the curve of the triangle

:return: number of the curve of the triangle
:rtype: int
)S")

.def("x1", &Triangle2D::x1,
R"S(
Returns the **x** coordinate of the first point of the triangle

:return: **x** coordinate of the first point
:rtype: float
)S")

.def("y1", &Triangle2D::y1,
R"S(
Returns the **y** coordinate of the first point of the triangle

:return: **y** coordinate of the first point
:rtype: float
)S")

.def("x2", &Triangle2D::x2,
R"S(
Returns the **x** coordinate of the second point of the triangle

:return: **x** coordinate of the second point
:rtype: float
)S")

.def("y2", &Triangle2D::y2,
R"S(
Returns the **y** coordinate of the second point of the triangle

:return: **y** coordinate of the second point
:rtype: float
)S")

.def("x3", &Triangle2D::x3,
R"S(
Returns the **x** coordinate of the third point of the triangle

:return: **x** coordinate of the third point
:rtype: float
)S")

.def("y3", &Triangle2D::y3,
R"S(
Returns the **y** coordinate of the third point of the triangle

:return: **y** coordinate of the third point
:rtype: float
)S")

.def("S0", &Triangle2D::S0,
R"S(
Returns the s0 of the triangle

:return: s0 of the triangle
:rtype: float
)S")

.def("S1", &Triangle2D::S1,
R"S(
Returns the s1 of the triangle

:return: s1 of the triangle
:rtype: float
)S")

.def("translate", &Triangle2D::translate,
py::arg("tx"), py::arg("ty"),
R"S(
Translates the triangle by the indicated amount

:param float tx: translation amount on x
:param float ty: translation amount on y
:return: nothing, works in place
:rtype: NoneType
)S")

.def("rotate", &Triangle2D::rotate,
py::arg("angle"), py::arg("cx"), py::arg("cy"),
R"S(
Rotates the triangle by the indicated amount

:param float angle: angle of which to rotate the triangle
:param float cx: **x** coordinate of the pivot point
:param float cy: **y** coordinate of the pivot point
:return: nothing, works in place
:rtype: NoneType
)S")

.def("scale", &Triangle2D::scale,
py::arg("sc"),
R"S(
Scales the triangle by the indicated amount

:param float sc: scale factor
:return: nothing, works in place
:rtype: NoneType
)S")

.def("bbox", [](Triangle2D & self) {
real_type x_min, y_min, x_max, y_max;
self->bbox(x_min, y_min, x_max, y_max);
self.bbox(x_min, y_min, x_max, y_max);
return std::make_tuple(
std::make_tuple(x_min, y_min),
std::make_tuple(x_max, y_max));
})
.def("baricenterX", &Triangle2D::baricenterX)
.def("baricenterY", &Triangle2D::baricenterY)
.def("P1", [](Triangle2D * self) {
real_type const * p = self->P1();
},
R"S(
Returns the bounding box of the triangle. The returned tuple will
contain two tuples: the first one will contain the x and y coordinates
of the first point of the bounding box, while the second one will
contain the x and y coordinates of the second point of the bounding
box.

:return: bounding box of the triangle
:rtype: Tuple[Tuple[float, float], Tuple[float, float]]
)S")

.def("baricenterX", &Triangle2D::baricenterX,
R"S(
Returns the x coordinate of the baricenter of the triangle

:return: **x** coordinate of the baricenter of the triangle
:rtype: float
)S")

.def("baricenterY", &Triangle2D::baricenterY,
R"S(
Returns the y coordinate of the baricenter of the triangle

:return: **y** coordinate of the baricenter of the triangle
:rtype: float
)S")

.def("P1", [](const Triangle2D & self) {
real_type const * p = self.P1();
return std::make_tuple(p[0], p[1]);
})
.def("P2", [](Triangle2D * self) {
real_type const * p = self->P2();
},
R"S(
Returns the first point of the triangle

:return: first point of the triangle
:rtype: Tuple[float, float]
)S")

.def("P2", [](const Triangle2D & self) {
real_type const * p = self.P2();
return std::make_tuple(p[0], p[1]);
})
.def("P3", [](Triangle2D * self) {
real_type const * p = self->P3();
},
R"S(
Returns the second point of the triangle

:return: second point of the triangle
:rtype: Tuple[float, float]
)S")

.def("P3", [](const Triangle2D & self) {
real_type const * p = self.P3();
return std::make_tuple(p[0], p[1]);
})
.def("overlap", &Triangle2D::overlap)
.def("isCounterClockwise", &Triangle2D::isCounterClockwise)
.def("isInside", py::overload_cast<real_type, real_type>(&Triangle2D::isInside, py::const_))
.def("isInside", [](Triangle2D * self, std::tuple<real_type, real_type> p) {
},
R"S(
Returns the third point of the triangle

:return: third point of the triangle
:rtype: Tuple[float, float]
)S")

.def("overlap", &Triangle2D::overlap,
py::arg("t2"),
R"S(
Returns whether the passed triangle overlaps with this triangle

:param Triangle2D t2: triangle to check
:return: whether the passed triangle overlaps with this triangle
:rtype: bool
)S")

.def("isCounterClockwise", &Triangle2D::isCounterClockwise,
R"S(
Returns whether the triangle has points defined in a counterclockwise
order. Possible return values are:

* +1: counterclockwise
* -1: clockwise
* 0: deenerate triangle

:return: whether the triangle is counterclockwise
:rtype: int
)S")

.def("isInside", py::overload_cast<real_type, real_type>(&Triangle2D::isInside, py::const_),
py::arg("x"), py::arg("y"),
R"S(
Returns whether the passed point is inside the triangle.
Possible return values are:
* +1: inside
* -1: outside
* 0: on the border

:param float x: **x** coordinate of the point to check
:param float y: **y** coordinate of the point to check
:return: whether the passed point is inside the triangle
:rtype: int
)S")

.def("isInside", [](Triangle2D & self, std::tuple<real_type, real_type> p) {
real_type _p[2] = {std::get<0>(p), std::get<1>(p)};
return self->isInside(_p);
})
.def("distMin", &Triangle2D::distMin)
.def("distMax", &Triangle2D::distMax)
.def("__str__", [](Triangle2D * self) {
return self.isInside(_p);
},
R"S(
Returns whether the passed point is inside the triangle.
Possible return values are:
* +1: inside
* -1: outside
* 0: on the border

:param Tuple[float, float]: point to check
:return: whether the passed point is inside the triangle
:rtype: int
)S")

.def("distMin", &Triangle2D::distMin,
py::arg("x"), py::arg("y"),
R"S(
Returns the minimum distance between the passed point and
the triangle

:param float x: **x** coordinate of the point to check
:param float y: **y** coordinate of the point to check
:return: minimum distance between the point and the triangle
:rtype: float
)S")

.def("distMax", &Triangle2D::distMax,
py::arg("x"), py::arg("y"),
R"S(
Returns the maximum distance between the passed point and
the triangle

:param float x: **x** coordinate of the point to check
:param float y: **y** coordinate of the point to check
:return: maximum distance between the point and the triangle
:rtype: float
)S")

.def("__str__", [](const Triangle2D & self) {
std::ostringstream str;
self->info(str);
self.info(str);
return str.str();
});
}
Expand Down