general path shape "types"

I

Ian Stanley

Hi,
I have an vector of shapes which I then apply transforms to.
I am trying to use some of the "attributes" of the reulting general path to
detemine what type of shape a mouse click has hit.
example a square has area = side*side.
I hope to use the shape's area to test what type of shape(general path) is
being selected. Part of my method is below.
The problem is that for rotated rectangles and some other shapes the
getbounds width & height cannot be used.
Can anyone please suggest a way this could be resolved. I have looked at the
getpathiterator but can't work out how it works?
Am I on the wrong track?
any help appreciated, thanking you
Ian

public Shape hitTest(int x, int y)
{
for (int i = 0; i < v.size(); i++){
Shape s = (Shape)v.elementAt(i);
if (s.contains(x,y) ){
int wid = s.getBounds().width;
int hei = s.getBounds().height;
... ... ...
return s;
}
}
return null;
}
 
S

Sudsy

Ian said:
Hi,
I have an vector of shapes which I then apply transforms to.
I am trying to use some of the "attributes" of the reulting general path to
detemine what type of shape a mouse click has hit.
example a square has area = side*side.
I hope to use the shape's area to test what type of shape(general path) is
being selected. Part of my method is below.
The problem is that for rotated rectangles and some other shapes the
getbounds width & height cannot be used.
Can anyone please suggest a way this could be resolved. I have looked at the
getpathiterator but can't work out how it works?
Am I on the wrong track?
any help appreciated, thanking you
Ian

Have you checked out the Shape.contains() method?
 
I

Ian

Sudsy said:
Have you checked out the Shape.contains() method?

Thanks for your reply
I am using the contains methos --s.contains(x,y)to check if the shape
is hit.
However, because the shapes are transformed using
public Shape rotateShape(int x, int y)
{
for (int i = 0; i < v.size(); i++){
Shape s = (Shape)v.elementAt(i);
if (s.contains(x,y) ){
int anchorX = s.getBounds().x + s.getBounds().width/2;
int anchorY = s.getBounds().y + s.getBounds().height
/2;
AffineTransform tr =
AffineTransform.getRotateInstance(Math.PI/4.0,anchorX
,anchorY );
Shape ts = tr.createTransformedShape(current_shape);
v.addElement(ts);
v.removeElement(s);
repaint();
break;
}
}
return null;
}
ts is now a instance of general path and I am trying to work out if it
is a rectangle, oval etc the next time it is selected
Thanks again
Ian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

shape selection tests 3
SVG not full width and space 0
2D shape problem 0
shape selection again 2
rotate shape with transform? 0
clicking on turtle 1
Help with transforms 3
Drawing math shape 15

Members online

Forum statistics

Threads
473,998
Messages
2,570,242
Members
46,835
Latest member
lila30

Latest Threads

Top