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

Merge ign-math6 as of Frustum SWIG to main #363

Merged
merged 18 commits into from
Jan 15, 2022
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
8 changes: 4 additions & 4 deletions examples/quaternion_from_euler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ int main(int argc, char **argv)
if (argc != 4)
{
std::cerr << "Invalid usage\n\n"
<< "Usage (angles specified in radians):\n"
<< "Usage (angles specified in degrees):\n"
<< " quaternion_from_euler "
<< "<float_roll> <float_pitch> <float_yaw>\n\n"
<< "Example\n"
Expand All @@ -53,9 +53,9 @@ int main(int argc, char **argv)
return -1;
}

double roll = strToDouble(argv[1]);
double pitch = strToDouble(argv[2]);
double yaw = strToDouble(argv[3]);
double roll = IGN_DTOR(strToDouble(argv[1]));
double pitch = IGN_DTOR(strToDouble(argv[2]));
double yaw = IGN_DTOR(strToDouble(argv[3]));

std::cout << "Converting Euler angles:\n";
printf(" roll % .6f radians\n"
Expand Down
20 changes: 15 additions & 5 deletions include/ignition/math/AxisAlignedBox.hh
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ namespace ignition
/// greater than zero.
/// \return Density of the cylinder in kg/m^3. A negative value is
/// returned if radius, length or _mass is <= 0.
public: double DensityFromMass(const double _mass) const;
/// \deprecated Unimplemented
public: double IGN_DEPRECATED(6.0) DensityFromMass(
const double _mass) const;

/// \brief Set the density of this box based on a mass value.
/// Density is computed using
Expand All @@ -243,15 +245,21 @@ namespace ignition
/// \return True if the density was set. False is returned if the
/// box's size or the _mass value are <= 0.
/// \sa double DensityFromMass(const double _mass) const
public: bool SetDensityFromMass(const double _mass);
/// \deprecated Unimplemented
public: bool IGN_DEPRECATED(6.0) SetDensityFromMass(
const double _mass);

/// \brief Get the material associated with this box.
/// \return The material assigned to this box.
public: const ignition::math::Material &Material() const;
/// \deprecated Unimplemented
public: const ignition::math::Material IGN_DEPRECATED(6.0)
&Material() const;

/// \brief Set the material associated with this box.
/// \param[in] _mat The material assigned to this box
public: void SetMaterial(const ignition::math::Material &_mat);
/// \deprecated Unimplemented
public: void IGN_DEPRECATED(6.0) SetMaterial(
const ignition::math::Material &_mat);

/// \brief Get the mass matrix for this box. This function
/// is only meaningful if the box's size and material
Expand All @@ -260,7 +268,9 @@ namespace ignition
/// here.
/// \return False if computation of the mass matrix failed, which
/// could be due to an invalid size (<=0) or density (<=0).
public: bool MassMatrix(MassMatrix3d &_massMat) const;
/// \deprecated Unimplemented
public: bool IGN_DEPRECATED(6.0) MassMatrix(
MassMatrix3d &_massMat) const;

/// \brief Clip a line to a dimension of the box.
/// This is a helper function to Intersects
Expand Down
126 changes: 126 additions & 0 deletions src/python/AxisAlignedBox.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
* Copyright (C) 2021 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

%module axisalignedbox
%{
#include <iostream>
#include <tuple>
#include <ignition/math/AxisAlignedBox.hh>
#include <ignition/math/config.hh>
#include <ignition/math/Helpers.hh>
#include <ignition/math/Line3.hh>
#include <ignition/math/Vector3.hh>
%}

%include "typemaps.i"

%typemap(out) (std::tuple<bool, double>) {
$result = PyTuple_New(2);
PyTuple_SET_ITEM($result, 0, PyBool_FromLong(std::get<0>($1)));
PyTuple_SET_ITEM($result, 1, PyFloat_FromDouble(std::get<1>($1)));
}

%typemap(out) (std::tuple<bool, double, ignition::math::Vector3< double > >) {
$result = PyTuple_New(3);
std::tuple<bool, double, ignition::math::Vector3< double > > tuplecpp($1);
PyTuple_SET_ITEM($result, 0, PyBool_FromLong(std::get<0>(tuplecpp)));
PyTuple_SET_ITEM($result, 1, PyFloat_FromDouble(std::get<1>(tuplecpp)));

ignition::math::Vector3<double> vector3 = std::get<2>(tuplecpp);
PyObject *pyobject = SWIG_NewPointerObj((new ignition::math::Vector3< double >(static_cast< const ignition::math::Vector3< double >& >(vector3))), SWIGTYPE_p_ignition__math__Vector3T_double_t, SWIG_POINTER_OWN | 0 );
PyTuple_SET_ITEM(resultobj, 2, pyobject);
}


namespace ignition
{
namespace math
{
class AxisAlignedBox
{
%rename("%(undercase)s", %$isfunction, notregexmatch$name="^[A-Z]*$") "";

public: AxisAlignedBox();

public: AxisAlignedBox(const math::Vector3<double> &_vec1, const math::Vector3<double> &_vec2);

public: AxisAlignedBox(double _vec1X, double _vec1Y, double _vec1Z,
double _vec2X, double _vec2Y, double _vec2Z);

public: AxisAlignedBox(const AxisAlignedBox &_b);

public: virtual ~AxisAlignedBox();

%rename(x_length) XLength;
public: double XLength() const;

%rename(y_length) YLength;
public: double YLength() const;

%rename(z_length) ZLength;
public: double ZLength() const;

public: math::Vector3<double> Size() const;

public: math::Vector3<double> Center() const;

public: void Merge(const AxisAlignedBox &_box);

public: AxisAlignedBox operator+(const AxisAlignedBox &_b) const;

public: const AxisAlignedBox &operator+=(const AxisAlignedBox &_b);

public: bool operator==(const AxisAlignedBox &_b) const;

public: bool operator!=(const AxisAlignedBox &_b) const;

public: AxisAlignedBox operator-(const math::Vector3<double> &_v);

public: AxisAlignedBox operator+(const math::Vector3<double> &_v);

public: const math::Vector3<double> &Min() const;

public: const math::Vector3<double> &Max() const;

public: math::Vector3<double> &Min();

public: math::Vector3<double> &Max();

public: bool Intersects(const AxisAlignedBox &_box) const;

public: bool Contains(const math::Vector3<double> &_p) const;

public: bool IntersectCheck(const math::Vector3<double> &_origin, const math::Vector3<double> &_dir,
const double _min, const double _max) const;

public: std::tuple<bool, double> IntersectDist(
const math::Vector3<double> &_origin, const math::Vector3<double> &_dir,
const double _min, const double _max) const;

public: std::tuple<bool, double, math::Vector3<double>> Intersect(
const math::Line3<double> &_line) const;

public: std::tuple<bool, double, math::Vector3<double>> Intersect(
const math::Vector3<double> &_origin, const math::Vector3<double> &_dir,
const double _min, const double _max) const;

/// \brief Get the volume of the box in m^3.
/// \return Volume of the box in m^3.
public: double Volume() const;
};
}
}
Loading