public LCSGeometryDiffImpl(@Nullable Geometry oldGeom, @Nullable Geometry newGeom) { String oldText = oldGeom == null ? "" : oldGeom.toText(); String newText = newGeom == null ? "" : newGeom.toText(); diffMatchPatch = new DiffMatchPatch(); LinkedList<Diff> diffs = diffMatchPatch.diff_main(oldText, newText); patches = diffMatchPatch.patch_make(diffs); // to calculate number of edits in the geometry, we do a diffing based on a string // representation of the coordinates of the geometry, instead of the WKT. // This is more more practical for counting added/removed/edited points and generating a // human-readable and easy-to-parse string representation of the diff. // NOTE! This is limited to geometries with less than 65535 different points, and might // yield wrong results for geometries over that limit. // This is a temporary hack, until a better solution is developed. oldText = geomToStringOfCoordinates(oldGeom); newText = geomToStringOfCoordinates(newGeom); LinesToCharsResult chars = coordsToChars(oldText, newText); diffs = diffMatchPatch.diff_main(chars.chars1, chars.chars2); charsToCoords(diffs, chars.lineArray); processDiffs(diffs); }
public LCSGeometryDiffImpl(@Nullable Geometry oldGeom, @Nullable Geometry newGeom) { String oldText = oldGeom == null ? "" : oldGeom.toText(); String newText = newGeom == null ? "" : newGeom.toText(); diffMatchPatch = new DiffMatchPatch(); LinkedList<Diff> diffs = diffMatchPatch.diff_main(oldText, newText); patches = diffMatchPatch.patch_make(diffs); // to calculate number of edits in the geometry, we do a diffing based on a string // representation of the coordinates of the geometry, instead of the WKT. // This is more more practical for counting added/removed/edited points and generating a // human-readable and easy-to-parse string representation of the diff. // NOTE! This is limited to geometries with less than 65535 different points, and might // yield wrong results for geometries over that limit. // This is a temporary hack, until a better solution is developed. oldText = geomToStringOfCoordinates(oldGeom); newText = geomToStringOfCoordinates(newGeom); LinesToCharsResult chars = coordsToChars(oldText, newText); diffs = diffMatchPatch.diff_main(chars.chars1, chars.chars2); charsToCoords(diffs, chars.lineArray); processDiffs(diffs); }