API > @blocksuite/blocks > Vec
Class: Vec ​
Constructors ​
constructor ​
new Vec():
Vec
Returns ​
Methods ​
abs ​
static
abs(A
):number
[]
Absolute value of a vector.
Parameters ​
Parameter | Type |
---|---|
A | number [] |
Returns ​
number
[]
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:352
add ​
static
add(A
,B
):number
[]
Add vectors.
Parameters ​
Parameter | Type |
---|---|
A | number [] |
B | number [] |
Returns ​
number
[]
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:42
addScalar ​
static
addScalar(A
,n
):number
[]
Add scalar to vector.
Parameters ​
Parameter | Type |
---|---|
A | number [] |
n | number |
Returns ​
number
[]
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:51
ang ​
static
ang(A
,B
):number
Angle between vector A and vector B in radians
Parameters ​
Parameter | Type |
---|---|
A | number [] |
B | number [] |
Returns ​
number
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:241
ang3 ​
static
ang3(p1
,pc
,p2
):number
Get the angle between the three vectors A, B, and C.
Parameters ​
Parameter | Type |
---|---|
p1 | number [] |
pc | number [] |
p2 | number [] |
Returns ​
number
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:340
angle ​
static
angle(A
,B
):number
Angle between vector A and vector B in radians
Parameters ​
Parameter | Type |
---|---|
A | number [] |
B | number [] |
Returns ​
number
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:250
clamp ​
static
clamp(n
,min
):number
Clamp a value into a range.
Parameters ​
Parameter | Type |
---|---|
n | number |
min | number |
Returns ​
number
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:12
static
clamp(n
,min
,max
):number
Parameters ​
Parameter | Type |
---|---|
n | number |
min | number |
max | number |
Returns ​
number
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:13
clampV ​
static
clampV(A
,min
):number
[]
Clamp a value into a range.
Parameters ​
Parameter | Type |
---|---|
A | number [] |
min | number |
Returns ​
number
[]
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:23
static
clampV(A
,min
,max
):number
[]
Parameters ​
Parameter | Type |
---|---|
A | number [] |
min | number |
max | number |
Returns ​
number
[]
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:24
clockwise ​
static
clockwise(p1
,pc
,p2
):boolean
Get whether p1 is left of p2, relative to pc.
Parameters ​
Parameter | Type |
---|---|
p1 | number [] |
pc | number [] |
p2 | number [] |
Returns ​
boolean
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:382
cpr ​
static
cpr(A
,B
):number
Cross product (outer product) | A X B |
Parameters ​
Parameter | Type |
---|---|
A | number [] |
B | number [] |
Returns ​
number
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:141
cross ​
static
cross(x
,y
,z
):number
Cross (for point in polygon)
Parameters ​
Parameter | Type |
---|---|
x | number [] |
y | number [] |
z | number [] |
Returns ​
number
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:149
dist ​
static
dist(A
,B
):number
Dist length from A to B
Parameters ​
Parameter | Type |
---|---|
A | number [] |
B | number [] |
Returns ​
number
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:218
dist2 ​
static
dist2(A
,B
):number
Dist length from A to B squared.
Parameters ​
Parameter | Type |
---|---|
A | number [] |
B | number [] |
Returns ​
number
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:209
distanceToBounds ​
static
distanceToBounds(bounds
,P
):number
Distance between a point and the nearest point on a bounding box.
Parameters ​
Parameter | Type | Description |
---|---|---|
bounds | object | The bounding box. |
bounds.maxX | number | - |
bounds.maxY | number | - |
bounds.minX | number | - |
bounds.minY | number | - |
P | number [] | The point |
Returns ​
number
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:508
distanceToLineSegment ​
static
distanceToLineSegment(A
,B
,P
,clamp
=true
):number
Distance between a point and the nearest point on a line segment between A and B
Parameters ​
Parameter | Type | Default value | Description |
---|---|---|---|
A | number [] | undefined | The start of the line segment |
B | number [] | undefined | The end of the line segment |
P | number [] | undefined | The off-line point |
clamp | boolean | true | Whether to clamp the point between A and B. |
Returns ​
number
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:472
distanceToLineThroughPoint ​
static
distanceToLineThroughPoint(A
,u
,P
):number
Distance between a point and a line with a known unit vector that passes through a point.
Parameters ​
Parameter | Type | Description |
---|---|---|
A | number [] | Any point on the line |
u | number [] | The unit vector for the line. |
P | number [] | A point not on the line to test. |
Returns ​
number
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:429
div ​
static
div(A
,n
):number
[]
Vector division by scalar.
Parameters ​
Parameter | Type |
---|---|
A | number [] |
n | number |
Returns ​
number
[]
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:106
divV ​
static
divV(A
,B
):number
[]
Vector division by vector.
Parameters ​
Parameter | Type |
---|---|
A | number [] |
B | number [] |
Returns ​
number
[]
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:115
dpr ​
static
dpr(A
,B
):number
Dot product
Parameters ​
Parameter | Type |
---|---|
A | number [] |
B | number [] |
Returns ​
number
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:132
fastDist ​
static
fastDist(A
,B
):number
[]
A faster, though less accurate method for testing distances. Maybe faster?
Parameters ​
Parameter | Type |
---|---|
A | number [] |
B | number [] |
Returns ​
number
[]
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:228
int ​
static
int(A
,B
,from
,to
,s
=1
):number
[]
Interpolate from A to B when curVAL goes fromVAL: number[] => to
Parameters ​
Parameter | Type | Default value | Description |
---|---|---|---|
A | number [] | undefined | - |
B | number [] | undefined | - |
from | number | undefined | Starting value |
to | number | undefined | Ending value |
s | number | 1 | Strength |
Returns ​
number
[]
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:323
isEqual ​
static
isEqual(A
,B
):boolean
Check of two vectors are identical.
Parameters ​
Parameter | Type |
---|---|
A | number [] |
B | number [] |
Returns ​
boolean
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:301
isLeft ​
static
isLeft(p1
,pc
,p2
):number
Get whether p1 is left of p2, relative to pc.
Parameters ​
Parameter | Type |
---|---|
p1 | number [] |
pc | number [] |
p2 | number [] |
Returns ​
number
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:367
len ​
static
len(A
):number
Length of the vector
Parameters ​
Parameter | Type |
---|---|
A | number [] |
Returns ​
number
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:165
len2 ​
static
len2(A
):number
Length of the vector squared
Parameters ​
Parameter | Type |
---|---|
A | number [] |
Returns ​
number
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:157
lrp ​
static
lrp(A
,B
,t
):number
[]
Interpolate vector A to B with a scalar t
Parameters ​
Parameter | Type | Description |
---|---|---|
A | number [] | - |
B | number [] | - |
t | number | scalar |
Returns ​
number
[]
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:311
max ​
static
max(...v
):number
[]
Get a vector comprised of the maximum of two or more vectors.
Parameters ​
Parameter | Type |
---|---|
...v | number [][] |
Returns ​
number
[]
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:583
med ​
static
med(A
,B
):number
[]
Mean between two vectors or mid vector between two vectors
Parameters ​
Parameter | Type |
---|---|
A | number [] |
B | number [] |
Returns ​
number
[]
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:259
min ​
static
min(...v
):number
[]
Get a vector comprised of the minimum of two or more vectors.
Parameters ​
Parameter | Type |
---|---|
...v | number [][] |
Returns ​
number
[]
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:590
mul ​
static
mul(A
,n
):number
[]
Vector multiplication by scalar
Parameters ​
Parameter | Type |
---|---|
A | number [] |
n | number |
Returns ​
number
[]
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:88
mulV ​
static
mulV(A
,B
):number
[]
Multiple two vectors.
Parameters ​
Parameter | Type |
---|---|
A | number [] |
B | number [] |
Returns ​
number
[]
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:97
nearestPointOnBounds ​
static
nearestPointOnBounds(bounds
,P
):number
[]
Get the nearest point on a bounding box to a point P.
Parameters ​
Parameter | Type | Description |
---|---|---|
bounds | object | The bounding box |
bounds.maxX | number | - |
bounds.maxY | number | - |
bounds.minX | number | - |
bounds.minY | number | - |
P | number [] | The point point |
Returns ​
number
[]
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:487
nearestPointOnLineSegment ​
static
nearestPointOnLineSegment(A
,B
,P
,clamp
=true
):number
[]
Get the nearest point on a line segment between A and B
Parameters ​
Parameter | Type | Default value | Description |
---|---|---|---|
A | number [] | undefined | The start of the line segment |
B | number [] | undefined | The end of the line segment |
P | number [] | undefined | The off-line point |
clamp | boolean | true | Whether to clamp the point between A and B. |
Returns ​
number
[]
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:445
nearestPointOnLineThroughPoint ​
static
nearestPointOnLineThroughPoint(A
,u
,P
):number
[]
Get the nearest point on a line with a known unit vector that passes through point A
Parameters ​
Parameter | Type | Description |
---|---|---|
A | number [] | Any point on the line |
u | number [] | The unit vector for the line. |
P | number [] | A point not on the line to test. |
Returns ​
number
[]
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:414
neg ​
static
neg(A
):number
[]
Negate a vector.
Parameters ​
Parameter | Type |
---|---|
A | number [] |
Returns ​
number
[]
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:33
normalize ​
static
normalize(A
):number
[]
Get normalized / unit vector.
Parameters ​
Parameter | Type |
---|---|
A | number [] |
Returns ​
number
[]
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:190
nudge ​
static
nudge(A
,B
,d
):number
[]
Push a point A towards point B by a given distance.
Parameters ​
Parameter | Type |
---|---|
A | number [] |
B | number [] |
d | number |
Returns ​
number
[]
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:527
nudgeAtAngle ​
static
nudgeAtAngle(A
,a
,d
):number
[]
Push a point in a given angle by a given distance.
Parameters ​
Parameter | Type |
---|---|
A | number [] |
a | number |
d | number |
Returns ​
number
[]
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:538
per ​
static
per(A
):number
[]
Perpendicular rotation of a vector A
Parameters ​
Parameter | Type |
---|---|
A | number [] |
Returns ​
number
[]
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:123
pointOffset ​
static
pointOffset(A
,B
,offset
):IVec
Parameters ​
Parameter | Type |
---|---|
A | IVec |
B | IVec |
offset | number |
Returns ​
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:565
pointsBetween ​
static
pointsBetween(A
,B
,steps
=6
):number
[][]
Get an array of points between two points.
Parameters ​
Parameter | Type | Default value | Description |
---|---|---|---|
A | number [] | undefined | The first point. |
B | number [] | undefined | The second point. |
steps | number | 6 | The number of points to return. |
Returns ​
number
[][]
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:557
pry ​
static
pry(A
,B
):number
Project A over B
Parameters ​
Parameter | Type |
---|---|
A | number [] |
B | number [] |
Returns ​
number
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:174
rescale ​
static
rescale(a
,n
):number
[]
Parameters ​
Parameter | Type |
---|---|
a | number [] |
n | number |
Returns ​
number
[]
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:356
rot ​
static
rot(A
,r
=0
):number
[]
Vector rotation by r (radians)
Parameters ​
Parameter | Type | Default value | Description |
---|---|---|---|
A | number [] | undefined | - |
r | number | 0 | rotation in radians |
Returns ​
number
[]
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:268
rotWith ​
static
rotWith(A
,C
,r
=0
):number
[]
Rotate a vector around another vector by r (radians)
Parameters ​
Parameter | Type | Default value | Description |
---|---|---|---|
A | number [] | undefined | vector |
C | number [] | undefined | center |
r | number | 0 | rotation in radians |
Returns ​
number
[]
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:281
slope ​
static
slope(A
,B
):number
Get the slope between two points.
Parameters ​
Parameter | Type |
---|---|
A | number [] |
B | number [] |
Returns ​
number
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:575
snap ​
static
snap(a
,step
=1
):number
[]
Snap vector to nearest step.
Parameters ​
Parameter | Type | Default value |
---|---|---|
a | number [] | undefined |
step | number | 1 |
Returns ​
number
[]
Example ​
Vec.snap([10.5, 28], 10) // [10, 30]
Vec.snap([10.5, 28], 10) // [10, 30]
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:403
sub ​
static
sub(A
,B
):number
[]
Subtract vectors.
Parameters ​
Parameter | Type |
---|---|
A | number [] |
B | number [] |
Returns ​
number
[]
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:60
subScalar ​
static
subScalar(A
,n
):number
[]
Subtract scalar from vector.
Parameters ​
Parameter | Type |
---|---|
A | number [] |
n | number |
Returns ​
number
[]
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:69
tangent ​
static
tangent(A
,B
):number
[]
Get the tangent between two vectors.
Parameters ​
Parameter | Type |
---|---|
A | number [] |
B | number [] |
Returns ​
number
[]
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:200
toFixed ​
static
toFixed(a
):number
[]
Round a vector to two decimal places.
Parameters ​
Parameter | Type |
---|---|
a | number [] |
Returns ​
number
[]
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:390
toPoint ​
static
toPoint(v
):object
Parameters ​
Parameter | Type |
---|---|
v | IVec |
Returns ​
x
​
x:
number
y
​
y:
number
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:596
toPrecision ​
static
toPrecision(a
,n
=4
):number
[]
Round a vector to a precision length.
Parameters ​
Parameter | Type | Default value |
---|---|---|
a | number [] | undefined |
n | number | 4 |
Returns ​
number
[]
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:547
toVec ​
static
toVec(v
):number
[]
Parameters ​
Parameter | Type |
---|---|
v | object |
v.x | number |
v.y | number |
Returns ​
number
[]
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:594
uni ​
static
uni(A
):number
[]
Get normalized / unit vector.
Parameters ​
Parameter | Type |
---|---|
A | number [] |
Returns ​
number
[]
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:182
vec ​
static
vec(A
,B
):number
[]
Get the vector from vectors A to B.
Parameters ​
Parameter | Type |
---|---|
A | number [] |
B | number [] |
Returns ​
number
[]
Defined In ​
packages/blocks/src/surface-block/utils/vec.ts:78