wxMaxima
Loading...
Searching...
No Matches
MatrixBlock.h
1// -*- mode: c++; c-file-style: "linux"; c-basic-offset: 2; indent-tabs-mode: nil -*-
2//
3// Copyright (C) 2026 Gunter Königsmann <wxMaxima@physikbuch.de>
4//
5// This program is free software; you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation; either version 2 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15//
16// You should have received a copy of the GNU General Public License
17// along with this program; if not, write to the Free Software
18// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19//
20// SPDX-License-Identifier: GPL-2.0+
21
22#ifndef MATRIXBLOCK_H
23#define MATRIXBLOCK_H
24
25#include <algorithm>
26#include <cstddef>
27
30{
31 std::size_t row = 0;
32 std::size_t col = 0;
33 bool operator==(const MatrixEntry &) const = default;
34};
35
47{
48 std::size_t firstRow = 0;
49 std::size_t lastRow = 0;
50 std::size_t firstCol = 0;
51 std::size_t lastCol = 0;
52
53 std::size_t Rows() const { return lastRow - firstRow + 1; }
54 std::size_t Columns() const { return lastCol - firstCol + 1; }
55 bool Contains(std::size_t row, std::size_t col) const {
56 return (row >= firstRow) && (row <= lastRow) &&
57 (col >= firstCol) && (col <= lastCol);
58 }
59 bool operator==(const MatrixBlock &) const = default;
60
62 static MatrixBlock Spanning(const MatrixEntry &a, const MatrixEntry &b) {
63 return MatrixBlock{std::min(a.row, b.row), std::max(a.row, b.row),
64 std::min(a.col, b.col), std::max(a.col, b.col)};
65 }
66};
67
68#endif // MATRIXBLOCK_H
A rectangular block of a matrix's entries: a sub-matrix (GH #2345)
Definition: MatrixBlock.h:47
static MatrixBlock Spanning(const MatrixEntry &a, const MatrixEntry &b)
The smallest block holding both entries: the rectangle they are corners of.
Definition: MatrixBlock.h:62
One entry of a matrix, by its zero-based row and column.
Definition: MatrixBlock.h:30