rs_graph/steinlib/
mod.rs

1// Copyright (c) 2016-2021 Frank Fischer <frank-fischer@shadow-soft.de>
2//
3// This program is free software: you can redistribute it and/or
4// modify it under the terms of the GNU General Public License as
5// published by the Free Software Foundation, either version 3 of the
6// License, or (at your option) any later version.
7//
8// This program is distributed in the hope that it will be useful, but
9// WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11// General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with this program.  If not, see  <http://www.gnu.org/licenses/>
15//
16
17//! Reading files in `SteinLib` format.
18//!
19//! This reader supports the following extensions to the `SteinLib` format:
20//!
21//! 1. Additional drawing attributes section
22//!
23//!   ```ignore
24//!   SECTION Drawing
25//!   A <u> <v> <attribute>...
26//!   E <u> <v> <attribute>...
27//!   END
28//!   ```
29//!
30//!   This is a list of drawing attributes for each edge. Possible
31//!   attributes are
32//!   - `bl` the arc should be bend to the left
33//!   - `br` the arc should be bend to the right
34
35use crate::IndexGraph;
36
37use std::result;
38
39mod parser;
40pub use self::parser::{read, SteinlibError as Error};
41
42/// Type of values with optional error code.
43pub type Result<T> = result::Result<T, Error>;
44
45/// Edge drawing attributes.
46#[derive(Debug, Clone, Copy, PartialEq)]
47pub enum EdgeAttr {
48    /// Arc should be bend to the left.
49    BendLeft,
50    /// Arc should be bend to the right.
51    BendRight,
52}
53
54/// An SteinLib instance.
55pub struct Instance<G>
56where
57    G: IndexGraph,
58{
59    /// The graph.
60    pub graph: G,
61    /// The edge weights.
62    pub weights: Vec<f64>,
63    /// The node coordinates.
64    pub coordinates: Vec<Vec<f64>>,
65    /// The edge attributes.
66    pub edgeattrs: Vec<Vec<EdgeAttr>>,
67}