~ubuntu-branches/ubuntu/lucid/inkscape/lucid

« back to all changes in this revision

Viewing changes to src/livarot/ShapeMisc.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook, Ted Gould, Kees Cook
  • Date: 2009-06-24 14:00:43 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20090624140043-07stp20mry48hqup
Tags: 0.47~pre0-0ubuntu1
* New upstream release

[ Ted Gould ]
* debian/control: Adding libgsl0 and removing version specifics on boost

[ Kees Cook ]
* debian/watch: updated to run uupdate and mangle pre-release versions.
* Dropped patches that have been taken upstream:
  - 01_mips
  - 02-poppler-0.8.3
  - 03-chinese-inkscape
  - 05_fix_latex_patch
  - 06_gcc-4.4
  - 07_cdr2svg
  - 08_skip-bad-utf-on-pdf-import
  - 09_gtk-clist
  - 10_belarussian
  - 11_libpng
  - 12_desktop
  - 13_slider
  - 100_svg_import_improvements
  - 102_sp_pattern_painter_free
  - 103_bitmap_type_print

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
 */
8
8
 
9
9
#include "livarot/Shape.h"
 
10
#include <libnr/nr-matrix-fns.h>
10
11
#include <libnr/nr-point-fns.h>
11
12
#include "livarot/Path.h"
12
13
#include "livarot/path-description.h"
527
528
 
528
529
 
529
530
int
530
 
Shape::MakeTweak (int mode, Shape *a, double power, JoinType join, double miter, bool do_profile, NR::Point c, NR::Point vector, double radius, NR::Matrix *i2doc)
 
531
Shape::MakeTweak (int mode, Shape *a, double power, JoinType join, double miter, bool do_profile, Geom::Point c, Geom::Point vector, double radius, Geom::Matrix *i2doc)
531
532
{
532
533
  Reset (0, 0);
533
534
  MakeBackData(a->_has_back_data);
583
584
      enB = a->CyclePrevAt (a->getEdge(i).en, i);
584
585
    }
585
586
    
586
 
    NR::Point stD, seD, enD;
 
587
    Geom::Point stD, seD, enD;
587
588
    double stL, seL, enL;
588
589
    stD = a->getEdge(stB).dx;
589
590
    seD = a->getEdge(i).dx;
596
597
    MiscNormalize (enD);
597
598
    MiscNormalize (seD);
598
599
    
599
 
    NR::Point ptP;
 
600
    Geom::Point ptP;
600
601
    int stNo, enNo;
601
602
    ptP = a->getPoint(a->getEdge(i).st).x;
602
603
 
603
 
        NR::Point to_center = ptP * (*i2doc) - c;
604
 
        NR::Point to_center_normalized = (1/NR::L2(to_center)) * to_center;
 
604
        Geom::Point to_center = ptP * (*i2doc) - c;
 
605
        Geom::Point to_center_normalized = (1/Geom::L2(to_center)) * to_center;
605
606
 
606
607
                double this_power;
607
608
                if (do_profile && i2doc) {
608
609
                        double alpha = 1;
609
610
                        double x;
610
611
                if (mode == tweak_mode_repel) {
611
 
                                x = (NR::L2(to_center)/radius);
 
612
                                x = (Geom::L2(to_center)/radius);
612
613
                        } else {
613
 
                                x = (NR::L2(ptP * (*i2doc) - c)/radius);
 
614
                                x = (Geom::L2(ptP * (*i2doc) - c)/radius);
614
615
                        }
615
616
                        if (x > 1) {
616
617
                                this_power = 0;
634
635
                if (this_power != 0)
635
636
                        done_something = true;
636
637
 
637
 
                double scaler = 1 / (*i2doc).expansion();
 
638
                double scaler = 1 / (*i2doc).descrim();
638
639
 
639
 
                NR::Point this_vec(0,0);
 
640
                Geom::Point this_vec(0,0);
640
641
    if (mode == tweak_mode_push) {
641
 
                        NR::Matrix tovec (*i2doc);
 
642
                        Geom::Matrix tovec (*i2doc);
642
643
                        tovec[4] = tovec[5] = 0;
643
644
                        tovec = tovec.inverse();
644
645
                        this_vec = this_power * (vector * tovec) ;
646
647
                        this_vec = this_power * scaler * to_center_normalized;
647
648
                } else if (mode == tweak_mode_roughen) {
648
649
                double angle = g_random_double_range(0, 2*M_PI);
649
 
                this_vec = g_random_double_range(0, 1) * this_power * scaler * NR::Point(sin(angle), cos(angle));
 
650
                this_vec = g_random_double_range(0, 1) * this_power * scaler * Geom::Point(sin(angle), cos(angle));
650
651
                }
651
652
 
652
653
    int   usePathID=-1;
717
718
// you gotta be very careful with the join, as anything but the right one will fuck everything up
718
719
// see PathStroke.cpp for the "right" joins
719
720
int
720
 
Shape::MakeOffset (Shape * a, double dec, JoinType join, double miter, bool do_profile, double cx, double cy, double radius, NR::Matrix *i2doc)
 
721
Shape::MakeOffset (Shape * a, double dec, JoinType join, double miter, bool do_profile, double cx, double cy, double radius, Geom::Matrix *i2doc)
721
722
{
722
723
  Reset (0, 0);
723
724
  MakeBackData(a->_has_back_data);
777
778
      enB = a->CycleNextAt (a->getEdge(i).en, i);
778
779
    }
779
780
    
780
 
    NR::Point stD, seD, enD;
 
781
    Geom::Point stD, seD, enD;
781
782
    double stL, seL, enL;
782
783
    stD = a->getEdge(stB).dx;
783
784
    seD = a->getEdge(i).dx;
790
791
    MiscNormalize (enD);
791
792
    MiscNormalize (seD);
792
793
    
793
 
    NR::Point ptP;
 
794
    Geom::Point ptP;
794
795
    int stNo, enNo;
795
796
    ptP = a->getPoint(a->getEdge(i).st).x;
796
797
 
797
798
                double this_dec;
798
799
                if (do_profile && i2doc) {
799
800
                        double alpha = 1;
800
 
                        double x = (NR::L2(ptP * (*i2doc) - NR::Point(cx,cy))/radius);
 
801
                        double x = (Geom::L2(ptP * (*i2doc) - Geom::Point(cx,cy))/radius);
801
802
                        if (x > 1) {
802
803
                                this_dec = 0;
803
804
                        } else if (x <= 0) {
981
982
}
982
983
 
983
984
int
984
 
Shape::ReFormeLineTo (int bord, int curBord, Path * dest, Path * orig)
 
985
Shape::ReFormeLineTo (int bord, int /*curBord*/, Path * dest, Path * /*orig*/)
985
986
{
986
987
  int nPiece = ebData[bord].pieceID;
987
988
  int nPath = ebData[bord].pathID;
988
989
  double /*ts=ebData[bord].tSt, */ te = ebData[bord].tEn;
989
 
  NR::Point nx = getPoint(getEdge(bord).en).x;
 
990
  Geom::Point nx = getPoint(getEdge(bord).en).x;
990
991
  bord = swdData[bord].suivParc;
991
992
  while (bord >= 0)
992
993
  {
1015
1016
}
1016
1017
 
1017
1018
int
1018
 
Shape::ReFormeArcTo (int bord, int curBord, Path * dest, Path * from)
 
1019
Shape::ReFormeArcTo (int bord, int /*curBord*/, Path * dest, Path * from)
1019
1020
{
1020
1021
  int nPiece = ebData[bord].pieceID;
1021
1022
  int nPath = ebData[bord].pathID;
1022
1023
  double ts = ebData[bord].tSt, te = ebData[bord].tEn;
1023
1024
  //      double  px=pts[getEdge(bord).st].x,py=pts[getEdge(bord).st].y;
1024
 
  NR::Point nx = getPoint(getEdge(bord).en).x;
 
1025
  Geom::Point nx = getPoint(getEdge(bord).en).x;
1025
1026
  bord = swdData[bord].suivParc;
1026
1027
  while (bord >= 0)
1027
1028
  {
1093
1094
}
1094
1095
 
1095
1096
int
1096
 
Shape::ReFormeCubicTo (int bord, int curBord, Path * dest, Path * from)
 
1097
Shape::ReFormeCubicTo (int bord, int /*curBord*/, Path * dest, Path * from)
1097
1098
{
1098
1099
  int nPiece = ebData[bord].pieceID;
1099
1100
  int nPath = ebData[bord].pathID;
1100
1101
  double ts = ebData[bord].tSt, te = ebData[bord].tEn;
1101
 
  NR::Point nx = getPoint(getEdge(bord).en).x;
 
1102
  Geom::Point nx = getPoint(getEdge(bord).en).x;
1102
1103
  bord = swdData[bord].suivParc;
1103
1104
  while (bord >= 0)
1104
1105
  {
1122
1123
    }
1123
1124
    bord = swdData[bord].suivParc;
1124
1125
  }
1125
 
  NR::Point prevx = from->PrevPoint (nPiece - 1);
 
1126
  Geom::Point prevx = from->PrevPoint (nPiece - 1);
1126
1127
  
1127
 
  NR::Point sDx, eDx;
 
1128
  Geom::Point sDx, eDx;
1128
1129
  {
1129
1130
    PathDescrCubicTo *nData = dynamic_cast<PathDescrCubicTo *>(from->descr_cmd[nPiece]);
1130
1131
    Path::CubicTangent (ts, sDx, prevx,nData->start,nData->p,nData->end);
1139
1140
}
1140
1141
 
1141
1142
int
1142
 
Shape::ReFormeBezierTo (int bord, int curBord, Path * dest, Path * from)
 
1143
Shape::ReFormeBezierTo (int bord, int /*curBord*/, Path * dest, Path * from)
1143
1144
{
1144
1145
  int nPiece = ebData[bord].pieceID;
1145
1146
  int nPath = ebData[bord].pathID;
1146
1147
  double ts = ebData[bord].tSt, te = ebData[bord].tEn;
1147
1148
  int ps = nPiece, pe = nPiece;
1148
 
  NR::Point px = getPoint(getEdge(bord).st).x;
1149
 
  NR::Point nx = getPoint(getEdge(bord).en).x;
 
1149
  Geom::Point px = getPoint(getEdge(bord).st).x;
 
1150
  Geom::Point nx = getPoint(getEdge(bord).en).x;
1150
1151
  int inBezier = -1, nbInterm = -1;
1151
1152
  int typ;
1152
1153
  typ = from->descr_cmd[nPiece]->getType();
1234
1235
      }
1235
1236
      else
1236
1237
      {
1237
 
        NR::Point tx;
 
1238
        Geom::Point tx;
1238
1239
        {
1239
1240
          PathDescrIntermBezierTo* psData = dynamic_cast<PathDescrIntermBezierTo*>(from->descr_cmd[pe]);
1240
1241
          PathDescrIntermBezierTo* pnData = dynamic_cast<PathDescrIntermBezierTo*>(from->descr_cmd[pe+1]);
1255
1256
    {
1256
1257
      if (te > 0.9999)
1257
1258
      {
1258
 
        NR::Point tx;
 
1259
        Geom::Point tx;
1259
1260
        {
1260
1261
          PathDescrIntermBezierTo* psData = dynamic_cast<PathDescrIntermBezierTo*>(from->descr_cmd[ps+1]);
1261
1262
          PathDescrIntermBezierTo* pnData = dynamic_cast<PathDescrIntermBezierTo*>(from->descr_cmd[ps+2]);
1273
1274
      }
1274
1275
      else
1275
1276
      {
1276
 
        NR::Point tx;
 
1277
        Geom::Point tx;
1277
1278
        {
1278
1279
          PathDescrIntermBezierTo* psData = dynamic_cast<PathDescrIntermBezierTo*>(from->descr_cmd[ps+1]);
1279
1280
          PathDescrIntermBezierTo* pnData = dynamic_cast<PathDescrIntermBezierTo*>(from->descr_cmd[ps+2]);
1314
1315
      }
1315
1316
      else
1316
1317
      {
1317
 
        NR::Point tx;
 
1318
        Geom::Point tx;
1318
1319
        {
1319
1320
          PathDescrIntermBezierTo* psData = dynamic_cast<PathDescrIntermBezierTo*>(from->descr_cmd[pe+1]);
1320
1321
          PathDescrIntermBezierTo* pnData = dynamic_cast<PathDescrIntermBezierTo*>(from->descr_cmd[pe+2]);
1335
1336
    {
1336
1337
      if (te < 0.0001)
1337
1338
      {
1338
 
        NR::Point tx;
 
1339
        Geom::Point tx;
1339
1340
        {
1340
1341
          PathDescrIntermBezierTo* psData = dynamic_cast<PathDescrIntermBezierTo*>(from->descr_cmd[ps]);
1341
1342
          PathDescrIntermBezierTo* pnData = dynamic_cast<PathDescrIntermBezierTo*>(from->descr_cmd[ps+1]);
1353
1354
      }
1354
1355
      else
1355
1356
      {
1356
 
        NR::Point tx;
 
1357
        Geom::Point tx;
1357
1358
        {
1358
1359
          PathDescrIntermBezierTo* psData = dynamic_cast<PathDescrIntermBezierTo*>(from->descr_cmd[ps]);
1359
1360
          PathDescrIntermBezierTo* pnData = dynamic_cast<PathDescrIntermBezierTo*>(from->descr_cmd[ps+1]);
1382
1383
}
1383
1384
 
1384
1385
void
1385
 
Shape::ReFormeBezierChunk (NR::Point px, NR::Point nx,
 
1386
Shape::ReFormeBezierChunk (Geom::Point px, Geom::Point nx,
1386
1387
                           Path * dest, int inBezier, int nbInterm,
1387
1388
                           Path * from, int p, double ts, double te)
1388
1389
{
1389
1390
  PathDescrBezierTo* nBData = dynamic_cast<PathDescrBezierTo*>(from->descr_cmd[inBezier]);
1390
 
  NR::Point bstx = from->PrevPoint (inBezier - 1);
1391
 
  NR::Point benx = nBData->p;
 
1391
  Geom::Point bstx = from->PrevPoint (inBezier - 1);
 
1392
  Geom::Point benx = nBData->p;
1392
1393
  
1393
 
  NR::Point mx;
 
1394
  Geom::Point mx;
1394
1395
  if (p == inBezier)
1395
1396
  {
1396
1397
    // premier bout
1429
1430
    nData = dynamic_cast<PathDescrIntermBezierTo*>(from->descr_cmd[p+2]);
1430
1431
    benx = (nData->p + mx) / 2;
1431
1432
  }
1432
 
  NR::Point cx;
 
1433
  Geom::Point cx;
1433
1434
  {
1434
1435
    Path::QuadraticPoint ((ts + te) / 2, cx, bstx, mx, benx);
1435
1436
  }