Closed rubyFeedback closed 1 year ago
Hey @rubyFeedback. First of all, thank you very much for your interest in CodeDraw and your suggestion.
You shouldn't really need to convert the integers by hand, Java should be able to this task automatically. For example if you want to draw a triangle which spans the whole CodeDraw window you can use either of these codes (remember getWidth and getHeight both return integers).
cd.drawTriangle(cd.getWidth()/2, 0, 0, cd.getHeight(), cd.getWidth(), cd.getHeight());
or
cd.drawTriangle((double) cd.getWidth() / 2, (double) 0, (double) 0, (double) cd.getHeight(), (double) cd.getWidth(), (double) cd.getHeight());
Actually, in the second example Intellij will highlight the double cast gray because the conversion is not necessary.
If you find an example in which drawTriangle doesn't accept int
please provide an example, otherwise please close the issue.
Hopefully I could resolve your issue and thank you for your active participation.
Hey there Niklas and whoever else may read this,
I am currently working on the problem set in "Aufgabenblatt 2, Example 5". This is the free-form example where other students had solutions such as this:
https://i.imgur.com/h0AH6qX.png
So, for one of the shapes / subshapes that I want to draw I am contemplating using drawTriangle().
When I was using it, though, I noticed I had to use double values (6 of them, e. g. for the 3 vertices or end points or however one calls them).
API is:
My canvas, though, right now only needs integer values. Or at the least I was thinking I was using integer values for x-coordinate and y-coordinate of the various subshapes.
It is not a big deal either way; I can convert the integer values into double values. But I was also thinking that there should not be a reason to not allow integer values here? Or perhaps there is one and I am unaware of that - that could be the case too.
Either way, the TL;DR variant for this suggestion:
Would it be possible to add the "same" method signature as-is, but also allow integer values for x1, y1 etc...?
The primary rationale here is just for a bit of extra convenience. It's not necessary since we can convert our integer to double values easily, but if CodeDraw directly could support this then we can save a tiny bit of code in our implementation.
As always thank you for reading either way.