Difference between revisions of "VectorA:round"

From ComputerCraft Wiki
Jump to: navigation, search
 
Line 1: Line 1:
Returns a vector with all components rounded to the nearest integer
+
{{lowercase}}
 
+
{{Function
Code representation:
+
|name=vector:round
local a = vector.new(10.2, 1.5, 3.4999)
+
|returns=[[vector (API)|vector]]
+
|api=vector
local c = vector.new(
+
|addon=ComputerCraft
  math.floor(a.x + 0.5),
+
|desc=Rounds the vector coordinates to the nearest integers and returns the result as a new vector.
  math.floor(a.y + 0.5),
+
|examples=
  math.floor(a.z + 0.5))
+
{{Example
--c.x = 10, c.y = 2, c.z = 3
+
|desc=Rounds a vector and prints the resulting coordinates.
 
+
|code=local a = vector.new(1.4999, 1.5, 3.14)
Code example:
+
local a = vector.new(1.4999, 1.5, 3.14)
+
 
   
 
   
 
  local c = a:round()
 
  local c = a:round()
Line 21: Line 19:
 
  --2
 
  --2
 
  --3
 
  --3
 +
}}
 +
{{Example
 +
|desc=Code to recreate the function. Gives insight into what the function does.
 +
|code=local a = vector.new(10.2, 1.5, 3.4999)
 +
 +
local c = vector.new(
 +
  math.floor(a.x + 0.5),
 +
  math.floor(a.y + 0.5),
 +
  math.floor(a.z + 0.5))
 +
--c.x = 10, c.y = 2, c.z = 3
 +
}}
 +
}}
 +
 +
[[Category:API_Functions]]

Latest revision as of 14:31, 23 February 2013


Grid Redstone.png  Function vector:round
Rounds the vector coordinates to the nearest integers and returns the result as a new vector.
Syntax vector:round()
Returns vector
Part of ComputerCraft
API vector

Examples

Grid paper.png  Example
Rounds a vector and prints the resulting coordinates.
Code
local a = vector.new(1.4999, 1.5, 3.14)

local c = a:round()

print(c.x)
print(c.y)
print(c.z)
--1
--2
--3



Grid paper.png  Example
Code to recreate the function. Gives insight into what the function does.
Code
local a = vector.new(10.2, 1.5, 3.4999)

local c = vector.new(
 math.floor(a.x + 0.5),
 math.floor(a.y + 0.5),
 math.floor(a.z + 0.5))
--c.x = 10, c.y = 2, c.z = 3