256
  B   ˆl—ß=¿J•4Ÿº‚ „ \¸Ó×yLZ7ÿ�þ^¤Y²‘öcáy·�üÿÂ„e‘:çÁ_ˆI|¥�+y,ÁÀ ?÷     //
// SPDX-License-Identifier: BSD-3-Clause
// Copyright Contributors to the OpenEXR Project.
//

// clang-format off

#ifndef _PyImathVec2Impl_h_
#define _PyImathVec2Impl_h_

//
// This .C file was turned into a header file so that instantiations
// of the various V2* types can be spread across multiple files in
// order to work around MSVC limitations.
//

#include <Python.h>
#include <boost/python.hpp>
#include <boost/python/make_constructor.hpp>
#include <boost/format.hpp>
#include <boost/cast.hpp>
#include <ImathVec.h>
#include <ImathVecAlgo.h>
#include "PyImath.h"
#include "PyImathMathExc.h"
#include "PyImathBox.h"
#include "PyImathVec.h"
#include "PyImathDecorators.h"
#include "PyImathOperators.h"
#include "PyImathVecOperators.h"

namespace PyImath {
using namespace boost::python;
using namespace IMATH_NAMESPACE;

template <class T> struct Vec2Name { static const char *value; };

// create a new default constructor that initializes Vec2<T> to zero.
template <class T>
static Vec2<T> * Vec2_construct_default()
{
    return new Vec2<T>(T(0),T(0));
}

template <class T,class BoostPyType>
static Vec2<T> * Vec2_tuple_constructor(const BoostPyType &t)
{
    if(t.attr("__len__")() == 1)
        return new Vec2<T>(extract<T>(t[0]), extract<T>(t[0]));
    else if(t.attr("__len__")() == 2)
        return new Vec2<T>(extract<T>(t[0]), extract<T>(t[1]));
    else
      throw std::invalid_argument ("Vec2 constructor expects tuple of length 1 or 2");
}

template <class T>
static Vec2<T> * Vec2_object_constructor1(const object &obj)
{
    Vec2<T> w;
    extract<Vec2<int> >     e1(obj);
    extract<Vec2<float> >   e2(obj);
    extract<Vec2<double> >  e3(obj);
    extract<tuple>          e4(obj);
    extract<double>         e5(obj);
    extract<list>           e6(obj);
    
    if(e1.check()){ w = e1(); }
    else if(e2.check()) { w = e2(); }
    else if(e3.check()) { w = e3(); }
    else if(e4.check())
    {
        tuple t = e4();
        if(t.attr("__len__")() == 2)
        {
            w.x = extract<T>(t[0]);
            w.y = extract<T>(t[1]);
        }
        else
            throw std::invalid_argument ("tuple must have length of 2");
    }
    else if(e5.check()) { T a = e5(); w.setValue(a, a); }
    else if(e6.check())
    {
        list l = e6();
        if(l.attr("__len__")() == 2)
        {
            w.x = extract<T>(l[0]);
            w.y = extract<T>(l[1]);
        }
        else
            throw std::invalid_argument ("list must have length of 2");
    }
    else
        throw std::invalid_argument ("invalid parameters passed to Vec2 constructor");
    
    Vec2<T> *v = new Vec2<T>;
    *v = w;
    
    return v;

}

template <class T>
static Vec2<T> * Vec2_object_constructor2(const object &obj1, const object &obj2)
{
    extract<double> e1(obj1);
    extract<double> e2(obj2);
    
    Vec2<T> *v = new Vec2<T>;
    
    if(e1.check()) { v->x = boost::numeric_cast<T>(e1());}
    else { throw std::invalid_argument ("invalid parameters passed to Vec2 constructor"); }
    
    if(e2.check()) { v->y = boost::numeric_cast<T>(e2());}
    else { throw std::invalid_argument ("invalid parameters passed to Vec2 constructor"); }    
    
    return v;
}

// Implementations of str and repr are same here,
// but we'll specialize repr for float and double to make them exact.
template <class T>
static std::string Vec2_str(const Vec2<T> &v)
{
    std::stringstream stream;
    stream << Vec2Name<T>::value << "(" << v.x << ", " << v.y << ")";
    return stream.str();
}
template <class T>
static std::string Vec2_repr(const Vec2<T> &v)
{
    std::stringstream stream;
    stream << Vec2Name<T>::value << "(" << v.x << ", " << v.y << ")";
    return stream.str();
}

template <class T>
static T
Vec2_cross(const IMATH_NAMESPACE::Vec2<T> &v, const IMATH_NAMESPACE::Vec2<T> &other) 
{ 
    MATH_EXC_ON;
    return v.cross(other);
}

template <class T>
static FixedArray<T>
Vec2_cross_Vec2Array(const IMATH_NAMESPACE::Vec2<T> &va, const FixedArray<IMATH_NAME