docs: private static int clipFilter_(EditShape edit_shape,
  			int fixed_vertices_index, int from_vertex, int to_vertex, int dir,
  			double abs_distance, double densify_distance, final int max_filter) {
  		// Note: vertices marked with fixed_vertices_index cannot be deleted.
  
  		Point2D pt1 = edit_shape.getXY(from_vertex);
  		Point2D pt2 = edit_shape.getXY(to_vertex);
  		if (pt1.equals(pt2))
  			return -1;
  
  		double densify_distance_delta = densify_distance * 0.25;// distance by
  																// which we can
  																// move the
  																// point closer
  																// to the chord
  																// (introducing
  																// an error into
  																// the buffer).
  		double erase_distance_delta = densify_distance * 0.25;// distance when
  																// we can erase
  																// the point
  																// (introducing
  																// an error into
  																// the buffer).
  		// This function goal is to modify or remove vertices between
  		// from_vertex and to_vertex in such a way that the result would not
  		// affect buffer to the left of the
  		// chain.
  		Point2D v_gap = new Point2D();
  		v_gap.sub(pt2, pt1);
  		double gap_length = v_gap.length();
  		double h2_4 = gap_length * gap_length * 0.25;
  		double sqr_center_to_chord = abs_distance * abs_distance - h2_4; // squared
  																			// distance
  																			// from
  																			// the
  																			// chord
  																			// to
  																			// the
  																			// circle
  																			// center
  		if (sqr_center_to_chord <= h2_4)
  			return -1;// center to chord distance is less than half gap, that
  						// means the gap is too wide for useful filtering (maybe
  						// this).
  
  		double center_to_chord = Math.sqrt(sqr_center_to_chord); // distance
  																	// from
  																	// circle
  																	// center to
  																	// the
  																	// chord.
  
  		v_gap.normalize();
  		Point2D v_gap_norm = new Point2D(v_gap);
  		v_gap_norm.rightPerpendicular();
  		double chord_to_corner = h2_4 / center_to_chord; // cos(a) =
  															// center_to_chord /
  															// distance;
  															// chord_to_corner =
  															// distance / cos(a)
  															// -
  															// center_to_chord;
  		boolean can_erase_corner_point = chord_to_corner <= erase_distance_delta;
  		Point2D chord_midpoint = new Point2D();
  		MathUtils.lerp(pt2, pt1, 0.5, chord_midpoint);
  		Point2D corner = new Point2D(v_gap_norm);
  		double corrected_chord_to_corner = chord_to_corner
  				- densify_distance_delta;// using slightly smaller than needed
  											// distance let us filter more.
  		corner.scaleAdd(Math.max(0.0, corrected_chord_to_corner),
  				chord_midpoint);
  		// corner = (p1 + p2) * 0.5 + v_gap_norm * chord_to_corner;
  
  		Point2D center = new Point2D(v_gap_norm);
  		center.negate();
  		center.scaleAdd(center_to_chord, chord_midpoint);
  
  		double allowed_distance = abs_distance - erase_distance_delta;
  		double sqr_allowed_distance = MathUtils.sqr(allowed_distance);
  		double sqr_large_distance = sqr_allowed_distance * (1.9 * 1.9);
  
  		Point2D co_p1 = new Point2D();
  		co_p1.sub(corner, pt1);
  		Point2D co_p2 = new Point2D();
  		co_p2.sub(corner, pt2);
  
  		boolean large_distance = false;// set to true when distance
  		int cnt = 0;
  		char[] locations = new char[64];
  		{
  			// check all vertices in the gap verifying that the gap can be
  			// clipped.
  			//
  
  			Point2D pt = new Point2D();
  			// firstly remove any duplicate vertices in the end.
  			for (int v = edit_shape.getPrevVertex(to_vertex, dir); v != from_vertex;) {
  				if (edit_shape.getUserIndex(v, fixed_vertices_index) == 1)
  					return -1;// this range contains protected vertex
  
  				edit_shape.getXY(v, pt);
  				if (pt.equals(pt2)) {
  					int v1 = edit_shape.getPrevVertex(v, dir);
  					edit_shape.removeVertex(v, false);
  					v = v1;
  					continue;
  				} else {
  					break;
  				}
  			}
  
  			Point2D prev_prev_pt = new Point2D();
  			prev_prev_pt.setNaN();
  			Point2D prev_pt = new Point2D();
  			prev_pt.setCoords(pt1);
  			locations[cnt++] = 1;
  			int prev_v = from_vertex;
  			Point2D dummyPt = new Point2D();
  			for (int v = edit_shape.getNextVertex(from_vertex, dir); v != to_vertex;) {
  				if (edit_shape.getUserIndex(v, fixed_vertices_index) == 1)
  					return -1;// this range contains protected vertex
  
  				edit_shape.getXY(v, pt);
  				if (pt.equals(prev_pt)) {
  					int v1 = edit_shape.getNextVertex(v, dir);
  					edit_shape.removeVertex(v, false);
  					v = v1;
  					continue;
  				}
  
  				locations[cnt++] = 0;
  
  				Point2D v1 = new Point2D();
  				v1.sub(pt, pt1);
  				if (v1.dotProduct(v_gap_norm) < 0)// we are crossing on the
  													// wrong site of the chord.
  													// Just bail out earlier.
  													// Maybe we could continue
  													// clipping though here, but
  													// it seems to be
  													// unnecessary complicated.
  					return 0;
  
  				if (Point2D.sqrDistance(pt, pt1) > sqr_large_distance
  						|| Point2D.sqrDistance(pt, pt2) > sqr_large_distance)
  					large_distance = true; // too far from points, may
  											// contribute to the outline (in
  											// case of a large loop)
  
  				char next_location = 0;
  
  				dummyPt.sub(pt, pt1);
  				double cs1 = dummyPt.crossProduct(co_p1);
  				if (cs1 >= 0) {
  					next_location = 1;
  				}
  
  				dummyPt.sub(pt, pt2);
  				double cs2 = dummyPt.crossProduct(co_p2);
  				if (cs2 <= 0) {
  					next_location |= 2;
  				}
  
  				if (next_location == 0)
  					return 0;
  
  				locations[cnt - 1] = next_location;
  				prev_prev_pt.setCoords(prev_pt);
  				prev_pt.setCoords(pt);
  				prev_v = v;
  				v = edit_shape.getNextVertex(v, dir);
  			}
  
  			if (cnt == 1)
  				return 0;
  
  			assert (!pt2.equals(prev_pt));
  			locations[cnt++] = 2;
  		}
  
  		boolean can_clip_all = true;
  		// we can remove all points and replace them with a single corner point
  		// if we are moving from location 1 via location 3 to location 2
  		for (int i = 1, k = 0; i < cnt; i++) {
  			if (locations[i] != locations[i - 1]) {
  				k++;
  				can_clip_all = k < 3
  						&& ((k == 1 && locations[i] == 3) || (k == 2 && locations[i] == 2));
  				if (!can_clip_all)
  					return 0;
  			}
  		}
  
  		if (cnt > 2 && can_clip_all && (cnt == 3 || !large_distance)) {
  			int clip_count = 0;
  			int v = edit_shape.getNextVertex(from_vertex, dir);
  			if (!can_erase_corner_point) {
  				edit_shape.setXY(v, corner);
  				v = edit_shape.getNextVertex(v, dir);
  			}
  
  			// we can remove all vertices between from and to, because they
  			// don't contribute
  			while (v != to_vertex) {
  				int v1 = edit_shape.getNextVertex(v, dir);
  				edit_shape.removeVertex(v, false);
  				v = v1;
  				++clip_count;
  			}
  
  			return clip_count;
  		}
  
  		if (cnt == 3) {
  			boolean case1 = (locations[0] == 1 && locations[1] == 2 && locations[2] == 2);
  			boolean case2 = (locations[0] == 1 && locations[1] == 1 && locations[2] == 2);
  			if (case1 || case2) {
  				// special case, when we cannot clip, but we can move the point
  				Point2D p1 = edit_shape.getXY(from_vertex);
  				int v = edit_shape.getNextVertex(from_vertex, dir);
  				Point2D p2 = edit_shape.getXY(v);
  				Point2D p3 = edit_shape.getXY(edit_shape.getNextVertex(v, dir));
  				if (case2) {
  					Point2D temp = p1;
  					p1 = p3;
  					p3 = temp;
  				}
  
  				Point2D vec = new Point2D();
  				vec.sub(p1, p2);
  				p3.sub(p2);
  				double veclen = vec.length();
  				double w = p3.length();
  				double wcosa = vec.dotProduct(p3) / veclen;
  				double wsina = Math.abs(p3.crossProduct(vec) / veclen);
  				double z = 2 * abs_distance - wsina;
  				if (z < 0)
  					return 0;
  
  				double x = wcosa + Math.sqrt(wsina * z);
  				if (x > veclen)
  					return 0;
  
  				Point2D hvec = new Point2D();
  				hvec.scaleAdd(-x / veclen, vec, p3); // hvec = p3 - vec * (x /
  														// veclen);
  				double h = hvec.length();
  				double y = -(h * h * veclen) / (2 * hvec.dotProduct(vec));
  
  				double t = (x - y) / veclen;
  				MathUtils.lerp(p2, p1, t, p2);
  				edit_shape.setXY(v, p2);
  				return 0;
  			}
  		}
  
  		if (large_distance && cnt > 3) {
  			// we are processing more than 3 points and there are some points
  			// further than the
  			return 0;
  		}
  
  		int v_prev = -1;
  		Point2D pt_prev = new Point2D();
  		int v_cur = from_vertex;
  		Point2D pt_cur = new Point2D(pt1);
  		int cur_location = 1;
  		int prev_location = -1; // 1 - semiplane to the right of [f,c]. 3 -
  								// semiplane to the right of [c,t], 2 - both
  								// above fc and ct, 0 - cannot clip, -1 -
  								// unknown
  		int v_next = v_cur;
  		int clip_count = 0;
  		cnt = 1;
  		while (v_next != to_vertex) {
  			v_next = edit_shape.getNextVertex(v_next, dir);
  			int next_location = locations[cnt++];
  			if (next_location == 0) {
  				if (v_next == to_vertex)
  					break;
  
  				continue;
  			}
  
  			Point2D pt_next = edit_shape.getXY(v_next);
  
  			if (prev_location != -1) {
  				int common_location = (prev_location & cur_location & next_location);
  				if ((common_location & 3) != 0) {
  					// prev and next are on the same semiplane as the current we
  					// can safely remove the current point.
  					edit_shape.removeVertex(v_cur, true);
  					clip_count++;// do not change prev point.
  					v_cur = v_next;
  					pt_cur.setCoords(pt_next);
  					cur_location = next_location;
  					continue;
  				}
  
  				if (cur_location == 3 && prev_location != 0
  						&& next_location != 0) {
  					assert ((prev_location & next_location) == 0);// going from
  																	// one semi
  																	// plane to
  																	// another
  																	// via the
  																	// mid.
  					pt_cur.setCoords(corner);
  					if (can_erase_corner_point || pt_cur.equals(pt_prev)) {// this
  																			// point
  																			// can
  																			// be
  																			// removed
  						edit_shape.removeVertex(v_cur, true);
  						clip_count++;// do not change prev point.
  						v_cur = v_next;
  						pt_cur.setCoords(pt_next);
  						cur_location = next_location;
  						continue;
  					} else {
  						edit_shape.setXY(v_cur, pt_cur); // snap to the corner
  					}
  				} else {
  					if (next_location == 0
  							&& cur_location != 0
  							|| next_location != 0
  							&& cur_location == 0
  							|| ((next_location | cur_location) == 3
  									&& next_location != 3 && cur_location != 3)) {
  						// clip
  					}
  				}
  			}
  
  			prev_location = cur_location;
  			v_prev = v_cur;
  			pt_prev.setCoords(pt_cur);
  			v_cur = v_next;
  			cur_location = next_location;
  			pt_cur.setCoords(pt_next);
  		}
  
  		return clip_count;
  	}