mirror of https://github.com/KLayout/klayout.git
adding / and /= operators to Point and Vector types in db [ci skip]
This commit is contained in:
parent
1db2bea26c
commit
cfbcc158bf
|
|
@ -194,6 +194,20 @@ public:
|
|||
*/
|
||||
point<C> &operator*= (long s);
|
||||
|
||||
/**
|
||||
* @brief Division by some divisor.
|
||||
*
|
||||
* Scaline involves rounding which in our case is simply handled
|
||||
* with the coord_traits scheme.
|
||||
*/
|
||||
|
||||
point<C> &operator/= (double s);
|
||||
|
||||
/**
|
||||
* @brief Dividing self by some integer divisor
|
||||
*/
|
||||
point<C> &operator/= (long s);
|
||||
|
||||
/**
|
||||
* @brief The euclidian distance to another point
|
||||
*
|
||||
|
|
@ -452,6 +466,32 @@ operator* (const db::point<C> &p, unsigned int s)
|
|||
return point<C> (p.x () * s, p.y () * s);
|
||||
}
|
||||
|
||||
template <class C, typename Number>
|
||||
inline point<C>
|
||||
operator/ (const db::point<C> &p, Number s)
|
||||
{
|
||||
double mult = 1.0 / static_cast<double>(s);
|
||||
return point<C> (p.x () * mult, p.y () * mult);
|
||||
}
|
||||
|
||||
template <class C>
|
||||
inline point<C> &
|
||||
point<C>::operator/= (double s)
|
||||
{
|
||||
double mult = 1.0 / static_cast<double>(s);
|
||||
*this *= mult;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class C>
|
||||
inline point<C> &
|
||||
point<C>::operator/= (long s)
|
||||
{
|
||||
double mult = 1.0 / static_cast<double>(s);
|
||||
*this *= mult;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class C>
|
||||
inline point<C> &
|
||||
point<C>::operator*= (double s)
|
||||
|
|
|
|||
|
|
@ -266,6 +266,20 @@ public:
|
|||
*/
|
||||
vector<C> operator*= (long s);
|
||||
|
||||
/**
|
||||
* @brief Division by some divisor.
|
||||
*
|
||||
* Scaline involves rounding which in our case is simply handled
|
||||
* with the coord_traits scheme.
|
||||
*/
|
||||
|
||||
vector<C> &operator/= (double s);
|
||||
|
||||
/**
|
||||
* @brief Dividing self by some integer divisor
|
||||
*/
|
||||
vector<C> &operator/= (long s);
|
||||
|
||||
/**
|
||||
* @brief The euclidian length
|
||||
*/
|
||||
|
|
@ -450,6 +464,32 @@ vector<C>::operator* (long s) const
|
|||
return vector<C> (m_x * s, m_y * s);
|
||||
}
|
||||
|
||||
template <class C, typename Number>
|
||||
inline vector<C>
|
||||
operator/ (const db::vector<C> &p, Number s)
|
||||
{
|
||||
double mult = 1.0 / static_cast<double>(s);
|
||||
return vector<C> (p.x () * mult, p.y () * mult);
|
||||
}
|
||||
|
||||
template <class C>
|
||||
inline vector<C> &
|
||||
vector<C>::operator/= (double s)
|
||||
{
|
||||
double mult = 1.0 / static_cast<double>(s);
|
||||
*this *= mult;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class C>
|
||||
inline vector<C> &
|
||||
vector<C>::operator/= (long s)
|
||||
{
|
||||
double mult = 1.0 / static_cast<double>(s);
|
||||
*this *= mult;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class C>
|
||||
inline vector<C>
|
||||
vector<C>::operator*= (double s)
|
||||
|
|
|
|||
|
|
@ -70,6 +70,23 @@ struct point_defs
|
|||
return C (*p * s);
|
||||
}
|
||||
|
||||
static C divide (const C *p, double s)
|
||||
{
|
||||
return C (*p / s);
|
||||
}
|
||||
|
||||
static C iscale (C *p, double s)
|
||||
{
|
||||
*p *= s;
|
||||
return *p;
|
||||
}
|
||||
|
||||
static C idiv (C *p, double s)
|
||||
{
|
||||
*p /= s;
|
||||
return *p;
|
||||
}
|
||||
|
||||
static C negate (const C *p)
|
||||
{
|
||||
return -*p;
|
||||
|
|
@ -175,6 +192,30 @@ struct point_defs
|
|||
"Returns the scaled object. All coordinates are multiplied with the given factor and if "
|
||||
"necessary rounded."
|
||||
) +
|
||||
method_ext ("*=", &iscale,
|
||||
"@brief Scaling by some factor\n"
|
||||
"\n"
|
||||
"@args f\n"
|
||||
"\n"
|
||||
"Scales object in place. All coordinates are multiplied with the given factor and if "
|
||||
"necessary rounded."
|
||||
) +
|
||||
method_ext ("/", ÷,
|
||||
"@brief Division by some divisor\n"
|
||||
"\n"
|
||||
"@args d\n"
|
||||
"\n"
|
||||
"Returns the scaled object. All coordinates are divided with the given divisor and if "
|
||||
"necessary rounded."
|
||||
) +
|
||||
method_ext ("/=", &idiv,
|
||||
"@brief Division by some divisor\n"
|
||||
"\n"
|
||||
"@args d\n"
|
||||
"\n"
|
||||
"Divides the object in place. All coordinates are divided with the given divisor and if "
|
||||
"necessary rounded."
|
||||
) +
|
||||
method ("distance", (double (C::*) (const C &) const) &C::double_distance,
|
||||
"@brief The Euclidian distance to another point\n"
|
||||
"\n"
|
||||
|
|
|
|||
|
|
@ -70,6 +70,23 @@ struct vector_defs
|
|||
return C (*p * s);
|
||||
}
|
||||
|
||||
static C divide (const C *p, double s)
|
||||
{
|
||||
return C (*p / s);
|
||||
}
|
||||
|
||||
static C iscale (C *p, double s)
|
||||
{
|
||||
*p *= s;
|
||||
return *p;
|
||||
}
|
||||
|
||||
static C idiv (C *p, double s)
|
||||
{
|
||||
*p /= s;
|
||||
return *p;
|
||||
}
|
||||
|
||||
static C negate (const C *p)
|
||||
{
|
||||
return -*p;
|
||||
|
|
@ -202,6 +219,30 @@ struct vector_defs
|
|||
"Returns the scaled object. All coordinates are multiplied with the given factor and if "
|
||||
"necessary rounded."
|
||||
) +
|
||||
method_ext ("*=", &iscale,
|
||||
"@brief Scaling by some factor\n"
|
||||
"\n"
|
||||
"@args f\n"
|
||||
"\n"
|
||||
"Scales object in place. All coordinates are multiplied with the given factor and if "
|
||||
"necessary rounded."
|
||||
) +
|
||||
method_ext ("/", ÷,
|
||||
"@brief Division by some divisor\n"
|
||||
"\n"
|
||||
"@args d\n"
|
||||
"\n"
|
||||
"Returns the scaled object. All coordinates are divided with the given divisor and if "
|
||||
"necessary rounded."
|
||||
) +
|
||||
method_ext ("/=", &idiv,
|
||||
"@brief Division by some divisor\n"
|
||||
"\n"
|
||||
"@args d\n"
|
||||
"\n"
|
||||
"Divides the object in place. All coordinates are divided with the given divisor and if "
|
||||
"necessary rounded."
|
||||
) +
|
||||
method_ext ("vprod", &vprod,
|
||||
"@brief Computes the vector product between self and the given vector\n"
|
||||
"\n"
|
||||
|
|
|
|||
|
|
@ -493,7 +493,11 @@ static std::string extract_python_name (const std::string &name)
|
|||
} else if (name == "-@") {
|
||||
return "__neg__";
|
||||
} else if (name == "/") {
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
return "__div__";
|
||||
#else
|
||||
return "__truediv__";
|
||||
#endif
|
||||
} else if (name == "*") {
|
||||
return "__mul__";
|
||||
} else if (name == "%") {
|
||||
|
|
@ -515,7 +519,11 @@ static std::string extract_python_name (const std::string &name)
|
|||
} else if (name == "-=") {
|
||||
return "__isub__";
|
||||
} else if (name == "/=") {
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
return "__idiv__";
|
||||
#else
|
||||
return "__itruediv__";
|
||||
#endif
|
||||
} else if (name == "*=") {
|
||||
return "__imul__";
|
||||
} else if (name == "%=") {
|
||||
|
|
|
|||
Loading…
Reference in New Issue