Blame view

Giac_maj/epsilon-giac/poincare/src/matrix.cpp 2.22 KB
6663b6c9   adorian   projet complet av...
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
  extern "C" {
  #include <assert.h>
  #include <stdlib.h>
  }
  #include <poincare/matrix.h>
  #include <poincare/complex.h>
  #include "layout/grid_layout.h"
  #include "layout/bracket_layout.h"
  #include <cmath>
  #include <float.h>
  #include <string.h>
  
  namespace Poincare {
  
  int Matrix::numberOfOperands() const {
    return numberOfRows() * numberOfColumns();
  }
  
  ExpressionLayout * Matrix::privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const {
    assert(floatDisplayMode != FloatDisplayMode::Default);
    assert(complexFormat != ComplexFormat::Default);
    ExpressionLayout ** childrenLayouts = new ExpressionLayout * [numberOfOperands()];
    for (int i = 0; i < numberOfOperands(); i++) {
      childrenLayouts[i] = operand(i)->createLayout(floatDisplayMode, complexFormat);
    }
    ExpressionLayout * layout = new BracketLayout(new GridLayout(childrenLayouts, numberOfRows(), numberOfColumns()));
    delete [] childrenLayouts;
    return layout;
  }
  
  int Matrix::writeTextInBuffer(char * buffer, int bufferSize) const {
    buffer[bufferSize-1] = 0;
    int currentChar = 0;
    if (currentChar >= bufferSize) {
      return 0;
    }
    buffer[currentChar++] = '[';
    if (currentChar >= bufferSize) {
      return currentChar;
    }
    for (int i = 0; i < numberOfRows(); i++) {
      buffer[currentChar++] = '[';
      if (currentChar >= bufferSize) {
        return currentChar;
      }
      currentChar += operand(i*numberOfColumns())->writeTextInBuffer(buffer+currentChar, bufferSize-currentChar);
      if (currentChar >= bufferSize) {
        return currentChar;
      }
      for (int j = 1; j < numberOfColumns(); j++) {
        buffer[currentChar++] = ',';
        if (currentChar >= bufferSize) {
          return currentChar;
        }
        currentChar += operand(i*numberOfColumns()+j)->writeTextInBuffer(buffer+currentChar, bufferSize-currentChar);
        if (currentChar >= bufferSize) {
          return currentChar;
        }
      }
      currentChar = strlen(buffer);
      if (currentChar >= bufferSize) {
        return currentChar;
      }
      buffer[currentChar++] = ']';
      if (currentChar >= bufferSize) {
        return currentChar;
      }
    }
    buffer[currentChar++] = ']';
    if (currentChar >= bufferSize) {
      return currentChar;
    }
    buffer[currentChar] = 0;
    return currentChar;
  }
  
  }