You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

147 lines
4.5 KiB

  1. /**
  2. * @file dist.cpp
  3. * @brief Routines to calculate PCB editor auto routing distances.
  4. */
  5. #include <autorout.h>
  6. #include <cell.h>
  7. /* The tables of distances and keep out areas are established on the basis of a
  8. * 50 units grid size (the pitch between the cells is 50 units).
  9. * The actual distance could be computed by a scaling factor, but this is
  10. * not needed, we can use only reduced values
  11. */
  12. /* calculate approximate distance (manhattan distance)
  13. */
  14. int GetApxDist( int r1, int c1, int r2, int c2 )
  15. {
  16. int d1, d2; /* row and column deltas */
  17. if( ( d1 = r1 - r2 ) < 0 ) /* get absolute row delta */
  18. d1 = -d1;
  19. if( ( d2 = c1 - c2 ) < 0 ) /* get absolute column delta */
  20. d2 = -d2;
  21. return ( d1+d2 ) * 50;
  22. }
  23. /* distance to go thru a cell (en mils) */
  24. static const int dist[10][10] =
  25. { /* OT=Otherside, OR=Origin (source) cell */
  26. /*..........N, NE, E, SE, S, SW, W, NW, OT, OR */
  27. /* N */ { 50, 60, 35, 60, 99, 60, 35, 60, 12, 12 },
  28. /* NE */ { 60, 71, 60, 71, 60, 99, 60, 71, 23, 23 },
  29. /* E */ { 35, 60, 50, 60, 35, 60, 99, 60, 12, 12 },
  30. /* SE */ { 60, 71, 60, 71, 60, 71, 60, 99, 23, 23 },
  31. /* S */ { 99, 60, 35, 60, 50, 60, 35, 60, 12, 12 },
  32. /* SW */ { 60, 99, 60, 71, 60, 71, 60, 71, 23, 23 },
  33. /* W */ { 35, 60, 99, 60, 35, 60, 50, 60, 12, 12 },
  34. /* NW */ { 60, 71, 60, 99, 60, 71, 60, 71, 23, 23 },
  35. /* OT */ { 12, 23, 12, 23, 12, 23, 12, 23, 99, 99 },
  36. /* OR */ { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99 }
  37. };
  38. /* penalty for extraneous holes and corners, scaled by sharpness of turn */
  39. static const int penalty[10][10] =
  40. { /* OT=Otherside, OR=Origin (source) cell */
  41. /*......... N, NE, E, SE, S, SW, W, NW, OT, OR */
  42. /* N */ { 0, 5, 10, 15, 20, 15, 10, 5, 50, 0 },
  43. /* NE */ { 5, 0, 5, 10, 15, 20, 15, 10, 50, 0 },
  44. /* E */ { 10, 5, 0, 5, 10, 15, 20, 15, 50, 0 },
  45. /* SE */ { 15, 10, 5, 0, 5, 10, 15, 20, 50, 0 },
  46. /* S */ { 20, 15, 10, 5, 0, 5, 10, 15, 50, 0 },
  47. /* SW */ { 15, 20, 15, 10, 5, 0, 5, 10, 50, 0 },
  48. /* W */ { 10, 15, 20, 15, 10, 5, 0, 5, 50, 0 },
  49. /* NW */ { 5, 10, 15, 20, 15, 10, 5, 0, 50, 0 },
  50. /* OT */ { 50, 50, 50, 50, 50, 50, 50, 50, 100, 0 },
  51. /* OR */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
  52. };
  53. /* penalty pour directions preferencielles */
  54. #define PN 20
  55. static const int dir_penalty_TOP[10][10] =
  56. {
  57. /* OT=Otherside, OR=Origin (source) cell */
  58. /*......... N, NE, E, SE, S, SW, W, NW, OT, OR */
  59. /* N */ { PN, 0, 0, 0, PN, 0, 0, 0, 0, 0 },
  60. /* NE */ { PN, 0, 0, 0, PN, 0, 0, 0, 0, 0 },
  61. /* E */ { PN, 0, 0, 0, PN, 0, 0, 0, 0, 0 },
  62. /* SE */ { PN, 0, 0, 0, PN, 0, 0, 0, 0, 0 },
  63. /* S */ { PN, 0, 0, 0, PN, 0, 0, 0, 0, 0 },
  64. /* SW */ { PN, 0, 0, 0, PN, 0, 0, 0, 0, 0 },
  65. /* W */ { PN, 0, 0, 0, PN, 0, 0, 0, 0, 0 },
  66. /* NW */ { PN, 0, 0, 0, PN, 0, 0, 0, 0, 0 },
  67. /* OT */ { PN, 0, 0, 0, PN, 0, 0, 0, 0, 0 },
  68. /* OR */ { PN, 0, 0, 0, PN, 0, 0, 0, 0, 0 }
  69. };
  70. static int dir_penalty_BOTTOM[10][10] =
  71. {
  72. /* OT=Otherside, OR=Origin (source) cell */
  73. /*......... N, NE, E, SE, S, SW, W, NW, OT, OR */
  74. /* N */ { 0, 0, PN, 0, 0, 0, PN, 0, 0, 0 },
  75. /* NE */ { 0, 0, PN, 0, 0, 0, PN, 0, 0, 0 },
  76. /* E */ { 0, 0, PN, 0, 0, 0, PN, 0, 0, 0 },
  77. /* SE */ { 0, 0, PN, 0, 0, 0, PN, 0, 0, 0 },
  78. /* S */ { 0, 0, PN, 0, 0, 0, PN, 0, 0, 0 },
  79. /* SW */ { 0, 0, PN, 0, 0, 0, PN, 0, 0, 0 },
  80. /* W */ { 0, 0, PN, 0, 0, 0, PN, 0, 0, 0 },
  81. /* NW */ { 0, 0, PN, 0, 0, 0, PN, 0, 0, 0 },
  82. /* OT */ { 0, 0, PN, 0, 0, 0, PN, 0, 0, 0 },
  83. /* OR */ { 0, 0, PN, 0, 0, 0, PN, 0, 0, 0 }
  84. };
  85. /*
  86. ** x is the direction to enter the cell of interest.
  87. ** y is the direction to exit the cell of interest.
  88. ** z is the direction to really exit the cell, if y=FROM_OTHERSIDE.
  89. **
  90. ** return the distance of the trace through the cell of interest.
  91. ** the calculation is driven by the tables above.
  92. */
  93. /* calculate distance (with penalty) of a trace through a cell
  94. */
  95. int CalcDist(int x,int y,int z ,int side )
  96. {
  97. int adjust, ldist;
  98. adjust = 0; /* set if hole is encountered */
  99. if( x == EMPTY )
  100. x = 10;
  101. if( y == EMPTY )
  102. {
  103. y = 10;
  104. }
  105. else if( y == FROM_OTHERSIDE )
  106. {
  107. if( z == EMPTY )
  108. z = 10;
  109. adjust = penalty[x-1][z-1];
  110. }
  111. ldist = dist[x-1][y-1] + penalty[x-1][y-1] + adjust;
  112. if( Nb_Sides )
  113. {
  114. if( side == BOTTOM )
  115. ldist += dir_penalty_TOP[x-1][y-1];
  116. if( side == TOP )
  117. ldist += dir_penalty_BOTTOM[x-1][y-1];
  118. }
  119. return ldist * 10;
  120. }