tPut contact check into dedicated and reusable function - Granular.jl - Julia package for granular dynamics simulation
 (HTM) git clone git://src.adamsgaard.dk/Granular.jl
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 0ca0e4abf901666fd3795f8b126be72e52645352
 (DIR) parent 026453ac365e0acd332634c91088f60639517aec
 (HTM) Author: Anders Damsgaard <andersd@riseup.net>
       Date:   Thu, 21 Dec 2017 14:57:50 -0500
       
       Put contact check into dedicated and reusable function
       
       Diffstat:
         M src/contact_search.jl               |      55 +++++++++++++++++++++++++++++++
       
       1 file changed, 55 insertions(+), 0 deletions(-)
       ---
 (DIR) diff --git a/src/contact_search.jl b/src/contact_search.jl
       t@@ -145,6 +145,61 @@ function findContactsInGrid!(simulation::Simulation, grid::Any)
            nothing
        end
        
       +
       +export checkForContacts
       +"""
       +    checkForContacts(grid, position, radius)
       +
       +Perform an O(n*log(n)) cell-based contact search between a candidate grain with
       +position `position` and `radius`, against all grains registered in the `grid`.
       +Returns `true` if no contacts were found, and `false` if contacts were found.
       +
       +# Arguments
       +* `grid::Any`: `Ocean` or `Atmosphere` grid containing sorted particles.
       +* `position::Vector{Float64}`: Candidate center position to probe for contacts
       +    with existing grains [m].
       +* `radius::Float64`: Candidate radius [m].
       +"""
       +function checkForContacts(grid::Any, x_candidate::Vector{Float64},
       +                          r_candidate::Float64)
       +
       +    sw = zeros(2); se = zeros(2); ne = zeros(2); nw = zeros(2)
       +    distance_modifier = zeros(2)
       +    no_overlaps_found = true
       +
       +    # Inter-grain position vector and grain overlap
       +    ix, iy = findCellContainingPoint(grid, x_candidate, sw, se, ne, nw)
       +
       +    # Check for overlap with existing grains
       +    for ix_=(ix - 1):(ix + 1)
       +        for iy_=(iy - 1):(iy + 1)
       +
       +            # correct indexes if necessary
       +            ix_corrected, iy_corrected =
       +                periodicBoundaryCorrection!(grid, ix_, iy_, distance_modifier)
       +
       +            # skip iteration if target still falls outside grid after
       +            # periodicity correction
       +            if ix_corrected < 1 || ix_corrected > nx ||
       +                iy_corrected < 1 || iy_corrected > ny
       +                continue
       +            end
       +
       +            @inbounds for idx in grid.grain_list[ix_corrected, iy_corrected]
       +                if norm(simulation.grains[idx].lin_pos - x_candidate +
       +                    distance_modifier) -
       +                    (simulation.grains[idx].contact_radius +
       +                     r_candidate) < 0.
       +
       +                    no_overlaps_found = false
       +                    break  # overlap: skip this candidate
       +                end
       +            end
       +        end
       +    end
       +    return no_overlaps_found
       +end
       +
        """
            periodicBoundaryCorrection!(grid::Any, i::Integer, j::Integer,
                                        i_corrected::Integer, j_corrected::Integer,