metapost

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revisionBoth sides next revision
metapost [2019/06/02 22:55] – [Symbol Sizing and Positioning] add u box to symbol parameter indicator code brucemuttonmetapost [2019/06/03 01:04] – [Symbol Sizing and Positioning] explain align in scrap versus output 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.  This is because we generally want the map symbols to be about ‘u’ in size.     * 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 is because we generally want the map symbols to be about ‘u’ in size.  
  
-This image is a symbol that has been defined with maximum x and y coordinates of 0.7u, both positive and negative.  The insertion point is at the intersection of the cross hairs, and the pdf has been exported with a rotate value of 15 degrees.  It has been overlaid with some code that highlights the origin and alignment loci, as described below.+This image is a symbol that has been defined with maximum x and y coordinates, supposedly, of 0.7u, both positive and negative.  The insertion point is at the intersection of the cross hairs, and the pdf has been exported with a rotate value of 15 degrees.  It has been overlaid with some code that highlights the origin and alignment loci, and unit symbol size, u, as described below.
  
 {{:metapost:symbol0.7x0.7notaligned.png?200 |Symbol 0.7u x 0.7u.  (0,0) at the intersection of the cross hairs,  pdf exported with rotate value of 15 degrees}} {{:metapost:symbol0.7x0.7notaligned.png?200 |Symbol 0.7u x 0.7u.  (0,0) at the intersection of the cross hairs,  pdf exported with rotate value of 15 degrees}}
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 ''centre''.  +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 ''centre''.  The U: variable is depicted by the light blue box.
   * 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, respectively.  ie for a symmetrically placed symbol who’s perimeter will just touch the insertion point, set U:=(0.5x symbol width, 0.5x symbol height). 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, respectively.  ie for a symmetrically placed symbol who’s perimeter will just touch the insertion point, set U:=(0.5x symbol width, 0.5x symbol height).
Line 115: Line 115:
   * If your symbol has its greatest dimension on a diagonal, then you should increase the U: components accordingly, to avoid unintentional drawing overlaps for aligned symbols.   * If your symbol has its greatest dimension on a diagonal, then you should increase the U: components accordingly, to avoid unintentional drawing overlaps for aligned symbols.
  
-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.  That way, an aligned symbol can always leave a pleasing small gap from its insertion point.+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.  So have written some code that you can temporarily place inside a symbol, to get a visual representation of how well placed its origin and alignment loci are with respect to 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.  So have written some code that you can temporarily place inside a symbol, to get a visual representation of how well placed its origin and alignment loci are with respect to its insertion point, and of its size compared to the nominal default size of u.
  
-Here it is inserted into an electric light symbol.  The code is between the lines with % % %.  It creates a green insertion point, a red origin point that represents the (0u, 0u) origin of the symbol, and a light blue rectangle that represents the loci of the alignment options (left, top-left etc). Note that this code requires that T:= ... rotated BEFORE aligned.  If your symbol uses T:= ... aligned BEFORE rotated, then the code needs to be modified slightly.  After writing the code, I realised that the symbol was in fact larger than 0.7u in the y direction!+Here it is inserted into an electric light symbol definition.  The code is between the lines with % % %.  It creates a green insertion point, a red origin point that represents the (0u, 0u) origin of the symbol, a light blue rectangle that represents the loci of the alignment options (left, top-left etc), and a grey unit symbol size. Note that this code requires that T:= ... rotated BEFORE aligned.  If your symbol uses T:= ... aligned BEFORE rotated, then the code needs to be modified slightly.   
 + 
 +After writing the code, I realised that this symbol was in fact larger than 0.7u in the y direction, therefore the U: variable is not tall enough, the symbol is not centered around around its (0u,0u) coordinates (which might be OK if you want the space below the luminaire to be part of the 'symbol') and it is just a bit (but probably acceptably) larger than u in size!
  
 <code> <code>
Line 157: Line 159:
  
  
-Here is an example with the above point symbol that has been redefined with three different U: settings, and inserted with ''-align top-right'' On the left, U:=(1.0u, 1.0u) [U/u=1.4], in the centre, U:=(0.7u, 0.7u) [U/u=1.0], on the right, U:=(0.5u, 0.5u) [U/u= 0.7].  Notice that the alignment, top-right, is relative to the local coordinate system in the scrap, not to the output page coordinate system.+Here is an example with the above point symbol that has been redefined with three different U: settings, and inserted with ''-align top-right'' On the left, U:=(1.0u, 1.0u) [U/u=1.4], in the centre, U:=(0.7u, 0.7u) [U/u=1.0], on the right, U:=(0.5u, 0.5u) [U/u= 0.7].  Note that the alignment, top-right, is relative to the local coordinate system in the scrap, not necessarily to the output page coordinate system.  In these examples it does match the output page orientation, because the scrap has 'north up'.
  
 {{:metapost:symbol0.7x0.7alignedtr-u1_7_5.png?400|}} {{:metapost:symbol0.7x0.7alignedtr-u1_7_5.png?400|}}
Line 164: Line 166:
  
 I'm going to suggest that the best values for U: components are between [U/u=1.0] to [U/u=1.2] I'm going to suggest that the best values for U: components are between [U/u=1.0] to [U/u=1.2]
 +
 +An here are some examples with a slightly improved U: variable, with the symbol aligned top-left and oriented 30 degrees, and the output rotated 15, 105, 195, 285 degrees.
 +
 +{{:metapost:symbolparameterindicatorsamples.png?400|}}
 +
 +And one last example, using ''point water'', with the above code added, that demonstrates how align is related to scrap coordinates rather than the output coordinates.
 +
 +{{:metapost:symbolscrapaligntooutputalignexplained.png?400|}}
  
 Bruce Bruce
  • metapost.txt
  • Last modified: 2 years ago
  • by tarquinwj