Re: [JAVA2D] AffineTransformation

2007-07-27 Thread Jim Graham

I wanted to follow up this suggestion with a warning.

The Area object is not a generalized Shape.  It has some very specific
properties which make it inappropriate for some Shapes.  Most of these
should be documented in the latest javadoc for the Area class.

1. Area cannot represent shapes which enclose no space, such as a Line.
 Line2D is a Shape since it has a path and can be stroked, but it
cannot be filled.  An Area constructed from a Line2D is an empty Area
containing no geometry since an Area only represents enclosed regions of
space.

2. Area will implicitly close a Shape upon construction.  If you define
an open triangle consisting of 2 lines and you draw that Shape then only
2 lines will be drawn.  If you construct an Area from that Shape and
then draw the Area, 3 lines will get drawn to represent the closed triangle.

3. Area performs a *lot* of calculations on a Shape when you construct
it.  The purpose of these calculations is to internalize a
representation of the regions of space that are enclosed to make the CAG
operations (union, intersect, subtract, xor) easy to implement.  Those
calculations are pretty fast if your goal is to perform CAG with the
Shape, but they are unnecessary if you are not using it to perform any
CAG.  The CAG operations go much faster because of these
precalculations, but if your only goal is to use Area to make a Shape
relocatable then the Area class (and its corresponding caveats and
precalculations) is overkill.

4. When you use the Area.transform(AT) method, the precalculations that
were done when the Area was constructed must be reexecuted and that
takes additional time as well.

As a result, I wouldn't use the Area class unless you are planning to
perform CAG operations on the Shapes.

However, the GeneralPath class (and now Path2D in JDK 6) offers very
similar capabilities.  There is a GeneralPath.transform(AT) method just
as on the Area class.  The even better news is that GeneralPath is
simply a repository of geometry, unlike Area, so it is very fast to
create one from an arbitrary Shape and it is also fast to transform it.

In the end, though, if you are having to implement any kind of mechanism
to manage your Shape objects, I would put translation (and other
transformation information) into that architecture and go for a full
Model/View approach rather than look to transform the Shapes themselves...

   ...jim

[EMAIL PROTECTED] wrote:

Hi swv,

I'm definitely not comfortable with my own Java2D capabilities but recently 
I've been working with the Area class alot and I think you should take alook at 
it. It is a mutable shape implementation as far as I know - take alook at 
Area.transform(AffineTransform at). With this you wouldn't have to translate 
your Graphics object at all, and your areas will still be where you left them 
the next time paint is called.  Also, Area can take any Shape in its 
constructor and it will try to construct a suitable Area interpretation of the 
given shape. Just remember to translate the new Area as necessary. I hope this 
may be of some assistance.

Regards,

Pierre
[Message sent by forum member 'irond13' (irond13)]

http://forums.java.net/jive/thread.jspa?messageID=228441

===
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".


===
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".


Re: [JAVA2D] AffineTransformation

2007-07-27 Thread Jim Graham

I wanted to clarify some points here...

[EMAIL PROTECTED] wrote:
[Points 1 and 2 omitted - all true]


3) Remembering that the goal as to shuffle these around the screen, and having 
them at definite places which are not so easily mutated, what's a developer to 
do?


Generally if a bunch of arbitrary shapes are to be manipulated, a
"model/view" system is constructed which manages mapping between the
coordinate space of the shape and the coordinate space of the view.


In order to draw them where I want them, it's a matter of remembering where they wer 
drawn last, getting the Graphics into device space 0,0 (which coincides with user-space 
0, 0 ) and now that device and user spaces are in agreement, using one of the methods of 
graphics to relocate where the "tip" of the graphics pen is located and hence 
where it will draw. IF I want the Shape to be at 100,500, then I relocate the graphics 
there and so on.


That is the beginnings of a model/view system.  Your terminology is
confusing, I would say that one should "translate the coordinate system
of the graphics so that 0,0 in user space refers to the appropriate
location of the object in the original coordinate system".

I'm not sure why you refer to "the tip of the pen" since the Graphics
object doesn't have a pen that has a location per se.  It does have an
attribute that defines how to stroke paths, and the default
implementation of that attribute (the BasicStroke) does operate as if it
were dragging a "pen" along the shape, but that "pen" is relative to the
path being drawn, it doesn't have an independent concept of "its location".

Also note that I said "original coordinate system" above, rather than
"device coordinate system" because when the paint() method is called (or
the Swing paintComponent() method), there may be some translation or
scaling that was applied by the system which means that the default
coordinate system when you start the paint() method is not "device
space".  At the very least, the 0,0 origin of the incoming graphics
object points to the upper left corner of your component, but your
component is likely not located at 0,0 on the screen, or even at 0,0 on
the window it is on.  Going beyond that, if you are printing then the
scale factor may not be 1:1 when the method is called to generate output
for the printer.  Perhaps "Component coordinate system" would be a
better term there.


Now my shapes appear where I want them. But their other methods, contains() 
intersects() et.al. are all liars, or at least, out of sync with where the 
Shape has been drawn.


I wouldn't call them "liars".  Those methods are defined relative to the
coordinate space in which they are drawn.  If you draw them in a
modified coordinate space, then you need to perform hit testing relative
to that coordinate space as well.


To bring these other methods into line, you have to, in the case of intersects 
and contains, first displace the point you're asking about so that it is 
relocated back into that ULHC where all the Shapes think they live, piled up 
one on top of the other.


This is where a good model/view system comes into play.  Not only does
it manage modifying the coordinate system on the Graphics during
rendering operations, it should also provide mechanisms to modify
coordinates being hit tested so that they are relative to the same
coordinate system in which the object is rendered within the view.


By my measure, Shape and its implementations have a built in contradiction with 
respect to the separation between Model and View, which could be a source of 
confusion.


I think it is better to consider that all of their methods are defined
within a single consistent coordinate system.  If your model/view system
translates the graphics to render them at a specific location and
orientation, then it needs to also perform equivalent transformations on
any other coordinates that are compared or executed against any other
Shape methods.

In this manner I consider the Shape interface to be Model and View
agnostic.  It doesn't provide any mechanisms to adjust for either a
Model transform or a View transform.  It is your Model/View architecture
which must maintain consistency in its interactions with the Shape
interface.

Beyond that, all is left up to your model/view implementation so the
ensuing paragraphs about how the Shape agrees or conflicts with either
the "Model" or the "View" concept are really just the fact that such
concepts are beyond the scope of the Shape interface as I have described
above.


But that AT, at least this is how it seems to me , is more View than anything 
else, while the Shape itself, which is to say the Model, lives unchanging 
elsewhere.


Again, I consider the AT to be a tool.  Model and View architectures are
free to use that tool to implement their own concepts and designs, but
the AT is not a View and it is not a Model, it is just a 6 element
affine transformation.


Because we have no, efficient, non- list-o'-points w

Re: [JAVA2D] AffineTransformation

2007-07-27 Thread java2d
Hi swv,

what is it that you're looking for without dependancies on SwingX and 
Substance? If it's the whole test app then I can't help since the whole point 
of the app was to show the difference between Substance and Metal. If it's my 
RoundedPanel you want, I can make a plan - removing its dependancy on Substance 
is easy enough but since it extends JXPanel and makes use of ShapePainter to 
paint itself, this will take a bit a longer. In any case I would really 
recommend getting the SwingX library, especially if you're doing alot of custom 
painting. Just let me know what you want & I'll see what I can do.

Regards,
Pierre
[Message sent by forum member 'irond13' (irond13)]

http://forums.java.net/jive/thread.jspa?messageID=228551

===
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".