-module(vec@vec2f). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/vec/vec2f.gleam"). -export([clamp/3, loosely_equals/3, min/2, max/2, ceiling/1, floor/1, round/1, truncate/1, to_precision/2, absolute_value/1, to_string/2, negate/1, add/2, sum/1, multiply/2, product/1, modulo/2, divide/2, subtract/2, length_squared/1, length/1, compare_length/2, loosely_compare_length/3, distance_squared/2, distance/2, compare_distance/3, loosely_compare_distance/4, scale/2, normalize/1, direction/2, cross/2, dot/2, project/2, slide/2, reflect/2, mirror/2, angle/2, signed_angle/2, rotate/2, anchor_position/3, anchor_rotation/3]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. -file("src/vec/vec2f.gleam", 54). ?DOC( " Returns a new vector with all components clamped between a lower and upper\n" " bound.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert\n" " Vec2(1.2, -3.4)\n" " |> clamp(Vec2(1.0, 2.1), Vec2(1.4, 18.2))\n" " == Vec2(1.2, 2.1)\n" " ```\n" ). -spec clamp( vec@vec2:vec2(float()), vec@vec2:vec2(float()), vec@vec2:vec2(float()) ) -> vec@vec2:vec2(float()). clamp(Vector, Start_bound, Stop_bound) -> vec@vec2:map3(Vector, Start_bound, Stop_bound, fun gleam@float:clamp/3). -file("src/vec/vec2f.gleam", 69). ?DOC( " Checks for equality of two vectors within a tolerance, returning an `Bool`.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert\n" " Vec2(1.2, -3.4)\n" " |> loosely_equals(Vec2(1.25, -3.43), tolerating: 0.1)\n" " == True\n" " ```\n" ). -spec loosely_equals(vec@vec2:vec2(float()), vec@vec2:vec2(float()), float()) -> boolean(). loosely_equals(A, B, Tolerance) -> case begin _pipe = A, vec@vec2:map2( _pipe, B, fun(A@1, B@1) -> gleam@float:loosely_equals(A@1, B@1, Tolerance) end ) end of {vec2, true, true} -> true; _ -> false end. -file("src/vec/vec2f.gleam", 88). ?DOC( " Compares two vectors, returning the smaller of the two.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert min(Vec2(1.2, -3.4), Vec2(1.0, 2.1)) == Vec2(1.0, -3.4)\n" " ```\n" ). -spec min(vec@vec2:vec2(float()), vec@vec2:vec2(float())) -> vec@vec2:vec2(float()). min(A, B) -> _pipe = A, vec@vec2:map2(_pipe, B, fun gleam@float:min/2). -file("src/vec/vec2f.gleam", 100). ?DOC( " Compares two vectors, returning the larger of the two.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert max(Vec2(1.2, -3.4), Vec2(1.4, -9.3)) == Vec2(1.4, -3.4)\n" " ```\n" ). -spec max(vec@vec2:vec2(float()), vec@vec2:vec2(float())) -> vec@vec2:vec2(float()). max(A, B) -> _pipe = A, vec@vec2:map2(_pipe, B, fun gleam@float:max/2). -file("src/vec/vec2f.gleam", 113). ?DOC( " Returns a new vector with all elements rounded to the next highest whole\n" " number as a `Float`.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert Vec2(1.2, -3.6) |> ceiling == Vec2(2.0, -3.0)\n" " ```\n" ). -spec ceiling(vec@vec2:vec2(float())) -> vec@vec2:vec2(float()). ceiling(Vector) -> _pipe = Vector, vec@vec2:map(_pipe, fun math:ceil/1). -file("src/vec/vec2f.gleam", 126). ?DOC( " Returns a new vector with all elements rounded to the next lowest whole\n" " number as an `Float`.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert Vec2(1.2, -3.6) |> floor == Vec2(1.0, -4.0)\n" " ```\n" ). -spec floor(vec@vec2:vec2(float())) -> vec@vec2:vec2(float()). floor(Vector) -> _pipe = Vector, vec@vec2:map(_pipe, fun math:floor/1). -file("src/vec/vec2f.gleam", 139). ?DOC( " Returns a new vector with all elements rounded to the nearest whole number\n" " as an `Int`.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert Vec2(1.2, -3.6) |> round == Vec2(1, -4)\n" " ```\n" ). -spec round(vec@vec2:vec2(float())) -> vec@vec2:vec2(integer()). round(Vector) -> _pipe = Vector, vec@vec2:map(_pipe, fun erlang:round/1). -file("src/vec/vec2f.gleam", 151). ?DOC( " Returns a new vector with all elements truncated as an `Int`.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert Vec2(1.2323232827383238, -3.656565) |> truncate == Vec2(1, -3)\n" " ```\n" ). -spec truncate(vec@vec2:vec2(float())) -> vec@vec2:vec2(integer()). truncate(Vector) -> _pipe = Vector, vec@vec2:map(_pipe, fun erlang:trunc/1). -file("src/vec/vec2f.gleam", 173). ?DOC( " Returns a new vector with all elements converted to a given precision.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert\n" " Vec2(2.43434348473, -3.656565)\n" " |> to_precision(2)\n" " == Vec2(2.43, -3.66)\n" " ```\n" "\n" " ```gleam\n" " assert\n" " Vec2(547_890.453444, -3.656565)\n" " |> to_precision(-3)\n" " == Vec2(548_000.0, 0.0)\n" " ```\n" ). -spec to_precision(vec@vec2:vec2(float()), integer()) -> vec@vec2:vec2(float()). to_precision(Vector, Precision) -> _pipe = Vector, vec@vec2:map( _pipe, fun(_capture) -> gleam@float:to_precision(_capture, Precision) end ). -file("src/vec/vec2f.gleam", 185). ?DOC( " Returns a new vector with all elements in absolute values.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert Vec2(1.2, -3.4) |> absolute_value == Vec2(1.2, 3.4)\n" " ```\n" ). -spec absolute_value(vec@vec2:vec2(float())) -> vec@vec2:vec2(float()). absolute_value(Vector) -> _pipe = Vector, vec@vec2:map(_pipe, fun gleam@float:absolute_value/1). -file("src/vec/vec2f.gleam", 197). ?DOC( " Prints a given vector to a string with a given separator.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert Vec2(1.2, -3.4) |> to_string(\" \") == \"1.2 -3.4\"\n" " ```\n" ). -spec to_string(vec@vec2:vec2(float()), binary()) -> binary(). to_string(Vector, Separator) -> _pipe = Vector, _pipe@1 = vec@vec2:map(_pipe, fun gleam_stdlib:float_to_string/1), _pipe@2 = vec@vec2:to_list(_pipe@1), gleam@string:join(_pipe@2, Separator). -file("src/vec/vec2f.gleam", 209). ?DOC( " Returns a new vector with all elements negated.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert Vec2(1.2, -3.4) |> negate == Vec2(-1.2, 3.4)\n" " ```\n" ). -spec negate(vec@vec2:vec2(float())) -> vec@vec2:vec2(float()). negate(Vector) -> _pipe = Vector, vec@vec2:map(_pipe, fun gleam@float:negate/1). -file("src/vec/vec2f.gleam", 283). ?DOC( " Adds two vectors together.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert Vec2(1.2, -3.4) |> add(Vec2(2.1, 4.5)) == Vec2(3.3, 1.1)\n" " ```\n" ). -spec add(vec@vec2:vec2(float()), vec@vec2:vec2(float())) -> vec@vec2:vec2(float()). add(A, B) -> _pipe = A, vec@vec2:map2(_pipe, B, fun gleam@float:add/2). -file("src/vec/vec2f.gleam", 224). ?DOC( " Sums a list of vectors.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert\n" " [Vec2(1.2, -3.4), Vec2(2.1, 4.5), Vec2(3.3, 0.0)]\n" " |> sum\n" " == Vec2(6.6, 1.1)\n" " ```\n" ). -spec sum(list(vec@vec2:vec2(float()))) -> vec@vec2:vec2(float()). sum(Vectors) -> _pipe = Vectors, gleam@list:fold(_pipe, vec@vec2:splat(+0.0), fun add/2). -file("src/vec/vec2f.gleam", 295). ?DOC( " Multiplies two vectors together.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert Vec2(1.2, -3.4) |> multiply(Vec2(2.1, -1.0)) == Vec2(2.52, 3.4)\n" " ```\n" ). -spec multiply(vec@vec2:vec2(float()), vec@vec2:vec2(float())) -> vec@vec2:vec2(float()). multiply(A, B) -> _pipe = A, vec@vec2:map2(_pipe, B, fun gleam@float:multiply/2). -file("src/vec/vec2f.gleam", 239). ?DOC( " Multiplies a list of vectors and returns the product.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert\n" " [Vec2(1.2, -3.4), Vec2(2.1, -1.0), Vec2(3.2, 2.0)]\n" " |> product\n" " == Vec2(8.064, 6.8)\n" " ```\n" ). -spec product(list(vec@vec2:vec2(float()))) -> vec@vec2:vec2(float()). product(Vectors) -> _pipe = Vectors, gleam@list:fold(_pipe, vec@vec2:splat(1.0), fun multiply/2). -file("src/vec/vec2f.gleam", 255). ?DOC( " Returns the modulo of the inputs as a `Result`.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert Vec2(13.3, 13.3) |> modulo(Vec2(3.3, -3.3)) == Ok(Vec2(0.1, -3.2))\n" " ```\n" "\n" " ```gleam\n" " assert Vec2(-13.3, -13.3) |> modulo(Vec2(3.3, -3.3)) == Ok(Vec2(3.2, -0.1))\n" " ```\n" ). -spec modulo(vec@vec2:vec2(float()), vec@vec2:vec2(float())) -> {ok, vec@vec2:vec2(float())} | {error, nil}. modulo(Dividend, Divisor) -> _pipe = Dividend, _pipe@1 = vec@vec2:map2(_pipe, Divisor, fun gleam@float:modulo/2), vec@vec2:result(_pipe@1). -file("src/vec/vec2f.gleam", 271). ?DOC( " Returns division of the inputs as a `Result`.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert Vec2(1.2, -3.4) |> divide(Vec2(2.0, 0.5)) == Ok(Vec2(0.6, -6.8))\n" " ```\n" "\n" " ```gleam\n" " assert Vec2(1.2, -3.4) |> divide(Vec2(0.0, 0.5)) == Error(Nil)\n" " ```\n" ). -spec divide(vec@vec2:vec2(float()), vec@vec2:vec2(float())) -> {ok, vec@vec2:vec2(float())} | {error, nil}. divide(Dividend, Divisor) -> _pipe = Dividend, _pipe@1 = vec@vec2:map2(_pipe, Divisor, fun gleam@float:divide/2), vec@vec2:result(_pipe@1). -file("src/vec/vec2f.gleam", 307). ?DOC( " Subtracts one vector from another.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert Vec2(1.2, -3.4) |> subtract(Vec2(0.7, -4.5)) == Vec2(0.5, 1.1)\n" " ```\n" ). -spec subtract(vec@vec2:vec2(float()), vec@vec2:vec2(float())) -> vec@vec2:vec2(float()). subtract(A, B) -> _pipe = A, vec@vec2:map2(_pipe, B, fun gleam@float:subtract/2). -file("src/vec/vec2f.gleam", 319). ?DOC( " Returns the squared length (squared magnitude) of the vector.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert Vec2(1.2, -3.4) |> length_squared == 13.0\n" " ```\n" ). -spec length_squared(vec@vec2:vec2(float())) -> float(). length_squared(Vector) -> _pipe = Vector, _pipe@1 = vec@vec2:to_list(_pipe), _pipe@2 = gleam@list:map(_pipe@1, fun(Element) -> Element * Element end), gleam@float:sum(_pipe@2). -file("src/vec/vec2f.gleam", 334). ?DOC( " Returns the length (magnitude) of the vector.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert Vec2(1.2, -3.4) |> length == 3.61\n" " ```\n" ). -spec length(vec@vec2:vec2(float())) -> float(). length(Vector) -> Length@1 = case begin _pipe = Vector, _pipe@1 = length_squared(_pipe), gleam@float:square_root(_pipe@1) end of {ok, Length} -> Length; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"vec/vec2f"/utf8>>, function => <<"length"/utf8>>, line => 335, value => _assert_fail, start => 7510, 'end' => 7579, pattern_start => 7521, pattern_end => 7531}) end, Length@1. -file("src/vec/vec2f.gleam", 349). ?DOC( " Compares two vector's lengths, returning an `Order`:\n" " `Lt` for lower than, `Eq` for equals, or `Gt` for greater than.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert compare_length(Vec2(1.2, -3.4), Vec2(1.0, 2.1)) == Gt\n" " ```\n" ). -spec compare_length(vec@vec2:vec2(float()), vec@vec2:vec2(float())) -> gleam@order:order(). compare_length(A, B) -> gleam@float:compare( begin _pipe = A, length_squared(_pipe) end, begin _pipe@1 = B, length_squared(_pipe@1) end ). -file("src/vec/vec2f.gleam", 368). ?DOC( " Compares two vector's lengths within a tolerance, returning an `Order`:\n" " `Lt` for lower than, `Eq` for equals, or `Gt` for greater than.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert\n" " loosely_compare_length(\n" " Vec2(1.2, -3.4),\n" " Vec2(-1.25, 3.43),\n" " tolerating: 0.5,\n" " )\n" " == Eq\n" " ```\n" ). -spec loosely_compare_length( vec@vec2:vec2(float()), vec@vec2:vec2(float()), float() ) -> gleam@order:order(). loosely_compare_length(A, B, Tolerance) -> gleam@float:loosely_compare( begin _pipe = A, length_squared(_pipe) end, begin _pipe@1 = B, length_squared(_pipe@1) end, Tolerance ). -file("src/vec/vec2f.gleam", 384). ?DOC( " Returns the squared distance between two vectors.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert Vec2(1.2, -3.4) |> distance_squared(Vec2(1.0, 2.1)) == 30.29\n" " ```\n" ). -spec distance_squared(vec@vec2:vec2(float()), vec@vec2:vec2(float())) -> float(). distance_squared(A, B) -> _pipe = A, _pipe@1 = subtract(_pipe, B), length_squared(_pipe@1). -file("src/vec/vec2f.gleam", 396). ?DOC( " Returns the distance between two vectors.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert Vec2(1.2, -3.4) |> distance(Vec2(1.0, 2.1)) == 5.5\n" " ```\n" ). -spec distance(vec@vec2:vec2(float()), vec@vec2:vec2(float())) -> float(). distance(A, B) -> Distance@1 = case begin _pipe = distance_squared(A, B), gleam@float:square_root(_pipe) end of {ok, Distance} -> Distance; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"vec/vec2f"/utf8>>, function => <<"distance"/utf8>>, line => 397, value => _assert_fail, start => 8952, 'end' => 9021, pattern_start => 8963, pattern_end => 8975}) end, Distance@1. -file("src/vec/vec2f.gleam", 417). ?DOC( " Compares two vector's distances to a vector, returning an `Order`:\n" " `Lt` for lower than, `Eq` for equals, or `Gt` for greater than.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert\n" " compare_distance(\n" " Vec2(1.2, -3.4),\n" " Vec2(1.0, 2.1),\n" " Vec2(-2.5, 6.7),\n" " )\n" " == Gt\n" " ```\n" ). -spec compare_distance( vec@vec2:vec2(float()), vec@vec2:vec2(float()), vec@vec2:vec2(float()) ) -> gleam@order:order(). compare_distance(A, B, Vector) -> gleam@float:compare( begin _pipe = A, distance_squared(_pipe, Vector) end, begin _pipe@1 = B, distance_squared(_pipe@1, Vector) end ). -file("src/vec/vec2f.gleam", 438). ?DOC( " Compares two vector's distances to a vector within a tolerance, returning\n" " an `Order`:\n" " `Lt` for lower than, `Eq` for equals, or `Gt` for greater than.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert\n" " loosely_compare_distance(\n" " Vec2(1.2, -3.4),\n" " Vec2(1.25, -3.43),\n" " Vec2(-2.5, 6.7),\n" " tolerating: 1.0,\n" " )\n" " == Eq\n" " ```\n" ). -spec loosely_compare_distance( vec@vec2:vec2(float()), vec@vec2:vec2(float()), vec@vec2:vec2(float()), float() ) -> gleam@order:order(). loosely_compare_distance(A, B, Vector, Tolerance) -> gleam@float:loosely_compare( begin _pipe = A, distance_squared(_pipe, Vector) end, begin _pipe@1 = B, distance_squared(_pipe@1, Vector) end, Tolerance ). -file("src/vec/vec2f.gleam", 459). ?DOC( " Returns a new vector containing the elements multiplies by `scalar`.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert Vec2(1.2, -3.4) |> scale(2.5) == Vec2(3.0, -8.5)\n" " ```\n" ). -spec scale(vec@vec2:vec2(float()), float()) -> vec@vec2:vec2(float()). scale(Vector, Scalar) -> _pipe = Vector, vec@vec2:map( _pipe, fun(_capture) -> gleam@float:multiply(_capture, Scalar) end ). -file("src/vec/vec2f.gleam", 471). ?DOC( " Normalize the vector.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert Vec2(1.2, -3.4) |> normalize == Vec2(0.33, -0.94)\n" " ```\n" ). -spec normalize(vec@vec2:vec2(float())) -> vec@vec2:vec2(float()). normalize(Vector) -> _pipe = Vector, scale( _pipe, case begin _pipe@1 = Vector, length(_pipe@1) end of +0.0 -> +0.0; -0.0 -> -0.0; Gleam@denominator -> 1.0 / Gleam@denominator end ). -file("src/vec/vec2f.gleam", 483). ?DOC( " Returns a normalized vector pointing from `a` to `b`.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert Vec2(1.2, -3.4) |> direction(Vec2(1.0, 2.1)) == Vec2(-0.04, 1.0)\n" " ```\n" ). -spec direction(vec@vec2:vec2(float()), vec@vec2:vec2(float())) -> vec@vec2:vec2(float()). direction(A, B) -> _pipe = B, _pipe@1 = subtract(_pipe, A), normalize(_pipe@1). -file("src/vec/vec2f.gleam", 495). ?DOC( " Returns the cross product of two vectors.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert Vec2(1.2, -3.4) |> cross(Vec2(1.0, 2.1)) == 5.92\n" " ```\n" ). -spec cross(vec@vec2:vec2(float()), vec@vec2:vec2(float())) -> float(). cross(A, B) -> (erlang:element(2, A) * erlang:element(3, B)) - (erlang:element(2, B) * erlang:element( 3, A )). -file("src/vec/vec2f.gleam", 507). ?DOC( " Returns the dot product of two vectors.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert Vec2(1.2, -3.4) |> dot(Vec2(1.0, 2.1)) == -5.94\n" " ```\n" ). -spec dot(vec@vec2:vec2(float()), vec@vec2:vec2(float())) -> float(). dot(A, B) -> _pipe = A, _pipe@1 = multiply(_pipe, B), _pipe@2 = vec@vec2:to_list(_pipe@1), gleam@float:sum(_pipe@2). -file("src/vec/vec2f.gleam", 519). ?DOC( " Returns the projection of a vector on another vector.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert Vec2(1.2, -3.4) |> project(Vec2(1.0, 2.1)) == Vec2(-1.1, -2.31)\n" " ```\n" ). -spec project(vec@vec2:vec2(float()), vec@vec2:vec2(float())) -> vec@vec2:vec2(float()). project(A, B) -> _pipe = B, scale(_pipe, case dot(B, B) of +0.0 -> +0.0; -0.0 -> -0.0; Gleam@denominator -> dot(A, B) / Gleam@denominator end). -file("src/vec/vec2f.gleam", 532). ?DOC( " Returns a new vector resulting from sliding this vector along a plane\n" " defined by the given normal vector.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert Vec2(1.2, -3.4) |> slide(Vec2(1.0, 2.1)) == Vec2(2.3, -1.09)\n" " ```\n" ). -spec slide(vec@vec2:vec2(float()), vec@vec2:vec2(float())) -> vec@vec2:vec2(float()). slide(A, B) -> _pipe = A, subtract( _pipe, begin _pipe@1 = A, project(_pipe@1, B) end ). -file("src/vec/vec2f.gleam", 545). ?DOC( " Returns the reflection of a vector through a plane defined by the given\n" " normal vector.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert Vec2(1.2, -3.4) |> reflect(Vec2(1.0, 2.1)) == Vec2(-3.4, -1.21)\n" " ```\n" ). -spec reflect(vec@vec2:vec2(float()), vec@vec2:vec2(float())) -> vec@vec2:vec2(float()). reflect(Vector, Normal) -> _pipe = Vector, _pipe@1 = project(_pipe, Normal), _pipe@2 = scale(_pipe@1, 2.0), subtract(_pipe@2, Vector). -file("src/vec/vec2f.gleam", 558). ?DOC( " Returns the mirror of a vector through a plane defined by the given normal\n" " vector.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert Vec2(1.2, -3.4) |> mirror(Vec2(1.0, 2.1)) == Vec2(3.34, 1.21)\n" " ```\n" ). -spec mirror(vec@vec2:vec2(float()), vec@vec2:vec2(float())) -> vec@vec2:vec2(float()). mirror(Vector, Normal) -> _pipe = Vector, _pipe@1 = reflect(_pipe, Normal), negate(_pipe@1). -file("src/vec/vec2f.gleam", 570). ?DOC( " Returns the angle (in radians) between two vectors in the range of (0, π).\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert Vec2(1.2, -3.4) |> angle(Vec2(1.0, 2.1)) == 2.36\n" " ```\n" ). -spec angle(vec@vec2:vec2(float()), vec@vec2:vec2(float())) -> float(). angle(A, B) -> Angle@1 = case begin _pipe = dot(normalize(A), normalize(B)), _pipe@1 = gleam@float:clamp(_pipe, -1.0, 1.0), gleam_community@maths:acos(_pipe@1) end of {ok, Angle} -> Angle; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"vec/vec2f"/utf8>>, function => <<"angle"/utf8>>, line => 571, value => _assert_fail, start => 12883, 'end' => 12981, pattern_start => 12894, pattern_end => 12903}) end, Angle@1. -file("src/vec/vec2f.gleam", 586). ?DOC( " Returns the signed angle (in radians) between two vectors in the range of\n" " (-π, π).\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert Vec2(1.2, -3.4) |> signed_angle(Vec2(1.0, 2.1)) == -2.36\n" " ```\n" ). -spec signed_angle(vec@vec2:vec2(float()), vec@vec2:vec2(float())) -> float(). signed_angle(A, B) -> gleam_community@maths:atan2(cross(B, A), dot(A, B)). -file("src/vec/vec2f.gleam", 598). ?DOC( " Rotate a vector by an angle (in radians).\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert Vec2(1.2, -3.4) |> rotate(maths.pi() *. 0.25) == Vec2(3.25, -1.56)\n" " ```\n" ). -spec rotate(vec@vec2:vec2(float()), float()) -> vec@vec2:vec2(float()). rotate(Vector, Angle) -> Cos_angle = gleam_community@maths:cos(Angle), Sin_angle = gleam_community@maths:sin(Angle), {vec2, (erlang:element(2, Vector) * Cos_angle) - (erlang:element(3, Vector) * Sin_angle), (erlang:element(2, Vector) * Sin_angle) + (erlang:element(3, Vector) * Cos_angle)}. -file("src/vec/vec2f.gleam", 619). ?DOC( " Return the equivalent of `vector |> subtract(position) |> fun |> add(position)`.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert\n" " Vec2(1.2, -3.4)\n" " |> anchor_position(Vec2(1.0, 2.1), rotate(_, maths.pi() *. 0.25))\n" " == Vec2(5.03, -1.65)\n" " ```\n" ). -spec anchor_position( vec@vec2:vec2(float()), vec@vec2:vec2(float()), fun((vec@vec2:vec2(float())) -> vec@vec2:vec2(float())) ) -> vec@vec2:vec2(float()). anchor_position(Vector, Position, Fun) -> _pipe = Vector, _pipe@1 = subtract(_pipe, Position), _pipe@2 = Fun(_pipe@1), add(_pipe@2, Position). -file("src/vec/vec2f.gleam", 638). ?DOC( " Return the equivalent of `vector |> rotate(float.negate(angle)) |> fun |> rotate(angle)`.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " assert\n" " Vec2(1.2, -3.4)\n" " |> anchor_rotation(maths.pi() *. 0.25, add(_, Vec2(6.0, 9.0)))\n" " == Vec2(-0.92, 7.21)\n" " ```\n" ). -spec anchor_rotation( vec@vec2:vec2(float()), float(), fun((vec@vec2:vec2(float())) -> vec@vec2:vec2(float())) ) -> vec@vec2:vec2(float()). anchor_rotation(Vector, Angle, Fun) -> _pipe = Vector, _pipe@1 = rotate(_pipe, gleam@float:negate(Angle)), _pipe@2 = Fun(_pipe@1), rotate(_pipe@2, Angle).