<commit_before>module OpenSolid.Core.Vector2d
  ( zero
  , fromComponents
  , components
  , equals
  , componentIn
  , squaredLength
  , length
  , normalized
  , direction
  , perpendicularVector
  , normalDirection
  , rotatedBy
  , relativeTo
  , placedIn
  , mirroredAbout
  , projectionIn
  , projectedOnto
  , placedOnto
  , negated
  , plus
  , minus
  , times
  , addedTo
  , subtractedFrom
  , dot
  , cross
  ) where


import Debug
import Maybe exposing (..)
import OpenSolid.Core exposing (..)


zero: Vector2d
zero =
  Vector2d 0 0


fromComponents: (Float, Float) -> Vector2d
fromComponents (x, y) =
  Vector2d x y


components: Vector2d -> (Float, Float)
components (Vector2d x y) =
  (x, y)


equals: Vector2d -> Vector2d -> Bool
equals (Vector2d x2 y2) (Vector2d x1 y1) =
  x1 == x2 && y1 == y2


componentIn: Direction2d -> Vector2d -> Float
componentIn (Direction2d vector) =
  dot vector


squaredLength: Vector2d -> Float
squaredLength (Vector2d x y) =
  x * x + y * y


length: Vector2d -> Float
length =
  squaredLength >> sqrt


normalized: Vector2d -> Maybe Vector2d
normalized vector =
  if equals zero vector then Nothing else Just (times (1 / length vector) vector)


direction: Vector2d -> Maybe Direction2d
direction =
  normalized >> Maybe.map Direction2d


perpendicularVector: Vector2d -> Vector2d
perpendicularVector (Vector2d x y) =
  Vector2d (-y) x


normalDirection: Vector2d -> Maybe Direction2d
normalDirection =
  perpendicularVector >> direction


rotatedBy: Float -> Vector2d -> Vector2d
rotatedBy angle =
  let
    cosine = Debug.log "cosine" (cos angle)
    sine = Debug.log "sine" (sin angle)
  in
    \(Vector2d x y) -> Vector2d (x * cosine - y * sine) (y * cosine + x * sine)


relativeTo: Frame2d -> Vector2d -> Vector2d
relativeTo frame vector =
  Vector2d (componentIn frame.xDirection vector) (componentIn frame.yDirection vector)


placedIn: Frame2d -> Vector2d -> Vector2d
placedIn frame =
  let
    (Direction2d (Vector2d x1 y1)) = frame.xDirection
    (Direction2d (Vector2d x2 y2)) = frame.yDirection
  in
    \(Vector2d x y) -> Vector2d (x1 * x + x2 * y) (y1 * x + y2 * y)


mirroredAbout: Direction2d -> Vector2d -> Vector2d
mirroredAbout direction =
  let
    (Direction2d (Vector2d dx dy)) = direction
    a = 1 - 2 * dy * dy
    b = 2 * dx * dy
    c = 1 - 2 * dx * dx
  in
    \(Vector2d vx vy) -> Vector2d (a * vx + b * vy) (c * vy + b * vx)


projectionIn: Direction2d -> Vector2d -> Vector2d
projectionIn (Direction2d directionVector as direction) vector =
  times (componentIn direction vector) directionVector


projectedOnto: Axis2d -> Vector2d -> Vector2d
projectedOnto axis =
  projectionIn axis.direction


placedOnto: Plane3d -> Vector2d -> Vector3d
placedOnto plane =
  let
    (Direction3d (Vector3d x1 y1 z1)) = plane.xDirection
    (Direction3d (Vector3d x2 y2 z2)) = plane.yDirection
  in
    \(Vector2d x y) -> Vector3d (x1 * x + x2 * y) (y1 * x + y2 * y) (z1 * x + z2 * y)
