package provide Freetype::fttrigon 0.1

if {![info exists _source([file tail [info script]])]} {
package require Freetype::ft2build
package require $FT_FREETYPE

ffidl::typedef FT_Angle FT_Fixed

set FT_ANGLE_PI  [expr {180 << 16}]
set FT_ANGLE_2PI [expr {$FT_ANGLE_PI * 2}]
set FT_ANGLE_PI2 [expr {$FT_ANGLE_PI / 2}]
set FT_ANGLE_PI4 [expr {$FT_ANGLE_PI / 4}]

::ffidl::callout _FT_Sin {FT_Angle} FT_Fixed \
    [::ffidl::symbol $::ft::lib FT_Sin]
proc  FT_Sin {angle} { return [_FT_Sin $angle] }

::ffidl::callout _FT_Cos {FT_Angle} FT_Fixed \
    [::ffidl::symbol $::ft::lib FT_Cos]
proc  FT_Cos {angle} { return [_FT_Cos $angle] }

::ffidl::callout _FT_Tan {FT_Angle} FT_Fixed \
    [::ffidl::symbol $::ft::lib FT_Tan]
proc  FT_Tan {angle} { return [_FT_Tan $angle] }

::ffidl::callout _FT_Atan2 {FT_Fixed FT_Fixed} FT_Angle \
    [::ffidl::symbol $::ft::lib FT_Atan2]
proc  FT_Atan2 {x y} { return [_FT_Atan2 $x $y] }

::ffidl::callout _FT_Angle_Diff {FT_Angle FT_Angle} FT_Angle \
    [::ffidl::symbol $::ft::lib FT_Angle_Diff]
proc  FT_Angle_Diff {angle1 angle2} { return [_FT_Angle_Diff $angle1 $angle2] }

::ffidl::callout _FT_Vector_Unit {pointer FT_Angle} void \
    [::ffidl::symbol $::ft::lib FT_Vector_Unit]
proc  FT_Vector_Unit {vec angle} {
    _FT_Vector_Unit [$vec getPointer] $angle
    return
}

::ffidl::callout _FT_Vector_Rotate {pointer FT_Angle} void \
    [::ffidl::symbol $::ft::lib FT_Vector_Rotate]
proc  FT_Vector_Rotate {vec angle} {
    _FT_Vector_Rotate [$vec getPointer] $angle
    return
}

::ffidl::callout _FT_Vector_Length {pointer} FT_Fixed \
    [::ffidl::symbol $::ft::lib FT_Vector_Length]
proc  FT_Vector_Length {vec} {
    set result [_FT_Vector_Length [$vec getPointer]]
    return $result
}

::ffidl::callout _FT_Vector_Polarize {pointer pointer-var pointer-var} void \
    [::ffidl::symbol $::ft::lib FT_Vector_Polarize]
proc  FT_Vector_Polarize {vec lengthVarName angleVarName} {
    set p1 [::ft::_bytearray_from FT_Fixed 0]
    set p2 [::ft::_bytearray_from FT_Fixed 0]
    _FT_Vector_Polarize [$vec getPointer] p1 p2
    uplevel [list set $lengthVarName [::ft::_bytearray_to FT_Fixed $p1]]
    uplevel [list set $angleVarName  [::ft::_bytearray_to FT_Fixed $p2]]
    return
}

::ffidl::callout _FT_Vector_From_Polar {pointer FT_Fixed FT_Fixed} void \
    [::ffidl::symbol $::ft::lib FT_Vector_From_Polar]
proc  FT_Vector_From_Polar {vec length angle} {
    _FT_Vector_From_Polar [$vec getPointer] $length $angle
    return
}

set _source([file tail [info script]]) 1
}
