Module Mesh
In: mesh.rb

Methods

Classes and Modules

Class Mesh::CubeMesh

Constants

FACEFACEMINDISTANCE = 0.1   begin faceface mesh Constant that define how close the facefaces are allowed to be. A factor of the cell density.

Public Instance methods

what do I wan to have from this? An array with faceface info: what do I wan to have from this? An array with faceface info:

  • maybe just the face numbers of the face-faces, to be filtered out later on.

The lines is easier to know which output is wanted. So maybe facefacearray = [ [[l0 vertex num],[l1 vertex num],[l2 vertex num],[l3 vertex num], [face num]] ] also vertices and celldef is given as output.

[Source]

# File mesh.rb, line 2365
   def altvertex(tmpvrt)
      tmpcount = 0
      vertalt = Array.new
      tmpvrt.each do |xarr|
         xarr.each do |vert|
            vertalt[tmpcount] = [vert.first[0],vert.last[0], 0.0]
            tmpcount += 1
         end
      end
      return vertalt
   end

[Source]

# File mesh.rb, line 2376
   def altvertex2(tmpvrt)
      vertalt = Array.new
      ilength = tmpvrt.size-1
      jlength = tmpvrt[0].size-1
      tmpcount = 0
      (0..jlength).each do |yind|
         (0..ilength).each do |xind|
            vertalt[tmpcount] = [tmpvrt[xind][yind].first[0], tmpvrt[xind][yind].last[0], 0.0]
            tmpcount += 1
         end
      end
      puts "vertcount #{tmpcount}"
      return vertalt
   end

[Source]

# File mesh.rb, line 2390
   def altvertex3(tmpvrt)
      vertalt = Array.new
      tmpcount = 0
      tmpvrt.each do |xarr|
         xarr.each do |vert|
            vertalt[tmpcount] = [vert.first[0], vert.last[0], 0.0]
            tmpcount += 1
         end
      end
      return vertalt
   end

[Source]

# File mesh.rb, line 527
   def anglesInCsys0(x,y,z)
      xang, zang = 0.0, 0.0
      if x == 0.0 && y == 0.0 && z == 0.0
         return 0.0, 0.0
      end
      # x == 0 && y >= 0 zang = 90
      # x == 0 && y < 0 zang = 270
      # z == 0 && y >= 0 xang = 90
      # z == 0 && y < 0 xang = 270
      if x > 0.0 && y > 0.0
         zang = Math::atan(y/x)*180.0/Math::PI
      elsif x < 0.0 && y
      end
      if y > 0.0 && z > 0.0
         xang = Math::atan(y/z)*180.0/Math::PI
      end
      return xang, zang
   end

an ascii representation of where the facefaces are located :-)

[Source]

# File mesh.rb, line 2340
   def asciivertex(tmpvrt,noidx)
      print "\n"
      tmpvrt.each do |xarr|
         xarr.each do |vert|
            if vert.first[1] == vert.last[1] && (vert.first[1] != noidx || vert.last[1] != noidx)
               print "x  "
            else
               print "o  "
            end
         end
         print "\n"
      end
   end

[Source]

# File mesh.rb, line 3029
   def cellnofromijk(i,j,k,imax,jmax,kmax)
??
      return k*imax*jmax + j*imax + i
   end

create cell definition

 fix vertex face info
 collect face index data

[Source]

# File mesh.rb, line 2185
   def collectinfo(vertex,noidx)
      faceinfo = Array.new
      vertex.each_with_index do |xrow,xind|
         xrow.each_with_index do |vrt,yind|
            if vrt.first[1] == vrt.last[1] && vrt.first[1] != noidx  && vrt.last[1] != noidx 
               if faceinfo[vrt.first[1]].class == NilClass
                  puts "new array for no #{vrt.first[1]}"
                  faceinfo[vrt.first[1]] = Array.new
               end
               puts "face no #{vrt.first[1]}, located #{xind}, #{yind}"
               faceinfo[vrt.first[1]].push([xind,yind])
            end
         end
      end
      return faceinfo
   end

Place Faces on Faces test if facefaces coincide. Array of facefaces in format [ faceface1, faceface2, .. ,facefaceN]. facefaceN = [ xmin, xmax, ymin, ymax ]

[Source]

# File mesh.rb, line 1198
def collide(facelist, xcelldens, ycelldens)
   xmindistance = xcelldens.to_f*FACEFACEMINDISTANCE
   ymindistance = ycelldens.to_f*FACEFACEMINDISTANCE
   collided = Array.new
   collided_idx = Array.new
   # x collide test put collided in collided array
   # compare [x1min, x2min ].max and [ x1max, x2max ].min 
   # if [x1min, x2min ].max < [ x1max, x2max ].min they collide
   facelist.each_with_index do |tmpface1, idx1|
      facelist.each_with_index do |tmpface2, idx2|
         if idx1 < idx2
            if [ tmpface1[0], tmpface2[0] ].max  <= ( [ tmpface1[1], tmpface2[1] ].min + xmindistance )
               collided.push(tmpface1)
               collided.push(tmpface2)
               collided_idx.push([idx1, idx2])
            end
         end
      end
   end
   # now its time to test the x-collided faces in the y-direction
   recollided = Array.new
   recollided_idx = Array.new
   collided_idx.each do |collidx|
      if [ facelist[collidx[0] ][2], facelist[collidx[1] ][2] ].max <= ( [ facelist[collidx[0] ][3], facelist[collidx[1] ][3] ].min + ymindistance )
         recollided.push(facelist[collidx[0] ])
         recollided.push(facelist[collidx[1] ])
         recollided_idx.push([ collidx[0], collidx[1] ])
      end
   end
   return recollided, recollided_idx
end

[Source]

# File mesh.rb, line 1705
   def collidetest(face1, face2)
      xmin1 = face1[0]
      xmax1 = face1[1]
      ymin1 = face1[2]
      ymax1 = face1[3]
      xmin2 = face2[0]
      xmax2 = face2[1]
      ymin2 = face2[2]
      ymax2 = face2[3]
      if ( xmax1 < xmin2 ) || ( xmax2 < xmin1 ) || ( ymax1 < ymin2 ) || ( ymax2 < ymin1 )
         return false
      else
         return true
      end
   end

[Source]

# File mesh.rb, line 1404
   def collidetest(face1, face2)
      imin1 = face1[0]
      imax1 = face1[1]
      jmin1 = face1[2]
      jmax1 = face1[3]
      imin2 = face2[0]
      imax2 = face2[1]
      jmin2 = face2[2]
      jmax2 = face2[3]
      if ( imax1 < imin2 ) || ( imax2 < imin1 ) || ( jmax1 < jmin2 ) || ( jmax2 < jmin1 )
         return false
      else
         return true
      end
   end

[Source]

# File mesh.rb, line 213
   def createdefline(ldef, x, y, z, parent, self1, text)
      # fill array l with LiteLines and v with InfoPoints
      # first line
      # LiteLine.new([x0,y0,z0], [x1,y1,z1], parent, (viewerobj), text)
      l = Array.new
      xdef = Array.new
      ydef = Array.new
      zdef = Array.new
      (0..ldef.size-2).each do |num|
         l[num]=LiteLine.new([x[ldef[num]], y[ldef[num]], z[ldef[num]]], [x[ldef[num+1]], y[ldef[num+1]], z[ldef[num+1]]], parent, self1, text)
      end
      (0..ldef.size-1).each do |num|
         xdef.push(x[ldef[num]])
         ydef.push(y[ldef[num]])
         zdef.push(z[ldef[num]])
      end
    
      return l, xdef, ydef, zdef
   end

not used anymore

[Source]

# File mesh.rb, line 196
   def createface(celldef, x, y, z, parent, self1, text) 
      f = Array.new
# f[0] = LiteFace.new(x[celldef[0][0]], y[celldef[0][0]], z[celldef[0][0]], x[celldef[0][1]], y[celldef[0][1]], z[celldef[0][1]], 
#                     x[celldef[0][2]], y[celldef[0][2]], z[celldef[0][2]], x[celldef[0][3]], y[celldef[0][3]], z[celldef[0][3]],
#                              parent, self1, text, celldef[0][4])
      if false  # to test new liteface
      celldef.each_with_index do |cell, num|
         f[num] = LiteFace.new(x[cell[0]], y[cell[0]], z[cell[0]], x[cell[1]], y[cell[1]], z[cell[1]], 
                               x[cell[2]], y[cell[2]], z[cell[2]], x[cell[3]], y[cell[3]], z[cell[3]],
                               parent, self1, text, cell[4])
      end
      else
      f = Array.new
      f[0] = LiteFace2.new(celldef, x, y, z, parent, self1, text)
      end
      return f
   end

now a method to create the final face and faceface mesh. This will be the inpos positions which will be coordinate system mapped.

[Source]

