!if manual # 1 then
	!epsilon
	eps = 0.001
	
	!length of reference line
	!------------------------	
	
		ref_length = sqr((ac_ref_coords[1][3]-ac_ref_coords[1][1])^2+(ac_ref_coords[1][4]-ac_ref_coords[1][2])^2)
			
		orient = (ac_ref_coords[1][3]-ac_ref_coords[1][1])

		if orient < 0 then
			orient = -1
		else
			orient = 1
		endif
		
		roof_angle = orient*ac_pitch
		
	!------------------------
	!number of points
	!----------------
	
	nr_points = vardim1(ac_coords)
	
	!----------------
	!get roof points without the holes
	!if ac_coords[1][] = 2", end of roof outline, the rest are the holes
	!-------------------------------------------------------------------
	
	found = 0
	dim new_ac_coords[][]
	
	for t = 1 to nr_points
		if found = 0 then
			if ac_coords[t][1] < 2" then
				new_ac_coords[t][1] = ac_coords[t][2] !x coordinate
				new_ac_coords[t][2] = ac_coords[t][3] !y coordinate
			else
				found = 1
			endif
		else
		endif
	next t
	
	!-------------------------------------------------------------------
	!find the lower edge points of the roof
	!also get the real pairs
	!-------------------------------------------------------------------
	
	!relative origo based on the ac_ref_height and the ac_pitch
	
	!print str("%.16ffi", rel_origo)
	
	new_nr_points = vardim1(new_ac_coords)
	
	for t = 1 to new_nr_points 		
				temp_h = new_ac_coords[t][2]*(tan(ac_pitch))
	
				new_ac_coords[t][3] = ac_ref_height+temp_h+ac_thickness
				put new_ac_coords[t][3]
	next t
	
	lowest_point = min(get(nsp))
	
	dim edge_pattern[]
	dim edge_index[]
	dim low_ac_coords[][]
	dim angles[][]
	dim pair_coords[][] ![1] 1st x, [2] 1st y, [3] 1st z, [4] 2nd x, [5] 2nd y, [6] 2nd z
	_t = 1
	n = 1
	
	for t = 1 to new_nr_points 		
		if (lowest_point-eps < new_ac_coords[t][3]) and (lowest_point+eps > new_ac_coords[t][3]) then
			edge_pattern[t] = 1
			edge_index[_t] = t
			put edge_index[_t]
			low_ac_coords[_t][1] = new_ac_coords[t][1]
			low_ac_coords[_t][2] = new_ac_coords[t][2]
			low_ac_coords[_t][3] = new_ac_coords[t][3]
			_t = _t+1
		else
			edge_pattern[t] = 0
		endif
	next t
	
	starter = min(get(nsp))
	
	for i = starter to vardim1(edge_pattern)
		if edge_pattern[i] = 1 then
			if i+1 <= vardim1(edge_pattern) then	
				if edge_pattern[i]+edge_pattern[i+1] > 1 then
					pair_coords[n][1] = new_ac_coords[i][1]
					pair_coords[n][2] = new_ac_coords[i][2]
					pair_coords[n][3] = new_ac_coords[i][3]
					pair_coords[n][4] = new_ac_coords[i+1][1]
					pair_coords[n][5] = new_ac_coords[i+1][2]
					pair_coords[n][6] = new_ac_coords[i+1][3]
					pair_coords[n][7] = i
					pair_coords[n][8] = i+1
				
					n = n+1
					i = i+2
		
				endif
				if edge_pattern[i]+edge_pattern[i+1] < 2 then
					!no pair
				endif
			endif
	
			if i-1 >= starter then
				if edge_pattern[i]+edge_pattern[i-1] > 1 then
					pair_coords[n][1] = new_ac_coords[i][1]
					pair_coords[n][2] = new_ac_coords[i][2]
					pair_coords[n][3] = new_ac_coords[i][3]
					pair_coords[n][4] = new_ac_coords[i-1][1]
					pair_coords[n][5] = new_ac_coords[i-1][2]
					pair_coords[n][6] = new_ac_coords[i-1][3]

					pair_coords[n][7] = i
					pair_coords[n][8] = i-1

					n = n+1
					i = i+2
				endif
				if edge_pattern[i]+edge_pattern[i-1] < 2 then
					!no pair
				endif
			endif
		else
		endif
	next i
	
	! check maybe first and last is pair
	
	if starter = 1 then
		if edge_pattern[starter]+edge_pattern[vardim1(edge_pattern)] > 1 then
						pair_coords[n][1] = new_ac_coords[starter][1]
						pair_coords[n][2] = new_ac_coords[starter][2]
						pair_coords[n][3] = new_ac_coords[starter][3]
						pair_coords[n][4] = new_ac_coords[vardim1(edge_pattern)][1]
						pair_coords[n][5] = new_ac_coords[vardim1(edge_pattern)][2]
						pair_coords[n][6] = new_ac_coords[vardim1(edge_pattern)][3]
	
						pair_coords[n][7] = starter
						pair_coords[n][8] = vardim1(edge_pattern)
	
		endif
		
		if edge_pattern[starter]+edge_pattern[vardim1(edge_pattern)] < 2 then
						!no pair
		endif
	else
	endif

	for i = 1 to vardim1(pair_coords)
		if pair_coords[i][7] + 1 # pair_coords[i][8] then

				x1 = new_ac_coords[pair_coords[i][8]-1][1]-new_ac_coords[pair_coords[i][8]][1]
				y1 = new_ac_coords[pair_coords[i][8]-1][2]-new_ac_coords[pair_coords[i][8]][2]
				
				if (x1 > - eps and x1 < eps) or (y1 > - eps and y1 < eps) then
					angles[i][2] = 90
	
				else
					angles[i][2] = atn(y1/x1)
				endif
		
				if angles[i][2] < 0 then
					angles[i][2] = 180+angles[i][2]
				endif

				x1 = new_ac_coords[pair_coords[i][7]+1][1]-new_ac_coords[pair_coords[i][7]][1]
				y1 = new_ac_coords[pair_coords[i][7]+1][2]-new_ac_coords[pair_coords[i][7]][2]
				
				if (x1 > - eps and x1 < eps) or (y1 > - eps and y1 < eps) then
					angles[i][1] = 90
	
				else
					angles[i][1] = atn(y1/x1)
				endif
		
				if angles[i][1] < 0 then
					angles[i][1] = 180+angles[i][1]
				endif
		else
			if pair_coords[i][7] < 2 then
				x1 = new_ac_coords[vardim1(new_ac_coords)][1]-new_ac_coords[pair_coords[i][7]][1]
				y1 = new_ac_coords[vardim1(new_ac_coords)][2]-new_ac_coords[pair_coords[i][7]][2]
				
				if (x1 > - eps and x1 < eps) or (y1 > - eps and y1 < eps) then
					angles[i][1] = 90
	
				else
					angles[i][1] = atn(y1/x1)
				endif
		
				if angles[i][1] < 0 then
					angles[i][1] = 180+angles[i][1]
				endif
			else
				x1 = new_ac_coords[pair_coords[i][7]-1][1]-new_ac_coords[pair_coords[i][7]][1]
				y1 = new_ac_coords[pair_coords[i][7]-1][2]-new_ac_coords[pair_coords[i][7]][2]
				
				if (x1 > - eps and x1 < eps) or (y1 > - eps and y1 < eps) then
					angles[i][1] = 90
	
				else
					angles[i][1] = atn(y1/x1)
				endif
		
				if angles[i][1] < 0 then
					angles[i][1] = 180+angles[i][1]
				endif
			endif

		!-----------------------------------------------------------------------------

			if pair_coords[i][8]+1 > vardim1(new_ac_coords) then
				x1 = new_ac_coords[1][1]-new_ac_coords[pair_coords[i][8]][1]
				y1 = new_ac_coords[1][2]-new_ac_coords[pair_coords[i][8]][2]
				
				if (x1 > - eps and x1 < eps) or (y1 > - eps and y1 < eps) then
					angles[i][2] = 90
	
				else
					angles[i][2] = atn(y1/x1)
				endif
		
				if angles[i][2] < 0 then
					angles[i][2] = 180+angles[i][2]
				endif
			else
				x1 = new_ac_coords[pair_coords[i][8]+1][1]-new_ac_coords[pair_coords[i][8]][1]
				y1 = new_ac_coords[pair_coords[i][8]+1][2]-new_ac_coords[pair_coords[i][8]][2]
				
				if (x1 > - eps and x1 < eps) or (y1 > - eps and y1 < eps) then
					angles[i][2] = 90
	
				else
					angles[i][2] = atn(y1/x1)
				endif
		
				if angles[i][2] < 0 then
					angles[i][2] = 180+angles[i][2]
				endif
			endif 
		endif

	next i
	
	nr_low_ac_coords = vardim1(low_ac_coords)
!endif
