XSection - negative rounding radius leads to missing structures

edited April 2016 in Ruby Scripting

Hi,

I started to use the XSection script recently and I am very impressed with the results (https://sourceforge.net/projects/xsectionklayout/).

The only problem I have is that if I specify a negative rounding radius and the deposited sturcture is smaller than twice this radius it will not show up at all in the final cross section. I looked through the source code of XSection.rbm and found this code segment, which probably is resposible:

Starting at line 475 (see arrows):

if taper
  d = @ep.size_to_polygon(d, xyi, zi, 0, true, true)
elsif xyi <= 0
  d = @ep.size_to_polygon(d, 0, zi, 2, true, true)
elsif mode == :round
  # emulate "rounding" of corners by performing soft-edged sizes
  d = @ep.size_to_polygon(d, xyi / 3, zi / 3, 1, true, true)                        <------------------
  d = @ep.size_to_polygon(d, xyi / 3, zi / 3, 0, true, true)                        <------------------
  d = @ep.size_to_polygon(d, xyi - 2 * (xyi / 3), zi - 2 * (zi / 3), 0, true, true) <------------------
elsif mode == :square
  d = @ep.size_to_polygon(d, xyi, zi, 2, true, true)
elsif mode == :octagon
  d = @ep.size_to_polygon(d, xyi, zi, 1, true, true)
end

I am not experienced with ruby so it is quite hard for me to add a correction.

Is there a way to either

  1. automatically reduce the negative radius until the source code works again or
  2. create a cross section with two intersecting circles which in total are just a rounded structure with reduced height.

Thanks for any help,
Luis

Comments

  • edited November -1

    Hi Luis,

    thanks for your feedback :-)

    I am aware of the limitations you described. Unfortunately that is cannot be avoided with the approach that XSection pursues. The problem is that "growing" is basically just supported outward. Negative values for the radius means "soften" edges but that is implemented by first reducing the structure and then growing outwards. When the structure is too small it is reduced to "nothing" with the effect you observe.

    An enhanced implementation which avoids this has to use a different approach. Like starting with a "hard" edge and then softening. For "softening" there basically is Polygon#round_corners, but I have not tried this approach myself.

    Matthias

  • edited December 2016

    Hello,

    I finally was able to ensure that all structures are always visible. Now the requested rounding radius is decreased, so no structures vanish.

    The following source code changes need to be made just before the code I quoted above:

    pi = (prebias / @xs.dbu + 0.5).floor.to_i
    xyi = (xy / @xs.dbu + 0.5).floor.to_i
    zi = (z / @xs.dbu + 0.5).floor.to_i - offset
    
    if pi < 0
      d = @ep.size_to_polygon(d, -pi, 0, 2, true, true)
    elsif pi > 0
    
      dd = []
    
      # check if rounding of all structures is possible, if not reduce rounding radius and prebias
      d.each do |p|
        box = p.bbox
        if box.width <= 2 * pi
          pi = (box.width / 2.0).floor.to_i - 1
          xyi = pi
        end
      end
    
      # apply a positive prebias by filtering with a sized box
      d.each do |p|
        box = p.bbox
        if box.width > 2 * pi
          box = RBA::Box.new(box.left + pi, box.bottom, box.right - pi, box.top)
          @ep.boolean_to_polygon([ RBA::Polygon.new(box) ], [p], RBA::EdgeProcessor::mode_and, true, true).each { |pp| dd.push(pp) }
        end
      end
      d = dd
    end
    

    Hope this helps others. Is there a way to upload the changed file to the forum?

    Luis

  • edited November -1

    Hi Luis,

    the project on SourceForge is under SVN. You can send a patch and I will submit it.

    Or it's time to move to GitHub with that project ...

    Matthias

  • Hello,

    I have adapted the above mentioned changes to the most recent version and created a pull request on GitHub:

    https://github.com/klayoutmatthias/xsection/pull/7

    Luis

Sign In or Register to comment.