0

I'm trying to understand a C++ code. (I'm a total beginner and used to Java) And I'm really struggeling to understand what happens here.

so I got this

      Eigen::Vector2i mapDims;
      Eigen::Vector2f mapLimits;
      float cellLength;

and a Constructor for my Class that looks like this:

MapDimensionProperties(const Eigen::Vector2f& OffsetIn, const Eigen::Vector2i& mapDimsIn, float cellLengthIn)
    : tOffset(OffsetIn)
    , mapDims(mapDimsIn)
        , cellLength(cellLengthIn)
      {
        // I don't understand the following part:
        mapLimits = (mapDimensionsIn.cast<float>()).array() - 1.0f;
      }

What is happening here? I see that this Integer Vector is cast to a Float Vector, and seemingly afterwards made into an Array. But how can you subtract a float number from an Array? I mean wouldn't you have to point out a specific index on which place you want to subtract something? And how can it override mapLimits, if its an Array and mapLimits is a vector?

Or am I completely wrong here?

Thank you in advance.

kalu
  • 169
  • 1
  • 11
  • 2
    You should look into operator overloading, and a [good C++ book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) – Passer By Jul 02 '17 at 17:26
  • @PasserBy ... well I know this is probably a stupid question, but I've tried to research it and it seems like I don't even know how to properly phrase what i don't know ... – kalu Jul 02 '17 at 17:29
  • @PasserBy EDIT: do you know where I can look up how the operator is oerloaded for the Eigen::Vector2f – kalu Jul 02 '17 at 17:36
  • 1
    @kalu I don't mean to be condescending, but with no familiarity with Eigen, I found [this page](https://eigen.tuxfamily.org/dox/group__TutorialMatrixArithmetic.html) after 15 seconds of googling. – cdhowie Jul 02 '17 at 17:52
  • @cdhowie oh wow thats embarassing... I've been working and studying for the last 11 hours and this is the definite proove that you can dump my brain in the trashcan by now. thank you for your effort, this answers my questions – kalu Jul 02 '17 at 17:59
  • @kalu No worries. I will admit that sometimes you just need a second set of eyes -- or, what usually happens to me: I'll be unable to solve a problem for hours, but less than five minutes after asking for help I will stumble on the answer myself. – cdhowie Jul 02 '17 at 18:03
  • @cdhowie oh yes, relatable. i actually realized i already had this page open but closed it again after a quick look, not realizing that this is exactly what i was searching for. – kalu Jul 02 '17 at 18:21

1 Answers1

2

This is an overloaded operator - which substracts scalar value from all of the array's items. I believe this piece of documentation describes it: link.

Nikolai Shalakin
  • 1,349
  • 2
  • 13
  • 25