Skip to content

Commit

Permalink
Merge branch 'feedback-generator'
Browse files Browse the repository at this point in the history
  • Loading branch information
alexhrao committed Dec 19, 2018
2 parents 9400723 + 067ae46 commit ccde58d
Show file tree
Hide file tree
Showing 12 changed files with 961 additions and 579 deletions.
384 changes: 200 additions & 184 deletions Plot.m

Large diffs are not rendered by default.

141 changes: 141 additions & 0 deletions Point.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
%% Point: Contains the Data for a Point on a Plot
%
% stores the coordinate, marker, and color for a point on a plot
%
%%% Fields
%
% * X:
%
% * Y:
%
% * Z:
%
% * Marker:
%
% * Color:
%
%%% Methods
%
% * Point: makes the points. Give it a 1x2 vec or a 1x3 vec. Doesnt matter.
% Give it one input if there is no marker. give it 3 if there is bc color
% matter
%
% * Equals: obviously returns if two points are the same
%
% * dataEquals: does equals but ignores color and marker.
%
%%% Remarks
%
% hey

classdef Point < handle
properties (Access = public)
X;
Y;
Z;
Marker = '';
Color;
end
methods (Access = public)
function this = Point(coord,marker,color)
%% Constructor
%
% creates an instance of Points from a vector containing
% coordinate data, char vec of marker, and char vec of color
%
%%% Remarks
% makes the points. Give it a 1x2 vec or a 1x3 vec. Doesnt
% matter. Give it one input if there is no marker. give it 3 if
% there is bc color matter
if nargin == 0
return;
end
this.X = coord(1);
this.Y = coord(2);
if length(coord) == 3
this.Z = coord(3);
else
this.Z = 0;
end
if nargin > 1
this.Marker = marker;
this.Color = color;
else
this.Marker = '';
this.Color = [0 0 0];
end
end
function areEqual = equals(this,that)
%% Equals: does the equals thing
% you know this
if isempty(this)
areEqual = [];
return;
elseif isempty(that)
areEqual = false;
return;
end
orig = this;
this = reshape(this, 1, []);
that = reshape(that, 1, []);
if isscalar(that)
tmp(numel(this)) = that;
tmp(:) = that;
that = tmp;
tmp = tmp(false);
end
if isscalar(this)
tmp(numel(that)) = this;
tmp(:) = this;
this = tmp;
end
areEqual = this.dataEquals(that) ...
& strcmp({this.Marker},{that.Marker}) ...
& cellfun(@isequal, {this.Color}, {that.Color});
if isscalar(orig)
areEqual = reshape(areEqual, size(that));
else
areEqual = reshape(areEqual, size(orig));
end
end
function tf = ne(this, that)
tf = ~this.equals(that);
end
function tf = eq(this, that)
tf = this.equals(that);
end
function areEqual = dataEquals(this,that)
%% dataEquals: does the equals thing
% you know this too
areEqual = [this.X] == [that.X] ...
& [this.Y] == [that.Y] ...
& [this.Z] == [that.Z];
areEqual = reshape(areEqual, size(this));
end

function [sorted, inds] = sort(points, varargin)
if isempty(points)
sorted = points;
inds = [];
return;
elseif isscalar(points)
sorted = points;
inds = 1;
return;
end
xx = reshape([points.X], [], 1);
yy = reshape([points.Y], [], 1);
zz = reshape([points.Z], [], 1);
colors = vertcat(points.Color);
markers = reshape(string({points.Marker}), [], 1);
tmp = compose('%0.5f %0.5f %0.5f %d %d %d %s', ...
[xx, yy, zz], ...
colors, ...
markers);
[~, inds] = sort(tmp, varargin{:});
sorted = points(inds);
end


end
end
150 changes: 150 additions & 0 deletions Segment.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
%% Segment: A single connection between two points
%
% A single connection between two points without marker!
%
%%% Fields
%
% * Start: A Point that represents where this segment starts
%
% * Stop: A Point that represents where this segment ends
%
% * Color: A 1x3 vector that represents the color
%
% * Style: A character vector that represents the style (i.e., dashed.
% etc.)
%
%%% Methods
%
% * Segment
%
% * equals
%
% * dataEquals
%
%%% Remarks
%
% This class keeps data for a single segment - a connection. It does not
% care about what the endpoints look like - only where they are.
%
% The Point will not have a style - just coordinates
%
classdef Segment < handle
properties (Access = public)
Start;
Stop;
Color double;
Style char;
end

methods
%% Constructor
%
% Segment(S, E, C, L) will use start S and stop E to make a
% segment, with color C and line style L.
%
%%% Remarks
%
% S and E can be Points or coordinates - if the latter, they will
% be constructed into points
function this = Segment(start, stop, color, style)
if nargin == 0
return;
end
if isa(start, 'Point')
this.Start = start;
this.Stop = stop;
else
this.Start = Point(start);
this.Stop = Point(stop);
end
pts = sort([this.Start, this.Stop]);
this.Start = pts(1);
this.Stop = pts(2);
this.Color = color;
if strcmp(style, 'none')
this.Style = '';
else
this.Style = style;
end
end
end
methods (Access = public)
function tf = equals(this, that)
if isempty(this)
tf = [];
return;
elseif isempty(that)
tf = false;
return;
end
orig = this;
this = reshape(this, 1, []);
that = reshape(that, 1, []);
if isscalar(that)
tmp(numel(this)) = that;
tmp(:) = that;
that = tmp;
tmp = tmp(false);
end
if isscalar(this)
tmp(numel(that)) = this;
tmp(:) = this;
this = tmp;

end
tf = this.dataEquals(that) ...
& cellfun(@isequal, {this.Color}, {that.Color}) ...
& strcmp({this.Style}, {that.Style});
if isscalar(orig)
tf = reshape(tf, size(that));
else
tf = reshape(tf, size(orig));
end
end

function tf = eq(this, that)
tf = this.equals(that);
end

function tf = ne(this, that)
tf = ~this.equals(that);
end

function tf = dataEquals(this, that)
if isempty(this) || isempty(that)
tf = [];
else
tf = dataEquals([this.Start], [that.Start]) ...
& dataEquals([this.Stop], [that.Stop]);
tf = reshape(tf, size(this));
end
end

function [sorted, inds] = sort(segments, varargin)
if isempty(segments)
sorted = segments;
inds = [];
return;
elseif isscalar(segments)
sorted = segments;
inds = 1;
return;
end
% sort by Point start -> stop
starts = [segments.Start];
xx1 = reshape([starts.X], [], 1);
yy1 = reshape([starts.Y], [], 1);
zz1 = reshape([starts.Z], [], 1);
stops = [segments.Stop];
xx2 = reshape([stops.X], [], 1);
yy2 = reshape([stops.Y], [], 1);
zz2 = reshape([stops.Z], [], 1);
styles = reshape(string({segments.Style}), [], 1);
tmp = compose('%0.5f %0.5f %0.5f %0.5f %0.5f %0.5f %s', ...
[xx1, yy1, zz1, xx2, yy2, zz2], styles);
[~, inds] = sort(tmp, varargin{:});
sorted = segments(inds);
sorted = reshape(sorted, size(segments));
end
end
end
2 changes: 2 additions & 0 deletions build.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
delete(['.' filesep 'release' filesep '*']);
% pcode Plot
pcode('Plot.m');
pcode('Segment.m');
pcode('Point.m');
pcode('checkPlots.m');
movefile('*.p', ['.' filesep 'release']);

Expand Down
Loading

0 comments on commit ccde58d

Please sign in to comment.