• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Rectangle类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Rectangle的典型用法代码示例。如果您正苦于以下问题:PHP Rectangle类的具体用法?PHP Rectangle怎么用?PHP Rectangle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Rectangle类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: testGetArea

 function testGetArea()
 {
     // Need a Rectangle:
     $r = new Rectangle(8, 9);
     // The assertion tests the math:
     $this->assertEquals(72, $r->getArea());
 }
开发者ID:gmgj,项目名称:gjsoap,代码行数:7,代码来源:RectangleTest.php


示例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());
 }
开发者ID:CodeLouisville,项目名称:php-exercise-oop,代码行数:8,代码来源:RectangleTest.php


示例3: areaVerifier

 function areaVerifier(Rectangle $r)
 {
     $r->setWidth(5);
     $r->setHeight(4);
     if ($r->area() != 20) {
         return false;
     }
     return true;
 }
开发者ID:erikfig,项目名称:curso-php-moderno-turma-2,代码行数:9,代码来源:Client.php


示例4: 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.");
}
开发者ID:BenSotty,项目名称:drawer,代码行数:11,代码来源:services_m.php


示例5: 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;
 }
开发者ID:possientis,项目名称:Prog,代码行数:12,代码来源:prototype.php


示例6: 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;
开发者ID:anthony87burns,项目名称:codeup-web-exercises,代码行数:13,代码来源:shapes_test.php


示例7: 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();
开发者ID:Reni789,项目名称:Exercises,代码行数:31,代码来源:rectangle.php


示例8: 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;
开发者ID:pascalallen,项目名称:Codeup_Exercises,代码行数:9,代码来源:shapes_test.php


示例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();
 }
开发者ID:roman-turchenko,项目名称:morm,代码行数:10,代码来源:Rectangle.php


示例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/>";
开发者ID:echmaster,项目名称:data,代码行数:12,代码来源:dz.php


示例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>
开发者ID:raynaldmo,项目名称:php-education,代码行数:28,代码来源:trait.php


示例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();
开发者ID:HogiQuin,项目名称:oop01,代码行数:9,代码来源:prueba.php


示例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;
//.........这里部分代码省略.........
开发者ID:rdmpage,项目名称:afd,代码行数:101,代码来源:qt.php


示例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 {
开发者ID:jeff1236,项目名称:first_commit,代码行数:31,代码来源:rectangle.php


示例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;
开发者ID:possientis,项目名称:Prog,代码行数:31,代码来源:wiki.php


示例16: Rectangle

<?php

require_once "rectangle.php";
require_once "square.php";
$rect1 = new Rectangle(9, 8);
echo "The area of rectangle 1 is: " . $rect1->getArea() . PHP_EOL;
$rect2 = new Rectangle(4, 5);
echo "The area of rectangle 2 is: " . $rect2->getArea() . PHP_EOL;
$square1 = new Square(5);
echo "The perim of square 1 is: " . $square1->getPerimeter() . PHP_EOL;
$square2 = new Square(4);
echo "The perim of square 2 is: " . $square2->getPerimeter() . PHP_EOL;
开发者ID:ZeshanNSegal,项目名称:Codeup-Web-Exercises,代码行数:12,代码来源:shapes_test.php


示例17: getX4

    public function getX4()
    {
        return $this->x4;
    }
    public function setY4($y4)
    {
        settype($y4, "integer");
        $this->y4 = $y4;
    }
    public function getY4()
    {
        return $this->y4;
    }
    public function display()
    {
        parent::display();
        // TODO: Change the autogenerated stub
        echo "x4=" . $this->x4 . "</br>";
        echo "y4=" . $this->y4 . "</br>";
    }
}
$rect = new Rectangle();
$rect->setX1(0);
$rect->setY1(0);
$rect->setX2(0);
$rect->setY2(5);
$rect->setX3(5);
$rect->setY3(5);
$rect->setX4(5);
$rect->setY4(0);
$rect->display();
开发者ID:MikhailUA,项目名称:PHP_Spalah_HomeWork,代码行数:31,代码来源:L14_HW.php


示例18: cropSquare

 /**
  * Вырезает произвольный квадрат из изображения.
  * Метод может принимать вырезаемый прямоугольник, обязанный быть квадратом,
  * либо параметры для создания такого прямоугольника.
  *
  * @throws IllegalArgumentException
  * @return AcImage
  */
 public function cropSquare()
 {
     $a = func_get_args();
     if (count($a) == 1 && $a[0] instanceof Rectangle && $a[0]->isSquare()) {
         $square = $a[0];
     } else {
         if (count($a) == 2 && $a[0] instanceof Point && is_int($a[1])) {
             $square = new Rectangle($a[0], new Size($a[1], $a[1]));
         } else {
             if (count($a) == 3) {
                 $square = new Rectangle(new Point($a[0], $a[1]), new Size($a[2], $a[2]));
             } else {
                 throw new IllegalArgumentException();
             }
         }
     }
     if (!$square->isInner(new Rectangle(new Point(0, 0), $this->getSize()))) {
         throw new IllegalArgumentException();
     }
     return $this->crop($square);
 }
开发者ID:vasinsky,项目名称:test,代码行数:29,代码来源:AcImage.class.php


示例19: __construct

{
    private $radius;
    public function __construct($x, $y, $radius)
    {
        parent::__construct($x, $y);
        $this->radius = $radius;
    }
    protected function drawShape()
    {
        return "Рисуем окружность с радиусом {$this->radius}";
    }
}
class Rectangle extends Shape
{
    private $width;
    private $height;
    public function __construct($x, $y, $width, $height)
    {
        parent::__construct($x, $y);
        $this->width = $width;
        $this->height = $height;
    }
    protected function drawShape()
    {
        return "Рисуем прямоугольник с шириной {$this->width} и высотой {$this->height}";
    }
}
$circle = new Circle(0, 0, 50);
$rectangle = new Rectangle(0, 0, 100, 50);
$circle->draw();
$rectangle->draw();
开发者ID:echmaster,项目名称:data,代码行数:31,代码来源:3-8+Абстрактные+классы.php


示例20: Rectangle

<?php

require_once 'square.php';
$rectangle = new Rectangle(20, 40);
echo 'The area of this rectangle is ' . $rectangle->area() . PHP_EOL;
$square = new Square(20);
echo 'The perimeter of this square is ' . $square->perimeter() . PHP_EOL;
开发者ID:Craig240z,项目名称:CodeUp-Web-Exercises,代码行数:7,代码来源:shapes_test.php



注:本文中的Rectangle类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP RecursiveArrayIterator类代码示例发布时间:2022-05-23
下一篇:
PHP RectPatternFactory类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap