////////////////////////////////////////////////////////////////////////
//
// SecWeight.C - 
//
// $Id: SecWeight.C,v 1.3 2001/12/28 18:27:15 goetz Exp $
//
////////////////////////////////////////////////////////////////////////

#include "SecWeight.h"

double DefaultSecW::w(const Alchar &a) const
{
  return 1;
}

double BlockScaleFixed::w(const Alchar &a) const
{
  // is position out of interval [beg+offs, end-offs] ?
  if ( (int(a.pos) < int(a.secstr.beg+offset)) || 
       (int(a.pos) > int(a.secstr.end-offset)) )
    return 1;
  else
    return scale;
}

double BlockScaleProp::w(const Alchar &a) const
{
  // is position out of interval [beg+offs, end-offs] ?
  if ( (double(a.pos) < a.secstr.beg+offset*a.secstr.len() ) || 
       (double(a.pos) > a.secstr.end-offset*a.secstr.len() ) )
    return 1;
  else
    return scale;
}

double LinearFixed::w(const Alchar &a) const
{
  // determine interval, in which the position of a is:
  if ( (a.pos < a.secstr.beg) || (a.pos > a.secstr.end) )
    return 1;     // out of any secondary structure interval
  else if (int(a.pos) < int(a.secstr.beg+offset)) // first linear interval
    return (a.pos - a.secstr.beg)*(scale - 1)/offset + 1;
  else if (int(a.pos) > int(a.secstr.end-offset)) // last linear interval
    return (a.secstr.end - a.pos)*(scale - 1)/offset + 1;
  else // in middle interval
    return scale;
}

double LinearProp::w(const Alchar &a) const
{
  double offs= a.secstr.len()*offset; // proportional offset
  // determine interval, in which the position of a is:
  if ( (a.pos < a.secstr.beg) || (a.pos > a.secstr.end) )
    return 1;     // out of any secondary structure interval
  else if (double(a.pos) < a.secstr.beg+offs) // first linear interval
    return (a.pos - a.secstr.beg)*(scale - 1)/offs + 1;
  else if (double(a.pos) > a.secstr.end-offs) // last linear interval
    return (a.secstr.end - a.pos)*(scale - 1)/offs + 1;
  else // in middle interval
    return scale;
}

double IndepSecW::w(const Alchar &a) const
{
  switch (a.secstr.type) {
  case SecStructure::ALPHA:
    return falpha->w(a);
  case SecStructure::BETA:
    return fbeta->w(a);
  default:
    return 1;
  }
}
