Results 1 to 1 of 1

Thread: Point2D + Point2DCollection: Reusable units for your projects

  1. #1
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,146
    Rep Power
    735

    Point2D + Point2DCollection: Reusable units for your projects

    In case anyone would have need for Point2D and collection of such a data, I prepared units for it.
    They are fully unit tested and I use them in my projects, so I trust them enough to share.

    Key advantages:
    • smart memory management (adding points does not always mean reallocating)
    • built in serialization/deserialization to/from string, so you can easily store/load from files, if needed for example


    Full code in the attachements, here a little code to give you idea:
    Uses "Console"
    
    #INCLUDE "Point2DCollection.tBasicU" ' -- All you need to use the type
    
    Dim points As Point2DCollection
    
    points.Initialize() ' -- Allocates internal structures
    
      points.AddPoint(1, 2)
      points.AddPoint(3, 4)
      points.SetPoint(2,
                      30, 40) ' -- Alter the data for second point
      points.AddPoint(5, 6)
      
      Long i
      Dim p As Point2D
      PrintL "Point set, one by one:"
      For i = 1 To points.GetPointCount()
      
        p = points.GetPoint(i)  ' -- Retrieves copy of the data you can work further with
        PrintL p.ToString()     ' -- Serialization to string
      
      Next
      
      String serializedBackup = points.ToString()
      PrintL
      PrintL "Point set, in one go: " + points.ToString()
      
      points.RemovePoint(1) ' -- Remove one point, or...
      PrintL
      PrintL "Point set with first point gone, in one go: " + points.ToString()
      
      points.RemoveAll()    ' -- all of them
      PrintL                            
      PrintL "Point set with all points gone, in one go (nothing, because empty): " + points.ToString()
      
      
      
      PrintL
      points.FromString(serializedBackup) ' -- Deserialization from string is built in
      PrintL "New set, loaded from backup string:" + points.ToString()
    
    points.Release() ' -- When you are done, release memory
    
    PrintL
    PrintL "Press any key to quit..."
    WaitKey
    
    Feel free to use in your projects...


    Petr
    Attached Files Attached Files
    Last edited by Petr Schreiber; 14-06-2015 at 21:10.
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

Similar Threads

  1. UI_ Pixels, Units & all that
    By ReneMiner in forum UI (User Interface)
    Replies: 7
    Last Post: 20-10-2013, 12:40
  2. Projects
    By fgasoi in forum thinAir General
    Replies: 3
    Last Post: 19-11-2010, 08:14
  3. String size in pixels or units
    By Pipes in forum TBGL General
    Replies: 9
    Last Post: 18-06-2009, 17:28
  4. Replies: 4
    Last Post: 24-08-2007, 23:49

Members who have read this thread: 0

There are no members to list at the moment.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •