-1

I'm doing a project in which I use the AWT library with shapes a lot. Most of the classes implementing Shape work with both Double and Float, except Polygon. Why? Why in Gods name and grace?!

Am I correct in saying that I can achieve the same functionality with methods from Path2D and Area?

Most of all I am wondering the why aspect of it all.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Tim Kuipers
  • 1,705
  • 2
  • 16
  • 26

1 Answers1

3

Because Polygon has been apart of the API since version 1.0, the Shape API was introduced in version 1.2 and Polygon was updated to meet the basic requirements of the Shape API.

Also, take a look at the Graphics class, it has support for Polygon but not Shape, that was introduced into the Graphics2D class.

Am I correct in saying that I can achieve the same functionality with methods from Path2D and Area?

I would say, yes.

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
  • I can't see how this answers my question. – Tim Kuipers Jan 22 '13 at 11:30
  • Graphics have nothing to do with this part of my project! I am just dealing with computations on objects in 2D space. – Tim Kuipers Jan 22 '13 at 11:34
  • The point is, Polygon existed before the Shape API and was retrofitted to for the API after the fact and the purpose of the Shape API is for rendering Graphics to a number of hardware devices. I don't see how it doesn't answer your direct question - personally – MadProgrammer Jan 22 '13 at 20:15
  • I don't see any reference to Graphics in the Shape Interface description. The description clearly states that it concerns geometric shapes. The fact that we can visualize shapes is not fundamental to the API, as I see it. Even if the Shape API is for rendering Graphics, this information doesn't help me in understanding why different implementing classes take different strategies. As long as you don't mention anything about integers and doubles or floats, you will not be answering my question... – Tim Kuipers Jan 24 '13 at 21:05
  • The simple fact of the matter is - Polygon was included in the API BEFORE the shape API was included, this includes things like Line and Rectangle, all of which implement Shape, but DO NOT include Float or Double implementations (nb Line2D and Rectangle2D are implementations that do. The choice not to do a Polygon2D implementation probably steams from, as you pointed out, the introduction of Path2D and Area, there was no need). These existing "shapes" we're retrofitted to include the Shape API. The question is the same as why have Vector when we have List or HashTable when we have Hashmap – MadProgrammer Jan 24 '13 at 21:14
  • The matter of fact is, well probably never really know. The choice was made, presumably, to reduce the possible impact on existing code. For example, you can not instantiate Shape2D, you need to use either it's Float or Double implementation. Changing the Polygon implementation would have broken existing, production code. This is a design choice that is often taken by the Java team in order to try and preserve existing code bases while introducing new features and expanding the API. The new File API in the nio package is an excellent example, the old File API still exists, so it doesn't break – MadProgrammer Jan 24 '13 at 21:19
  • I think that now you have really answered my question. Thank you for taking the time and effort! And sorry if I have offended you or anything, by my persistence. – Tim Kuipers Jan 25 '13 at 10:28