# File mesh.rb, line 2095
def createfacefacemesh(facelist, xnumin, ynumin, xmin, xmax, ymin, ymax)
   newxnum, newynum, newxmesh, newymesh, newnoidx = faceonfaceindex(facelist, xnumin, ynumin, xmin, xmax, ymin, ymax)
   # look for close or perfectly matched grid lines.
   # Now some grid lines might be removed. Still it is important that faces are preserved
   xmindistance = FACEFACEMINDISTANCE * 0.9 * (xmax-xmin).abs.to_f/newxnum
   ymindistance = FACEFACEMINDISTANCE * 0.9 * (ymax-ymin).abs.to_f/newynum
   # puts "xmindistance #{xmindistance}, ymindistance #{ymindistance}"
   xcount = 0
   # list of non-qualified grid line. One that lies too close to another.
   # just collect all dropped lines and then do a .uniq on [x,y]dropped array
   xdropped = Array.new
   (0..newxmesh.size-2).each do |idx|
      if newxmesh[idx+1].first - newxmesh[idx].first <= xmindistance
         xdropped.push(idx+1)
         xcount += 1
      end
   end
   ycount = 0
   ydropped = Array.new
   (0..newymesh.size-2).each do |idx|
      if newymesh[idx+1].first - newymesh[idx].first <= ymindistance
         ydropped.push(idx+1)
         ycount += 1
      end
   end
   # first do mesh without the dropped grid lines, then modify with dropped grid lines. Just modify the gridline closest.
   vertex = Array.new
   # puts "xcount #{xcount}, ycount #{ycount}"
   xind = 1
   xtmp = (0..newxmesh.size-1).to_a - xdropped
   ytmp = (0..newymesh.size-1).to_a - ydropped
   xlen = xtmp.size - 1
   ylen = ytmp.size - 1
   (0..xtmp.size-1).each do |idx|
      vertex[idx] = Array.new
   end
   tmpx = 0
   tmpy = 0
   (0..newymesh.size-1).each do |yind|
      if !ydropped.include?(yind)
         (0..newxmesh.size-1).each do |xind|
            if !xdropped.include?(xind)
               # mesh node format   [newxmesh[xind], newymesh[yind] ]
               # mesh vertex array organisation vertex[xind][yind]
               # puts "tmpx #{tmpx}, tmpy #{tmpy}"
              vertex[tmpx][tmpy] = [newxmesh[xind], newymesh[yind] ]
              tmpx +=1
            end
         end
         tmpy +=1
         tmpx = 0
      end
   end
   # this gives the correct index when there are dropped grid lines
   def testidx(index,dropped)
       # puts "testindex is #{index}"
       tmpindex = 0
      (1..index).each do |test|
         if !dropped.include?(test)
            tmpindex += 1
         end
      end
      # puts "tmpindex is #{tmpindex}"
      return tmpindex
   end
   # There are some lost faces from the previous step, here they are inserted again
   xdropped.each do |xind|
      findindex = newxmesh[xind].last
      newymesh.each_with_index do |ymsh, yidx|
         if ymsh.last == findindex
            vertex[testidx(xind,xdropped)][testidx(yidx,ydropped)] = [ newxmesh[xind],ymsh]
         end
      end
   end
   ydropped.each do |yind|
      # puts "ydropped #{yind}, newymesh #{newymesh[yind]}"
      findindex = newymesh[yind].last
      newxmesh.each_with_index do |xmsh, xidx|
         if xmsh.last == findindex
            # puts "newxmesh #{xmsh.last}, index #{xidx}"
            # puts "insert #{xmsh.first}, #{xmsh.last}, #{newymesh[yind].first}, #{newymesh[yind].last}"
            # puts "at x #{xidx}, y #{yind}"
            # puts "at x #{testidx(xidx,xdropped)}, y #{testidx(yind,ydropped)}"
            vertex[testidx(xidx,xdropped)][testidx(yind,ydropped)] = [xmsh, newymesh[yind]]
         end
      end
   end
   #create cell definition
   # fix vertex face info
   # collect face index data
   def collectinfo(vertex,noidx)
      faceinfo = Array.new
      vertex.each_with_index do |xrow,xind|
         xrow.each_with_index do |vrt,yind|
            if vrt.first[1] == vrt.last[1] && vrt.first[1] != noidx  && vrt.last[1] != noidx 
               if faceinfo[vrt.first[1]].class == NilClass
                  puts "new array for no #{vrt.first[1]}"
                  faceinfo[vrt.first[1]] = Array.new
               end
               puts "face no #{vrt.first[1]}, located #{xind}, #{yind}"
               faceinfo[vrt.first[1]].push([xind,yind])
            end
         end
      end
      return faceinfo
   end
   def printfaceinfo(faceinfo)
      puts "Face Info"
      faceinfo.each do |face|
         print "face info #{face[0].first}, #{face[0].last}, "
         print "#{face[1].first}, #{face[1].last}, "
         print "#{face[2].first}, #{face[2].last}, "
         print "#{face[3].first}, #{face[3].last}, size #{face.size}\n"
      end
   end
   faceinfo1 = collectinfo(vertex,newnoidx)
   # printfaceinfo(faceinfo1)
   # finf = face info
   # correct the face info on nodes created between start and end index of faceface
   faceinfo1.each do |finf|
      if finf[2][0] - finf[0][0] > 1
         nx = finf[2][0] - finf[0][0]
         print "correct x #{nx} at"
         idxx = (finf[0][0]+1 .. finf[2][0]-1).to_a
         idxx.each do |tmp|
            print " #{tmp},"
         end
         print "\n"
         idxx.each do |tmpx|
            # don't touch x value
            xcurr1 = finf[0][0]
            ycurr1 = finf[0][1]
            xcurr2 = finf[1][0]
            ycurr2 = finf[1][1]
            faceno1 = vertex[xcurr1][ycurr1].first[1]
            vertex[tmpx][ycurr1] = [[vertex[tmpx][ycurr1].first[0],faceno1],[vertex[xcurr1][ycurr1].last[0],faceno1]]
            vertex[tmpx][ycurr2] = [[vertex[tmpx][ycurr2].first[0],faceno1],[vertex[xcurr2][ycurr2].last[0],faceno1]]
         end
      end
      if finf[1][1] - finf[0][1] > 1
         ny = finf[1][1] - finf[0][1]
         print "correct y #{ny} at"
         idxy = (finf[0][1]+1 .. finf[1][1]-1).to_a
         idxy.each do |tmp|
            print " #{tmp},"
         end
         print "\n"
         idxy.each do |tmpy|
            # don't touch y value
            xcurr1 = finf[0][0]
            ycurr1 = finf[0][1]
            xcurr2 = finf[2][0]
            ycurr2 = finf[2][1]
            faceno1 = vertex[xcurr1][ycurr1].first[1]
            # I have to do it like this when I tried to assign with vertex[][].first[1] = ... other parts of the 
            # Array got changed in other instances!
            vertex[xcurr1][tmpy] = [[vertex[xcurr1][ycurr1].first[0],faceno1],[vertex[xcurr1][tmpy].last[0],faceno1]]
            vertex[xcurr2][tmpy] = [[vertex[xcurr2][ycurr2].first[0],faceno1],[vertex[xcurr2][tmpy].last[0],faceno1]]

            # this didn't work for me
            #vertex[finf[1][0]][tmpy].last[2] = vertex[finf[2][1]][finf[2][1]].last[2]
         end
      end
   end
   
    
   # and after that do the faceface cell definition?
   cell = Array.new
   ilength = vertex.size
   jlength = vertex[0].size
   cellno = 0
   flag=true
   (0..jlength-2).each do |yind|
      if flag
         truefalse = [true,false]
         flag = false
      else
         truefalse = [false,true]
         flag = true
      end
      (0..ilength-2).each do |xind|
         # input the face numbers
         if vertex[xind][yind].first[1] == vertex[xind][yind].last[1] &&
            vertex[xind][yind].first[1] != newnoidx && 
            vertex[xind][yind].last[1] != newnoidx
            # this is not right!
            facenum = vertex[xind][yind].first[1]
         else
            facenum = nil
         end

         cell[cellno] = [xind+ilength*yind, xind+1+ilength*yind,
                         xind+1+ilength*(1+yind),xind+ilength*(1+yind), 
                         truefalse.last,facenum]
         cell[cellno].each do |prt|
            print " #{prt} "
         end
         print "\n"
         cellno += 1
         truefalse = truefalse.reverse
      end
   end
   # create faceface line definitions
   # in format? 
   # print cell table
   def printcells(cell)
      cell.each_with_index do |cel,cellno|
         puts "cell no #{cellno} i #{cel[0]}, j #{cel[1]}, k #{cel[2]}, l #{cel[3]}, truefalse #{cel[4]}, faceno #{cel[5]}"
      end
   end
   #printcells(cell)
   puts "cell count #{cellno}"

   # printfaceinfo(faceinfo1)
   def printvertex(tmpvrt,noidx)
      print "\n"
      puts "Print Vertex method"
      tmpvrt.each_with_index do |xarr,xind|
         xarr.each_with_index do |vert,yind|
            if vert.first[1] == vert.last[1] && (vert.first[1] != noidx || vert.last[1] != noidx)
               #print "face(#{vert.first[1]})  #{vert.first[0]}, #{vert.last[0]}       "
               #print "face(#{vert.first[1]})  "
               printf("%s(%2d) ", "face",vert.first[1])
            else
               #print "vrt(#{xind},#{yind}) #{vert.first[0]}, #{vert.last[0]}  "
               #print "vrt(#{xind},#{yind}) "
               printf("v(%2d,%2d) ", xind, yind) 
            end
             printf("%1$.1f, %2$.1f  ",vert.first[0], vert.last[0])
               #sprintf("%1$d, %2$d ",vert.first[0], vert.last[0])
               #         ,vert.last[0]
         end
         print "\n"
      end
   end
   def printidx(tmpvrt,noidx)
      print "\n"
      tmpvrt.each do |xarr|
         xarr.each do |vert|
            printf("%3d, %3d  |", vert.first[1],vert.last[1])
         end
         print "\n"
      end
   end
   # an ascii representation of where the facefaces are located :-)
   def asciivertex(tmpvrt,noidx)
      print "\n"
      tmpvrt.each do |xarr|
         xarr.each do |vert|
            if vert.first[1] == vert.last[1] && (vert.first[1] != noidx || vert.last[1] != noidx)
               print "x  "
            else
               print "o  "
            end
         end
         print "\n"
      end
   end
   # vertexes within an faceface edge doesn't have the right id assigned, make a method for that
   # maybe the noidx-vertices should be renamed as well
   #printvertex(vertex, newnoidx)
   # asciivertex(vertex, newnoidx)
   #printidx(vertex, newnoidx)

   # what do I wan to have from this? An array with faceface info:
   # what do I wan to have from this? An array with faceface info:
   # - maybe just the face numbers of the face-faces, to be filtered out later on.
   # The lines is easier to know which output is wanted. 
   # So maybe facefacearray = [ [[l0 vertex num],[l1 vertex num],[l2 vertex num],[l3 vertex num], [face num]] ] 
   # also vertices and celldef is given as output.
   def altvertex(tmpvrt)
      tmpcount = 0
      vertalt = Array.new
      tmpvrt.each do |xarr|
         xarr.each do |vert|
            vertalt[tmpcount] = [vert.first[0],vert.last[0], 0.0]
            tmpcount += 1
         end
      end
      return vertalt
   end
   def altvertex2(tmpvrt)
      vertalt = Array.new
      ilength = tmpvrt.size-1
      jlength = tmpvrt[0].size-1
      tmpcount = 0
      (0..jlength).each do |yind|
         (0..ilength).each do |xind|
            vertalt[tmpcount] = [tmpvrt[xind][yind].first[0], tmpvrt[xind][yind].last[0], 0.0]
            tmpcount += 1
         end
      end
      puts "vertcount #{tmpcount}"
      return vertalt
   end
   def altvertex3(tmpvrt)
      vertalt = Array.new
      tmpcount = 0
      tmpvrt.each do |xarr|
         xarr.each do |vert|
            vertalt[tmpcount] = [vert.first[0], vert.last[0], 0.0]
            tmpcount += 1
         end
      end
      return vertalt
   end
   def ldef(vertex)
      l0seg = Array.new
      l1seg = Array.new
      l2seg = Array.new
      l3seg = Array.new
      # from celldef ??
      # test in a irb session
      ilength = vertex.length
      jlength = vertex[0].length
      alot = ilength*(jlength-1)
      (0..ilength-2).each do |xind|
         l0seg.push([xind,xind+1])
         l2seg.push([xind+alot+1,xind+alot])
      end
      l2seg = l2seg.reverse
      (0..jlength*ilength-ilength-1).step(ilength) do |yind|
         l1seg.push([yind+ilength-1, yind+2*ilength-1])
         l3seg.push([yind+ilength, yind])
      end
      l3seg = l3seg.reverse
      return l0seg, l1seg, l2seg, l3seg
   end
   l0, l1, l2, l3 = ldef(vertex)


# get the vertex number when i,j position and ilength is known
def xy2vertno(x,y,ilength)
   return y*ilength +x
end
# faceinfo = [[[1,1],[1,3],[2,1],[2,3]]]
# create the line definitions for the facefaces
def createl0l1l2l3(faceinfoin,ilen)
   allines = Array.new
   faceinfoin.each do |faceinfo|
      l0tmp = Array.new
      l1tmp = Array.new
      l2tmp = Array.new
      l3tmp = Array.new
      (faceinfo[0][0]..faceinfo[2][0]).each do |xdir|
         vert1 = xy2vertno(xdir,faceinfo[0][1],ilen)
         l0tmp.push(vert1)
      end

      (faceinfo[2][1]..faceinfo[3][1]).each do |ydir|
         vert1 = xy2vertno(faceinfo[2][0],ydir,ilen)
         l1tmp.push(vert1)
      end

      (faceinfo[1][0]..faceinfo[3][0]).to_a.reverse.each do |xdir|
        vert1 = xy2vertno(xdir,faceinfo[3][1],ilen)
         l2tmp.push(vert1)
      end

      (faceinfo[0][1]..faceinfo[1][1]).to_a.reverse.each do |ydir|
         vert1 = xy2vertno(faceinfo[1][0],ydir,ilen)
         l3tmp.push(vert1)
      end
      def makedef(lXtmp)
         ltmp = Array.new
         (0..lXtmp.size-2).each do |slice1|
            ltmp.push(lXtmp[(slice1)..(slice1+1)])
         end
         return ltmp
      end
      l0tmp = makedef(l0tmp)
      l1tmp = makedef(l1tmp)
      l2tmp = makedef(l2tmp)
      l3tmp = makedef(l3tmp)
      allines.push([l0tmp,l1tmp,l2tmp,l3tmp])
   end
   return allines
end
facefacelX = createl0l1l2l3(faceinfo1,vertex.length)


   #printvertex(vertex,newnoidx)
   #altvert = altvertex3(vertex,newnoidx)
   altvert = altvertex2(vertex)
   #return xdropped, ydropped, vertex, cell
   return altvert, cell, l0, l1, l2, l3, facefacelX
end

[Source]

# File mesh.rb, line 1338
def createfacefacemesh2(facelist, p0pos, p1pos, p2pos, p3pos, meshx, meshy)
   xpos, ypos, zpos, celldef, l0def, l1def, l2def, l3def = createfrom4points(p0pos, p1pos, p2pos, p3pos, meshx, meshy)
   # returns cellrest, facefacecelldef, facefaceldef
   cellrest, facefacecelldef, facefaceldef = createfacefacemesh2tmp(facelist, xpos, ypos, zpos, celldef)
   return xpos, ypos, zpos, cellrest, l0def, l1def, l2def, l3def, facefacecelldef, facefaceldef, meshx, meshy
end

[Source]

# File mesh.rb, line 1695
def createfacefacemesh2tmp(facelist, xpos, ypos,celldef)
   # after this we will just modify celldef and remove cells that belongs to facefaces
   # break out this, make it more tolerant to all types of faces, not just face1p
   #xpos, ypos, zpos, celldef, l0def, l1def, l2def, l3def = createfrom4points(p0pos, p1pos, p2pos, p3pos, meshx, meshy)
   # find collided facefaces
   # xpos and ypos should be l0-dir l2-dir
   xposmin = xpos.first
   xposmax = xpos.last
   yposmin = ypos.first
   yposmax = ypos.last
   def collidetest(face1, face2)
      xmin1 = face1[0]
      xmax1 = face1[1]
      ymin1 = face1[2]
      ymax1 = face1[3]
      xmin2 = face2[0]
      xmax2 = face2[1]
      ymin2 = face2[2]
      ymax2 = face2[3]
      if ( xmax1 < xmin2 ) || ( xmax2 < xmin1 ) || ( ymax1 < ymin2 ) || ( ymax2 < ymin1 )
         return false
      else
         return true
      end
   end
   collided1 = Array.new
   (0..facelist.size-1).each do |idx1|
      (idx1..facelist.size-1).each do |idx2|
         if idx1 != idx2
            if collidetest(facelist[idx1], facelist[idx2])
               collided1.push(idx2)
               # puts "collision detected"
            end
         end
      end
   end
   # these faces coincide
   collided = collided1.sort.uniq
   # test cells if they are within facefaces
   # celldef[X] = [ p0idx, p1idx, p2idx, p3idx, truefalse]
   facefaceinfo = Array.new
   delcell = Array.new
   (0..celldef.size-1).each do |idx1|
      xmin = xpos[celldef[idx1][0]] 
      xmax = xpos[celldef[idx1][2]]
      ymin = ypos[celldef[idx1][0]] 
      ymax = ypos[celldef[idx1][2]]
      (0..facelist.size-1).each do |idx2|
         # test if its a collided face
         if !collided.member?idx2
            xmin1 = facelist[idx2][0] - (xpos[celldef[idx1][2]]-xpos[celldef[idx1][0]])/2.0
            xmax1 = facelist[idx2][1] + (xpos[celldef[idx1][2]]-xpos[celldef[idx1][0]])/2.0
            ymin1 = facelist[idx2][2] - (ypos[celldef[idx1][2]]-ypos[celldef[idx1][0]])/2.0
            ymax1 = facelist[idx2][3] + (ypos[celldef[idx1][2]]-ypos[celldef[idx1][0]])/2.0
            if xmin > xmin1 && xmax < xmax1 && ymin > ymin1 && ymax < ymax1
               # idx1 - cell no, idx2 - faceface no 
               facefaceinfo.push([idx1,idx2])
               delcell.push(idx1)
            end
         end
      end
   end
   cellrest = Array.new
   faceface1 = delcell.sort.uniq
   (0..celldef.size-1).each do |cell1|
      if !faceface1.member?cell1
         cellrest.push(celldef[cell1])
      end
   end
   # adjust edge nodes
   facefacecell = Array.new
   (0..facelist.size-1).each do |idx|
      facefacecell[idx] = Array.new
   end
   sortinfo = facefaceinfo.sort.uniq
   sortinfo.each do |cellff|
      facefacecell[cellff[1]].push(cellff[0])
      #puts "cellff #{cellff[1]}, #{cellff[0]}"
   end
   facefacecelldef = Array.new
   facefacecell.each_with_index do |celarr1, idx1|
      facefacecelldef[idx1] = Array.new
      celarr1.each do |cel1|
         facefacecelldef[idx1].push(celldef[cel1])
      end
   end
   # create faceface lXdef. facefaceldef on format [ [ldef ff 0], [ldef ff 1], ... ] where
   # ldef ff X is [ l0def, l1def, l2def, ld3def ]. lXdef is [ point0, point1, point2, .. ]
   # ff ldef is created from the cells. (maybe just create all l0def on cell underside and then remove 
   # the wrong ones?)
   # find next point in line definition
   # celldef -> single faceface cell definition
   # cellno -> current cell
   # lno -> l0, l1, l2 or l3
   def findldef(celldef1)
      if celldef1.size == 0
         return 0
      end
      @celldef = celldef1
      def findnextl0(currentcell)
         ressize = @res0.size
         (0..@celldef.size-1).each do |cellno1|
            if @celldef[cellno1][0] == @celldef[currentcell][1] && cellno1 != currentcell
               @res0.push(@celldef[cellno1][1])
               @cell0.push(cellno1)
               break
            end
         end
         if ressize == @res0.size
            @flag = false
         end
      end
      def findnextl1(currentcell)
         ressize = @res1.size
         (0..@celldef.size-1).each do |cellno1|
            if @celldef[cellno1][1] == @celldef[currentcell][2] && cellno1 != currentcell
               @res1.push(@celldef[cellno1][2])
               @cell1.push(cellno1)
               break
            end
         end
         if ressize == @res1.size
            @flag = false
         end
      end
      def findnextl2(currentcell)
         ressize = @res2.size
         (0..@celldef.size-1).each do |cellno1|
            if @celldef[cellno1][2] == @celldef[currentcell][3] && cellno1 != currentcell
               @res2.push(@celldef[cellno1][3])
               @cell2.push(cellno1)
               break
            end
         end
         if ressize == @res2.size
            @flag = false
         end
      end
      def findnextl3(currentcell)
         ressize = @res3.size
         (0..@celldef.size-1).each do |cellno1|
            if @celldef[cellno1][3] == @celldef[currentcell][0]  && cellno1 != currentcell
               @res3.push(@celldef[cellno1][0])
               @cell3.push(cellno1)
               break
            end
         end
         if ressize == @res3.size
            @flag = false
         end
      end
      @res0 = Array.new
      @res0.push( celldef[0][0] )
      @res0.push( celldef[0][1] )
      @cell0 = Array.new
      @cell0.push(0)
      @flag = true
      while @flag
         findnextl0(@cell0.last)
      end
      @res1 = Array.new
      @res1.push( celldef[@cell0.last][1] )
      @res1.push( celldef[@cell0.last][2] )
      @cell1 = Array.new
      @cell1.push(@cell0.last)
      @flag = true
      while @flag
         findnextl1(@cell1.last)
      end
      @res2 = Array.new
      @res2.push( celldef[@cell1.last][2] )
      @res2.push( celldef[@cell1.last][3] )
      @cell2 = Array.new
      @cell2.push(@cell1.last)
      @flag = true
      while @flag
         findnextl2(@cell2.last)
      end
      @res3 = Array.new
      @res3.push( celldef[@cell2.last][3] )
      @res3.push( celldef[@cell2.last][0] )
      @cell3 = Array.new
      @cell3.push(@cell2.last)
      @flag = true
      while @flag
         findnextl3(@cell3.last)
      end




      print "\nl0 vertices "
      @res0.each do |vert1|
         print vert1, ", "
      end
      print "\nl0 cells "
      @cell0.each do |celltmp|
         print celltmp, ", "
      end
      print "\nl1 vertices "
      @res1.each do |vert1|
         print vert1, ", "
      end
      print "\nl1 cells "
      @cell1.each do |celltmp|
         print celltmp, ", "
      end
      print "\nl2 vertices "
      @res2.each do |vert1|
         print vert1, ", "
      end
      print "\nl2 cells "
      @cell2.each do |celltmp|
         print celltmp, ", "
      end
      print "\nl3 vertices "
      @res3.each do |vert1|
         print vert1, ", "
      end
      print "\nl3 cells "
      @cell3.each do |celltmp|
         print celltmp, ", "
      end
      return @res0, @res1, @res2, @res3
   end
   #findldef(facefacecelldef.first)
   facefaceldef = Array.new
   (0..facefacecelldef.size-1).each do |ffidx|
      facefaceldef[ffidx] = Array.new
      ld0, ld1, ld2, ld3 = findldef(facefacecelldef[ffidx])
      facefaceldef[ffidx].push( ld0 ) 
      facefaceldef[ffidx].push( ld1 ) 
      facefaceldef[ffidx].push( ld2 ) 
      facefaceldef[ffidx].push( ld3 ) 
   end
   (0..facefaceldef.size-1).each do |ffidx|
      if facefacecelldef[ffidx].size > 0
         xmin = [facelist[ffidx][0], xposmin].max
         xmax = [facelist[ffidx][1], xposmax].min
         ymin = [facelist[ffidx][2], yposmin].max
         ymax = [facelist[ffidx][3], yposmax].min
         (0..facefaceldef[ffidx][0].size-1).each do |vertidx|
            ypos[facefaceldef[ffidx][0][vertidx]] = ymin
         end
         (0..facefaceldef[ffidx][1].size-1).each do |vertidx|
            xpos[facefaceldef[ffidx][1][vertidx]] = xmax
         end
         (0..facefaceldef[ffidx][2].size-1).each do |vertidx|
            ypos[facefaceldef[ffidx][2][vertidx]] = ymax
         end
         (0..facefaceldef[ffidx][3].size-1).each do |vertidx|
            xpos[facefaceldef[ffidx][3][vertidx]] = xmin
         end
      end
   end
??
??
??
# @x[@csys.count], @y[@csys.count], @z[@csys.count] ,@celldef, @l0def, @l1def, @l2def, @l3def,@facefacecelldef, @facefaceldef @meshx, @meshy
   #return xpos, ypos, zpos, cellrest, l0def, l1def, l2def, l3def, facefacecelldef, facefaceldef, meshx, meshy
   return cellrest, facefacecelldef, facefaceldef
end

[Source]

# File mesh.rb, line 1345
def createfacefacemesh3(facelist, xpos, ypos, zpos, celldef, l0def, l1def, l2def, l3def, adjust)
   # after this we will just modify celldef and remove cells that belongs to facefaces
   # break out this, make it more tolerant to all types of faces, not just face1p
   #xpos, ypos, zpos, celldef, l0def, l1def, l2def, l3def = createfrom4points(p0pos, p1pos, p2pos, p3pos, meshx, meshy)
   # find collided facefaces
   # xpos and ypos should be l0-dir l2-dir
   # x0, y0, z0 => xpos[l0def.first], ypos[l0def.first], zpos[l0def.first]
   # x1, y1, z1 => xpos[l0def.last], ypos[l0def.last], zpos[l0def.last]
   # example x 0->10, y 0->0, z 0->0 l0-dir: point:[0,0,0], vector:[10,0,0], xlength: 10
   # imax [10,0,0], imin [0,0,0]
   # example2 x 0->10, y 0->5, z 0->0 l0-dir: point:[0,0,0], vector[10,5,0], xlength sqrt(10**2+5**2)
   # imin 0, imax 11.2
   # x_i(i) = x0 + k_ix*i
   # y_i(i) = y0 + k_ix*i
   # z_i(i) = z0 + k_ix*i
   # compare with i, adjust with formula above
   imin = 0.0
   imax = Math::sqrt((xpos[l0def.last] - xpos[l0def.first])**2 + (ypos[l0def.last] - ypos[l0def.first])**2 + (zpos[l0def.last] - zpos[l0def.first])**2)
   jmin = 0.0
   jmax = Math::sqrt((xpos[l3def.first] - xpos[l3def.last])**2 + (ypos[l3def.first] - ypos[l3def.last])**2 + (zpos[l3def.first] - zpos[l3def.last])**2)
   @x_i0 = xpos[l0def.first]
   @y_i0 = ypos[l0def.first]
   @z_i0 = zpos[l0def.first]
   @x_j0 = xpos[l3def.last]
   @y_j0 = ypos[l3def.last]
   @z_j0 = zpos[l3def.last]
   @k_ix = (xpos[l0def.last] - xpos[l0def.first]) / imax
   @k_iy = (ypos[l0def.last] - ypos[l0def.first]) / imax
   @k_iz = (zpos[l0def.last] - zpos[l0def.first]) / imax
   @k_jx = (xpos[l3def.first] - xpos[l3def.last]) / jmax
   @k_jy = (ypos[l3def.first] - ypos[l3def.last]) / jmax
   @k_jz = (zpos[l3def.first] - zpos[l3def.last]) / jmax
   def x_i(i)
      return @x_i0 + @k_ix*i
   end
   def y_i(i)
      return @y_i0 + @k_iy*i
   end
   def z_i(i)
      return @z_i0 + @k_iz*i
   end
   def x_j(j)
      return @x_j0 + @k_jx*j
   end
   def y_j(j)
      return @y_j0 + @k_jy*j
   end
   def z_j(j)
      return @z_j0 + @k_jz*j
   end
   def x_ij(i,j)
      return x_i(i) + x_j(j)
   end
   def y_ij(i,j)
      return y_i(i) + y_j(j)
   end
   def z_ij(i,j)
      return z_i(i) + z_j(j)
   end
   def collidetest(face1, face2)
      imin1 = face1[0]
      imax1 = face1[1]
      jmin1 = face1[2]
      jmax1 = face1[3]
      imin2 = face2[0]
      imax2 = face2[1]
      jmin2 = face2[2]
      jmax2 = face2[3]
      if ( imax1 < imin2 ) || ( imax2 < imin1 ) || ( jmax1 < jmin2 ) || ( jmax2 < jmin1 )
         return false
      else
         return true
      end
   end
   collided1 = Array.new
   (0..facelist.size-1).each do |idx1|
      (idx1..facelist.size-1).each do |idx2|
         if idx1 != idx2
            if collidetest(facelist[idx1], facelist[idx2])
               collided1.push(idx2)
               # puts "collision detected"
            end
         end
      end
   end
   # these faces coincide
   collided = collided1.sort.uniq
   # test cells if they are within facefaces
   # celldef[X] = [ p0idx, p1idx, p2idx, p3idx, truefalse]
   facefaceinfo = Array.new
   delcell = Array.new
   # i, j test instead
   def idxToIJ(cellno, l0def, l1def, imax, jmax)
      l0size = l0def.size - 1
      l1size = l1def.size - 1
      i0 = cellno % l0size
      j0 = (cellno / l0size).truncate
      i1 = i0 + 1
      j1 = j0 + 1
      xmin = imax * i0 / l0size
      xmax = imax * i1 / l0size
      ymin = jmax * j0 / l1size
      ymax = jmax * j1 / l1size
      return xmin, xmax, ymin, ymax 
   end
   xtol = (imax / l0def.size) / 2.0
   ytol = (jmax / l1def.size) / 2.0
   puts "xtol #{xtol}, ytol #{ytol}" 
   (0..celldef.size-1).each do |idx1|
      xmin, xmax, ymin, ymax = idxToIJ(idx1, l0def, l1def, imax, jmax)
      (0..facelist.size-1).each do |idx2|
         # test if its a collided face
         if !collided.member?idx2
            # i and j represents faceface x and y
            xmin1 = facelist[idx2][0] - xtol
            xmax1 = facelist[idx2][1] + xtol
            ymin1 = facelist[idx2][2] - ytol
            ymax1 = facelist[idx2][3] + ytol
            # test if cell is within current faceface
            if xmin > xmin1 && xmax < xmax1 && ymin > ymin1 && ymax < ymax1
               # idx1 - cell no, idx2 - faceface no 
               facefaceinfo.push([idx1,idx2])
               delcell.push(idx1)
            end
         end
      end
   end
   cellrest = Array.new
   faceface1 = delcell.sort.uniq
   (0..celldef.size-1).each do |cell1|
      if !faceface1.member?cell1
         cellrest.push(celldef[cell1])
      end
   end
   # adjust edge nodes
   facefacecell = Array.new
   (0..facelist.size-1).each do |idx|
      facefacecell[idx] = Array.new
   end
   sortinfo = facefaceinfo.sort.uniq
   sortinfo.each do |cellff|
      facefacecell[cellff[1]].push(cellff[0])
      #puts "cellff #{cellff[1]}, #{cellff[0]}"
   end
   facefacecelldef = Array.new
   facefacecell.each_with_index do |celarr1, idx1|
      facefacecelldef[idx1] = Array.new
      celarr1.each do |cel1|
         facefacecelldef[idx1].push(celldef[cel1])
      end
   end
   # create faceface lXdef. facefaceldef on format [ [ldef ff 0], [ldef ff 1], ... ] where
   # ldef ff X is [ l0def, l1def, l2def, ld3def ]. lXdef is [ point0, point1, point2, .. ]
   # ff ldef is created from the cells. (maybe just create all l0def on cell underside and then remove 
   # the wrong ones?)
   # find next point in line definition
   # celldef -> single faceface cell definition
   # cellno -> current cell
   # lno -> l0, l1, l2 or l3
   def findldef(celldef1)
      if celldef1.size == 0
         return 0
      end
      @celldef = celldef1
      def findnextl0(currentcell)
         ressize = @res0.size
         (0..@celldef.size-1).each do |cellno1|
            if @celldef[cellno1][0] == @celldef[currentcell][1] && cellno1 != currentcell
               @res0.push(@celldef[cellno1][1])
               @cell0.push(cellno1)
               break
            end
         end
         if ressize == @res0.size
            @flag = false
         end
      end
      def findnextl1(currentcell)
         ressize = @res1.size
         (0..@celldef.size-1).each do |cellno1|
            if @celldef[cellno1][1] == @celldef[currentcell][2] && cellno1 != currentcell
               @res1.push(@celldef[cellno1][2])
               @cell1.push(cellno1)
               break
            end
         end
         if ressize == @res1.size
            @flag = false
         end
      end
      def findnextl2(currentcell)
         ressize = @res2.size
         (0..@celldef.size-1).each do |cellno1|
            if @celldef[cellno1][2] == @celldef[currentcell][3] && cellno1 != currentcell
               @res2.push(@celldef[cellno1][3])
               @cell2.push(cellno1)
               break
            end
         end
         if ressize == @res2.size
            @flag = false
         end
      end
      def findnextl3(currentcell)
         ressize = @res3.size
         (0..@celldef.size-1).each do |cellno1|
            if @celldef[cellno1][3] == @celldef[currentcell][0]  && cellno1 != currentcell
               @res3.push(@celldef[cellno1][0])
               @cell3.push(cellno1)
               break
            end
         end
         if ressize == @res3.size
            @flag = false
         end
      end
      @res0 = Array.new
      @res0.push( celldef[0][0] )
      @res0.push( celldef[0][1] )
      @cell0 = Array.new
      @cell0.push(0)
      @flag = true
      while @flag
         findnextl0(@cell0.last)
      end
      @res1 = Array.new
      @res1.push( celldef[@cell0.last][1] )
      @res1.push( celldef[@cell0.last][2] )
      @cell1 = Array.new
      @cell1.push(@cell0.last)
      @flag = true
      while @flag
         findnextl1(@cell1.last)
      end
      @res2 = Array.new
      @res2.push( celldef[@cell1.last][2] )
      @res2.push( celldef[@cell1.last][3] )
      @cell2 = Array.new
      @cell2.push(@cell1.last)
      @flag = true
      while @flag
         findnextl2(@cell2.last)
      end
      @res3 = Array.new
      @res3.push( celldef[@cell2.last][3] )
      @res3.push( celldef[@cell2.last][0] )
      @cell3 = Array.new
      @cell3.push(@cell2.last)
      @flag = true
      while @flag
         findnextl3(@cell3.last)
      end

      return @res0, @res1, @res2, @res3
   end
   #findldef(facefacecelldef.first)
   facefaceldef = Array.new
   (0..facefacecelldef.size-1).each do |ffidx|
      facefaceldef[ffidx] = Array.new
      ld0, ld1, ld2, ld3 = findldef(facefacecelldef[ffidx])
      facefaceldef[ffidx].push( ld0 ) 
      facefaceldef[ffidx].push( ld1 ) 
      facefaceldef[ffidx].push( ld2 ) 
      facefaceldef[ffidx].push( ld3 ) 
   end
   # adjust all nodes/vertices?
   # Create something like i and j -index for vertices?
   # i and j represents faceface x and y
   (0..facefaceldef.size-1).each do |ffidx|
      puts "adjust from mesh #{adjust[ffidx]}"
      if adjust[ffidx] ==  1
      if facefacecelldef[ffidx].size > 0
         imin1 = [facelist[ffidx][0], 0.0].max
         imax1 = [facelist[ffidx][1], imax].min
         jmin1 = [facelist[ffidx][2], 0.0].max
         jmax1 = [facelist[ffidx][3], jmax].min
         # l0
         tmpimax1 = facefaceldef[ffidx][0].size-1
         (0..facefaceldef[ffidx][0].size-1).each do |vertidx|
            # now we have to set the x,y z as function of j where j = jmin1
            # ypos[facefaceldef[ffidx][0][vertidx]] = jmin1
            xpos[facefaceldef[ffidx][0][vertidx]] = x_i(imin1 + (imax1-imin1)/tmpimax1*vertidx) + x_j(jmin1) -@x_i0
            ypos[facefaceldef[ffidx][0][vertidx]] = y_i(imin1 + (imax1-imin1)/tmpimax1*vertidx) + y_j(jmin1) -@y_i0
            zpos[facefaceldef[ffidx][0][vertidx]] = z_i(imin1 + (imax1-imin1)/tmpimax1*vertidx) + z_j(jmin1) -@z_i0
         end
         # l1
         tmpjmax1 = facefaceldef[ffidx][1].size-1
         (0..facefaceldef[ffidx][1].size-1).each do |vertidx|
            # now we have to set the x,y z as function of i
            #xpos[facefaceldef[ffidx][1][vertidx]] = imax1
            xpos[facefaceldef[ffidx][1][vertidx]] = x_i(imax1) + x_j(jmin1 + (jmax1-jmin1)/tmpjmax1*vertidx) -@x_i0
            ypos[facefaceldef[ffidx][1][vertidx]] = y_i(imax1) + y_j(jmin1 + (jmax1-jmin1)/tmpjmax1*vertidx) -@y_i0
            zpos[facefaceldef[ffidx][1][vertidx]] = z_i(imax1) + z_j(jmin1 + (jmax1-jmin1)/tmpjmax1*vertidx) -@z_i0
         end
         # l2
         #tmpimax1 = facefaceldef[ffidx][2].size-1
         (0..facefaceldef[ffidx][2].size-1).each do |vertidx|
            # now we have to set the x,y z as function of j
            #ypos[facefaceldef[ffidx][2][vertidx]] = jmax1
            xpos[facefaceldef[ffidx][2][vertidx]] = x_i(imax1 - (imax1-imin1)/tmpimax1*vertidx) + x_j(jmax1) -@x_i0
            ypos[facefaceldef[ffidx][2][vertidx]] = y_i(imax1 - (imax1-imin1)/tmpimax1*vertidx) + y_j(jmax1) -@y_i0
            zpos[facefaceldef[ffidx][2][vertidx]] = z_i(imax1 - (imax1-imin1)/tmpimax1*vertidx) + z_j(jmax1) -@z_i0
         end
         # l3
         #tmpjmax1 = facefaceldef[ffidx][3].size-1
         (0..facefaceldef[ffidx][3].size-1).each do |vertidx|
            # now we have to set the x,y z as function of i
            #xpos[facefaceldef[ffidx][3][vertidx]] = imin1
            xpos[facefaceldef[ffidx][3][vertidx]] = x_i(imin1) + x_j(jmax1 - (jmax1-jmin1)/tmpjmax1*vertidx) -@x_i0
            ypos[facefaceldef[ffidx][3][vertidx]] = y_i(imin1) + y_j(jmax1 - (jmax1-jmin1)/tmpjmax1*vertidx) -@y_i0
            zpos[facefaceldef[ffidx][3][vertidx]] = z_i(imin1) + z_j(jmax1 - (jmax1-jmin1)/tmpjmax1*vertidx) -@z_i0
         end
   # trufalse begin
   if true
   # test-begin
   # i,j 0,0 at i,j=0
   # j 0, i 0..isize
   # j 1, i 0..isize
   #(0..facefacecelldef.size-1).each do |ffidx|
      #facefacecelldef[ffidx].each do |celidx|
         def jplus(jpos)
            if jpos == 0
               return 0
            else
               return jpos + 1
            end
         end
         isize1 = facefaceldef[ffidx][0].size - 2
         cellno2 = 0
         (0..facefaceldef[ffidx][1].size-2).each do |jind|
            (0..facefaceldef[ffidx][0].size-2).each do |iind|
               xpos[facefacecelldef[ffidx][cellno2][0]] = x_i(imin1 + (imax1-imin1)/tmpimax1*iind) + x_j(jmin1 + (jmax1-jmin1)/tmpjmax1*jind) -@x_i0
               ypos[facefacecelldef[ffidx][cellno2][0]] = y_i(imin1 + (imax1-imin1)/tmpimax1*iind) + y_j(jmin1 + (jmax1-jmin1)/tmpjmax1*jind) -@y_i0
               zpos[facefacecelldef[ffidx][cellno2][0]] = z_i(imin1 + (imax1-imin1)/tmpimax1*iind) + z_j(jmin1 + (jmax1-jmin1)/tmpjmax1*jind) -@z_i0
             
               cellno2 += 1
            end
         end
         # truefalse end
         end
      #end
   #end
   # test-end
      end
   end  # adjust end
   end
# @x[@csys.count], @y[@csys.count], @z[@csys.count] ,@celldef, @l0def, @l1def, @l2def, @l3def,@facefacecelldef, @facefaceldef @meshx, @meshy
   #return xpos, ypos, zpos, cellrest, l0def, l1def, l2def, l3def, facefacecelldef, facefaceldef, meshx, meshy
   return cellrest, facefacecelldef, facefaceldef
end

[Source]

# File mesh.rb, line 285
   def createfrom4points(p0, p1, p2, p3, meshx, meshy)
      # I do a general method where p0-p3 can be positioned anywhere
      xpos = Array.new
      ypos = Array.new
      zpos = Array.new
      x0 = Array.new
      y0 = Array.new
      z0 = Array.new
      x2 = Array.new
      y2 = Array.new
      z2 = Array.new
      # create points between p0 and p1 + p3 and p2
      (0..meshx - 1).each do |tmpx|
         x0[tmpx] = p0[0] + (p1[0]-p0[0]) * tmpx / (meshx -1)
         y0[tmpx] = p0[1] + (p1[1]-p0[1]) * tmpx / (meshx -1)
         z0[tmpx] = p0[2] + (p1[2]-p0[2]) * tmpx / (meshx -1)
         x2[tmpx] = p3[0] + (p2[0]-p3[0]) * tmpx / (meshx -1)
         y2[tmpx] = p3[1] + (p2[1]-p3[1]) * tmpx / (meshx -1)
         z2[tmpx] = p3[2] + (p2[2]-p3[2]) * tmpx / (meshx -1)
      end
      # create all points in face
      num = 0
      (0..meshy -1).each do |tmpy|
         (0..meshx - 1).each do |tmpx|
            xpos[num] = x0[tmpx] + (x2[tmpx]-x0[tmpx]) * tmpy / (meshy -1)
            ypos[num] = y0[tmpx] + (y2[tmpx]-y0[tmpx]) * tmpy / (meshy -1)
            zpos[num] = z0[tmpx] + (z2[tmpx]-z0[tmpx]) * tmpy / (meshy -1)
            num += 1
         end
      end
      # create cell definition
      celldef = Array.new
      cellnum = 0
      #rowlength = meshx
      #collength = meshy
      truefalse = [true,false]
      #(0..rowlength-2).each do |row|
      (0..meshy-2).each do |ydir|
         truefalse = truefalse.reverse
         tmptruefalse = truefalse
         #(0..collength-2).each do |col|
         (0..meshx-2).each do |xdir|
            celldef[cellnum] = [xdir+ydir*meshx, xdir+ydir*meshx+1, xdir+(1+ydir)*meshx+1, xdir+(1+ydir)*meshx, tmptruefalse[0]]
            #celldef[cellnum] = [col+row*collength, col+row*collength+1, col+(1+row)*collength+1, col+(1+row)*collength, tmptruefalse[0]]
            #celldef[cellnum] = [col+row*rowlength, col+row*rowlength+1, col+(1+row)*rowlength+1, col+(1+row)*rowlength, tmptruefalse[0]]
            cellnum += 1
            tmptruefalse = tmptruefalse.reverse
         end
      end
      l0def = Array.new
      l1def = Array.new
      l2def = Array.new
      l3def = Array.new
      (0..meshx-1).each do |xdir|
         l0def[xdir] = xdir
         l2def[xdir] = meshx * (meshy - 1) + xdir
      end
      (0..meshy-1).each do |ydir|
         l3def[ydir] = ydir * meshx 
         l1def[ydir] = ydir * meshx + meshx -1
      end
      return xpos, ypos, zpos, celldef, l0def, l1def, l2def.reverse, l3def.reverse
   end

faceinfo = [[[1,1],[1,3],[2,1],[2,3]]] create the line definitions for the facefaces

[Source]

# File mesh.rb, line 2432
def createl0l1l2l3(faceinfoin,ilen)
   allines = Array.new
   faceinfoin.each do |faceinfo|
      l0tmp = Array.new
      l1tmp = Array.new
      l2tmp = Array.new
      l3tmp = Array.new
      (faceinfo[0][0]..faceinfo[2][0]).each do |xdir|
         vert1 = xy2vertno(xdir,faceinfo[0][1],ilen)
         l0tmp.push(vert1)
      end

      (faceinfo[2][1]..faceinfo[3][1]).each do |ydir|
         vert1 = xy2vertno(faceinfo[2][0],ydir,ilen)
         l1tmp.push(vert1)
      end

      (faceinfo[1][0]..faceinfo[3][0]).to_a.reverse.each do |xdir|
        vert1 = xy2vertno(xdir,faceinfo[3][1],ilen)
         l2tmp.push(vert1)
      end

      (faceinfo[0][1]..faceinfo[1][1]).to_a.reverse.each do |ydir|
         vert1 = xy2vertno(faceinfo[1][0],ydir,ilen)
         l3tmp.push(vert1)
      end
      def makedef(lXtmp)
         ltmp = Array.new
         (0..lXtmp.size-2).each do |slice1|
            ltmp.push(lXtmp[(slice1)..(slice1+1)])
         end
         return ltmp
      end
      l0tmp = makedef(l0tmp)
      l1tmp = makedef(l1tmp)
      l2tmp = makedef(l2tmp)
      l3tmp = makedef(l3tmp)
      allines.push([l0tmp,l1tmp,l2tmp,l3tmp])
   end
   return allines
