Skip to content

Some fun in CRUD

August 13, 2012

I hate crud, but who doesn’t? Also, I no matter how much as I hate it, I still need to do it sometimes. But then again, who doesn’t?

So I had this task: on map event click, all its properties should be arranged in a circle around it. Sounds like a perfect CRUD task: user created an event and added some properties to it, it is now displayed on map. Now on click, I only have to collect all its properties and display them nicely.

But how do I display them in a perfect circle? Well here is some fun from high school, use SIN and COS functions to do it. Here is an example:

Event event = GetSelectedEvent();
EventProperty[] eventProperties = event.GetProperties();

int xDelta = 0;
int yDelta = 0;
int lambda = 0;

foreach (var eventProperty in eventProperties)
{                       
    xDelta = (int)(Math.Cos(lambda * Math.PI / 180) * 200);
    yDelta = (int)(Math.Sin(lambda * Math.PI / 180) * 200);
    lambda += 360 / eventProperties.Count;
    AddSymbol(LayerId, event.xCoord + xDelta, event.yCoord + yDelta, eventProperty.Type);
}

It is just a small piece of code, but for some reason I was very happy to write it. Even CRUD can be fun sometimes!

Advertisements
3 Comments leave one →
  1. August 27, 2012 18:56

    Why do you see it as Create, Read, Update, Delete?
    I don’t get that.

    Or have I missabbreviated something?
    http://discuss.joelonsoftware.com/default.asp?biz.5.368790.18

    • August 27, 2012 19:09

      Because basically I’ve had to read data from Database and display it in a beautiful form; if it is using API for map engine or some report engine doesn’t really matter; for me this means CRUD. But I’ve had some fun with math, so maybe it isn’t that much of a CRUD anymore… 🙂

    • August 27, 2012 19:10

      oh, and thanks for the link!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: