# A New Approach to Detect Hand-Drawn Dashed Lines in Engineering Sketches
## 4 Non-Solid Line Clustering
### Chaining Dashed Strokes  
Chains of strokes are calculated recursively by adding new strokes that must meet the following criteria: (1) they should not have been previously visited (which is easily achieved by labeling the dashes already visited); (2) their length must align with the current range (candidate dashes must fall inside the range [DashLengthMin, DashLengthMax], as explained previously); (3) they must be consecutive to one of the tips of the current chain of dashes (without overlapping or being too distant), by falling inside the range [DashGapMin, DashGapMax], as explained earlier; and (4) they should exhibit a similar orientation to previous dashes, within a specified angle and offset. We next describe in detail the procedures that guarantee that the last two conditions are satisfied. * Consecutiveness verification:  
The new stroke must be _consecutive_ (continue or precede, not overlapping) to the current chain (which may contain more than one stroke). Furthermore, the gap, which represents the minimum distance between the new stroke**[i]** and the chain, as illustrated in Figure 7, must fall within the range defined by the calculated maximum and minimum gap, as per Equation (4). The decision is made following the Algorithm 3:
```
1:gap = min(F0, F1, L0, L1);
2:if ((gap > DashGapMax)! | (gap < DashGapMin)) then
3: Discard stroke[i]
4:endif
```
**Algorithm 3**Consecutive stroke verification  
Figure 6: Non-straight dash in context. The algorithm verifies the consecutiveness of strokes and checks if they fall within the defined gap range. For valid gaps, their merit (_meritGap_) is calculated as a ramp function that equals 1 for a gap equal to the average gap, while it equals 0 for gaps equal to DashGapMin or DashGapMax (Figure 8). Alignment with current segment:  
The new stroke should also be reasonably _aligned_ with the current chain. To perform this verification, the thresholds derived from the user-configured dashed line search parameters (refer to Section 5) are employed. \[Threshold\Angle[i]=IncreasedTol[i]\textbf{-MaxDashAngle}\]  
\[ThresholdOffset[i]=IncreasedTol[i]\textbf{-MaxDashOffset} \tag{5}\]  
It must be noted that the tolerances used for the thresholds are calculated relative to their lengths. This is performed to automatically adapt the algorithm to detect dashed lines of different sizes, which typically coexist in the same sketch. The calculations are as follows:  
\[IncreasedTol[i]=1+\textbf{IncreasedDashTolerances}\cdot\left(1-\frac{L[i]-Lmin}{L max-Lmin}\right) \tag{6}\]  
where Lmin and Lmax are the minimum and maximum lengths of the candidate strokes, and L[i] is the length of the current stroke. The orientation of stroke[i] should closely match that of the chain segment (Figure 9); therefore, if the difference between both orientations exceeds the threshold, stroke[i] is discarded as outlined in Algorithm 4. ```
1:if ((\(|\alpha-\text{cb}|>\) ThresholdAngle[i]), then
2: stroke[i] is discarded;
3:endif
4:end if
5:end if
6:end for
```
Figure 8: Gap merit ramp function. Figure 7: The gap is the minimum distance between tips of the chain and the new stroke. The algorithm checks for orientation matching between stroke[i] and the chain segment. For valid orientations, their merit (_meritAngle_) is calculated as a ramp function that equals 1 for exactly the same orientation, while it equals 0 for differences in orientation greater than the ThresholdAngle (Figure 10). The offset value is determined as a combination of two factors. For very close lines, the gap line connecting their ends may be far from collinear. Alternatively, for more distant lines, the gap line discriminates poorly, while the step is the parameter that best measures the gap. We assume that when segments are closer to each other, the same step is perceived as more likely intentional.