end

[Source]

# File mesh.rb, line 233
   def createline(x, y, z, parent, self1)
      # fill array l with LiteLines and v with InfoPoints
      # first line
      # LiteLine.new([x0,y0,z0], [x1,y1,z1], parent, (viewerobj), text)
      l = Array.new
      (0..(x.size-2)).each do |num|
         l[num]=LiteLine.new([x[num], y[num], z[num]], [x[num+1], y[num+1], z[num+1]], parent, self1, "meshline#{num}")
      end
      return l
   end

if firstpoint true firstpoint, otherwise lastpoint

[Source]

# File mesh.rb, line 2491
   def endpoint(face, line, firstpoint)
      #puts "endpoint start"
      @face, @line, @firstpoint = face, line, firstpoint
      if @face == nil
         if @firstpoint
            #puts "returned nil face line firstpoint"
            return @line.firstpoint
         else
            #puts "returned nil face line lastpoint"
            return @line.lastpoint
         end
      else
         if @face.firstline == line
            if @firstpoint
               #puts "returned 1st face context p0"
               return @face.p0
            else
               puts "returned 1st face context p1"
               return @face.p1
            end
         elsif @face.secondline == line
            if @firstpoint
               #puts "returned 2nd face context p1"
               return @face.p1
            else
               #puts "returned 2nd face context p2"
               return @face.p2
            end
         elsif @face.thirdline == line
            if @firstpoint
               #puts "returned 3rd face context p2"
               return @face.p2
            else
               #puts "returned 3rd face context p3"
               return @face.p3
            end
         elsif @face.fourthline == line
            if @firstpoint
               #puts "returned 4th face context p3"
               return @face.p3
            else
               #puts "returned 4th face context p0"
               return @face.p0
            end
         end
      end
   end

[Source]

# File mesh.rb, line 868
   def extrude(line,csys,dir,meshnum,self1)
      # create nodes
      vertcount = 0
      vertex = Array.new(line.v.size)
      (0..line.v.size-1).each do |row|
         vertex[row] = Array.new(meshnum)
         (0..meshnum-1).each do |col|
            vert2pos = invPositionInCsys(csys,line.v[row].pos)
            movfac1 = col/(meshnum-1)
            vertex[row][col] = InfoPoint.new(csys,[vert2pos[0]+dir[0]*movfac1, 
                                                    vert2pos[1]+dir[1]*movfac1, 
                                                    vert2pos[2]+dir[2]*movfac1])
            vertex[row][col].inpos = [vert2pos[0]+dir[0]*movfac1, 
                                       vert2pos[1]+dir[1]*movfac1, 
                                       vert2pos[2]+dir[2]*movfac1]
            vertex[row][col].update
            #vertex[row][col].show($globalviewer)
            vertcount += 1
         end
      end
      # to get the right vertcount
      vertcount -= 1
      # line vertex positions in line.v[num].pos
      # create celldef
      cell = Array.new
      f = Array.new
      # create a celldef method with vertex as input
      cell = celldef(vertex)
      cellno = 0
      cell.each do |cell1|
         p0tmp = havePoint(vertex,cell1[0]) 
         p1tmp = havePoint(vertex,cell1[1]) 
         p2tmp = havePoint(vertex,cell1[2]) 
         p3tmp = havePoint(vertex,cell1[3]) 
            # puts "p0tmp #{p0tmp.pos[0]}, #{p0tmp.pos[1]}, #{p0tmp.pos[2]}" 
            # puts "p1tmp #{p1tmp.pos[0]}, #{p1tmp.pos[1]}, #{p1tmp.pos[2]}" 
            # puts "p2tmp #{p2tmp.pos[0]}, #{p2tmp.pos[1]}, #{p2tmp.pos[2]}" 
            # puts "p3tmp #{p3tmp.pos[0]}, #{p3tmp.pos[1]}, #{p3tmp.pos[2]}" 
         f[cellno] = LiteFace.new(p0tmp.pos[0], 
                                     p0tmp.pos[1], 
                                     p0tmp.pos[2], 
                                     p1tmp.pos[0], 
                                     p1tmp.pos[1], 
                                     p1tmp.pos[2], 
                                     p2tmp.pos[0], 
                                     p2tmp.pos[1], 
                                     p2tmp.pos[2], 
                                     p3tmp.pos[0], 
                                     p3tmp.pos[1], 
                                     p3tmp.pos[2],self1,cell1[4])
         cellno += 1
      end
      # create the edge lines
      l0 = Array.new
      l2 = Array.new
      lineseg = 0
      (0..vertex.size-2).each do |row1|
         l0[lineseg] = LiteLine.new(vertex[row1].first, vertex[row1+1].first,self1,l0, "l0")
         l2[lineseg] = LiteLine.new(vertex[row1].last, vertex[row1+1].last,self1,l2, "l2")
         #l0[lineseg].info[1] = l0[lineseg]
         #l2[lineseg].info[1] = l2[lineseg]
         lineseg += 1
      end
      l3 = Array.new
      l1 = Array.new
      lineseg = 0
      (0..vertex[0].size-2).each do |col1|
         l3[lineseg] = LiteLine.new(vertex.first[col1], vertex.first[col1+1],self1,l3, "l3")
         l1[lineseg] = LiteLine.new(vertex.last[col1], vertex.last[col1+1],self1,l1, "l1")
         #l3[lineseg].info[1] = l3[lineseg]
         #l1[lineseg].info[1] = l1[lineseg]
         lineseg += 1
      end
      return vertex,cell,f,l0,l1,l2,l3
   end

[Source]

# File mesh.rb, line 348
   def extrudeincsys(x, y, z, xvec, yvec, zvec, meshnum)
      xpos = Array.new
      ypos = Array.new
      zpos = Array.new
      num = 0
      meshcol = x.size - 1
      (0..meshnum - 1).each do |row|
         (0..meshcol).each do |col|
            xpos[num] = x[col] + xvec.to_f * row / (meshnum-1)
            ypos[num] = y[col] + yvec.to_f * row / (meshnum-1)
            zpos[num] = z[col] + zvec.to_f * row / (meshnum-1)
            num += 1
         end
      end
      celldef = Array.new
      cellnum = 0
      rowlength = meshnum
      collength = x.size
      truefalse = [true,false]
      # not god
      (0..rowlength-2).each do |row|
         truefalse = truefalse.reverse
         tmptruefalse = truefalse
         (0..collength-2).each do |col|
            celldef[cellnum] = [col+row*collength, col+row*collength+1, col+(1+row)*collength+1, col+(1+row)*collength, tmptruefalse[0]]
            #celldef[cellnum] = [col+row*rowlength, col+row*rowlength+1, col+(1+row)*rowlength+1, col+(1+row)*rowlength, tmptruefalse[0]]
            cellnum += 1
            tmptruefalse = tmptruefalse.reverse
         end
      end
      l1def = Array.new
      l2def = Array.new
      l3def = Array.new
      (0..meshnum-1).each do |row|
         l1def[row] = row * collength + collength - 1
         l3def[row] = row * collength 
      end
      (0..collength-1).each do |col|
         l2def[col] = collength * (meshnum -1)  + col
      end
      return xpos, ypos, zpos, celldef, l1def, l2def.reverse, l3def.reverse
   end

