Skip to content

File angles.hpp

File List > include > nebula_decoders > nebula_decoders_common > angles.hpp

Go to the documentation of this file

// Copyright 2024 TIER IV, Inc.
//
// 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.

#pragma once

#include <cmath>
namespace nebula::drivers
{

template <typename T>
bool angle_is_between(
  T start_angle, T end_angle, T angle, bool start_inclusive = true, bool end_inclusive = true)
{
  if (!start_inclusive && angle == start_angle) return false;
  if (!end_inclusive && angle == end_angle) return false;

  return (start_angle <= angle && angle <= end_angle) ||
         ((end_angle < start_angle) && (angle <= end_angle || start_angle <= angle));
}

template <typename T>
T normalize_angle(T angle, T max_angle)
{
  T factor = std::floor((1.0 * angle) / max_angle);
  return angle - (factor * max_angle);
}

}  // namespace nebula::drivers