开发者

Arc2D.Double contains(double x, double y) method not working

开发者 https://www.devze.com 2023-02-15 22:48 出处:网络
Background: A little background info, this is taking place on JPanel (PiePanel) thats inside a JPanel on a JFrame. On PiePanel, i have added a Componentthat draws objects from class Pie that extends A

Background: A little background info, this is taking place on JPanel (PiePanel) thats inside a JPanel on a JFrame. On PiePanel, i have added a Component that draws objects from class Pie that extends Arc2D.Double and creates Arcs in PIE form. Essentially I'm making pie chart.

I made constants in Pie class for making the arc as: x = 20, y = 20, w = 240, h = 240

public TestComponent()  {
    setPreferredSize(new Dimension(280,270));
    pies = new ArrayList<PieChartSlice>();
    Pie a = new Pie(0, 120, Color.black);
    pies.add(a);
    System.out.println(a.contains(150.0,130.0));
    }

Since the dimen开发者_如何学Pythonsions are 280 by 270, and i start each pies bounded box with x,y = 20 and h,w = 240, the middle of the piechart should be (140,140). Since the Pie 'a' is 120 degrees, coordinates 150,130 should definitely be in Pie a, but it returns false!!

It also seems that a.toString() gives PieChartSlice@0


I just had this problem and while I can't definitively provide the answer the OP's problem without seeing their code, I did figure out a solution to my identical problem (a point clearly inside the arc is not being "seen".)

When calling the constructor

Arc2D.Double(double x, double y, double w, double h, double start, double extent,
             int type)

use Arc2D.PIE for int type. The other two types didn't work for me.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号