none
Awkward Graphics.DrawPolygon method bevavior RRS feed

  • Question

  • Hello,

    I've been trying to develop a simple program to draw some fractals (not complete fractals, that's basically impossible!), in order to improve my F# skills, and I'm not used to drawing graphics, so I haven't been able to find the reason for my problem. Here's the relevant code snippet:

    use img = new Bitmap(300, 300) use gr = Graphics.FromImage img use caneta = new Pen(brush = Brushes.Black, width = 0.5f) let pontos = // (1) [|new PointF(20.0f, 30.0f); new PointF(200.0f, 30.0f); new PointF(20.0f, 300.0f); new PointF(200.0f, 300.0f)|] let fractTeste : PointF[] = // (2) ([new PointF(20.0f, 20.0f); new PointF(40.0f, 20.0f)]) |> Base.aplicFractal 5 Base.funcFractal1 |> List.toArray gr.DrawPolygon(caneta, pontos) // (3) gr.DrawPolygon(caneta, fracTeste) // (4)

    The comment labeled lines (1) and (3) are tests that do work and compile, and that can be commented out with no interferences. (2): The ": PointF[]" thing (I don't remember its name) makes no difference in the resulting errors, it was my (failed) attempt to make it all work. Finally, (4) is the line that results in 2 errors, shown below:

    --- A unique overload for method 'DrawPolygon' could not be determined based on type information prior to this program point. A type annotation may be needed. Candidates: Graphics.DrawPolygon(pen: Pen, points: Point []) : unit, Graphics.DrawPolygon(pen: Pen, points: PointF []) : unit

    --- The value or constructor 'fracTeste' is not defined

    Below are the method signatures (I could give you the whole code, but it would just fill up the post, and I don't think it is important, it is certainly not the place from which the error comes) used by the above code snippet:

    val inline internal deltaAbs : x:^a *  y:^b -> float32
        when ( ^a or  ^b) : (static member ( - ) :  ^a *  ^b ->  ^c)
         and ^c : (static member op_Explicit :  ^c -> float32)
    val comprimento : pontos:PointF list -> float32
    val angulo : segm:(PointF * PointF) -> float32
    val funcFractal1 : pontos:PointF list -> PointF list
    // ...
    val aplicFractal : numPassos:int -> funcFractal:(PointF list -> PointF list) -> pontos:PointF list -> PointF list

    The first 3 functions are used by the 4th. Also, as a side-question (does this expression exist?), should any of the functions have a different parameter order?

    Thanks for reading, I hope you can help!


    "Penso, logo existo" - René Descartes
    "A produção de muitas coisas úteis resulta em muitas pessoas inúteis" - Karl Marx
    "Vive como se fosses morrer amanhã, aprende como se fosses viver para sempre" - Mahatma Gandhi

    João Miguel

    Saturday, March 2, 2013 7:44 PM

Answers

  • It's a simple typo
    let fractTeste : PointF[] = // (2)
    gr.DrawPolygon(caneta, fracTeste) // (4)
    There's a second letter t in the first identifier.
    • Marked as answer by JMCF125 Saturday, March 2, 2013 10:11 PM
    Saturday, March 2, 2013 9:30 PM

All replies

  • It's a simple typo
    let fractTeste : PointF[] = // (2)
    gr.DrawPolygon(caneta, fracTeste) // (4)
    There's a second letter t in the first identifier.
    • Marked as answer by JMCF125 Saturday, March 2, 2013 10:11 PM
    Saturday, March 2, 2013 9:30 PM
  • Actually, there's a 't' lacking in the first identifier :) "fractTeste" is to test a fractal.

    I knew that was some kind of boneheaded error, but it was so boneheaded of me that I couldn't find it. Thank you very much, it would take me forever to get it myself.

    Also, do you think the functions should have their parameters in other order? Is there any recommendation like "most important last, numbers first"?


    "Penso, logo existo" - René Descartes
    "A produção de muitas coisas úteis resulta em muitas pessoas inúteis" - Karl Marx
    "Vive como se fosses morrer amanhã, aprende como se fosses viver para sempre" - Mahatma Gandhi

    João Miguel

    Saturday, March 2, 2013 10:11 PM