1## Copyright (C) 2018 Martin Janda <janda.martin1@gmail.com>
2##
3## This program is free software: you can redistribute it and/or modify it
4## under the terms of the GNU General Public License as published by
5## the Free Software Foundation, either version 3 of the License, or
6## (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
11## GNU 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
15## <https://www.gnu.org/licenses/>.
16
17## -*- texinfo -*-
18## @deftypefn {} {@var{rout} =} subsasgn (@var{r}, @var{index}, @var{val})
19##
20## @seealso{}
21## @end deftypefn
22
23function rout = subsasgn (r, index, val)
24  switch (index.type)
25    case "."
26      fld = index.subs;
27      switch (fld)
28        case "ImageSize"
29          imageSize = val;
30
31          if (length (imageSize) < 2)
32            error ("Octave:invalid-input-arg", ...
33            "ImageSize must have at least two elements");
34          endif
35
36          validateattributes (imageSize, {"numeric"}, ...
37          {"positive", "integer", "vector"}, "imref2d", "imageSize");
38
39          m = imageSize(1);
40          n = imageSize(2);
41
42          rout = r;
43          rout.ImageSize = imageSize;
44          rout.PixelExtentInWorldX = r.ImageExtentInWorldX / n;
45          rout.PixelExtentInWorldY = r.ImageExtentInWorldY / m;
46          rout.XIntrinsicLimits = [0.5, n + 0.5];
47          rout.YIntrinsicLimits = [0.5, m + 0.5];
48        case "XWorldLimits"
49          xWorldLimits = val;
50
51          validateattributes (xWorldLimits, {"numeric"}, ...
52          {"increasing", "real", "vector", "size", [1, 2]}, ...
53          "imref2d", "xWorldLimits");
54
55          imageSize = r.ImageSize;
56          imageExtentInWorldX = xWorldLimits(2) - xWorldLimits(1);
57
58          rout = r;
59          rout.XWorldLimits = val;
60          rout.ImageExtentInWorldX = imageExtentInWorldX;
61          rout.PixelExtentInWorldX = imageExtentInWorldX / imageSize(2);
62        case "YWorldLimits"
63          yWorldLimits = val;
64
65          validateattributes (yWorldLimits, {"numeric"}, ...
66          {"increasing", "real", "vector", "size", [1, 2]}, ...
67          "imref2d", "yWorldLimits");
68
69          imageSize = r.ImageSize;
70          imageExtentInWorldY = yWorldLimits(2) - yWorldLimits(1);
71
72          rout = r;
73          rout.YWorldLimits = val;
74          rout.ImageExtentInWorldY = imageExtentInWorldY;
75          rout.PixelExtentInWorldY = imageExtentInWorldY / imageSize(1);
76        otherwise
77          error ("Octave:invalid-indexing", ...
78          "@imref2d/subsasgn: invalid property '%s'", fld);
79      endswitch
80
81    otherwise
82      error ("Octave:invalid-indexing", "@imref2d/subsasgn: invalid index type")
83  endswitch
84endfunction