## `plot::Point` -- graphical primitive for a point

#### Introduction

`plot::Point``(x, y)` represents a plot of a two-dimensional point with the coordinates (x; y).

`plot::Point``(x, y, z)` represents a plot of a three-dimensional point with the coordinates (x; y; z).

#### Creating Elements

`plot::Point(x, y <, option1, option2...>)`
`plot::Point(x, y, z <, option1, option2...>)`

#### Parameters

`x, y, z` | - | arithmetical expressions
`option1, option2, ...` | - | plot option(s) of the form `OptionName = value`

#### Related Domains

`DOM_POINT`, `plot::Pointlist`, `plot::Scene`, `RGB`

#### Related Functions

`plot`, `plot2d`, `plot3d`, `plot::copy`, `point`

#### Details

- Objects generated by `plot::Point` represent graphical primitives for two- or three-dimensional points that can be displayed via the call `plot(...)`, or used with other graphical primitives of the `plot` library.
- Note that `plot::Point`, in difference to the standard graphical primitive `point`, allows arbitrary arithmetical expressions. These expressions must evaluate to numbers at the time where you plot the points.
- An object of `plot::Point` has type `"graphprim"`, i.e., if `o` is such an object, then the result of `type(o)` is the string `"graphprim"`.
- Options `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]` | `[Height]`
  LineStyle | SolidLines, DashedLines | SolidLines
  LineWidth | positive integers | `1`
  PointStyle | Circles, FilledCircles, FilledSquares, Squares | FilledSquares
  PointWidth | positive integers | `30`
  Title | strings |
  TitlePosition | `[x, y]` |

  See `plot2d` and `plot3d`, respectively, 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.

- A so-called attribute of a graphical primitive is a named entry of the object which can be accessed via the slot operator `::`.

  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 point primitive:

  attribute | meaning | properties
  `coords` | The list of the coordinates of the point (list of two or three arithmetical expressions). The initial value is the list `[x, y]` and `x, y, z]`, respectively. | read/write
  `options` | A table of plot options of the point 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 point primitives. Invalid entries lead to runtime errors. The initial value of this attribute is the table stored under the domain entry `"defaultOptions"`, where such options are replaced and added, respectively, which are given with the parameters `option1`, `option2`... of the creating call. | read/write
  `plotdata` | List of the plot data of the point 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 point primitive must be (re-)build with the method `"getPlotdata"` (see below). If its value is `FALSE`, then the plot data of the point primitive is stored in the attribute `plotdata`. The initial value is `TRUE`. | read/write

  See the help page of `plot::Curve2d` for examples for working with attributes of graphical primitives.

#### Operands

An object of `plot::Point` has either two or three operands, namely the coordinates `x`, `y` and `z`, respectively.

#### Important Operations

Operands of a point primitive can be accessed either using the system function `op`, the index operator `[ ]`, or using the attribute `coords` described above. For example, if `point` is such an object, then the calls `op(point,1)`, `point[1]` and `point::coords[1]` return the first coordinate of `point`.

Via `point[1] := x_new` or `point::coords[1] := x_new`, the first coordinate of `point` is replaced by `x_new`.

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 `point` is such an object, then `point::Color := RGB::Red` changes the color of the point to red.

#### Result of Evaluation

Evaluating an object of type `plot::Point` returns itself.

#### Function Call

Calling an object of `plot::Point` as a function yields the object itself, regardless of the arguments. The arguments are not evaluated.

#### Entries

defaultOptions

  is a table of plot options for point primitives and their default values. Each entry has the form `OptionName = default_value`.

  When an object of the domain `plot::Point` 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 the table stored under the attribute `options` will not be included in the plot data of the object created by the method `"getPlotdata"` (see below).

  For those options, the corresponding default value either is set by a graphical scene, if the option also exists as a scene option (such as the option PointWidth), or it is internally set by the function `plot2d` and `plot3d`, respectively, which are used to plot the object. See the table of plot options above, which gives a summary of the available plot options for point primitives and their default values.

  To change the default value of some plot options, the option name and its default value may be added to the table `"defaultOptions"`, or replaced by a new value, respectively.

optionNames

  is a set of the available option names for plots of points.

#### Method _index: indexed access to the operands of a point primitive

- `_index(dom point, positive integer i)`
- - Returns the `i`th coordinate of `point`. If `i` is greater than the number of coordinates of `point`, then `FAIL` is returned.
  - This method overloads the system function `_index`, i.e., one may use it in the form `point[i]`, or in functional notation `_index(point, i)`.

#### Method dimension: dimension of a point primitive

- `dimension(dom point)`
- - Returns the number of coordinates of `point`.

#### Method getPlotdata: create the plot data of a point primitive

- `getPlotdata(dom point)`
- - Returns a list of an inner list, where the inner list is a plot description of `point` in a `plot2d` and `plot3d` conforming syntax, respectively, i.e., it has the form `[Mode = List, [point(...)], ...]`.

    For example, with `s := plot::Point::getPlotdata(point)` the call `plot2d(s[1])` and `plot3d(s[1])`, respectively, gives a plot of `point`.

  - Only those plot options will be included in the plot data of the point, that are contained in the table stored under the attribute `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` and `plot3d`, respectively, for lists of primitives is used when plotting the object.
  - The result is stored as the value of the attribute `plotdata` of `point`.
  - A call of this method sets the value of the attribute `refreshPlotdata` of `point` to `FALSE`.
  - This method is called from `plot::Scene` to build the plot data of the graphical scene.

#### Method nops: number of operands of a point primitive

- `nops(dom point)`
- - Returns the number of coordinates of `point`, i.e., the integer 2 or 3.
  - This method overloads the system function `nops`, i.e., onemay use it in the form `nops(point)`.

#### Method op: extract operands of a point primitive

- `op(dom point, positive integer i)`
- - Returns the `i`th coordinate of `point`. If `i` is greater than the number of coordinates of `point`, then `FAIL` is returned.
  - This method overloads the system function `op`, i.e., one may use it in the form `op(point, i)`.

#### Method set_index: set operands of a point primitive

- `set_index(dom point, positive integer i, arithm. expr. x)`
- - Replaces the `i`th coordinate of `point` to the value `x`.
  - If `i` is greater than the number of coordinates of `point`, or if `x` is not an arithmetical expression, then a warning message is issued. In this case the call of this method has no effect on the object `point`.
  - A call of this method sets the value of the attribute `refreshPlotdata` of `point` to `TRUE`.

#### Method slot: read and write attributes and plot options

- `slot(dom point, string slotname)`
- - Reads the value of the slot `slotname` of `point`. `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.
  - If `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.

  - This method overloads the system function `slot`, i.e., one may use it in the form `point::slotname_id` (here, `slotname_id` must be the identifier corresponding to the string `slotname`), or in functional notation `slot(point, slotname)`.
- `slot(dom point, string slotname, any val)`
- - Changes the value of the attribute or option with the name `slotname` to the value `val`.
  - If there is no attribute or option with the name `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.
  - This method overloads the system function `slot`, i.e., one may use it in the form `point::slotname_id := val` (here, `slotname_id` must be the identifier corresponding to the string `slotname`), or in functional notation `slot(point, slotname, val)`.
  - The value of the attribute `refreshPlotdata` of `point` is set to `TRUE`.

#### Method convert: conversion of objects into a point primitive

- `convert(any p)`
- - This method tries to convert `p` into an object of the domain `plot::Point`. If this is not possible, then `FAIL` is returned.
  - Currently this method handles objects of the following two domain types:
    - `p` is an object of the domain `DOM_POINT`. If `p` does not have a color specification, then the default color for objects of `plot::Point` is used (see ``Details'' above).
    - `p` is a list of two or three arithmetical expressions.

#### Method convert_to: conversion of a point primitive

- `convert_to(dom point, domain T)`
- - This method tries to convert `point` into an object of the domain `T`. If this is not possible, then `FAIL` is returned.
  - Currently this method handles the following domains:
    - `T` is the domain `DOM_LIST`. Then the result is a list of the coordinates of `point`.
    - `T` is the domain `DOM_POINT`. Then the result is a system point primitive, i.e., an object of the domain type `DOM_POINT`.

      Note that plot options can not be stored in such an object, except of the option Color. However, the color specification is used only if it is contained in the attribute `options` of the point primitive `point` (see the table of attributes above). Otherwise the default color specification for system point primitives is used (see the help page of `DOM_POINT`).

#### Method expr: conversion into a system point primitive

- `expr(dom point)`
- - This method converts `point` into an object of the domain type `DOM_POINT`. See the method `"convert_to"` above for details.

#### Method checkOption: check a plot option

- `checkOption(equation OptionName = value)`
- - This method checks whether `OptionName` is a known plot option for point primitives (see the table of available plot options above), and `value` is an admissible value for this option.
  - If both is correct, then the list `[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`.
  - Otherwise, the list `[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.

#### Method copy: create a copy of a point primitive

- `copy(dom point)`
- - Returns a copy of the object `point`.
  - This method is called from the function `plot::copy`. See its help page for details.

#### Method modify: modify a copy of a point primitive

- `modify(dom point, equation(s) Name1 = value1...)`
- - Creates a copy of the object `point` and changes the slots `Name1`... of this copy to the new values `value1`...
  - The identifiers `Name1`... must be names of attributes or plot options of the domain `plot::Point`. 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.

  - A call of this method sets the value of the attribute `refreshPlotdata` of the copy of `point` to `TRUE`.
  - This method is called from the function `plot::modify`.

#### Method print: print a point primitive

- `print(dom point)`
- - This method returns an unevaluated expression of the form `plot::Point([x, y]` and `plot::Point([x, y, z]`, respectively. It is used to print objects of `plot::Point` to the screen.
  - See the system function `print` for details.

#### Example 1

We create the points (1; 2) and (3; -1), setting the color of the second point to green and its size to 50:

    >> p1 := plot::Point([1, 2]);
       p2 := plot::Point([3, 1], Color = RGB::Blue, PointWidth = 50)

                                 plot::Point(1, 2)

                                 plot::Point(3, 1)

To plot these two points in a graphical scene, enter:

    >> plot(p1, p2)

Scene options may be given to the call of `plot`, such as changing the style of the axes and drawing grid lines in the background of the plot:

    >> plot(p1, p2, Axes = Box, GridLines = Automatic)

#### Example 2

Objects of the domain `plot::Point`, and objects of the basic domain `DOM_POINT` are graphical primitives for two- or three dimensional points. The main difference between objects of these two domains is, that objects of `plot::Point` can be used together with other graphical primitives of the library `plot` such as function graphs, surface plots, point-list plots, and more.

To ease the use of such different objects, you can easily convert objects of one domain into the other. For example, an object of the domain `plot::Point` such as:

    >> p := plot::Point([1, 2])

                                 plot::Point(1, 2)

can be converted into the domain `DOM_POINT` as follows:

    >> plot::Point::convert_to(p, DOM_POINT)

                                  point(1.0, 2.0)

Note that because objects of the domain `DOM_POINT` only know the plot option Color, any other plot option set for the object `p` is lost by this conversion.

With the method `"convert"`, objects can be converted into the domain `plot::Point`. For example, we convert the list `[1, 2, 3]` into the point (1; 2; 3) as an object of the domain `plot::Point`:

    >> l := [1, 2, 3]: p:= plot::Point::convert(l)

                               plot::Point(1, 2, 3)

One may now override default values of some plot options for the object `p` as follows:

    >> p::Color := RGB::Blue: p::PointWidth := 50:
       plot(p, Axes = None)

#### Changes

- new function

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000