1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899
|
// SPDX-FileCopyrightText: 2003 Dominique Devriese <devriese@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later
#include "transform_types.h"
#include <math.h>
#include "../misc/coordinate.h"
#include "../misc/kigtransform.h"
#include "bogus_imp.h"
#include "line_imp.h"
#include "other_imp.h"
#include "point_imp.h"
#include "polygon_imp.h"
#include "special_imptypes.h"
#include <cmath>
static const ArgsParser::spec argsspecTranslation[] = {
{ObjectImp::stype(), kli18n("Translate this object"), kli18n("Select the object to translate..."), false},
{VectorImp::stype(), kli18n("Translate by this vector"), kli18n("Select the vector to translate by..."), false}};
KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE(TranslatedType)
TranslatedType::TranslatedType()
: ArgsParserObjectType("Translation", argsspecTranslation, 2)
{
}
TranslatedType::~TranslatedType()
{
}
const TranslatedType *TranslatedType::instance()
{
static const TranslatedType t;
return &t;
}
ObjectImp *TranslatedType::calc(const Args &args, const KigDocument &) const
{
if (!margsparser.checkArgs(args))
return new InvalidImp;
Coordinate dir = static_cast<const VectorImp *>(args[1])->dir();
Transformation t = Transformation::translation(dir);
return args[0]->transform(t);
}
static const ArgsParser::spec argsspecPointReflection[] = {
{ObjectImp::stype(), kli18n("Reflect this object"), kli18n("Select the object to reflect..."), false},
{PointImp::stype(), kli18n("Reflect in this point"), kli18n("Select the point to reflect in..."), false}};
KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE(PointReflectionType)
PointReflectionType::PointReflectionType()
: ArgsParserObjectType("PointReflection", argsspecPointReflection, 2)
{
}
PointReflectionType::~PointReflectionType()
{
}
const PointReflectionType *PointReflectionType::instance()
{
static const PointReflectionType t;
return &t;
}
ObjectImp *PointReflectionType::calc(const Args &args, const KigDocument &) const
{
if (!margsparser.checkArgs(args))
return new InvalidImp;
Coordinate center = static_cast<const PointImp *>(args[1])->coordinate();
Transformation t = Transformation::pointReflection(center);
return args[0]->transform(t);
}
static const ArgsParser::spec argsspecLineReflection[] = {
{ObjectImp::stype(), kli18n("Reflect this object"), kli18n("Select the object to reflect..."), false},
{AbstractLineImp::stype(), kli18n("Reflect in this line"), kli18n("Select the line to reflect in..."), false}};
KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE(LineReflectionType)
LineReflectionType::LineReflectionType()
: ArgsParserObjectType("LineReflection", argsspecLineReflection, 2)
{
}
LineReflectionType::~LineReflectionType()
{
}
const LineReflectionType *LineReflectionType::instance()
{
static const LineReflectionType t;
return &t;
}
ObjectImp *LineReflectionType::calc(const Args &args, const KigDocument &) const
{
if (!margsparser.checkArgs(args))
return new InvalidImp;
LineData d = static_cast<const AbstractLineImp *>(args[1])->data();
Transformation t = Transformation::lineReflection(d);
return args[0]->transform(t);
}
static const ArgsParser::spec argsspecRotation[] = {
{ObjectImp::stype(), kli18n("Rotate this object"), kli18n("Select the object to rotate..."), false},
{PointImp::stype(), kli18n("Rotate around this point"), kli18n("Select the center point of the rotation..."), false},
// { AngleImp::stype(), kli18n( "Rotate by this angle" ),
// kli18n( "Select the angle of the rotation..." ), false }
{&angleimptypeinstance, kli18n("Rotate by this angle"), kli18n("Select the angle of the rotation..."), false}};
KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE(RotationType)
RotationType::RotationType()
: ArgsParserObjectType("Rotation", argsspecRotation, 3)
{
}
RotationType::~RotationType()
{
}
const RotationType *RotationType::instance()
{
static const RotationType t;
return &t;
}
ObjectImp *RotationType::calc(const Args &args, const KigDocument &) const
{
if (!margsparser.checkArgs(args))
return new InvalidImp;
Coordinate center = static_cast<const PointImp *>(args[1])->coordinate();
// double angle = static_cast<const AngleImp*>( args[2] )->size();
bool valid;
double angle = getDoubleFromImp(args[2], valid);
if (!valid)
return new InvalidImp;
return args[0]->transform(Transformation::rotation(angle, center));
}
static const ArgsParser::spec argsspecScalingOverCenter[] = {
{ObjectImp::stype(), kli18n("Scale this object"), kli18n("Select the object to scale..."), false},
{PointImp::stype(), kli18n("Scale with this center"), kli18n("Select the center point of the scaling..."), false},
// { SegmentImp::stype(), kli18n( "Scale by the length of this segment" ),
// kli18n( "Select a segment whose length is the factor of the scaling..." ), false }
{&lengthimptypeinstance, kli18n("Scale by this length"), kli18n("Select a length or a segment whose length is the factor of the scaling..."), false}};
KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE(ScalingOverCenterType)
ScalingOverCenterType::ScalingOverCenterType()
: ArgsParserObjectType("ScalingOverCenter", argsspecScalingOverCenter, 3)
{
}
ScalingOverCenterType::~ScalingOverCenterType()
{
}
const ScalingOverCenterType *ScalingOverCenterType::instance()
{
static const ScalingOverCenterType t;
return &t;
}
ObjectImp *ScalingOverCenterType::calc(const Args &args, const KigDocument &) const
{
if (!margsparser.checkArgs(args))
return new InvalidImp;
Coordinate center = static_cast<const PointImp *>(args[1])->coordinate();
bool valid;
double ratio = getDoubleFromImp(args[2], valid);
if (!valid)
return new InvalidImp;
return args[0]->transform(Transformation::scalingOverPoint(ratio, center));
}
static const ArgsParser::spec argsspecScalingOverCenter2[] = {
{ObjectImp::stype(), kli18n("Scale this object"), kli18n("Select the object to scale..."), false},
{PointImp::stype(), kli18n("Scale with this center"), kli18n("Select the center point of the scaling..."), false},
// { SegmentImp::stype(), kli18n( "Scale the length of this segment..." ),
// kli18n( "Select the first of two segments whose ratio is the factor of the scaling..." ), false },
// { SegmentImp::stype(), kli18n( "...to the length of this other segment" ),
// kli18n( "Select the second of two segments whose ratio is the factor of the scaling..." ), false }
{&lengthimptypeinstance,
kli18n("Scale this length..."),
kli18n("Select the first of two lengths whose ratio is the factor of the scaling..."),
false},
{&lengthimptypeinstance,
kli18n("...to this other length"),
kli18n("Select the second of two lengths whose ratio is the factor of the scaling..."),
false}};
KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE(ScalingOverCenter2Type)
ScalingOverCenter2Type::ScalingOverCenter2Type()
: ArgsParserObjectType("ScalingOverCenter2", argsspecScalingOverCenter2, 4)
{
}
ScalingOverCenter2Type::~ScalingOverCenter2Type()
{
}
const ScalingOverCenter2Type *ScalingOverCenter2Type::instance()
{
static const ScalingOverCenter2Type t;
return &t;
}
ObjectImp *ScalingOverCenter2Type::calc(const Args &args, const KigDocument &) const
{
if (!margsparser.checkArgs(args))
return new InvalidImp;
Coordinate center = static_cast<const PointImp *>(args[1])->coordinate();
// double ratio = static_cast<const SegmentImp*>( args[3] )->length()/
// static_cast<const SegmentImp*>( args[2] )->length();
bool valid;
double denom = getDoubleFromImp(args[2], valid);
if (!valid || denom == 0.0)
return new InvalidImp;
double ratio = getDoubleFromImp(args[3], valid) / denom;
if (!valid)
return new InvalidImp;
return args[0]->transform(Transformation::scalingOverPoint(ratio, center));
}
static const ArgsParser::spec argsspecScalingOverLine[] = {
{ObjectImp::stype(), kli18n("Scale this object"), kli18n("Select the object to scale"), false},
{AbstractLineImp::stype(), kli18n("Scale over this line"), kli18n("Select the line to scale over"), false},
// { SegmentImp::stype(), kli18n( "Scale by the length of this segment" ), kli18n( "Select a segment whose length is the factor for the scaling" ),
// false }
{&lengthimptypeinstance, kli18n("Scale by this length"), kli18n("Select a length or a segment whose length is the factor of the scaling..."), false}};
KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE(ScalingOverLineType)
ScalingOverLineType::ScalingOverLineType()
: ArgsParserObjectType("ScalingOverLine", argsspecScalingOverLine, 3)
{
}
ScalingOverLineType::~ScalingOverLineType()
{
}
const ScalingOverLineType *ScalingOverLineType::instance()
{
static const ScalingOverLineType t;
return &t;
}
ObjectImp *ScalingOverLineType::calc(const Args &args, const KigDocument &) const
{
if (!margsparser.checkArgs(args))
return new InvalidImp;
LineData line = static_cast<const AbstractLineImp *>(args[1])->data();
bool valid;
double ratio = getDoubleFromImp(args[2], valid);
if (!valid)
return new InvalidImp;
return args[0]->transform(Transformation::scalingOverLine(ratio, line));
}
static const ArgsParser::spec argsspecScalingOverLine2[] = {
{ObjectImp::stype(), kli18n("Scale this object"), kli18n("Select the object to scale"), false},
{AbstractLineImp::stype(), kli18n("Scale over this line"), kli18n("Select the line to scale over"), false},
// { SegmentImp::stype(), kli18n( "Scale the length of this segment..." ), kli18n( "Select the first of two segments whose ratio is the factor for
// the scaling" ), false }, { SegmentImp::stype(), kli18n( "...to the length of this segment" ), kli18n( "Select the second of two segments whose
// ratio is the factor for the scaling" ), false }
{&lengthimptypeinstance,
kli18n("Scale this length..."),
kli18n("Select the first of two lengths whose ratio is the factor of the scaling..."),
false},
{&lengthimptypeinstance,
kli18n("...to this other length"),
kli18n("Select the second of two lengths whose ratio is the factor of the scaling..."),
false}};
KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE(ScalingOverLine2Type)
ScalingOverLine2Type::ScalingOverLine2Type()
: ArgsParserObjectType("ScalingOverLine2", argsspecScalingOverLine2, 4)
{
}
ScalingOverLine2Type::~ScalingOverLine2Type()
{
}
const ScalingOverLine2Type *ScalingOverLine2Type::instance()
{
static const ScalingOverLine2Type t;
return &t;
}
ObjectImp *ScalingOverLine2Type::calc(const Args &args, const KigDocument &) const
{
if (!margsparser.checkArgs(args))
return new InvalidImp;
LineData line = static_cast<const AbstractLineImp *>(args[1])->data();
// double ratio = static_cast<const SegmentImp*>( args[3] )->length()/
// static_cast<const SegmentImp*>( args[2] )->length();
bool valid;
double denom = getDoubleFromImp(args[2], valid);
if (!valid || denom == 0.0)
return new InvalidImp;
double ratio = getDoubleFromImp(args[3], valid) / denom;
if (!valid)
return new InvalidImp;
return args[0]->transform(Transformation::scalingOverLine(ratio, line));
}
static const ArgsParser::spec argsspecProjectiveRotation[] = {
{ObjectImp::stype(), kli18n("Projectively rotate this object"), kli18n("Select the object to rotate projectively"), false},
{RayImp::stype(),
kli18n("Projectively rotate with this half-line"),
kli18n("Select the half line of the projective rotation that you want to apply to the object"),
false},
{AngleImp::stype(),
kli18n("Projectively rotate by this angle"),
kli18n("Select the angle of the projective rotation that you want to apply to the object"),
false}};
KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE(ProjectiveRotationType)
ProjectiveRotationType::ProjectiveRotationType()
: ArgsParserObjectType("ProjectiveRotation", argsspecProjectiveRotation, 3)
{
}
ProjectiveRotationType::~ProjectiveRotationType()
{
}
const ProjectiveRotationType *ProjectiveRotationType::instance()
{
static const ProjectiveRotationType t;
return &t;
}
ObjectImp *ProjectiveRotationType::calc(const Args &args, const KigDocument &) const
{
if (!margsparser.checkArgs(args))
return new InvalidImp;
const RayImp *ray = static_cast<const RayImp *>(args[1]);
Coordinate c1 = ray->data().a;
Coordinate dir = ray->data().dir().normalize();
double alpha = static_cast<const AngleImp *>(args[2])->size();
return args[0]->transform(Transformation::projectiveRotation(alpha, dir, c1));
}
static const ArgsParser::spec argsspecHarmonicHomology[] = {
{ObjectImp::stype(), kli18n("Harmonic Homology of this object"), kli18n("Select the object to transform..."), false},
{PointImp::stype(), kli18n("Harmonic Homology with this center"), kli18n("Select the center point of the harmonic homology..."), false},
{AbstractLineImp::stype(), kli18n("Harmonic Homology with this axis"), kli18n("Select the axis of the harmonic homology..."), false}};
KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE(HarmonicHomologyType)
HarmonicHomologyType::HarmonicHomologyType()
: ArgsParserObjectType("HarmonicHomology", argsspecHarmonicHomology, 3)
{
}
HarmonicHomologyType::~HarmonicHomologyType()
{
}
const HarmonicHomologyType *HarmonicHomologyType::instance()
{
static const HarmonicHomologyType t;
return &t;
}
ObjectImp *HarmonicHomologyType::calc(const Args &args, const KigDocument &) const
{
if (!margsparser.checkArgs(args))
return new InvalidImp;
Coordinate center = static_cast<const PointImp *>(args[1])->coordinate();
LineData axis = static_cast<const AbstractLineImp *>(args[2])->data();
return args[0]->transform(Transformation::harmonicHomology(center, axis));
}
static const ArgsParser::spec argsspecAffinityB2Tr[] = {
{ObjectImp::stype(), kli18n("Generic affinity of this object"), kli18n("Select the object to transform..."), false},
{FilledPolygonImp::stype3(), kli18n("Map this triangle"), kli18n("Select the triangle that has to be transformed onto a given triangle..."), false},
{FilledPolygonImp::stype3(),
kli18n("onto this other triangle"),
kli18n("Select the triangle that is the image by the affinity of the first triangle..."),
false}};
KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE(AffinityB2TrType)
AffinityB2TrType::AffinityB2TrType()
: ArgsParserObjectType("AffinityB2Tr", argsspecAffinityB2Tr, 3)
{
}
AffinityB2TrType::~AffinityB2TrType()
{
}
const AffinityB2TrType *AffinityB2TrType::instance()
{
static const AffinityB2TrType t;
return &t;
}
ObjectImp *AffinityB2TrType::calc(const Args &args, const KigDocument &) const
{
if (!margsparser.checkArgs(args))
return new InvalidImp;
std::vector<Coordinate> frompoints = static_cast<const FilledPolygonImp *>(args[1])->points();
std::vector<Coordinate> topoints = static_cast<const FilledPolygonImp *>(args[2])->points();
bool valid = true;
Transformation t = Transformation::affinityGI3P(frompoints, topoints, valid);
if (valid == false)
return new InvalidImp;
return args[0]->transform(t);
}
static const ArgsParser::spec argsspecAffinityGI3P[] = {
{ObjectImp::stype(), kli18n("Generic affinity of this object"), kli18n("Select the object to transform..."), false},
{PointImp::stype(), kli18n("First of 3 starting points"), kli18n("Select the first of the three starting points of the generic affinity..."), false},
{PointImp::stype(),
kli18n("Second of 3 starting points"),
kli18n("Select the second of the three starting points of the generic affinity..."),
false},
{PointImp::stype(), kli18n("Third of 3 starting points"), kli18n("Select the third of the three starting points of the generic affinity..."), false},
{PointImp::stype(),
kli18n("Transformed position of first point"),
kli18n("Select the first of the three end points of the generic affinity..."),
false},
{PointImp::stype(),
kli18n("Transformed position of second point"),
kli18n("Select the second of the three end points of the generic affinity..."),
false},
{PointImp::stype(),
kli18n("Transformed position of third point"),
kli18n("Select the third of the three end points of the generic affinity..."),
false},
};
KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE(AffinityGI3PType)
AffinityGI3PType::AffinityGI3PType()
: ArgsParserObjectType("AffinityGI3P", argsspecAffinityGI3P, 7)
{
}
AffinityGI3PType::~AffinityGI3PType()
{
}
const AffinityGI3PType *AffinityGI3PType::instance()
{
static const AffinityGI3PType t;
return &t;
}
ObjectImp *AffinityGI3PType::calc(const Args &args, const KigDocument &) const
{
if (!margsparser.checkArgs(args))
return new InvalidImp;
std::vector<Coordinate> frompoints;
std::vector<Coordinate> topoints;
for (uint i = 0; i < 3; ++i) {
frompoints.push_back(static_cast<const PointImp *>(args[i + 1])->coordinate());
topoints.push_back(static_cast<const PointImp *>(args[i + 4])->coordinate());
}
bool valid = true;
Transformation t = Transformation::affinityGI3P(frompoints, topoints, valid);
if (valid == false)
return new InvalidImp;
return args[0]->transform(t);
}
static const ArgsParser::spec argsspecProjectivityB2Qu[] = {
{ObjectImp::stype(), kli18n("Generic projective transformation of this object"), kli18n("Select the object to transform..."), false},
{FilledPolygonImp::stype4(),
kli18n("Map this quadrilateral"),
kli18n("Select the quadrilateral that has to be transformed onto a given quadrilateral..."),
false},
{FilledPolygonImp::stype4(),
kli18n("onto this other quadrilateral"),
kli18n("Select the quadrilateral that is the image by the projective transformation of the first quadrilateral..."),
false}};
KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE(ProjectivityB2QuType)
ProjectivityB2QuType::ProjectivityB2QuType()
: ArgsParserObjectType("ProjectivityB2Qu", argsspecProjectivityB2Qu, 3)
{
}
ProjectivityB2QuType::~ProjectivityB2QuType()
{
}
const ProjectivityB2QuType *ProjectivityB2QuType::instance()
{
static const ProjectivityB2QuType t;
return &t;
}
ObjectImp *ProjectivityB2QuType::calc(const Args &args, const KigDocument &) const
{
if (!margsparser.checkArgs(args))
return new InvalidImp;
std::vector<Coordinate> frompoints = static_cast<const FilledPolygonImp *>(args[1])->points();
std::vector<Coordinate> topoints = static_cast<const FilledPolygonImp *>(args[2])->points();
bool valid = true;
Transformation t = Transformation::projectivityGI4P(frompoints, topoints, valid);
if (valid == false)
return new InvalidImp;
return args[0]->transform(t);
}
static const ArgsParser::spec argsspecProjectivityGI4P[] = {
{ObjectImp::stype(), kli18n("Generic projective transformation of this object"), kli18n("Select the object to transform..."), false},
{PointImp::stype(),
kli18n("First of 4 starting points"),
kli18n("Select the first of the four starting points of the generic projectivity..."),
false},
{PointImp::stype(),
kli18n("Second of 4 starting points"),
kli18n("Select the second of the four starting points of the generic projectivity..."),
false},
{PointImp::stype(),
kli18n("Third of 4 starting points"),
kli18n("Select the third of the four starting points of the generic projectivity..."),
false},
{PointImp::stype(),
kli18n("Fourth of 4 starting points"),
kli18n("Select the fourth of the four starting points of the generic projectivity..."),
false},
{PointImp::stype(),
kli18n("Transformed position of first point"),
kli18n("Select the first of the four end points of the generic projectivity..."),
false},
{PointImp::stype(),
kli18n("Transformed position of second point"),
kli18n("Select the second of the four end points of the generic projectivity..."),
false},
{PointImp::stype(),
kli18n("Transformed position of third point"),
kli18n("Select the third of the four end points of the generic projectivity..."),
false},
{PointImp::stype(),
kli18n("Transformed position of fourth point"),
kli18n("Select the fourth of the four end points of the generic projectivity..."),
false}};
KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE(ProjectivityGI4PType)
ProjectivityGI4PType::ProjectivityGI4PType()
: ArgsParserObjectType("ProjectivityGI4P", argsspecProjectivityGI4P, 9)
{
}
ProjectivityGI4PType::~ProjectivityGI4PType()
{
}
const ProjectivityGI4PType *ProjectivityGI4PType::instance()
{
static const ProjectivityGI4PType t;
return &t;
}
ObjectImp *ProjectivityGI4PType::calc(const Args &args, const KigDocument &) const
{
if (!margsparser.checkArgs(args))
return new InvalidImp;
std::vector<Coordinate> frompoints;
std::vector<Coordinate> topoints;
for (uint i = 0; i < 4; ++i) {
frompoints.push_back(static_cast<const PointImp *>(args[i + 1])->coordinate());
topoints.push_back(static_cast<const PointImp *>(args[i + 5])->coordinate());
}
bool valid = true;
Transformation t = Transformation::projectivityGI4P(frompoints, topoints, valid);
if (valid == false)
return new InvalidImp;
return args[0]->transform(t);
}
static const ArgsParser::spec argsspecCastShadow[] = {
{ObjectImp::stype(), kli18n("Cast the shadow of this object"), kli18n("Select the object of which you want to construct the shadow..."), false},
{PointImp::stype(),
kli18n("Cast a shadow from this light source"),
kli18n("Select the light source from which the shadow should originate..."),
false},
{AbstractLineImp::stype(), kli18n("Cast a shadow on the horizon represented by this line"), kli18n("Select the horizon for the shadow..."), false}};
KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE(CastShadowType)
CastShadowType::CastShadowType()
: ArgsParserObjectType("CastShadow", argsspecCastShadow, 3)
{
}
CastShadowType::~CastShadowType()
{
}
const CastShadowType *CastShadowType::instance()
{
static const CastShadowType t;
return &t;
}
ObjectImp *CastShadowType::calc(const Args &args, const KigDocument &) const
{
if (!margsparser.checkArgs(args))
return new InvalidImp;
Coordinate lightsrc = static_cast<const PointImp *>(args[1])->coordinate();
LineData d = static_cast<const AbstractLineImp *>(args[2])->data();
return args[0]->transform(Transformation::castShadow(lightsrc, d));
}
const ObjectImpType *TranslatedType::resultId() const
{
return ObjectImp::stype();
}
const ObjectImpType *PointReflectionType::resultId() const
{
return ObjectImp::stype();
}
const ObjectImpType *LineReflectionType::resultId() const
{
return ObjectImp::stype();
}
const ObjectImpType *RotationType::resultId() const
{
return ObjectImp::stype();
}
const ObjectImpType *ScalingOverCenterType::resultId() const
{
return ObjectImp::stype();
}
const ObjectImpType *ScalingOverCenter2Type::resultId() const
{
return ObjectImp::stype();
}
const ObjectImpType *ScalingOverLineType::resultId() const
{
return ObjectImp::stype();
}
const ObjectImpType *ScalingOverLine2Type::resultId() const
{
return ObjectImp::stype();
}
const ObjectImpType *ProjectiveRotationType::resultId() const
{
return ObjectImp::stype();
}
const ObjectImpType *HarmonicHomologyType::resultId() const
{
return ObjectImp::stype();
}
const ObjectImpType *AffinityB2TrType::resultId() const
{
return ObjectImp::stype();
}
const ObjectImpType *AffinityGI3PType::resultId() const
{
return ObjectImp::stype();
}
const ObjectImpType *ProjectivityB2QuType::resultId() const
{
return ObjectImp::stype();
}
const ObjectImpType *ProjectivityGI4PType::resultId() const
{
return ObjectImp::stype();
}
const ObjectImpType *CastShadowType::resultId() const
{
return ObjectImp::stype();
}
bool TranslatedType::isTransform() const
{
return true;
}
bool PointReflectionType::isTransform() const
{
return true;
}
bool LineReflectionType::isTransform() const
{
return true;
}
bool RotationType::isTransform() const
{
return true;
}
bool ScalingOverCenterType::isTransform() const
{
return true;
}
bool ScalingOverCenter2Type::isTransform() const
{
return true;
}
bool ScalingOverLineType::isTransform() const
{
return true;
}
bool ScalingOverLine2Type::isTransform() const
{
return true;
}
bool ProjectiveRotationType::isTransform() const
{
return true;
}
bool HarmonicHomologyType::isTransform() const
{
return true;
}
bool AffinityB2TrType::isTransform() const
{
return true;
}
bool AffinityGI3PType::isTransform() const
{
return true;
}
bool ProjectivityB2QuType::isTransform() const
{
return true;
}
bool ProjectivityGI4PType::isTransform() const
{
return true;
}
bool CastShadowType::isTransform() const
{
return true;
}
static const ArgsParser::spec argsspecApplyTransformation[] = {
{ObjectImp::stype(), kli18n("Transform this object"), {}, false},
{TransformationImp::stype(), kli18n("Transform using this transformation"), {}, false}};
KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE(ApplyTransformationObjectType)
ApplyTransformationObjectType::ApplyTransformationObjectType()
: ArgsParserObjectType("ApplyTransformation", argsspecApplyTransformation, 2)
{
}
ApplyTransformationObjectType::~ApplyTransformationObjectType()
{
}
const ApplyTransformationObjectType *ApplyTransformationObjectType::instance()
{
static const ApplyTransformationObjectType t;
return &t;
}
ObjectImp *ApplyTransformationObjectType::calc(const Args &args, const KigDocument &) const
{
if (!margsparser.checkArgs(args))
return new InvalidImp;
return args[0]->transform(static_cast<const TransformationImp *>(args[1])->data());
}
const ObjectImpType *ApplyTransformationObjectType::resultId() const
{
return ObjectImp::stype();
}
bool ApplyTransformationObjectType::isTransform() const
{
return true;
}
bool SimilitudeType::isTransform() const
{
return true;
}
const ObjectImpType *SimilitudeType::resultId() const
{
return ObjectImp::stype();
}
const SimilitudeType *SimilitudeType::instance()
{
static const SimilitudeType t;
return &t;
}
ObjectImp *SimilitudeType::calc(const Args &args, const KigDocument &) const
{
if (!margsparser.checkArgs(args))
return new InvalidImp;
Coordinate c = static_cast<const PointImp *>(args[1])->coordinate();
Coordinate a = static_cast<const PointImp *>(args[2])->coordinate();
Coordinate b = static_cast<const PointImp *>(args[3])->coordinate();
a -= c;
b -= c;
double factor = sqrt(b.squareLength() / a.squareLength());
double theta = atan2(b.y, b.x) - atan2(a.y, a.x);
return args[0]->transform(Transformation::similitude(c, theta, factor));
}
SimilitudeType::~SimilitudeType()
{
}
static const ArgsParser::spec argsspecSimilitude[] = {
{ObjectImp::stype(), kli18n("Apply a similitude to this object"), kli18n("Select the object to transform..."), false},
{PointImp::stype(), kli18n("Apply a similitude with this center"), kli18n("Select the center for the similitude..."), false},
{PointImp::stype(),
kli18n("Apply a similitude mapping this point onto another point"),
kli18n("Select the point which the similitude should map onto another point..."),
false},
{PointImp::stype(),
kli18n("Apply a similitude mapping a point onto this point"),
kli18n("Select the point onto which the similitude should map the first point..."),
false}};
KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE(SimilitudeType)
SimilitudeType::SimilitudeType()
: ArgsParserObjectType("Similitude", argsspecSimilitude, 4)
{
}
|