Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. I'm looking for review in terms of readability, approachability of this code

I'm looking for review in terms of readability, approachability of this code

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsdatabasecom
15 Posts 4 Posters 65 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Lost User

    Even "lower case" comments without punctuation are "jarring" for some people. One can never be too well dressed; especially when out in public.

    "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

    honey the codewitchH Offline
    honey the codewitchH Offline
    honey the codewitch
    wrote on last edited by
    #5

    Ha! What's jarring to me is When people write partial sentences. - punctuating and capitalizing them as though they are complete sentences. Comments to me are usually partial thoughts rather than complete sentences like if(ptr) { // if not out of mem memcpy(buf,ptr,sizeof(buf)); // copy it } Like that, so that's why I do not punctuate

    Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

    L 1 Reply Last reply
    0
    • honey the codewitchH honey the codewitch

      // renders a Scalable Vector Graphic (SVG)
      // as an ASCII image
      // takes a filename and an optional
      // numeric percentage for scaling
      #include
      #include
      #include
      #include
      #include
      #include
      using namespace gfx;

      // prints a source as 4-bit grayscale ASCII
      template
      void print_ascii(const Source& src) {
      // the color table
      static const char* col_table = " .,-~;+=x!1%$O@#";
      // move through the draw source
      for (int y = 0; y < src.dimensions().height; ++y) {
      for (int x = 0; x < src.dimensions().width; ++x) {
      typename Source::pixel_type px;
      // get the pixel at the current point
      src.point(point16(x, y), &px);
      // convert it to 4-bit grayscale (0-15)
      const auto px2 = convert>(px);
      // get the solitary "L" (luminosity) channel value off the pixel
      size_t i = px2.template channel();
      // use it as an index into the color table
      putchar(col_table[i]);
      }
      putchar('\r'); putchar('\n');
      }
      }
      int main(int argc, char** argv) {
      if(argc>1) { // at least 1 param
      float scale = 1; // scale of SVG
      if(argc>2) { // 2nd arg is scale percentage
      int pct = atoi(argv[2]);
      if(pct>0 && pct<1000) {
      scale = ((float)pct/100.0f);
      }
      }
      // open the SVG file
      file_stream fs(argv[1]);
      svg_doc doc;
      // read it
      svg_doc::read(&fs,&doc);
      fs.close();
      // create a bitmap the size of our final scaled SVG
      auto bmp = create_bitmap>(
      {uint16_t(doc.dimensions().width*scale),
      uint16_t(doc.dimensions().height*scale)});
      // if not out of mem allocating bitmap
      if (bmp.begin()) {
      // clear it
      bmp.clear(bmp.bounds());
      // draw the SVG
      draw::svg(bmp,bmp.bounds(),doc,scale);
      // dump as ascii
      print_ascii(bmp);
      // free the bmp
      free(bmp.begin());
      }
      }
      return (argc<1);
      }

      And there's this documentation[^] I was wondering how difficult it

      J Offline
      J Offline
      jschell
      wrote on last edited by
      #6

      honey the codewitch wrote:

      I was wondering how difficult it is to follow

      Presuming it is the docs and not the code... Some review comments...(I didn't review completely - just randomly jumping around.) I suggest that you use a different name than 'GFX'. Possible that you might even be required to since a company uses that. Also makes it easier to google for information on it if it much more unique. You just start right up into what I can only presume is the setup. I say presumably because you do not actually state that. As an intro? example there should only be one example. Myself I prefer that code blocks are indented from explaining text. There is nothing in the entire document about exceptions or errors. Nor troubleshooting. ---------------------------------- Pixels Intro is a bit odd. There are subsections but those are not in the table of contents? Pixels section is also hanging out by itself in table of contents. Perhaps Pixels should be under 'Addendum'? Seems like it might fit. Arduino TFT Bus Lots of stuff like 'PIN_NUM_CS' in code. Is that a stand in for actual hard value? A macro that user must define? From the library (your library) that you reference? Streams This seems extreme. Anyone that is going to be using this successfully needs to already understand a fairly high level of programming. So is this section needed? Suspend and Resume What happens if there is a suspend but then I want to stop completely? Drivers This is in the wrong location based on the content (sparse). This and what you put in the header suggests you need a section on setting up to use the library including decisions (with examples) that one might make. Tools Fontgen seems to make sense to me but Bingen doesn't. Always concerning to me when header files initialize data. Which is what the text seems to suggest with 'test_dat_stream'? There is an odd 'performance' link at the bottom of this page?

      honey the codewitchH 2 Replies Last reply
      0
      • J jschell

        honey the codewitch wrote:

        I was wondering how difficult it is to follow

        Presuming it is the docs and not the code... Some review comments...(I didn't review completely - just randomly jumping around.) I suggest that you use a different name than 'GFX'. Possible that you might even be required to since a company uses that. Also makes it easier to google for information on it if it much more unique. You just start right up into what I can only presume is the setup. I say presumably because you do not actually state that. As an intro? example there should only be one example. Myself I prefer that code blocks are indented from explaining text. There is nothing in the entire document about exceptions or errors. Nor troubleshooting. ---------------------------------- Pixels Intro is a bit odd. There are subsections but those are not in the table of contents? Pixels section is also hanging out by itself in table of contents. Perhaps Pixels should be under 'Addendum'? Seems like it might fit. Arduino TFT Bus Lots of stuff like 'PIN_NUM_CS' in code. Is that a stand in for actual hard value? A macro that user must define? From the library (your library) that you reference? Streams This seems extreme. Anyone that is going to be using this successfully needs to already understand a fairly high level of programming. So is this section needed? Suspend and Resume What happens if there is a suspend but then I want to stop completely? Drivers This is in the wrong location based on the content (sparse). This and what you put in the header suggests you need a section on setting up to use the library including decisions (with examples) that one might make. Tools Fontgen seems to make sense to me but Bingen doesn't. Always concerning to me when header files initialize data. Which is what the text seems to suggest with 'test_dat_stream'? There is an odd 'performance' link at the bottom of this page?

        honey the codewitchH Offline
        honey the codewitchH Offline
        honey the codewitch
        wrote on last edited by
        #7

        Thanks! I'll bookmark this feedback and use it when I do a doc update.

        Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

        1 Reply Last reply
        0
        • honey the codewitchH honey the codewitch

          Ha! What's jarring to me is When people write partial sentences. - punctuating and capitalizing them as though they are complete sentences. Comments to me are usually partial thoughts rather than complete sentences like if(ptr) { // if not out of mem memcpy(buf,ptr,sizeof(buf)); // copy it } Like that, so that's why I do not punctuate

          Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #8

          Exactly ... missing punctuation (for me) is an incomplete thought. My comments are comments; and sometimes they are instructions; and sometimes they are warnings. Anything else is noise.

          "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

          1 Reply Last reply
          0
          • J jschell

            honey the codewitch wrote:

            I was wondering how difficult it is to follow

            Presuming it is the docs and not the code... Some review comments...(I didn't review completely - just randomly jumping around.) I suggest that you use a different name than 'GFX'. Possible that you might even be required to since a company uses that. Also makes it easier to google for information on it if it much more unique. You just start right up into what I can only presume is the setup. I say presumably because you do not actually state that. As an intro? example there should only be one example. Myself I prefer that code blocks are indented from explaining text. There is nothing in the entire document about exceptions or errors. Nor troubleshooting. ---------------------------------- Pixels Intro is a bit odd. There are subsections but those are not in the table of contents? Pixels section is also hanging out by itself in table of contents. Perhaps Pixels should be under 'Addendum'? Seems like it might fit. Arduino TFT Bus Lots of stuff like 'PIN_NUM_CS' in code. Is that a stand in for actual hard value? A macro that user must define? From the library (your library) that you reference? Streams This seems extreme. Anyone that is going to be using this successfully needs to already understand a fairly high level of programming. So is this section needed? Suspend and Resume What happens if there is a suspend but then I want to stop completely? Drivers This is in the wrong location based on the content (sparse). This and what you put in the header suggests you need a section on setting up to use the library including decisions (with examples) that one might make. Tools Fontgen seems to make sense to me but Bingen doesn't. Always concerning to me when header files initialize data. Which is what the text seems to suggest with 'test_dat_stream'? There is an odd 'performance' link at the bottom of this page?

            honey the codewitchH Offline
            honey the codewitchH Offline
            honey the codewitch
            wrote on last edited by
            #9

            Regarding your comments on my use of x and y, I honestly can't think of a more descriptive name for them, as they translate directly to 2D cartesian coordinates*. In math that's x and y. *y is inverted. Anyway, do you have suggestions for those, as I am drawing a blank?

            Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

            K L J 4 Replies Last reply
            0
            • honey the codewitchH honey the codewitch

              Regarding your comments on my use of x and y, I honestly can't think of a more descriptive name for them, as they translate directly to 2D cartesian coordinates*. In math that's x and y. *y is inverted. Anyway, do you have suggestions for those, as I am drawing a blank?

              Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

              K Offline
              K Offline
              k5054
              wrote on last edited by
              #10

              honey the codewitch wrote:

              Anyway, do you have suggestions for those, as I am drawing a blank?

              There's always abcissa and ordinate, but that's getting just a wee bit pedantic, in my opinion. I think that anyone familiar with the problem space would probably expect the use of x, y (and z) for cartesian coordinates. At the very least, they shouldn't be confused by it. Just as you wouldn't expect someone to be confused by the use of (theta,r) for polar coordinates, or F=m*a, etc.

              Keep Calm and Carry On

              1 Reply Last reply
              0
              • honey the codewitchH honey the codewitch

                Regarding your comments on my use of x and y, I honestly can't think of a more descriptive name for them, as they translate directly to 2D cartesian coordinates*. In math that's x and y. *y is inverted. Anyway, do you have suggestions for those, as I am drawing a blank?

                Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #11

                x and y it is (X and Y as properties) ... and often, accompanied by Left and Top. And you should be aware when they correspond. x and y can also simply mean displacements.

                "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

                1 Reply Last reply
                0
                • honey the codewitchH honey the codewitch

                  Regarding your comments on my use of x and y, I honestly can't think of a more descriptive name for them, as they translate directly to 2D cartesian coordinates*. In math that's x and y. *y is inverted. Anyway, do you have suggestions for those, as I am drawing a blank?

                  Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #12

                  I think anyone who works, or wants to, with computer graphics, will understand the use of x and y addressing.

                  1 Reply Last reply
                  0
                  • honey the codewitchH honey the codewitch

                    Regarding your comments on my use of x and y, I honestly can't think of a more descriptive name for them, as they translate directly to 2D cartesian coordinates*. In math that's x and y. *y is inverted. Anyway, do you have suggestions for those, as I am drawing a blank?

                    Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                    J Offline
                    J Offline
                    jschell
                    wrote on last edited by
                    #13

                    honey the codewitch wrote:

                    Regarding your comments on my use of x and y

                    Me? I don't think I said anything about that.

                    honey the codewitchH L 2 Replies Last reply
                    0
                    • J jschell

                      honey the codewitch wrote:

                      Regarding your comments on my use of x and y

                      Me? I don't think I said anything about that.

                      honey the codewitchH Offline
                      honey the codewitchH Offline
                      honey the codewitch
                      wrote on last edited by
                      #14

                      I could have sworn you did, but sure enough you did not. :laugh: I can't find it on this thread, so I don't know where I got that. Sorry!

                      Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                      1 Reply Last reply
                      0
                      • J jschell

                        honey the codewitch wrote:

                        Regarding your comments on my use of x and y

                        Me? I don't think I said anything about that.

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #15

                        I assumed you saw something we didn't get to see, somehow.

                        "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups