Skip to content

Pass comparator arguments in Translation2d::Nearest() by const reference #8019

Closed
@calcmogul

Description

@calcmogul

They're larger than the machine word size, so they should be passed by const reference instead of by value. Here's the relevant code:

  /**
   * Returns the nearest Translation2d from a collection of translations
   * @param translations The collection of translations.
   * @return The nearest Translation2d from the collection.
   */
  constexpr Translation2d Nearest(
      std::span<const Translation2d> translations) const {
    return *std::min_element(translations.begin(), translations.end(),
                             [this](Translation2d a, Translation2d b) {
                               return this->Distance(a) < this->Distance(b);
                             });
  }

  /**
   * Returns the nearest Translation2d from a collection of translations
   * @param translations The collection of translations.
   * @return The nearest Translation2d from the collection.
   */
  constexpr Translation2d Nearest(
      std::initializer_list<Translation2d> translations) const {
    return *std::min_element(translations.begin(), translations.end(),
                             [this](Translation2d a, Translation2d b) {
                               return this->Distance(a) < this->Distance(b);
                             });
  }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions