# VectorExtensions

Kind: Class · Namespace: Sansar · Assembly: Sansar.Script.dll · Script API 47.10.0

<div class="api-meta">
<span class="api-kind api-kind-class" data-pagefind-filter="kind:Class">Class</span>
<span data-pagefind-filter="namespace:Sansar">Namespace <a href="/scripting/api/sansar"><code>Sansar</code></a></span>
</div>

<span id="T:Sansar.VectorExtensions"></span>

Additional methods for Mono.Simd.Vector4f.

```csharp
public static class VectorExtensions
```

## Members at a glance

| Kind | Members |
|---|---|
| **Methods** | [Cos](#cos) · [CosSlow](#cosslow) · [SelectWithMask](#selectwithmask) · [Sin](#sin) · [SinSlow](#sinslow) · [SinZeroPiOverTwo](#sinzeropiovertwo) |

## Methods

### Cos

<div class="api-card">
<span id="M:Sansar.VectorExtensions.Cos(Mono.Simd.Vector4f)"></span>

```csharp signature
public static Mono.Simd.Vector4f Cos(this Mono.Simd.Vector4f x)
```

Returns the approximate cosine of the four floats in the vector.

| Parameter | Type | Description |
|---|---|---|
| `x` | Mono.Simd.Vector4f | A vector of 4 floats. |

**Returns:** Mono.Simd.Vector4f — The approximate cosine of each element.

<details class="api-remarks"><summary>Remarks</summary>

Uses [`VectorExtensions.Sin`](/scripting/api/sansar/vectorextensions#sin)

</details>

</div>

### CosSlow

<div class="api-card">
<span id="M:Sansar.VectorExtensions.CosSlow(Mono.Simd.Vector4f)"></span>

```csharp signature
public static Mono.Simd.Vector4f CosSlow(this Mono.Simd.Vector4f v1)
```

Returns the cosine each element of the vector.

| Parameter | Type | Description |
|---|---|---|
| `v1` | Mono.Simd.Vector4f | A vector of 4 floats. |

**Returns:** Mono.Simd.Vector4f — The cosine of each element.

<details class="api-remarks"><summary>Remarks</summary>

Uses [`Math.Cos`](https://learn.microsoft.com/dotnet/api/system.math.cos). The results are more accurate than [`VectorExtensions.Cos`](/scripting/api/sansar/vectorextensions#cos) but take approximately 3x the time to calculate.

</details>

</div>

### SelectWithMask

<div class="api-card">
<span id="M:Sansar.VectorExtensions.SelectWithMask(Mono.Simd.Vector4i,Mono.Simd.Vector4f,Mono.Simd.Vector4f)"></span>

```csharp signature
public static Mono.Simd.Vector4f SelectWithMask(
    this Mono.Simd.Vector4i mask,
    Mono.Simd.Vector4f sourceIfTrue,
    Mono.Simd.Vector4f sourceIfFalse
)
```

Creates a new vector4f from the given vectors, selecting a component from sourceIfTrue if the corresponding component in the mask is -1 and from sourceIfFalse if 0.

| Parameter | Type | Description |
|---|---|---|
| `mask` | Mono.Simd.Vector4i | The mask vector. |
| `sourceIfTrue` | Mono.Simd.Vector4f | The vector containing the elements that are selected if the mask is true. |
| `sourceIfFalse` | Mono.Simd.Vector4f | The vector containing the elements that are selected if the maks is false. |

**Returns:** Mono.Simd.Vector4f — A new vector with elements selected from the source vectors based on the mask.

<details class="api-remarks"><summary>Remarks</summary>

Each element in the mask must be 0 or -1 or the results are undefined. Courtesy of Mark++, http\://markplusplus.wordpress.com/2007/03/14/fast-sse-select-operation/

</details>

<details class="api-example" open><summary>Example</summary>

```csharp
Vector4f left = new Vector4f(1, 2, 3, 4);
Vector4f right = new Vector4f(5, 6, 7, 8);

// Select X and Z from right and Y and W from left
Vector4i mask = new Vector4i(0, -1, 0, -1);
var result = mask.SelectWithMask(left, right);
Assertions.AlmostEqual((Vector)new Vector4f(5, 2, 7, 4), result);
```

</details>

</div>

### Sin

<div class="api-card">
<span id="M:Sansar.VectorExtensions.Sin(Mono.Simd.Vector4f)"></span>

```csharp signature
public static Mono.Simd.Vector4f Sin(this Mono.Simd.Vector4f a)
```

Returns the approximate sine of the four floats in the vector.

| Parameter | Type | Description |
|---|---|---|
| `a` | Mono.Simd.Vector4f | A vector of 4 floats |

**Returns:** Mono.Simd.Vector4f — A fast approximation of the sine of each of the 4 floats.

<details class="api-remarks"><summary>Remarks</summary>

Uses [`VectorExtensions.SinZeroPiOverTwo`](/scripting/api/sansar/vectorextensions#sinzeropiovertwo)

</details>

</div>

### SinSlow

<div class="api-card">
<span id="M:Sansar.VectorExtensions.SinSlow(Mono.Simd.Vector4f)"></span>

```csharp signature
public static Mono.Simd.Vector4f SinSlow(this Mono.Simd.Vector4f v1)
```

Returns the sine each element of the vector.

| Parameter | Type | Description |
|---|---|---|
| `v1` | Mono.Simd.Vector4f | A vector of 4 floats. |

**Returns:** Mono.Simd.Vector4f — The sine of each element.

<details class="api-remarks"><summary>Remarks</summary>

Uses [`Math.Sin`](https://learn.microsoft.com/dotnet/api/system.math.sin). The results are more accurate than [`VectorExtensions.Sin`](/scripting/api/sansar/vectorextensions#sin) but take approximately 3x the time to calculate.

</details>

</div>

### SinZeroPiOverTwo

<div class="api-card">
<span id="M:Sansar.VectorExtensions.SinZeroPiOverTwo(Mono.Simd.Vector4f)"></span>

```csharp signature
public static Mono.Simd.Vector4f SinZeroPiOverTwo(
    this Mono.Simd.Vector4f x
)
```

Returns the approximate sine of each element in the vector.

| Parameter | Type | Description |
|---|---|---|
| `x` | Mono.Simd.Vector4f | A vector of 4 floats. |

**Returns:** Mono.Simd.Vector4f — The approximate sine of each element.

<details class="api-remarks"><summary>Remarks</summary>

Results only valid if each element is in \[0 and Pi/2\]. For unconstrained input use [`VectorExtensions.Sin`](/scripting/api/sansar/vectorextensions#sin). Calculated using the Maclaurin series as sin(x) = x - (x^3)/3! + (x^5)/5! - (x^7)/7! + (x^9)/9!

</details>

</div>




<p class="api-generated" data-pagefind-ignore>Generated from the Sansar 47.10.0 client ScriptApi snapshot.</p>