PHP code example of kudm761 / martinez-rueda-php

1. Go to this page and download the library: Download kudm761/martinez-rueda-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kudm761 / martinez-rueda-php example snippets


$ composer 

    $data = [[[-1, 4], [-3, 4], [-3, 0], [-3, -1], [-1, -1], [-1, -2], [2, -2], [2, 1], [-1, 1], [-1, 4]]];
    $subject = new \MartinezRueda\Polygon($data);
    
    $data = [[[-2, 5], [-2, 0], [3, 0], [3, 3], [2, 3], [2, 2], [0, 2], [0, 5], [-2, 5]]];
    $clipping = new \MartinezRueda\Polygon($data);
    
    $result = (new \MartinezRueda\Algorithm())->getUnion($subject, $clipping);
    
    echo json_encode($result->toArray()), PHP_EOL;
    
    // Result is:
    // [[[2,3],[2,2],[0,2],[0,5],[-2,5],[-2,4],[-3,4],[-3,0],[-3,-1],[-1,-1],[-1,-2],[2,-2],[2,0],[3,0],[3,3],[2,3]]]