MCPcopy Create free account
hub / github.com/OpenOrienteering/mapper / copyLengths

Method copyLengths

src/core/virtual_path.cpp:767–835  ·  view source on GitHub ↗

This algorithm must (nearly) match VirtualPath::copy(). (It will always copy the length of the starting point, but VirtualPath::copy() might skip this point in some cases.)

Source from the content-addressed store, hash-verified

765// (It will always copy the length of the starting point, but
766// VirtualPath::copy() might skip this point in some cases.)
767void VirtualPath::copyLengths(
768 const SplitPathCoord& first,
769 const SplitPathCoord& last,
770 std::vector<PathCoord::length_type>& out_lengths ) const
771{
772 Q_ASSERT(!empty());
773 Q_ASSERT(first.path_coords == &path_coords);
774 Q_ASSERT(last.path_coords == &path_coords);
775
776 auto& flags = coords.flags;
777
778 // Handle first coordinate
779 out_lengths.emplace_back(first.clen);
780
781 bool after_curve_start = false;
782
783 if (first.index == last.index)
784 {
785 after_curve_start = last.is_curve_end && last.param != first.param;
786 }
787 else
788 {
789 after_curve_start = first.is_curve_start;
790
791 auto stop_index = last.index;
792 if (last.param == 0.0f)
793 {
794 stop_index -= last.is_curve_end ? 3 : 1;
795 }
796
797 auto index = first.index + 1;
798 if (first.is_curve_start && index < stop_index)
799 {
800 after_curve_start = false;
801 out_lengths.emplace_back(first.clen);
802 out_lengths.emplace_back(first.clen);
803 index += 2;
804 }
805
806 auto path_coord_index = first.path_coord_index;
807 for (; index <= stop_index; ++index)
808 {
809 while (path_coords[path_coord_index].index < index)
810 ++path_coord_index;
811
812 if (path_coords[path_coord_index].index == index)
813 {
814 // Normal node
815 out_lengths.emplace_back(path_coords[path_coord_index].clen);
816 after_curve_start = flags[index].isCurveStart();
817 }
818 else
819 {
820 // Control point
821 out_lengths.emplace_back(out_lengths.back());
822 after_curve_start = false;
823 }
824 }

Callers 1

createPointedLineCapMethod · 0.80

Calls 2

isCurveStartMethod · 0.80
backMethod · 0.80

Tested by

no test coverage detected