Created
January 31, 2013 22:24
-
-
Save Talleyran/4687207 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require "./lib/conf" | |
require "./lib/ingeo_func" | |
(ARGV.size-1).times do|i| | |
if ARGV[i]=="-L" || ARGV[i]=="--layer" | |
@layer_id = ARGV[i+1] | |
end | |
if ARGV[i]=="-P" || ARGV[i]=="--step" | |
@step = ARGV[i+1].to_f | |
end | |
end | |
def com_contour_vertexs_with_add_params contour | |
prev_vertex=nil | |
com_contour_vertexs( contour ).map{ |vertex| | |
output_vertex=vertex.clone | |
if !prev_vertex.nil? && vertex.last!=0.0 | |
alpha = 2 * arctg( vertex.last ) | |
beta = radian( 90 ) - alpha | |
horda = ( ( vertex[1] - prev_vertex[1] )**2 + ( vertex[2] - prev_vertex[2] )**2 )**0.5 | |
r = horda/Math::cos( beta )/2 | |
cx,cy,l = cx_cy_l prev_vertex, vertex, r | |
hvx = ( vertex[1] - prev_vertex[1] )/l | |
hvy = ( vertex[2] - prev_vertex[2] )/l | |
output_vertex<<r | |
output_vertex<<cx | |
output_vertex<<cy | |
output_vertex<<hvx | |
output_vertex<<hvy | |
output_vertex<<alpha | |
end | |
prev_vertex = vertex | |
# p output_vertex | |
output_vertex | |
} | |
end | |
def cx_cy_l prev_vertex, vertex, r | |
x1 = prev_vertex[1] | |
y1 = prev_vertex[2] | |
x2 = vertex[1] | |
y2 = vertex[2] | |
x = ( x1+x2 ) / 2 | |
y = ( y1+y2 ) / 2 | |
l=( ( x1-x2 )**2+( y1-y2 )**2 )**0.5 | |
h = ( r**2-l**2 / 4 )**0.5 | |
ox1 = x + h*(y1-y2)/l | |
oy1 = y + h*(x2-x1)/l | |
ox2 = x - h*(y1-y2)/l | |
oy2 = y - h*(x2-x1)/l | |
if ( vertex[3] < 0 && vertex[3] > -1 ) || ( vertex[3] > 1 ) | |
[ox2,oy2,l] | |
else | |
[ox1,oy1,l] | |
end | |
end | |
def smart_step vertex, s | |
r = vertex[4] | |
alpha = vertex[9] | |
c = 2*r*alpha | |
pieces = ( c/s ).to_i | |
sp = 2 * alpha / pieces | |
# p sp,pieces+1 | |
[ sp, pieces ] | |
end | |
def break_arch_by_piece vertex, s =1 | |
new_vertexs = [] | |
unless vertex[4].nil? | |
r = vertex[4] | |
hvx = vertex[7] | |
hvy = vertex[8] | |
vvx = - hvy | |
vvy = hvx | |
cx = vertex[5] | |
cy = vertex[6] | |
alpha = vertex[9] | |
c=2*r*alpha | |
else | |
c=0 | |
end | |
unless c<@step | |
step,t = smart_step vertex, s | |
t.times{|j| | |
i = j+1 | |
new_vertexs << [ | |
cx + r * ( vvx * Math::cos(step*i-alpha+Math::PI) - vvy * Math::sin(step*i-alpha+Math::PI) ), | |
cy + r * ( vvy * Math::cos(step*i-alpha+Math::PI) + vvx * Math::sin(step*i-alpha+Math::PI) ) | |
] | |
} | |
else | |
new_vertexs << [ vertex[1], vertex[2] ] | |
end | |
new_vertexs | |
end | |
com_objects_by_layer_id(@layer_id).each{|com_object| | |
com_object_com_shapes(com_object).each{|com_shape| | |
all_new_contour_paths = [] | |
com_shape_com_contours(com_shape).each{|contour| | |
new_contour_path_vertexs = [] | |
com_contour_vertexs_with_add_params( contour ).each{|vertex| | |
new_contour_path_vertexs += break_arch_by_piece vertex, @step | |
} | |
all_new_contour_paths << [new_contour_path_vertexs, contour.Closed] | |
contour.Clear | |
} | |
all_new_contour_paths.each{|contour_path_vertex,closed| | |
new_counter_path = com_shape.Contour.Insert -1 | |
new_counter_path.Closed = closed | |
contour_path_vertex.each{|x,y| | |
new_counter_path.InsertVertex( -1, x, y, 0) | |
} | |
} | |
} | |
com_object.MapObjects.UpdateChanges | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment