public VectorTileFeature Clip(VectorTileFeature feature, double scale, double k1, double k2, int axis, Func <double[], double[], double, double[]> intersect, double minAll, double maxAll) { k1 /= scale; k2 /= scale; if (minAll >= k1 && maxAll <= k2) { return(feature); // trivial accept } else if (minAll > k2 || maxAll < k1) { return(null); // trivial reject } // var geometry = feature.Geometry; var type = feature.Type; var min = feature.Min[axis]; var max = feature.Max[axis]; if (min >= k1 && max <= k2) { // trivial accept return(feature); } else if (min > k2 || max < k1) { return(null); // trivial reject } var slices = type == 1 ? clipPoints(feature.GetPoints(), k1, k2, axis) : clipGeometry(feature.GetRings(), k1, k2, axis, intersect, type == 3); if ((slices.Length == 1) ? slices[0].Count > 0 : slices.Length > 0) { // if a feature got clipped, it will likely get clipped on the next zoom level as well, // so there's no need to recalculate bboxes return(new VectorTileFeature { Geometry = slices, Type = type, Tags = feature.Tags, Min = feature.Min, Max = feature.Max }); } return(null); }
private VectorTileFeature CalcBBox(VectorTileFeature feature) { // var geometry = feature.Geome; var min = feature.Min; var max = feature.Max; if (feature.Type == 1) { CalcRingBBox(min, max, feature.GetPoints()); } else { var geometry = feature.GetRings(); for (var i = 0; i < geometry.Length; i++) { CalcRingBBox(min, max, geometry[i]); } } return(feature); }
private VectorTileFeature ShiftFeatureCoords(VectorTileFeature feature, double offset) { var newFeatures = new List <VectorTileFeature>(); var type = feature.Type; if (type == 1) { return(new VectorTileFeature { Geometry = ShiftCoords(feature.GetPoints(), offset), Type = type, Tags = feature.Tags, Min = new[] { feature.Min[0] + offset, feature.Min[1] }, Max = new[] { feature.Max[0] + offset, feature.Max[1] } }); } var newGeometry = new List <VectorTileGeometry>(); var rings = feature.GetRings(); for (var j = 0; j < rings.Length; j++) { newGeometry.Add(ShiftCoords(rings[j], offset)); } return(new VectorTileFeature { Geometry = newGeometry.ToArray(), Type = type, Tags = feature.Tags, Min = new[] { feature.Min[0] + offset, feature.Min[1] }, Max = new[] { feature.Max[0] + offset, feature.Max[1] } }); }