Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revisionBoth sides next revision | ||
metapost [2019/06/02 05:44] – [Symbol Sizing and Positioning] brucemutton | metapost [2019/06/02 23:11] – [Symbol Sizing and Positioning] clarify symbol parameter indicator brucemutton | ||
---|---|---|---|
Line 101: | Line 101: | ||
* Your symbols should generally be defined so that they fit within the size range -0.5u to +0.5u in both x and y axes, although you can use larger or smaller values in either dimension. | * Your symbols should generally be defined so that they fit within the size range -0.5u to +0.5u in both x and y axes, although you can use larger or smaller values in either dimension. | ||
- | This image is a symbol that has been defined with maximum x and y coordinates of 0.7u, both positive and negative. | + | This image is a symbol that has been defined with maximum x and y coordinates, supposedly, |
{{: | {{: | ||
Line 107: | Line 107: | ||
- | In addition, the symbol alignment option relies on the definition of a U: variable, otherwise your symbol will cause an error and stop Therion if a user sets an alignment option other than '' | + | The symbol alignment option relies on the definition of a U: variable, otherwise your symbol will cause an error and stop Therion if a user sets an alignment option other than '' |
* U: is a scaling factor for alignment parameters, such as right, top or top-right. | * U: is a scaling factor for alignment parameters, such as right, top or top-right. | ||
U: defines the size of the x horizontal (left-right) and y vertical (up-down) offset when a symbol is aligned, so the x and y components of U: should be set to be around the maximum absolute value of x and y symbol coordinates, | U: defines the size of the x horizontal (left-right) and y vertical (up-down) offset when a symbol is aligned, so the x and y components of U: should be set to be around the maximum absolute value of x and y symbol coordinates, | ||
Line 115: | Line 115: | ||
* If your symbol has its greatest dimension on a diagonal, then you should increase the U: components accordingly, | * If your symbol has its greatest dimension on a diagonal, then you should increase the U: components accordingly, | ||
- | As one 'use case' for aligning symbols is to enable them to be placed ‘near’ to another symbol, and be always positioned appropriately at a variety of output scales, I am going to suggest that U: components for user friendly point symbols should always be just a little greater than half the symbol dimension. | + | As one 'use case' for aligning symbols is to enable them to be placed ‘near’ to another symbol, and be always positioned appropriately at a variety of output scales, I am going to suggest that U: components for user friendly point symbols should always be just a little greater than half the symbol dimension. ie the light blue box should enclose the symbol. That way, an aligned symbol can always leave a pleasing small gap from its insertion point. |
- | When writing a new point symbol and testing that it aligns and rotates nicely, it can be a bit tricky to figure out where the origin, insertion point, and alignment loci are located. | + | When writing a new point symbol and testing that it aligns and rotates nicely, it can be a bit tricky to figure out where the origin, insertion point, and alignment loci are located. |
- | Here it is inserted into an electric light symbol. | + | Here it is inserted into an electric light symbol |
+ | |||
+ | After writing the code, I realised that this symbol was in fact larger than 0.7u in the y direction, the symbol is not centered around around its (0u,0u) coordinates and it is just a bit (but probably acceptably) larger than u in size! | ||
< | < | ||
Line 128: | Line 130: | ||
T:=identity rotated theta aligned al scaled defaultscale shifted pos; %corrected to rotate THEN align | T:=identity rotated theta aligned al scaled defaultscale shifted pos; %corrected to rotate THEN align | ||
| | ||
- | % % % SYMBOL PARAMETER INDICATOR (origin, insertion, alignment | + | % % % SYMBOL PARAMETER INDICATOR (origin, insertion, alignment |
- | | + | % Placing this code directly after T:= identity line will put the indicators under the symbol |
+ | % Placing this code immediately | ||
+ | % Before | ||
rotation:= theta; | rotation:= theta; | ||
pair alignment; alignment:= al; %set this to the last parsed variable (ie al) | pair alignment; alignment:= al; %set this to the last parsed variable (ie al) | ||
- | | + | |
- | thdraw fullcircle shifted -(xpart alignment * xpart U, ypart alignment * ypart U) rotated -rotation withpen PenD withcolor green; | + | % show symbol origin, (0,0) red |
- | | + | |
- | | + | |
+ | thdraw fullcircle shifted -(xpart alignment * xpart U, ypart alignment * ypart U) rotated -rotation withpen PenD withcolor green; | ||
+ | | ||
+ | q:= (xpart U, -ypart U) -- (xpart U, ypart U) -- (-xpart U, ypart U) -- (-xpart U, -ypart U) -- cycle; | ||
+ | thdraw q shifted -(xpart alignment * xpart U, ypart alignment * ypart U) rotated -rotation withpen PenD withcolor 0.5blue+0.5white; | ||
+ | | ||
+ | thdraw unitsquare scaled u shifted (-0.5u, -0.5u) withpen PenD withcolor 0.1black+0.5white; | ||
% % % | % % % | ||
| |