Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8091868

Provide a Shape copy method

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Unresolved
    • P4
    • tbd
    • 8
    • javafx
    • n/a

    Description

      I'm doing some complex clipping of multiple Reflections to ensure that the transparent reflections don't partially mix with each other. I'm using clips for this. I use one cumulative clip that gets expanded with each reflection drawn. This cumulative clip then must be applied to a Node. Since the cumulative clip will be different for each Node (as it depends on their front-to-back order), I must make a copy of it.

      I've added some code below to illustrate what I'm doing. I'm copying shapes now with the following construct:

        Shape copy = Shape.intersect(cumulativeClip, new Rectangle(0, 0, w, h));

      I've looked around for a better way, but I haven't found one. I was expecting either a copy constructor on Shape (but it is abstract) or a static copy method on Shape.

      The code:

        Shape cumulativeClip = null;

        while(someCondition) {
              Shape clip = ...; // obtain clip of the reflection part

              (...)

              if(cumulativeClip != null) {
                Shape cellClip = Shape.intersect(cumulativeClip, new Rectangle(0, 0, w, h)); // TODO there must be a better way to just copy a Shape...
                Point2D localToParent = cell.localToParent(0, 0);

                cellClip.getTransforms().add(new Translate(-localToParent.getX(), -localToParent.getY()));

                cell.setClip(cellClip);
              }
              else {
                cell.setClip(null);
              }

              if(clip != null) {
                clip.getTransforms().add(cell.getLocalToParentTransform());

                if(cumulativeClip == null) {
                  cumulativeClip = new Rectangle(0, 0, w, h);
                }

                cumulativeClip = Shape.subtract(cumulativeClip, clip);
              }
         }

      Attachments

        Activity

          People

            Unassigned Unassigned
            jhendrikx John Hendrikx
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Imported: