mirror of https://github.com/KLayout/klayout.git
Added some convenience methods for transformations
* Reactivated (deprecated) from_xtrans methods for backward compatibility * Added more flavours of "trans" and "*" (like transformation of boxes)
This commit is contained in:
parent
7e6dfdf5b4
commit
9ff1a76f94
|
|
@ -24,6 +24,10 @@
|
|||
#include "gsiDecl.h"
|
||||
#include "dbPoint.h"
|
||||
#include "dbBox.h"
|
||||
#include "dbEdge.h"
|
||||
#include "dbPolygon.h"
|
||||
#include "dbPath.h"
|
||||
#include "dbText.h"
|
||||
|
||||
namespace gsi
|
||||
{
|
||||
|
|
@ -106,6 +110,31 @@ struct trans_defs
|
|||
*trans = C (trans->angle (), mirror, trans->disp ());
|
||||
}
|
||||
|
||||
static db::edge<coord_type> trans_edge (const C *t, const db::edge<coord_type> &edge)
|
||||
{
|
||||
return edge.transformed (*t);
|
||||
}
|
||||
|
||||
static db::box<coord_type> trans_box (const C *t, const db::box<coord_type> &box)
|
||||
{
|
||||
return box.transformed (*t);
|
||||
}
|
||||
|
||||
static db::polygon<coord_type> trans_polygon (const C *t, const db::polygon<coord_type> &polygon)
|
||||
{
|
||||
return polygon.transformed (*t);
|
||||
}
|
||||
|
||||
static db::path<coord_type> trans_path (const C *t, const db::path<coord_type> &path)
|
||||
{
|
||||
return path.transformed (*t);
|
||||
}
|
||||
|
||||
static db::text<coord_type> trans_text (const C *t, const db::text<coord_type> &text)
|
||||
{
|
||||
return text.transformed (*t);
|
||||
}
|
||||
|
||||
static gsi::Methods methods ()
|
||||
{
|
||||
return
|
||||
|
|
@ -217,6 +246,56 @@ struct trans_defs
|
|||
"@param v The vector to transform\n"
|
||||
"@return The transformed vector\n"
|
||||
) +
|
||||
method_ext ("trans|*", &trans_box, arg ("box"),
|
||||
"@brief Transforms a box\n"
|
||||
"\n"
|
||||
"'t*box' or 't.trans(box)' is equivalent to box.transformed(t).\n"
|
||||
"\n"
|
||||
"@param box The box to transform\n"
|
||||
"@return The transformed box\n"
|
||||
"\n"
|
||||
"This convenience method has been introduced in version 0.25."
|
||||
) +
|
||||
method_ext ("trans|*", &trans_edge, arg ("edge"),
|
||||
"@brief Transforms an edge\n"
|
||||
"\n"
|
||||
"'t*edge' or 't.trans(edge)' is equivalent to edge.transformed(t).\n"
|
||||
"\n"
|
||||
"@param edge The edge to transform\n"
|
||||
"@return The transformed edge\n"
|
||||
"\n"
|
||||
"This convenience method has been introduced in version 0.25."
|
||||
) +
|
||||
method_ext ("trans|*", &trans_polygon, arg ("polygon"),
|
||||
"@brief Transforms a polygon\n"
|
||||
"\n"
|
||||
"'t*polygon' or 't.trans(polygon)' is equivalent to polygon.transformed(t).\n"
|
||||
"\n"
|
||||
"@param polygon The polygon to transform\n"
|
||||
"@return The transformed polygon\n"
|
||||
"\n"
|
||||
"This convenience method has been introduced in version 0.25."
|
||||
) +
|
||||
method_ext ("trans|*", &trans_path, arg ("path"),
|
||||
"@brief Transforms a path\n"
|
||||
"\n"
|
||||
"'t*path' or 't.trans(path)' is equivalent to path.transformed(t).\n"
|
||||
"\n"
|
||||
"@param path The path to transform\n"
|
||||
"@return The transformed path\n"
|
||||
"\n"
|
||||
"This convenience method has been introduced in version 0.25."
|
||||
) +
|
||||
method_ext ("trans|*", &trans_text, arg ("text"),
|
||||
"@brief Transforms a text\n"
|
||||
"\n"
|
||||
"'t*text' or 't.trans(text)' is equivalent to text.transformed(t).\n"
|
||||
"\n"
|
||||
"@param text The text to transform\n"
|
||||
"@return The transformed text\n"
|
||||
"\n"
|
||||
"This convenience method has been introduced in version 0.25."
|
||||
) +
|
||||
method ("*", &C::concat, arg ("t"),
|
||||
"@brief Returns the concatenated transformation\n"
|
||||
"\n"
|
||||
|
|
@ -343,7 +422,7 @@ static db::DTrans trans_to_dtrans (const db::Trans *t, double dbu)
|
|||
}
|
||||
|
||||
Class<db::Trans> decl_Trans ("Trans",
|
||||
constructor ("new", &trans_from_dtrans, gsi::arg ("dtrans"),
|
||||
constructor ("new|#from_dtrans", &trans_from_dtrans, gsi::arg ("dtrans"),
|
||||
"@brief Creates an integer coordinate transformation from a floating-point coordinate transformation\n"
|
||||
"\n"
|
||||
"This constructor has been introduced in version 0.25 and replaces the previous static method 'from_dtrans'."
|
||||
|
|
@ -393,7 +472,7 @@ static db::Trans dtrans_to_trans (const db::DTrans *t, double dbu)
|
|||
}
|
||||
|
||||
Class<db::DTrans> decl_DTrans ("DTrans",
|
||||
constructor ("new", &dtrans_from_itrans, gsi::arg ("trans"),
|
||||
constructor ("new|#from_itrans", &dtrans_from_itrans, gsi::arg ("trans"),
|
||||
"@brief Creates a floating-point coordinate transformation from an integer coordinate transformation\n"
|
||||
"\n"
|
||||
"This constructor has been introduced in version 0.25 and replaces the previous static method 'from_itrans'."
|
||||
|
|
@ -518,6 +597,31 @@ struct cplx_trans_defs
|
|||
return simple_trans_type (db::complex_trans<coord_type, coord_type> (*cplx_trans));
|
||||
}
|
||||
|
||||
static db::edge<target_coord_type> trans_edge (const C *t, const db::edge<coord_type> &edge)
|
||||
{
|
||||
return edge.transformed (*t);
|
||||
}
|
||||
|
||||
static db::box<target_coord_type> trans_box (const C *t, const db::box<coord_type> &box)
|
||||
{
|
||||
return box.transformed (*t);
|
||||
}
|
||||
|
||||
static db::polygon<target_coord_type> trans_polygon (const C *t, const db::polygon<coord_type> &polygon)
|
||||
{
|
||||
return polygon.transformed (*t);
|
||||
}
|
||||
|
||||
static db::path<target_coord_type> trans_path (const C *t, const db::path<coord_type> &path)
|
||||
{
|
||||
return path.transformed (*t);
|
||||
}
|
||||
|
||||
static db::text<target_coord_type> trans_text (const C *t, const db::text<coord_type> &text)
|
||||
{
|
||||
return text.transformed (*t);
|
||||
}
|
||||
|
||||
static gsi::Methods methods ()
|
||||
{
|
||||
return
|
||||
|
|
@ -651,6 +755,56 @@ struct cplx_trans_defs
|
|||
"@param v The vector to transform\n"
|
||||
"@return The transformed vector\n"
|
||||
) +
|
||||
method_ext ("trans|*", &trans_box, arg ("box"),
|
||||
"@brief Transforms a box\n"
|
||||
"\n"
|
||||
"'t*box' or 't.trans(box)' is equivalent to box.transformed(t).\n"
|
||||
"\n"
|
||||
"@param box The box to transform\n"
|
||||
"@return The transformed box\n"
|
||||
"\n"
|
||||
"This convenience method has been introduced in version 0.25."
|
||||
) +
|
||||
method_ext ("trans|*", &trans_edge, arg ("edge"),
|
||||
"@brief Transforms an edge\n"
|
||||
"\n"
|
||||
"'t*edge' or 't.trans(edge)' is equivalent to edge.transformed(t).\n"
|
||||
"\n"
|
||||
"@param edge The edge to transform\n"
|
||||
"@return The transformed edge\n"
|
||||
"\n"
|
||||
"This convenience method has been introduced in version 0.25."
|
||||
) +
|
||||
method_ext ("trans|*", &trans_polygon, arg ("polygon"),
|
||||
"@brief Transforms a polygon\n"
|
||||
"\n"
|
||||
"'t*polygon' or 't.trans(polygon)' is equivalent to polygon.transformed(t).\n"
|
||||
"\n"
|
||||
"@param polygon The polygon to transform\n"
|
||||
"@return The transformed polygon\n"
|
||||
"\n"
|
||||
"This convenience method has been introduced in version 0.25."
|
||||
) +
|
||||
method_ext ("trans|*", &trans_path, arg ("path"),
|
||||
"@brief Transforms a path\n"
|
||||
"\n"
|
||||
"'t*path' or 't.trans(path)' is equivalent to path.transformed(t).\n"
|
||||
"\n"
|
||||
"@param path The path to transform\n"
|
||||
"@return The transformed path\n"
|
||||
"\n"
|
||||
"This convenience method has been introduced in version 0.25."
|
||||
) +
|
||||
method_ext ("trans|*", &trans_text, arg ("text"),
|
||||
"@brief Transforms a text\n"
|
||||
"\n"
|
||||
"'t*text' or 't.trans(text)' is equivalent to text.transformed(t).\n"
|
||||
"\n"
|
||||
"@param text The text to transform\n"
|
||||
"@return The transformed text\n"
|
||||
"\n"
|
||||
"This convenience method has been introduced in version 0.25."
|
||||
) +
|
||||
method ("*", (C (C::*) (const C &c) const) &C::concat_same, arg ("t"),
|
||||
"@brief Returns the concatenated transformation\n"
|
||||
"\n"
|
||||
|
|
@ -813,7 +967,7 @@ static F cplxtrans_to_dcplxtrans (const I *t, double dbu)
|
|||
}
|
||||
|
||||
Class<db::DCplxTrans> decl_DCplxTrans ("DCplxTrans",
|
||||
constructor ("new", &cplxtrans_from_cplxtrans<db::DCplxTrans, db::CplxTrans>, gsi::arg ("trans"),
|
||||
constructor ("new|#from_itrans", &cplxtrans_from_cplxtrans<db::DCplxTrans, db::CplxTrans>, gsi::arg ("trans"),
|
||||
"@brief Creates a floating-point coordinate transformation from another coordinate flavour\n"
|
||||
"\n"
|
||||
"This constructor has been introduced in version 0.25 and replaces the previous static method 'from_itrans'."
|
||||
|
|
@ -893,7 +1047,7 @@ Class<db::DCplxTrans> decl_DCplxTrans ("DCplxTrans",
|
|||
);
|
||||
|
||||
Class<db::CplxTrans> decl_CplxTrans ("CplxTrans",
|
||||
constructor ("new", &cplxtrans_from_cplxtrans<db::CplxTrans, db::DCplxTrans>, gsi::arg ("trans"),
|
||||
constructor ("new|#from_dtrans", &cplxtrans_from_cplxtrans<db::CplxTrans, db::DCplxTrans>, gsi::arg ("trans"),
|
||||
"@brief Creates a floating-point coordinate transformation from another coordinate flavour\n"
|
||||
"\n"
|
||||
"This constructor has been introduced in version 0.25 and replaces the previous static method 'from_dtrans'."
|
||||
|
|
@ -985,12 +1139,12 @@ Class<db::CplxTrans> decl_CplxTrans ("CplxTrans",
|
|||
);
|
||||
|
||||
Class<db::ICplxTrans> decl_ICplxTrans ("ICplxTrans",
|
||||
constructor ("new", &cplxtrans_from_cplxtrans<db::ICplxTrans, db::DCplxTrans>, gsi::arg ("trans"),
|
||||
constructor ("new|#from_dtrans", &cplxtrans_from_cplxtrans<db::ICplxTrans, db::DCplxTrans>, gsi::arg ("trans"),
|
||||
"@brief Creates a floating-point coordinate transformation from another coordinate flavour\n"
|
||||
"\n"
|
||||
"This constructor has been introduced in version 0.25 and replaces the previous static method 'from_dtrans'."
|
||||
) +
|
||||
constructor ("new", &cplxtrans_from_cplxtrans<db::ICplxTrans, db::CplxTrans>, gsi::arg ("trans"),
|
||||
constructor ("new|#from_trans", &cplxtrans_from_cplxtrans<db::ICplxTrans, db::CplxTrans>, gsi::arg ("trans"),
|
||||
"@brief Creates a floating-point coordinate transformation from another coordinate flavour\n"
|
||||
"\n"
|
||||
"This constructor has been introduced in version 0.25 and replaces the previous static method 'from_trans'."
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ class DBTrans_TestClass < TestBase
|
|||
c = RBA::DTrans::new( 3, true, RBA::DPoint::new( 17, 5 ))
|
||||
d = RBA::DTrans::new( RBA::DPoint::new( 17, 5 ))
|
||||
e = RBA::DTrans::new( RBA::DTrans::M135 )
|
||||
e2 = RBA::DTrans::from_itrans( RBA::Trans::M135 )
|
||||
f = RBA::DTrans::new( RBA::Trans::new( RBA::Trans::M135, RBA::Point::new( 17, 5 )) )
|
||||
|
||||
assert_equal( a.to_s, "r0 0,0" )
|
||||
|
|
@ -21,6 +22,7 @@ class DBTrans_TestClass < TestBase
|
|||
assert_equal( c.to_s, "m135 17,5" )
|
||||
assert_equal( d.to_s, "r0 17,5" )
|
||||
assert_equal( e.to_s, "m135 0,0" )
|
||||
assert_equal( e2.to_s, "m135 0,0" )
|
||||
assert_equal( f.to_s, "m135 17,5" )
|
||||
assert_equal( RBA::DTrans::from_s(f.to_s).to_s, f.to_s )
|
||||
|
||||
|
|
@ -56,6 +58,17 @@ class DBTrans_TestClass < TestBase
|
|||
assert_equal( RBA::Trans::new(RBA::Trans::R180, RBA::DVector::new(5,-7)).to_s, "r180 5,-7" )
|
||||
assert_equal( RBA::Trans::new(RBA::Trans::R180).to_s, "r180 0,0" )
|
||||
|
||||
assert_equal( e.trans( RBA::Edge::new(0, 1, 2, 3) ).to_s, "(-1,0;-3,-2)" )
|
||||
assert_equal( ( e * RBA::Edge::new(0, 1, 2, 3) ).to_s, "(-1,0;-3,-2)" )
|
||||
assert_equal( e.trans( RBA::Box::new(0, 1, 2, 3) ).to_s, "(-3,-2;-1,0)" )
|
||||
assert_equal( ( e * RBA::Box::new(0, 1, 2, 3) ).to_s, "(-3,-2;-1,0)" )
|
||||
assert_equal( e.trans( RBA::Text::new("text", RBA::Vector::new(0, 1)) ).to_s, "('text',m135 -1,0)" )
|
||||
assert_equal( ( e * RBA::Text::new("text", RBA::Vector::new(0, 1)) ).to_s, "('text',m135 -1,0)" )
|
||||
assert_equal( e.trans( RBA::Polygon::new( [ RBA::Point::new(0, 1), RBA::Point::new(2, -3), RBA::Point::new(4, 5) ] ) ).to_s, "(-5,-4;-1,0;3,-2)" )
|
||||
assert_equal( ( e * RBA::Polygon::new( [ RBA::Point::new(0, 1), RBA::Point::new(2, -3), RBA::Point::new(4, 5) ] ) ).to_s, "(-5,-4;-1,0;3,-2)" )
|
||||
assert_equal( e.trans( RBA::Path::new( [ RBA::Point::new(0, 1), RBA::Point::new(2, 3) ], 10 ) ).to_s, "(-1,0;-3,-2) w=10 bx=0 ex=0 r=false" )
|
||||
assert_equal( ( e * RBA::Path::new( [ RBA::Point::new(0, 1), RBA::Point::new(2, 3) ], 10 ) ).to_s, "(-1,0;-3,-2) w=10 bx=0 ex=0 r=false" )
|
||||
|
||||
end
|
||||
|
||||
# Magnification basics
|
||||
|
|
@ -104,6 +117,20 @@ class DBTrans_TestClass < TestBase
|
|||
assert_equal( c.s_trans.to_s, "m135 0,0" )
|
||||
assert_equal( c.angle, 270 )
|
||||
|
||||
assert_equal( c.trans( RBA::Edge::new(0, 1, 2, 3) ).to_s, "(-1,0;-3,-2)" )
|
||||
assert_equal( ( c * RBA::Edge::new(0, 1, 2, 3) ).to_s, "(-1,0;-3,-2)" )
|
||||
assert_equal( c.trans( RBA::Box::new(0, 1, 2, 3) ).to_s, "(-3,-2;-1,0)" )
|
||||
assert_equal( ( c * RBA::Box::new(0, 1, 2, 3) ).to_s, "(-3,-2;-1,0)" )
|
||||
assert_equal( c.trans( RBA::Text::new("text", RBA::Vector::new(0, 1)) ).to_s, "('text',m135 -1,0)" )
|
||||
assert_equal( ( c * RBA::Text::new("text", RBA::Vector::new(0, 1)) ).to_s, "('text',m135 -1,0)" )
|
||||
assert_equal( c.trans( RBA::Polygon::new( [ RBA::Point::new(0, 1), RBA::Point::new(2, -3), RBA::Point::new(4, 5) ] ) ).to_s, "(-5,-4;-1,0;3,-2)" )
|
||||
assert_equal( ( c * RBA::Polygon::new( [ RBA::Point::new(0, 1), RBA::Point::new(2, -3), RBA::Point::new(4, 5) ] ) ).to_s, "(-5,-4;-1,0;3,-2)" )
|
||||
assert_equal( c.trans( RBA::Path::new( [ RBA::Point::new(0, 1), RBA::Point::new(2, 3) ], 10 ) ).to_s, "(-1,0;-3,-2) w=10 bx=0 ex=0 r=false" )
|
||||
assert_equal( ( c * RBA::Path::new( [ RBA::Point::new(0, 1), RBA::Point::new(2, 3) ], 10 ) ).to_s, "(-1,0;-3,-2) w=10 bx=0 ex=0 r=false" )
|
||||
|
||||
c = RBA::DCplxTrans::from_itrans( RBA::CplxTrans::M135 )
|
||||
assert_equal( c.to_s, "m135 *1 0,0" )
|
||||
|
||||
c = RBA::DCplxTrans::new( 1.5 )
|
||||
assert_equal( c.to_s, "r0 *1.5 0,0" )
|
||||
assert_equal( c.is_unity?, false )
|
||||
|
|
@ -153,6 +180,7 @@ class DBTrans_TestClass < TestBase
|
|||
c = RBA::Trans::new( 3, true, RBA::Point::new( 17, 5 ))
|
||||
d = RBA::Trans::new( RBA::Point::new( 17, 5 ))
|
||||
e = RBA::Trans::new( RBA::Trans::M135 )
|
||||
e2 = RBA::Trans::from_dtrans( RBA::DTrans::M135 )
|
||||
f = RBA::Trans::new( RBA::DTrans::new( RBA::DTrans::M135, RBA::DPoint::new( 17, 5 )) )
|
||||
|
||||
assert_equal( a.to_s, "r0 0,0" )
|
||||
|
|
@ -161,6 +189,7 @@ class DBTrans_TestClass < TestBase
|
|||
assert_equal( c.to_s, "m135 17,5" )
|
||||
assert_equal( d.to_s, "r0 17,5" )
|
||||
assert_equal( e.to_s, "m135 0,0" )
|
||||
assert_equal( e2.to_s, "m135 0,0" )
|
||||
assert_equal( f.to_s, "m135 17,5" )
|
||||
assert_equal( RBA::Trans::from_s(f.to_s).to_s, f.to_s )
|
||||
|
||||
|
|
@ -190,6 +219,17 @@ class DBTrans_TestClass < TestBase
|
|||
c.mirror = true
|
||||
assert_equal( c.to_s, "m135 1,7" )
|
||||
|
||||
assert_equal( e.trans( RBA::Edge::new(0, 1, 2, 3) ).to_s, "(-1,0;-3,-2)" )
|
||||
assert_equal( ( e * RBA::Edge::new(0, 1, 2, 3) ).to_s, "(-1,0;-3,-2)" )
|
||||
assert_equal( e.trans( RBA::Box::new(0, 1, 2, 3) ).to_s, "(-3,-2;-1,0)" )
|
||||
assert_equal( ( e * RBA::Box::new(0, 1, 2, 3) ).to_s, "(-3,-2;-1,0)" )
|
||||
assert_equal( e.trans( RBA::Text::new("text", RBA::Vector::new(0, 1)) ).to_s, "('text',m135 -1,0)" )
|
||||
assert_equal( ( e * RBA::Text::new("text", RBA::Vector::new(0, 1)) ).to_s, "('text',m135 -1,0)" )
|
||||
assert_equal( e.trans( RBA::Polygon::new( [ RBA::Point::new(0, 1), RBA::Point::new(2, -3), RBA::Point::new(4, 5) ] ) ).to_s, "(-5,-4;-1,0;3,-2)" )
|
||||
assert_equal( ( e * RBA::Polygon::new( [ RBA::Point::new(0, 1), RBA::Point::new(2, -3), RBA::Point::new(4, 5) ] ) ).to_s, "(-5,-4;-1,0;3,-2)" )
|
||||
assert_equal( e.trans( RBA::Path::new( [ RBA::Point::new(0, 1), RBA::Point::new(2, 3) ], 10 ) ).to_s, "(-1,0;-3,-2) w=10 bx=0 ex=0 r=false" )
|
||||
assert_equal( ( e * RBA::Path::new( [ RBA::Point::new(0, 1), RBA::Point::new(2, 3) ], 10 ) ).to_s, "(-1,0;-3,-2) w=10 bx=0 ex=0 r=false" )
|
||||
|
||||
end
|
||||
|
||||
# Complex transformation basics
|
||||
|
|
@ -241,6 +281,9 @@ class DBTrans_TestClass < TestBase
|
|||
assert_equal( c.s_trans.to_s, "m135 0,0" )
|
||||
assert_equal( c.angle, 270 )
|
||||
|
||||
c = RBA::CplxTrans::from_dtrans( RBA::DCplxTrans::M135 )
|
||||
assert_equal( c.to_s, "m135 *1 0,0" )
|
||||
|
||||
c = RBA::CplxTrans::new( 1.5 )
|
||||
assert_equal( c.to_s, "r0 *1.5 0,0" )
|
||||
assert_equal( c.is_unity?, false )
|
||||
|
|
@ -322,6 +365,11 @@ class DBTrans_TestClass < TestBase
|
|||
assert_equal( RBA::ICplxTrans::new(RBA::ICplxTrans::R180, 1.5, RBA::DVector::new(5,-7)).to_s, "r180 *1.5 5,-7" )
|
||||
assert_equal( RBA::ICplxTrans::new(RBA::ICplxTrans::R180, 1.5).to_s, "r180 *1.5 0,0" )
|
||||
|
||||
c = RBA::ICplxTrans::from_dtrans( RBA::DCplxTrans::M135 )
|
||||
assert_equal( c.to_s, "m135 *1 0,0" )
|
||||
c = RBA::ICplxTrans::from_trans( RBA::CplxTrans::M135 )
|
||||
assert_equal( c.to_s, "m135 *1 0,0" )
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue