sp-star.cpp revision a8ccce3fe7248cc5294a4f1716593c2c9c358c3c
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh * <sodipodi:star> implementation
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh * Mitsuru Oka <oka326@parkcity.ne.jp>
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh * Lauris Kaplinski <lauris@kaplinski.com>
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh * bulia byak <buliabyak@users.sf.net>
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh * Abhishek Sharma
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh * Copyright (C) 1999-2002 Lauris Kaplinski
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh * Copyright (C) 2000-2001 Ximian, Inc.
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh * Released under GNU GPL, read the file 'COPYING' for more information
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh return new SPStar();
3711b3e25395437ee0a09dbbb2a76d999c4ef322miklosh bool starRegistered = SPFactory::instance().registerObject("star", createStar);
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh this->r[0] = 1.0;
c53f16f52840e8c0f2be9c1cc3af633c0ba1552emikloshvoid SPStar::build(SPDocument * document, Inkscape::XML::Node * repr) {
c53f16f52840e8c0f2be9c1cc3af633c0ba1552emiklosh // CPPIFY: see header file
7a7fa095a483e8b652af9f00e5169f62c84f09b9mikloshInkscape::XML::Node* SPStar::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
dc4f69a188c203f2fdc65f22d0d57904a8c52dd7miklosh sp_repr_set_int (repr, "sodipodi:sides", this->sides);
3711b3e25395437ee0a09dbbb2a76d999c4ef322miklosh sp_repr_set_svg_double(repr, "sodipodi:cx", this->center[Geom::X]);
3711b3e25395437ee0a09dbbb2a76d999c4ef322miklosh sp_repr_set_svg_double(repr, "sodipodi:cy", this->center[Geom::Y]);
a4d12a5147f3d1d6b568a326e39ef5dca384248dmiklosh sp_repr_set_svg_double(repr, "sodipodi:r1", this->r[0]);
1667116521643e2475184b048e0abb77a2aa9735miklosh sp_repr_set_svg_double(repr, "sodipodi:r2", this->r[1]);
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh sp_repr_set_svg_double(repr, "sodipodi:arg1", this->arg[0]);
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh sp_repr_set_svg_double(repr, "sodipodi:arg2", this->arg[1]);
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh sp_repr_set_boolean (repr, "inkscape:flatsided", this->flatsided);
1cda9431ef400135f5e1bd899a94b921bdad0eafmiklosh sp_repr_set_svg_double(repr, "inkscape:rounded", this->rounded);
3711b3e25395437ee0a09dbbb2a76d999c4ef322miklosh sp_repr_set_svg_double(repr, "inkscape:randomized", this->randomized);
1667116521643e2475184b048e0abb77a2aa9735miklosh char *d = sp_svg_write_path (this->_curve->get_pathvector());
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh // CPPIFY: see header file
1667116521643e2475184b048e0abb77a2aa9735mikloshvoid SPStar::set(unsigned int key, const gchar* value) {
1667116521643e2475184b048e0abb77a2aa9735miklosh /* fixme: we should really collect updates */
3711b3e25395437ee0a09dbbb2a76d999c4ef322miklosh this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh if (!sp_svg_length_read_ldd (value, &unit, NULL, &this->center[Geom::X]) ||
68664e00e2372534b4df2fdc5f54f836bafece18miklosh this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
68664e00e2372534b4df2fdc5f54f836bafece18miklosh if (!sp_svg_length_read_ldd (value, &unit, NULL, &this->center[Geom::Y]) ||
c53f16f52840e8c0f2be9c1cc3af633c0ba1552emiklosh this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
c53f16f52840e8c0f2be9c1cc3af633c0ba1552emiklosh if (!sp_svg_length_read_ldd (value, &unit, NULL, &this->r[0]) ||
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh this->r[0] = 1.0;
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh /* fixme: Need CLAMP (Lauris) */
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
1667116521643e2475184b048e0abb77a2aa9735miklosh if (!sp_svg_length_read_ldd (value, &unit, NULL, &this->r[1]) ||
1667116521643e2475184b048e0abb77a2aa9735miklosh this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
1667116521643e2475184b048e0abb77a2aa9735miklosh this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
1cda9431ef400135f5e1bd899a94b921bdad0eafmiklosh this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
68664e00e2372534b4df2fdc5f54f836bafece18miklosh this->flatsided = true;
68664e00e2372534b4df2fdc5f54f836bafece18miklosh this->flatsided = false;
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
3711b3e25395437ee0a09dbbb2a76d999c4ef322miklosh this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
fba63a357654d8b3e84c60007e40aa698cd45d19miklosh this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
3711b3e25395437ee0a09dbbb2a76d999c4ef322miklosh // CPPIFY: see header file
3711b3e25395437ee0a09dbbb2a76d999c4ef322miklosh // CPPIFY: see header file
3711b3e25395437ee0a09dbbb2a76d999c4ef322miklosh gchar *str = sp_svg_write_path(this->_curve->get_pathvector());
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh if (this->flatsided == false)
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh return _("Star");
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh return _("Polygon");
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh // while there will never be less than 3 vertices, we still need to
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh // make calls to ngettext because the pluralization may be different
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh // for various numbers >=3. The singular form is used as the index.
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh return g_strdup_printf (ngettext(_("with %d vertex"), _("with %d vertices"),
7a7fa095a483e8b652af9f00e5169f62c84f09b9mikloshReturns a unit-length vector at 90 degrees to the direction from o to n
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh return ((1/Geom::L2(n - o)) * Geom::Point ((n - o)[Geom::Y], (o - n)[Geom::X]));
3711b3e25395437ee0a09dbbb2a76d999c4ef322mikloshReturns a unique 32 bit int for a given point.
7a7fa095a483e8b652af9f00e5169f62c84f09b9mikloshObvious (but acceptable for my purposes) limits to uniqueness:
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh- returned value for x,y repeats for x+n*1024,y+n*1024
3711b3e25395437ee0a09dbbb2a76d999c4ef322miklosh- returned value is unchanged when the point is moved by less than 1/1024 of px
3711b3e25395437ee0a09dbbb2a76d999c4ef322miklosh (((int) floor (o[Geom::X] * 64)) % 1024 + ((int) floor (o[Geom::X] * 1024)) % 64)
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh (((int) floor (o[Geom::Y] * 64)) % 1024 + ((int) floor (o[Geom::Y] * 1024)) % 64)
7a7fa095a483e8b652af9f00e5169f62c84f09b9mikloshReturns the next pseudorandom value using the Linear Congruential Generator algorithm (LCG)
7a7fa095a483e8b652af9f00e5169f62c84f09b9mikloshwith the parameters (m = 2^32, a = 69069, b = 1). These parameters give a full-period generator,
7a7fa095a483e8b652af9f00e5169f62c84f09b9mikloshi.e. it is guaranteed to go through all integers < 2^32 (see http://random.mat.sbg.ac.at/~charly/server/server.html)
7a7fa095a483e8b652af9f00e5169f62c84f09b9mikloshstatic inline guint32
7a7fa095a483e8b652af9f00e5169f62c84f09b9mikloshReturns a random number in the range [-0.5, 0.5) from the given seed, stepping the given number of steps from the seed.
7a7fa095a483e8b652af9f00e5169f62c84f09b9mikloshstatic double
7a7fa095a483e8b652af9f00e5169f62c84f09b9mikloshsp_star_get_curvepoint (SPStar *star, SPStarPoint point, gint index, bool previ)
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh // the point whose neighboring curve handle we're calculating
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh Geom::Point o = sp_star_get_xy (star, point, index);
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh // indices of previous and next points
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh gint pi = (index > 0)? (index - 1) : (star->sides - 1);
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh gint ni = (index < star->sides - 1)? (index + 1) : 0;
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh // the other point type
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh SPStarPoint other = (point == SP_STAR_POINT_KNOT2? SP_STAR_POINT_KNOT1 : SP_STAR_POINT_KNOT2);
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh // the neighbors of o; depending on flatsided, they're either the same type (polygon) or the other type (star)
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh Geom::Point prev = (star->flatsided? sp_star_get_xy (star, point, pi) : sp_star_get_xy (star, other, point == SP_STAR_POINT_KNOT2? index : pi));
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh Geom::Point next = (star->flatsided? sp_star_get_xy (star, point, ni) : sp_star_get_xy (star, other, point == SP_STAR_POINT_KNOT1? index : ni));
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh // prev-next midpoint
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh // point to which we direct the bissector of the curve handles;
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh // it's far enough outside the star on the perpendicular to prev-next through mid
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh Geom::Point biss = mid + 100000 * rot90_rel (mid, next);
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh // lengths of vectors to prev and next
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh // unit-length vector perpendicular to o-biss
3711b3e25395437ee0a09dbbb2a76d999c4ef322miklosh // multiply rot by star->rounded coefficient and the distance to the star point; flip for next
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh // add the vector to o to get the final curvepoint
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh return o + ret;
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh // the seed corresponding to the exact point
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh // randomly rotate (by step 3 from the seed) and scale (by step 4) the vector
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh ret = ret * Geom::Affine (Geom::Rotate (star->randomized * M_PI * rnd (seed, 3)));
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh // the randomized corner point
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh Geom::Point o_randomized = sp_star_get_xy (star, point, index, true);
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh#define NEXT false
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh#define PREV true
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh // perhaps we should convert all our shapes into LPEs without source path
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh // and with knotholders for parameters, then this situation will be handled automatically
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh // by disabling the entire stack (including the shape LPE)
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh g_warning ("The star shape has unknown LPE on it! Convert to path to make it editable preserving the appearance; editing it as star will remove the bad LPE");
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh // unconditionally read the curve from d, if any, to preserve appearance
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh Geom::PathVector pv = sp_svg_read_pathv(this->getRepr()->attribute("d"));
3711b3e25395437ee0a09dbbb2a76d999c4ef322miklosh // note that we pass randomized=true to sp_star_get_xy, because the curve must be randomized;
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh // other places that call that function (e.g. the knotholder) need the exact point
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh // draw 1st segment
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh c->moveto(sp_star_get_xy (this, SP_STAR_POINT_KNOT1, 0, true));
3711b3e25395437ee0a09dbbb2a76d999c4ef322miklosh if (this->flatsided == false) {
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh c->lineto(sp_star_get_xy (this, SP_STAR_POINT_KNOT2, 0, true));
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh c->curveto(sp_star_get_curvepoint (this, SP_STAR_POINT_KNOT1, 0, NEXT),
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh sp_star_get_curvepoint (this, SP_STAR_POINT_KNOT2, 0, PREV),
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh sp_star_get_xy (this, SP_STAR_POINT_KNOT2, 0, true));
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh // draw all middle segments
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh c->lineto(sp_star_get_xy (this, SP_STAR_POINT_KNOT1, i, true));
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh if (this->flatsided == false) {
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh c->curveto(sp_star_get_curvepoint (this, SP_STAR_POINT_KNOT2, i - 1, NEXT),
3711b3e25395437ee0a09dbbb2a76d999c4ef322miklosh sp_star_get_curvepoint (this, SP_STAR_POINT_KNOT1, i, PREV),
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh sp_star_get_xy (this, SP_STAR_POINT_KNOT1, i, true));
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh c->curveto(sp_star_get_curvepoint (this, SP_STAR_POINT_KNOT1, i - 1, NEXT),
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh sp_star_get_curvepoint (this, SP_STAR_POINT_KNOT1, i, PREV),
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh sp_star_get_xy (this, SP_STAR_POINT_KNOT1, i, true));
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh if (this->flatsided == false) {
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh c->lineto(sp_star_get_xy (this, SP_STAR_POINT_KNOT2, i, true));
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh c->curveto(sp_star_get_curvepoint (this, SP_STAR_POINT_KNOT1, i, NEXT),
3686c32a570c3df738a09b34e85fc5d6bd50d020miklosh sp_star_get_curvepoint (this, SP_STAR_POINT_KNOT2, i, PREV),
3686c32a570c3df738a09b34e85fc5d6bd50d020miklosh sp_star_get_xy (this, SP_STAR_POINT_KNOT2, i, true));
3686c32a570c3df738a09b34e85fc5d6bd50d020miklosh // draw last segment
3686c32a570c3df738a09b34e85fc5d6bd50d020miklosh if (this->flatsided == false) {
3686c32a570c3df738a09b34e85fc5d6bd50d020miklosh c->curveto(sp_star_get_curvepoint (this, SP_STAR_POINT_KNOT2, sides - 1, NEXT),
3686c32a570c3df738a09b34e85fc5d6bd50d020miklosh sp_star_get_curvepoint (this, SP_STAR_POINT_KNOT1, 0, PREV),
3686c32a570c3df738a09b34e85fc5d6bd50d020miklosh sp_star_get_xy (this, SP_STAR_POINT_KNOT1, 0, true));
3686c32a570c3df738a09b34e85fc5d6bd50d020miklosh c->curveto(sp_star_get_curvepoint (this, SP_STAR_POINT_KNOT1, sides - 1, NEXT),
d27f5758e12c3107ee69e66702043931e0756f6bmiklosh sp_star_get_curvepoint (this, SP_STAR_POINT_KNOT1, 0, PREV),
3686c32a570c3df738a09b34e85fc5d6bd50d020miklosh sp_star_get_xy (this, SP_STAR_POINT_KNOT1, 0, true));
3686c32a570c3df738a09b34e85fc5d6bd50d020miklosh /* Reset the shape'scurve to the "original_curve"
3686c32a570c3df738a09b34e85fc5d6bd50d020miklosh * This is very important for LPEs to work properly! (the bbox might be recalculated depending on the curve in shape)*/
7a7fa095a483e8b652af9f00e5169f62c84f09b9mikloshsp_star_position_set (SPStar *star, gint sides, Geom::Point center, gdouble r1, gdouble r2, gdouble arg1, gdouble arg2, bool isflat, double rounded, double randomized)
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh if (isflat == false) {
920fbbf5386a5d3b1d0a1304cb71eb48112abe0dmiklosh star->r[1] = CLAMP( r1*cos(M_PI/sides) ,0.0, star->r[0] );
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh star->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
7a7fa095a483e8b652af9f00e5169f62c84f09b9mikloshvoid SPStar::snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs) const {
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh // We will determine the star's midpoint ourselves, instead of trusting on the base class
3711b3e25395437ee0a09dbbb2a76d999c4ef322miklosh // Therefore snapping to object midpoints is temporarily disabled
3711b3e25395437ee0a09dbbb2a76d999c4ef322miklosh Inkscape::SnapPreferences local_snapprefs = *snapprefs;
3711b3e25395437ee0a09dbbb2a76d999c4ef322miklosh local_snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_OBJECT_MIDPOINT, false);
3711b3e25395437ee0a09dbbb2a76d999c4ef322miklosh // CPPIFY: see header file
3711b3e25395437ee0a09dbbb2a76d999c4ef322miklosh if (snapprefs->isTargetSnappable(Inkscape::SNAPTARGET_OBJECT_MIDPOINT)) {
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh p.push_back(Inkscape::SnapCandidatePoint(this->center * i2dt,Inkscape::SNAPSOURCE_OBJECT_MIDPOINT, Inkscape::SNAPTARGET_OBJECT_MIDPOINT));
7a7fa095a483e8b652af9f00e5169f62c84f09b9mikloshGeom::Affine SPStar::set_transform(Geom::Affine const &xform)
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh // Only set transform with proportional scaling
3711b3e25395437ee0a09dbbb2a76d999c4ef322miklosh // Allow live effects
3711b3e25395437ee0a09dbbb2a76d999c4ef322miklosh /* Calculate star start in parent coords. */
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh /* This function takes care of translation and scaling, we return whatever parts we can't
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh Geom::Affine ret(Geom::Affine(xform).withoutTranslation());
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh if (s > 1e-9) {
3711b3e25395437ee0a09dbbb2a76d999c4ef322miklosh this->r[0] *= s;
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh this->r[1] *= s;
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh /* Find start in item coords */
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh // Adjust stroke width
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh // Adjust pattern fill
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh // Adjust gradient fill
dc4f69a188c203f2fdc65f22d0d57904a8c52dd7miklosh this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);
3686c32a570c3df738a09b34e85fc5d6bd50d020miklosh * sp_star_get_xy: Get X-Y value as item coordinate system
3711b3e25395437ee0a09dbbb2a76d999c4ef322miklosh * @star: star item
dc4f69a188c203f2fdc65f22d0d57904a8c52dd7miklosh * @point: point type to obtain X-Y value
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh * @index: index of vertex
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh * @p: pointer to store X-Y value
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh * @randomized: false (default) if you want to get exact, not randomized point
7a7fa095a483e8b652af9f00e5169f62c84f09b9miklosh * Initial item coordinate system is same as document coordinate system.
7a7fa095a483e8b652af9f00e5169f62c84f09b9mikloshsp_star_get_xy (SPStar const *star, SPStarPoint point, gint index, bool randomized)
dc4f69a188c203f2fdc65f22d0d57904a8c52dd7miklosh Geom::Point xy = star->r[point] * Geom::Point(cos(arg), sin(arg)) + star->center;
dc4f69a188c203f2fdc65f22d0d57904a8c52dd7miklosh // return the exact point
dc4f69a188c203f2fdc65f22d0d57904a8c52dd7miklosh } else { // randomize the point
dc4f69a188c203f2fdc65f22d0d57904a8c52dd7miklosh // find out the seed, unique for this point so that randomization is the same so long as the original point is stationary
dc4f69a188c203f2fdc65f22d0d57904a8c52dd7miklosh // the full range (corresponding to star->randomized == 1.0) is equal to the star's diameter
dc4f69a188c203f2fdc65f22d0d57904a8c52dd7miklosh // find out the random displacement; x is controlled by step 1 from the seed, y by the step 2
dc4f69a188c203f2fdc65f22d0d57904a8c52dd7miklosh Geom::Point shift (star->randomized * range * rnd (seed, 1), star->randomized * range * rnd (seed, 2));
dc4f69a188c203f2fdc65f22d0d57904a8c52dd7miklosh // add the shift to the exact point
dc4f69a188c203f2fdc65f22d0d57904a8c52dd7miklosh Local Variables:
dc4f69a188c203f2fdc65f22d0d57904a8c52dd7miklosh c-file-style:"stroustrup"
dc4f69a188c203f2fdc65f22d0d57904a8c52dd7miklosh c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
dc4f69a188c203f2fdc65f22d0d57904a8c52dd7miklosh indent-tabs-mode:nil
dc4f69a188c203f2fdc65f22d0d57904a8c52dd7miklosh fill-column:99
dc4f69a188c203f2fdc65f22d0d57904a8c52dd7miklosh// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :