nismod / snail

spatial networks impact assessment library 🐌
https://nismod.github.io/snail/
MIT License
9 stars 1 forks source link

Fix splitting when intersection point falls on on grid crossing #28

Closed tlestang closed 2 years ago

tlestang commented 2 years ago
  // Linestring points are marked by o:
  // Intersection points are marked by (o):
  // +---------------+--------------+
  // |               |              |
  // |               |              |
  // |               |              |
  // |               |       o      |
  // |               |              |
  // |               |              |
  // |               |              |
  // +--------------(o)--------------+
  // |               |              |
  // |               |              |
  // |               |              |
  // |       o       |              |
  // |               |              |
  // |               |              |
  // |               |              |
  // +---------------+--------------+
  // (0,0)         (1,0)          (2,0)

At the moment the intersection point is registered twice:

    // In function findIntersections (grid.hpp) 
    // If pE.length() == pN.length() the else case is executed twice for point pE and pN
    while (pE.length() <= length || pN.length() <= length) {
      if (pE.length() < pN.length()) {
        crossings.push_back(line.start + pE);
        dE += double(east - 1) * cellsize_x;
        pE = geometry::Vec2<double>(dE, dE * rise / run);
      } else {
        crossings.push_back(line.start + pN);
        dN += double(north - 1) * cellsize_y;
        pN = geometry::Vec2<double>(dN * run / rise, dN);
      }