Add a JavaScript function to obtain the vertices of a Polygon.

This commit is contained in:
Glen Whitney 2018-09-05 00:37:49 -04:00
parent e2f0f34394
commit bb1c2813be
2 changed files with 59 additions and 16 deletions

View File

@ -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", 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", "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", "Parallèle", "Perpendicular", "Perpendiculaire", "FixedCircle", "CercleRayon",
"CartesianFunction", "FonctionCartésienne", "ParametricFunction", "FonctionParamétrique", "SetColor", "MettreCouleur", "SetText", "MettreTexte", "SetThickness", "MettreEpaisseur", "SetFixed", "MettreFixe", "Vector", "Vecteur", "SetRGBColor", "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", "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", "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", "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") * 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 name Name of the polygon (suggestion)
* @param params list of objects * @param params list of objects
* @return Name of the created polygon * @return Name of the created polygon
@ -6024,6 +6029,38 @@ public class JSFunctions {
} }
} }
/**
* 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) { static public String Triangle(String name, String som1, String som2, String som3) {
synchronized (getC()) { synchronized (getC()) {
if (som3.equals("undefined")) { if (som3.equals("undefined")) {

View File

@ -92,21 +92,27 @@ public class AreaObject extends ConstructionObject implements InsideObject,
return "Polygon"; 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 @Override
public void updateText() { public void updateText() {
String Text=Global.name("text.area"); String Text=Global.name("text.area");
final Enumeration en=V.elements(); Text = Text + " ";
boolean first=true; Text = Text + getVertexString(", ");
while (en.hasMoreElements()) {
final PointObject p=(PointObject) en.nextElement();
if (!first) {
Text=Text+", ";
} else {
Text=Text+" ";
}
first=false;
Text=Text+p.getName();
}
setText(Text); setText(Text);
} }