summaryrefslogtreecommitdiffstats
path: root/kpovmodeler/pmvectorcontrolpoint.cpp
blob: fe7b0fe2e2d194584ecfbb96a834b673f766a5c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
**************************************************************************
                                 description
                             --------------------
    copyright            : (C) 2000-2001 by Andreas Zehender
    email                : zehender@kde.org
**************************************************************************

**************************************************************************
*                                                                        *
*  This program is free software; you can redistribute it and/or modify  *
*  it under the terms of the GNU General Public License as published by  *
*  the Free Software Foundation; either version 2 of the License, or     *
*  (at your option) any later version.                                   *
*                                                                        *
**************************************************************************/

#include "pmvectorcontrolpoint.h"
#include "pmmath.h"
#include <math.h>

PMVectorControlPoint::PMVectorControlPoint( PMControlPoint* base,
                                            const PMVector& v, int id,
                                            const TQString& description,
                                            bool extraLine, bool normalize )
      : PMControlPoint( id, description )
{
   m_vector = v;
   m_pBasePoint = base;
   m_extraLine = extraLine;
   m_normalize = normalize;
}

PMVectorControlPoint::PMVectorControlPoint( const PMVector& base,
                                            const PMVector& v, int id,
                                            const TQString& description,
                                            bool extraLine, bool normalize )
      : PMControlPoint( id, description )
{
   m_vector = v;
   m_constBasePoint = base;
   m_pBasePoint = 0;
   m_extraLine = extraLine;
   m_normalize = normalize;
}

PMVector PMVectorControlPoint::position( ) const
{
   return basePoint( ) + m_vector;
}

PMVector PMVectorControlPoint::basePoint( ) const
{
   if( m_pBasePoint )
      return m_pBasePoint->position( );
   return m_constBasePoint;
}

void PMVectorControlPoint::graphicalChangeStarted( )
{
   m_originalVector = m_vector;
}

void PMVectorControlPoint::graphicalChange( const PMVector& startPoint,
                                        const PMVector& /*viewNormal*/,
                                        const PMVector& endPoint )
{
   double d;
   
   m_vector = m_originalVector + endPoint - startPoint;
   if( m_normalize )
   {
      d = m_vector.abs( );
      if( approxZero( d ) )
         m_vector = m_originalVector;
      else
         m_vector /= d;
   }
}

void PMVectorControlPoint::snapToGrid( )
{
   int i;
   double d = moveGrid( );
   if( !approxZero( d ) )
      for( i = 0; i < 3; i++ )
         m_vector[i] = rint( m_vector[i] / d ) * d;
   setChanged( );
}