Giter Site home page Giter Site logo

Comments (5)

msteiger avatar msteiger commented on August 17, 2024

Thanks, I will try to reproduce the error.

from jxmapviewer2.

msteiger avatar msteiger commented on August 17, 2024

Sorry for the long delay. I am able to reproduce the problem and will debug it a bit. Maybe I can find something... in the
meantime, did find anything related to the problem?

from jxmapviewer2.

ulixit avatar ulixit commented on August 17, 2024

Yes. After some more attempts I recently found a possible problem with Graphics2D.translate(...) which is presumably called somewhere before paintWaypoint(...)
By replacing my previous sample code with this following the problem disappears:

// paints a blue circle with an internal white circle
Rectangle rect = viewer.getViewportBounds(); // added
g.translate(rect.x, rect.y);                 // added to undo g.translate(-rect.x, -rect.y) called elsewhere 
g.setColor(Color.BLUE);
g.fillOval(x-7-rect.x, y-7-rect.y, 14, 14);  // changed
g.setColor(Color.WHITE);
g.fillOval(x-4-rect.x, y-4-rect.y, 8, 8);    // changed
System.out.println("zoom"+viewer.getZoom());

from jxmapviewer2.

javagl avatar javagl commented on August 17, 2024

There is

debugging

and there is

debugging

The first one refers to the process of diligently and systematically analyzing a flaw (preferably not in your own code), in order to solve the problem.

The latter refers to things of which you'd hesitate to admit publicly that you have done them (and that may be fueled by some geeky curiosity, and may not even lead to a solution).

When inserting the following debugging statements in the FancyWaypointRenderer

        try {
            System.out.println("graphics: "+g);
            sun.java2d.SunGraphics2D sg = (SunGraphics2D) g;

            sun.java2d.pipe.PixelToShapeConverter sunGraphicsFillPipe = (PixelToShapeConverter) sg.fillpipe;
            System.out.println("graphics.fillPipe: "+sunGraphicsFillPipe);

            Field f = Class.forName("sun.java2d.pipe.PixelToShapeConverter").getDeclaredField("outpipe");
            f.setAccessible(true);
            Object pixelToShapeConverterOutpipe = f.get(sunGraphicsFillPipe);
            System.out.println("pixelToShapeConverter.outpipe: "+pixelToShapeConverterOutpipe);
            
        } catch (Exception e) {
            e.printStackTrace();
        }

(which may not even work in the newer Java versions, with all this "module sealing" and such...), then the output may be something like

graphics: sun.java2d.SunGraphics2D[font=javax.swing.plaf.FontUIResource[family=Dialog,name=Dialog,style=plain,size=12],color=sun.swing.PrintColorUIResource[r=51,g=51,b=51]]
graphics.fillPipe: sun.java2d.pipe.PixelToParallelogramConverter@e9940ac
pixelToShapeConverter.outpipe: sun.java2d.pipe.PixelToParallelogramConverter@3429e7aa

Looking at the code of PixelToShapeConverter#fillOval, it reveals...

    public void fillOval(SunGraphics2D sg,
                         int x, int y, int w, int h) {
        outpipe.fill(sg, new Ellipse2D.Float(x, y, w, h));
    }

Now. There's that Float. And I'm reasonably sure that this is the culprit. The translation (when fully zoomed in) is 17586168, and in the single-precision floating-point world, adding 1 to that will yield ... 17586168, i.e. the same value. You're hitting the limit of float here.

The solution... might be... well, ... handwavingly: to carry this translation, in an "un-applied form", until shortly before it is supposed to be used for rendering, then do the computations (in double) that are required to bring that into the pixel space, and draw these pixels where they should be.


An aside: I noticed that when changing

    g.fillOval(x-7, y-7, 14, 14);

to

    g.fill(new Ellipse2D.Double(x-7, x-7, 14, 14));

then the ellipses are drawn at the wrong place, and I haven't figured out why. It seems like it's flipped vertically or so.

An aside to the aside:

Similar pixel-artifacts still appear with Ellipse2D.Double. I just thought that this might be an easy solution/workaround, but ... it isn't, becasue the problem is deeper.

from jxmapviewer2.

msteiger avatar msteiger commented on August 17, 2024

Wow, impressive research, thanks a lot!

from jxmapviewer2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.