Skip to content

Commit 4ae8103

Browse files
committed
Merge branch 'master' into polygon_polyline
2 parents 94583ed + b98ea24 commit 4ae8103

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+118
-483
lines changed

Sources/AGGRenderer/AGGRenderer/AGGRenderer.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,22 @@ public class AGGRenderer: Renderer{
123123
agg_object)
124124
}
125125

126+
public func drawSolidEllipse(center c: Point,
127+
radiusX rx: Float,
128+
radiusY ry: Float,
129+
fillColor: Color) {
130+
draw_solid_ellipse(c.x + xOffset,
131+
c.y + yOffset,
132+
rx,
133+
ry,
134+
fillColor.r,
135+
fillColor.g,
136+
fillColor.b,
137+
fillColor.a,
138+
agg_object)
139+
}
140+
141+
126142
public func drawSolidTriangle(point1: Point,
127143
point2: Point,
128144
point3: Point,

Sources/AGGRenderer/CAGGRenderer/CAGGRenderer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ void draw_solid_circle(float cx, float cy, float radius, float r, float g, float
2626
CPPAGGRenderer::draw_solid_circle(cx, cy, radius, r, g, b, a, object);
2727
}
2828

29+
void draw_solid_ellipse(float cx, float cy, float rx, float ry, float r, float g, float b, float a, const void *object){
30+
CPPAGGRenderer::draw_solid_ellipse(cx, cy, rx, ry, r, g, b, a, object);
31+
}
32+
2933
void draw_solid_triangle(float x1, float x2, float x3, float y1, float y2, float y3, float r, float g, float b, float a, const void *object){
3034
CPPAGGRenderer::draw_solid_triangle(x1, x2, x3, y1, y2, y3, r, g, b, a, object);
3135
}

Sources/AGGRenderer/CAGGRenderer/include/CAGGRenderer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ void draw_solid_rect_with_border(const float *x, const float *y, float thickness
1616

1717
void draw_solid_circle(float cx, float cy, float radius, float r, float g, float b, float a, const void *object);
1818

19+
void draw_solid_ellipse(float cx, float cy, float rx, float ry, float r, float g, float b, float a, const void *object);
20+
1921
void draw_solid_triangle(float x1, float x2, float x3, float y1, float y2, float y3, float r, float g, float b, float a, const void *object);
2022

2123
void draw_solid_polygon(const float* x, const float* y, int count, float r, float g, float b, float a, const void *object);

Sources/AGGRenderer/CPPAGGRenderer/CPPAGGRenderer.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,21 @@ namespace CPPAGGRenderer{
324324
agg::render_scanlines(m_ras, m_sl_p8, ren_aa);
325325
}
326326

327+
void draw_solid_ellipse(float cx, float cy, float rx, float ry, float r, float g, float b, float a) {
328+
agg::rendering_buffer rbuf = agg::rendering_buffer(buffer, frame_width, frame_height, -frame_width*3);
329+
pixfmt pixf = pixfmt(rbuf);
330+
renderer_base rb = renderer_base(pixf);
331+
ren_aa = renderer_aa(rb);
332+
agg::ellipse ellipse(cx, cy, rx, ry, 100);
333+
Color c(r, g, b, a);
334+
agg::trans_affine matrix;
335+
matrix *= agg::trans_affine_translation(0, 0);
336+
agg::conv_transform<agg::ellipse, agg::trans_affine> trans(ellipse, matrix);
337+
m_ras.add_path(trans);
338+
ren_aa.color(c);
339+
agg::render_scanlines(m_ras, m_sl_p8, ren_aa);
340+
}
341+
327342
void draw_solid_triangle(float x1, float x2, float x3, float y1, float y2, float y3, float r, float g, float b, float a) {
328343
agg::rendering_buffer rbuf = agg::rendering_buffer(buffer, frame_width, frame_height, -frame_width*3);
329344
pixfmt pixf = pixfmt(rbuf);
@@ -539,6 +554,11 @@ namespace CPPAGGRenderer{
539554
plot -> draw_solid_circle(cx, cy, radius, r, g, b, a);
540555
}
541556

557+
void draw_solid_ellipse(float cx, float cy, float rx, float ry, float r, float g, float b, float a, const void *object){
558+
Plot *plot = (Plot *)object;
559+
plot -> draw_solid_ellipse(cx, cy, rx, ry, r, g, b, a);
560+
}
561+
542562
void draw_solid_triangle(float x1, float x2, float x3, float y1, float y2, float y3, float r, float g, float b, float a, const void *object){
543563
Plot *plot = (Plot *)object;
544564
plot -> draw_solid_triangle(x1, x2, x3, y1, y2, y3, r, g, b, a);

Sources/AGGRenderer/CPPAGGRenderer/include/CPPAGGRenderer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ namespace CPPAGGRenderer{
1414

1515
void draw_solid_circle(float cx, float cy, float radius, float r, float g, float b, float a, const void *object);
1616

17+
void draw_solid_ellipse(float cx, float cy, float rx, float ry, float r, float g, float b, float a, const void *object);
18+
1719
void draw_solid_triangle(float x1, float x2, float x3, float y1, float y2, float y3, float r, float g, float b, float a, const void *object);
1820

1921
void draw_solid_polygon(const float* x, const float* y, int count, float r, float g, float b, float a, const void *object);

Sources/QuartzRenderer/QuartzRenderer.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,18 @@ public class QuartzRenderer: Renderer {
348348
context.addEllipse(in: rectBound)
349349
context.drawPath(using: .fill)
350350
}
351+
352+
public func drawSolidEllipse(center c: Point,
353+
radiusX rx: Float,
354+
radiusY ry: Float,
355+
fillColor: Color) {
356+
let ellipse = CGMutablePath()
357+
ellipse.addEllipse(in: CGRect(x: CGFloat(c.x-rx), y: CGFloat(c.y-ry), width: CGFloat(rx*2), height: CGFloat(ry*2)),
358+
transform: CGAffineTransform(translationX: CGFloat(xOffset), y: CGFloat(yOffset)))
359+
context.setFillColor(fillColor.cgColor)
360+
context.addPath(ellipse)
361+
context.fillPath()
362+
}
351363

352364
public func drawSolidTriangle(point1: Point,
353365
point2: Point,

Sources/SVGRenderer/SVGRenderer.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public class SVGRenderer: Renderer{
6868
lines.append(rectStr)
6969
drawHatchingRect(rect, hatchPattern: hatchPattern)
7070
}
71-
71+
7272
func drawHatchingRect(_ rect: Rect,
7373
hatchPattern: BarGraphSeriesOptions.Hatching) {
7474
let patternName: String
@@ -145,6 +145,15 @@ public class SVGRenderer: Renderer{
145145
lines.append(circle)
146146
}
147147

148+
public func drawSolidEllipse(center c: Point,
149+
radiusX rx: Float,
150+
radiusY ry: Float,
151+
fillColor: Color) {
152+
let c = convertToSVGCoordinates(c)
153+
let circle: String = #"<ellipse cx="\#(c.x)" cy="\#(c.y)" rx="\#(rx)" ry="\#(ry)" style="fill:\#(fillColor.svgColorString);opacity:\#(fillColor.a)" />"#
154+
lines.append(circle)
155+
}
156+
148157
public func drawSolidTriangle(point1: Point,
149158
point2: Point,
150159
point3: Point,

Sources/SwiftPlot/Renderer.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,23 @@ public protocol Renderer: AnyObject{
129129
radius r: Float,
130130
fillColor: Color)
131131

132+
133+
/*drawSolidEllipse()
134+
*params: center c: Point,
135+
* radius rx: Float,
136+
* radius rx: Float,
137+
* fillColor: Color,
138+
* isOriginShifted: Bool
139+
*description: Draws an ellipse with specified fill color, center and radii
140+
* This function can operate in both coordinate systems with and
141+
* without shifted origin.
142+
* This is decided by the boolean parameter isOriginShifted.
143+
*/
144+
func drawSolidEllipse(center c: Point,
145+
radiusX rx: Float,
146+
radiusY ry: Float,
147+
fillColor: Color)
148+
132149
/*drawSolidTriangle()
133150
*params: point1: Point,
134151
* point2: Point,

Tests/SwiftPlotTests/Annotation/annotation-arrow-dart.swift

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,6 @@ extension AnnotationTests {
3030
startAnnotation: Text(text: "relative maxima",
3131
direction: .west)))
3232

33-
let svg_renderer = SVGRenderer()
34-
try lineGraph.drawGraphAndOutput(fileName: svgOutputDirectory+fileName,
35-
renderer: svg_renderer)
36-
verifyImage(name: fileName, renderer: .svg)
37-
#if canImport(AGGRenderer)
38-
let agg_renderer = AGGRenderer()
39-
try lineGraph.drawGraphAndOutput(fileName: aggOutputDirectory+fileName,
40-
renderer: agg_renderer)
41-
verifyImage(name: fileName, renderer: .agg)
42-
#endif
43-
/*
44-
#if canImport(QuartzRenderer)
45-
let quartz_renderer = QuartzRenderer()
46-
try lineGraph.drawGraphAndOutput(fileName: coreGraphicsOutputDirectory+fileName,
47-
renderer: quartz_renderer)
48-
verifyImage(name: fileName, renderer: .coreGraphics)
49-
#endif
50-
*/
33+
try renderAndVerify(lineGraph, fileName: fileName)
5134
}
5235
}

Tests/SwiftPlotTests/Annotation/annotation-arrow-double-headed.swift

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,6 @@ extension AnnotationTests {
2626
end: Point(585.0, 585.0),
2727
isDoubleHeaded: true))
2828

29-
let svg_renderer = SVGRenderer()
30-
try lineGraph.drawGraphAndOutput(fileName: svgOutputDirectory+fileName,
31-
renderer: svg_renderer)
32-
verifyImage(name: fileName, renderer: .svg)
33-
#if canImport(AGGRenderer)
34-
let agg_renderer = AGGRenderer()
35-
try lineGraph.drawGraphAndOutput(fileName: aggOutputDirectory+fileName,
36-
renderer: agg_renderer)
37-
verifyImage(name: fileName, renderer: .agg)
38-
#endif
39-
/*
40-
#if canImport(QuartzRenderer)
41-
let quartz_renderer = QuartzRenderer()
42-
try lineGraph.drawGraphAndOutput(fileName: coreGraphicsOutputDirectory+fileName,
43-
renderer: quartz_renderer)
44-
verifyImage(name: fileName, renderer: .coreGraphics)
45-
#endif
46-
*/
29+
try renderAndVerify(lineGraph, fileName: fileName)
4730
}
4831
}

0 commit comments

Comments
 (0)