Class WorldGraphicsUtils
Coordinate systems
The MDI framework maintains two coordinate systems for each view:
- World coordinates — the application's logical coordinate
space (kilometres, degrees, arbitrary units, etc.), represented by
doublevalues andPoint2D.Double. - Local (screen/pixel) coordinates — the pixel space of the
rendered component, represented by
intvalues andPoint.
Conversion between the two spaces is handled by
IContainer.worldToLocal(java.awt.Point, java.awt.geom.Point2D.Double) and IContainer.localToWorld(java.awt.Point, java.awt.geom.Point2D.Double).
Every drawing method in this class accepts world coordinates and performs
the conversion internally before issuing Java2D drawing calls.
Graphics context
All methods that perform drawing accept a Graphics2D context
directly. No internal casting from Graphics is performed.
The sole exception is drawImageOnQuad(java.awt.Graphics2D, java.awt.image.BufferedImage, java.awt.geom.Point2D.Double[], edu.cnu.mdi.container.IContainer), which calls
Graphics.create() — a method declared on
Graphics that returns Graphics — and
therefore requires a cast back to Graphics2D for the child context.
This is unavoidable and is the only cast in the class.
Null colors
Where fill and line colors are accepted separately, passing null
suppresses that part of the drawing. For example, a null fill
color produces an unfilled (outline-only) shape, and a null line
color produces a filled shape with no outline.
Path support
Several methods operate on Path2D.Double objects. These methods
support only straight-segment paths composed of
SEG_MOVETO, SEG_LINETO, and SEG_CLOSE segments.
If a path contains curve segments (SEG_QUADTO or
SEG_CUBICTO) an IllegalArgumentException is thrown rather
than producing silently incorrect results.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic doublearea(Point2D.Double[] poly) Compute the signed area of a polygon using the shoelace formula.static doubleccwSweepDeg(Point2D.Double wpc, Point2D.Double wp1, Point2D.Double wp2) Compute the counter-clockwise (CCW) sweep angle in degrees from vector(wpc→wp1)to vector(wpc→wp2).static Point2D.DoubleReturn the point on segmenta→bthat is closest top.static booleancontains(Point2D.Double[] poly, Point2D.Double wp) Test whether a world point lies inside a polygon.static PolygoncreateWorldArc(IContainer container, double xc, double yc, double radius, double startAngle, double stopAngle) Build a screenPolygonapproximating a world-coordinate arc (a portion of a circle's circumference).static PolygoncreateWorldCircle(IContainer container, double xc, double yc, double radius) Build a screenPolygonapproximating a world-coordinate circle.static PolygoncreateWorldDonut(IContainer container, double xc, double yc, double minRadius, double maxRadius) Build a screenPolygonapproximating a world-coordinate donut (annulus).static voiddrawEtchedHorizontalWorldLine(Graphics2D g2, IContainer container, double x, double y, double w, boolean lightAbove) Draw a horizontal "etched" line in world coordinates.static voiddrawEtchedVerticalWorldLine(Graphics2D g2, IContainer container, double x, double y, double h, boolean lightLeft) Draw a vertical "etched" line in world coordinates.static voiddrawHighlightedRectangle(Graphics2D g2, IContainer container, Rectangle2D.Double wr, Color color1, Color color2) Draw the outline of a highlighted (marching-ants style) world rectangle.static voiddrawImageOnQuad(Graphics2D g2, BufferedImage image, Point2D.Double[] wpoly, IContainer container) Draw aBufferedImagemapped onto an arbitrary world-coordinate quadrilateral.static PolygondrawPath2D(Graphics2D g2, IContainer container, Path2D.Double path, IStyled style, boolean closed) Draw a straight-segment world path as either a closed polygon or an open polyline, deriving style from anIStyledobject.static PolygondrawPath2D(Graphics2D g2, IContainer container, Path2D.Double path, Color fillColor, Color lineColor, float lineWidth, LineStyle lineStyle, boolean closed) Draw a straight-segment world path as either a closed polygon or an open polyline, with explicit style parameters.static voiddrawWorldLine(Graphics2D g2, IContainer container, double x1, double y1, double x2, double y2, IStyled style) Draw a styled world line between two coordinate pairs.static voiddrawWorldLine(Graphics2D g2, IContainer container, double x1, double y1, double x2, double y2, Color lineColor) Draw a 1-pixel solid world line between two coordinate pairs.static voiddrawWorldLine(Graphics2D g2, IContainer container, double x1, double y1, double x2, double y2, Color lineColor, float lineWidth, LineStyle lineStyle) Draw a world line with explicit color, width, and dash style.static voiddrawWorldLine(Graphics2D g2, IContainer container, Point2D.Double wp0, Point2D.Double wp1, IStyled style) Draw a styled world line between twoPoint2D.Doubleendpoints.static voiddrawWorldLine(Graphics2D g2, IContainer container, Point2D.Double wp0, Point2D.Double wp1, Color lineColor) Draw a 1-pixel solid world line between twoPoint2D.Doubleendpoints.static voiddrawWorldOval(Graphics2D g2, IContainer container, Rectangle2D.Double worldRectangle, IStyled style) Draw a world oval using anIStyledsource for style properties.static voiddrawWorldOval(Graphics2D g2, IContainer container, Rectangle2D.Double worldRectangle, Color fillColor, Color lineColor) Draw a world oval with a 1-pixel solid outline.static voiddrawWorldOval(Graphics2D g2, IContainer container, Rectangle2D.Double worldRectangle, Color fillColor, Color lineColor, float lineWidth, LineStyle lineStyle) Draw a world oval with explicit style parameters.static voiddrawWorldPolygon(Graphics2D g2, IContainer container, WorldPolygon worldPolygon, Color fillColor, Color lineColor, float lineWidth) Draw a world polygon with a 1-pixel solid outline.static voiddrawWorldPolygon(Graphics2D g2, IContainer container, WorldPolygon worldPolygon, Color fillColor, Color lineColor, float lineWidth, LineStyle lineStyle) Draw a world polygon with explicit style parameters.static voiddrawWorldRadArc(Graphics2D g2, IContainer container, double xc, double yc, double rmin, double rmax, double startAngle, double stopAngle, IStyled style) Draw a radar arc (annular sector) using anIStyledsource for fill color, line color, line width, and line style.static voiddrawWorldRadArc(Graphics2D g2, IContainer container, double xc, double yc, double rmin, double rmax, double startAngle, double stopAngle, Color fillColor, Color lineColor) Draw a radar arc (annular sector) with a 1-pixel solid outline.static voiddrawWorldRadArc(Graphics2D g2, IContainer container, double xc, double yc, double rmin, double rmax, double startAngle, double stopAngle, Color fillColor, Color lineColor, float lineWidth, LineStyle lineStyle) Draw a radar arc (annular sector) with explicit style parameters.static voiddrawWorldRectangle(Graphics2D g2, IContainer container, Rectangle2D.Double worldRectangle, IStyled style) Draw a world rectangle using anIStyledsource for style properties.static voiddrawWorldRectangle(Graphics2D g2, IContainer container, Rectangle2D.Double worldRectangle, Color fillColor, Color lineColor) Draw a world rectangle with a 1-pixel solid outline.static voiddrawWorldRectangle(Graphics2D g2, IContainer container, Rectangle2D.Double worldRectangle, Color fillColor, Color lineColor, float lineWidth, LineStyle lineStyle) Draw a world rectangle with explicit style parameters.static voiddrawWorldText(Graphics2D g2, IContainer container, double x, double y, String text, int dh, int dv) Draw a string anchored at a world coordinate with a pixel offset.static Point2D.Double[]getArcPoints(Point2D.Double wpc, Point2D.Double wp1, double arcAngle) Build an array of world points approximating a simple arc sweep.static RectanglegetBounds(IContainer container, double x1, double y1, double x2, double y2) Compute the pixel bounding rectangle for a line between two world coordinate pairs.static RectanglegetBounds(IContainer container, Point2D.Double wp0, Point2D.Double wp1) Compute the pixel bounding rectangle for a line between two world points.static Point2D.DoublegetCentroid(Path2D.Double path) Compute the centroid of a straight-segment path.static Point2D.DoublegetCentroid(Point2D.Double[] poly) Compute the centroid of a polygon.static Point2D.Double[]getEllipsePoints(double w, double h, double azimuth, int numFill, Point2D.Double center) Build an array of world points approximating an ellipse.static doublegetMeanPixelDensity(IContainer container) Estimate the pixel density of the container in pixels per world unit.static Point2D.DoublegetPathPointAt(Path2D.Double path, int index) Return the world-coordinate vertex at the specified zero-based index in a straight-segment path.static intCount the explicit vertex points in a straight-segmentPath2D.Double.static voidgetPixelEnds(IContainer container, Point p0, Point p1, Point2D.Double wp0, Point2D.Double wp1) Convert two world endpoints to their pixel equivalents.static ArrayList<Point2D.Double> Extract the vertices of a straight-segmentPath2Das a list.static Point2D.Double[]Return the four corners of a world rectangle as a point array.static Point2D.Double[]getRadArcPoints(Point2D.Double wpc, Point2D.Double wp1, double arcAngle) Build an array of world points approximating a radar-arc sweep.static Point2D.Doubleintersection(Point2D.Double p1, Point2D.Double p2, Point2D.Double q1, Point2D.Double q2) Compute the intersection point of two line segments.static booleanisPointNearPath(Path2D.Double path, Point2D.Double wp, double tolWorld) Test whether a world point lies within a given tolerance of any segment in a straight-segmentPath2D.Double.static doublelongestDiagonal(Point2D.Double focus, Point2D.Double[] poly) Compute the distance fromfocusto the farthest vertex of a polygon.static intneededCapacity(Path2D.Double path) Return the capacity (vertex count) needed to store a straight-segment path in a flat array.static PolygonpathToPolygon(IContainer container, Path2D.Double path) Convert a straight-segment world path to a screenPolygon.static Point2D.Double[]Extract the world-coordinate vertices of a straight-segment path as a new array.static voidpathToWorldPolygon(Path2D.Double path, Point2D.Double[] wp) Copy the world-coordinate vertices of a straight-segment path into a pre-allocated array.static Point2D.DoublepolygonIntersection(Point2D.Double p0, double azimuth, Path2D.Double path) Find the first intersection of a ray with a world path.static Point2D.DoublepolygonIntersection(Point2D.Double p0, double azimuth, Point2D.Double[] poly) Find the first intersection of a ray with a world polygon.static voidproject(Point2D.Double focus, double distance, double angle, Point2D.Double wp) Project a world point by a distance and azimuth angle.static Point2D.DoubleradiusPoint(Point2D.Double center, double radius, double theta) Create a world point at a given distance and polar angle from a center.static voidReset the graphics context to the MDI default drawing style.static doublesignedSweepDeg(Point2D.Double wpc, Point2D.Double wp1, Point2D.Double wp2) Compute the signed sweep angle in degrees from vector(wpc→wp1)to vector(wpc→wp2).static doubleunwrapSweepDeg(double prevUnwrapped, double signedNow) Unwrap a signed angle measurement so it varies continuously relative to a previous unwrapped angle, eliminating ±180° discontinuities.static Path2D.DoubleworldPolygonToPath(Point2D.Double[] points) Convert an array of world points into an openPath2D.Double.static Path2D.DoubleConvert an axis-aligned world rectangle into a closedPath2D.Double.
-
Field Details
-
DEFAULTSTROKE
Default stroke: 1 pixel wide, solid style.Applied by
setStyleDefaults(Graphics2D)and used as a fallback wherever no explicit stroke is specified.
-
-
Constructor Details
-
WorldGraphicsUtils
public WorldGraphicsUtils()
-
-
Method Details
-
drawEtchedHorizontalWorldLine
public static void drawEtchedHorizontalWorldLine(Graphics2D g2, IContainer container, double x, double y, double w, boolean lightAbove) Draw a horizontal "etched" line in world coordinates.An etched line is rendered as two parallel pixel-offset lines in contrasting colors to simulate a bevelled groove cut into a surface.
- Parameters:
g2- the graphics contextcontainer- the container defining the world-to-screen transformx- world X coordinate of the left end of the liney- world Y coordinate of the linew- width of the line in world unitslightAbove- iftrue, the light color is drawn on top (simulating illumination from above); iffalse, the dark color is on top
-
drawEtchedVerticalWorldLine
public static void drawEtchedVerticalWorldLine(Graphics2D g2, IContainer container, double x, double y, double h, boolean lightLeft) Draw a vertical "etched" line in world coordinates.An etched line is rendered as two parallel pixel-offset lines in contrasting colors to simulate a bevelled groove cut into a surface.
- Parameters:
g2- the graphics contextcontainer- the container defining the world-to-screen transformx- world X coordinate of the vertical liney- world Y coordinate of the top end of the lineh- height of the line in world unitslightLeft- iftrue, the light color is drawn on the left (simulating illumination from the left); iffalse, the dark color is on the left
-
drawWorldLine
public static void drawWorldLine(Graphics2D g2, IContainer container, Point2D.Double wp0, Point2D.Double wp1, IStyled style) Draw a styled world line between twoPoint2D.Doubleendpoints.color, width, and dash pattern are taken from
style.- Parameters:
g2- the graphics contextcontainer- the container defining the world-to-screen transformwp0- first endpoint in world coordinateswp1- second endpoint in world coordinatesstyle- source of line color, width, and style
-
drawWorldLine
public static void drawWorldLine(Graphics2D g2, IContainer container, double x1, double y1, double x2, double y2, IStyled style) Draw a styled world line between two coordinate pairs.color, width, and dash pattern are taken from
style.- Parameters:
g2- the graphics contextcontainer- the container defining the world-to-screen transformx1- world X of the first endpointy1- world Y of the first endpointx2- world X of the second endpointy2- world Y of the second endpointstyle- source of line color, width, and style
-
drawWorldLine
public static void drawWorldLine(Graphics2D g2, IContainer container, double x1, double y1, double x2, double y2, Color lineColor, float lineWidth, LineStyle lineStyle) Draw a world line with explicit color, width, and dash style.If
lineColorisnullthe method returns immediately without drawing.- Parameters:
g2- the graphics contextcontainer- the container defining the world-to-screen transformx1- world X of the first endpointy1- world Y of the first endpointx2- world X of the second endpointy2- world Y of the second endpointlineColor- line color;nullsuppresses drawinglineWidth- line width in pixelslineStyle- dash style
-
drawWorldLine
public static void drawWorldLine(Graphics2D g2, IContainer container, Point2D.Double wp0, Point2D.Double wp1, Color lineColor) Draw a 1-pixel solid world line between twoPoint2D.Doubleendpoints.- Parameters:
g2- the graphics contextcontainer- the container defining the world-to-screen transformwp0- first endpoint in world coordinateswp1- second endpoint in world coordinateslineColor- line color;nullsuppresses drawing
-
drawWorldLine
public static void drawWorldLine(Graphics2D g2, IContainer container, double x1, double y1, double x2, double y2, Color lineColor) Draw a 1-pixel solid world line between two coordinate pairs.- Parameters:
g2- the graphics contextcontainer- the container defining the world-to-screen transformx1- world X of the first endpointy1- world Y of the first endpointx2- world X of the second endpointy2- world Y of the second endpointlineColor- line color;nullsuppresses drawing
-
setStyleDefaults
Reset the graphics context to the MDI default drawing style.Sets the color to
Color.blackand the stroke toDEFAULTSTROKE(1 pixel wide, solid). Useful at the start of a draw method that does not receive explicit style parameters.- Parameters:
g2- the graphics context to reset
-
getPixelEnds
public static void getPixelEnds(IContainer container, Point p0, Point p1, Point2D.Double wp0, Point2D.Double wp1) Convert two world endpoints to their pixel equivalents.The results are written into the pre-allocated
Pointobjectsp0andp1to avoid allocating new objects on the critical drawing path.- Parameters:
container- the container defining the world-to-screen transformp0- receives the pixel coordinates ofwp0p1- receives the pixel coordinates ofwp1wp0- first world endpointwp1- second world endpoint
-
getBounds
Compute the pixel bounding rectangle for a line between two world points.The returned rectangle is expanded to a minimum size of 2 × 2 pixels so that nearly-horizontal and nearly-vertical lines still have a usable hit-test area.
- Parameters:
container- the container defining the world-to-screen transformwp0- first world endpointwp1- second world endpoint- Returns:
- pixel bounding rectangle with a minimum dimension of 2
-
getBounds
Compute the pixel bounding rectangle for a line between two world coordinate pairs.The returned rectangle is expanded to a minimum size of 2 × 2 pixels so that nearly-horizontal and nearly-vertical lines still have a usable hit-test area.
- Parameters:
container- the container defining the world-to-screen transformx1- world X of the first endpointy1- world Y of the first endpointx2- world X of the second endpointy2- world Y of the second endpoint- Returns:
- pixel bounding rectangle with a minimum dimension of 2
-
signedSweepDeg
Compute the signed sweep angle in degrees from vector(wpc→wp1)to vector(wpc→wp2).Uses
atan2(cross, dot)so the result carries the correct sign: positive for a counter-clockwise rotation, negative for clockwise.- Parameters:
wpc- the common origin of the two vectors (pivot point)wp1- tip of the first vector; defines the start directionwp2- tip of the second vector; defines the end direction- Returns:
- signed sweep angle in degrees, in the range
(-180, 180]
-
ccwSweepDeg
Compute the counter-clockwise (CCW) sweep angle in degrees from vector(wpc→wp1)to vector(wpc→wp2).Unlike
signedSweepDeg(java.awt.geom.Point2D.Double, java.awt.geom.Point2D.Double, java.awt.geom.Point2D.Double), this method always returns a value in[0, 360)so that major arcs are representable. For example, a signed angle of −60° becomes 300°.- Parameters:
wpc- the common origin of the two vectors (pivot point)wp1- tip of the first vector; defines the start directionwp2- tip of the second vector; defines the end direction- Returns:
- CCW sweep angle in degrees, in the range
[0, 360)
-
unwrapSweepDeg
public static double unwrapSweepDeg(double prevUnwrapped, double signedNow) Unwrap a signed angle measurement so it varies continuously relative to a previous unwrapped angle, eliminating ±180° discontinuities.This is useful when accumulating a running sweep angle during an interactive drag: without unwrapping, crossing the ±180° boundary causes the accumulated angle to jump by 360°.
- Parameters:
prevUnwrapped- the previous accumulated (unwrapped) angle, which may lie outside(-180, 180]signedNow- the new raw measurement fromsignedSweepDeg(java.awt.geom.Point2D.Double, java.awt.geom.Point2D.Double, java.awt.geom.Point2D.Double), in(-180, 180]- Returns:
- the new unwrapped angle, adjusted to be continuous with
prevUnwrapped
-
drawWorldRadArc
public static void drawWorldRadArc(Graphics2D g2, IContainer container, double xc, double yc, double rmin, double rmax, double startAngle, double stopAngle, Color fillColor, Color lineColor, float lineWidth, LineStyle lineStyle) Draw a radar arc (annular sector) with explicit style parameters.A radar arc is defined by inner and outer radii (
rmin,rmax) and an angular sweep fromstartAngletostopAngle. The resulting shape is the region between the two arcs, closed by two radial edges.- Parameters:
g2- the graphics contextcontainer- the container defining the world-to-screen transformxc- world X of the arc centeryc- world Y of the arc centerrmin- inner radius in world unitsrmax- outer radius in world unitsstartAngle- start angle in degreesstopAngle- stop angle in degreesfillColor- fill color;nullsuppresses filllineColor- outline color;nullsuppresses outlinelineWidth- outline width in pixelslineStyle- outline dash style
-
drawWorldRadArc
public static void drawWorldRadArc(Graphics2D g2, IContainer container, double xc, double yc, double rmin, double rmax, double startAngle, double stopAngle, Color fillColor, Color lineColor) Draw a radar arc (annular sector) with a 1-pixel solid outline.- Parameters:
g2- the graphics contextcontainer- the container defining the world-to-screen transformxc- world X of the arc centeryc- world Y of the arc centerrmin- inner radius in world unitsrmax- outer radius in world unitsstartAngle- start angle in degreesstopAngle- stop angle in degreesfillColor- fill color;nullsuppresses filllineColor- outline color;nullsuppresses outline
-
drawWorldRadArc
public static void drawWorldRadArc(Graphics2D g2, IContainer container, double xc, double yc, double rmin, double rmax, double startAngle, double stopAngle, IStyled style) Draw a radar arc (annular sector) using anIStyledsource for fill color, line color, line width, and line style.- Parameters:
g2- the graphics contextcontainer- the container defining the world-to-screen transformxc- world X of the arc centeryc- world Y of the arc centerrmin- inner radius in world unitsrmax- outer radius in world unitsstartAngle- start angle in degreesstopAngle- stop angle in degreesstyle- source of fill color, line color, width, and style
-
drawImageOnQuad
public static void drawImageOnQuad(Graphics2D g2, BufferedImage image, Point2D.Double[] wpoly, IContainer container) Draw aBufferedImagemapped onto an arbitrary world-coordinate quadrilateral.The image is mapped so that its top-left pixel aligns with
wpoly[0], and the two edges adjacent to that corner determine the width and height directions. The method automatically selects which adjacent corner (wpoly[1]orwpoly[3]) is the width direction by matching the quad's aspect ratio to the image's aspect ratio.If the affine mapping has a negative determinant (i.e. the quad is mirror-reflected in local coordinates) the v-axis of the image mapping is flipped to prevent the image from being drawn upside down.
Note on casting: this method calls
Graphics.create(), which is declared onGraphicsand returnsGraphics. A cast toGraphics2Dis therefore required for the child context. This is the only unavoidable cast inWorldGraphicsUtils.- Parameters:
g2- the graphics contextimage- the image to draw; ignored ifnullwpoly- four world-coordinate corners in order:[w0, wa, w2, wb]wherewaandwbare the corners adjacent tow0; ignored ifnullor fewer than 4 elementscontainer- the container defining the world-to-screen transform
-
createWorldCircle
Build a screenPolygonapproximating a world-coordinate circle.The circle is approximated by 60 line segments.
- Parameters:
container- the container defining the world-to-screen transformxc- world X of the centeryc- world Y of the centerradius- radius in world units- Returns:
- polygon approximating the circle in pixel coordinates
-
createWorldDonut
public static Polygon createWorldDonut(IContainer container, double xc, double yc, double minRadius, double maxRadius) Build a screenPolygonapproximating a world-coordinate donut (annulus).If
minRadiusis less thanTINYthe inner ring is degenerate and the result degrades gracefully to a plain circle atmaxRadius.- Parameters:
container- the container defining the world-to-screen transformxc- world X of the centeryc- world Y of the centerminRadius- inner radius in world unitsmaxRadius- outer radius in world units- Returns:
- polygon approximating the annulus in pixel coordinates
-
createWorldArc
public static Polygon createWorldArc(IContainer container, double xc, double yc, double radius, double startAngle, double stopAngle) Build a screenPolygonapproximating a world-coordinate arc (a portion of a circle's circumference).If the angular span
|stopAngle - startAngle|is at least 360° −TINY, the full circle is returned viacreateWorldCircle(edu.cnu.mdi.container.IContainer, double, double, double).- Parameters:
container- the container defining the world-to-screen transformxc- world X of the centeryc- world Y of the centerradius- radius in world unitsstartAngle- start angle in degreesstopAngle- stop angle in degrees- Returns:
- polygon approximating the arc in pixel coordinates
-
drawWorldOval
public static void drawWorldOval(Graphics2D g2, IContainer container, Rectangle2D.Double worldRectangle, Color fillColor, Color lineColor, float lineWidth, LineStyle lineStyle) Draw a world oval with explicit style parameters.The oval is inscribed within the axis-aligned world rectangle
worldRectangle.- Parameters:
g2- the graphics contextcontainer- the container defining the world-to-screen transformworldRectangle- bounding world rectangle of the ovalfillColor- fill color;nullsuppresses filllineColor- outline color;nullsuppresses outlinelineWidth- outline width in pixelslineStyle- outline dash style
-
drawWorldOval
public static void drawWorldOval(Graphics2D g2, IContainer container, Rectangle2D.Double worldRectangle, Color fillColor, Color lineColor) Draw a world oval with a 1-pixel solid outline.- Parameters:
g2- the graphics contextcontainer- the container defining the world-to-screen transformworldRectangle- bounding world rectangle of the ovalfillColor- fill color;nullsuppresses filllineColor- outline color;nullsuppresses outline
-
drawWorldOval
public static void drawWorldOval(Graphics2D g2, IContainer container, Rectangle2D.Double worldRectangle, IStyled style) Draw a world oval using anIStyledsource for style properties.- Parameters:
g2- the graphics contextcontainer- the container defining the world-to-screen transformworldRectangle- bounding world rectangle of the ovalstyle- source of fill color, line color, width, and style
-
drawWorldRectangle
public static void drawWorldRectangle(Graphics2D g2, IContainer container, Rectangle2D.Double worldRectangle, Color fillColor, Color lineColor, float lineWidth, LineStyle lineStyle) Draw a world rectangle with explicit style parameters.- Parameters:
g2- the graphics contextcontainer- the container defining the world-to-screen transformworldRectangle- the world rectangle to drawfillColor- fill color;nullsuppresses filllineColor- outline color;nullsuppresses outlinelineWidth- outline width in pixelslineStyle- outline dash style
-
drawWorldRectangle
public static void drawWorldRectangle(Graphics2D g2, IContainer container, Rectangle2D.Double worldRectangle, Color fillColor, Color lineColor) Draw a world rectangle with a 1-pixel solid outline.- Parameters:
g2- the graphics contextcontainer- the container defining the world-to-screen transformworldRectangle- the world rectangle to drawfillColor- fill color;nullsuppresses filllineColor- outline color;nullsuppresses outline
-
drawWorldRectangle
public static void drawWorldRectangle(Graphics2D g2, IContainer container, Rectangle2D.Double worldRectangle, IStyled style) Draw a world rectangle using anIStyledsource for style properties.- Parameters:
g2- the graphics contextcontainer- the container defining the world-to-screen transformworldRectangle- the world rectangle to drawstyle- source of fill color, line color, width, and style
-
drawHighlightedRectangle
public static void drawHighlightedRectangle(Graphics2D g2, IContainer container, Rectangle2D.Double wr, Color color1, Color color2) Draw the outline of a highlighted (marching-ants style) world rectangle.The outline alternates between
color1andcolor2on successive pixels to produce a high-visibility selection indicator.- Parameters:
g2- the graphics contextcontainer- the container defining the world-to-screen transformwr- the world rectangle to highlightcolor1- first alternating colorcolor2- second alternating color
-
drawWorldPolygon
public static void drawWorldPolygon(Graphics2D g2, IContainer container, WorldPolygon worldPolygon, Color fillColor, Color lineColor, float lineWidth) Draw a world polygon with a 1-pixel solid outline.- Parameters:
g2- the graphics contextcontainer- the container defining the world-to-screen transformworldPolygon- the polygon in world coordinatesfillColor- fill color;nullsuppresses filllineColor- outline color;nullsuppresses outlinelineWidth- outline width in pixels
-
drawWorldPolygon
public static void drawWorldPolygon(Graphics2D g2, IContainer container, WorldPolygon worldPolygon, Color fillColor, Color lineColor, float lineWidth, LineStyle lineStyle) Draw a world polygon with explicit style parameters.- Parameters:
g2- the graphics contextcontainer- the container defining the world-to-screen transformworldPolygon- the polygon in world coordinatesfillColor- fill color;nullsuppresses filllineColor- outline color;nullsuppresses outlinelineWidth- outline width in pixelslineStyle- outline dash style
-
drawWorldText
public static void drawWorldText(Graphics2D g2, IContainer container, double x, double y, String text, int dh, int dv) Draw a string anchored at a world coordinate with a pixel offset.The text is drawn using the current font and color of the graphics context. The pixel offset
(dh, dv)is applied after the world-to-screen conversion, allowing fine-grained label placement relative to a world point.- Parameters:
g2- the graphics contextcontainer- the container defining the world-to-screen transformx- world X of the text anchory- world Y of the text anchor (baseline)text- the string to draw; ignored ifnulldh- additional horizontal pixel offset (positive = right)dv- additional vertical pixel offset (positive = down)
-
drawPath2D
public static Polygon drawPath2D(Graphics2D g2, IContainer container, Path2D.Double path, IStyled style, boolean closed) Draw a straight-segment world path as either a closed polygon or an open polyline, deriving style from anIStyledobject.- Parameters:
g2- the graphics contextcontainer- the container defining the world-to-screen transformpath- the world path (straight segments only)style- source of fill color, line color, width, and styleclosed- iftruethe path is drawn as a filled/outlined polygon; iffalseas an open polyline- Returns:
- the pixel
Polygonthat was drawn, ornullif the path had no vertices
-
drawPath2D
public static Polygon drawPath2D(Graphics2D g2, IContainer container, Path2D.Double path, Color fillColor, Color lineColor, float lineWidth, LineStyle lineStyle, boolean closed) Draw a straight-segment world path as either a closed polygon or an open polyline, with explicit style parameters.Anti-aliasing is enabled for the duration of this call to produce smooth diagonal edges. If
lineWidthis zero it is clamped to 0.5 so the path remains visible at all zoom levels.- Parameters:
g2- the graphics contextcontainer- the container defining the world-to-screen transformpath- the world path (straight segments only)fillColor- fill color;nullsuppresses fill (only meaningful whenclosedistrue)lineColor- outline color;nullsuppresses outlinelineWidth- outline width in pixels; clamped to 0.5 if zerolineStyle- outline dash styleclosed- iftruethe path is drawn as a filled/outlined polygon; iffalseas an open polyline- Returns:
- the pixel
Polygonthat was drawn, ornullif the path had no vertices
-
getPathPointCount
Count the explicit vertex points in a straight-segmentPath2D.Double.Vertices are contributed by
SEG_MOVETOandSEG_LINETOsegments only.SEG_CLOSEis ignored.- Parameters:
path- the path to inspect;nullreturns 0- Returns:
- the number of MOVETO + LINETO vertices
- Throws:
IllegalArgumentException- if the path contains curve segments
-
neededCapacity
Return the capacity (vertex count) needed to store a straight-segment path in a flat array.This is a convenience alias for
getPathPointCount(Path2D.Double), intended for use at array-allocation sites to make the intent clear.- Parameters:
path- the path;nullreturns 0- Returns:
- number of MOVETO + LINETO vertices
- Throws:
IllegalArgumentException- if the path contains curve segments
-
getPoints
Extract the vertices of a straight-segmentPath2Das a list.Vertices from
SEG_MOVETOandSEG_LINETOare included. Iteration stops when aSEG_CLOSEis encountered if only one sub-path has been seen; multiple sub-paths are not supported.- Parameters:
path- the world path; must not benull- Returns:
- a list of world vertices in path order
- Throws:
IllegalArgumentException- if the path contains curve segments or multiple sub-paths
-
getPathPointAt
Return the world-coordinate vertex at the specified zero-based index in a straight-segment path.Only
SEG_MOVETOandSEG_LINETOsegments contribute vertices.SEG_CLOSEis ignored.- Parameters:
path- the world path;nullreturnsnullindex- zero-based vertex index- Returns:
- the vertex at
index, ornullif the index is out of range - Throws:
IllegalArgumentException- if the path contains curve segments
-
pathToPolygon
Convert a straight-segment world path to a screenPolygon.Each
SEG_MOVETOandSEG_LINETOvertex is transformed from world to screen coordinates.SEG_CLOSEcontributes no new vertex.- Parameters:
container- the container defining the world-to-screen transform;nullreturnsnullpath- the world path;nullreturnsnull- Returns:
- screen polygon, or
nullif there are no vertices - Throws:
IllegalArgumentException- if the path contains curve segments
-
pathToWorldPolygon
Extract the world-coordinate vertices of a straight-segment path as a new array.- Parameters:
path- the world path;nullreturnsnull- Returns:
- array of world vertices, or
nullif the path has none - Throws:
IllegalArgumentException- if the path contains curve segments
-
pathToWorldPolygon
Copy the world-coordinate vertices of a straight-segment path into a pre-allocated array.Each element of
wpmust already be a non-nullPoint2D.Double. Iteration stops early ifwpis full.- Parameters:
path- the world path; no-op ifnullwp- destination array of pre-allocatedPoint2D.Doubleobjects; must not benull- Throws:
IllegalArgumentException- if the path contains curve segments
-
worldRectangleToPath
Convert an axis-aligned world rectangle into a closedPath2D.Double.The path visits the four corners in order: top-left → bottom-left → bottom-right → top-right, then closes.
- Parameters:
wr- the world rectangle; must not benull- Returns:
- a closed path tracing the rectangle boundary
-
worldPolygonToPath
Convert an array of world points into an openPath2D.Double.The first point becomes a
moveTo; subsequent points becomelineTocalls. The path is not closed.- Parameters:
points- world vertices;nullreturnsnull- Returns:
- open world path, or
nullifpointsisnull
-
getPoints
Return the four corners of a world rectangle as a point array.Corners are returned in order: top-left, bottom-left, bottom-right, top-right.
- Parameters:
wr- the world rectangle; must not benull- Returns:
- array of four
Point2D.Doublecorners
-
intersection
public static Point2D.Double intersection(Point2D.Double p1, Point2D.Double p2, Point2D.Double q1, Point2D.Double q2) Compute the intersection point of two line segments.Each segment is defined by two endpoints. Returns
nullif the segments are parallel (denominator near zero) or if the intersection lies outside either segment (parametric parameter outside [0, 1]).- Parameters:
p1- first endpoint of segment 1p2- second endpoint of segment 1q1- first endpoint of segment 2q2- second endpoint of segment 2- Returns:
- the intersection point, or
nullif there is none within both segments
-
contains
Test whether a world point lies inside a polygon.- Parameters:
poly- the polygon vertices; must not benullwp- the point to test; must not benull- Returns:
trueifwpis insidepoly
-
area
Compute the signed area of a polygon using the shoelace formula.A positive result indicates a counter-clockwise winding; negative indicates clockwise. Returns 0 for degenerate or collinear polygons.
- Parameters:
poly- the polygon vertices;nullor fewer than 3 vertices returns 0- Returns:
- signed area in world-coordinate square units
-
getCentroid
Compute the centroid of a polygon.Uses the standard area-weighted formula. Returns
nullfor degenerate polygons whose area is effectively zero.- Parameters:
poly- the polygon vertices;nullreturnsnull- Returns:
- the centroid, or
nullif the polygon is degenerate
-
getCentroid
Compute the centroid of a straight-segment path.- Parameters:
path- the world path;nullreturnsnull- Returns:
- the centroid, or
nullif the path is degenerate
-
longestDiagonal
Compute the distance fromfocusto the farthest vertex of a polygon.This is used internally by
polygonIntersection(java.awt.geom.Point2D.Double, double, java.awt.geom.Path2D.Double)to determine how long a ray must be to guarantee it crosses the polygon boundary.- Parameters:
focus- the reference point;nullreturnsDouble.NaNpoly- the polygon vertices;nullor empty returnsDouble.NaN- Returns:
- the longest vertex distance, or
Double.NaNif inputs are invalid
-
polygonIntersection
public static Point2D.Double polygonIntersection(Point2D.Double p0, double azimuth, Path2D.Double path) Find the first intersection of a ray with a world path.The ray starts at
p0and radiates in the direction ofazimuth. This is a convenience overload that converts the path to a polygon array before delegating topolygonIntersection(Point2D.Double, double, Point2D.Double[]).- Parameters:
p0- the start point (typically inside the polygon)azimuth- direction of the ray in degrees (azimuth convention: 0 = north, 90 = east)path- the world path to intersect- Returns:
- the first intersection point, or
nullif none found
-
polygonIntersection
public static Point2D.Double polygonIntersection(Point2D.Double p0, double azimuth, Point2D.Double[] poly) Find the first intersection of a ray with a world polygon.The ray starts at
p0and extends twice the length of the longest vertex distance to ensure it crosses the boundary. The first segment intersection found is returned.This works reliably when
p0is inside a convex or mildly concave polygon. For very irregular polygons the "first" intersection may not be the geometrically nearest one.- Parameters:
p0- the start point (typically inside the polygon)azimuth- direction of the ray in degrees (azimuth convention: 0 = north, 90 = east)poly- the polygon vertices- Returns:
- the first intersection point, or
nullif none found
-
project
Project a world point by a distance and azimuth angle.The azimuth follows the compass convention: 0° is north (+Y), 90° is east (+X), 180° is south (−Y), 270° is west (−X).
- Parameters:
focus- the origin pointdistance- the projection distance in world unitsangle- the direction in degrees (azimuth: 0 = north, 90 = east)wp- receives the projected point; must not benull
-
radiusPoint
Create a world point at a given distance and polar angle from a center.Unlike
project(java.awt.geom.Point2D.Double, double, double, java.awt.geom.Point2D.Double), this method uses the standard mathematical polar angle convention (0° = east, 90° = north).- Parameters:
center- the origin point; must not benullradius- the distance from the center in world unitstheta- the angle in degrees (standard polar: 0 = east, 90 = north)- Returns:
- the new world point
-
getRadArcPoints
public static Point2D.Double[] getRadArcPoints(Point2D.Double wpc, Point2D.Double wp1, double arcAngle) Build an array of world points approximating a radar-arc sweep.The array begins at the center
wpc, proceeds towp1(the first leg endpoint), then sweeps counter-clockwise byarcAngledegrees, using 60 interpolation steps. The first element is always the center; the remaining elements trace the arc.- Parameters:
wpc- the center of the arcwp1- the first leg endpoint; the distancewpc→wp1defines the radiusarcAngle- the CCW sweep angle in degrees- Returns:
- array of 60
+ 2world points (center + wp1 + arc samples)
-
getArcPoints
public static Point2D.Double[] getArcPoints(Point2D.Double wpc, Point2D.Double wp1, double arcAngle) Build an array of world points approximating a simple arc sweep.Similar to
getRadArcPoints(java.awt.geom.Point2D.Double, java.awt.geom.Point2D.Double, double)but does not include the center point. The array begins atwp1and sweeps counter-clockwise byarcAngledegrees.- Parameters:
wpc- the center of the arc (not included in the output)wp1- the first leg endpoint; the distancewpc→wp1defines the radiusarcAngle- the CCW sweep angle in degrees- Returns:
- array of 60
+ 1world points tracing the arc fromwp1
-
getEllipsePoints
public static Point2D.Double[] getEllipsePoints(double w, double h, double azimuth, int numFill, Point2D.Double center) Build an array of world points approximating an ellipse.The ellipse is defined by its half-widths (
w/2,h/2) and an azimuth rotation. Four primary compass points are computed first, the centroid is recomputed from those, and then4 * numFillequally-spaced angular samples are generated. A closing point equal to the first is appended so the returned polygon is explicitly closed.- Parameters:
w- full width of the ellipse in world unitsh- full height of the ellipse in world unitsazimuth- rotation of the ellipse in degrees (azimuth convention: 0 = north, 90 = east)numFill- number of sample points per quadrant; the total returned is4 * numFill + 1center- the center of the ellipse- Returns:
- array of world points approximating the ellipse, closed at the last element
-
getMeanPixelDensity
Estimate the pixel density of the container in pixels per world unit.Computed as the diagonal pixel length divided by the diagonal world length across the full component bounds. The bigger this number is, the more zoomed in the view is. Returns 0 if the component is too small to produce a meaningful estimate.
- Parameters:
container- the container to measure; must not benull- Returns:
- approximate pixels per world unit, or 0 if the component is too small
-
isPointNearPath
Test whether a world point lies within a given tolerance of any segment in a straight-segmentPath2D.Double.Proximity to path vertices is also tested (a point exactly on a vertex counts as a hit).
SEG_CLOSEis treated as a segment from the last point back to the most recentSEG_MOVETOpoint.- Parameters:
path- the world path to test;nullreturnsfalsewp- the world point to test;nullreturnsfalsetolWorld- tolerance distance in world units; must be ≥ 0- Returns:
trueifwpis withintolWorldof any segment or vertex inpath- Throws:
IllegalArgumentException- if the path contains curve segments
-
closestPointOnSegment
public static Point2D.Double closestPointOnSegment(Point2D.Double p1, Point2D.Double p2, Point2D.Double wp) Return the point on segmenta→bthat is closest top.If the segment is degenerate (zero length) the method returns a copy of
a.- Parameters:
p1- one end of the segmentp2- the other end of the segmentwp- the query point- Returns:
- the closest point on the segment
-