docs: @SuppressWarnings({"checkstyle:cyclomaticcomplexity", "checkstyle:npathcomplexity"})
  	public final boolean addRoadPolyline(RoadPolyline segment) throws RoadNetworkException {
  		// Check element validity
  		assert segment != null;
  		final RoadNetwork currentNetwork = segment.getRoadNetwork();
  		if (currentNetwork == this) {
  			return false;
  		}
  		if (currentNetwork != null) {
  			throw new RoadNetworkException("segment is already in a road network"); //$NON-NLS-1$;
  		}
  		if (segment.getPointCount() <= 1) {
  			throw new RoadNetworkException("segment has not two points"); //$NON-NLS-1$;
  		}
  
  		// Get segment information
  		StandardRoadConnection startConnection = null;
  		StandardRoadConnection endConnection = null;
  		final Point2d firstPoint;
  		final Point2d lastPoint;
  		try {
  			firstPoint = segment.getFirstPoint();
  			if (firstPoint == null) {
  				throw new RoadNetworkException("segment has not a first point"); //$NON-NLS-1$
  			}
  		} catch (IndexOutOfBoundsException exception) {
  			throw new RoadNetworkException("segment has not a first point"); //$NON-NLS-1$
  		}
  		try {
  			lastPoint = segment.getLastPoint();
  			if (lastPoint == null) {
  				throw new RoadNetworkException("segment has not a last point"); //$NON-NLS-1$
  			}
  		} catch (IndexOutOfBoundsException exception) {
  			throw new RoadNetworkException("segment has not a last point"); //$NON-NLS-1$
  		}
  
  		final OutputParameter<RoadPolyline> firstNeighbour = new OutputParameter<>();
  		final OutputParameter<RoadPolyline> secondNeighbour = new OutputParameter<>();
  
  		if (this.roadSegments.add(
  				segment,
  				RoadNetworkConstants.getPreferredRoadConnectionDistance(),
  				firstNeighbour, secondNeighbour)) {
  			RoadPolyline seg = firstNeighbour.get();
  			if (seg != null) {
  				startConnection = seg.getNearestPoint(StandardRoadConnection.class, firstPoint.getX(), firstPoint.getY());
  			}
  			seg = secondNeighbour.get();
  			if (seg != null) {
  				endConnection = seg.getNearestPoint(StandardRoadConnection.class, lastPoint.getX(), lastPoint.getY());
  			}
  
  			int nbNewConn = 0;
  
  			if (startConnection == null && endConnection == null
  					&& firstPoint.epsilonEquals(lastPoint, MapElementConstants.POINT_FUSION_DISTANCE)) {
  				startConnection = new StandardRoadConnection();
  				endConnection = startConnection;
  				nbNewConn += 2;
  			}
  			if (startConnection == null) {
  				startConnection = new StandardRoadConnection();
  				++nbNewConn;
  			}
  			if (endConnection == null) {
  				endConnection = new StandardRoadConnection();
  				++nbNewConn;
  			}
  
  			try {
  				segment.setRoadNetwork(this);
  				segment.setStartPoint(startConnection);
  				segment.setEndPoint(endConnection);
  				this.connectionCount += nbNewConn;
  			} catch (AssertionError e) {
  				throw e;
  			} catch (Throwable e) {
  				this.roadSegments.remove(segment);
  				throw new RuntimeException(e);
  			}
  
  			Rectangle2d bb = getBoundingBox();
  			if (bb == null) {
  				bb = segment.getBoundingBox();
  			} else {
  				bb = bb.createUnion(segment.getBoundingBox());
  			}
  			setBoundingBox(bb);
  
  			segment.addGISEditableChangeListener(this.eventHandler);
  
  			fireSegmentAdded(segment);
  
  			return true;
  		}
  
  		return false;
  	}