Skip to main content

PinstripePainter - incorrect intersection of the graphics clip area

8 replies [Last post]

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kschaefe
Offline
Joined: 2006-06-08
Points: 0

These are great comments.  Can you file a bug report, so we can track and implement fixes?

Thanks,

Karl

Protuhj
Offline
Joined: 2012-01-10
Points: 0
Protuhj
Offline
Joined: 2012-01-10
Points: 0

I was trying to find where to enter a bug report on the JIRA site, do I need to make an account on there to file one?

kschaefe
Offline
Joined: 2006-06-08
Points: 0

Should be your java.net account.

Karl

Protuhj
Offline
Joined: 2012-01-10
Points: 0

You're right, I had checked the JIRA site before I created a java.net account. Will enter a report shortly.

Protuhj
Offline
Joined: 2012-01-10
Points: 0

Also, the actual line drawing does not take into account the offset of the clip.

Here's the top of the code in the doPaint(...) method that I'm using to get this to work:

    Rectangle r = new Rectangle(0, 0, width, height);
    Area area = new Area(new Rectangle(0, 0, width, height));
    if (oldClip != null) {
      area = new Area(oldClip);
      r.setLocation(oldClip.getBounds().x, oldClip.getBounds().y);
    }
    area.intersect(new Area(r));

Here's the for-loop that works for me:

    for (int i = 0; i < numLines; i++) {
      double x = i * spacing;
      Line2D line = new Line2D.Double(r.x + x, r.y - hypLength, r.x + x, r.y + hypLength);
      g.draw(line);
    }

Edit: I also cannot use angled pinstripes with this code because the rotate code seems to screw up the clip significantly.

Protuhj
Offline
Joined: 2012-01-10
Points: 0

I have modified the for-loop to be able to use rotated pinstripes with a non-(0,0)-centered clip:

    for (int i = 0; i < numLines; i++) {
      double x = i * spacing;
      Line2D line;
      if (oldClip != null) {
        Rectangle currentBounds = g.getClip().getBounds();
        line = new Line2D.Double(currentBounds.x + x, currentBounds.y - hypLength,
            currentBounds.x + x, currentBounds.y + hypLength);
      } else {
        line = new Line2D.Double(r.x + x, r.y - hypLength, r.x + x, r.y + hypLength);

      }
      g.draw(line);
    }
Protuhj
Offline
Joined: 2012-01-10
Points: 0

Also, the code doesn't work for very large shapes (width of 12000 causes overflow when trying to calculate the hypLength).

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