For various reasons related to workflow associated with creating figures for journals, I am creating functions that will accept graphics primitives and a set of options and spit out a Graphics
object with those primitives and those options in some configuration.
(Of course, this sounds like all I'm doing is re-creating Graphics
, in that I can call
Graphics[ <List of primitives>, <Sequence of options>]
but it's more complicated than that.)
In any case, I would like to be able to check whether the inputs to the function are graphics primitives or not. We can create our own GraphicsPrimitiveQ
if we have a list of the Head
s of graphics primitives. For instance,
Clear[GraphicsPrimitiveQ, listOfHeads]
listOfHeads = {Line, Polygon, Point, Arrow, Tube};
GraphicsPrimitiveQ[x_] := MatchQ[Head[x], Alternatives @@ listOfHeads]
in which case if we define
f[x__?GraphicsPrimitiveQ] := {x}
then
f[Point[{0, 0}], Line[{{1, 1}, {0, 0}}]]
(* {Point[{0, 0}], Line[{{1, 1}, {0, 0}}} *)
and
f[Point[{0, 0}], 1]
(* f[Point[{0, 0}], 1] *)
So: Is there something like a GraphicsPrimitiveQ?
Or: Is there hidden somewhere in Mathematica an easy way to get a list of all graphics primitives?
Alternatively, if there's no built-in
ListOfGraphicsPrimitives[]
, then Is there a programmatic way of making the functionGraphicsPrimitiveQ
? (Added this because I for some reason didn't anticipate the clever answers below.)
primitives
in a package if I need to. Thanks! $\endgroup$GraphicsDirectiveQ[]
. :) $\endgroup$