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

Method convertRangeToCurves

src/core/objects/object.cpp:2132–2229  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2130}
2131
2132PathPart::size_type PathObject::convertRangeToCurves(const PathPart& part, PathPart::size_type start_index, PathPart::size_type end_index)
2133{
2134 Q_ASSERT(end_index > start_index);
2135
2136 Q_ASSERT(!coords[start_index].isCurveStart());
2137 coords[start_index].setCurveStart(true);
2138
2139 // Special case: last coordinate
2140 MapCoord direction;
2141 if (end_index != part.last_index)
2142 {
2143 // Use direction of next segment
2144 direction = coords[end_index + 1] - coords[end_index];
2145 }
2146 else if (part.isClosed())
2147 {
2148 // Use average direction at close point
2149 direction = coords[part.first_index + 1] - coords[end_index - 1];
2150 }
2151 else
2152 {
2153 // Use direction of last segment
2154 direction = coords[end_index] - coords[end_index - 1];
2155 }
2156
2157 MapCoordF tangent = MapCoordF(direction);
2158 tangent.normalize();
2159
2160 MapCoord end_handle = coords[end_index];
2161 end_handle.setFlags(0);
2162 auto baseline = (coords[end_index] - coords[end_index - 1]).length() * BEZIER_HANDLE_DISTANCE;
2163 end_handle = end_handle - MapCoord(tangent * baseline);
2164
2165 // Special case: first coordinate
2166 if (start_index != part.first_index)
2167 {
2168 // Use direction of previous segment
2169 direction = coords[start_index] - coords[start_index - 1];
2170 }
2171 else if (part.isClosed())
2172 {
2173 // Use average direction at close point
2174 direction = coords[start_index + 1] - coords[part.last_index - 1];
2175 }
2176 else
2177 {
2178 // Use direction of first segment
2179 direction = coords[start_index + 1] - coords[start_index];
2180 }
2181
2182 tangent = MapCoordF(direction);
2183 tangent.normalize();
2184
2185 MapCoord handle = coords[start_index];
2186 handle.setFlags(0);
2187 baseline = (coords[start_index + 1] - coords[start_index]).length() * BEZIER_HANDLE_DISTANCE;
2188 handle = handle + MapCoord(tangent * baseline);
2189 addCoordinate(start_index + 1, handle);

Callers

nothing calls this directly

Calls 8

isCurveStartMethod · 0.80
setCurveStartMethod · 0.80
setFlagsMethod · 0.80
MapCoordFClass · 0.50
MapCoordClass · 0.50
isClosedMethod · 0.45
normalizeMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected