# Class: scalararray

Scalarrays are created as plain C arrays within luxinia. They can be used for operations that require lot's of calculations or are used by other native C functions. They can be 1D,2D or 3D similar to textures and contain 1-4 component vectors.
Normally the arrays have a memorychunk and you can set the 'region' of operation within this chunk via offset, size and stride.
'Mounted' arrays, however do not have their own allocated data, but directly operate on their host data. Be aware that there is no mechanism to check whether internal host is still valid, you will need to do this yourself.

## Hierarchy

    o-+ mathlib
      o-+ scalararray

## Methods:

### Method overview:

- convert
- convertranged
- count
- curvelinear
- curvespline
- datapointer
- datasize
- datastart
- fnormalize
- fnormalizeacc
- fromstring
- ftransform
- ftransformfull
- ftransformrot
- mounted
- mountscalararray
- mountstaticarray
- new
- newfrompointer
- offset
- op0
- op0region
- op1
- op1region
- op2
- op2region
- op3
- op3region
- sample
- scalartype
- size
- vector
- vectorall
- vectorat
- vectorsize
- vectorstride

new (scalartype, int count, [vectorsize])
  returns: ([scalararray])
  returns a new compact scalar array. vectorsize defaults to 1 and stride equals vectorsize.
convert (scalararray to, scalararray from)
  returns: (scalararray to)
  Straight converts current vector count from one scalararray (different types allowed) to another
convertranged (scalararray to, value tomin, tomax, scalararray from, value frommin, frommax)
  returns: (scalararray to)
  Straight converts current vector count from one scalararray (different types allowed) to another. And ranges input and output values accordingly. values are int/float.
count (scalararray)
  returns: (int)
  returns maximum number of current affected vectors (takes size and offset into account)
curvelinear (scalararray out, scalararray keys, [boolean closed])
  returns: (scalararray)
  creates linear interpolated curve/line based from the key segment points. Closed is false by default. Make sure vectorsizes are equal and out array has higher count than key array.
curvespline (scalararray out, scalararray keys, [boolean closed])
  returns: (scalararray)
  creates catmull rom spline interpolated curve/line based from the key segment points. Closed is false by default. Make sure vectorsizes are equal and out array has higher count than key array.
datapointer (staticarray self)
  returns: (pointer start, end, sarray3dstruct)
  you can access the memory directly in other lua dlls. Be aware that you must make sure not to corrupt memory, make sure you are always smaller than the 'end' pointer.
datasize (scalararray, [int bytes])
  returns: ([int bytes]/[boolean lostonresize])
  gets or sets maximum number of bytes. If new count is greater old size, old content may be preserved (returns true if data is lost). Decreasing can result into error if current size and stride settings are beyond new datasize. Offset and datashift will be reseted.
datastart (scalararray, [int bytes])
  returns: ([int bytes])
  gets or sets startpoint in bytes. The startpoint is the base from which offsets are applied. Useful for accessing individual components. Will keep size and reapply offset from new startpoint.
fnormalize (scalararray outfloats, scalararray floats)
  returns: (scalararray)
  normalizes the vectors to unit-length. Fast version less accurate, output length may not exactly be 1. Input and output array can be same.
fnormalizeacc (scalararray outfloats, scalararray floats)
  returns: (scalararray)
  normalizes the vectors to unit-length. Accurate version. Input and output array can be same.
fromstring (scalararray, binstring, [byteoffset])
  returns: ()
  copies the data from a binary string. Copies as much as possible, ignores dataoffset. Will throw error if stride does not match vectordim.
ftransform (scalararray outfloats, scalararray floats, matrix44)
  returns: (scalararray)
  transforms the vectors (size must 2,3 or 4) with given matrix. For Vector4 ignores W. Input and output array can be same.
ftransformfull (scalararray outfloats, scalararray floats, matrix44)
  returns: (scalararray)
  homogeneously transforms the vectors (size must 2,3 or 4) with given matrix. Vectorsize of 2 and 3 will be divided by w coordinate. Input and output array can be same.
ftransformrot (scalararray outfloats, scalararray floats, matrix44)
  returns: (scalararray)
  rotates the vectors (size must 2,3 or 4) with given matrix. Input and output array can be same.
mounted (scalararray)
  returns: (boolean)
  returns whether array is mounted, i.e. points to external memory. When mounted to internal data, its rather unsafe to change sizes or strides.
mountscalararray (scalararray)
  returns: (scalararray)
  returns a new mounted array on the current's content. Mounting a scalararray from another will make sure the data stays valid, as it prevents host's gc. The maximum size you can operate with, is taken at the moment the mount happens using active offset,stride and count. Resizing host via maxscalars will cause crashes!
mountstaticarray (scalararray)
  returns: (floatarray/intarray)
  returns a new mounted array on the current's content. Mounting a staticarray from another will make sure the data stays valid, as it prevents host's gc. The maximum size you can operate with, is taken at the moment the mount happens using active offset,stride and count. Resizing host via maxscalars will cause crashes!
newfrompointer (pointer start, [int count / pointer end], scalartype, [vectorsize], [vecotrstride])
  returns: ([scalararray])
  returns a new mounted scalar array. vectorsize defaults to 1 and stride equals vectorsize. You must make sure the pointer is and stays valid. If endpointer is given count is derived from the remaining attributes.!
offset (scalararray, [int w,h,d])
  returns: ([int w,h,d])
  gets or sets sets access pointer from current memchunk start. Must be within current size.
op0 (scalararray,scalarop)
  returns: (scalararray)
  performs a single operation. Returns self on success.
op0region (scalararray,scalarop, int w,h,d)
  returns: (scalararray)
  performs a single operation. Returns self on success.
op1 (scalararray out,scalarop,scalararray/values)
  returns: (scalararray)
  performs a single operation into out. Returns self on success.
op1region (scalararray out, int w,h,d, scalarop, scalararray/values)
  returns: (scalararray)
  performs a single operation into out. Returns self on success.
op2 (scalararray out,scalarop,scalararray,scalararray/values)
  returns: (scalararray)
  performs a dual operation into out. Returns self on success.
op2region (scalararray out,int w,h,d, scalarop, scalararray,scalararray/values)
  returns: (scalararray)
  performs a dual operation into out. Returns self on success.
op3 (scalararray out,scalarop,scalararray,scalararray,scalararray/values)
  returns: (scalararray)
  performs a triple operation int out. Returns self on success.
op3region (scalararray out,int w,h,d, scalarop, scalararray,scalararray,scalararray/values)
  returns: (scalararray)
  performs a triple operation int out. Returns self on success.
sample (scalararray,float x,y,z, [boolean unclamped])
  returns: ([float values...)
  samples data with given texcoord, always returns float interpolated data. Unclamped is true by default.
scalartype (scalararray, [scalartype])
  returns: ([scalartype])
  gets or sets current scalartype. Changing can influence size as types have different memcosts.
size (scalararray, [int w,h,d])
  returns: ([int w,h,d])
  gets or sets current total dimension of used elements. Will throw error if datasize isnt sufficient for current vectorsize and vectorstride. Setting will reset offset to 0,0,0.
vector (scalararray,index,[values...])
  returns: ([values...])
  assigns i-th vector the float/int value if given or simply returns the value at the index. Returns error in case of invalid indices (< 0 or > count).
vectorall (scalararray,[values...])
  returns: ()
  assigns all vectors the float/int values
vectorat (scalararray,x,y,z,[values...])
  returns: ([values...])
  assigns vector at the given position the float/int value if given or simply returns the value at the position. Returns error in case of invalid position address (< 0 or > size).
vectorsize (scalararray, [int])
  returns: ([int])
  gets or sets current vector dimension. Raising may cause vectorstride to change.
vectorstride (scalararray, [int])
  returns: ([int])
  gets or sets current vector stride. This must be zero or vectorsize as minimum, but can be greater for interleaved data. Using zero allows to create virtually any sizes from a single vector.

## Inherited Methods:

### From mathlib

quatslerpq, quatslerpqt