Skip to content

Vector3 to vector4 functions#132

Merged
mjcarroll merged 8 commits intogazebosim:ign-math6from
luccosta:vector3_to_vector4_functions
Jul 20, 2020
Merged

Vector3 to vector4 functions#132
mjcarroll merged 8 commits intogazebosim:ign-math6from
luccosta:vector3_to_vector4_functions

Conversation

@luccosta
Copy link
Copy Markdown
Contributor

@luccosta luccosta commented Jul 13, 2020

Resolves #71 .

This implements the functions Min(), Min(Vector4), Max() and Max(Vector4) in Vector4 API, similar to the existing same functions in Vector3.

It enables Vector4 objects to perform:

vec4_a.max(vec4_b); vec4_a.min(vec4_b); vec4.max(); vec4.min();

All the tests passed, and I dont know how to evaluate the code coverage.

To build the changes correctly i had to adjust some files.

One was src/CMakeLists.txt to add Vector4 to the swig files, because the include of Vector4 library at Vector4_TEST.cc was using build/fake/install/include/ignition/math7/ignition/math/Vector4.hh. Also had to change RollingMean.hh because the lack of the limits library was causing build errors.

This is my first pull request, I was in doubt if was better make the PR with this adjusts asking if they were correct or ask about them before make the PR and if the correct thing to do is to make this adjusts in another PR. Also, I would like to receive advices to improvement.

luccosta added 2 commits July 13, 2020 10:40
Signed-off-by: Lucas Fernando <lucas.costa@ee.ufcg.edu.br>
Signed-off-by: Lucas Fernando <lucas.costa@ee.ufcg.edu.br>
@luccosta luccosta requested a review from scpeters as a code owner July 13, 2020 14:12
@luccosta
Copy link
Copy Markdown
Contributor Author

ignition_math-abichecker-any_to_any-ubuntu_auto-amd64 and ignition_math-ci-pr_any-ubuntu_auto-amd64 do not pass because they depends on the "Vector4.i" file, that I suppose to be an interface to ruby test code, and both does not exist on branch ign-math6 for Vector4.

I have started to write both "Vector4.i" and "Vector4_TEST.rb", the ideal is report this in an new Issue and make a new PR?

@chapulina chapulina requested a review from mjcarroll July 13, 2020 18:43
@mjcarroll
Copy link
Copy Markdown

ignition_math-abichecker-any_to_any-ubuntu_auto-amd64 and ignition_math-ci-pr_any-ubuntu_auto-amd64 do not pass because they depends on the "Vector4.i" file, that I suppose to be an interface to ruby test code, and both does not exist on branch ign-math6 for Vector4.

I believe if you want you can leave Vector4 out of the list of swig_files here: https://github.com/ignitionrobotics/ign-math/pull/132/files#diff-95e351a3805a1dafa85bf20b81d086e6R30, which should cause that generation to be skipped. We can then ticket that separately if you don't have it implemented right this second.

Copy link
Copy Markdown

@mjcarroll mjcarroll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions for conciseness, and a few vestigial changes.

/// \return the maximum element
public: T Max() const
{
return std::max(std::max(std::max(this->data[0],
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that std::max_element would be a bit more concise: https://en.cppreference.com/w/cpp/algorithm/max_element

/// \return the minimum element
public: T Min() const
{
return std::min(std::min(std::min(this->data[0],
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above but with std::min_element.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better.

Comment on lines +136 to +137
if (_v[0] > this->data[0])
this->data[0] = _v[0];
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this would be more concise

Suggested change
if (_v[0] > this->data[0])
this->data[0] = _v[0];
this->data[0] = std::max(_v[0], this->data[0]);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thing the same, and prefer std::min, only did with the ifs because is implemented this way in Vector3. Despite that I can use std::min?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer this, it would actually probably make sense to go back and fix vector3 and vector2 to be the same, but it's out of the scope of this pr.

/// \brief Set this vector's components to the minimum of itself and the
/// passed in vector
/// \param[in] _v the minimum clamping vector
public: void Min(const Vector4<T> &_v)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, but with std::min

#include "ignition/math/Helpers.hh"
#include "ignition/math/Matrix4.hh"
#include "ignition/math/Vector4.hh"
#include "../include/ignition/math/Vector4.hh"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem necessary, the same header should be included above.

Copy link
Copy Markdown
Contributor Author

@luccosta luccosta Jul 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ops, I forgot that rs, will remove.

#define IGNITION_MATH_ROLLINGMEAN_HH_

#include <memory>
#include <limits>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of scope for this PR?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree and will remove from the PR, only put this library because before it the build is giving the following error:

ign-math/src/RollingMean.cc:57:10: error: 'numeric_limits' is not a member of 'std'

Must I create an Issue for this?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine to put in here, but since it's used in the cc file, rather than the header, it should be added there, I believe.

@chapulina chapulina added enhancement New feature or request 🏰 citadel Ignition Citadel 📜 blueprint Ignition Blueprint 🔮 dome Ignition Dome labels Jul 15, 2020
luccosta and others added 5 commits July 14, 2020 22:37
Signed-off-by: Lucas Fernando <lucas.costa@ee.ufcg.edu.br>
Signed-off-by: Lucas Fernando <lucas.costa@ee.ufcg.edu.br>
Signed-off-by: Lucas Fernando <lucas.costa@ee.ufcg.edu.br>
@luccosta
Copy link
Copy Markdown
Contributor Author

I believe if you want you can leave Vector4 out of the list of swig_files here: https://github.com/ignitionrobotics/ign-math/pull/132/files#diff-95e351a3805a1dafa85bf20b81d086e6R30, which should cause that generation to be skipped. We can then ticket that separately if you don't have it implemented right this second.

Remove Vector4 from swig_files and made the suggested changes.

Also had finished Vector4.i and am close to finish Vector4_TEST.rb, that will be a relative big pull request.

Copy link
Copy Markdown
Contributor Author

@luccosta luccosta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes made, only in doubt with the proper use of std::max_element with pure arrays.

Copy link
Copy Markdown

@mjcarroll mjcarroll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks for the contribution!

@mjcarroll mjcarroll merged commit 0270a51 into gazebosim:ign-math6 Jul 20, 2020
@luccosta luccosta deleted the vector3_to_vector4_functions branch July 20, 2020 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📜 blueprint Ignition Blueprint 🏰 citadel Ignition Citadel 🔮 dome Ignition Dome enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants