Skip to content

Commit 4d9d148

Browse files
committed
Curve base class, structure the project
1 parent 29c413d commit 4d9d148

23 files changed

+1977
-1592
lines changed

beeld.config

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
###################################################
2+
#
3+
# The buildtools repository is at:
4+
# https://github.com/foo123/Beeld
5+
#
6+
###################################################
7+
8+
settings ={}
9+
Xpresion = "Xpresion::"
10+
RegExp = "RegExp::"
11+
@
12+
13+
plugins =[{}]
14+
"minify" = "!plg:minify"
15+
"doc" = "!plg:doc"
16+
@
17+
18+
tasks =[{}]
19+
20+
build =[{}]
21+
22+
src =[]
23+
### Geometrize.js ###
24+
./src/header.js
25+
./src/EventEmitter.js
26+
./src/Style.js
27+
./src/Matrix.js
28+
./src/Primitive.js
29+
./src/Point.js
30+
./src/Curve.js
31+
./src/Line.js
32+
./src/Polyline.js
33+
./src/Arc.js
34+
./src/Bezier2.js
35+
./src/Bezier3.js
36+
./src/Polybezier3.js
37+
./src/Polygon.js
38+
./src/Circle.js
39+
./src/Ellipse.js
40+
./src/Shape.js
41+
./src/utils.js
42+
./src/footer.js
43+
@
44+
45+
# extract header from this file
46+
header = ./src/header.js
47+
48+
replace =[{}]
49+
"@@VERSION@@" = "0.1.0"
50+
"@@DATE@@" = Xpresion::date("Y-m-d H:i:s")
51+
@
52+
53+
# Extract documentation from the source (map)
54+
doc ={}
55+
56+
"startdoc" = "/**[DOC_MARKDOWN]"
57+
"enddoc" = "[/DOC_MARKDOWN]**/"
58+
"trim" = RegExp::^\\s*\\*[ ]?
59+
"output" = "./manual.md"
60+
61+
@
62+
63+
out = ./build/Geometrize.js
64+
@
65+
66+
minify =[{}]
67+
68+
src =[]
69+
./build/Geometrize.js
70+
@
71+
72+
# Minify the Package (map of lists)
73+
minify ={}
74+
# Options for Node UglifyJS Compiler (if used, default), (mangle and compress)
75+
uglifyjs =[]
76+
-m -c
77+
@
78+
79+
# Options for Java Closure Compiler (if used)
80+
closure =[]
81+
"--language_in=ECMASCRIPT5_STRICT"
82+
@
83+
84+
# Options for Java YUI Compressor Compiler (if used)
85+
yui =[]
86+
--preserve-semi
87+
@
88+
@
89+
90+
out = ./build/Geometrize.min.js
91+
@
92+
@

build.bat

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@echo off
2+
3+
REM ###################################################
4+
REM #
5+
REM # The buildtools repository is at:
6+
REM # https://github.com/foo123/Beeld
7+
REM #
8+
REM ###################################################
9+
10+
REM to use the python build tool do:
11+
rem python %BUILDTOOLS%\Beeld.py --config ".\beeld.config"
12+
13+
REM to use the php build tool do:
14+
rem php -f %BUILDTOOLS%\Beeld.php -- --config=".\beeld.config"
15+
16+
REM to use the node build tool do:
17+
node %BUILDTOOLS%\Beeld.js --config ".\beeld.config"

build/Geometrize.js

Whitespace-only changes.

src/Arc.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// 2D Elliptic Arc class
2+
var Arc = makeClass(Curve, {});

src/Bezier2.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// 2D Quadratic Bezier class
2+
var Bezier2 = makeClass(Curve, {});

src/Bezier3.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// 2D Cubic Bezier class
2+
var Bezier3 = makeClass(Curve, {});

src/Circle.js

