Sorry for this dumb question, but I really don't understand what to do.
First, I'll tell about my task.
I have 5 different polygons and 1 point. I need to find which polygon that point belongs to. I know the algorithm, I'm ok with Nasal as scripting language and absolute dumb with any OOP, but I want to make code nice, so I decided to make it object-oriented.
My idea: create Point class, which defines point with pair of coords. Create Polygon class, which consists of Points, which define vertexes of Polygon. Then create objects: 5 different polygons and my point. And then call to objects like Polygon_A[0].
I have read wiki about Nasal and OOP, but don't understand.
I have used Nasal/geo.nas as example and created this part of code:
- Code: Select all
var Point = {
new: func(x, y) {
var m = { parents: [Point] };
m._x = x;
m._y = y;
},
x: func { me._x },
y: func { me._y },
xy: func { [me._x, me._y] },
};
Now I need to create something similar for Polygon, but don't understand how. I don't know size of polygon (all 5 consist of different number of points). How to do that? Or, maybe, my whole idea is wrong and it will be easier to do it with simple scripting?