From bb1c2813be547bab56c76d55b82f11d9773ec737 Mon Sep 17 00:00:00 2001 From: Glen Whitney Date: Wed, 5 Sep 2018 00:37:49 -0400 Subject: [PATCH] Add a JavaScript function to obtain the vertices of a Polygon. --- eric/JSprogram/JSFunctions.java | 45 ++++++++++++++++++++++++++--- rene/zirkel/objects/AreaObject.java | 30 +++++++++++-------- 2 files changed, 59 insertions(+), 16 deletions(-) diff --git a/eric/JSprogram/JSFunctions.java b/eric/JSprogram/JSFunctions.java index 9fc1227..74692fa 100644 --- a/eric/JSprogram/JSFunctions.java +++ b/eric/JSprogram/JSFunctions.java @@ -53,8 +53,13 @@ public class JSFunctions { static String[] allnames={"cm", "Input", "Entrée", "EntréeNombreEntier", "EntréeNombreDécimal", "Prompt", "Signaler", "Print", "Afficher", "afficher", "Println", "Afficherligne", "Shownames", "MontrerNoms", "Hidenames", "CacherNoms", "Hide", "Cacher", "Show", "Montrer", "Point", "PointOn", "PointSur", "ImplicitPlot", "TracéImplicite", "Intersection", "Intersection2", "Intersections", "MidPoint", "Milieu", "Symmetry", "SymétrieCentrale", "Line", "Droite", "Segment", "Circle", "Cercle", "Parallel", - "Parallèle", "Perpendicular", "Perpendiculaire", "FixedCircle", "CercleRayon", "Move", "Déplacer", "X", "Y", "GetExpressionValue", "PrendreValeurExpression", "Ray", "DemiDroite", "Angle", "Polygon", "Polygone", "Quadric", "Quadrique", - "CartesianFunction", "FonctionCartésienne", "ParametricFunction", "FonctionParamétrique", "SetColor", "MettreCouleur", "SetText", "MettreTexte", "SetThickness", "MettreEpaisseur", "SetFixed", "MettreFixe", "Vector", "Vecteur", "SetRGBColor", + "Parallèle", "Perpendicular", "Perpendiculaire", "FixedCircle", "CercleRayon", + "Move", "Déplacer", "X", "Y", "GetExpressionValue", "PrendreValeurExpression", + "Ray", "DemiDroite", "Angle", "Polygon", "Polygone", "Vertices", "Sommets", + "Quadric", "Quadrique", "CartesianFunction", "FonctionCartésienne", + "ParametricFunction", "FonctionParamétrique", "SetColor", "MettreCouleur", + "SetText", "MettreTexte", "SetThickness", "MettreEpaisseur", "SetFixed", + "MettreFixe", "Vector", "Vecteur", "SetRGBColor", "MettreCouleurRVB", "SetShowName", "MettreMontrerNom", "SetShowValue", "MettreMontrerValeur", "SetFilled", "MettreRempli", "SetSolid", "MettreOpaque", "SetPartial", "MettrePartiel", "Expression", "Text", "Texte", "SetAlias", "MettreAlias", "SetMagneticObjects", "MettreObjetsMagnétiques", "AddMagneticObject", "AjouterObjetMagnétique", "SetMagneticRay", "MettreRayonMagnétique", "SetPointType", "MettreTypePoint", "InteractiveInput", "EntréeInteractive", "FixedSegment", "SegmentFixe", "SetHide", "MettreCaché", "Pause", "Delete", "Supprimer", "SetExpressionValue", "MettreValeurExpression", "Reflection", "SymétrieAxiale", "Translation", "PerpendicularBisector", "Médiatrice", "AngleBisector", "Bissectrice", "Circle3pts", "Cercle3pts", @@ -5877,7 +5882,7 @@ public class JSFunctions { /** * Creates a polygon define by a list of points. e.g. Polygon("","A,B,C") - * will create the triangle ABgetC(). + * will create the triangle ABC. * @param name Name of the polygon (suggestion) * @param params list of objects * @return Name of the created polygon @@ -5931,7 +5936,7 @@ public class JSFunctions { return LastNObjectsName(1); } } - + static public String Polygone3D(String name, String params) throws Exception{ synchronized (getC()) { if (params.equals("undefined")) { @@ -6023,6 +6028,38 @@ public class JSFunctions { return LastNObjectsName(1); } } + + /** + * Obtains the list of vertices of a polygon, for example if "t" is the + * the triangle created by Polygon("t","A,B,C"), returns the comma-separated + * string "A,B,C". + * @param name Name of the polygon + * @return Comma-separated string of the names of the vertices + * */ + static public String Vertices(String name) { + synchronized (getC()) { + name = parseVariables(name); + ConstructionObject o = getC().find(name); + if (o == null) { return ""; } + if (!(o instanceof AreaObject)) { return ""; } + return ((AreaObject) o).getVertexString(","); + } + } + + /* Why isn't this + * static public String Sommets(String nom) { return Vertices(nom); } + * ??? + */ + + static public String Sommets(String name) { + synchronized (getC()) { + name = parseVariables(name); + ConstructionObject o = getC().find(name); + if (o == null) { return ""; } + if (!(o instanceof AreaObject)) { return ""; } + return ((AreaObject) o).getVertexString(","); + } + } static public String Triangle(String name, String som1, String som2, String som3) { synchronized (getC()) { diff --git a/rene/zirkel/objects/AreaObject.java b/rene/zirkel/objects/AreaObject.java index aa8b9a4..152ef80 100644 --- a/rene/zirkel/objects/AreaObject.java +++ b/rene/zirkel/objects/AreaObject.java @@ -92,21 +92,27 @@ public class AreaObject extends ConstructionObject implements InsideObject, return "Polygon"; } + public String getVertexString(String sep) { + String ret = ""; + boolean first = true; + final Enumeration en = V.elements(); + while (en.hasMoreElements()) { + final PointObject p = (PointObject) en.nextElement(); + if (!first) { + ret = ret + sep; + } else { + first = false; + } + ret = ret + p.getName(); + } + return ret; + } + @Override public void updateText() { String Text=Global.name("text.area"); - final Enumeration en=V.elements(); - boolean first=true; - while (en.hasMoreElements()) { - final PointObject p=(PointObject) en.nextElement(); - if (!first) { - Text=Text+", "; - } else { - Text=Text+" "; - } - first=false; - Text=Text+p.getName(); - } + Text = Text + " "; + Text = Text + getVertexString(", "); setText(Text); }