private Rectangle buildRectangle(Rectangle r, double endx, double endy) {

		double x = r.x;
		double y = r.y;

		double w = Math.abs(x - endx);
		double h = Math.abs(y - endy);

		if (w != 0 && h != 0) {
			// already has a size; don't alter it
			r.setSize((int) w, (int) h);
			return r;
		}

		if (h == 0) { // add some height

			if (x > endx) {
				// right-to-left; swap x values, since rectangles are l-to-r
				x = endx;
			}

			y -= 1;
			h = 2;
		}
		else { // add some width

			if (y > endy) {
				// bottom-to-top; swap y values, since rectangles are t-to-b
				y = endy;
			}

			x -= 1;
			w = 2;
		}

		r.setFrame(x, y, w, h);
		return r;
	}
Call when the screen moves so that the shape can be updated
Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/flowarrow/FlowArrow.java