AutoCAD points are defined as the following array type:
typedef ads_real ads_point[3];
A point always includes three values. If the point is two-dimensional, the third element of the array can be ignored; it is safest to initialize it to 0.
ObjectARX defines the following point values:
#define X 0 #define Y 1 #define Z 2
Unlike simple data types (or point lists in AutoLISP), a point cannot be assigned with a single statement. To assign a pointer, you must copy the individual elements of the array, as shown in the following example:
newpt[X] = oldpt[X]; newpt[Y] = oldpt[Y]; newpt[Z] = oldpt[Z];
You can also copy a point value with the ads_point_set() macro. The result is the second argument to the macro.
The following sample code sets the point to equal to the point from:
ads_point to, from; from[X] = from[Y] = 5.0; from[Z] = 0.0; ads_point_set(from, to);
#include <string.h>
Because of the argument-passing conventions of the C language, points are passed by reference without the address (indirection) operator &. (C always passes array arguments by reference, with a pointer to the first element of the array.)
The acedOsnap() library function takes a point as an argument, and returns a point as a result. It is declared as follows:
int acedOsnap(pt, mode, result) ads_point pt; char *mode; ads_point result;
The acedOsnap() function behaves like the AutoLISP osnap function. It takes a point (pt) and some object snap modes (specified in the string mode), and returns the nearest point (in result). The int value that acedOsnap() returns is a status code that indicates success (RTNORM) or failure.
The following code fragment calls acedOsnap():
int findendpoint(ads_point oldpt, ads_point newpt) { ads_point ptres; int foundpt; foundpt = acedOsnap(oldpt, "end", ptres); if (foundpt == RTNORM) { ads_point_set(ptres, newpt); } return foundpt; }
Because points are arrays, oldpt and ptres are automatically passed to acedOsnap() by reference (that is, as pointers to the first element of each array) rather than by value. The acedOsnap() function returns its result (as opposed to its status) by setting the value of the newpt argument.
ObjectARX defines a pointer to a point when a pointer is needed instead of an array type.
typedef ads_real *ads_pointp;