當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Box::getArea方法代碼示例

本文整理匯總了PHP中Box::getArea方法的典型用法代碼示例。如果您正苦於以下問題:PHP Box::getArea方法的具體用法?PHP Box::getArea怎麽用?PHP Box::getArea使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Box的用法示例。


在下文中一共展示了Box::getArea方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: findPath


//.........這裏部分代碼省略.........
        /*if ($debug_all) {
              echo "lines_array<br/>\n";
              print_r($lines_array);
              echo "<br/>\n";
          }*/
        $DoF = getDegreeOfFreedom($lines_array);
        $connection_added = array();
        if ($DoF - 1 <= 1) {
            // station only has two connections
            // grab the next station
            $old_marker = $path->getSTLMarker();
            // loop through each connection and find the new marker
            #echo "connections = <br/>";
            foreach ($lines_array[0]->getConnections() as $connection) {
                #echo $connection->id . ": ";
                if ($connection->id != $old_marker->id) {
                    // new marker found, add to path
                    $next_marker = $markers[$connection->id];
                    //if ($debug) {
                    //    echo "next_marker: $next_marker->id<br/>";
                    //}
                    $original_dist = $last_marker->point->getDistanceMiles($end_marker->point);
                    $dist = $next_marker->point->getDistanceMiles($end_marker->point);
                    #echo "p2p distance = $dist ";
                    #echo "from " . $next_marker->toString() . "<br/>";
                    // calculate the box
                    if ($single_path_length < 3) {
                        $new_box = new Box($next_marker->point, $end_marker->point);
                    } else {
                        $new_box = null;
                    }
                    $single_path_length = $path->single_path_length;
                    if ($original_dist < $dist && $single_path_length > 2) {
                        if ($new_box->getArea() > $boundary_box->getArea()) {
                            // outside our scope, move to closed list
                            ##echo "spl: $single_path_length :: bounding box (". $next_marker->id .") is too big: " . $new_box->getArea() . ">" . $boundary_box->getArea() . ". will not add path...<br/>";
                            $closed[] = $path;
                            continue;
                        }
                    }
                    $single_path_length++;
                    if (in_array($next_marker, $path->visited)) {
                        if ($debug_all) {
                            echo "connection (" . $connection->id . ") is backtracking to " . $next_marker->toString() . ". ignoring.<br/>";
                        }
                        continue;
                    }
                    if (in_array($next_marker->id, $connection_added)) {
                        if ($debug_all) {
                            echo "[{$next_marker->id}] marker was already added. skipping.<br/>\n";
                        }
                        continue;
                    }
                    $new_path = new Path2($path, $next_marker, $lines_array[0], $connection->duration + $STATION_STOP_TIME, $connection->type, $new_box, $path->visited, $single_path_length);
                    $connection_added[] = $next_marker->id;
                    // check to see if the new station is one of the end stations. if so, then mark the path as completed and remove from OPEN
                    foreach ($end_stations as $station) {
                        /*
                            If the station marker is the next marker, then we know we're at one of the end points. We will definitely add this path, but we should also make one more check to see if the next possible marker is also an end station.
                        */
                        if ($station->marker == $next_marker) {
                            // grab the next set of markers from this marker and see if any of them are also end stations
                            $next_lines = $next_marker->lines;
                            foreach ($next_lines as $next_line) {
                                $next_connections = $next_line->connections;
                                foreach ($next_connections as $next_connection) {
開發者ID:abc2mit,項目名稱:abc2mit.github.io,代碼行數:67,代碼來源:algorithm2.php

示例2: createPaths

function createPaths($station, $destination)
{
    $debug = false;
    if ($debug) {
        echo "algorithm.createPaths()<br/>\n";
        echo "looking at station: " . $station->toString() . "<br/>\n";
    }
    $open = array();
    $connectionCreated = array();
    foreach ($station->getLines() as $line) {
        foreach ($line->getConnections() as $connection) {
            $id = $connection->id;
            if (in_array($id, $connectionCreated)) {
                continue;
            }
            // get associated marker
            $station2 = retrieveStation($id);
            $connectionCreated[] = $id;
            if ($debug) {
                echo "retrieved marker from connection (" . $id . "): ";
                $station2->printInfo();
            }
            $lines = $station->getOverlapLines($station2);
            $segment = new Segment($station, $station2, $lines, $connection->duration, $connection->type);
            $visited = array();
            $visited[] = $station;
            $visited[] = $station2;
            $new_box = new Box($station2->point, $destination->point);
            $path = new Path($segment, $visited, $destination);
            if ($debug) {
                echo "creating path: ";
                echo $path->toString() . "<br/>\n";
            }
            /*if ($station == $station2) {
                  return $path;
              }*/
            $area = $new_box->getArea();
            $array = $open["{$area}"];
            if ($array == null) {
                $array = array();
            }
            $array[] = $path;
            $open["{$area}"] = $array;
        }
    }
    return $open;
}
開發者ID:abc2mit,項目名稱:abc2mit.github.io,代碼行數:47,代碼來源:algorithm.php

示例3: findPath

/**
    @param $end_marker<Marker> can be null if S2S search
    @return<Path2> a path from the start to the end or null if none is found
*/
function findPath($open, $end_stations, $end_marker)
{
    $walking_speed = 2 / 3600;
    #echo "findPath<br/>";
    global $markers;
    // create array of completed paths
    $completed = array();
    // create closed paths
    $closed = array();
    $restart = false;
    //$boundary_box = $original_box;
    #$counter = 0;
    $completed_time = -1;
    $completed_stops = -1;
    $multiple_paths = array();
    while (count($open) > 0) {
        #echo "loop: $counter<br/>";
        #$counter++;
        ##echo "open size = " . count($open) . "<br/>";
        //if (count($completed) > 4) {
        //    break;
        //}
        ksort($open);
        // look at the path at the front of OPEN, remove from list
        $keys = array_keys($open);
        #echo "KEYS = ";
        #print_r($keys);
        #echo "<br/>";
        $multiple_paths = $open[$keys[0]];
        $path = array_shift($multiple_paths);
        if (count($multiple_paths) == 0) {
            unset($open[$keys[0]]);
            if (count($open) > 0) {
                reset($open);
            } else {
                $open = array();
            }
        } else {
            $open[$keys[0]] = $multiple_paths;
        }
        if ($completed_time > 0 && $completed_time < $path->time) {
            #echo "path is too long ($completed_time < " . $new_path2->time . "). discard.<br/>";
            continue;
        }
        $par = $completed_time * pow($completed_stops, 2);
        if ($completed_stops > 0 && $completed_time > 0) {
            $metric = pow(count($path->path), 2) * $path->time;
            #echo "metric = $metric | par = $par<br/>";
            if ($par / $metric < 0.8) {
                #echo "path metric is too big (" . $par/$metric . "). discard.<br/>";
                continue;
            }
        }
        $boundary_box = $path->bounding_box;
        #echo "box area = " . $boundary_box->getArea() . "<br/>";
        #echo "open size (after shift) = " . count($open) . "<br/>";
        // print path
        ##echo $path->toString();
        // find degree of freedom for each station at the end of each path
        // DoF is defined as the number of outbound connections from the marker
        $last_marker = $path->getLastMarker();
        $box = new Box($last_marker->point, $end_marker->point);
        #$dist = $last_marker->point->getDistanceMiles($end_marker->point);
        #echo "p2p distance = $dist ";
        #echo "from".$last_marker->toString()."<br/>";
        #echo "box area = " . $box->getArea() . "<br/>";
        #$stl_marker = $path->getSTLMarker();
        #echo $stl_marker->toString() . " looking at marker = [" . $last_marker->toString() . "]<br/>";
        $lines_array = $last_marker->getLines();
        $DoF = getDegreeOfFreedom($lines_array);
        $connection_added = array();
        if ($DoF - 1 <= 1) {
            // station only has two connections
            // grab the next station
            $old_marker = $path->getSTLMarker();
            // loop through each connection and find the new marker
            #echo "connections = <br/>";
            foreach ($lines_array[0]->getConnections() as $connection) {
                #echo $connection->id . ": ";
                if ($connection->id != $old_marker->id) {
                    // new marker found, add to path
                    $next_marker = $markers[$connection->id];
                    $original_dist = $last_marker->point->getDistanceMiles($end_marker->point);
                    $dist = $next_marker->point->getDistanceMiles($end_marker->point);
                    #echo "p2p distance = $dist ";
                    #echo "from " . $next_marker->toString() . "<br/>";
                    // calculate the box
                    $new_box = new Box($next_marker->point, $end_marker->point);
                    if ($original_dist < $dist) {
                        if ($new_box->getArea() > $box->getArea()) {
                            // outside our scope, move to closed list
                            #echo "bounding box (". $next_marker->id .") is too big: " . $new_box->getArea() . ">" . $box->getArea() . ". will not add path<br/>";
                            $closed[] = $path;
                            continue;
                        }
                    }
//.........這裏部分代碼省略.........
開發者ID:abc2mit,項目名稱:abc2mit.github.io,代碼行數:101,代碼來源:algorithm2.php

示例4: findPath


//.........這裏部分代碼省略.........
        // find degree of freedom for each station at the end of each path
        // DoF is defined as the number of outbound connections from the marker
        $last_marker = $path->getLastMarker();
        //$box = new Box($last_marker->point, $end_marker->point);
        #echo "box area = " . $box->getArea() . "<br/>";
        #$stl_marker = $path->getSTLMarker();
        #echo $stl_marker->toString() . " looking at marker = [" . $last_marker->toString() . "]<br/>";
        $lines_array = $last_marker->getLines();
        $DoF = getDegreeOfFreedom($lines_array);
        $connection_added = array();
        if ($DoF - 1 <= 1) {
            // station only has two connections
            // grab the next station
            $old_marker = $path->getSTLMarker();
            // loop through each connection and find the new marker
            #echo "connections = <br/>";
            foreach ($lines_array[0]->getConnections() as $connection) {
                #echo $connection->id . ": ";
                if ($connection->id != $old_marker->id) {
                    // new marker found, add to path
                    $next_marker = $markers[$connection->id];
                    $original_dist = $last_marker->point->getDistanceMiles($end_marker->point);
                    $dist = $next_marker->point->getDistanceMiles($end_marker->point);
                    #echo "p2p distance = $dist ";
                    #echo "from " . $next_marker->toString() . "<br/>";
                    // calculate the box
                    if ($single_path_length < 3) {
                        $new_box = new Box($next_marker->point, $end_marker->point);
                    } else {
                        $new_box = null;
                    }
                    $single_path_length = $path->single_path_length;
                    if ($original_dist < $dist && $single_path_length > 2) {
                        if ($new_box->getArea() > $boundary_box->getArea()) {
                            // outside our scope, move to closed list
                            ##echo "spl: $single_path_length :: bounding box (". $next_marker->id .") is too big: " . $new_box->getArea() . ">" . $boundary_box->getArea() . ". will not add path...<br/>";
                            $closed[] = $path;
                            continue;
                        }
                    }
                    $single_path_length++;
                    if (in_array($next_marker, $path->visited)) {
                        if ($debug_all) {
                            echo "connection (" . $connection->id . ") is backtracking to " . $next_marker->toString() . ". ignoring.<br/>";
                        }
                        continue;
                    }
                    if (in_array($next_marker->id, $connection_added)) {
                        if ($debug_all) {
                            echo "[{$next_marker->id}] marker was already added. skipping.<br/>\n";
                        }
                        continue;
                    }
                    $new_path = new Path2($path, $next_marker, $lines_array[0], $connection->duration + $STATION_STOP_TIME, $connection->type, $new_box, $path->visited, $single_path_length);
                    $connection_added[] = $next_marker->id;
                    // check to see if the new station is one of the end stations. if so, then mark the path as completed and remove from OPEN
                    foreach ($end_stations as $station) {
                        if ($station->marker == $next_marker) {
                            if ($end_marker != $next_marker) {
                                // add end location marker
                                $new_path2 = new Path2($new_path, $end_marker, null, $station->getDistance() / $WALKING_SPEED, "walking", $box, $new_path->visited, $single_path_length);
                            } else {
                                $new_path2 = $new_path;
                            }
                            if ($completed_time > 0 && $completed_time < $new_path2->time) {
                                if ($debug_all) {
開發者ID:abc2mit,項目名稱:abc2mit.github.io,代碼行數:67,代碼來源:algorithm2.php


注:本文中的Box::getArea方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。