Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

GetPointCount() is now a property #41

Closed
wants to merge 1 commit into from

3 participants

@zsbzsb
Collaborator

It was impossible to change the SetPointCount on the circle and rectangle shapes because it is impossible to change the get/set definition of a property when overriding. So this is the best I can do for this. See the following link for more information.

http://stackoverflow.com/questions/82437/why-is-it-impossible-to-override-a-getter-only-property-and-add-a-setter

@LaurentGomila

Reminds me of something... I got stuck with the same problem, and ended up choosing consistency over making it a property at all costs.

I think this should be discussed further.

@dejangeci

tldr: I'd keep it both as functions because it looks weird.

The problem, as I see it, is that all classes derived from Shape are convenience classes that don't fit the inheritance model. How come? Well, isn't RectangleShape actually a ConvexShape with 4 points that are distributed in a particular manner? Circle also?

This is why C# isn't working to our advantage.

What we have here is one of the real-world-usage-convenience/language-inheritance-limitation clashes, since circle is essentially a ConvexShape with many points, so it gives the illusion of being a circle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 23, 2014
  1. @zsbzsb
This page is out of date. Refresh to see the latest.
View
9 src/Graphics/CircleShape.cs
@@ -58,7 +58,7 @@ public CircleShape(float radius, uint pointCount)
base(copy)
{
Radius = copy.Radius;
- SetPointCount(copy.GetPointCount());
+ SetPointCount(copy.PointCount);
}
////////////////////////////////////////////////////////////
@@ -74,13 +74,12 @@ public float Radius
////////////////////////////////////////////////////////////
/// <summary>
- /// Get the total number of points of the shape
+ /// The total number of points of the shape
/// </summary>
- /// <returns>The total point count</returns>
////////////////////////////////////////////////////////////
- public override uint GetPointCount()
+ public override uint PointCount
{
- return myPointCount;
+ get { return myPointCount; }
}
////////////////////////////////////////////////////////////
View
11 src/Graphics/ConvexShape.cs
@@ -44,20 +44,19 @@ public ConvexShape(uint pointCount)
public ConvexShape(ConvexShape copy) :
base(copy)
{
- SetPointCount(copy.GetPointCount());
- for (uint i = 0; i < copy.GetPointCount(); ++i)
+ SetPointCount(copy.PointCount);
+ for (uint i = 0; i < copy.PointCount; ++i)
SetPoint(i, copy.GetPoint(i));
}
////////////////////////////////////////////////////////////
/// <summary>
- /// Get the total number of points of the shape
+ /// The total number of points of the shape
/// </summary>
- /// <returns>The total point count</returns>
////////////////////////////////////////////////////////////
- public override uint GetPointCount()
+ public override uint PointCount
{
- return (uint)myPoints.Length;
+ get { return (uint)myPoints.Length; }
}
////////////////////////////////////////////////////////////
View
7 src/Graphics/RectangleShape.cs
@@ -60,13 +60,12 @@ public Vector2f Size
////////////////////////////////////////////////////////////
/// <summary>
- /// Get the total number of points of the shape
+ /// The total number of points of the shape
/// </summary>
- /// <returns>The total point count</returns>
////////////////////////////////////////////////////////////
- public override uint GetPointCount()
+ public override uint PointCount
{
- return 4;
+ get { return 4; }
}
////////////////////////////////////////////////////////////
View
7 src/Graphics/Shape.cs
@@ -71,11 +71,10 @@ public float OutlineThickness
////////////////////////////////////////////////////////////
/// <summary>
- /// Get the total number of points of the shape
+ /// The total number of points of the shape
/// </summary>
- /// <returns>The total point count</returns>
////////////////////////////////////////////////////////////
- public abstract uint GetPointCount();
+ public abstract uint PointCount { get; }
////////////////////////////////////////////////////////////
/// <summary>
@@ -220,7 +219,7 @@ protected override void Destroy(bool disposing)
////////////////////////////////////////////////////////////
private uint InternalGetPointCount(IntPtr userData)
{
- return GetPointCount();
+ return PointCount;
}
////////////////////////////////////////////////////////////
Something went wrong with that request. Please try again.