Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the SVG linter to the repository. #43

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions test/fixtures/demo_map_1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,384 changes: 2,384 additions & 0 deletions tools/Doxyfile

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions tools/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# C++ SECTION

DEBUG_MODE = TRUE

CXX = g++
OUTPUT = svgLinter

BIN_DIR = ./bin
INC_DIR = ./include
OBJ_DIR = ./obj
SRC_DIR = ./src
DAT_DIR = ./data

OBJS = $(OBJ_DIR)/coordinates.o \
$(OBJ_DIR)/edge.o \
$(OBJ_DIR)/logging.o \
$(OBJ_DIR)/main.o \
$(OBJ_DIR)/node.o \
$(OBJ_DIR)/parser.o \
$(OBJ_DIR)/portal.o

INCLUDES += -I$(INC_DIR)

CFLAGS = -Wall -Wextra -ansi -pedantic -std=c++11 $(INCLUDES)

ifdef DEBUG_MODE
CFLAGS += -g
endif

all: directories $(BIN_DIR)/$(OUTPUT)

$(BIN_DIR)/$(OUTPUT): $(OBJS)
$(CXX) $(OBJS) $(CFLAGS) -o $(BIN_DIR)/$(OUTPUT)

$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
$(CXX) -c $(CFLAGS) $< -o $@

# FILES SECTION

.PHONY: directories
directories:
mkdir -p $(OBJ_DIR)
mkdir -p $(BIN_DIR)

.PHONY: clean
clean:
-rm $(OBJ_DIR)/*.o $(BIN_DIR)/$(OUTPUT)
33 changes: 33 additions & 0 deletions tools/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Wayfinding SVG Linter

This application verifies a set of SVGs given to ensure the data is consistent. It is designed for use with the [Wayfinding plugin](https://github.com/ucdavis/wayfinding).

## Building the Project

To build the project, use the provided Makefile, and run

make

Change the compiler if so desired. All external libraries are included.

## Building the Documentation

For more detailed documentation, run Doxygen with the provided Doxyfile using

doxygen

## Flags

The supported flags are:

* `--help` for help information.

* `--floor=FILEID,FILENAME` to specify the data to be used by the linter. This needs to be done for each floor to be parsed.

* `--verbose` to print out more information about what the linter is doing.

* `--threshold` to specify the threshold to be used by the Euclidean distance checker, otherwise a default value of 1 unit will be used.

At a minimum, data and floor IDs *must* be specified using the `--floor` flag, for example

--floor=floor0,data/floor0.svg --floor=floor1,home/data/data1.svg
87 changes: 87 additions & 0 deletions tools/include/coordinates.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/// \file coordinates.hpp This file contains the definition for the Coordinates class.

#ifndef COORDINATES_HPP
#define COORDINATES_HPP

#include "logging.hpp"

#include <iomanip>
#include <math.h>
#include <sstream>

/**
* Represents a coordinate point in a map. It has x, y, and z coordinate points.
* The z coordinate point, a string, corresponds to the floor. These are parsed from the SVGs
* but are expected to align to the flags passed in by the user.
*/
class Coordinates
{
private:
double x;
double y;
std::string z;

public:
/**
* Creates a coordinate point from the given xyz-values.
* \param xValue The x-value of this coordinate.
* \param yValue The y-value of this coordinate.
* \param zValue The z-value of this coordinate.
*/
Coordinates(double xValue, double yValue, std::string zValue);

/**
* Returns a string version of the coordinate point.
* Useful when printing out coordinate points.
* \return The coordinate in string form, i.e. "(x, y, z)".
*/
std::string toString() const;

/**
* Getter function which returns the x-coordinate of this coordinate point.
* \return The x-value of this coordinate.
*/
double getX() const;
/**
* Getter function which returns the y-coordinate of this coordinate point.
* \return The y-value of this coordinate.
*/
double getY() const;

/**
* Getter function which returns the z-coordinate of this coordinate point.
* Note that this is a string, unlike the others.
* \return The z-value of this coordinate.
*/
std::string getZ() const;

/**
* Comparator operator that determines equivalence between two coordinate points.
* \param rhs The other coordinate being compared to.
*/
bool operator==(const Coordinates &rhs) const;
/**
* Comparator operator that determines inequivalence between two coordinate points.
* Defined in terms of the equality operator.
* \param rhs The other coordinate being compared to.
* \return True if the coordinate is not equal to the other, false otherwise.
*/
bool operator!=(const Coordinates &rhs) const;

/**
* Comparator operator that determines whether a coordinate is less than another.
* This operator is only required for STL containers, since they use a comparison function.
* \param rhs The other coordinate being compared to.
* \return True if this coordinate is less than the other, false otherwise.
*/
bool operator<(const Coordinates &rhs) const;

/**
* Returns the distance between two coordinates assuming they're on the same floor.
* \param rhs The other coordinate being compared to.
* \return The distance between the two nodes, or -1 if they're on the same floor.
*/
double distance(Coordinates &rhs);
}; // Coordinates class

