# Polygon problem

edited October 2013
Hi Matthias,

First of I'd like to say thanks for sharing and supporting an amazing piece of software.

I'm having a bit of a problem, and I'm not sure what I'm missing. When I try to generate a polygon from an equation, I end up missing some points.

Observations:
1) I can't see a pattern to what points are missing (seems random).
2) If I change the polygon to a path, all the points appear to be there
3) If I copy the data generated from the code into a polygon directly, the polygon contains all the points.

Any suggestions would be appreciated.

Thanks

Here is some sample code illustrating the problem:

#!/usr/bin/env ruby

module MyMacro

include RBA

begin
# Enter your Ruby code here ..

main_window = RBA::Application::instance.main_window
ly = main_window.create_layout(1).layout
layout_view = main_window.current_view

layerB=RBA::LayerInfo::new(202,0,"layer")
lyrB = ly.insert_layer( layerB )

a=2.0
len=400.0

a_s=(a/ly.dbu)
len_s=(len/ly.dbu)

pts = []
pts.push(Point.from_dpoint(DPoint.new(0,-10.0/ly.dbu)))

n=1000
dx=len_s/n.to_f

n.times do |i|
pts.push(Point.from_dpoint(DPoint.new( ((i+1)*dx.to_f), (a_s*Math::sin(2*Math::PI*i*dx/len_s)) )))
printf("%s %s \n", ((i+1)*dx).to_i,(a_s*Math::sin(2*Math::PI*i*dx/len_s)).to_i )

end

pts.push(Point.from_dpoint(DPoint.new(len_s,-10.0/ly.dbu)))

# create the shape
ly.cell(cCell_cell).shapes(lyrB).insert(Polygon.new(pts))
ly.cell(cCell_cell).shapes(lyrB).insert(Path.new(pts,0.5/ly.dbu))

end
end

• edited November -1

Hello,

thank you :-)

Regarding your problem with the polygon - that is intentional. Polygon points are compressed - collinear points are removed because they don't add information to the polygon.

The reason for that is compaction. If after the removal of points the polygon is manhattan, it can be stored in half the memory because x and y coordinates are arranged in redundant pairs then.

You don't have manhattan polygons, but points may be removed nevertheless if they are on the line connecting it's neighbors within +/- half a database unit.

Is there a reason you want to keep these points? It is possible to add an option to the polygon constructor for keeping the original points, but so far nobody asked for that.

Matthias

• edited November -1
Hi Matthias,

I've had a closer look at the data, and that does appear to be what is happening. Thanks for the explanation.

No, I don't have a reason to keep the extra points.

Regards.