'SHAPEfill v1.0 by D.Griffiths  2005

HELP and NOTES about programme

This programme is freeware and may be used, modified and incorporated into your own programmes for non commercial purposes as long as I get top billing in your programme credits!

Credits
Thanks to all the folks at Just BASIC community whose ideas I have frequently borrowed (stolen) especially Janet Terra, Alyce Watson and John Davidson.

This programmes primary purpose is to fill irregular shapes and would be useful tool in any paint and draw  and other graphic programmes.

In addition the programme contains a simple draw routine and several demo routines to show how it works. Included in the folder are several shapes for demonstration purposes some of which it can fill others it cannot. These were created as part of my testing process. they have the ext. .dtf.

The programme slightly overdraws the size of the shape so is recommended for use on large area's not recommended for drawing icon's or intricate detail. 

To stop the programme launching in to the start up demo routine delete the lines indicated near the beginning. To change the fill colours modify variables "acolour$" for color "bcolour$" for back color and "ccolour$" for paper color. Also you could load your own bmp file to the background to draw over but you will need to add your own routine to this. The draw and fill routine will happily cope with this.

Note:- SHAPEfill.bas, jbdemo1.dtf, SHAPEdata.dti, SHAPEdata1.dti, SHAPEdata3.dtf and Shapehelp.txt should all be kept in the same folder so the programme can find them. 

The programme can be slow at times be patient!

MENUS
files
qsave & qload are quick save & load with a fixed file name SHAPEdata.dti
load & save  and save operate normally allowing the user to chose the name with the ext. .dtf 

DRAW
draw - is a drawing routine to draw your own shape.
redraw -  just redraws the shape.
 
fill - fills the shape. Note:- the current shape is automatically saved and is also loaded on start up this  has the name SHAPEdata1.dti 
cls - clears the screen.

demos
These are demonstration routines that show how the programme works. these also print all the calculation details to the main window. Not recommended you use the "just basic" shape in this as it is slow and confusing.

JBDEMO'S
Just a couple off simple demo's. The full demo shows how the shape was created.

CHECK
This selects the level of checking required more on that later.

STEP CHK.
This was written for checking the programme and steps drawing the shape at different stating positions. Not very useful. Reset turns it off.

time
Displays time taken to fill shape and toggles this feature on or off.

help
Your reading it now.


How the programme works.

The programme primarily fills in triangles as these can be used to fill any shape. The programme starts by calculating the shape details it then checks to see which is the inside of the shape by always working clockwise and if the shape is anticlockwise making it clock wise it does this by seeing if the 180 minus internal angle add up to 360 deg, if it is-360 anticlockwise and 0 means the shape is a figure of eight and cannot be filled. This comes free with this procedure. It also grades corners with difficulty to fill.

The next part is an non essential option, this checks to see if any of the lines cross one another to see if the shape can be filled. Generates error if it cannot. The programme then proceeds to find triangles it can fill. First it will try to fill triangles with a corner less than 5 deg. as small angles are the most difficult to fill and only get smaller as the process goes on then it selects triangles with a corner below 170 deg and leaves the rest to last as these will be broken up into smaller angles as the search progresses.

Next the programme checks to see if this triangle can be filled and does not cross any part of the shape if it does not, the triangle is filled . This check is optional but recommended. This carries on until all the shape is filled or it cannot find any more triangles to fill in which case it generates an error message.

To fill the triangle the programme calculates the triangle  details and fills it by drawing a succession of smaller triangles then filling the hole left in the middle with an inscribed circle. The programme very occasionally does not fill the triangle correctly. This is why corners are graded, it has trouble with very small & very large angles. 
 
The two check routines are optional but recommended their only problem is they slow the programme down this is why there is a time option which displays the total time to fill the shape so you can decide. Its curios shape three can be successfully filled with no checking but makes a right mess of shape thirteen (caused me a lot of grief). The rule is simple, regular simple shapes can be filled with no checking. You decide which option you require?

The programme listing contains remarks what each routine does though these are brief.

Statements marked (D) are demo statements and can be deleted from this routine. Routines marked (C) are check statements. I have not tested this, so proceed with caution!. Also a few need to be replaced with another line left remarked these are commented upon.

If some of the if statements in the programme seem to lack purpose they are do deal with special situations that may occur (even I can remember all the reasoning and one that I tried to delete but found it was still required, and I do not fully understand why it works). 

Convention uses origin of X=0 and Y=1000 in window pixel positions but X=0 and Y=0 for calculation purposes there for 100,200 in window position is equal to 100,800 for calculation , display and store purposes, there for if figures are to be entered manually or from a file they should follow this convention, going positive north/easterly, dimensions in pixels, The yzero and xzero variables may be changed for convenience, negative values for x and y that result do not matter.

For calculation purposes only:- 0 deg = north going clockwise i.e. 90 deg = east all calculations are worked out clockwise fashion in this way. For triangles corners are no 0 to 2 the sides are numbered the side opposite the angle. For shapes the corners are numbered 0 to N, sides are numbered the side proceeding the angle, for other details see remarks in programme.

.dti &  .dtf Files are created in the following format 1st.rnd no 452841 to confirm file type. 2nd. no of points then X & Y alternating to end of file.

Some of the demo's have been slowed down so you can see how the programme works.

I hope that is as clear as it confusing me writing this. 

Have fun?