plot::Rectangle2d
--
graphical primitive for a two-dimensional rectangleplot::Rectangle2d
(p, w, h)
represents a
plot of a two-dimensional rectangle with lower left corner p =
(px; py), width w and height h.
plot::Rectangle2d(c, w, h <, option1,
option2...>)
plot::Rectangle2d(p, w, h <, option1,
option2...>)
c |
- | a list of two arithmetical expressions |
p |
- | a two-dimensional point, i.e., an object of the domain
plot::Point or DOM_POINT |
w, h |
- | arithmetical expressions |
option1, option2, ... |
- | plot option(s) of the form OptionName =
value |
plot::Ellipse2d
,
plot::Point
, plot::Polygon
, plot::Scene
, RGB
plot
, plot2d
, plot::copy
, plot::line
plot::Rectangle2d
represent
graphical primitives for two-dimensional rectangles that can be
displayed via the clal plot(...)
, or used with other
graphical primitives of the plot
library. See example 1.plot::Rectangle2d
is a point p
, then it is
converted into a list of the two coordinates of p
.
Specified plot options for p
are ignored! (Cf.
example 2.)w
and height h
can also be negative numbers. The rectangle drawn consists of the four
points p = (px; py), (px; py + h), (px + w;
py + h) and (px + w; py).plot::Rectangle2d
has type
"graphprim"
, i.e., if o
is such an object,
then the result of type(o)
is the string
"graphprim"
.option1
, option2
... are specified
by equations OptionName = value
. The following table gives
an overview of the available options:
OptionName |
admissible values | default value |
Color | [Flat] , [Flat, [r,g,b]] , [Height] , [Height, [r,g,b], [R,G,B]] , [Function, f] |
[Flat, RGB::Red]
|
Filled | TRUE , FALSE |
FALSE |
LineStyle | SolidLines, DashedLines | SolidLines |
LineWidth | positive integers | 1 |
PointStyle | Circles, FilledCircles, FilledSquares, Squares | FilledSquares |
PointWidth | positive integers | 30 |
Title | strings | |
TitlePosition | [x, y] |
|
plot2d
and polygon
for further details on
each option.Scene options for the parameters
option1
, option2
... are not allowed! One may
pass scene options to the call of plot
, or use plot::Scene
to create an object
representing a graphical scene. Cf. example 1.
::
.
Each attribute has the property ``read'', i.e., the value of an
attribute attr
of a graphical primitive o
can
be read with o::attr
. If the attribute also has the
``write'' property, then the value of the attribute can be changed with
o::attr := new_value
.
The following attributes are available for a rectangle primitive:
attribute | meaning | properties |
corner |
a list of two arithmetical expressions being the lower
left corner of the rectangle. The initial value is the parameter
c , or the list of the coordinates of p ,
respectively. |
read/write |
dimension |
The dimension of the rectangle primitive, i.e., the integer 2. | read |
height |
The height of the rectangle (an arithmetical
expression). The initial value is the parameter h . |
read/write |
options |
A table of plot options of the rectangle primitive.
Note that if you change the value of this attribute, the entries of the
assigned table are not checked to be valid plot options for rectangle
primitives. Invalid entries lead to runtime errors.
The initial value of this attribute is the table stored under the
domain entry |
read/write |
plotdata |
List of the plot data of the rectangle primitive in a
plot2d and plot3d conforming syntax,
respectively (see the method "getPlotdata" below). Note
that the value of this attribute should only be used if the attribute
refreshPlotdata has the value FALSE (see
below). |
read |
refreshPlotdata |
A boolean value which signals whether the plot data of
the rectangle primitive must be (re-)build with the method
"getPlotdata" (see below). If its value is
FALSE , then the plot data of the rectangle primitive is
stored in the attribute plotdata . The initial value is
TRUE . |
read/write |
width |
The width of the rectangle (an arithmetical
expression). The initial value is the parameter w . |
read/write |
An object of plot::Rectangle2d
consists of the three
operands c
, w
and h
.
Operands of a rectangle primitive can be accessed either using the
system function op
, the
index operator [ ]
, or
using the attributes corner
, height
and width
described above. For example, if
rectangle
is such an object, then the calls
op(rectangle,1)
, rectangle[1]
and
rectangle::corner
return the list representing the lower
left corner of rectangle
.
Via rectangle[1] := new_point
or
rectangle::corner := new_point
, the lower left corner of
rectangle
is replaced by the list
new_point
.
See the methods "op"
, "_index"
,
"set_index"
and "slot"
below.
Use the slot operator ::
to get or set plot options of
such objects afterwards, i.e., when they have been created. For
example, if rectangle
is such an object, then
rectangle::Color := RGB::Red
changes the color of of
rectangle
to red.
Evaluating an object of type plot::Rectangle2d
returns
itself.
Calling an object of plot::Rectangle2d
as a function
yields the object itself, regardless of the arguments. The arguments
are not evaluated.
is a table of plot options for rectangle primitives and their
default values. Each entry has the form OptionName =
default
.
When an object of the domain plot::Rectangle2d
is
created, then a copy of this table is stored under the attribute
options
(see the table of attributes above), where those
options are added and replaced, respectively, which are given by the
(optional) parameters option1
, option2
... of
the creating call (see ``Creating Elements'' above).
Plot options, which are not contained in this table, will not be
included in the plot data of the object created by the method
"getPlotdata"
(see below).
is a set of the available options for plots of two-dimensional rectangles.
_index(dom rectangle, positive integer i)
i
th operand of rectangle
. See
``Operands'' above for a description of the operands of
curve
. If i
is greater
than 2, then FAIL
is returned._index
, i.e., one may use it in the
form rectangle[i]
, or in functional notation
_index(rectangle, i)
.dimension(dom rectangle)
getPlotdata(dom rectangle)
rectangle
in a plot2d
conforming syntax, i.e., it
has the form [Mode = List, [polygon(...)], ...]
.
For example, with s :=
plot::Rectangle2d::getPlotdata(rectangle)
the call
plot2d(s[1])
gives a plot of rectangle
.
options
(see the table of attributes above). For any other
plot option not contained in this table, the corresponding default
value set by the function plot2d
for curves is used when
plotting the object.plotdata
of rectangle
.refreshPlotdata
of rectangle
to
FALSE
.plot::Scene
to build the plot data of
the graphical scene.nops(dom rectangle)
nops
, i.e., one may use it in the form
nops(rectangle)
.op(dom rectangle, positive integer i)
i
th operand of rectangle
. See
``Operands'' above for a description of the operands of
rectangle
. If i
is greater
than 3, then FAIL
is returned.op
, i.e., one may use it in the form
op(rectangle, i)
.set_index(dom rectangle, positive integer i, any val)
i
th operand of rectangle
by
the value val
. See ``Operands'' above for a description of
the operands of rectangle
.i
is greater than 3, or if
val
is not an admissible value for the i
th
operand, then a warning message is issued. In this case the call of
this method has no effect on the object rectangle
.refreshPlotdata
of rectangle
to
TRUE
.slot(dom rectangle, string slotname)
slotname
of
rectangle
. slotname
may either be the name of
an attribute or the name of a plot option. See the tables of available
plot options and attributes above.slotname
is the name of a plot option, but the
option is not contained in the table stored under the attribute
options
, then FAIL
is returned.
If slotname
is an invalid attribute or option, then an
error message is issued.
slot
, i.e., one may use it in the form
rectangle::slotname_id
(here, slotname_id
must be the identifier corresponding to the string
slotname
), or in functional notation slot(rectangle,
slotname)
.slot(dom rectangle, string slotname, any val)
slotname
to the value val
.slotname
, or if val
is not an admissible
value for slotname
, then a warning message is issued. In
this case, the value of slotname
remains unchanged.slot
, i.e., one may use it in the form
rectangle::slotname_id := val
(here,
slotname_id
must be the identifier corresponding to the
string slotname
), or in functional notation
slot(rectangle, slotname, val)
.refreshPlotdata
of
rectangle
is set to TRUE
.checkOption(equation OptionName =
value)
OptionName
is a known plot
option for rectangle primitives (see the table of available plot
options above), and value
is an admissible value for this
option.[TRUE, OptionName,
newValue]
is returned. Note that the value of the option could
have been converted into an admissible format. Thus,
newValue
must be used as the value of the option
OptionName
instead of value
.[FALSE, error_msg]
is returned.
The string error_msg
is a description of the located
problem, which can be passed, for example, to the system function
error
to raise a
user-specified exception.copy(dom rectangle)
rectangle
.plot::copy
. See its help page for
details.modify(dom rectangle, equation(s) Name1 = value1...)
rectangle
and changes the
slots Name1
... of this copy to the new values
value1
...Name1
... must be names of attributes
or plot options of the domain plot::Rectangle2d
. Otherwise
a warning message is issued, and the slot remains unchanged. Also, if
one of the values value1
... is not an admissible value for
the corresponding attribute or plot option, respectively, the change of
the slot is ignored.
See the tables of available options and attributes above.
refreshPlotdata
of the copy of rectangle
to
TRUE
.plot::modify
.print(dom rectangle)
plot::Rectangle2d(p, w, h)
. It is used to print objects of
plot::Rectangle2d
to the screen.print
for details.We define a rectangle with lower left corner at point (1;2), width 3 and height 4, and a square of length one with lower left corner at the point (0;0):
>> r := plot::Rectangle2d([1, 2], 3, 4); s := plot::Rectangle2d([0, 0], 1, 1, Filled = TRUE)
plot::Rectangle2d([1, 2], 3, 4) plot::Rectangle2d([0, 0], 1, 1)
The area of the square is filled in the color of the border of the rectangle (which is red by default). We plot these two objects in a graphical scene, without showing axes:
>> plot(r, s, Axes = None)
The attribute corner
, which specifies the
lower left point of the rectangle, is a list of two arithmetical
expressions also if the corner point of the object created was given as
an object of the domain plot::Point
or DOM_POINT
:
>> c := plot::Point([-1, 1]): r := plot::Rectangle2d(c, 2, -2): r::corner
[-1, 1]
If you replace the value of the attribute
corner
, then the point must be given as a list of two
arithmetical expressions, otherwise a warning message is issued, saying
that the assignment is ignored:
>> r::corner:= point(0, 0)
Warning: 3rd argument: expecting a list of two arithmetical ex\ pressions; assignment ignored [plot::Rectangle2d::slot] point(0, 0)
>> r::corner
[-1, 1]
Note that if you specify an object of the domain
plot::Point
or DOM_POINT
as the corner of
the rectangle, then plot options of the point are ignored. For example,
if we change the color of the point c
created above to
blue and create a new rectangle:
>> c::Color := RGB::Blue: r := plot::Rectangle2d(c, 1, 1): plot(r)
then the rectangle is still drawn in red color (the
default color of objects of the domain plot::Rectangle2d
).
You must use the color option of the object r
to change
the color of the rectangle:
>> r::Color := RGB::Blue: plot(r)
See the help page of plot::Curve2d
for more examples for
working with attributes of graphical primitives.