#endif
47 changes: 47 additions & 0 deletions tools/include/edge.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/// \file edge.hpp This file contains the definitions for the Edge class.

#ifndef EDGE_HPP
#define EDGE_HPP

#include "node.hpp"

#include <tuple>

// Forward declaration.
class Node;

/**
* Represents a connection between two nodes.
* The SVGs define one line between two points that can be traversed in both directions,
* thus, an undirected graph. This implementation turns the undirected graph into a directed graph.
*
* The adjacency list is held on each Node, so only the destination is defined.
*
* Accessibility is whether or not an edge can be traversed by those with low mobility.
* This only matters for edges created from portals, as all other paths should be traversable.
* See the Portal class for more details.
*/
class Edge
{
private:
Node *edgeTo;
double weight;
bool accessible;

public:
/**
* Instantiate an edge between two nodes.
* \param edgeToValue Pointer to the destination node.
* \param weightValue The weight on this edge.
* \param isAccessible Whether or not this edge is accessible.
*/
Edge(Node *edgeToValue, double weightValue, bool isAccessible);

/**
* Getter function which returns the node to which this edge points.
* \return A pointer to the destination node.
*/
Node* getDestination() const;
}; // Edge class

#endif
22 changes: 22 additions & 0 deletions tools/include/logging.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/// \file logging.hpp This file contains the global logging variables and functions.

#ifndef LOGGING_HPP
#define LOGGING_HPP

#include <iostream>
#include <vector>

// Contains all of the warnings encountered in the parsing.
extern std::vector<std::string> warnings;
// Contains all of the errors encountered in the parsing.
extern std::vector<std::string> errors;

/**
* Print out a summary of the warnings and errors (issues) that were identified.
* If the verbose flag is set, the actual warning and error messages will be printed. Otherwise, a
* quantification of the warnings and errors will be the only information provided.
* \param verbose Whether or not the user wants verbose output.
*/
void printIssues(bool verbose);

#endif
77 changes: 77 additions & 0 deletions tools/include/node.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/// \file node.hpp This file contains definitions for the Node class.

#ifndef NODE_HPP
#define NODE_HPP

#include "coordinates.hpp"

// Forward declaration.
class Edge;

/// Represents a single point on the map. The adjacency list for each node is contained here.
class Node
{
private:
double x;
double y;
std::string floor;
Coordinates coordinates;

std::string room;
bool processed;

// The adjacency list assumes the current node is the starting point, and each Edge is to the destination.
std::vector<Edge*> adjacencyList;

public:
/**
* Initialize a node for some regular point.
* \param coordinateValue The location of this node.
*/
Node(Coordinates coordinateValue);

/**
* Initialize a node for a room in particular.
* \param coordinateValue The location of this node.
* \param roomValue The ID for the room.
*/
Node(Coordinates coordinateValue, std::string roomValue);

/**
* Add an edge to the adjacency list of this node.
* \param newEdge A pointer to the edge to be added.
*/
void addEdge(Edge *newEdge);

/**
* Getter function that returns the coordinates of this node.
* \return The coordinates for this node.
*/
Coordinates getCoordinates() const;

/**
* Getter function that returns an iterator to the beginning of the node's adjacency list.
* \return A const iterator to the beginning of the adjacency list.
*/
std::vector<Edge*>::const_iterator beginAdjacencyIterator() const;

/**
* Getter function that returns an iterator to the end of the node's adjacency list.
* \return A const iterator to the end of the adjacency list.
*/
std::vector<Edge*>::const_iterator endAdjacencyIterator() const;

/**
* Getter function that returns whether or not this node has been processed.
* \return True if this node was processed, false otherwise.
*/
bool isProcessed() const;

/**
* Setter function that sets whether or not this node has been processed.
* \param processValue The new processed state for this node.
*/
void setProcessed(bool processValue);
}; // Node class

#endif
Loading