mirror of https://github.com/KLayout/klayout.git
Added a convenience binding for vector+point
This way, the vector/point sum is commutable. vector+point == point+vector.
This commit is contained in:
parent
374816fe0e
commit
d90593df89
|
|
@ -100,6 +100,11 @@ struct vector_defs
|
||||||
return std_ext::hfunc (*v);
|
return std_ext::hfunc (*v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static db::point<coord_type> add_with_point (const C *v, const db::point<coord_type> &p)
|
||||||
|
{
|
||||||
|
return p + *v;
|
||||||
|
}
|
||||||
|
|
||||||
static gsi::Methods methods ()
|
static gsi::Methods methods ()
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
|
|
@ -120,6 +125,7 @@ struct vector_defs
|
||||||
method_ext ("to_p", &to_point,
|
method_ext ("to_p", &to_point,
|
||||||
"@brief Turns the vector into a point\n"
|
"@brief Turns the vector into a point\n"
|
||||||
"This method returns the point resulting from adding the vector to (0,0)."
|
"This method returns the point resulting from adding the vector to (0,0)."
|
||||||
|
"\n"
|
||||||
"This method has been introduced in version 0.25."
|
"This method has been introduced in version 0.25."
|
||||||
) +
|
) +
|
||||||
method_ext ("-@", &negate,
|
method_ext ("-@", &negate,
|
||||||
|
|
@ -136,6 +142,13 @@ struct vector_defs
|
||||||
"\n"
|
"\n"
|
||||||
"Adds vector v to self by adding the coordinates.\n"
|
"Adds vector v to self by adding the coordinates.\n"
|
||||||
) +
|
) +
|
||||||
|
method_ext ("+", &add_with_point,
|
||||||
|
"@brief Adds a vector and a point\n"
|
||||||
|
"\n"
|
||||||
|
"@args p\n"
|
||||||
|
"\n"
|
||||||
|
"Returns the point p shifted by the vector.\n"
|
||||||
|
) +
|
||||||
method ("-", (C (C::*) (const C &) const) &C::subtract,
|
method ("-", (C (C::*) (const C &) const) &C::subtract,
|
||||||
"@brief Subtract two vectors\n"
|
"@brief Subtract two vectors\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,11 @@ class DBVector_TestClass < TestBase
|
||||||
b.y = a.y
|
b.y = a.y
|
||||||
assert_equal( a, b )
|
assert_equal( a, b )
|
||||||
|
|
||||||
|
assert_equal( c.to_p.class == RBA::DPoint, true )
|
||||||
|
assert_equal( c.class == RBA::DVector, true )
|
||||||
|
assert_equal( (c + RBA::DPoint::new(1, 2)).class == RBA::DPoint, true )
|
||||||
|
assert_equal( (c + RBA::DPoint::new(1, 2)).to_s, "6,13" )
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Transforming DVector
|
# Transforming DVector
|
||||||
|
|
@ -101,6 +106,11 @@ class DBVector_TestClass < TestBase
|
||||||
b.y = a.y
|
b.y = a.y
|
||||||
assert_equal( a, b )
|
assert_equal( a, b )
|
||||||
|
|
||||||
|
assert_equal( c.to_p.class == RBA::Point, true )
|
||||||
|
assert_equal( c.class == RBA::Vector, true )
|
||||||
|
assert_equal( (c + RBA::Point::new(1, 2)).class == RBA::Point, true )
|
||||||
|
assert_equal( (c + RBA::Point::new(1, 2)).to_s, "6,13" )
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Transforming Vector
|
# Transforming Vector
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue