PHP Classes

PHP Rectangle Class: Perform operations and draw rectangle shapes

Recommend this page to a friend!

  Author Author  
Picture of Win Aung Cho
Name: Win Aung Cho <contact>
Classes: 11 packages by
Country: Myanmar Myanmar
Innovation award
Innovation award
Nominee: 3x


  Detailed description   Download Download .zip .tar.gz  
This class can perform operations and draw rectangle shapes.

It can take the coordinates of rectangular areas on a two-dimensional plane and perform several operations.

Currently, it can perform operations like:

- Merging rectangles

- Unite rectangles

- Subtract rectangles

- Etc...

After the rectangle operations, the class can also render the resulting shapes as images.

Details

PHP-RECTSLIB

This class Lib help you to construct the rectangles using various logical operations such as Union, Intersect and Subtract. It will generate the border edges of non-overlapped rectangles. JScript version

Algorythm

Algorythm is very simple. - A region on which contains all the rectangles is divided into several rectangles according to the corners of the rectangles. - Remove the rectangles above which does not lie inside all rectangles. This step gives the non-overlapped union of the rectangles. - Then choose or remove the rectangles which lies inside the subject rectangles according to boolean operation union, intersect or subtract.

Operation procedure

Create rectangles

Rectangles are represenred by the associative array in which diagonal points p1 and p2 are stored. Other variables for drawing are name, color and state. Point p1 is always upper left corner and p2 is for lower right of rectangles so that p1 has smaller value of x and y then p2.

$rectslib = new RectsLib();
$A = $rectslib->p1p2(10, 10, 300, 200, "A", $green);
$B = $rectslib->p1p2(40, 30, 200, 300, "B", $red);
$C = $rectslib->p1p2(150, 40, 400, 150, "C", $orange);
$D = $rectslib->p1p2(140, 320, 200, 400, "D", $blue);
$E = $rectslib->p1p2(80, 160, 250, 250, "E", $brown);
$rects = [$A, $B, $C, $D, $E];

Merge all rectangles into mesh

List all x and y coordinates from the corner points p1, p2 of rectangles. Sort x and y list and then create rectangles for all x and y. Get (2n-1)^2 mesh rectangles for n original rectangles.

$all = $rectslib->merge($rects, $grey);

Generate rectangle operation

Select mesh by checking inside or not the desired rectangles which for logical operation. Eg. If A B C D E are the recangles, - For union of [A B C] & [D E], mesh must be lied in side both of [A B C] & [D E]. - For subtract [B E] from [A B C D], mesh must be inside the [A B C D] and outside of [B E]. - For intersect [A B C D] & [B E], mesh must be inside of both [A B C] & [D E].

$uni = $rectslib->union([$A, $B, $C], [$E, $D]);
$subt = $rectslib->subtract([$A, $B, $C, $D], [$B, $E]);
$Intersect = $rectslib->intersect([$A, $B, $C, $D], [$B, $E]);

Generate bounding edges

Generate edges of each rectangles and select external edges by removing common edges.

$edges = $rectslib->genEdges($subt);
$rectslib->drawEdges($img, $edges, $white);

Check with Images

Original Rectangles

  • A-GREEN-{10,10:300,200}
  • B-RED-{40,30:200,300}
  • C-ORANGE-{150,40:400,150}
  • D-BLUE-{140,320:200,400}
  • E-BROWN-{80,160:250,250}

PHP-RECTSLIB

Start meshing for all rectangles

PHP-RECTSLIB

Meshing and get union of rectangles

  • Union of [A B] & [C D]
  • [A B] ? [C D] PHP-RECTSLIB

Intersection of all with 2 rectangles

  • Intersect of [A B C D] & [B E]
  • [A B C D] ? [B E] PHP-RECTSLIB

Subtract of 2 from all

  • Subtract [B E] from [A B C D]
  • [A B C D] - [B E] PHP-RECTSLIB

Contact

Contact me for comercial use via mail winaungcho@gmail.com.


  Classes of Win Aung Cho  >  PHP Rectangle Class  >  Download Download .zip .tar.gz  >  Support forum Support forum  >  Blog Blog  >  RSS 1.0 feed RSS 2.0 feed Latest changes  
Name: PHP Rectangle Class
Base name: php-rectslib
Description: Perform operations and draw rectangle shapes
Version: -
PHP version: 5
License: Custom (specified in a license file)
 
  Groups   Screenshots Screenshots   Applications   Files Files  

  Groups  
Group folder image Algorithms Numerical and statistical algorithms View top rated classes
Group folder image PHP 5 Classes using PHP 5 specific features View top rated classes
Group folder image Graphics Colors, images, charts and picture formats View top rated classes
Group folder image Math Math related classes. View top rated classes

  Files folder image Screenshots  
File Role Description
Files folder imageimages (5 files)

  Files folder image Screenshots  /  images  
images/rectsintersect.png
File Role Description
  Accessible without login Image file rectsintersect.png Screen Screenshot
  Accessible without login Image file rectsorigin.png Screen Screenshot
  Accessible without login Image file rectssubtract.png Screen Screenshot
  Accessible without login Image file rectsunion.png Screen Screenshot
  Accessible without login Image file rectsuniversal.png Screen Screenshot


  Applications that use this package  
No pages of applications that use this class were specified.

Add link image If you know an application of this package, send a message to the author to add a link here.

  Files folder image Files  
File Role Description
Files folder imagesrc (2 files, 1 directory)
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
Files folder imageimages (1 file)
  Accessible without login Plain text file example.php Example Example script
  Plain text file rectslib.php Class Class source

  Files folder image Files  /  src  /  images  
File Role Description
  Accessible without login Plain text file index.php Aux. Auxiliary script

Download Download all files: php-rectslib.tar.gz php-rectslib.zip
NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.
  Files folder image Files  
File Role Description
Files folder imagesrc (2 files, 1 directory)
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
Files folder imageimages (1 file)
  Accessible without login Plain text file example.php Example Example script
  Plain text file rectslib.php Class Class source

  Files folder image Files  /  src  /  images  
File Role Description
  Accessible without login Plain text file index.php Aux. Auxiliary script

Download Download all files: php-rectslib.tar.gz php-rectslib.zip
NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.