add Arc patch

This commit is contained in:
wyq 2023-05-03 23:02:02 +08:00
parent cf5cacd028
commit d107e5a585
12 changed files with 232 additions and 53 deletions

View File

@ -159,10 +159,12 @@ public class Plot2D extends AbstractPlot2D {
@Override
void drawGraph(Graphics2D g, Rectangle2D area) {
if (isPiePlot()){
/*if (isPiePlot()){
plotPie(g, area);
} else
plotGraphics(g, area);
plotGraphics(g, area);*/
plotGraphics(g, area);
}
private boolean isPiePlot(){

View File

@ -15,7 +15,7 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<freehep.version>2.4</freehep.version>
<flatlaf.version>3.1</flatlaf.version>
<flatlaf.version>3.1.1</flatlaf.version>
</properties>
<repositories>

View File

@ -19,9 +19,8 @@ import org.meteoinfo.geometry.legend.*;
import org.meteoinfo.geometry.geoprocess.Spline;
import org.meteoinfo.common.colors.ColorUtil;
import org.meteoinfo.geometry.graphic.Graphic;
import org.meteoinfo.geometry.shape.Polyline;
import org.meteoinfo.geometry.shape.WindArrow;
import org.meteoinfo.geometry.shape.WindBarb;
import org.meteoinfo.geometry.shape.*;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
@ -49,10 +48,6 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import org.meteoinfo.geometry.shape.EllipseShape;
import org.meteoinfo.geometry.shape.Polygon;
import org.meteoinfo.geometry.shape.PolygonShape;
import org.meteoinfo.geometry.shape.StationModelShape;
import org.scilab.forge.jlatexmath.TeXConstants;
import org.scilab.forge.jlatexmath.TeXFormula;
import org.scilab.forge.jlatexmath.TeXIcon;
@ -2440,9 +2435,9 @@ public class Draw {
* @param points The points
* @param aGraphic The graphic
* @param g Graphics2D
* @param isEditingVertice Is editing vertice
* @param isEditingVertices Is editing vertices
*/
public static void drawGrahpic(PointF[] points, Graphic aGraphic, Graphics2D g, boolean isEditingVertice) {
public static void drawGraphic(PointF[] points, Graphic aGraphic, Graphics2D g, boolean isEditingVertices) {
Rectangle rect = new Rectangle();
Extent aExtent = MIMath.getPointFsExtent(points);
rect.x = (int) aExtent.minX;
@ -2498,11 +2493,16 @@ public class Draw {
EllipseShape eshape = (EllipseShape) aGraphic.getShape();
drawEllipse(points, eshape.getAngle(), (PolygonBreak) aGraphic.getLegend(), g);
break;
case ARC:
ArcShape arcShape = (ArcShape) aGraphic.getShape();
drawArc(points, arcShape.getAngle(), arcShape.getStartAngle(), arcShape.getSweepAngle(),
(PolygonBreak) aGraphic.getLegend(), g);
break;
}
//Draw selected rectangle
if (aGraphic.getShape().isSelected()) {
if (isEditingVertice) {
if (isEditingVertices) {
drawSelectedVertices(g, points);
} else {
float[] dashPattern = new float[]{2.0F, 1.0F};
@ -4116,7 +4116,7 @@ public class Draw {
* @param points The points
* @param angle The angle
* @param aPGB The polygon break
* @param g Grahpics2D
* @param g Graphics2D
*/
public static void drawEllipse(PointF[] points, float angle, PolygonBreak aPGB, Graphics2D g) {
float sx = Math.min(points[0].X, points[2].X);
@ -4165,7 +4165,7 @@ public class Draw {
*
* @param points The points
* @param aPGB The polygon break
* @param g Grahpics2D
* @param g Graphics2D
*/
public static void drawEllipse(PointF[] points, PolygonBreak aPGB, Graphics2D g) {
float sx = Math.min(points[0].X, points[2].X);
@ -4184,6 +4184,37 @@ public class Draw {
}
}
/**
* Draw Arc
*
* @param points The points
* @param angle The angle
* @param aPGB The polygon break
* @param g Graphics2D
*/
public static void drawArc(PointF[] points, float angle, float startAngle, float sweepAngle,
PolygonBreak aPGB, Graphics2D g) {
float sx = Math.min(points[0].X, points[2].X);
float sy = Math.min(points[0].Y, points[2].Y);
float width = Math.abs(points[2].X - points[0].X);
float height = Math.abs(points[2].Y - points[0].Y);
if (angle != 0) {
AffineTransform tempTrans = g.getTransform();
AffineTransform myTrans = (AffineTransform) tempTrans.clone();
myTrans.translate(sx + width / 2, sy + height / 2);
g.setTransform(myTrans);
Draw.drawPie(new PointF((float)sx, (float)sy),
(float) width, (float) height, startAngle, sweepAngle, aPGB, g);
g.setTransform(tempTrans);
} else {
Draw.drawPie(new PointF((float)sx, (float)sy),
(float) width, (float) height, startAngle, sweepAngle, aPGB, g);
}
}
/**
* Draw selected vertices rectangles
*

View File

@ -112,7 +112,6 @@ import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
@ -120,7 +119,6 @@ import java.util.logging.Logger;
import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageTypeSpecifier;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
import javax.imageio.metadata.IIOMetadata;
import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
@ -5952,6 +5950,7 @@ public class MapView extends JPanel implements IWebMapPanel {
case CIRCLE:
case CURVE_POLYGON:
case ELLIPSE:
case ARC:
if (((PolygonBreak) aGraphic.getLegend()).isMaskout()) {
setClipRegion(g);
}
@ -5961,23 +5960,12 @@ public class MapView extends JPanel implements IWebMapPanel {
//Get screen points
double[] sXY;
List<PointD> points = (List<PointD>) aGraphic.getShape().getPoints();
// if (aGraphic.getShape().getShapeType().isPolygon()){
// this.drawPolygonShape(g, (PolygonShape)aGraphic.getShape(),
// (PolygonBreak)aGraphic.getLegend(), lonShift);
// } else {
// PointF[] screenPoints = new PointF[points.size()];
// for (int i = 0; i < points.size(); i++) {
// sXY = projToScreen(points.get(i).X, points.get(i).Y, lonShift);
// screenPoints[i] = new PointF((float) sXY[0], (float) sXY[1]);
// }
// Draw.drawGrahpic(screenPoints, aGraphic, g, _mouseTool == MouseTools.EditVertices);
// }
PointF[] screenPoints = new PointF[points.size()];
for (int i = 0; i < points.size(); i++) {
sXY = projToScreen(points.get(i).X, points.get(i).Y, lonShift);
screenPoints[i] = new PointF((float) sXY[0], (float) sXY[1]);
}
Draw.drawGrahpic(screenPoints, aGraphic, g, _mouseTool == MouseTools.EDIT_VERTICES);
Draw.drawGraphic(screenPoints, aGraphic, g, _mouseTool == MouseTools.EDIT_VERTICES);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, rend);
}

View File

@ -153,8 +153,13 @@ public class GeoComputation {
return false;
}
if (aPolygon instanceof CircleShape) {
return ((CircleShape) aPolygon).contains(aPoint);
switch (aPolygon.getShapeType()) {
case CIRCLE:
return ((CircleShape) aPolygon).contains(aPoint);
case ELLIPSE:
return ((EllipseShape) aPolygon).contains(aPoint);
case ARC:
return ((ArcShape) aPolygon).contains(aPoint);
}
boolean isIn = false;

View File

@ -13,13 +13,16 @@
*/
package org.meteoinfo.geometry.shape;
import org.meteoinfo.common.PointD;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Yaqiang Wang
*/
public class ArcShape extends PolygonShape {
public class ArcShape extends EllipseShape {
// <editor-fold desc="Variables">
private float startAngle;
private float sweepAngle;
@ -27,7 +30,28 @@ public class ArcShape extends PolygonShape {
private Float wedgeWidth = null;
// </editor-fold>
// <editor-fold desc="Constructor">
/**
* Constructor
*/
public ArcShape() {
}
/**
* Constructor
* @param x Center x
* @param y Center y
* @param width Width
* @param height Height
*/
public ArcShape(double x, double y, double width, double height) {
List<PointD> points = new ArrayList<>();
points.add(new PointD(x - width * 0.5, y - height * 0.5));
points.add(new PointD(x - width * 0.5, y + height * 0.5));
points.add(new PointD(x + width * 0.5, y + height * 0.5));
points.add(new PointD(x + width * 0.5, y - height * 0.5));
super.setPoints(points);
}
// </editor-fold>
// <editor-fold desc="Get Set Methods">
@Override
@ -101,6 +125,35 @@ public class ArcShape extends PolygonShape {
// </editor-fold>
// <editor-fold desc="Methods">
/**
* If this shape contains a point
* @param p Point
* @return Contains a point or not
*/
public boolean contains(PointD p){
PointD center = this.getCenter();
double a = this.getA();
double b = this.getB();
// checking the equation of
// ellipse with the given point
double r = (Math.pow((p.X - center.X), 2)
/ Math.pow(a, 2))
+ (Math.pow((p.Y - center.Y), 2)
/ Math.pow(b, 2));
if (r > 1) {
return false;
}
double angle = Math.toDegrees(Math.atan2(p.Y - center.Y, p.X - center.X));
if (angle < 0) {
angle += 360;
}
return angle >= this.startAngle && angle <= this.startAngle + this.sweepAngle;
}
/**
* Clone
*

View File

@ -14,6 +14,7 @@
package org.meteoinfo.geometry.shape;
import org.meteoinfo.common.PointD;
import org.meteoinfo.geometry.geoprocess.GeoComputation;
import org.meteoinfo.geometry.geoprocess.GeometryUtil;
import java.util.ArrayList;
@ -26,7 +27,7 @@
*/
public class EllipseShape extends PolygonShape {
// <editor-fold desc="Variables">
private float angle = 0.0f;
protected float angle = 0.0f;
// </editor-fold>
// <editor-fold desc="Constructor">
@ -45,10 +46,10 @@
*/
public EllipseShape(double x, double y, double width, double height) {
List<PointD> points = new ArrayList<>();
points.add(new PointD(x - width * 0.5, y));
points.add(new PointD(x, y - height * 0.5));
points.add(new PointD(x + width * 0.5, y));
points.add(new PointD(x, y + height * 0.5));
points.add(new PointD(x - width * 0.5, y - height * 0.5));
points.add(new PointD(x - width * 0.5, y + height * 0.5));
points.add(new PointD(x + width * 0.5, y + height * 0.5));
points.add(new PointD(x + width * 0.5, y - height * 0.5));
super.setPoints(points);
}
@ -103,6 +104,42 @@
// </editor-fold>
// <editor-fold desc="Methods">
/**
* Get semi-major axis a
* @return Semi-major axis a
*/
public double getA() {
return getWidth() / 2;
}
/**
* Get semi-minor axis b
* @return Semi-minor axis b
*/
public double getB() {
return getHeight() / 2;
}
/**
* If this shape contains a point
* @param p Point
* @return Contains a point or not
*/
public boolean contains(PointD p){
PointD center = this.getCenter();
double a = this.getA();
double b = this.getB();
// checking the equation of
// ellipse with the given point
double r = ((double)Math.pow((p.X - center.X), 2)
/ (double)Math.pow(a, 2))
+ ((double)Math.pow((p.Y - center.Y), 2)
/ (double)Math.pow(b, 2));
return r <= 1;
}
/**
* Clone
*

View File

@ -40,6 +40,14 @@ public class PointShape extends Shape implements Cloneable{
public PointShape(){
}
/**
* Constructor
* @param point The point
*/
public PointShape(PointD point) {
this.setPoint(point);
}
/**
* Constructor

View File

@ -1,12 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<MeteoInfo File="milconfig.xml" Type="configurefile">
<Path OpenPath="D:\Working\MIScript\Jython\mis\traj">
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\3d_earth"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\funny"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\chart"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\chart\legend"/>
<Path OpenPath="D:\Working\MIScript\Jython\mis\map\maskout">
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\dataframe"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\streamplot"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl"/>
@ -14,21 +8,27 @@
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\radar"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\ascii"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\traj"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\chart"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\pie"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\map"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\patch"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\map\maskout"/>
</Path>
<File>
<OpenedFiles>
<OpenedFile File="D:\Working\MIScript\Jython\mis\dataframe\dataframe_1.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\dataframe\reindex_1.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\streamslice\streamslice_xy_1.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\traj\cluster_1.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\map\maskout\maskout_data_arc_1.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\map\maskout\maskout_data_arc.py"/>
</OpenedFiles>
<RecentFiles>
<RecentFile File="D:\Working\MIScript\Jython\mis\dataframe\dataframe_1.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\dataframe\reindex_1.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\streamslice\streamslice_xy_1.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\traj\cluster_1.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\map\maskout\maskout_data_arc_1.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\map\maskout\maskout_data_arc.py"/>
</RecentFiles>
</File>
<Font>
@ -36,5 +36,5 @@
</Font>
<LookFeel DockWindowDecorated="true" LafDecorated="true" Name="FlatDarkLaf"/>
<Figure DoubleBuffering="true"/>
<Startup MainFormLocation="-7,0" MainFormSize="1394,799"/>
<Startup MainFormLocation="-7,-7" MainFormSize="1293,685"/>
</MeteoInfo>

View File

@ -3052,12 +3052,14 @@ class Axes(object):
for graphic in graphics:
self.add_graphic(graphic)
self._axes.setAutoExtent()
self._axes.setAspectType(AspectType.EQUAL)
self._axes.getAxis(Location.BOTTOM).setVisible(False)
self._axes.getAxis(Location.LEFT).setVisible(False)
self._axes.getAxis(Location.TOP).setVisible(False)
self._axes.getAxis(Location.RIGHT).setVisible(False)
self._axes.setClip(False)
return tuple(graphics)

View File

@ -1,11 +1,11 @@
from org.meteoinfo.geometry.graphic import Graphic
from org.meteoinfo.geometry.shape import ShapeUtil, CircleShape, EllipseShape, \
RectangleShape
RectangleShape, ArcShape
from . import plotutil
import mipylib.numeric as np
__all__ = ['Circle','Ellipse','Rectangle','Polygon']
__all__ = ['Arc','Circle','Ellipse','Rectangle','Polygon']
class Circle(Graphic):
"""
@ -40,7 +40,7 @@ class Ellipse(Graphic):
def __init__(self, xy, width, height, angle=0, **kwargs):
"""
Create a ellipse at center *xy* = (*x*, *y*) with given *width* and *height*.
Create an ellipse at center *xy* = (*x*, *y*) with given *width* and *height*.
:param xy: (float, float) xy coordinates of ellipse centre.
:param width: (float) Ellipse width.
@ -72,6 +72,59 @@ class Ellipse(Graphic):
def angle(self):
return self._angle
class Arc(Graphic):
"""
An Arc patch.
"""
def __init__(self, xy, width, height, angle=0, theta1=0.0, theta2=360.0, **kwargs):
"""
Create an arc at anchor point *xy* = (*x*, *y*) with given *width* and *height*.
:param xy: (float, float) xy coordinates of anchor point.
:param width: (float) Ellipse width.
:param height: (float) Ellipse height.
:param angle: (float) Ellipse angle. Default is `0`.
:param theta1: (float) Starting angle of the arc in degrees. Default is `0.0`.
:param theta2: (float) Ending angle of the arc in degrees. Default is `360`.
"""
self._center = xy
self._width = width
self._height = height
self._angle = angle
self._theta1 = theta1
self._theta2 = theta2
shape = ArcShape(xy[0], xy[1], width, height)
shape.setAngle(angle)
shape.setStartAngle(theta1)
shape.setSweepAngle(theta2 - theta1)
legend, isunique = plotutil.getlegendbreak('polygon', **kwargs)
super(Arc, self).__init__(shape, legend)
@property
def center(self):
return self._center
@property
def width(self):
return self._width
@property
def height(self):
return self._height
@property
def angle(self):
return self._angle
@property
def theta1(self):
return self._theta1
@property
def theta2(self):
return self._theta2
class Rectangle(Graphic):
"""
A rectangle patch.