<commit_msg>Make function order more consistent across modules<commit_after>module OpenSolid.Core.Vector2d
  ( zero
  , fromComponents
  , components
  , equals
  , componentIn
  , squaredLength
  , length
  , normalized
  , direction
  , perpendicularVector
  , normalDirection
  , rotatedBy
  , mirroredAbout
  , relativeTo
  , placedIn
  , projectionIn
  , projectedOnto
  , placedOnto
  , negated
  , plus
  , minus
  , times
  , addedTo
  , subtractedFrom
  , dot
  , cross
  ) where


import Debug
import Maybe exposing (..)
import OpenSolid.Core exposing (..)


zero: Vector2d
zero =
  Vector2d 0 0


fromComponents: (Float, Float) -> Vector2d
fromComponents (x, y) =
  Vector2d x y


components: Vector2d -> (Float, Float)
components (Vector2d x y) =
  (x, y)


equals: Vector2d -> Vector2d -> Bool
equals (Vector2d x2 y2) (Vector2d x1 y1) =
  x1 == x2 && y1 == y2


componentIn: Direction2d -> Vector2d -> Float
componentIn (Direction2d vector) =
  dot vector


squaredLength: Vector2d -> Float
squaredLength (Vector2d x y) =
  x * x + y * y


length: Vector2d -> Float
length =
  squaredLength >> sqrt


normalized: Vector2d -> Maybe Vector2d
normalized vector =
  if equals zero vector then Nothing else Just (times (1 / length vector) vector)


direction: Vector2d -> Maybe Direction2d
direction =
  normalized >> Maybe.map Direction2d


perpendicularVector: Vector2d -> Vector2d
perpendicularVector (Vector2d x y) =
  Vector2d (-y) x


normalDirection: Vector2d -> Maybe Direction2d
normalDirection =
  perpendicularVector >> direction


rotatedBy: Float -> Vector2d -> Vector2d
rotatedBy angle =
  let
    cosine = Debug.log "cosine" (cos angle)
    sine = Debug.log "sine" (sin angle)
  in
    \(Vector2d x y) -> Vector2d (x * cosine - y * sine) (y * cosine + x * sine)


mirroredAbout: Direction2d -> Vector2d -> Vector2d
mirroredAbout direction =
  let
    (Direction2d (Vector2d dx dy)) = direction
    a = 1 - 2 * dy * dy
    b = 2 * dx * dy
    c = 1 - 2 * dx * dx
  in
    \(Vector2d vx vy) -> Vector2d (a * vx + b * vy) (c * vy + b * vx)


relativeTo: Frame2d -> Vector2d -> Vector2d
relativeTo frame vector =
  Vector2d (componentIn frame.xDirection vector) (componentIn frame.yDirection vector)


placedIn: Frame2d -> Vector2d -> Vector2d
placedIn frame =
  let
    (Direction2d (Vector2d x1 y1)) = frame.xDirection
    (Direction2d (Vector2d x2 y2)) = frame.yDirection
  in
    \(Vector2d x y) -> Vector2d (x1 * x + x2 * y) (y1 * x + y2 * y)


projectionIn: Direction2d -> Vector2d -> Vector2d
projectionIn (Direction2d directionVector as direction) vector =
  times (componentIn direction vector) directionVector


projectedOnto: Axis2d -> Vector2d -> Vector2d
projectedOnto axis =
  projectionIn axis.direction


placedOnto: Plane3d -> Vector2d -> Vector3d
placedOnto plane =
  let
    (Direction3d (Vector3d x1 y1 z1)) = plane.xDirection
    (Direction3d (Vector3d x2 y2 z2)) = plane.yDirection
  in
    \(Vector2d x y) -> Vector3d (x1 * x + x2 * y) (y1 * x + y2 * y) (z1 * x + z2 * y)

{'fraction_non_alphanumeric': 0.10222892575833753, 'fraction_numerical': 0.034858387799564274, 'mean_word_length': 3.2416488983653164, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 75, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '904542', 'n_tokens_mistral': 2203, 'n_tokens_neox': 2088, 'n_words': 646}