create a matrix with vertex positions vertex = [[vert1.pos[0], vert1.pos[1], vert1.pos[2],[vert2.pos,..] create cell information cell = [[vertno1,vertno2,vertno9,vertno8], then you can create a cell from vertex[cell[0,0]],vertex[cell[0,1]],vertex[cell[0,2]],vertex[cell[0,3]] Vertex positions could be where the projection from l0 to l2 and l1 to l3 are closest (or coincide). so I will (for each vertex to be positioned) the closest 4 vertices from the l0-l2 and l1-l3 projections and then calculate the best position.

  1. do the linearSpace for the l0-l2 and l1-l3
  2. calculate best vertex positions and put/modify in vertex matrix

puts "l3 radius #{l3.radius} l3 xaxis #{l3.xaxis} l3 yaxis #{l3.yaxis} l3 zaxis #{l3.zaxis}"

[Source]

# File mesh.rb, line 954
   def facemesh1(csys,l0,l1,l2,l3) 

     l0xyz = Array.new
     l0.v.each_with_index do |vertex,idx|
        l0xyz[idx] = vertex.inpos
     end
     l1xyz = Array.new
     l1.v.each_with_index do |vertex,idx|
        l1xyz[idx] = vertex.inpos
     end
     l2xyz = Array.new
     l2.v.each_with_index do |vertex,idx|
        l2xyz[idx] = vertex.inpos
     end
     # no reverse ? l2xyz = l2xyz.reverse
     l3xyz = Array.new
     l3.v.each_with_index do |vertex,idx|
        l3xyz[idx] = vertex.inpos
     end
     # no reverse? l3xyz = l3xyz.reverse
     # test radius
     if l0.radius != nil
        length = vertexDistance(l0.p0.pos,l0.p1.pos)
        if l0.radius < length/2.0
           l0radius = length/2.0
        else
           l0radius = l0.radius
        end
     else
        l0radius = 0.0
     end
     # test radius
     if l1.radius != nil
        length = vertexDistance(l1.p0.pos,l1.p1.pos)
        if l1.radius < length/2.0
           l1radius = length/2.0
        else
           l1radius = l1.radius
        end
     else
        l1radius = 0.0
     end
     # test radius
     if l2.radius != nil
        length = vertexDistance(l2.p0.pos,l2.p1.pos)
        if l2.radius < length/2.0
           l2radius = length/2.0
        else
           l2radius = l2.radius
        end
     else
        l2radius = 0.0
     end
     # test radius
     if l3.radius != nil
        length = vertexDistance(l3.p0.pos,l3.p1.pos)
        if l3.radius < length/2.0
           l3radius = length/2.0
        else
           l3radius = l3.radius
        end
     else
        l3radius = 0.0
     end
     # create linearSpace between l0-l2 and l3-l1
     # these linearspaces has to be radiusadjusted.
     # mesh method can get radius info from InfoLine input. l0.radius, l0.xaxis ..
     totalsize = l0xyz.size - 1 
     fadesize = (l0xyz.size/2).to_i
     if l0xyz.size == l2xyz.size
        l0l2 = Array.new
        tmpmshnum = (l1xyz.size-1)*$meshinterpolationfactor + 1
        l0xyz.each_with_index do |l0tmp,idx|
           tmpx,tmpy,tmpz = linearSpace(l0tmp[0], l0tmp[1], l0tmp[2], 
              l2xyz[idx][0], l2xyz[idx][1], l2xyz[idx][2],tmpmshnum)
           # do the radiusadjust
           # x,y,z = radiusadjust(x,y,z, radius, @xaxis, @yaxis, @zaxis, @refattr)
           ##if idx <= fadesize - 1 && l3.radius != 0.0 
           if l3.radius != nil 
              #tmpx, tmpy, tmpz = radiusadjust(tmpx, tmpy, tmpz, 150.0, 0.0, 0.0, 1.0, tmpmshnum, 0)
              tmpx, tmpy, tmpz = radiusadjust(tmpx, tmpy, tmpz, 
                ##l3.radius + ($meshradiusrecover*l3.radius*(idx)/fadesize)**3 , 
                l3radius + ($meshradiusrecover*l3radius*(idx)/totalsize)**3 , 
                l3.xaxis, l3.yaxis, l3.zaxis, tmpmshnum, swapbool(l3.refattr))
           end
           ## if idx >= totalsize - fadesize - 1 && l1.radius != 0.0 
           if l1.radius != nil 
              #tmpx, tmpy, tmpz = radiusadjust(tmpx, tmpy, tmpz, 150.0, 0.0, 0.0, 1.0, tmpmshnum, 0)
              tmpx, tmpy, tmpz = radiusadjust(tmpx, tmpy, tmpz, 
                ##l1.radius + ($meshradiusrecover*l1.radius*(totalsize-idx)/fadesize)**3 , 
                l1radius + ($meshradiusrecover*l1radius*(totalsize-idx)/totalsize)**3 , 
                l1.xaxis, l1.yaxis, l1.zaxis, tmpmshnum, l1.refattr)
           end
           l0l2[idx] =  [tmpx.to_a, tmpy.to_a, tmpz.to_a]
        end
     else
        puts "mesh generation fail"
     end
     # and for l3-l1
     totalsize = l3xyz.size - 1 
     fadesize = (l3xyz.size/2).to_i
     if l3xyz.size == l1xyz.size
        l3l1 = Array.new
        tmpmshnum = (l0xyz.size-1)*$meshinterpolationfactor + 1
        l3xyz.each_with_index do |l3tmp,idx|
           tmpx,tmpy,tmpz= linearSpace(l3tmp[0], l3tmp[1], l3tmp[2], 
              l1xyz[idx][0], l1xyz[idx][1], l1xyz[idx][2],tmpmshnum)
           # do the radiusadjust
           ##if idx <= fadesize - 1 && l0.radius != 0.0 
           if l0.radius != nil
              tmpx, tmpy, tmpz = radiusadjust(tmpx, tmpy, tmpz, 
                ##l0.radius + ($meshradiusrecover*l0.radius*(idx)/fadesize)**3 , 
                l0radius + ($meshradiusrecover*l0radius*(idx)/totalsize)**3 , 
                l0.xaxis, l0.yaxis, l0.zaxis, tmpmshnum, l0.refattr)
           end
           ##if idx >= (totalsize - fadesize) && l2.radius != 0.0 
           if l2.radius != nil 
              tmpx, tmpy, tmpz = radiusadjust(tmpx, tmpy, tmpz, 
                ##l2.radius + ($meshradiusrecover*l2.radius*(totalsize-idx)/fadesize)**3 ,
                l2radius + ($meshradiusrecover*l2radius*(totalsize-idx)/totalsize)**3 ,
                l2.xaxis, l2.yaxis, l2.zaxis, tmpmshnum, swapbool(l2.refattr))
           end
           l3l1[idx] =  [tmpx.to_a, tmpy.to_a, tmpz.to_a]
        end
     else
        puts "mesh generation fail"
     end
     # first we take l0l2[0] and intersect with l3l1[0], then l0l2[1] with l3l1[0] ..
     # first l0:s vertices, then 1 vertex from l3, then intersect, then 1 vertex from l1, then 1 vertex from l3 ..
     vertex = Array.new
     vertcount = 0
     (0..l0xyz.size-1).each do |xdir|
        vertex[vertcount] = [ l0xyz[xdir][0], l0xyz[xdir][1], l0xyz[xdir][2] ] 
        vertcount += 1
     end
     if l3xyz.size-2 > 0
        (1..l3xyz.size-2).each do |ydir|
           (0..l0xyz.size-1).each do |xdir|
              if xdir == 0
                 vertex[vertcount] = [ l3xyz[ydir][0], l3xyz[ydir][1], l3xyz[ydir][2]] 
                 vertcount += 1
              elsif xdir == l0xyz.size-1
                 vertex[vertcount] = [ l1xyz[ydir][0], l1xyz[ydir][1], l1xyz[ydir][2]] 
                 vertcount += 1
              else
                 vertex[vertcount] = findvertex(l3l1[ydir],l0l2[xdir],xdir,ydir)
                 vertcount += 1
               end
            end
         end
      end
     (0..l0xyz.size-1).each do |xdir|
        vertex[vertcount] = [ l2xyz[xdir][0], l2xyz[xdir][1], l2xyz[xdir][2] ] 
        vertcount += 1
     end
              
   # place the vertices in coordinate system
   vertex.each_with_index do |tmpvertex, idx|
      vertex[idx] = positionInCsys(csys, vertex[idx])
   end
      

??
     cell = Array.new
     ilength = l0xyz.size
     jlength = l3xyz.size
     cellno = 0
     flag=true
     (0..jlength-2).each do |yind|
        if flag
           truefalse = [true,false]
           flag = false
        else
           truefalse = [false,true]
           flag = true
        end
        (0..ilength-2).each do |xind|
           cell[cellno] = [xind+ilength*yind, xind+1+ilength*yind,xind+1+ilength*(1+yind),xind+ilength*(1+yind), truefalse.last]
           cellno += 1
           truefalse = truefalse.reverse
        end
     end
     puts "cell count #{cellno}"
     return vertex,cell
   end

now a method that returns the facefaces index position in a face

[Source]

# File mesh.rb, line 1268
def faceonfaceindex(facelist, xnumin, ynumin, xmin, xmax, ymin, ymax)
   # sort [x,y]min/max values
   xmin, xmax = [xmin, xmax].sort
   ymin, ymax = [ymin, ymax].sort
   # test wich faces that are going to be created
   xcelldens = (xmax.to_f - xmin.to_f).abs/xnumin
   ycelldens = (ymax.to_f - ymin.to_f).abs/ynumin
   ok_idx = uncollideparent(facelist, xcelldens, ycelldens, xmin, xmax, ymin, ymax)
   # x discretization
   # should all the x values be thrown in the air? like [xvalues,,,,].sort how do I catch them later on?
   # probably not a good idea... maybe also return x_collided faces in collide output?
   # or every x value is idx-tagged? like [xval, faceidx] -> yes, then they can be sorted without loosing information.
   xvalues = Array.new
   xmesh = Array.new
   ok_idx.each do |idx|
      xvalues.push([ facelist[idx][0].to_f, idx])
      xvalues.push([ facelist[idx][1].to_f, idx])
   end
   noidx = ok_idx.size + 100
   xvalues.push([xmin.to_f, noidx])
   xvalues.push([xmax.to_f, noidx])
   xvalues = xvalues.sort
   (0..xvalues.size-2).each do |idx|
      # add additional points if faceface is bigger than cell density
      # number of added points
      extrapoints = ((xvalues[idx + 1].first - xvalues[idx].first )/ xcelldens).round
      if extrapoints >= 2
         (1..extrapoints-1).each do |extraidx|
            xmesh.push([xvalues[idx].first + (xvalues[idx + 1].first - xvalues[idx].first)*extraidx.to_f/extrapoints, noidx] )
         end
      end
      # no mesh point added if distance to close? how do I do that without losing index information??
      # it has to be resolved later on, I guess
      xmesh.push(xvalues[idx])
   end
   xmesh.push(xvalues.last)
   xmesh = xmesh.sort

   # y discretization
   yvalues = Array.new
   ymesh = Array.new
   ok_idx.each do |idx|
      yvalues.push([ facelist[idx][2].to_f, idx])
      yvalues.push([ facelist[idx][3].to_f, idx])
   end
   yvalues.push([ymin.to_f, noidx])
   yvalues.push([ymax.to_f, noidx])
   yvalues = yvalues.sort
   (0..yvalues.size-2).each do |idx|
      # add additional points if faceface is bigger than cell density
      # number of added points
      extrapoints = ((yvalues[idx + 1].first - yvalues[idx].first )/ ycelldens).round
      if extrapoints >= 2
         (1..extrapoints-1).each do |extraidx|
            ymesh.push([yvalues[idx].first + (yvalues[idx + 1].first - yvalues[idx].first)*extraidx.to_f/extrapoints, noidx] )
         end
      end
      # no mesh point added if distance to close? how do I do that without losing index information??
      # it has to be resolved later on, I guess
      ymesh.push(yvalues[idx])
   end
   ymesh.push(yvalues.last)
   ymesh = ymesh.sort
   # if the points are close enough a new mesh line is not created. That distance is half FACEFACEMINDISTANCE
   # this mindistance is not going to become a constant since it's only important that it is smaller to avoid
   # strange things to happend.
   # temporary [x,y]numout
   xnumout, ynumout = xmesh.size-1, ymesh.size-1
   return xnumout, ynumout, xmesh, ymesh, noidx
end

maybe create a function like connectionmatrix = findStructure4l(@ref) or l0, l1, l2, l3, p0, p1, p2, p3 = findStructure4l(ref)

[Source]

# File mesh.rb, line 2733
   def findStructure4l(ref)
      if ref.size != 4
         puts "ref.size is != 4 in method findStructure4l in module Mesh"
         return 0
      end
      # now I will create an array like:
      # endpoints[idx] = [ lineX, lineX.pX_0, lineX.pX_1 ]
      # maybe I should sort out which point that is start and end point already here
      #@ref.each do |tmp|
      puts "

      findStruct4l begins

      "
      @printlineinfo = true
      def getEndPoints(line)
         if line.class == DefLine
            case line.info[2]
               when "l0"
                  puts "line #{line}, line.info[0].p0 #{line.info[0].p0} line.info[0].p1 #{line.info[0].p1}" if @printlineinfo
                  return [line, line.info[0].p0, line.info[0].p1]
               when "l1"
                  puts "line #{line}, line.info[0].p1 #{line.info[0].p1} line.info[0].p2 #{line.info[0].p2}" if @printlineinfo
                  return [line, line.info[0].p1, line.info[0].p2]
               when "l2"
                  puts "line #{line}, line.info[0].p2 #{line.info[0].p2} line.info[0].p3 #{line.info[0].p3}" if @printlineinfo
                  return [line, line.info[0].p2, line.info[0].p3]
               when "l3"
                  puts "line #{line}, line.info[0].p3 #{line.info[0].p3} line.info[0].p0 #{line.info[0].p0}" if @printlineinfo
                  return [line, line.info[0].p3, line.info[0].p0]
            end
         elsif line.class == InfoLine
            return [line, line.p0, line.p1]
         end
       end
       # first ref is our start line
       @reftmp = Array.new
       ref.each do |line|
          @reftmp.push( getEndPoints(line) )
       end
       def getNextLine(refno, refpno )
          # distance[idx] = [ distance, refno, point (= 1 or 2) ]
          distance = Array.new
          (0..3).each do |line|
             if line != refno
                (1..2).each do |point|
                   # calculate every distance and sort to make the method more stable
                   distance.push( [ vertexDistance(@reftmp[refno][refpno].pos[0], @reftmp[line][point].pos[0]), line, point ] )
                end
             end
          end
          result = distance.sort[0]
          respoint = 2
          puts
          distance.each do |tmp|
             puts "dist #{tmp[0]}, line #{tmp[1]}, point #{tmp[2]}"
          end
          if result[2] == 2
             lineno = result[1]
             respoint = 1
          end
          return result[1], respoint
       end
       l0 = @reftmp[0][0]
       p0 = @reftmp[0][1]
       p1 = @reftmp[0][2]
       nextlineno, nextpointno = getNextLine(0, 2)
       l1 = @reftmp[nextlineno][0]
       p2 = @reftmp[nextlineno][nextpointno]
       nextlineno, nextpointno = getNextLine(nextlineno, nextpointno)
       l2 = @reftmp[nextlineno][0]
       p3 = @reftmp[nextlineno][nextpointno]
       nextlineno, nextpointno = getNextLine(nextlineno, nextpointno)
       l3 = @reftmp[nextlineno][0]
       #p3 = @reftmp[nextlineno][nextpointno]
       unless fourdifferent(l0,l1,l2,l3)
         puts "THERE ARE NOT FOUR DIFFERENT LINES!!!"
         break
       end
       return l0, l1, l2, l3, p0, p1, p2, p3
   end

[Source]

# File mesh.rb, line 2603
   def findStructure4lalt(ref)
      printstring = "find4l(l0,"
      @lines = Array.new
      ref.each do |reftmp|
         @lines.push( getEndPointsAlt( nil, reftmp ) )
      end
      # maybe use [ array ].member?<already assigned>
      @l0, @p0, @p1 = @lines[0]
      @linecheck = Array.new
      @linecheck.push(0)
      @l1, @l2, @l3 = nil, nil, nil
      @p2, @p3 = nil, nil
      (0..@lines.size - 1).each do |lineno|
         if @p1 == @lines[lineno][1] && !( @linecheck.member?lineno ) && @l1 == nil
            @p2 = @lines[lineno][2]
            @l1 = @lines[lineno][0]
            @linecheck.push(lineno)
            printstring += "l1,"
         end
         if @p1 == @lines[lineno][2] && !( @linecheck.member?lineno ) && @l1 == nil
            @p2 = @lines[lineno][1]
            @l1 = @lines[lineno][0]
            @linecheck.push(lineno)
            printstring += "l1,"
         end
         if @p0 == @lines[lineno][1] && !( @linecheck.member?lineno ) && @l3 == nil
            @p3 = @lines[lineno][2]
            @l3 = @lines[lineno][0]
            @linecheck.push(lineno)
            printstring += "l3,"
         end
         if @p0 == @lines[lineno][2] && !( @linecheck.member?lineno ) && @l3 == nil
            @p3 = @lines[lineno][1]
            @l3 = @lines[lineno][0]
            @linecheck.push(lineno)
            printstring += "l3,"
         end
      end
      (0..@lines.size - 1).each do |lineno|
         if @p2 == @lines[lineno][1] && !( @linecheck.member?lineno ) && @l2 == nil
            @p3 = @lines[lineno][2]
            @l2 = @lines[lineno][0]
            @linecheck.push(lineno)
            printstring += "l2,"
         end
         if @p3 == @lines[lineno][1] && !( @linecheck.member?lineno ) && @l2 == nil
            @p2 = @lines[lineno][2]
            @l2 = @lines[lineno][0]
            @linecheck.push(lineno)
            printstring += "l2,"
         end
         if @p2 == @lines[lineno][2] && !( @linecheck.member?lineno ) && @l2 == nil
            @p3 = @lines[lineno][1]
            @l2 = @lines[lineno][0]
            @linecheck.push(lineno)
            printstring += "l2,"
         end
         if @p3 == @lines[lineno][2] && !( @linecheck.member?lineno ) && @l2 == nil
            @p2 = @lines[lineno][1]
            @l2 = @lines[lineno][0]
            @linecheck.push(lineno)
            printstring += "l2,"
         end
      end
      (0..@lines.size - 1).each do |lineno|
         if @p2 == @lines[lineno][1] && !( @linecheck.member?lineno ) && @l1 == nil && @l3 != nil
            @l1 = @lines[lineno][0]
            @linecheck.push(lineno)
            printstring += "l1,"
         end
         if @p3 == @lines[lineno][1] && !( @linecheck.member?lineno ) && @l3 == nil && @l1 != nil
            @l3 = @lines[lineno][0]
            @linecheck.push(lineno)
            printstring += "l3,"
         end
         if @p2 == @lines[lineno][2] && !( @linecheck.member?lineno ) && @l1 == nil && @l3 != nil
            @l1 = @lines[lineno][0]
            @linecheck.push(lineno)
            printstring += "l1,"
         end
         if @p3 == @lines[lineno][2] && !( @linecheck.member?lineno ) && @l3 == nil && @l1 != nil
            @l3 = @lines[lineno][0]
            @linecheck.push(lineno)
            printstring += "l3,"
         end
      end
??
      if false
         puts "stucture 4l start"
         puts @linecheck
         puts @l0
         puts @l1
         puts @l2
         puts @l3
         puts @p0
         puts @p1
         puts @p2
         puts @p3
         puts "stucture 4l end"
      end
      unless fourdifferent(@l0,@l1,@l2,@l3)
         puts "THERE ARE NOT FOUR DIFFERENT LINES!!! alt"
         puts @l0
         puts @l1
         puts @l2
         puts @l3
         break
      end
      printstring.chop!
      printstring += ") "
      print printstring
      return @l0, @l1, @l2, @l3, @p0, @p1, @p2, @p3
   end

find structure of cube find internal faces ifX if0, if1, .. = findStructure6f(ref)

[Source]

# File mesh.rb, line 2828
   def findStructure6f(ref)
      intface = Array.new
      intface[0] = InternalFace.new(0, 0, ref[0],nil)
      (0..3).each do |line|
         closeface = whichFace(ref[0], line, ref)
         closetype = whichFaceConnection(ref[0], line, closeface)
         # maybe intfaceX an array?? and maybe points in faces also an Array p[0] to p[3] instead of p0 to p3
         intface[line+1] = InternalFace.new(closetype, line + 1, closeface,nil)
      end
      # intface[5] requires special attention
      # intface type = 0 line 2
      # intface type = 1 line 3
      # intface type = 2 line 0
      # intface type = 3 line 1
      # intface type = 4 line 2
      # intface type = 5 line 3
      # intface type = 6 line 0 
      # intface type = 7 line 1
      case intface[1].type
         when 0
            line = 2
         when 1
            line = 3
         when 2
            line = 0
         when 3
            line = 1
         when 4
            line = 2
         when 5
            line = 3
         when 6
            line = 0
         when 7
            line = 1
      end
      closeface = whichFace(intface[1].parent, line, ref)
      closetype = whichFaceConnection(intface[1].parent, line, closeface)
      intface[5] = InternalFace.new(closetype, 5, closeface, intface[1].type)
      return intface
   end

given four lines with shared endpoints. Structure them. even if too many lines are given it should work

[Source]

# File mesh.rb, line 2548
   def findUnconnectedPoints(ref)
      @lines = Array.new
      ref.each do |reftmp|
         @lines.push( getEndPointsAlt( nil, reftmp ) )
      end
      @endlines = Array.new
      (0..@lines.size - 1).each do |line1|      
         @neighbours = 0
         (0..@lines.size - 1).each do |line2|      
            if line1 != line2
               if @lines[line1][1] == @lines[line2][1] || @lines[line1][1] == @lines[line2][2] || @lines[line1][2] == @lines[line2][1] || @lines[line1][2] == @lines[line2][2] 
                  @neighbours += 1
               end
            end
         end
         # got an endline?
         if @neighbours == 1
            @endlines.push(@lines[line1])
         end
      end
      (0..@lines.size - 1).each do |idx|
         line = @lines[idx][0]
         if @endlines[0][0] != line && @endlines[1][0] != line
            @midline = @lines[idx]
         end
      end
      if @endlines[0][1] != @midline[1] && @endlines[0][1] != @midline[2] 
         p0 = @endlines[0][1]
         p1 = @endlines[0][2]
      else
         p0 = @endlines[0][2]
         p1 = @endlines[0][1]
      end
      if @endlines[1][1] != @midline[1] && @endlines[1][1] != @midline[2] 
         p2 = @endlines[1][2]
         p3 = @endlines[1][1]
      else
         p2 = @endlines[1][1]
         p3 = @endlines[1][2]
      end
      
      l0 = @endlines[0][0]
      l1 = @midline[0]
      l2 = @endlines[1][0]
      puts "endlines size #{@endlines.size}"

      puts "l0 #{l0}"
      puts "l1 #{l1}"
      puts "l2 #{l2}"
      puts "p0 #{p0}"
      puts "p1 #{p1}"
      puts "p2 #{p2}"
      puts "p3 #{p3}"
      return l0, l1, l2, p0, p1, p2, p3
   end

create faceface lXdef. facefaceldef on format [ [ldef ff 0], [ldef ff 1], … ] where ldef ff X is [ l0def, l1def, l2def, ld3def ]. lXdef is [ point0, point1, point2, .. ] ff ldef is created from the cells. (maybe just create all l0def on cell underside and then remove the wrong ones?) find next point in line definition celldef -> single faceface cell definition cellno -> current cell lno -> l0, l1, l2 or l3

[Source]

# File mesh.rb, line 1789
   def findldef(celldef1)
      if celldef1.size == 0
         return 0
      end
      @celldef = celldef1
      def findnextl0(currentcell)
         ressize = @res0.size
         (0..@celldef.size-1).each do |cellno1|
            if @celldef[cellno1][0] == @celldef[currentcell][1] && cellno1 != currentcell
               @res0.push(@celldef[cellno1][1])
               @cell0.push(cellno1)
               break
            end
         end
         if ressize == @res0.size
            @flag = false
         end
      end
      def findnextl1(currentcell)
         ressize = @res1.size
         (0..@celldef.size-1).each do |cellno1|
            if @celldef[cellno1][1] == @celldef[currentcell][2] && cellno1 != currentcell
               @res1.push(@celldef[cellno1][2])
               @cell1.push(cellno1)
               break
            end
         end
         if ressize == @res1.size
            @flag = false
         end
      end
      def findnextl2(currentcell)
         ressize = @res2.size
         (0..@celldef.size-1).each do |cellno1|
            if @celldef[cellno1][2] == @celldef[currentcell][3] && cellno1 != currentcell
               @res2.push(@celldef[cellno1][3])
               @cell2.push(cellno1)
               break
            end
         end
         if ressize == @res2.size
            @flag = false
         end
      end
      def findnextl3(currentcell)
         ressize = @res3.size
         (0..@celldef.size-1).each do |cellno1|
            if @celldef[cellno1][3] == @celldef[currentcell][0]  && cellno1 != currentcell
               @res3.push(@celldef[cellno1][0])
               @cell3.push(cellno1)
               break
            end
         end
         if ressize == @res3.size
            @flag = false
         end
      end
      @res0 = Array.new
      @res0.push( celldef[0][0] )
      @res0.push( celldef[0][1] )
      @cell0 = Array.new
      @cell0.push(0)
      @flag = true
      while @flag
         findnextl0(@cell0.last)
      end
      @res1 = Array.new
      @res1.push( celldef[@cell0.last][1] )
      @res1.push( celldef[@cell0.last][2] )
      @cell1 = Array.new
      @cell1.push(@cell0.last)
      @flag = true
      while @flag
         findnextl1(@cell1.last)
      end
      @res2 = Array.new
      @res2.push( celldef[@cell1.last][2] )
      @res2.push( celldef[@cell1.last][3] )
      @cell2 = Array.new
      @cell2.push(@cell1.last)
      @flag = true
      while @flag
         findnextl2(@cell2.last)
      end
      @res3 = Array.new
      @res3.push( celldef[@cell2.last][3] )
      @res3.push( celldef[@cell2.last][0] )
      @cell3 = Array.new
      @cell3.push(@cell2.last)
      @flag = true
      while @flag
         findnextl3(@cell3.last)
      end




      print "\nl0 vertices "
      @res0.each do |vert1|
         print vert1, ", "
      end
      print "\nl0 cells "
      @cell0.each do |celltmp|
         print celltmp, ", "
      end
      print "\nl1 vertices "
      @res1.each do |vert1|
         print vert1, ", "
      end
      print "\nl1 cells "
      @cell1.each do |celltmp|
         print celltmp, ", "
      end
      print "\nl2 vertices "
      @res2.each do |vert1|
         print vert1, ", "
      end
      print "\nl2 cells "
      @cell2.each do |celltmp|
         print celltmp, ", "
      end
      print "\nl3 vertices "
      @res3.each do |vert1|
         print vert1, ", "
      end
      print "\nl3 cells "
      @cell3.each do |celltmp|
         print celltmp, ", "
      end
      return @res0, @res1, @res2, @res3
   end

create faceface lXdef. facefaceldef on format [ [ldef ff 0], [ldef ff 1], … ] where ldef ff X is [ l0def, l1def, l2def, ld3def ]. lXdef is [ point0, point1, point2, .. ] ff ldef is created from the cells. (maybe just create all l0def on cell underside and then remove the wrong ones?) find next point in line definition celldef -> single faceface cell definition cellno -> current cell lno -> l0, l1, l2 or l3

[Source]

# File mesh.rb, line 1504
   def findldef(celldef1)
      if celldef1.size == 0
         return 0
      end
      @celldef = celldef1
      def findnextl0(currentcell)
         ressize = @res0.size
         (0..@celldef.size-1).each do |cellno1|
            if @celldef[cellno1][0] == @celldef[currentcell][1] && cellno1 != currentcell
               @res0.push(@celldef[cellno1][1])
               @cell0.push(cellno1)
               break
            end
         end
         if ressize == @res0.size
            @flag = false
         end
      end
      def findnextl1(currentcell)
         ressize = @res1.size
         (0..@celldef.size-1).each do |cellno1|
            if @celldef[cellno1][1] == @celldef[currentcell][2] && cellno1 != currentcell
               @res1.push(@celldef[cellno1][2])
               @cell1.push(cellno1)
               break
            end
         end
         if ressize == @res1.size
            @flag = false
         end
      end
      def findnextl2(currentcell)
         ressize = @res2.size
         (0..@celldef.size-1).each do |cellno1|
            if @celldef[cellno1][2] == @celldef[currentcell][3] && cellno1 != currentcell
               @res2.push(@celldef[cellno1][3])
               @cell2.push(cellno1)
               break
            end
         end
         if ressize == @res2.size
            @flag = false
         end
      end
      def findnextl3(currentcell)
         ressize = @res3.size
         (0..@celldef.size-1).each do |cellno1|
            if @celldef[cellno1][3] == @celldef[currentcell][0]  && cellno1 != currentcell
               @res3.push(@celldef[cellno1][0])
               @cell3.push(cellno1)
               break
            end
         end
         if ressize == @res3.size
            @flag = false
         end
      end
      @res0 = Array.new
      @res0.push( celldef[0][0] )
      @res0.push( celldef[0][1] )
      @cell0 = Array.new
      @cell0.push(0)
      @flag = true
      while @flag
         findnextl0(@cell0.last)
      end
      @res1 = Array.new
      @res1.push( celldef[@cell0.last][1] )
      @res1.push( celldef[@cell0.last][2] )
      @cell1 = Array.new
      @cell1.push(@cell0.last)
      @flag = true
      while @flag
         findnextl1(@cell1.last)
      end
      @res2 = Array.new
      @res2.push( celldef[@cell1.last][2] )
      @res2.push( celldef[@cell1.last][3] )
      @cell2 = Array.new
      @cell2.push(@cell1.last)
      @flag = true
      while @flag
         findnextl2(@cell2.last)
      end
      @res3 = Array.new
      @res3.push( celldef[@cell2.last][3] )
      @res3.push( celldef[@cell2.last][0] )
      @cell3 = Array.new
      @cell3.push(@cell2.last)
      @flag = true
      while @flag
         findnextl3(@cell3.last)
      end

      return @res0, @res1, @res2, @res3
   end

[Source]

# File mesh.rb, line 1794
      def findnextl0(currentcell)
         ressize = @res0.size
         (0..@celldef.size-1).each do |cellno1|
            if @celldef[cellno1][0] == @celldef[currentcell][1] && cellno1 != currentcell
               @res0.push(@celldef[cellno1][1])
               @cell0.push(cellno1)
               break
            end
         end
         if ressize == @res0.size
            @flag = false
         end
      end

[Source]

# File mesh.rb, line 1509
      def findnextl0(currentcell)
         ressize = @res0.size
         (0..@celldef.size-1).each do |cellno1|
            if @celldef[cellno1][0] == @celldef[currentcell][1] && cellno1 != currentcell
               @res0.push(@celldef[cellno1][1])
               @cell0.push(cellno1)
               break
            end
         end
         if ressize == @res0.size
            @flag = false
         end
      end

[Source]

# File mesh.rb, line 1807
      def findnextl1(currentcell)
         ressize = @res1.size
         (0..@celldef.size-1).each do |cellno1|
            if @celldef[cellno1][1] == @celldef[currentcell][2] && cellno1 != currentcell
               @res1.push(@celldef[cellno1][2])
               @cell1.push(cellno1)
               break
            end
         end
         if ressize == @res1.size
            @flag = false
         end
      end

[Source]

# File mesh.rb, line 1522
      def findnextl1(currentcell)
         ressize = @res1.size
         (0..@celldef.size-1).each do |cellno1|
            if @celldef[cellno1][1] == @celldef[currentcell][2] && cellno1 != currentcell
               @res1.push(@celldef[cellno1][2])
               @cell1.push(cellno1)
               break
            end
         end
         if ressize == @res1.size
            @flag = false
         end
      end

[Source]

# File mesh.rb, line 1535
      def findnextl2(currentcell)
         ressize = @res2.size
         (0..@celldef.size-1).each do |cellno1|
            if @celldef[cellno1][2] == @celldef[currentcell][3] && cellno1 != currentcell
               @res2.push(@celldef[cellno1][3])
               @cell2.push(cellno1)
               break
            end
         end
         if ressize == @res2.size
            @flag = false
         end
      end

[Source]

# File mesh.rb, line 1820
      def findnextl2(currentcell)
         ressize = @res2.size
         (0..@celldef.size-1).each do |cellno1|
            if @celldef[cellno1][2] == @celldef[currentcell][3] && cellno1 != currentcell
               @res2.push(@celldef[cellno1][3])
               @cell2.push(cellno1)
               break
            end
         end
         if ressize == @res2.size
            @flag = false
         end
      end

[Source]

# File mesh.rb, line 1548
      def findnextl3(currentcell)
         ressize = @res3.size
         (0..@celldef.size-1).each do |cellno1|
            if @celldef[cellno1][3] == @celldef[currentcell][0]  && cellno1 != currentcell
               @res3.push(@celldef[cellno1][0])
               @cell3.push(cellno1)
               break
            end
         end
         if ressize == @res3.size
            @flag = false
         end
      end

[Source]

# File mesh.rb, line 1833
      def findnextl3(currentcell)
         ressize = @res3.size
         (0..@celldef.size-1).each do |cellno1|
            if @celldef[cellno1][3] == @celldef[currentcell][0]  && cellno1 != currentcell
               @res3.push(@celldef[cellno1][0])
               @cell3.push(cellno1)
               break
            end
         end
         if ressize == @res3.size
            @flag = false
         end
      end

finds the closest vertexes in two arrays with vectors in it don‘t search through all of l1,l2 , maybe provide initial guess findvertex(l1,l2,guess1,guess2)

[Source]

# File mesh.rb, line 1152
   def findvertex(l1,l2,guess1,guess2)
      perfectmatch = false
      guess1 *= $meshinterpolationfactor
      guess2 *= $meshinterpolationfactor
      if  [(l1[0][guess1]-l2[0][guess2]).abs, (l1[1][guess1]-l2[1][guess2]).abs, (l1[2][guess1]-l2[2][guess2]).abs].max < $perfectmatchtol
         # puts "perfectmatch is true"
         return [ l1[0][guess1], l1[1][guess1], l1[2][guess1] ]
      end
      idx1low = [guess1 - $meshfindwideness, 1 ].max
      idx2low = [guess2 - $meshfindwideness, 1 ].max
      idx1high = [guess1 + $meshfindwideness, l1[0].size-2 ].min
      idx2high = [guess2 + $meshfindwideness, l2[0].size-2 ].min
      firsttime = true
      vertexrank = Array.new
      (idx1low..idx1high).each do |idx1|
         (idx2low..idx2high).each do |idx2|
            # access x points in l1 with l1[0][idx]
            cheapdistance = [(l1[0][idx1]-l2[0][idx2]).abs, 
                (l1[1][idx1]-l2[1][idx2]).abs, 
                (l1[2][idx1]-l2[2][idx2]).abs].max
            #cheapdistance = vertexDistance([l1[0][idx1], l1[1][idx1], l1[2][idx1]],[l2[0][idx1], l2[1][idx1], l2[2][idx1] ])
            # store the nearest vertices
            if firsttime
               vertexrank = [cheapdistance,idx1,idx2]
               firsttime = false
            else
               if cheapdistance < vertexrank[0]
                  vertexrank = [cheapdistance,idx1,idx2]
               end
            end
         end
      end
      idx1 = vertexrank[1]
      idx2 = vertexrank[2]
      return [ (l1[0][idx1]+l2[0][idx2])/2.0, (l1[1][idx1]+l2[1][idx2])/2.0, (l1[2][idx1]+l2[2][idx2])/2.0 ]
      #return [ l1[0][idx1], l1[1][idx1], l1[2][idx1] ]
      #return [ l2[0][idx2], l2[1][idx2], l2[2][idx2] ]
   end

linearspace with flip dir true

[Source]

# File mesh.rb, line 159
   def flipspace(pos0,pos1,meshnum,csys)
      newp0 = pos0
      newp1 = pos1
      if csys.csystype == 1 || csys.csystype == 2
         if pos0[1].abs > pos1[1].abs
            newp0[1] = pos0[1] - 360.0
         else
            newp1[1] = pos1[1] - 360.0
         end
         linearspace(newp0,newp1,meshnum)
      else
         linearspace(pos0,pos1,meshnum)
      end
   end

[Source]

# File mesh.rb, line 2814
   def fourdifferent(no0, no1, no2, no3)
     items = [no0, no1, no2, no3]
     (0..3).each do |idx0|
       (idx0..2).each do |idx1|
          if ( items[idx0] == items[idx1] ) && idx0 != idx1
             return false
          end
       end
     end
     return true
   end

[Source]

# File mesh.rb, line 2748
      def getEndPoints(line)
         if line.class == DefLine
            case line.info[2]
               when "l0"
                  puts "line #{line}, line.info[0].p0 #{line.info[0].p0} line.info[0].p1 #{line.info[0].p1}" if @printlineinfo
                  return [line, line.info[0].p0, line.info[0].p1]
               when "l1"
                  puts "line #{line}, line.info[0].p1 #{line.info[0].p1} line.info[0].p2 #{line.info[0].p2}" if @printlineinfo
                  return [line, line.info[0].p1, line.info[0].p2]
               when "l2"
                  puts "line #{line}, line.info[0].p2 #{line.info[0].p2} line.info[0].p3 #{line.info[0].p3}" if @printlineinfo
                  return [line, line.info[0].p2, line.info[0].p3]
               when "l3"
                  puts "line #{line}, line.info[0].p3 #{line.info[0].p3} line.info[0].p0 #{line.info[0].p0}" if @printlineinfo
                  return [line, line.info[0].p3, line.info[0].p0]
            end
         elsif line.class == InfoLine
            return [line, line.p0, line.p1]
         end
       end

[Source]

# File mesh.rb, line 2483
   def getEndPoints(line)
      # have to have something better for 4l faces than first/lastpoints 
      # maybe firstpoint(<face in context>,<line>)
      if line.class == DefLine || line.class == InfoLine
         return [ line, line.firstpoint, line.lastpoint ]
      end
   end

[Source]

# File mesh.rb, line 2538
   def getEndPointsAlt(face, line)
      # have to have something better for 4l faces than first/lastpoints 
      # maybe firstpoint(<face in context>,<line>)
      @face, @line = face, line
      if @line.class == DefLine || @line.class == InfoLine
         return [ @line, endpoint(@face, @line, true), endpoint(@face, @line, false) ]
      end
   end

[Source]

# File mesh.rb, line 2773
       def getNextLine(refno, refpno )
          # distance[idx] = [ distance, refno, point (= 1 or 2) ]
          distance = Array.new
          (0..3).each do |line|
             if line != refno
                (1..2).each do |point|
                   # calculate every distance and sort to make the method more stable
                   distance.push( [ vertexDistance(@reftmp[refno][refpno].pos[0], @reftmp[line][point].pos[0]), line, point ] )
                end
             end
          end
          result = distance.sort[0]
          respoint = 2
          puts
          distance.each do |tmp|
             puts "dist #{tmp[0]}, line #{tmp[1]}, point #{tmp[2]}"
          end
          if result[2] == 2
             lineno = result[1]
             respoint = 1
          end
          return result[1], respoint
       end

i, j test instead

[Source]

# File mesh.rb, line 1437
   def idxToIJ(cellno, l0def, l1def, imax, jmax)
      l0size = l0def.size - 1
      l1size = l1def.size - 1
      i0 = cellno % l0size
      j0 = (cellno / l0size).truncate
      i1 = i0 + 1
      j1 = j0 + 1
      xmin = imax * i0 / l0size
      xmax = imax * i1 / l0size
      ymin = jmax * j0 / l1size
      ymax = jmax * j1 / l1size
      return xmin, xmax, ymin, ymax 
   end
 test-begin
 i,j 0,0 at i,j=0
 j 0, i 0..isize
 j 1, i 0..isize

(0..facefacecelldef.size-1).each do |ffidx| facefacecelldef[ffidx].each do |celidx|

[Source]

# File mesh.rb, line 1665
         def jplus(jpos)
            if jpos == 0
               return 0
            else
               return jpos + 1
            end
         end

[Source]

# File mesh.rb, line 2401
   def ldef(vertex)
      l0seg = Array.new
      l1seg = Array.new
      l2seg = Array.new
      l3seg = Array.new
      # from celldef ??
      # test in a irb session
      ilength = vertex.length
      jlength = vertex[0].length
      alot = ilength*(jlength-1)
      (0..ilength-2).each do |xind|
         l0seg.push([xind,xind+1])
         l2seg.push([xind+alot+1,xind+alot])
      end
      l2seg = l2seg.reverse
      (0..jlength*ilength-ilength-1).step(ilength) do |yind|
         l1seg.push([yind+ilength-1, yind+2*ilength-1])
         l3seg.push([yind+ilength, yind])
      end
      l3seg = l3seg.reverse
      return l0seg, l1seg, l2seg, l3seg
   end

linearspace(pos0(Array), pos1(Array), meshnum(Fixnum))

[Source]

# File mesh.rb, line 125
   def linearspace(pos0,pos1,meshnum)
      # puts "p0 #{p0}, p1 #{p1}"
      if meshnum < 2
         meshnum = 2
      end
      # distance between points
      begin
         xrange = pos1[0] - pos0[0]
         yrange = pos1[1] - pos0[1]
         zrange = pos1[2] - pos0[2]
      rescue
         xrange = 10.0
         yrange = 10.0
         zrange = 10.0
      end
      # fill vectors with distances
      xpoints = Array.new
      ypoints = Array.new
      zpoints = Array.new
      xstep = xrange.to_f/(meshnum-1)
      ystep = yrange.to_f/(meshnum-1)
      zstep = zrange.to_f/(meshnum-1)
      (0..meshnum-1).each do |num|
         xpoints.push(pos0[0]+num*xstep)
         ypoints.push(pos0[1]+num*ystep)
         zpoints.push(pos0[2]+num*zstep)
      end
      #puts "linearspace"
      #print3vectors(xpoints, ypoints, zpoints)
      return xpoints, ypoints, zpoints
   end

[Source]

# File mesh.rb, line 38
   def linemeshpoints(csys,p0,p1,meshnum)
      if meshnum < 2
         meshnum = 2
      end
      # distance between points
      tmp0 = invPositionInCsys(csys,p0.pos[0])
      tmp1 = invPositionInCsys(csys,p1.pos[0])
      case csys.csystype
         when 1
            if tmp1[1] < tmp0[1]
               tmp1[1] += 360.0
            end
         when 2
            if tmp1[1] < tmp0[1]
               tmp1[1] += 360.0
            end
            # didn't work so good
            #if tmp1[2] < tmp0[2]
               #tmp1[2] += 360.0
            #end
      end
      #xrange = p1.inpos[0] -p0.inpos[0]
      #yrange = p1.inpos[1] -p0.inpos[1]
      #zrange = p1.inpos[2] -p0.inpos[2]
      xrange = tmp1[0] - tmp0[0]
      yrange = tmp1[1] - tmp0[1]
      zrange = tmp1[2] - tmp0[2]
      # fill vectors with distances
      xpoints = Vector.elements( (0..(meshnum-1)).to_a )*(xrange.to_f/(meshnum-1).to_f)
      ypoints = Vector.elements( (0..(meshnum-1)).to_a )*(yrange.to_f/(meshnum-1).to_f)
      zpoints = Vector.elements( (0..(meshnum-1)).to_a )*(zrange.to_f/(meshnum-1).to_f)
      # adjust position of vectors so it starts at point @p0
      ones = Array.new
      (0..meshnum-1).each do |i|
         ones[i]=1.0
      end
      x0pos = Vector.elements(ones)* tmp0[0].to_f
      y0pos = Vector.elements(ones)* tmp0[1].to_f
      z0pos = Vector.elements(ones)* tmp0[2].to_f
      xpoints += x0pos
      ypoints += y0pos
      zpoints += z0pos
      # print3vectors(xpoints,ypoints,zpoints)
??
      return Vector.elements(xpoints).to_a, Vector.elements(ypoints).to_a, Vector.elements(zpoints).to_a
      #return Vector.elements(xarr), Vector.elements(yarr), Vector.elements(zarr)
   end

[Source]

# File mesh.rb, line 96
   def linemeshpointsRealCsys(csys,p0,p1,meshnum)
      puts "p0 #{p0}, p1 #{p1}"
      if meshnum < 2
         meshnum = 2
      end
      # distance between points
      xrange = p1.pos[0][0] -p0.pos[0][0]
      yrange = p1.pos[0][1] -p0.pos[0][1]
      zrange = p1.pos[0][2] -p0.pos[0][2]
      # fill vectors with distances
      xpoints = Vector.elements( (0..(meshnum-1)).to_a )*(xrange.to_f/(meshnum-1).to_f)
      ypoints = Vector.elements( (0..(meshnum-1)).to_a )*(yrange.to_f/(meshnum-1).to_f)
      zpoints = Vector.elements( (0..(meshnum-1)).to_a )*(zrange.to_f/(meshnum-1).to_f)
      # adjust position of vectors so it starts at point @p0
      ones = Array.new
      (0..meshnum-1).each do |i|
         ones[i]=1.0
      end
      x1pos = Vector.elements(ones)* p0.pos[0][0].to_f
      y1pos = Vector.elements(ones)* p0.pos[0][1].to_f
      z1pos = Vector.elements(ones)* p0.pos[0][2].to_f
      xpoints += x1pos
      ypoints += y1pos
      zpoints += z1pos
      return xpoints.to_a, ypoints.to_a, zpoints.to_a
   end

[Source]

# File mesh.rb, line 2458
      def makedef(lXtmp)
         ltmp = Array.new
         (0..lXtmp.size-2).each do |slice1|
            ltmp.push(lXtmp[(slice1)..(slice1+1)])
         end
         return ltmp
      end

meshline is created in RealCsys (inRealCsys), a radius in a cylindrical/spherica coordinate system had no real meaning. meshline cases csys cartesian, linear discretization between points csys cyl or spherical, discretized between points in spherical or cylindrical space line has a radius, discretization arount specificed axis

[Source]

# File mesh.rb, line 249
   def meshline(csys,p0,p1,meshnum,radius,xaxis,yaxis,zaxis,refattr,parent,self1)

      # correct too small radius
      # mesh method input p0, [x,y,z]range, meshnum, 
      # returns celldef and vertex. Or the GLViewer objects
      if radius == nil
         # to be continued
         # puts "cystype #{csys.csystype}"
         if csys.csystype == "normal"
            x,y,z = linemeshpointsRealCsys(csys,p0,p1,meshnum)
         else
            x,y,