GithubHelp home page GithubHelp logo

Comments (1)

fp-matt avatar fp-matt commented on September 26, 2024

I spent some time today combing through path.py and marked what I have found to be the lines causing the issue:

@cell
def extrude(
    p: Path,
    cross_section: CrossSectionSpec | None = None,
    layer: LayerSpec | None = None,
    width: float | None = None,
    simplify: float | None = None,
    shear_angle_start: float | None = None,
    shear_angle_end: float | None = None,
    allow_offgrid: bool | None = None,
    snap_to_grid: bool = False,
    add_bbox: bool = True,
) -> Component:
    
    #  Skipping lines

        if section.insets and section.insets != (0, 0):
            p_pts = p_sec.points

            new_x_start = p.xmin + section.insets[0]
            new_x_stop = p.xmax - section.insets[1]

            if new_x_start > np.max(p_pts[:, 0]) or new_x_stop < np.min(p_pts[:, 0]):
                warnings.warn(
                    f"Cannot apply delay to Section '{section.name}', delay results in points outside of original path.",
                    stacklevel=3,
                )
                continue

            new_start_idx = np.argwhere(p_pts[:, 0] > new_x_start)[0, 0]              # <---
            new_stop_idx = np.argwhere(p_pts[:, 0] < new_x_stop)[-1, 0]             # <---

            new_start_point = [new_x_start, p_pts[new_start_idx, 1]]
            new_stop_point = [new_x_stop, p_pts[new_stop_idx, 1]]

            p_sec = Path(
                [new_start_point, *p_pts[new_start_idx:new_stop_idx], new_stop_point]  # <---
            )
    #  Skipping Lines

From what I understand, the problem I ran into is being caused by the fact that the path ends in a non-horizontal straight.
So, when it finds new_stop_idx,

            new_stop_idx = np.argwhere(p_pts[:, 0] < new_x_stop)[-1, 0]

the index of the first x-position that is less than new_x_stop is all the way back at the end of the bend, so gf.path.extrude() then tries to draw the last point at the same y-position as the second to last point.

An additional (potential) problem I noticed is that the insets are applied solely along the x-axis. This means that even if the specific issue of the new inset points being drawn horizontally is fixed, the inset amount may still be more than expected if the start or end of the path is angled. I am relatively new to layout and GDSFactory, so I don't know if the convention for inset amounts is normally to apply it across a single axis, but if it isn't, I believe having the inset amount relative to the overall path length would be more intuitive for the user.

My proposed methodology is to:

  1. Find the difference array of the path (each (x, y) pair can then be treated as a vector describing each segment of the path)

  2. Calculate the norm of each vector in the difference array to find each segment length

  3. Find where the inset value is less than or equal to the cumulative sum of the normed difference array or reversed normed difference array in the case of the end inset (similar to existing method except index would now be relative to the path length)

  4. Get the vectors that correspond to the path segments the insets overlap with along the path

  5. Find the unit vectors of the vectors found in step 4

  6. Calculate the difference between the start/stop inset values and the path length up to the indices found in step 3 and multiply by the respective unit vectors found in step 5

  7. Translate vectors back to their proper position along the original path

  8. Construct the new path array

I believe this should enable arbitrary path extrusion on any otherwise valid gf.cross-section.Section

I know that writing this out is likely not the easiest way to interpret what I mean - I just put in a PR with my suggested changes. Any suggested edits are more than welcome!

from gdsfactory.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.