Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Trans API differences between 0.24.10 and 0.25.8

Hi Matthias, we're in the process of migrating our existing Ruby scripts to the latest KLayout version.

I just came across something that I didn't expect and wanted to check with you whether that's intentional or a bug:

RBA::Trans.new(1000,6610).trans(RBA::Trans.new(780,-3670).disp)
  • In 0.24.10, this returns an RBA::Point at 1780,2940
  • In 0.25.8, this returns an RBA::Vector of 780,-3670

While I don't care so much about the type of the resulting object, I would've expected the resulting coordinates to be the same.

Reading the API documentation, I realise Trans.disp was changed to return a Vector instead of a Point and also support for Vector inputs was added to the Trans.trans method.

I find the 0.25.8 result particularly puzzling as it appears to be simply (a copy of?) the 2nd Trans instance at 780,-3670.

Ideally, I'd like the scripts to be compatible with both KLayout versions, is there an alternative way to code what version 0.24.10 does, so it works the same in 0.25.8?

Comments

  • edited May 10

    Hi,

    I see I need to explain the concept here. The main difference between 0.25.x and 0.24.10 was a cleaner type system of geometrical primitive types.

    One concept is that of vector vs. point (see https://www.klayout.de/doc-qt4/programming/geometry_api.html#h2-43 ).

    In short, a point in an absolute location in 2d cartesian space and a vector connects two points. So:

    • point - point -> vector
    • point + vector -> point
    • vector + vector -> vector

    A major difference between points and vectors is the transformation behaviour:

    • T * point -> R * point + d (R: rotation matrix, d: displacement)
    • T * vector -> R * vector (no displacement)

    The reasoning is that with this definition the following intuitive equivalence is true:

    • T * (point - point) = T * point - T * point

    because the displacements cancel.

    As the "disp" part of the transformation is a vector, it will behave differently with 0.25 than with 0.24.

    These are ways to achieve your desired behaviour in a portable way:

    RBA::Trans.new(1000,6610).trans(RBA::Point::new + RBA::Trans.new(780,-3670).disp)
    (RBA::Trans.new(1000,6610) * RBA::Trans.new(780,-3670)).disp
    RBA::Trans.new(1000,6610).trans(RBA::Trans.new(780,-3670) * RBA::Point::new)
    

    Matthias

  • Hi Matthias, thanks for the explanation and the documentation link. The following section cleared up my question about why the vector in my example wasn't transformed:

    Vectors don't transform the same way than points. On transformation, only rotation, mirror and scaling (if applicable) is applied. Displacement is not applied.

    Also thanks for the code examples. To keep my scripts as close to the original as possible, I used the following variant:

    RBA::Trans.new(1000,6610).trans(RBA::Point::new(780,-3670))
    

    This actually simplified the original code and made the intention more clear. Great!

    Christian

Sign In or Register to comment.