Home My Page Projects Code Snippets Project Openings 3D graphics for Standard ML
Summary Activity SCM

SCM Repository

[sml3d] View of /trunk/sml3d/src/sml3d/base/vec2-sig.sml
ViewVC logotype

View of /trunk/sml3d/src/sml3d/base/vec2-sig.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1260 - (download) (annotate)
Tue Jan 17 14:01:50 2012 UTC (7 years, 8 months ago) by jhr
File size: 2198 byte(s)
  Working on new SML3d core library
(* vec2-sig.sml
 *
 * COPYRIGHT (c) 2012 The SML3d Project (http://sml3d.cs.uchicago.edu)
 * All rights reserved.
 *)

signature VEC2 =
  sig

    type flt	(* coordinate type: either float or double *)

    type vec2 = (flt * flt)
    type vec3 = (flt * flt * flt)

    val nth : vec2 * int -> flt

  (* functional update *)
    val setNth : vec2 * int * flt -> vec2

  (* lift a 2D vector into homogeneous space *)
    val vector : vec2 -> vec3
    val point : vec2 -> vec3

    val zero : vec2

  (* standard basis vectors *)
    val e1 : vec2
    val e2 : vec2

    val toString : vec2 -> string

    val neg : vec2 -> vec2
    val add : (vec2 * vec2) -> vec2
    val sub : (vec2 * vec2) -> vec2
    val mul : (vec2 * vec2) -> vec2

    val scale : (flt * vec2) -> vec2

  (* adds (u, s, v) = u + s*v *)
    val adds : (vec2 * flt * vec2) -> vec2

  (* per-element operations *)
    val abs : vec2 -> vec2
    val min : vec2 * vec2 -> vec2
    val max : vec2 * vec2 -> vec2

  (* lerp (u, t, v) = (1-t)*u + t*v; we assume that 0 <= t <= 1 *)
    val lerp : (vec2 * flt * vec2) -> vec2

  (* spherical interpolation between unit vectors *)
    val slerp : (vec2 * flt * vec2) -> vec2

    val dot : (vec2 * vec2) -> flt
    val normalize : vec2 -> vec2
    val length : vec2 -> flt
    val lengthSq : vec2 -> flt		(* length squared *)
    val lengthAndDir : vec2 -> (flt * vec2)	(* length and normal vector *)
    val distanceSq : (vec2 * vec2) -> flt	(* distance squared *)
    val distance : (vec2 * vec2) -> flt	(* distance between two points *)
    val clipLength : (vec2 * flt) -> vec2

  (* return the parallel and perpendicular components of a vector v relative to a
   * unit basis vector.
   *)
    val parallelComponent : {basis : vec2, v : vec2} -> vec2
    val perpendicularComponent : {basis : vec2, v : vec2} -> vec2

  (* rotate the vector by 90 degrees in the CW direction *)
    val perpCW : vec2 -> vec2
  (* rotate the vector by 90 degrees in the CCW direction *)
    val perpCCW : vec2 -> vec2

  (* iterators *)
    val app  : (flt -> unit) -> vec2 -> unit
    val map  : (flt -> 'a) -> vec2 -> ('a * 'a)
    val map2 : (flt * flt -> 'a) -> (vec2 * vec2) -> ('a * 'a)

  end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0