private void RenderAndDeleteTrajectory(ref IntPtr trajectory_iterator,
                              VectorLine vector_line)
 {
     int new_min_draw_index = 0;
     try {
       XYZSegment segment;
       int index_in_line_points = vector_line.points3.Length -
       2 * trajectory_iterator.NumberOfSegments();
       // If the |VectorLine| is too big, make sure we're not keeping garbage.
       for (int i = vector_line.minDrawIndex; i < index_in_line_points; ++i) {
     vector_line.points3[i] = UnityEngine.Vector3.zero;
       }
       while (index_in_line_points < 0) {
     trajectory_iterator.FetchAndIncrement();
     index_in_line_points += 2;
       }
       new_min_draw_index = index_in_line_points;
       vector_line.minDrawIndex = Math.Min(vector_line.minDrawIndex,
                               new_min_draw_index);
       while (!trajectory_iterator.AtEnd()) {
     segment = trajectory_iterator.FetchAndIncrement();
     // TODO(egg): should we do the |LocalToScaledSpace| conversion in
     // native code?
     // TODO(egg): could we directly assign to
     // |vector_line.points3| from C++ using unsafe code and
     // something like the following?
     // |fixed (UnityEngine.Vector3* pts = vector_line.points3)|
     vector_line.points3[index_in_line_points++] =
     ScaledSpace.LocalToScaledSpace((Vector3d)segment.begin);
     vector_line.points3[index_in_line_points++] =
     ScaledSpace.LocalToScaledSpace((Vector3d)segment.end);
       }
     } finally {
       Interface.DeleteLineAndIterator(ref trajectory_iterator);
     }
     if (MapView.Draw3DLines && !force_2d_trajectories_) {
       Vector.DrawLine3D(vector_line);
     } else {
       Vector.DrawLine(vector_line);
     }
     vector_line.minDrawIndex = new_min_draw_index;
 }