+181
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
// 2D Circle class
2+
var Circle = makeClass(Curve, {
3+
constructor: function Circle(center, radius) {
4+
var self = this,
5+
_radius = null,
6+
_length = null,
7+
_area = null,
8+
_bbox = null,
9+
_hull = null
10+
;
11+
12+
if (center instanceof Circle) return center;
13+
if (!(self instanceof Circle)) return new Circle(center, radius);
14+
_radius = stdMath.abs(Num(radius));
15+
Curve.call(self, [center]);
16+
17+
Object.defineProperty(self, 'center', {
18+
get() {
19+
return self.points[0];
20+
},
21+
set(center) {
22+
self.points[0] = center;
23+
},
24+
enumerable: true
25+
});
26+
Object.defineProperty(self, 'radius', {
27+
get() {
28+
return _radius;
29+
},
30+
set(radius) {
31+
radius = stdMath.abs(Num(radius));
32+
if (_radius !== radius)
33+
{
34+
var isDirty = false;
35+
if (!is_almost_equal(_radius, radius))
36+
{
37+
isDirty = true;
38+
}
39+
_radius = radius;
40+
if (isDirty)
41+
{
42+
if (!self.isDirty())
43+
{
44+
self.isDirty(true);
45+
self.triggerChange();
46+
}
47+
}
48+
}
49+
},
50+
enumerable: true
51+
});
52+
Object.defineProperty(self, 'length', {
53+
get() {
54+
if (null == _length)
55+
{
56+
_length = 2 * stdMath.PI * _radius;
57+
}
58+
return _length;
59+
},
60+
enumerable: true
61+
});
62+
Object.defineProperty(self, 'area', {
63+
get() {
64+
if (null == _area)
65+
{
66+
_area = stdMath.PI * _radius * _radius;
67+
}
68+
return _area;
69+
},
70+
enumerable: true
71+
});
72+
Object.defineProperty(self, '_bbox', {
73+
get() {
74+
if (null == _bbox)
75+
{
76+
var c = self.center, r = _radius;
77+
_bbox = {
78+
top: c.y - r,
79+
left: c.x - r,
80+
bottom: c.y + r,
81+
right: c.x + r
82+
};
83+
}
84+
return _bbox;
85+
},
86+
enumerable: false
87+
});
88+
Object.defineProperty(self, '_hull', {
89+
get() {
90+
if (null == _hull)
91+
{
92+
var c = self.center, r = _radius;
93+
_hull = [
94+
new Point(c.x-r, c.y-r),
95+
new Point(c.x+r, c.y-r),
96+
new Point(c.x+r, c.y+r),
97+
new Point(c.x-r, c.y+r)
98+
];
99+
}
100+
return _hull;
101+
},
102+
enumerable: false
103+
});
104+
self.isDirty = function(isDirty) {
105+
if (true === isDirty)
106+
{
107+
_length = null;
108+
_area = null;
109+
_bbox = null;
110+
_hull = null;
111+
}
112+
return self.$super.isDirty.apply(self, arguments);
113+
};
114+
},
115+
clone: function() {
116+
return new Circle(this.center.clone(), this.radius);
117+
},
118+
transform: function(matrix) {
119+
var c = this.center,
120+
r = this.radius,
121+
ct = c.transform(matrix),
122+
p = new Point(c.x+r, c.y).transform(matrix)
123+
;
124+
return new Circle(ct, dist(ct, pt));
125+
},
126+
isClosed: function() {
127+
return true;
128+
},
129+
getBoundingBox: function() {
130+
return this._bbox;
131+
},
132+
getConvexHull: function() {
133+
return this._hull;
134+
},
135+
getPoint: function(t) {
136+
t = Num(t);
137+
if (0 > t || 1 < t) return null;
138+
var c = this.center, r = this.radius;
139+
return new Point(
140+
c.x + r*stdMath.cos(t*2*stdMath.PI),
141+
c.y + r*stdMath.sin(t*2*stdMath.PI)
142+
);
143+
},
144+
hasPoint: function(point, notInside) {
145+
var center = this.center,
146+
radius2 = this.radius*this.radius,
147+
dx = point.x - center.x,
148+
dy = point.y - center.y,
149+
d = dx*dx + dy*dy
150+
;
151+
return notInside ? is_almost_equal(d, radius2) : d <= radius2;
152+
},
153+
intersects: function(other) {
154+
if (other instanceof Point)
155+
{
156+
return this.hasPoint(other) ? other : false;
157+
}
158+
else if (other instanceof Line)
159+
{
160+
return line_circle_intersection(other.start, other.end, this.center, this.radius);
161+
}
162+
else if (other instanceof Polyline)
163+
{
164+
}
165+
else if (other instanceof Circle)
166+
{
167+
return circle_circle_intersection(other.center, other.radius, this.center, this.radius);
168+
}
169+
else if ((other instanceof Primitive) && is_function(other.intersects))
170+
{
171+
return other.intersects(this);
172+
}
173+
return false;
174+
},
175+
toTex: function() {
176+
return '\\text{Circle:}'+'(x - '+Str(this.center.x)+')^2 + (y - '+Str(this.center.y)+')^2 = '+Str(this.radius)+'^2';
177+
},
178+
toString: function() {
179+
return 'Circle('+[Str(this.center), Str(this.radius)].join(',')+')';
180+
}
181+
});

0 commit comments

Comments
 (0)