diff --git a/icons/22-actions-segment_golden_point.png b/icons/22-actions-segment_golden_point.png
new file mode 100644
diff --git a/icons/32-actions-segment_golden_point.png b/icons/32-actions-segment_golden_point.png
new file mode 100644
diff --git a/icons/CMakeLists.txt b/icons/CMakeLists.txt
--- a/icons/CMakeLists.txt
+++ b/icons/CMakeLists.txt
@@ -17,6 +17,7 @@
22-actions-perpendicular.png
32-actions-circlebps.png
sc-actions-segment_midpoint.svgz
+ sc-actions-segment_golden_point.svgz
32-actions-genericaffinity.png
sc-actions-bezier4.svgz
32-actions-ellipsebffp.png
@@ -117,6 +118,7 @@
22-actions-genericaffinity.png
32-actions-testcontains.png
22-actions-segment_midpoint.png
+ 22-actions-segment_golden_point.png
32-actions-kig_text.png
22-actions-conicasymptotes.png
22-actions-directrix.png
@@ -220,6 +222,7 @@
sc-actions-bezierN.svgz
sc-actions-radicalline.svgz
32-actions-segment_midpoint.png
+ 32-actions-segment_golden_point.png
sc-actions-slope.svgz
32-actions-ray.png
22-actions-projection.png
diff --git a/icons/sc-actions-segment_golden_point.svgz b/icons/sc-actions-segment_golden_point.svgz
new file mode 100644
diff --git a/kig/kigpartui.rc b/kig/kigpartui.rc
--- a/kig/kigpartui.rc
+++ b/kig/kigpartui.rc
@@ -37,7 +37,8 @@
&Points
-
+
+
diff --git a/misc/builtin_stuff.cc b/misc/builtin_stuff.cc
--- a/misc/builtin_stuff.cc
+++ b/misc/builtin_stuff.cc
@@ -294,6 +294,32 @@
actions->add( new ConstructibleAction( &m, "objects_new_midpoint", Qt::Key_M ) );
};
+ {
+ // now for the Golden Ratio Point action. It does both the golden ratio point of
+ // a segment, and the golden ratio point of two points. The golden ratio point of
+ // two segments just shows the golden ratio point property, and therefore
+ // doesn't need to be added to the ctors, because there are
+ // already facilities to construct an object's properties..
+ // therefore, we add only an mpotp to the ctors, and add the
+ // merged constructor only to the actions..
+ ctors->add( new GoldenPointOfTwoPointsConstructor() );
+
+ ObjectConstructor* mpotp = new GoldenPointOfTwoPointsConstructor();
+ ObjectConstructor* mpos = new PropertyObjectConstructor(
+ SegmentImp::stype(), I18N_NOOP( "Construct the golden ratio point of this segment" ),
+ "", "", "", "", "golden-point" );
+
+ // make this a static object, so it gets deleted at the end of
+ // the program.
+ static MergeObjectConstructor m(
+ I18N_NOOP( "Golden Ratio Point" ),
+ I18N_NOOP( "The golden ratio point of a segment or two other points" ),
+ "segment_golden_point" );
+ m.merge( mpotp );
+ m.merge( mpos );
+ actions->add( new ConstructibleAction( &m, "objects_new_golden_point", Qt::Key_G ) );
+ };
+
c = new SimpleObjectTypeConstructor(
VectorType::instance(),
I18N_NOOP( "Vector" ),
diff --git a/misc/special_constructors.h b/misc/special_constructors.h
--- a/misc/special_constructors.h
+++ b/misc/special_constructors.h
@@ -409,6 +409,21 @@
bool isTransform() const Q_DECL_OVERRIDE;
};
+class GoldenPointOfTwoPointsConstructor
+ : public StandardConstructorBase
+{
+ ArgsParser mparser;
+public:
+ GoldenPointOfTwoPointsConstructor();
+ ~GoldenPointOfTwoPointsConstructor();
+ void drawprelim( const ObjectDrawer& drawer, KigPainter& p, const std::vector& parents,
+ const KigDocument& ) const Q_DECL_OVERRIDE;
+ std::vector build( const std::vector& os, KigDocument& d,
+ KigWidget& w ) const Q_DECL_OVERRIDE;
+ void plug( KigPart* doc, KigGUIAction* kact ) Q_DECL_OVERRIDE;
+ bool isTransform() const Q_DECL_OVERRIDE;
+};
+
class TestConstructor
: public StandardConstructorBase
{
diff --git a/misc/special_constructors.cc b/misc/special_constructors.cc
--- a/misc/special_constructors.cc
+++ b/misc/special_constructors.cc
@@ -2056,7 +2056,7 @@
static const ArgsParser::spec argsspecMidPointOfTwoPoints[] =
{
- { PointImp::stype(), I18N_NOOP( "Construct Midpoint of This Point and Another One" ),
+ { PointImp::stype(), I18N_NOOP( "Construct midpoint of this point and another one" ),
I18N_NOOP( "Select the first of the points of which you want to construct the midpoint..." ), false },
{ PointImp::stype(), I18N_NOOP( "Construct the midpoint of this point and another one" ),
I18N_NOOP( "Select the other of the points of which to construct the midpoint..." ), false }
@@ -2110,6 +2110,66 @@
return false;
}
+static const ArgsParser::spec argsspecGoldenPointOfTwoPoints[] =
+{
+ { PointImp::stype(), I18N_NOOP( "Construct golden ratio point of this point and another one" ),
+ I18N_NOOP( "Select the first of the points of which you want to construct the golden ratio point..." ), false },
+ { PointImp::stype(), I18N_NOOP( "Construct the golden ratio point of this point and another one" ),
+ I18N_NOOP( "Select the other of the points of which to construct the golden ratio point..." ), false }
+};
+
+GoldenPointOfTwoPointsConstructor::GoldenPointOfTwoPointsConstructor()
+ : StandardConstructorBase( "Golden Ratio Point",
+ "Construct the golden ratio point of two points",
+ "bisection", mparser ),
+ mparser( argsspecGoldenPointOfTwoPoints, 2 )
+{
+}
+
+GoldenPointOfTwoPointsConstructor::~GoldenPointOfTwoPointsConstructor()
+{
+}
+
+void GoldenPointOfTwoPointsConstructor::drawprelim(
+ const ObjectDrawer& drawer, KigPainter& p, const std::vector& parents,
+ const KigDocument& ) const
+{
+ if ( parents.size() != 2 ) return;
+ assert( parents[0]->imp()->inherits( PointImp::stype() ) );
+ assert( parents[1]->imp()->inherits( PointImp::stype() ) );
+ const Coordinate m =
+ ( static_cast( parents[0]->imp() )->coordinate() +
+ (sqrt(5) - 1) / 2 *
+ ( static_cast( parents[1]->imp() )->coordinate() -
+ static_cast( parents[0]->imp() )->coordinate()
+ )
+ );
+ drawer.draw( PointImp( m ), p, true );
+}
+
+std::vector GoldenPointOfTwoPointsConstructor::build(
+ const std::vector& os, KigDocument& d, KigWidget& ) const
+{
+ ObjectTypeCalcer* seg = new ObjectTypeCalcer( SegmentABType::instance(), os );
+ seg->calc( d );
+// int index = seg->imp()->propertiesInternalNames().indexOf( "golden-point" );
+// assert( index != -1 );
+ ObjectPropertyCalcer* prop = new ObjectPropertyCalcer( seg, "golden-point" );
+ prop->calc( d );
+ std::vector ret;
+ ret.push_back( new ObjectHolder( prop ) );
+ return ret;
+}
+
+void GoldenPointOfTwoPointsConstructor::plug( KigPart*, KigGUIAction* )
+{
+}
+
+bool GoldenPointOfTwoPointsConstructor::isTransform() const
+{
+ return false;
+}
+
TestConstructor::TestConstructor( const ArgsParserObjectType* type, const char* descname,
const char* desc, const char* iconfile )
: StandardConstructorBase( descname, desc, iconfile, type->argsParser() ),
diff --git a/objects/line_imp.cc b/objects/line_imp.cc
--- a/objects/line_imp.cc
+++ b/objects/line_imp.cc
@@ -100,14 +100,15 @@
int SegmentImp::numberOfProperties() const
{
- return Parent::numberOfProperties() + 5;
+ return Parent::numberOfProperties() + 6;
}
const QByteArrayList SegmentImp::propertiesInternalNames() const
{
QByteArrayList s = Parent::propertiesInternalNames();
s << "length";
s << "mid-point";
+ s << "golden-point";
s << "support";
s << "end-point-A";
s << "end-point-B";
@@ -120,6 +121,7 @@
QByteArrayList s = Parent::properties();
s << I18N_NOOP( "Length" );
s << I18N_NOOP( "Mid Point" );
+ s << I18N_NOOP( "Golden Ratio Point" );
s << I18N_NOOP( "Support Line" );
s << I18N_NOOP( "First End Point" );
s << I18N_NOOP( "Second End Point" );
@@ -143,6 +145,8 @@
return "distance"; // length
else if ( which == Parent::numberOfProperties() + pnum++ )
return "segment_midpoint"; // mid point
+ else if ( which == Parent::numberOfProperties() + pnum++ )
+ return "segment_golden_point"; // golden ratio point
else if ( which == Parent::numberOfProperties() + pnum++ )
return ""; // support line
else if ( which == Parent::numberOfProperties() + pnum++ )
@@ -163,6 +167,8 @@
return new DoubleImp( mdata.dir().length() );
else if ( which == Parent::numberOfProperties() + pnum++ )
return new PointImp( ( mdata.a + mdata.b ) / 2 );
+ else if ( which == Parent::numberOfProperties() + pnum++ )
+ return new PointImp( mdata.a + (sqrt(5) - 1) / 2 * (mdata.b - mdata.a) );
else if ( which == Parent::numberOfProperties() + pnum++ )
return new LineImp( mdata.a, mdata.b );
else if ( which == Parent::numberOfProperties() + pnum++ )
diff --git a/objects/point_type.h b/objects/point_type.h
--- a/objects/point_type.h
+++ b/objects/point_type.h
@@ -149,6 +149,18 @@
const ObjectImpType* resultId() const Q_DECL_OVERRIDE;
};
+class GoldenPointType
+ : public ObjectABType
+{
+ GoldenPointType();
+ ~GoldenPointType();
+public:
+ static const GoldenPointType* instance();
+ // calcx was an overloaded calc, which produced a compilation warning
+ ObjectImp* calcx( const Coordinate& a, const Coordinate& b ) const Q_DECL_OVERRIDE;
+ const ObjectImpType* resultId() const Q_DECL_OVERRIDE;
+};
+
class MeasureTransportType
: public ObjectType
{
diff --git a/objects/point_type.cc b/objects/point_type.cc
--- a/objects/point_type.cc
+++ b/objects/point_type.cc
@@ -288,6 +288,36 @@
return new PointImp( ( a + b ) / 2 );
}
+static const ArgsParser::spec argsspecGoldenPoint[] =
+{
+ { PointImp::stype(), I18N_NOOP( "Construct the golden ratio point of this point and another point" ),
+ I18N_NOOP( "Select the first of the two points of which you want to construct the golden ratio point..." ), false },
+ { PointImp::stype(), I18N_NOOP( "Construct the golden ratio point of this point and another point" ),
+ I18N_NOOP( "Select the other of the two points of which you want to construct the golden ratio point..." ), false }
+};
+
+KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( GoldenPointType )
+
+GoldenPointType::GoldenPointType()
+ : ObjectABType( "GoldenPoint", argsspecGoldenPoint, 2 )
+{
+}
+
+GoldenPointType::~GoldenPointType()
+{
+}
+
+const GoldenPointType* GoldenPointType::instance()
+{
+ static const GoldenPointType t;
+ return &t;
+}
+
+ObjectImp* GoldenPointType::calcx( const Coordinate& a, const Coordinate& b ) const
+{
+ return new PointImp( a + (sqrt(5) - 1) * (b - a) / 2 );
+}
+
bool ConstrainedPointType::inherits( int type ) const
{
return type == ID_ConstrainedPointType;
@@ -362,6 +392,11 @@
return PointImp::stype();
}
+const ObjectImpType* GoldenPointType::resultId() const
+{
+ return PointImp::stype();
+}
+
QStringList FixedPointType::specialActions() const
{
QStringList ret;