本文整理汇总了PHP中Rectangle类的典型用法代码示例。如果您正苦于以下问题:PHP Rectangle类的具体用法?PHP Rectangle怎么用?PHP Rectangle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Rectangle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetArea
function testGetArea()
{
// Need a Rectangle:
$r = new Rectangle(8, 9);
// The assertion tests the math:
$this->assertEquals(72, $r->getArea());
}
示例2: test_getFullDescription
public function test_getFullDescription()
{
$rectangle = new Rectangle(6, 7);
$id = $rectangle->getId();
$name = str_shuffle(time());
$rectangle->name = $name;
$this->assertEquals('Rectangle<#' . $id . '>: ' . $name . ' - 6 x 7', $rectangle->getFullDescription());
}
示例3: areaVerifier
function areaVerifier(Rectangle $r)
{
$r->setWidth(5);
$r->setHeight(4);
if ($r->area() != 20) {
return false;
}
return true;
}
示例4: Rectangle
<?php
require_once "rectangle.php";
require_once "square.php";
$rectangle = new Rectangle(15, 5);
$square = new Square(10);
echo $rectangle->getArea() . PHP_EOL;
echo $square->getArea() . PHP_EOL;
echo $square->getPerimeter() . PHP_EOL;
示例5: saveRectangle
function saveRectangle()
{
if (!isset($_POST['topA']) || !isset($_POST['topB']) || !isset($_POST['leftA']) || !isset($_POST['leftB'])) {
return array("success" => false, "error" => "Wrong formatted request");
}
$rectangle = new Rectangle((int) $_POST['topA'], (int) $_POST['leftA'], (int) $_POST['topB'], (int) $_POST['leftB']);
if ($rectangle->save()) {
return array("success" => true);
}
return array("success" => false, "error" => $rectangle->isValid() ? "Oops, something went wrong when saving the rectangle" : "Rectangle with no width and height cannot be registered.");
}
示例6: loadCache
public function loadCache()
{
$rect = new Rectangle();
$rect->setId("1");
$this->shapeMap["1"] = $rect;
$square = new Square();
$square->setId("2");
$this->shapeMap["2"] = $square;
$circle = new Circle();
$circle->setId("3");
$this->shapeMap["3"] = $circle;
}
示例7: Rectangle
<?php
// PHP exercise about extending classes from a parent class. Rectangle is the parent class.
// Square is the child class extending off of Rectangle.
// This file runs in the command line.
// Because Square.php requires Rectangle.php, this file has access to both.
require_once 'Square.php';
$rectangle = new Rectangle(5, 10);
echo 'Rectangle area: ' . $rectangle->getArea() . PHP_EOL;
echo 'Rectangle perimeter: ' . $rectangle->getPerimeter() . PHP_EOL;
$square = new Square(9);
echo 'Square area: ' . $square->getArea() . PHP_EOL;
echo 'Square perimeter: ' . $square->getPerimeter() . PHP_EOL;
示例8: setHeight
$this->setWidth($width);
}
protected function setHeight($height)
{
$this->height = $height;
}
protected function setWidth($width)
{
$this->width = $width;
}
protected function getHeight()
{
return $this->height;
}
protected function getWidth()
{
return $this->width;
}
public function area()
{
return $this->getHeight() * $this->getWidth();
}
public function perimeter()
{
return $this->getHeight() * 2 + $this->getWidth() * 2;
}
}
$rectangle = new Rectangle(10, 10);
echo $rectangle->area();
echo $rectangle->getHeight();
echo $rectangle->getWidth();
示例9: isInner
/**
* Определяет, вложен ли текущий прямоугольник в заданный.
*
* @param Rectangle $rect
* @return type
*/
public function isInner(Rectangle $rect)
{
return $this->getTop() >= 0 && $this->getLeft() >= 0 && $this->getBottom() <= $rect->getHeight() && $this->getRight() <= $rect->getWidth();
}
示例10: getenv
<?php
require_once getenv("DOCUMENT_ROOT") . "/lib/config.php";
require_once "Shape.php";
require_once "Arc.php";
require_once "Rectangle.php";
$arc = new Arc(10);
echo $arc->calcS() . "<br/>";
echo $arc->calcP() . "<br/>";
$rect = new Rectangle(8, 6);
echo $rect->calcS() . "<br/>";
echo $rect->calcP() . "<br/>";
示例11: __autoload
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Trait</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<?php
# Script 6.7 - trait.php
// This page uses the tDebug trait through the Rectangle object.
// Include the trait definition:
// require('tDebug.php');
// Include the class definition:
// require('Rectangle.php');
function __autoload($class)
{
require $class . '.php';
}
// Create a new object:
$r = new Rectangle(42, 37);
// Dump the information:
$r->dumpObject();
// Delete the object:
unset($r);
?>
</body>
</html>
示例12: Rectangle
<?php
require_once 'classes/rectangle.php';
$r1 = new Rectangle();
$r1->set_width(5);
$r1->set_height(4);
echo 'R1<br>Area: ' . $r1->get_area() . '<br>Perimeter: ' . $r1->get_perimeter();
$r2 = new Rectangle(8, 6);
echo '<br>R1<br>Area: ' . $r2->get_area() . '<br>Perimeter: ' . $r2->get_perimeter();
示例13: quantumLayoutParams
function quantumLayoutParams(&$sizes, &$box, &$growWide)
{
global $debug;
global $offset_y;
if ($debug) {
echo '<ul>';
echo '<li>';
$offset_y += 100;
}
$boxes = array();
$pivotIndex = $this->computePivotIndex($sizes);
$pivotSize = $sizes[$pivotIndex];
$boxAR = $box->aspectRatio();
//echo "pivotIndex=$pivotIndex";
//echo '<br/>';
if (count($sizes) == 1) {
$boxes[] = $box;
if ($debug) {
echo "Stop 1: box = \n";
$box->Dump();
echo '<br/>';
}
}
if (count($sizes) == 2) {
$ratio = $sizes[0] / ($sizes[0] + $sizes[1]);
if ($growWide) {
$dim1 = $this->computeTableLayout($sizes[0], $boxAR * $ratio);
$dim2 = $this->computeTableLayout($sizes[1], $boxAR * $ratio);
$h = max($dim1[1], $dim2[1]);
//echo "h=$h<br/>";
$dim2 = $this->computeTableLayoutGivenHeight($sizes[1], $h);
$boxes[0] = new Rectangle($box->x, $box->y, $dim1[0], $h);
$boxes[1] = new Rectangle($box->x + $dim1[0], $box->y, $dim2[0], $dim2[1]);
} else {
$dim1 = $this->computeTableLayout($sizes[0], $boxAR / $ratio);
$dim2 = $this->computeTableLayout($sizes[1], $boxAR / (1 - $ratio));
$w = max($dim1[0], $dim2[0]);
//echo "w=$w<br/>";
$dim2 = $this->computeTableLayoutGivenWidth($sizes[1], $w);
$boxes[0] = new Rectangle($box->x, $box->y, $w, $dim1[1]);
$boxes[1] = new Rectangle($box->x, $box->y + $dim1[1], $dim2[0], $dim2[1]);
}
if ($debug) {
echo "Stop 2: box[0] = ";
$boxes[0]->Dump();
echo '<br />';
echo " Stop 2: box[1] = ";
$boxes[1]->Dump();
echo '<br/>';
echo 'Return ' . __LINE__ . '';
echo '<br/>';
}
return $boxes;
}
// More than 2
$box2 = NULL;
$r1 = NULL;
$l1 = array();
$l2 = array();
$l3 = array();
// First compute R1
if ($pivotIndex > 0) {
$l1 = array_slice($sizes, 0, $pivotIndex);
$l1Size = $this->computeSize($l1);
$b2Size = $this->computeSizeBetween($sizes, $pivotIndex, count($sizes) - 1);
if ($growWide) {
$dim1 = $this->computeTableLayoutGivenHeight($l1Size, $box->h);
$dim2 = $this->computeTableLayoutGivenHeight($b2Size, $box->h);
$r1 = new Rectangle($box->x, $box->y, $dim1[0], $dim1[1]);
$box2 = new Rectangle($box->x + $dim1[0], $box->y, $dim2[0], $dim2[1]);
} else {
$dim1 = $this->computeTableLayoutGivenWidth($l1Size, $box->w);
$dim2 = $this->computeTableLayoutGivenWidth($b2Size, $box->w);
$r1 = new Rectangle($box->x, $box->y, $dim1[0], $dim1[1]);
$box2 = new Rectangle($box->x, $box->y + $dim1[1], $dim2[0], $dim2[1]);
}
} else {
$box2 = new Rectangle($box->x, $box->y, $box->w, $box->h);
}
// Recurse on R1 to compute better box2
if ($debug) {
echo "<b>Recurse on R1 to get better box2</b><br />";
}
if (count($l1) != 0) {
if (count($l1) > 1) {
$r1AR = $r1->aspectRatio();
if ($r1AR == 1) {
$newGrowWidth = $growWide;
} else {
$newGrowWidth = $r1AR >= 1 ? true : false;
}
$l1boxes = $this->quantumLayoutParams($l1, $r1, $newGrowWide);
} else {
$l1boxes[0] = $r1;
}
$l1FinalBox = $this->computeUnion($l1boxes);
if ($growWide) {
$box2->h = $r1->h;
} else {
$box2->w = $r1->w;
//.........这里部分代码省略.........
示例14: isSquare
public $length;
public $width;
function isSquare()
{
if ($this->length == $this->width) {
return true;
} else {
return false;
}
}
function getArea()
{
return $this->length * $this->width;
}
}
$my_rectangle = new Rectangle();
$my_rectangle->length = $_GET["length"];
$my_rectangle->width = $_GET["width"];
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<title>Make a Rectangle</title>
</head>
<body>
<div class="container">
<?php
if ($my_rectangle->isSquare()) {
echo "<h1>Congratulations! You made a square!</h1>";
} else {
示例15: draw
}
class Rectangle extends AbstractShape
{
public function draw()
{
print "Inside Rectangle::draw method.\n";
// 'print' works too
}
}
$we = new Employee('Bob', 'Diamond');
echo $we->greeting();
echo PHP_EOL;
$we->foo();
// overriding seems to work
$he->foo();
$rect = new Rectangle();
// or 'new Rectangle()'
$rect->draw();
echo empty("");
echo PHP_EOL;
echo null == NULL;
echo PHP_EOL;
// PHP Arrays are in fact associative arrays, i.e. Map and Dictionaries
$myArray = ["1" => "Hello", "2" => "How are you?", "3" => "Very well ty"];
$yourArray = [];
echo $myArray["1"] . PHP_EOL;
echo $myArray["2"] . PHP_EOL;
echo $myArray["3"] . PHP_EOL;
$myArray["4"] = "This is a new item";
echo $myArray["4"] . PHP_EOL;
echo $myArray["4"] . PHP_EOL;