1/*
2* Copyright (c) 2018 (https://github.com/phase1geo/Minder)
3*
4* This program is free software; you can redistribute it and/or
5* modify it under the terms of the GNU General Public
6* License as published by the Free Software Foundation; either
7* version 2 of the License, or (at your option) any later version.
8*
9* This program is distributed in the hope that it will be useful,
10* but WITHOUT ANY WARRANTY; without even the implied warranty of
11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12* General Public License for more details.
13*
14* You should have received a copy of the GNU General Public
15* License along with this program; if not, write to the
16* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17* Boston, MA 02110-1301 USA
18*
19* Authored by: Trevor Williams <phase1geo@gmail.com>
20*/
21
22using GLib;
23
24/*
25 Helper class to the Animator class. This class should not
26 be accessed outside of this file.
27*/
28public class AnimatorPositions : Object {
29
30  private Array<double?> _old_x;
31  private Array<double?> _old_y;
32  private Array<double?> _new_x;
33  private Array<double?> _new_y;
34  private Array<Node?>   _node;
35
36  /* Default constructor */
37  public AnimatorPositions( DrawArea da, Array<Node> nodes ) {
38    _old_x = new Array<double?>();
39    _old_y = new Array<double?>();
40    _new_x = new Array<double?>();
41    _new_y = new Array<double?>();
42    _node  = new Array<Node?>();
43    for( int i=0; i<nodes.length; i++ ) {
44      gather_old_positions( nodes.index( i ) );
45    }
46  }
47
48  /*
49   Gathers the nodes and their current positions and stores
50   them into array structures.
51  */
52  private void gather_old_positions( Node n ) {
53    _old_x.append_val( n.posx );
54    _old_y.append_val( n.posy );
55    _node.append_val( n );
56    for( int i=0; i<n.children().length; i++ ) {
57      gather_old_positions( n.children().index( i ) );
58    }
59  }
60
61  /*
62   Gathers the new node positions for the stored nodes.
63  */
64  public void gather_new_positions() {
65    for( int i=0; i<_node.length; i++ ) {
66      _new_x.append_val( _node.index( i ).posx );
67      _new_y.append_val( _node.index( i ).posy );
68    }
69  }
70
71  /* Returns the number of nodes in this structure */
72  public uint length() {
73    return( _node.length );
74  }
75
76  /* Returns the old X position at the given index */
77  public double old_x( int index ) {
78    return( _old_x.index( index ) );
79  }
80
81  /* Returns the old Y position at the given index */
82  public double old_y( int index ) {
83    return( _old_y.index( index ) );
84  }
85
86  /* Returns the new X position at the given index */
87  public double new_x( int index ) {
88    return( _new_x.index( index ) );
89  }
90
91  /* Returns the new Y position at the given index */
92  public double new_y( int index ) {
93    return( _new_y.index( index ) );
94  }
95
96  /* Returns the node at the given index */
97  public Node node( int index ) {
98    return( _node.index( index ) );
99  }
100
101}
102