-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPoint.m
More file actions
144 lines (140 loc) · 4.06 KB
/
Point.m
File metadata and controls
144 lines (140 loc) · 4.06 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
%% 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
%
% NOTE: We have to account for -0.000!
if nargin == 0
return;
end
coord(coord < eps & coord > -eps) = +0;
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