本文整理汇总了PHP中Line类的典型用法代码示例。如果您正苦于以下问题:PHP Line类的具体用法?PHP Line怎么用?PHP Line使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Line类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isOverlap
/**
* Return true if the given line intersect/overlap
*
* @param Line $line
* @return bool
*/
public function isOverlap(Line $line)
{
$nvA = $this->getNormalVector();
$nvB = $line->getNormalVector();
// line equation 1
$a1 = $nvA->getX();
$b1 = $nvA->getY();
$c1 = $nvA->getX() * $this->a->getX() + $nvA->getY() * $this->a->getY();
// line equation 2
$a2 = $nvB->getX();
$b2 = $nvB->getY();
$c2 = $nvB->getX() * $line->a->getX() + $nvB->getY() * $line->a->getY();
// Calculation cheat: http://www.thelearningpoint.net/computer-science/c-program-solving-simultaneous-equations-in-two-variables
if ($a1 * $b2 - $a2 * $b1 != 0 && $b1 * $a2 - $b2 * $a1 != 0) {
// we have a unique solution
$x = ($c1 * $b2 - $c2 * $b1) / ($a1 * $b2 - $a2 * $b1);
$y = ($c1 * $a2 - $c2 * $a1) / ($b1 * $a2 - $b2 * $a1);
// they intersect so let's check if that intersection point is on the line section
return $this->hasPoint(new Point($x, $y));
} elseif ($a1 * $b2 - $a2 * $b1 == 0 && $b1 * $a2 - $b2 * $a1 == 0 && $c1 * $b2 - $c2 * $b1 == 0 && $c1 * $a2 - $c2 * $a1 == 0) {
// infinite solutions
return true;
}
// no solution: the lines don't intersect each other
return false;
}
示例2: testFormat_returnsString_ifFormatIsText
/**
* format() should return string if format is html
*/
public function testFormat_returnsString_ifFormatIsText()
{
$word = new Line();
$expected = "\n";
$actual = $word->format('text');
$this->assertEquals($expected, $actual);
return;
}
示例3: validateLine
protected function validateLine($line)
{
if (!$line instanceof Line) {
$line = new Line((string) $line);
}
if ($line->getLength() != $this->getWidth()) {
throw new \InvalidArgumentException(sprintf('All lines in a batch file must be %d chars wide this line is %d chars wide.', $this->getWidth(), strlen($line)));
}
return $line;
}
示例4: testDefine
/**
* @dataProvider dataProviderTestDefine
*/
public function testDefine($string, $isDefine, $getDefineKey, $getDefineWord)
{
$line = new Line($string);
$this->assertSame($isDefine, $line->isDefine());
$this->assertSame($getDefineKey, $line->getDefineKey());
if (is_null($getDefineWord)) {
$this->assertNull($line->getDefineWord());
} else {
$word = $line->getDefineWord();
$this->assertInstanceOf('\\Inml\\Text\\Word', $word);
$this->assertSame($getDefineWord, $word->getWord());
}
}
示例5: addToCart
function addToCart($itemId, $itemName, $qtty, $price, $itemCode, $remarks)
{
$cart = $_SESSION['cart'];
$line = new Line();
if (!isset($cart)) {
$line->addNewLine(1, $itemId, $itemName, $qtty, $price, $itemCode, $remarks);
$_SESSION['cart'][1] = $line;
return;
}
$pos = count($_SESSION['cart']) + 1;
$line->addNewLine($pos, $itemId, $itemName, $qtty, $price, $itemCode, $remarks);
$_SESSION['cart'][$pos] = $line;
return;
}
示例6: show
/**
* Show the prompt to user and return the answer.
*
* @return mixed
*/
public function show()
{
/**
* Ask for a number and validate it.
*/
do {
$valid = true;
$number = parent::show();
if ($number === "" && !$this->allowEmpty) {
$valid = false;
} elseif ($number === "") {
$number = null;
} elseif (!is_numeric($number)) {
$this->getConsole()->writeLine("{$number} is not a number\n");
$valid = false;
} elseif (!$this->allowFloat && round($number) != $number) {
$this->getConsole()->writeLine("Please enter a non-floating number, i.e. " . round($number) . "\n");
$valid = false;
} elseif ($this->max !== null && $number > $this->max) {
$this->getConsole()->writeLine("Please enter a number not greater than " . $this->max . "\n");
$valid = false;
} elseif ($this->min !== null && $number < $this->min) {
$this->getConsole()->writeLine("Please enter a number not smaller than " . $this->min . "\n");
$valid = false;
}
} while (!$valid);
/**
* Cast proper type
*/
if ($number !== null) {
$number = $this->allowFloat ? (double) $number : (int) $number;
}
return $this->lastResponse = $number;
}
示例7: drawGraph
static function drawGraph($obj=NULL,$parent=NULL)
{
$link = $GLOBALS['GRAPHITE_URL'].'/render/?';
$lines = Line::findAll($obj->getGraphId());
foreach($lines as $line) {
$link .= 'target=';
$target = 'alias(' . $line->getTarget() . '%2C%22' . $line->getAlias() . '%22)';
if ($line->getColor() != '') {
$target = 'color(' . $target . '%2C%22' . $line->getColor() . '%22)';
}
$link .= $target .'&';
}
if (!is_null($parent)) {
$link .= 'width=' . $parent->getGraphWidth() .'&';
$link .= 'height=' . $parent->getGraphHeight() .'&';
if ($obj->getVtitle() != '') {
$link .= 'vtitle=' . $obj->getVtitle() .'&';
}
if ($obj->getName() != '') {
$link .= 'title=' . $obj->getName() .'&';
}
if ($obj->getArea() != 'none') {
$link .= 'areaMode=' . $obj->getArea() .'&';
}
if ($obj->getTime_Value() != '' && $obj->getUnit() != '') {
$link .= 'from=-' . $obj->getTime_Value() . $obj->getUnit() . '&';
}
if ($obj->getCustom_Opts() != '') {
$link .= $obj->getCustom_Opts() . '&';
}
}
return $link;
}
示例8: addBuffer
/**
* @param LineBuffer $buffer
* @param int $indent
* @param string $firstPrefix
*/
public function addBuffer(LineBuffer $buffer, $indent = 0, $firstPrefix = '')
{
$first = true;
foreach ($buffer->getLines() as $line) {
$newline = null;
if ($first) {
$first = false;
$newline = new Line($line->hasMatched(), $firstPrefix . $line->getText(), $line->getMarker());
$newline->setExtraIndent(max(0, $indent - strlen($firstPrefix)));
} else {
$newline = $line;
$newline->setExtraIndent($indent);
}
$this->lines[] = $newline;
}
}
示例9: merge
/**
* @inheritDoc
*/
public function merge($base, $remote, $local)
{
// Skip merging if there is nothing to do.
if ($merged = PhpMergeBase::simpleMerge($base, $remote, $local)) {
return $merged;
}
// First try the built in xdiff_string_merge3.
$merged = xdiff_string_merge3($base, $remote, $local, $error);
// if ($error) {
// // Try it the other way around.
// $error = null;
// $merged = xdiff_string_merge3($base, $local, $remote, $error);
// }
if ($error) {
// So there might be a merge conflict.
$baseLines = $this->base = Line::createArray(array_map(function ($l) {
return [$l, 0];
}, explode("\n", $base)));
// Get patch strings and transform them to Hunks.
$remotePatch = xdiff_string_diff($base, $remote, 0);
$localPatch = xdiff_string_diff($base, $local, 0);
// Note that patching $remote with $localPatch will work only in
// some cases because xdiff patches differently than git and will
// apply the same change twice.
$remote_hunks = self::interpretDiff($remotePatch);
$local_hunks = self::interpretDiff($localPatch);
// Merge Hunks and detect conflicts the same way PhpMerge does.
$conflicts = [];
$merged = PhpMerge::mergeHunks($baseLines, $remote_hunks, $local_hunks, $conflicts);
if ($conflicts) {
throw new MergeException('A merge conflict has occured.', $conflicts, $merged);
}
}
return $merged;
}
示例10: tokenize
/**
* Tokenize a line
*
* @param net.daringfireball.markdown.Line $l The line
* @param net.daringfireball.markdown.Node $target The target node to add nodes to
* @return net.daringfireball.markdown.Node The target
*/
public function tokenize(Line $line, Node $target)
{
$safe = 0;
$l = $line->length();
while ($line->pos() < $l) {
$t = '';
$c = $line->chr();
if ('\\' === $c) {
$t = $line[$line->pos() + 1];
$line->forward(2);
// Skip escape, don't tokenize next character
} else {
if (isset($this->tokens[$c])) {
if (!$this->tokens[$c]($line, $target, $this)) {
$t = $c;
// Push back
$line->forward();
}
}
}
// Optimization: Do not create empty text nodes
if ('' !== ($t .= $line->until($this->span))) {
$target->add(new Text($t));
}
if ($safe++ > $l) {
throw new \lang\IllegalStateException('Endless loop detected');
}
}
return $target;
}
示例11: CheckIsAllWordsRepeateableAtLines
/**
* checks is word repeatable at different lines
* @param Line $line - each line object
* @return boolean
*/
private function CheckIsAllWordsRepeateableAtLines(Line $line)
{
$temp_words = array();
foreach ($this->repeatableWordsInfo as $key => $value) {
$temp_words[] = $key;
}
$flag = 0;
$amount = count($temp_words);
foreach ($line->GetRepeatableWords() as $word) {
foreach ($temp_words as $item) {
if ($item == $word->GetContent()) {
$flag++;
}
}
}
if ($flag != $amount) {
return false;
} else {
return true;
}
}
示例12: __construct
/**
* Constructor
*
* @param string $string String to parse
*/
public function __construct($string)
{
$this->rawString = $string;
$parts = explode(Line::SEPARATOR, $string);
foreach ($parts as $item) {
$line = new Line($item);
if ($line->isStyle()) {
$this->styles = array_merge($this->styles, $line->getStyles());
} elseif ($line->isDefine()) {
$this->defines[$line->getDefineKey()] = $line->getDefineWord();
} elseif (!$line->isEmpty()) {
$this->lines[] = $line;
}
}
}
示例13: cloneLine
public static function cloneLine($line_id, $ignore_clone_name = FALSE, $graph_id = NULL)
{
$line_to_clone = new Line($line_id);
if (empty($graph_id)) {
$graph_id = $line_to_clone->getGraphId();
}
$line = new Line();
if ($ignore_clone_name) {
$clone_alias = $line_to_clone->getAlias();
} else {
$clone_alias = 'Clone of ' . $line_to_clone->getAlias();
// If it's too long, we truncate
if (strlen($clone_alias) > 255) {
$clone_alias = substr($clone_alias, 0, 255);
}
}
$line->setAlias($clone_alias);
$line->setTarget($line_to_clone->getTarget());
$line->setColor($line_to_clone->getColor());
$line->setGraphId($graph_id);
$line->setWeight($line_to_clone->getWeight());
$line->store();
}
示例14: setName
/**
* Set the tag name.
*
* This will also be persisted to the upsteam line and annotation.
*
* @param string $name
*/
public function setName($name)
{
$current = $this->getName();
if ('other' === $current) {
throw new \RuntimeException('Cannot set name on unknown tag');
}
$this->line->setContent(preg_replace("/@{$current}/", "@{$name}", $this->line->getContent(), 1));
$this->name = $name;
}
示例15: apply
public function apply($resource)
{
// Extract arguments
@(list(, $direction, $step, $thickness, $color) = func_get_args());
$step = (int) $step;
$thickness = (int) $thickness;
if ($step < 2) {
$step = 2;
}
// Get resolution
$width = imagesx($resource);
$height = imagesy($resource);
if ($width === false || $height === false) {
throw new Exception("An error was encountered while getting image resolution");
}
// Apply effect
switch ($direction) {
case self::VERTICAL:
$x = 0;
while (($x += $step) < $width) {
parent::apply($resource, $x, 0, $x, $height, $thickness, $color);
}
break;
case self::HORIZONTAL:
default:
$y = 0;
while (($y += $step) < $height) {
parent::apply($resource, 0, $y, $width, $y, $thickness, $color);
}
}
return $resource;
}