swingx
  1. swingx
  2. SWINGX-1478

PinstripePainter - incorrect intersection of the graphics clip area

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.6.2
    • Fix Version/s: 1.6.5
    • Component/s: Painter
    • Labels:
      None
    • Environment:

      Windows XP, Java 1.6 r17, SwingX 1.6.2

      Description

      I understand that this may have only been tested on Swing components, but I would expect it to work on any Graphics context without modification. I am working on an application to draw a simplified map with very large coordinates, and very large shapes. I wanted to use the PinstripePainter to draw a large (non-rectangular) shape with a pinstriped interior, so I set the clip to the desired shape on the graphics context before invoking the PinstripePainter, the clip is not located at (0,0).

      See This post for the original discussion.

      In PinstripePainter.java#doPaint(...), the code attempts to intersect the area object with a rectangle at (x,y) (0,0).
      If you have a clip set that is not at (0,0), the Areas don't intersect, obviously, and nothing gets painted.
      I am trying to set a clip of an Ellipse2D.Double object that is nowhere near the center of the graphics context, and after intersect() gets called, the area object contains no curves (no intersection).
      If I evaluate this code in my IDE via a breakpoint, the proper intersection is created:

      area.intersect(new Area(new Rectangle(oldClip.getBounds().x, oldClip.getBounds().y, width, height))
      

      So, if a clip exists, the Rectangle used to check for intersection needs to use the clip's bounding rectangle coordinates.

      Also, the code doesn't work for very large shapes (where ((width * width) + (height + height)) would overflow an int).

      Cast to a double to get it to work for large shapes in the Math.sqrt(...) call.

      To test your fix, I would just use a Canvas to draw a large Ellipse2D.Double (20000 width, 75000 height) not located at (0,0).

        Activity

        Hide
        Karl Schaefer added a comment -

        SWINGX-1478: Fix the clip intersection issue. Also fix possible overflow issue, by using Math.hypot instead of performing the intermediate steps using various Math functions.

        swingx-painters/src/main/java/org/jdesktop/swingx/painter/PinstripePainter.java

        Committed revision 4259.

        Show
        Karl Schaefer added a comment - SWINGX-1478 : Fix the clip intersection issue. Also fix possible overflow issue, by using Math.hypot instead of performing the intermediate steps using various Math functions. swingx-painters/src/main/java/org/jdesktop/swingx/painter/PinstripePainter.java Committed revision 4259.

          People

          • Assignee:
            Karl Schaefer
            Reporter:
            Protuhj
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 6 hours
              6h
              Remaining:
              Remaining Estimate - 6 hours
              6h
              Logged:
              Time Spent - Not Specified
              Not Specified