Program Listing for File Size.hpp

Return to documentation for file (nvcv_types/include/nvcv/Size.hpp)

/*
 * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 * SPDX-License-Identifier: Apache-2.0
 *
 * 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.
 */

#ifndef NVCV_SIZE_HPP
#define NVCV_SIZE_HPP

#include "Size.h"

#include <cassert>
#include <iostream>
#include <tuple>

namespace nvcv {

struct Size2D : NVCVSize2D
{
    using NVCVSize2D::NVCVSize2D;

    constexpr Size2D(int32_t w, int32_t h)
        : NVCVSize2D{w, h}
    {
    }

    constexpr Size2D(const NVCVSize2D &s)
        : NVCVSize2D{s.w, s.h}
    {
    }

    inline Size2D &operator=(const NVCVSize2D &s)
    {
        static_cast<NVCVSize2D &>(*this) = s;
        return *this;
    }

    constexpr bool operator==(const Size2D &rhs) const
    {
        return w == rhs.w && h == rhs.h;
    }

    constexpr bool operator!=(const Size2D &rhs) const
    {
        return !(*this == rhs);
    }

    inline bool operator<(const nvcv::Size2D &rhs) const
    {
        return std::tie(w, h) < std::tie(rhs.w, rhs.h);
    }
};

constexpr Size2D MaxSize(const Size2D &a, const Size2D &b)
{
    return {b.w > a.w ? b.w : a.w, b.h > a.h ? b.h : a.h};
}

inline std::ostream &operator<<(std::ostream &out, const nvcv::Size2D &size)
{
    return out << size.w << "x" << size.h;
}

} // namespace nvcv

#endif // NVCV_SIZE_HPP