docs: static int linearPathIntersectsLinearPathMaxDim_(MultiPath _multipathA,
  			MultiPath _multipathB, double tolerance,
  			AttributeStreamOfDbl intersections) {
  		MultiPath multipathA;
  		MultiPath multipathB;
  
  		if (_multipathA.getSegmentCount() > _multipathB.getSegmentCount()) {
  			multipathA = _multipathB;
  			multipathB = _multipathA;
  		} else {
  			multipathA = _multipathA;
  			multipathB = _multipathB;
  		}
  
  		SegmentIteratorImpl segIterA = ((MultiPathImpl) multipathA._getImpl())
  				.querySegmentIterator();
  		SegmentIteratorImpl segIterB = ((MultiPathImpl) multipathB._getImpl())
  				.querySegmentIterator();
  		double[] scalarsA = new double[2];
  		double[] scalarsB = new double[2];
  
  		int dim = -1;
  
  		int ievent = 0;
  		double overlapLength;
  		AttributeStreamOfInt32 eventIndices = new AttributeStreamOfInt32(0);
  		RelationalOperations relOps = new RelationalOperations();
  		OverlapComparer overlapComparer = new OverlapComparer(relOps);
  		OverlapEvent overlapEvent;
  
  		Envelope2D env_a = new Envelope2D();
  		Envelope2D env_b = new Envelope2D();
  		Envelope2D envInter = new Envelope2D();
  		multipathA.queryEnvelope2D(env_a);
  		multipathB.queryEnvelope2D(env_b);
  		env_a.inflate(tolerance, tolerance);
  		env_b.inflate(tolerance, tolerance);
  		envInter.setCoords(env_a);
  		envInter.intersect(env_b);
  
  		Point2D int_point = null;
  
  		if (intersections != null) {
  			int_point = new Point2D();
  		}
  
  		QuadTreeImpl qtB = null;
  		QuadTreeImpl quadTreeB = null;
          QuadTreeImpl quadTreePathsB = null;
  
  		GeometryAccelerators accel = ((MultiPathImpl) multipathB._getImpl())
  				._getAccelerators();
  
  		if (accel != null) {
  			quadTreeB = accel.getQuadTree();
              quadTreePathsB = accel.getQuadTreeForPaths();
  			if (quadTreeB == null) {
  				qtB = InternalUtils.buildQuadTree(
  						(MultiPathImpl) multipathB._getImpl(), envInter);
  				quadTreeB = qtB;
  			}
  		} else {
  			qtB = InternalUtils.buildQuadTree(
  					(MultiPathImpl) multipathB._getImpl(), envInter);
  			quadTreeB = qtB;
  		}
  
  		QuadTreeImpl.QuadTreeIteratorImpl qtIterB = quadTreeB.getIterator();
  
          QuadTreeImpl.QuadTreeIteratorImpl qtIterPathsB = null;
          if (quadTreePathsB != null)
              qtIterPathsB = quadTreePathsB.getIterator();
  
  		while (segIterA.nextPath()) {
  			overlapLength = 0.0;
  
  			while (segIterA.hasNextSegment()) {
  				Segment segmentA = segIterA.nextSegment();
  				segmentA.queryEnvelope2D(env_a);
  
  				if (!env_a.isIntersecting(envInter)) {
  					continue;
  				}
  
                  if (qtIterPathsB != null) {
                      qtIterPathsB.resetIterator(env_a, tolerance);
  
                      if (qtIterPathsB.next() == -1)
                          continue;
                  }
  
  				double lengthA = segmentA.calculateLength2D();
  
  				qtIterB.resetIterator(segmentA, tolerance);
  
  				for (int elementHandleB = qtIterB.next(); elementHandleB != -1; elementHandleB = qtIterB
  						.next()) {
  					int vertex_b = quadTreeB.getElement(elementHandleB);
  					segIterB.resetToVertex(vertex_b);
  
  					Segment segmentB = segIterB.nextSegment();
  					double lengthB = segmentB.calculateLength2D();
  
  					int result = segmentA.intersect(segmentB, null, scalarsA,
  							scalarsB, tolerance);
  
  					if (result > 0) {
  						double scalar_a_0 = scalarsA[0];
  						double scalar_b_0 = scalarsB[0];
  						double scalar_a_1 = (result == 2 ? scalarsA[1]
  								: NumberUtils.TheNaN);
  						double scalar_b_1 = (result == 2 ? scalarsB[1]
  								: NumberUtils.TheNaN);
  
  						if (result == 2) {
  							if (lengthA * (scalar_a_1 - scalar_a_0) > tolerance) {
  								dim = 1;
  								return dim;
  							}
  
  							// Quick neighbor check
  							double length = lengthA * (scalar_a_1 - scalar_a_0);
  
  							if (segIterB.hasNextSegment()) {
  								segmentB = segIterB.nextSegment();
  								result = segmentA.intersect(segmentB, null,
  										scalarsA, null, tolerance);
  
  								if (result == 2) {
  									double nextScalarA0 = scalarsA[0];
  									double nextScalarA1 = scalarsA[1];
  
  									double lengthNext = lengthA
  											* (nextScalarA1 - nextScalarA0);
  
  									if (length + lengthNext > tolerance) {
  										dim = 1;
  										return dim;
  									}
  								}
  
  								segIterB.resetToVertex(vertex_b);
  								segIterB.nextSegment();
  							}
  
  							if (!segIterB.isFirstSegmentInPath()) {
  								segIterB.previousSegment();
  								segmentB = segIterB.previousSegment();
  								result = segmentA.intersect(segmentB, null,
  										scalarsA, null, tolerance);
  
  								if (result == 2) {
  									double nextScalarA0 = scalarsA[0];
  									double nextScalarA1 = scalarsA[1];
  
  									double lengthPrevious = lengthA
  											* (nextScalarA1 - nextScalarA0);
  
  									if (length + lengthPrevious > tolerance) {
  										dim = 1;
  										return dim;
  									}
  								}
  
  								segIterB.resetToVertex(vertex_b);
  								segIterB.nextSegment();
  							}
  
  							if (segIterA.hasNextSegment()) {
  								int vertex_a = segIterA.getStartPointIndex();
  								segmentA = segIterA.nextSegment();
  								result = segmentA.intersect(segmentB, null,
  										scalarsA, null, tolerance);
  
  								if (result == 2) {
  									double nextScalarA0 = scalarsA[0];
  									double nextScalarA1 = scalarsA[1];
  
  									double lengthNext = lengthA
  											* (nextScalarA1 - nextScalarA0);
  
  									if (length + lengthNext > tolerance) {
  										dim = 1;
  										return dim;
  									}
  								}
  
  								segIterA.resetToVertex(vertex_a);
  								segIterA.nextSegment();
  							}
  
  							if (!segIterA.isFirstSegmentInPath()) {
  								int vertex_a = segIterA.getStartPointIndex();
  								segIterA.previousSegment();
  								segmentA = segIterA.previousSegment();
  								result = segmentA.intersect(segmentB, null,
  										scalarsA, null, tolerance);
  
  								if (result == 2) {
  									double nextScalarA0 = scalarsA[0];
  									double nextScalarA1 = scalarsA[1];
  
  									double lengthPrevious = lengthB
  											* (nextScalarA1 - nextScalarA0);
  
  									if (length + lengthPrevious > tolerance) {
  										dim = 1;
  										return dim;
  									}
  								}
  
  								segIterA.resetToVertex(vertex_a);
  								segIterA.nextSegment();
  							}
  
  							int ivertex_a = segIterA.getStartPointIndex();
  							int ipath_a = segIterA.getPathIndex();
  							int ivertex_b = segIterB.getStartPointIndex();
  							int ipath_b = segIterB.getPathIndex();
  
  							overlapEvent = OverlapEvent.construct(ivertex_a,
  									ipath_a, scalar_a_0, scalar_a_1, ivertex_b,
  									ipath_b, scalar_b_0, scalar_b_1);
  							relOps.m_overlap_events.add(overlapEvent);
  							eventIndices.add(eventIndices.size());
  						}
  
  						dim = 0;
  
  						if (intersections != null) {
  							segmentA.getCoord2D(scalar_a_0, int_point);
  							intersections.add(int_point.x);
  							intersections.add(int_point.y);
  						}
  					}
  				}
  
  				if (ievent < relOps.m_overlap_events.size()) {
  					eventIndices.Sort(ievent, eventIndices.size(),
  							overlapComparer);
  
  					double lastScalar = 0.0;
  					int lastPath = relOps.m_overlap_events.get(eventIndices
  							.get(ievent)).m_ipath_a;
  
  					for (int i = ievent; i < relOps.m_overlap_events.size(); i++) {
  						overlapEvent = relOps.m_overlap_events.get(eventIndices
  								.get(i));
  
  						if (overlapEvent.m_scalar_a_0 < lastScalar
  								&& overlapEvent.m_scalar_a_1 < lastScalar) {
  							continue;
  						}
  
  						if (lengthA * (overlapEvent.m_scalar_a_0 - lastScalar) > tolerance) {
  							overlapLength = lengthA
  									* (overlapEvent.m_scalar_a_1 - overlapEvent.m_scalar_a_0); // reset
  							lastScalar = overlapEvent.m_scalar_a_1;
  							lastPath = overlapEvent.m_ipath_a;
  						} else {
  							if (overlapEvent.m_ipath_a != lastPath) {
  								overlapLength = lengthA
  										* (overlapEvent.m_scalar_a_1 - overlapEvent.m_scalar_a_0); // reset
  								lastPath = overlapEvent.m_ipath_a;
  							} else {
  								overlapLength += lengthA
  										* (overlapEvent.m_scalar_a_1 - overlapEvent.m_scalar_a_0); // accumulate
  							}
  							if (overlapLength > tolerance) {
  								dim = 1;
  								return dim;
  							}
  
  							lastScalar = overlapEvent.m_scalar_a_1;
  
  							if (lastScalar == 1.0) {
  								break;
  							}
  						}
  					}
  
  					if (lengthA * (1.0 - lastScalar) > tolerance) {
  						overlapLength = 0.0; // reset
  					}
  					ievent = 0;
  					eventIndices.resize(0);
  					relOps.m_overlap_events.clear();
  				}
  			}
  		}
  
  		return dim;
  	}