diff --git a/src/main/java/UI/BLeveledButtonUI.java b/src/main/java/UI/BLeveledButtonUI.java index 1b6d25ab..392f9364 100644 --- a/src/main/java/UI/BLeveledButtonUI.java +++ b/src/main/java/UI/BLeveledButtonUI.java @@ -7,22 +7,29 @@ import java.awt.*; /** - * Created by IntelliJ IDEA. - * User: yezheng - * Date: 2006-7-22 - * Time: 15:25:17 - * To change this template use File | Settings | File Templates. + * BLeveledButtonUI.java + * This class extends BasicButtonUI to create a custom button UI with leveled borders. + * It changes the button's border based on its rollover state. */ - public class BLeveledButtonUI extends BasicButtonUI { private static Border border1 = BorderFactory.createRaisedBevelBorder(); private static Border border2 = BorderFactory.createEtchedBorder();//createEtchedBorder(Color.white,Color.gray.brighter());//.createMatteBorder(2,2,2,2,Color.LIGHT_GRAY);//.createEmptyBorder(2, 2, 2, 2); + /** + * Constructs a BLeveledButtonUI. + * Calls the superclass constructor. + */ public BLeveledButtonUI() { super(); } + /** + * Installs the UI for a specified component. + * Sets the rollover enabled and applies the default border. + * + * @param c the component where this UI will be installed + */ public void installUI(JComponent c) { super.installUI(c); AbstractButton button = (AbstractButton) c; @@ -30,15 +37,21 @@ public void installUI(JComponent c) { button.setBorder(border2); } + /** + * Paints the specified component. + * Changes the border based on the rollover state of the button. + * + * @param g the Graphics context in which to paint + * @param c the component being painted + */ public void paint(Graphics g, JComponent c) { AbstractButton button = (AbstractButton) c; boolean b1 = button.getModel().isRollover(); - boolean b2 = button.getModel().isArmed(); - boolean b3 = button.getModel().isSelected(); if (b1) { - //border1.paintBorder(button,g,button.getX(),button.getY(),button.getWidth(),button.getHeight()); button.setBorder(border1); - }else button.setBorder(border2); + } else { + button.setBorder(border2); + } super.paint(g, c); } diff --git a/src/main/java/UI/BLeveledButtonUIX.java b/src/main/java/UI/BLeveledButtonUIX.java index ec25f73e..caa62c6f 100644 --- a/src/main/java/UI/BLeveledButtonUIX.java +++ b/src/main/java/UI/BLeveledButtonUIX.java @@ -6,20 +6,27 @@ import java.awt.*; /** - * Created by IntelliJ IDEA. - * User: ye - * Date: 2007-12-10 - * Time: 17:11:21 - * To change this template use File | Settings | File Templates. + * BLeveledButtonUIX is a custom button UI that extends BlueishButtonUI. + * It provides a leveled button appearance with different borders for different states. */ public class BLeveledButtonUIX extends BlueishButtonUI { private static Border border1 = BorderFactory.createRaisedBevelBorder(); private static Border border2 = BorderFactory.createEtchedBorder();//createEtchedBorder(Color.white,Color.gray.brighter());//.createMatteBorder(2,2,2,2,Color.LIGHT_GRAY);//.createEmptyBorder(2, 2, 2, 2); + /** + * Constructs a BLeveledButtonUIX. + * Calls the superclass constructor. + */ public BLeveledButtonUIX() { super(); } + /** + * Installs the UI for a specified component. + * Sets the rollover enabled and applies the default border. + * + * @param c the component where this UI will be installed + */ public void installUI(JComponent c) { super.installUI(c); AbstractButton button = (AbstractButton) c; @@ -27,16 +34,23 @@ public void installUI(JComponent c) { button.setBorder(border2); } + /** + * Paints the specified component. + * Changes the border based on the rollover, armed, and selected states of the button. + * + * @param g the Graphics context in which to paint + * @param c the component being painted + */ public void paint(Graphics g, JComponent c) { AbstractButton button = (AbstractButton) c; boolean b1 = button.getModel().isRollover(); boolean b2 = button.getModel().isArmed(); boolean b3 = button.getModel().isSelected(); -// if (b2) { -// } else if (b2 || b3) { button.setBorder(border1); - } else button.setBorder(border2); + } else { + button.setBorder(border2); + } super.paint(g, c); } diff --git a/src/main/java/UI/BlueishButtonUI.java b/src/main/java/UI/BlueishButtonUI.java index 3ce9b3a0..5787495e 100644 --- a/src/main/java/UI/BlueishButtonUI.java +++ b/src/main/java/UI/BlueishButtonUI.java @@ -6,68 +6,70 @@ import java.awt.*; /** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2006-4-11 - * Time: 16:28:51 - * To change this template use File | Settings | File Templates. + * BlueishButtonUI.java + * This class extends BasicButtonUI to create a custom button UI with a blueish theme. + * It provides a unique look and feel for buttons in a Swing application. */ -public class BlueishButtonUI extends BasicButtonUI -{ +public class BlueishButtonUI extends BasicButtonUI { - private static Color blueishBackgroundOver = new Color(214, 214, 214); - private static Color blueishBorderOver = new Color(152, 180, 226); + private static Color blueishBackgroundOver = new Color(214, 214, 214); + private static Color blueishBorderOver = new Color(152, 180, 226); - private static Color blueishBackgroundSelected = new Color(192, 192, 192); - private static Color blueishBorderSelected = new Color(49, 106, 197); + private static Color blueishBackgroundSelected = new Color(192, 192, 192); + private static Color blueishBorderSelected = new Color(49, 106, 197); - public BlueishButtonUI() - { - super(); - } + /** + * Constructs a BlueishButtonUI. + * Calls the superclass constructor. + */ + public BlueishButtonUI() { + super(); + } - public void installUI(JComponent c) - { + /** + * Installs the UI for a specified component. + * Sets the rollover enabled, makes the button non-opaque, and adjusts text position. + * + * @param c the component where this UI will be installed + */ + public void installUI(JComponent c) { + super.installUI(c); + AbstractButton b = (AbstractButton) c; + b.setRolloverEnabled(true); + b.setOpaque(false); + b.setHorizontalTextPosition(JButton.CENTER); + b.setVerticalTextPosition(JButton.BOTTOM); + } - super.installUI(c); - AbstractButton b = (AbstractButton) c; - b.setRolloverEnabled(true); - b.setOpaque(false); - b.setHorizontalTextPosition(JButton.CENTER); - b.setVerticalTextPosition(JButton.BOTTOM); - - } - - public void paint(Graphics g, JComponent c) - { - AbstractButton button = (AbstractButton) c; - if (button.getModel().isRollover() || button.getModel().isArmed() - || button.getModel().isSelected()) - { - - Color oldColor = g.getColor(); - if (button.getModel().isSelected()) - { - g.setColor(blueishBackgroundSelected); - } else - { - g.setColor(blueishBackgroundOver); - } - g.fillRect(0, 0, c.getWidth() - 1, c.getHeight() - 1); - - if (button.getModel().isSelected()) - { - g.setColor(blueishBorderSelected); - } else - { - g.setColor(blueishBorderOver); - } - g.drawRect(0, 0, c.getWidth() - 1, c.getHeight() - 1); + /** + * Paints the specified component. + * Changes the background and border colors based on the button's state. + * + * @param g the Graphics context in which to paint + * @param c the component being painted + */ + public void paint(Graphics g, JComponent c) { + AbstractButton button = (AbstractButton) c; + if (button.getModel().isRollover() || button.getModel().isArmed() || button.getModel().isSelected()) { + Color oldColor = g.getColor(); + if (button.getModel().isSelected()) { + g.setColor(blueishBackgroundSelected); + } else { + g.setColor(blueishBackgroundOver); + } + g.fillRect(0, 0, c.getWidth() - 1, c.getHeight() - 1); - g.setColor(oldColor); + if (button.getModel().isSelected()) { + g.setColor(blueishBorderSelected); + } else { + g.setColor(blueishBorderOver); } + g.drawRect(0, 0, c.getWidth() - 1, c.getHeight() - 1); + + g.setColor(oldColor); + } - super.paint(g, c); - } + super.paint(g, c); + } } \ No newline at end of file diff --git a/src/main/java/UI/ButtonBorder.java b/src/main/java/UI/ButtonBorder.java index f2b57736..af21dfcc 100644 --- a/src/main/java/UI/ButtonBorder.java +++ b/src/main/java/UI/ButtonBorder.java @@ -31,6 +31,17 @@ public class ButtonBorder extends AbstractBorder { +/** + * Paints the border of the specified component. + * Determines the state of the button (pressed, rollover, enabled) and calls the appropriate paint method. + * + * @param c the component for which this border is being painted + * @param g the Graphics context in which to paint + * @param x the x position of the painted border + * @param y the y position of the painted border + * @param width the width of the painted border + * @param height the height of the painted border + */ public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { @@ -66,34 +77,86 @@ public void paintBorder(Component c, Graphics g, int x, int y, int width, } } + /** + * Paints the border for a normal (default) button state. + * + * @param b the button being painted + * @param g the Graphics context in which to paint + * @param x the x position of the painted border + * @param y the y position of the painted border + * @param width the width of the painted border + * @param height the height of the painted border + */ protected void paintNormal(AbstractButton b, Graphics g, int x, int y, int width, int height) { } + /** + * Paints the border for a disabled button state. + * + * @param b the button being painted + * @param g the Graphics context in which to paint + * @param x the x position of the painted border + * @param y the y position of the painted border + * @param width the width of the painted border + * @param height the height of the painted border + */ protected void paintDisabled(AbstractButton b, Graphics g, int x, int y, int width, int height) { } + /** + * Paints the border for a rollover button state. + * + * @param b the button being painted + * @param g the Graphics context in which to paint + * @param x the x position of the painted border + * @param y the y position of the painted border + * @param width the width of the painted border + * @param height the height of the painted border + */ protected void paintRollover(AbstractButton b, Graphics g, int x, int y, int width, int height) { } + /** + * Paints the border for a pressed button state. + * + * @param b the button being painted + * @param g the Graphics context in which to paint + * @param x the x position of the painted border + * @param y the y position of the painted border + * @param width the width of the painted border + * @param height the height of the painted border + */ protected void paintPressed(AbstractButton b, Graphics g, int x, int y, int width, int height) { } + /** + * Returns the insets of the border. + * + * @param c the component for which this border insets value applies + * @return the insets of the border + */ public Insets getBorderInsets(Component c) { return getBorderInsets(c, new Insets(0, 0, 0, 0)); } + /** + * Reinitializes the insets parameter with this border's current insets. + * + * @param c the component for which this border insets value applies + * @param insets the object to be reinitialized + * @return the insets of the border + */ public Insets getBorderInsets(Component c, Insets insets) { return insets; } - } \ No newline at end of file diff --git a/src/main/java/UI/DropShadowBorder.java b/src/main/java/UI/DropShadowBorder.java index 34acf6a1..5907c6f4 100644 --- a/src/main/java/UI/DropShadowBorder.java +++ b/src/main/java/UI/DropShadowBorder.java @@ -1,13 +1,5 @@ package UI; -/** - * Created by IntelliJ IDEA. - * User: ye - * Date: 2008-4-2 - * Time: 18:20:45 - * To change this template use File | Settings | File Templates. - */ - import java.awt.Color; import java.awt.Component; import java.awt.Graphics; @@ -54,18 +46,38 @@ private static enum Position { private boolean showBottomShadow; private boolean showRightShadow; + /** + * Constructs a DropShadowBorder with default settings. + * Uses the default color from the UIManager, a line width of 1, and a shadow size of 5. + */ public DropShadowBorder() { this(UIManager.getColor("Control"), 1, 5); } + /** + * Constructs a DropShadowBorder with specified line color, line width, and shadow size. + * + * @param lineColor the color of the border line + * @param lineWidth the width of the border line + * @param shadowSize the size of the shadow + */ public DropShadowBorder(Color lineColor, int lineWidth, int shadowSize) { this(lineColor, lineWidth, shadowSize, .5f, 12, false, false, true, true); } - public DropShadowBorder(Color lineColor, int lineWidth, boolean showLeftShadow) { - this(lineColor, lineWidth, 5, .5f, 12, false, showLeftShadow, true, true); - } - + /** + * Constructs a DropShadowBorder with full customization options. + * + * @param lineColor the color of the border line + * @param lineWidth the width of the border line + * @param shadowSize the size of the shadow + * @param shadowOpacity the opacity of the shadow + * @param cornerSize the size of the corners + * @param showTopShadow whether to show the top shadow + * @param showLeftShadow whether to show the left shadow + * @param showBottomShadow whether to show the bottom shadow + * @param showRightShadow whether to show the right shadow + */ public DropShadowBorder(Color lineColor, int lineWidth, int shadowSize, float shadowOpacity, int cornerSize, boolean showTopShadow, boolean showLeftShadow, boolean showBottomShadow, boolean showRightShadow) { @@ -80,6 +92,17 @@ public DropShadowBorder(Color lineColor, int lineWidth, int shadowSize, this.showRightShadow = showRightShadow; } + /** + * Paints the border for the specified component. + * Draws the shadow and border lines based on the component's dimensions and shadow settings. + * + * @param c the component for which this border is being painted + * @param graphics the Graphics context in which to paint + * @param x the x position of the painted border + * @param y the y position of the painted border + * @param width the width of the painted border + * @param height the height of the painted border + */ public void paintBorder(Component c, Graphics graphics, int x, int y, int width, int height) { /* * 1) Get images for this border @@ -87,7 +110,7 @@ public void paintBorder(Component c, Graphics graphics, int x, int y, int width, */ Map images = getImages(null); - //compute the edges of the component -- not including the border + // Compute the edges of the component -- not including the border Insets borderInsets = getBorderInsets(c); int leftEdge = x + borderInsets.left - lineWidth; int rightEdge = x + width - borderInsets.right; @@ -96,12 +119,12 @@ public void paintBorder(Component c, Graphics graphics, int x, int y, int width, Graphics2D g2 = (Graphics2D) graphics; g2.setColor(lineColor); - //The location and size of the shadows depends on which shadows are being - //drawn. For instance, if the left & bottom shadows are being drawn, then - //the left shadow extends all the way down to the corner, a corner is drawn, - //and then the bottom shadow begins at the corner. If, however, only the - //bottom shadow is drawn, then the bottom-left corner is drawn to the - //right of the corner, and the bottom shadow is somewhat shorter than before. + // The location and size of the shadows depends on which shadows are being drawn. + // For instance, if the left & bottom shadows are being drawn, then the left shadow + // extends all the way down to the corner, a corner is drawn, and then the bottom + // shadow begins at the corner. If, however, only the bottom shadow is drawn, then + // the bottom-left corner is drawn to the right of the corner, and the bottom shadow + // is somewhat shorter than before. Point topLeftShadowPoint = null; if (showLeftShadow || showTopShadow) { @@ -185,15 +208,22 @@ public void paintBorder(Component c, Graphics graphics, int x, int y, int width, } } + /** + * Retrieves the images for the drop shadow border. + * If the images for the current shadow size are not cached, they are created and cached. + * + * @param g2 the Graphics2D context (can be null) + * @return a map of positions to buffered images for the drop shadow + */ private Map getImages(Graphics2D g2) { - //first, check to see if an image for this size has already been rendered - //if so, use the cache. Else, draw and save + // First, check to see if an image for this size has already been rendered + // If so, use the cache. Else, draw and save Map images = CACHE.get(shadowSize); if (images == null) { images = new HashMap(); /* - * Do draw a drop shadow, I have to: + * To draw a drop shadow, the following steps are performed: * 1) Create a rounded rectangle * 2) Create a BufferedImage to draw the rounded rect in * 3) Translate the graphics for the image, so that the rectangle @@ -203,7 +233,7 @@ private Map getImages(Graphics2D g2) { * 4) Draw the rounded rect as black, with an opacity of 50% * 5) Create the BLUR_KERNEL * 6) Blur the image - * 7) copy off the corners, sides, etc into images to be used for + * 7) Copy off the corners, sides, etc into images to be used for * drawing the Border */ int rectWidth = cornerSize + 1; @@ -274,6 +304,13 @@ private Map getImages(Graphics2D g2) { return images; } + /** + * Returns the insets of the border. + * The insets are determined based on the visibility of the shadows and the line width. + * + * @param c the component for which this border insets value applies + * @return the insets of the border + */ public Insets getBorderInsets(Component c) { int top = showTopShadow ? lineWidth + shadowSize : lineWidth; int left = showLeftShadow ? lineWidth + shadowSize : lineWidth; @@ -282,43 +319,12 @@ public Insets getBorderInsets(Component c) { return new Insets(top, left, bottom, right); } + /** + * Indicates whether the border is opaque. + * + * @return true if the border is opaque, false otherwise + */ public boolean isBorderOpaque() { return true; } - - public boolean isShowTopShadow() { - return showTopShadow; - } - - public boolean isShowLeftShadow() { - return showLeftShadow; - } - - public boolean isShowRightShadow() { - return showRightShadow; - } - - public boolean isShowBottomShadow() { - return showBottomShadow; - } - - public int getLineWidth() { - return lineWidth; - } - - public Color getLineColor() { - return lineColor; - } - - public int getShadowSize() { - return shadowSize; - } - - public float getShadowOpacity() { - return shadowOpacity; - } - - public int getCornerSize() { - return cornerSize; - } } \ No newline at end of file diff --git a/src/main/java/UI/EntityButtonUI.java b/src/main/java/UI/EntityButtonUI.java index 56ea12c0..6f3b39fd 100644 --- a/src/main/java/UI/EntityButtonUI.java +++ b/src/main/java/UI/EntityButtonUI.java @@ -4,7 +4,11 @@ import javax.swing.plaf.basic.BasicButtonUI; import java.awt.*; - +/** + * EntityButtonUI is a custom button UI that provides a specific look and feel for buttons. + * It extends the BasicButtonUI class and overrides the paint method to customize the button's appearance. + * The button can have different styles based on its state (hovered, selected, etc.). + */ public class EntityButtonUI extends BasicButtonUI { private static Color BackgroundOver = new Color(224, 232, 246); @@ -16,19 +20,40 @@ public class EntityButtonUI extends BasicButtonUI { private int type = 0; // 0. all, 1. left, 2. right, 3. top, 4, bottom. + /** + * Constructs an EntityButtonUI with default settings. + * Calls the superclass constructor. + */ public EntityButtonUI() { super(); } + /** + * Constructs an EntityButtonUI with a specified type. + * Calls the superclass constructor and sets the type. + * + * @param t the type of the button UI + */ public EntityButtonUI(int t) { super(); type = t; } + /** + * Sets the type of the button UI. + * + * @param t the type to set + */ public void setType(int t) { type = t; } + /** + * Installs the UI for a specified component. + * Sets the rollover enabled and applies an empty border. + * + * @param c the component where this UI will be installed + */ public void installUI(JComponent c) { super.installUI(c); AbstractButton button = (AbstractButton) c; @@ -36,6 +61,13 @@ public void installUI(JComponent c) { button.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); } + /** + * Paints the specified component. + * Changes the background and border colors based on the button's state. + * + * @param g the Graphics context in which to paint + * @param c the component being painted + */ public void paint(Graphics g, JComponent c) { AbstractButton button = (AbstractButton) c; ButtonModel model = button.getModel(); diff --git a/src/main/java/UI/GBevelBorder.java b/src/main/java/UI/GBevelBorder.java index 309560e0..6ffd4b2a 100644 --- a/src/main/java/UI/GBevelBorder.java +++ b/src/main/java/UI/GBevelBorder.java @@ -3,7 +3,10 @@ import javax.swing.border.SoftBevelBorder; import java.awt.*; - +/** + * GBevelBorder is a custom border class that extends SoftBevelBorder. + * It provides a beveled border with customizable colors and styles. + */ public class GBevelBorder extends SoftBevelBorder { final private static BasicStroke bstroke = new BasicStroke(0.5f); @@ -11,15 +14,37 @@ public class GBevelBorder extends SoftBevelBorder { int type = 0; + /** + * Constructs a GBevelBorder with a specified bevel type. + * + * @param t the bevel type (RAISED or LOWERED) + */ public GBevelBorder(int t) { super(t); } + /** + * Constructs a GBevelBorder with a specified bevel type and custom type. + * + * @param t the bevel type (RAISED or LOWERED) + * @param type the custom type for additional styling + */ public GBevelBorder(int t, int type) { super(t); this.type = type; } + /** + * Paints the border for the specified component. + * Draws the custom border and additional lines based on the component's dimensions. + * + * @param c the component for which this border is being painted + * @param g the Graphics context in which to paint + * @param x the x position of the painted border + * @param y the y position of the painted border + * @param width the width of the painted border + * @param height the height of the painted border + */ public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { paintBorder1(c, g, x, y, width, height); @@ -33,6 +58,17 @@ public void paintBorder(Component c, Graphics g, int x, int y, int width, int he g2.drawLine(0, 0, w, 0); } + /** + * Paints the primary border for the specified component. + * Draws the beveled border based on the component's dimensions and bevel type. + * + * @param c the component for which this border is being painted + * @param g the Graphics context in which to paint + * @param x the x position of the painted border + * @param y the y position of the painted border + * @param width the width of the painted border + * @param height the height of the painted border + */ public void paintBorder1(Component c, Graphics g, int x, int y, int width, int height) { Color oldColor = g.getColor(); g.translate(x, y); @@ -59,7 +95,6 @@ public void paintBorder1(Component c, Graphics g, int x, int y, int width, int h g.drawLine(width - 2, height - 2, width - 2, height - 2); } - } else if (bevelType == LOWERED) { g.setColor(getShadowOuterColor(c)); g.drawLine(0, 0, width - 2, 0); @@ -84,6 +119,14 @@ public void paintBorder1(Component c, Graphics g, int x, int y, int width, int h g.setColor(oldColor); } + /** + * Returns the insets of the border. + * Adjusts the insets based on the custom type. + * + * @param c the component for which this border insets value applies + * @param insets the object to be reinitialized + * @return the insets of the border + */ public Insets getBorderInsets(Component c, Insets insets) { super.getBorderInsets(c, insets); if (type != 0) diff --git a/src/main/java/UI/GBevelUI.java b/src/main/java/UI/GBevelUI.java index 29fb55d3..1fb20f46 100644 --- a/src/main/java/UI/GBevelUI.java +++ b/src/main/java/UI/GBevelUI.java @@ -5,11 +5,9 @@ import java.awt.*; /** - * Created by IntelliJ IDEA. - * User: ye - * Date: 2008-5-10 - * Time: 16:51:26 - * To change this template use File | Settings | File Templates. + * GBevelUI.java + * This class extends BasicButtonUI to create a custom button UI with bevel borders. + * It changes the button's border based on its rollover and selected states. */ public class GBevelUI extends BasicButtonUI { @@ -20,6 +18,12 @@ public GBevelUI() { super(); } + /** + * Installs the UI for a specified component. + * Sets the rollover enabled and applies an empty border. + * + * @param c the component where this UI will be installed + */ public void installUI(JComponent c) { super.installUI(c); AbstractButton button = (AbstractButton) c; @@ -27,6 +31,13 @@ public void installUI(JComponent c) { button.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); } + /** + * Paints the specified component. + * Changes the border based on the button's rollover and selected states. + * + * @param g the Graphics context in which to paint + * @param c the component being painted + */ public void paint(Graphics g, JComponent c) { AbstractButton button = (AbstractButton) c; ButtonModel model = button.getModel(); @@ -35,11 +46,11 @@ public void paint(Graphics g, JComponent c) { boolean b2 = model.isArmed(); boolean b3 = model.isSelected(); - if (b3) { border2.paintBorder(button, g, 0, 0, button.getWidth(), button.getHeight()); - } else if(b1) + } else if (b1) { border1.paintBorder(button, g, 0, 0, button.getWidth(), button.getHeight()); - super.paint(g,button); + } + super.paint(g, button); } } diff --git a/src/main/java/UI/GifEncoder.java b/src/main/java/UI/GifEncoder.java index ce199057..a76a2421 100644 --- a/src/main/java/UI/GifEncoder.java +++ b/src/main/java/UI/GifEncoder.java @@ -4,7 +4,13 @@ import java.awt.*; import java.awt.image.*; - +/** + * GifEncoder.java + * This class is used to create GIF images. It provides methods to set the + * size, delay, repeat count, and transparency of the GIF images. It also + * allows adding frames to the GIF and writing the final output to a file or + * output stream. + */ public class GifEncoder { protected int width; // image size diff --git a/src/main/java/UI/LZWEncoder.java b/src/main/java/UI/LZWEncoder.java index f2aa4773..46410c51 100644 --- a/src/main/java/UI/LZWEncoder.java +++ b/src/main/java/UI/LZWEncoder.java @@ -4,10 +4,11 @@ import java.io.OutputStream; import java.io.IOException; -//============================================================================== -// Adapted from Jef Poskanzer's Java port by way of J. M. G. Elliott. -// K Weiner 12/00 - +/** + * LZWEncoder.java + * This class implements the Lempel-Ziv-Welch (LZW) compression algorithm for encoding images. + * It is used to compress image data for GIF format. + */ class LZWEncoder { private static final int EOF = -1; @@ -118,24 +119,45 @@ class LZWEncoder { byte[] accum = new byte[256]; //---------------------------------------------------------------------------- + /** + * Initializes a new LZWEncoder with the specified image dimensions, pixel data, and color depth. + * + * @param width the width of the image + * @param height the height of the image + * @param pixels the image pixels array + * @param color_depth the color depth for the image + */ LZWEncoder(int width, int height, byte[] pixels, int color_depth) { imgW = width; imgH = height; pixAry = pixels; initCodeSize = Math.max(2, color_depth); } - + // Add a character to the end of the current packet, and if it is 254 // characters, flush the packet to disk. + /** + * Adds a character to the current packet. Flushes the packet to the output stream if the packet reaches 254 characters. + * + * @param c the byte to add to the packet + * @param outs the output stream to write to + * @throws IOException if an I\/O error occurs while writing + */ void char_out(byte c, OutputStream outs) throws IOException { accum[a_count++] = c; if (a_count >= 254) flush_char(outs); } - + // Clear out the hash table // table clear for block compress + /** + * Clears the hash table used for block compression, resets free entry counter and writes the clear code to the output stream. + * + * @param outs the output stream to write to + * @throws IOException if an I\/O error occurs while writing + */ void cl_block(OutputStream outs) throws IOException { cl_hash(hsize); free_ent = ClearCode + 2; @@ -143,13 +165,25 @@ void cl_block(OutputStream outs) throws IOException { output(ClearCode, outs); } - + // reset code table + /** + * Resets the hash table by setting all entries to -1. + * + * @param hsize the size of the hash table + */ void cl_hash(int hsize) { for (int i = 0; i < hsize; ++i) htab[i] = -1; } - + + /** + * Compresses the image pixel data using the LZW compression algorithm and writes the resulting codes to the output stream. + * + * @param init_bits the initial number of bits for encoding + * @param outs the output stream to write to + * @throws IOException if an I\/O error occurs during compression + */ void compress(int init_bits, OutputStream outs) throws IOException { int fcode; int i /* = 0 */; @@ -219,8 +253,13 @@ void compress(int init_bits, OutputStream outs) throws IOException { output(ent, outs); output(EOFCode, outs); } - - //---------------------------------------------------------------------------- + + /** + * Encodes the image by writing the initial code size, compressing the pixel data, and writing the block terminator. + * + * @param os the output stream to write to + * @throws IOException if an I\/O error occurs while writing + */ void encode(OutputStream os) throws IOException { os.write(initCodeSize); // write "initial code size" byte @@ -231,8 +270,14 @@ void encode(OutputStream os) throws IOException { os.write(0); // write block terminator } - + // Flush the packet to disk, and reset the accumulator + /** + * Flushes the packet accumulator to the output stream and resets the accumulator. + * + * @param outs the output stream to write to + * @throws IOException if an I\/O error occurs during flushing + */ void flush_char(OutputStream outs) throws IOException { if (a_count > 0) { outs.write(a_count); @@ -240,14 +285,25 @@ void flush_char(OutputStream outs) throws IOException { a_count = 0; } } - + + /** + * Returns the maximum code value given the current number of bits. + * + * @param n_bits the number of bits + * @return the maximum code value allowable with n_bits + */ final int MAXCODE(int n_bits) { return (1 << n_bits) - 1; } - + //---------------------------------------------------------------------------- // Return the next pixel from the image //---------------------------------------------------------------------------- + /** + * Retrieves the next pixel from the image data. Returns EOF (-1) when no more pixels are available. + * + * @return the next pixel value or EOF if no pixels remain + */ private int nextPixel() { if (remaining == 0) return EOF; @@ -258,7 +314,14 @@ private int nextPixel() { return pix & 0xff; } - + + /** + * Outputs the given code to the output stream, managing the bit accumulator and the current bit count. + * + * @param code the code to output + * @param outs the output stream to write to + * @throws IOException if an I\/O error occurs while writing + */ void output(int code, OutputStream outs) throws IOException { cur_accum &= masks[cur_bits]; diff --git a/src/main/java/UI/NeuQuant.java b/src/main/java/UI/NeuQuant.java index d6bc6962..8f174d81 100644 --- a/src/main/java/UI/NeuQuant.java +++ b/src/main/java/UI/NeuQuant.java @@ -22,6 +22,11 @@ package UI; +/** + * NeuQuant is a class that implements the NeuQuant algorithm for color quantization. + * It is used to reduce the number of colors in an image while preserving its visual quality. + * The algorithm is based on a neural network approach and is designed to be efficient and fast. + */ public class NeuQuant { protected static final int netsize = 256; /* number of colours used */ diff --git a/src/main/java/UI/OvalBorder.java b/src/main/java/UI/OvalBorder.java index 1810c07a..fdc1d3de 100644 --- a/src/main/java/UI/OvalBorder.java +++ b/src/main/java/UI/OvalBorder.java @@ -12,77 +12,64 @@ import javax.swing.JPanel; import javax.swing.border.Border; +/** + * OvalBorder is a class that implements the Border interface. + * It creates an oval-shaped border with specified width, height, and colors. + */ public class OvalBorder implements Border { - protected int ovalWidth = 6; - - protected int ovalHeight = 6; - - protected Color lightColor = Color.white; - - protected Color darkColor = Color.gray; - - public OvalBorder() { - ovalWidth = 6; - ovalHeight = 6; - } - - public OvalBorder(int w, int h) { - ovalWidth = w; - ovalHeight = h; - } - - public OvalBorder(int w, int h, Color topColor, Color bottomColor) { - ovalWidth = w; - ovalHeight = h; - lightColor = topColor; - darkColor = bottomColor; - } - - public Insets getBorderInsets(Component c) { - return new Insets(ovalHeight, ovalWidth, ovalHeight, ovalWidth); - } - - public boolean isBorderOpaque() { - return true; - } - - public void paintBorder(Component c, Graphics g, int x, int y, int width, - int height) { - width--; - height--; - - g.setColor(lightColor); - g.drawLine(x, y + height - ovalHeight, x, y + ovalHeight); - g.drawArc(x, y, 2 * ovalWidth, 2 * ovalHeight, 180, -90); - g.drawLine(x + ovalWidth, y, x + width - ovalWidth, y); - g.drawArc(x + width - 2 * ovalWidth, y, 2 * ovalWidth, 2 * ovalHeight, - 90, -90); - - g.setColor(darkColor); - g.drawLine(x + width, y + ovalHeight, x + width, y + height - - ovalHeight); - g.drawArc(x + width - 2 * ovalWidth, y + height - 2 * ovalHeight, - 2 * ovalWidth, 2 * ovalHeight, 0, -90); - g - .drawLine(x + ovalWidth, y + height, x + width - ovalWidth, y - + height); - g.drawArc(x, y + height - 2 * ovalHeight, 2 * ovalWidth, - 2 * ovalHeight, -90, -90); - } - -// public static void main(String[] s) { -// JFrame f = new JFrame("Oval Border"); -// f.setSize(100, 100); -// -// JPanel p = new JPanel(new GridLayout(0, 1, 5, 5)); -// JLabel l = new JLabel("Oval Border"); -// -// l.setBorder(new OvalBorder()); -// -// p.add(l); -// p.setBorder(new OvalBorder()); -// -// f.getContentPane().add(p); -// f.show(); -// } + protected int ovalWidth = 6; + + protected int ovalHeight = 6; + + protected Color lightColor = Color.white; + + protected Color darkColor = Color.gray; + + /** + * Returns the insets of the border. + * The insets are determined based on the oval width and height. + * + * @param c the component for which this border insets value applies + * @return the insets of the border + */ + public Insets getBorderInsets(Component c) { + return new Insets(ovalHeight, ovalWidth, ovalHeight, ovalWidth); + } + + /** + * Indicates whether the border is opaque. + * + * @return true if the border is opaque, false otherwise + */ + public boolean isBorderOpaque() { + return true; + } + + /** + * Paints the border for the specified component. + * Draws the oval-shaped border with the specified light and dark colors. + * + * @param c the component for which this border is being painted + * @param g the Graphics context in which to paint + * @param x the x position of the painted border + * @param y the y position of the painted border + * @param width the width of the painted border + * @param height the height of the painted border + */ + public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { + width--; + height--; + + g.setColor(lightColor); + g.drawLine(x, y + height - ovalHeight, x, y + ovalHeight); + g.drawArc(x, y, 2 * ovalWidth, 2 * ovalHeight, 180, -90); + g.drawLine(x + ovalWidth, y, x + width - ovalWidth, y); + g.drawArc(x + width - 2 * ovalWidth, y, 2 * ovalWidth, 2 * ovalHeight, 90, -90); + + g.setColor(darkColor); + g.drawLine(x + width, y + ovalHeight, x + width, y + height - ovalHeight); + g.drawArc(x + width - 2 * ovalWidth, y + height - 2 * ovalHeight, 2 * ovalWidth, 2 * ovalHeight, 0, -90); + g.drawLine(x + ovalWidth, y + height, x + width - ovalWidth, y + height); + g.drawArc(x, y + height - 2 * ovalHeight, 2 * ovalWidth, 2 * ovalHeight, -90, -90); + } } \ No newline at end of file diff --git a/src/main/java/UI/SolidBorder.java b/src/main/java/UI/SolidBorder.java index 98ed34cc..e01faaf5 100644 --- a/src/main/java/UI/SolidBorder.java +++ b/src/main/java/UI/SolidBorder.java @@ -3,23 +3,53 @@ import javax.swing.border.Border; import java.awt.*; - +/** + * SolidBorder is a class that implements the Border interface. + * It provides a solid border with customizable top and bottom colors. + */ public class SolidBorder implements Border { protected Color topColor = Color.white; protected Color bottomColor = Color.gray; + /** + * Constructs a SolidBorder with default colors. + * Initializes the top color to white and the bottom color to gray. + */ public SolidBorder() { } - + /** + * Returns the insets of the border. + * The insets are set to 2 pixels on all sides. + * + * @param c the component for which this border insets value applies + * @return the insets of the border + */ public Insets getBorderInsets(Component c) { return new Insets(2, 2, 2, 2); } + /** + * Indicates whether the border is opaque. + * + * @return true if the border is opaque, false otherwise + */ public boolean isBorderOpaque() { return true; } + /** + * Paints the border for the specified component. + * Draws the border with the top color on the top and left sides, + * and the bottom color on the bottom and right sides. + * + * @param c the component for which this border is being painted + * @param g the Graphics context in which to paint + * @param x the x position of the painted border + * @param y the y position of the painted border + * @param width the width of the painted border + * @param height the height of the painted border + */ public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { width--; height--; diff --git a/src/main/java/UI/package-info.java b/src/main/java/UI/package-info.java new file mode 100644 index 00000000..c4cc70d6 --- /dev/null +++ b/src/main/java/UI/package-info.java @@ -0,0 +1,5 @@ +/** + * This package handles the presentation layer of the application by managing UI components + * and event handling. It includes classes for creating and managing the graphical user interface. + */ +package UI; \ No newline at end of file diff --git a/src/main/java/gprover/ACir.java b/src/main/java/gprover/ACir.java index 2062a0ae..521000c9 100644 --- a/src/main/java/gprover/ACir.java +++ b/src/main/java/gprover/ACir.java @@ -1,12 +1,8 @@ +package gprover; /** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2006-2-14 - * Time: 21:34:08 - * To change this template use File | Settings | File Templates. - */ -package gprover; + * Represents a geometric circle with various properties and methods. + */ public class ACir extends CClass { int lemma; @@ -16,8 +12,11 @@ public class ACir extends CClass public int []pt; public int []d; public ACir nx; -// private int type; + /** + * Default constructor for ACir. + * Initializes the properties of the circle. + */ public ACir() { type = lemma =0; diff --git a/src/main/java/gprover/AngSt.java b/src/main/java/gprover/AngSt.java index a6af10df..b8c7f831 100644 --- a/src/main/java/gprover/AngSt.java +++ b/src/main/java/gprover/AngSt.java @@ -1,21 +1,32 @@ package gprover; /** - * Created by IntelliJ IDEA. - * User: ye - * Date: Oct 11, 2006 - * Time: 10:32:50 AM - * To change this template use File | Settings | File Templates. + * The AngSt class represents a geometric configuration of angles. + * It extends the CClass and includes properties for lines, dependencies, + * and other attributes related to angles. */ public class AngSt extends CClass { + /** The number of angles. */ public int no; + + /** The first set of lines that define the angles. */ public LLine[] ln1; + + /** The second set of lines that define the angles. */ public LLine[] ln2; + + /** The dependencies associated with the angles. */ long[] dep; + + /** A string representation of the angles. */ public String sd; - public AngSt nx; + /** The next AngSt object in a linked list structure. */ + public AngSt nx; + /** + * Constructs an AngSt object with default values. + */ public AngSt() { type = 1; no = 0; @@ -24,6 +35,11 @@ public AngSt() { dep = new long[1000]; } + /** + * Constructs an AngSt object with the specified number of lines. + * + * @param n the number of lines + */ public AngSt(int n) { no = 0; ln1 = new LLine[n]; @@ -31,6 +47,13 @@ public AngSt(int n) { dep = new long[n]; } + /** + * Checks if the specified lines are contained in the angles. + * + * @param l1 the first line + * @param l2 the second line + * @return true if the lines are contained in the angles, false otherwise + */ public boolean contain(LLine l1, LLine l2) { for (int i = 0; i < no; i++) { if (ln1[i] == l1 && ln2[i] == l2 || ln1[i] == l2 && ln2[i] == l1) @@ -39,6 +62,13 @@ public boolean contain(LLine l1, LLine l2) { return false; } + /** + * Gets the direction of the specified lines. + * + * @param l1 the first line + * @param l2 the second line + * @return 1 if the lines are in the same direction, -1 if they are in opposite directions, 0 otherwise + */ public int get_dr(LLine l1, LLine l2) { for (int i = 0; i < no; i++) { if (ln1[i] == l1 && ln2[i] == l2) @@ -49,6 +79,12 @@ public int get_dr(LLine l1, LLine l2) { return 0; } + /** + * Adds an angle to the angles. + * + * @param as the Angles object to add + * @return true if the angle was added, false otherwise + */ public boolean addAngle(Angles as) { boolean r1, r2; LLine l1 = as.l1; @@ -104,7 +140,13 @@ else if (ln1[i] == l4 && ln2[i] == l3) { return true; } + /** + * Returns a string representation of the angles. + * + * @return a string representation of the angles + */ + @Override public String toString() { return sd; } -} +} \ No newline at end of file diff --git a/src/main/java/gprover/AngTn.java b/src/main/java/gprover/AngTn.java index d14ea5b3..c77bb671 100644 --- a/src/main/java/gprover/AngTn.java +++ b/src/main/java/gprover/AngTn.java @@ -1,32 +1,61 @@ package gprover; -/** - * Created by IntelliJ IDEA. - * User: ye - * Date: Nov 16, 2006 - * Time: 2:21:58 PM - * To change this template use File | Settings | File Templates. - */ -public class AngTn extends CClass { - int lemma; - public LLine ln1, ln2, ln3, ln4; - public int t1, t2; - Cond co; - AngTn nx; - - public AngTn(LLine l1, LLine l2, LLine l3, LLine l4) { - this(); - ln1 = l1; - ln2 = l2; - ln3 = l3; - ln4 = l4; - } - - public AngTn() { - ln1 = ln2 = ln3 = ln4 = null; - co = null; - nx = null; - t1 = t2 = lemma = 0; - - } -} + /** + * The AngTn class represents a geometric configuration of four lines. + * It extends the CClass and includes properties for lemma, condition, + * and other attributes related to angles. + */ + public class AngTn extends CClass { + /** The lemma associated with the angles. */ + int lemma; + + /** The first line that defines the angles. */ + public LLine ln1; + + /** The second line that defines the angles. */ + public LLine ln2; + + /** The third line that defines the angles. */ + public LLine ln3; + + /** The fourth line that defines the angles. */ + public LLine ln4; + + /** The first integer attribute related to the angles. */ + public int t1; + + /** The second integer attribute related to the angles. */ + public int t2; + + /** The condition associated with the angles. */ + Cond co; + + /** The next AngTn object in a linked list structure. */ + AngTn nx; + + /** + * Constructs an AngTn object with the specified lines. + * + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @param l4 the fourth line + */ + public AngTn(LLine l1, LLine l2, LLine l3, LLine l4) { + this(); + ln1 = l1; + ln2 = l2; + ln3 = l3; + ln4 = l4; + } + + /** + * Constructs an AngTn object with default values. + */ + public AngTn() { + ln1 = ln2 = ln3 = ln4 = null; + co = null; + nx = null; + t1 = t2 = lemma = 0; + } + } \ No newline at end of file diff --git a/src/main/java/gprover/AngTr.java b/src/main/java/gprover/AngTr.java index 76cb20ef..7131dfb4 100644 --- a/src/main/java/gprover/AngTr.java +++ b/src/main/java/gprover/AngTr.java @@ -1,34 +1,59 @@ package gprover; -/** - * Created by IntelliJ IDEA. - * User: ye - * Date: Nov 17, 2006 - * Time: 11:06:48 AM - * To change this template use File | Settings | File Templates. - */ -public class AngTr extends CClass { - public int v, t1, t2; - public LLine l1; - public LLine l2; - Cond co; - AngTr nx; - - public AngTr() { - l1 = l2 = null; - co = null; - nx = null; - v = 0; - } - - - public int get_lpt1() { - if (t1 != 0) return t1; - return LLine.get_lpt1(l1, v); - } - - public int get_lpt2() { - if (t2 != 0) return t2; - return LLine.get_lpt1(l2, v); - } -} + /** + * The AngTr class represents a geometric configuration of two lines. + * It extends the CClass and includes properties for values, lines, + * and other attributes related to angles. + */ + public class AngTr extends CClass { + /** An integer value associated with the angle. */ + public int v; + + /** The first integer attribute related to the angle. */ + public int t1; + + /** The second integer attribute related to the angle. */ + public int t2; + + /** The first line that defines the angle. */ + public LLine l1; + + /** The second line that defines the angle. */ + public LLine l2; + + /** The condition associated with the angle. */ + Cond co; + + /** The next AngTr object in a linked list structure. */ + AngTr nx; + + /** + * Constructs an AngTr object with default values. + */ + public AngTr() { + l1 = l2 = null; + co = null; + nx = null; + v = 0; + } + + /** + * Gets the first point of the first line that is not equal to the value t1. + * + * @return the first point of the first line that is not equal to the value t1 + */ + public int get_lpt1() { + if (t1 != 0) return t1; + return LLine.get_lpt1(l1, v); + } + + /** + * Gets the first point of the second line that is not equal to the value t2. + * + * @return the first point of the second line that is not equal to the value t2 + */ + public int get_lpt2() { + if (t2 != 0) return t2; + return LLine.get_lpt1(l2, v); + } + } \ No newline at end of file diff --git a/src/main/java/gprover/AngleT.java b/src/main/java/gprover/AngleT.java index d97e6a72..0437753b 100644 --- a/src/main/java/gprover/AngleT.java +++ b/src/main/java/gprover/AngleT.java @@ -1,54 +1,93 @@ package gprover; -/** - * Created by IntelliJ IDEA. - * User: ye - * Date: Nov 4, 2006 - * Time: 1:57:36 PM - * To change this template use File | Settings | File Templates. - */ -public class AngleT extends CClass { // angle with intersection; - public int lemma; - public int p; - public LLine l1; - public LLine l2; - public int v; - Cond co; - AngleT nx; - - public AngleT() { - p = 0; - l1 = l2 = null; - v = 0; - nx = null; - } - - public AngleT(int p, LLine l1, LLine l2, int v) { - this(); - this.p = p; - this.l1 = l1; - this.l2 = l2; - this.v = v; - } - - - public int get_pt1() { - if (l1.pt[0] == p) - return l1.pt[1]; - else - return l1.pt[0]; - } - - public int get_pt2() { - if (l2.pt[0] == p) - return l2.pt[1]; - else - return l2.pt[0]; - } - - public int get_val(int p1, int p2) { - if (l1.on_ln(p1) && l2.on_ln(p2)) return v; - if (l1.on_ln(p2) && l2.on_ln(p1)) return -v; - return 9999; // shall never happen. - } -} + /** + * The AngleT class represents an angle with an intersection. + * It extends the CClass and includes properties for lemma, points, lines, + * and other attributes related to the angle. + */ + public class AngleT extends CClass { // angle with intersection; + + /** The lemma associated with the angle. */ + public int lemma; + + /** The point associated with the angle. */ + public int p; + + /** The first line that defines the angle. */ + public LLine l1; + + /** The second line that defines the angle. */ + public LLine l2; + + /** An integer value associated with the angle. */ + public int v; + + /** The condition associated with the angle. */ + Cond co; + + /** The next AngleT object in a linked list structure. */ + AngleT nx; + + /** + * Constructs an AngleT object with default values. + */ + public AngleT() { + p = 0; + l1 = l2 = null; + v = 0; + nx = null; + } + + /** + * Constructs an AngleT object with the specified values. + * + * @param p the point associated with the angle + * @param l1 the first line that defines the angle + * @param l2 the second line that defines the angle + * @param v an integer value associated with the angle + */ + public AngleT(int p, LLine l1, LLine l2, int v) { + this(); + this.p = p; + this.l1 = l1; + this.l2 = l2; + this.v = v; + } + + /** + * Gets the first point of the first line that is not equal to the point p. + * + * @return the first point of the first line that is not equal to the point p + */ + public int get_pt1() { + if (l1.pt[0] == p) + return l1.pt[1]; + else + return l1.pt[0]; + } + + /** + * Gets the first point of the second line that is not equal to the point p. + * + * @return the first point of the second line that is not equal to the point p + */ + public int get_pt2() { + if (l2.pt[0] == p) + return l2.pt[1]; + else + return l2.pt[0]; + } + + /** + * Gets the value associated with the angle based on the points p1 and p2. + * + * @param p1 the first point + * @param p2 the second point + * @return the value associated with the angle, or 9999 if the points do not lie on the lines + */ + public int get_val(int p1, int p2) { + if (l1.on_ln(p1) && l2.on_ln(p2)) return v; + if (l1.on_ln(p2) && l2.on_ln(p1)) return -v; + return 9999; // shall never happen. + } + } \ No newline at end of file diff --git a/src/main/java/gprover/Angles.java b/src/main/java/gprover/Angles.java index 4d0a6b36..ce8889ff 100644 --- a/src/main/java/gprover/Angles.java +++ b/src/main/java/gprover/Angles.java @@ -1,23 +1,38 @@ +package gprover; /** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2006-2-14 - * Time: 21:34:29 - * To change this template use File | Settings | File Templates. + * The Angles class represents a geometric configuration of four lines. + * It extends the CClass and includes properties for lemma, condition, + * and other attributes related to angles. */ -package gprover; - public class Angles extends CClass { - // int type; + /** The lemma associated with the angles. */ int lemma; + + /** The condition associated with the angles. */ Cond co; + + /** An integer attribute related to the angles. */ int sa; - public LLine l1,l2, l3, l4; + + /** The four lines that define the angles. */ + public LLine l1, l2, l3, l4; + + /** The next Angles object in a linked list structure. */ Angles nx; + + /** An integer attribute with a default value of 0. */ int atp = 0; + /** + * Constructs an Angles object with the specified lines. + * + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @param l4 the fourth line + */ public Angles(LLine l1, LLine l2, LLine l3, LLine l4) { this.l1 = l1; @@ -25,6 +40,10 @@ public Angles(LLine l1, LLine l2, LLine l3, LLine l4) this.l3 = l3; this.l4 = l4; } + + /** + * Constructs an Angles object with default values. + */ public Angles() { type = lemma = sa = 0; @@ -32,5 +51,4 @@ public Angles() nx = null; l1 = l2 = l3 = l4 = null; } - } diff --git a/src/main/java/gprover/Area.java b/src/main/java/gprover/Area.java index 748a7f2f..2ad76561 100644 --- a/src/main/java/gprover/Area.java +++ b/src/main/java/gprover/Area.java @@ -1,1330 +1,129 @@ package gprover; -/** - * Created by IntelliJ IDEA. - * User: yezheng - * Date: 2006-5-1 - * Time: 13:18:45 - * To change this template use File | Settings | File Templates. - */ -public class Area extends Full -{ - boolean elim_cir = false; - - int pts_pno; - void prove_area() - { - int fpt_no, ptn; - - max_term = 1; - elim_cir = false; - last_pr = proof = new GrTerm(); - proof.nx = null; - pts_pno = cons_no; - pconc(); - if (qerror) return; - ptn = pts_pno; - - - while (ptn >= 1 && !elim_cir) - { - if (end_pr()) - { - print_end(); - return; - } - if (elim_cir == false && ATYPE(ptn) == C_CIRCUM) - pe_gr(ptn); - else if (circle_p(ptn)) - { - elim_cir = true; - } else if (ATYPE(ptn) == C_CIRCLE) - { - elim_cir = true; - } else if (ATYPE(ptn) == C_POINT) - { - } else if (ATYPE(ptn) == -100) - { - } - else - pe_gr(ptn); - if (qerror) return; - ptn--; - } - - if (end_pr()) - { - print_end(); - return; - } - if (elim_cir == true) - { - int k1, k2; - GrTerm gr1 = last_pr; - pe_gr(-13); - if (end_pr()) - { - print_end(); - return; - } - pe_gr(-11); - if (end_pr()) - { - print_end(); - return; - } - if (gr1 != last_pr) - { - k1 = gr_length(gr1); - k2 = gr_length(last_pr); - if (k2 >= k1) - { - put_gr(last_pr); - last_pr = gr1; - } - } - pe_gr(-20); - if (end_pr()) - { - print_end(); - return; - } - pe_gr(-21); - if (end_pr()) - { - print_end(); - return; - } - pe_gr(-22); - if (end_pr()) - { - print_end(); - return; - } - pe_gr(-23); - elim_cir = false; - print_end(); - return; - } - if (vec_gr(last_pr)) - { - pe_gr(-30); - if (end_pr()) - { - print_end(); - return; - } - print_end(); - return; - } - fpt_no = 0; - while (ATYPE(fpt_no + 1) == C_POINT) fpt_no++; - if (fpt_no < 3) - { - print_end(); - return; - } - if (fpt_no == 3) - { - pe_gr(-10); - if (end_pr()) - { - print_end(); - return; - } - pe_gr(-11); - print_end(); - return; - } - if (area_gr(last_pr)) - { - for (ptn = fpt_no; ptn > 3; ptn--) - { - pe_gr(ptn); - } - print_end(); - return; - } - pe_gr(-12); - print_end(); - } - - boolean end_pr() - { - return ((last_pr.ps1 == null) && (last_pr.ps2 == null)); - } - - void print_end() - { - XTerm p1, p2; - if (last_pr.ps1 == null) - { - if ((last_pr.ps2 == null) && (last_pr.c1 == last_pr.c2)) print_t(); else print_f(); - return; - } - if (last_pr.ps2 == null) - { - if ((last_pr.ps1 == null) && (last_pr.c1 == last_pr.c2)) print_t(); else print_f(); - return; - } - p1 = ps_times(cp_pols(last_pr.ps1)); - p1 = ptimes(get_n(last_pr.c1), p1); - p2 = ps_times(cp_pols(last_pr.ps2)); - p2 = ptimes(get_n(last_pr.c2), p2); - if (eq_poly(p1, p2)) - { - put_p(p1); - conc_gr(1L, null, 1L, null); - last_pr.c = -1; - last_pr.ps = get_dt(1, p2, null); - if (last_pr.c1 == last_pr.c2) - { - print_t(); - return; - } else - { - print_f(); - return; - } - } - put_p(p1); - put_p(p2); - print_f(); - return; - } - - void print_t() - { - if (print_conc) - { //gprint("\r\n***************The results****** \r\n"); + /** + * The Area class represents a geometric area and extends the Full class. + * It includes methods for printing results, creating geometric terms, + * and evaluating geometric expressions. + */ + public class Area extends Full { + + /** + * Prints the results if the print_conc flag is set. + */ + void print_t() { + if (print_conc) { + // gprint("\r\n***************The results****** \r\n"); gprint(Cm.s2300); - } - //pro_result = 1; - } - - void print_f() - { - if (print_conc) - { //gprint("\n The results \n"); - gprint(Cm.s2301); - } - - gprint("(" + last_pr.c1 + ")"); - print_ps(last_pr.ps1, (char) 0); - gprint(" = "); - gprint("(" + last_pr.c2 + ")"); - print_ps(last_pr.ps2, (char) 0); - gprint("\r\n"); - //pro_result = -1; - } - - boolean area_gr(GrTerm gr) - { - DTerm ps; - ps = gr.ps1; - while (ps != null) if (area_p(ps.p)) ps = ps.nx; else return (false); - ps = gr.ps2; - while (ps != null) if (area_p(ps.p)) ps = ps.nx; else return (false); - return (true); - } - - boolean area_p(XTerm p) - { - DTerm ps; - Var v; - if (p.var == null) return (true); - v = p.var; - if (v.nm == 2 || v.nm < 0) - { - ps = p.ps; - while (ps != null) if (area_p(ps.p)) ps = ps.nx; else return (false); - return (true); - } else - return (false); - } - - boolean vec_gr(GrTerm gr) - { - DTerm ps; - ps = gr.ps1; - while (ps != null) if (vec_p(ps.p)) return (true); else ps = ps.nx; - ps = gr.ps2; - while (ps != null) if (vec_p(ps.p)) return (true); else ps = ps.nx; - return (false); - } - - boolean vec_p(XTerm p) -//xterm p; - { - DTerm ps; - Var v; - if (p.var == null) return (false); - v = p.var; - if (v.nm != 4) - { - ps = p.ps; - while (ps != null) if (vec_p(ps.p)) return (true); else ps = ps.nx; - return (false); - } else - return (true); - } - - boolean str_p(XTerm p) - { - DTerm ps; - Var v; - if (p.var == null) return (false); - v = p.var; - if (v.nm != 0) - { - ps = p.ps; - while (ps != null) if (str_p(ps.p)) return (true); else ps = ps.nx; - return (false); - } else - return (true); - } - - -/* conclusions */ - void conc_gr(long c1, XTerm p1, long c2, XTerm p2) - { - GrTerm gr = mk_gr1(mk_num(c1), p1, mk_num(c2), p2); - gr.c = 0; - last_pr.nx = gr; - last_pr = gr; - } - - void pconc() - { - switch (conc.pred) - { - case CO_COLL: /* collinear */ - conc_coll(); - break; - case CO_PARA: /* parallel */ - conc_gr(1L, trim_a(conc.p[0], conc.p[2], conc.p[3], conc.p[3]), - 1L, trim_a(conc.p[1], conc.p[2], conc.p[3], conc.p[3])); - break; - case CO_PERP: /* perpendicular */ - conc_gr(1L, trim_g(conc.p[0], conc.p[2], conc.p[2], conc.p[3]), - 1L, trim_g(conc.p[1], conc.p[2], conc.p[2], conc.p[3])); - break; - case CO_CONG: /* eqdistance */ - conc_gr(1L, trim_g(conc.p[0], conc.p[0], conc.p[1], conc.p[1]), - 1L, trim_g(conc.p[2], conc.p[2], conc.p[3], conc.p[3])); - break; - case CO_ACONG: /* eqangle */ - conc_gr(1L, ptimes(trim_a(conc.p[0], conc.p[1], conc.p[2], conc.p[3]), - trim_g(conc.p[4], conc.p[5], conc.p[6], conc.p[7])), - 1L, ptimes(trim_g(conc.p[0], conc.p[1], conc.p[2], conc.p[3]), - trim_a(conc.p[4], conc.p[5], conc.p[6], conc.p[7]))); - break; - case CO_MIDP: /*midpoint */ - conc_gr(1L, trim_r(conc.p[0], conc.p[1], conc.p[0], conc.p[2]), -1L, null); - break; - case CO_PROD: /*eq-product */ - conc_eqproduct(); - break; - case CO_CYCLIC: /*cocircle */ - conc_gr(1L, ptimes(trim_a(conc.p[3], conc.p[1], conc.p[1], conc.p[4]), - trim_g(conc.p[3], conc.p[2], conc.p[2], conc.p[4])), - 1L, ptimes(trim_g(conc.p[3], conc.p[1], conc.p[1], conc.p[4]), - trim_a(conc.p[3], conc.p[2], conc.p[2], conc.p[4]))); - break; - case -9: /*on_radical */ - conc_gr(1L, pminus(trim_g(conc.p[0], conc.p[1], conc.p[1], conc.p[0]), - trim_g(conc.p[1], conc.p[2], conc.p[2], conc.p[1])), - 1L, pminus(trim_g(conc.p[0], conc.p[3], conc.p[3], conc.p[0]), - trim_g(conc.p[3], conc.p[4], conc.p[4], conc.p[3]))); - break; - case CO_TANGENT: /*tangent */ - pconc_11(conc.p[0], conc.p[1], conc.p[2], conc.p[3]); - break; - case -12: /* perp-b */ - conc_gr(1L, trim_g(conc.p[0], conc.p[0], conc.p[1], conc.p[1]), - 1L, trim_g(conc.p[0], conc.p[0], conc.p[2], conc.p[2])); - break; - case CO_HARMONIC: /* harmonic */ - conc_gr(1L, trim_r(conc.p[2], conc.p[0], conc.p[2], conc.p[1]), - -1L, trim_r(conc.p[3], conc.p[0], conc.p[3], conc.p[1])); - break; - case -16: /* inversion */ - if (xcoll4(conc.p[1], conc.p[2], conc.p[3], conc.p[0])) - conc_gr(1L, trim_r(conc.p[0], conc.p[2], conc.p[0], conc.p[1]), - 1L, trim_r(conc.p[0], conc.p[1], conc.p[0], conc.p[3])); - else - conc_gr(1L, trim_g(conc.p[0], conc.p[1], conc.p[1], conc.p[0]), - 1L, trim_g(conc.p[2], conc.p[0], conc.p[0], conc.p[3])); - break; - case CO_PETRI: /*-18 pe-traingle */ - conc_gr(1L, pplus3(trim_vec(conc.p[0], 0), - ptimes(get_s("w".toCharArray()), trim_vec(conc.p[1], 0)), - ptimes3(get_s("w".toCharArray()), get_s("w".toCharArray()), trim_vec(conc.p[2], 0))), - 0L, null); - break; - -/* case CO_STRI: - conc_gr(1L,ptimes(trim_a(conc.p[0],conc.p[1],conc.p[2],conc.p[3]), - trim_g(conc.p[4],conc.p[5],conc.p[6],conc.p[7])), - 1L,ptimes(trim_g(conc.p[0],conc.p[1],conc.p[2],conc.p[3]), - trim_a(conc.p[4],conc.p[5],conc.p[6],conc.p[7]))); - break; - case CO_CTRI: - conc_gr(1L,ptimes(trim_a(conc.p[0],conc.p[1],conc.p[2],conc.p[3]), - trim_g(conc.p[4],conc.p[5],conc.p[6],conc.p[7])), - 1L,ptimes(trim_g(conc.p[0],conc.p[1],conc.p[2],conc.p[3]), - trim_a(conc.p[4],conc.p[5],conc.p[6],conc.p[7]))); - break; -*/ - case -21: /* eq-ratio */ - conc_gr(1L, trim_r(conc.p[0], conc.p[1], conc.p[2], conc.p[3]), - 1L, trim_r(conc.p[4], conc.p[5], conc.p[6], conc.p[7])); - break; - case CO_EQ: /* constants8 */ - if (npoly(conc_p1) && npoly(conc_p2)) - conc_gr(num_int(conc_p1.c), null, num_int(conc_p2.c), null); - if (npoly(conc_p1)) - conc_gr(num_int(conc_p1.c), null, 1L, conc_p2); - else if (npoly(conc_p2)) - conc_gr(1L, conc_p1, num_int(conc_p2.c), null); - else - conc_gr(1L, conc_p1, 1L, conc_p2); - break; - - default: - { - gerror(Cm.s2302 + conc.pred); - } - } - if (print_geo) - { - gprint("pconc:\r\n"); - print_gr(last_pr, (char) 0); - } - } - - - static int f_pt1, f_pt2; - - void fd_mpts(int pt) - { - int i, m; - LLine ln1 = null; - - m = 100; - LLine ln = all_ln.nx; - while (ln != null) - { - if (on_ln(pt, ln) && ln.no > 1) - { - for (i = 0; i <= ln.no; i++) - if (ln.pt[i] != pt && ln.pt[i] < m) - { - ln1 = ln; - m = ln.pt[i]; - } - } - ln = ln.nx; - } - f_pt1 = m; - m = 100; - for (i = 0; i <= ln1.no; i++) - if (ln1.pt[i] != pt && ln1.pt[i] != f_pt1 && ln1.pt[i] < m) m = ln1.pt[i]; - f_pt2 = m; - } - - void conc_coll() - { - int p, p1, p2, p3; - LLine ln; - p1 = conc.p[0]; - p2 = conc.p[1]; - p3 = conc.p[2]; - if (p1 > p2) - { - p = p1; - p1 = p2; - p2 = p; - } - if (p1 > p3) - { - p = p1; - p1 = p3; - p3 = p; - } - if (p2 > p3) - { - p = p2; - p2 = p3; - p3 = p; - } - - ln = fd_ln1(p3); - if (ln == null) - { - ln = fd_ln1(p2); - if (ln != null) - { - p = p2; - p2 = p3; - p3 = p; - ; - } else - { - ln = fd_ln1(p1); - if (ln != null) - { - p = p1; - p1 = p3; - p3 = p; - ; - } else - { - conc_gr(1L, trim_a(p1, p2, p3, p3), 0L, null); - return; - } - } - } - //l1: - fd_mpts(p3); - gprint("conc_coll: " + p1 + " " + p2 + " " + p3 + " " + f_pt1 + " " + f_pt2); - pts_pno++; - String s1 = ("I_{" + ANAME(p3) + "}"); - allpts[pts_pno] = new ProPoint(C_I_LL,s1,f_pt1,f_pt2,p1,p2,0,0,0,0); -// allpts[pts_pno].name = s1; -// allpts[pts_pno].type = C_I_LL; -// allpts[pts_pno].ps[0] = f_pt1; -// allpts[pts_pno].ps[1] = f_pt2; -// allpts[pts_pno].ps[2] = p1; -// allpts[pts_pno].ps[3] = p2; - add_line(0, pts_pno, APTS(pts_pno, 0), APTS(pts_pno, 1)); - add_line(0, pts_pno, APTS(pts_pno, 2), APTS(pts_pno, 3)); - conc_gr(1L, trim_r(f_pt1, p3, f_pt2, p3), 1L, trim_r(f_pt1, pts_pno, f_pt2, pts_pno)); - - - gprint("\r\n***************************************\r\n"); - gprint(Cm.s2303 + " " + ANAME(pts_pno) + " " + Cm.s2304); - // do_cons(6, pts_pno); ///////////////////////////////////////////////////////////////////////////////////////////////////////////// - gprint("\r\n\r\n"); - gprint(Cm.s2305); - gprint(ANAME(f_pt1) + " " + ANAME(p3) + " " + ANAME(f_pt2) + " " + ANAME(p3) + - ANAME(f_pt1) + " " + ANAME(pts_pno) + " " + ANAME(f_pt2) + " " + ANAME(pts_pno) + "\n" + - "\r\n\r\n"); - - } - - void conc_eqproduct() - { - int p1, p2, p3, p4, p5, p6, p7, p8; - p1 = conc.p[0]; - p2 = conc.p[1]; - p3 = conc.p[6]; - p4 = conc.p[7]; - p5 = conc.p[2]; - p6 = conc.p[3]; - p7 = conc.p[4]; - p8 = conc.p[5]; - if (xpara(p1, p2, p5, p6) && xpara(p3, p4, p7, p8)) - conc_gr(1L, trim_r(p1, p2, p5, p6), 1L, trim_r(p7, p8, p3, p4)); - else if (xpara(p1, p2, p7, p8) && xpara(p3, p4, p5, p6)) - conc_gr(1L, trim_r(p1, p2, p7, p8), 1L, trim_r(p5, p6, p3, p4)); - else if (xpara(p1, p2, p3, p4) && xpara(p5, p6, p7, p8)) - conc_gr(1L, trim_g(p1, p3, p2, p4), 1L, trim_g(p5, p7, p6, p8)); - else if (xcoll4(p1, p2, p3, p4)) - conc_gr(1L, ptimes(trim_g(p1, p3, p2, p4), trim_g(p1, p3, p2, p4)), - 1L, ptimes(trim_g(p5, p6, p6, p5), trim_g(p7, p8, p8, p7))); - else - conc_gr(1L, ptimes(trim_g(p1, p2, p2, p1), trim_g(p3, p4, p4, p3)), - 1L, ptimes(trim_g(p5, p6, p6, p5), trim_g(p7, p8, p8, p7))); - } - -/* -void pconc_11(p0,p1,p2,p3) -int p0,p1,p2,p3; -{ gr_term *gr; - xterm *po1,*po2,*po3; - dterm *ps1, *ps2; - po1=pminus(trim_g(p2,p3,p3,p2),trim_g(p0,p2,p2,p0)); - po2=trim_g(p0,p1,p1,p0); - po3=pplus3(ptimes(get_n(2L),trim_g(p0,p2,p2,p0)), - ptimes(get_n(2L),trim_g(p2,p3,p3,p2)), - ptimes(get_n(-1L),trim_g(p0,p1,p1,p0))); - ps1 = get_dt(2,po1,null); - ps2 = get_dt(1,po2,null); - ps2 = get_dt(1,po3,ps2); - - gr = mk_gr(mk_num(1L),ps1,mk_num(1L),ps2,0,null); - gr.c = 0; - last_pr.nx = gr; - last_pr = gr; -} */ - - void pconc_11(int p0, int p1, int p2, int p3) - { - GrTerm gr; - XTerm po1, po2, po3; - DTerm ps1, ps2; - po1 = pminus(pplus(trim_g(p0, p1, p1, p0), trim_g(p2, p3, p3, p2)), - trim_g(p0, p2, p2, p0)); - po2 = trim_g(p0, p1, p1, p0); - po3 = trim_g(p2, p3, p3, p2); - ps1 = get_dt(2, po1, null); - ps2 = get_dt(1, po2, null); - ps2 = get_dt(1, po3, ps2); - - gr = mk_gr(mk_num(1L), ps1, mk_num(4L), ps2, 0, null); - gr.c = 0; - last_pr.nx = gr; - last_pr = gr; - } - - - -/* eliminations */ - - ElTerm all_elim = new ElTerm(); - DTerm ds_set = new DTerm(); - DTerm last_ds; - - ElTerm mk_elim(Var v, XTerm p1, XTerm p2) - { - ElTerm v1 = new ElTerm();//(el_term )calloc(1,sizeof(el_term)); - v1.v = v; - v1.p1 = p1; - v1.p2 = p2; - v1.nx = all_elim.nx; - all_elim.nx = v1; - return (v1); - } - - - void pe_gr(int ptn) - { - GrTerm gr, gr0; - DTerm ps, ps1, ps2, qs1, qs2; - gr = last_pr; - - if (print_geo && ptn > 0) - { - gprint("\r\npe_gr: " + ptn + "(" + pt_name(ptn) + "\r\n"); - } - all_elim.nx = null; - ps1 = cp_pols(gr.ps1); - if (test_pt(ptn)) - { - ps1 = get_dt(1, ps_times(ps1), null); - } - ps = ps1; - ds_set.nx = null; - last_ds = ds_set; - while (ps != null) - { - ps.p = pe_p(ps.p, ptn, ps.deg); - ps = ps.nx; - if (qerror) - { - return; - } - } - qs1 = ds_set.nx; - if (qerror) return; - - ps2 = cp_pols(gr.ps2); - if (test_pt(ptn)) - { - ps2 = get_dt(1, ps_times(ps2), null); - } - ps = ps2; - ds_set.nx = null; - last_ds = ds_set; - while (ps != null) - { - ps.p = pe_p(ps.p, ptn, ps.deg); - ps = ps.nx; - if (qerror) - { - return; - } - } - qs2 = ds_set.nx; - - if (all_elim.nx != null) - { - gr0 = mk_gr(gr.c1, ps_append(ps1, qs2), - gr.c2, ps_append(ps2, qs1), ptn, null); - gr0.el = all_elim.nx; - last_pr.nx = gr0; - last_pr = gr0; - gr0 = simp_gr(gr0); - if (gr0 != null) - { - if (num_zop(gr0.c1) && num_zop(gr0.c2)) - { - last_pr = gr0; - } else - { - last_pr.nx = gr0; - last_pr = gr0; - } - last_pr.nx = null; - } - } - } - - boolean test_pt(int ptn) - { - if (ptn > 0) return (ATYPE(ptn) == -1); - return (ptn == -10 || ptn == -23); - } - - XTerm pe_p(XTerm p, int c, int d) - { - Var v1; - ElTerm el1; - XTerm p1; - -// if (print_geo) { wsprintf(txt,"\r\n\r\npe_p: (%d)",c); gprint(txt); } - - if (c < 0) return (pe_pv(p, c, d)); - if (ATYPE(c) == C_CONSTANT) return (pe_pv(p, c, d)); - - p1 = p; - l1: ///////////////////////??????????? - //if (c==5) { gprint("\r\npe_p:"); pprint(p1); } - while (true) - { - if (p1.var == null) - { - return (p1); - } - v1 = p1.var; - if (v1.nm <= 0) - { - return (p1); - } else if (lpt(v1) < c) - { - return (p1); - } else if (lpt(v1) == c) - { - if (elim_varp(v1, c)) - { - el1 = all_elim.nx; - while ((el1 != null) && (el1.v != v1)) el1 = el1.nx; - if (el1 == null) el1 = pe_v_c(v1, c); - if (qerror) - { - return (null); - } - if (el1 == null) - { - gerror(Cm.s2314); - return (null); - } - p1 = eprem(p1, el1); - if (init_deg > 0) - { - last_ds.nx = get_dt(d * init_deg, cp_poly(el1.p2), null); - last_ds = last_ds.nx; - } - if (max_termp) - { - int tem = plength(p1); - if (tem > max_term) max_term = tem; - } - //goto l1; - } else - return (p1); - } else - { - gerror("pe_p: ERRRRROR"); - } - } - // return (null); //???? - } - - boolean elim_varp(Var v, int pt) - { - if (ATYPE(pt) == 11) - { - if (v.nm == 3) - { - if (c_pt(v.pt[0], pt) && c_pt(v.pt[1], pt) && - c_pt(v.pt[2], pt) && c_pt(v.pt[3], pt)) - return (true); - else - return (false); - } else - return (false); - } - return (true); - } - - boolean c_pt(int pt, int c) - { - return ((pt == c) || (pt == APTS(c, 0)) || (pt == APTS(c, 1))); - } - - - XTerm eprem(XTerm p, ElTerm e) - { - XTerm p1, p2, p3; - if (e == null) return p; - p2 = get_n(1L); - if (e.p1 == null) - { - p1 = prem_var(p, e.p2, e.v); - p3 = init_v(cp_poly(e.p2), e.v); - if (eq_poly(p3, p2)) - { - init_deg = 0; - } - put_p(p3); - } else - { - p1 = get_m(e.v); - p1 = ptimes(p1, cp_poly(e.p2)); - p1 = pminus(p1, cp_poly(e.p1)); - p1 = prem_var(p, p1, e.v); - if (eq_poly(e.p2, p2)) - { - init_deg = 0; - } - } - put_x(p2); - return (p1); - } - - ElTerm pe_v_c(Var v, int ptn) - { - int etype = 0; - - int[] p = new int[9]; - ElTerm e1 = null; - int j; - for (j = 0; j <= 5; j++) p[j + 1] = APTS(ptn, j); - - switch (ATYPE(ptn)) - { - case C_POINT: /*free point*/ - e1 = pe_v_fpt(v, ptn); - break; - case C_MIDPOINT: /* midpoint */ - e1 = pe_v_pratio(v, ptn, p[1], p[1], p[2], get_n(1L), get_n(2L)); - break; - case C_SYM: /* sym */ - e1 = pe_v_pratio(v, ptn, p[1], p[1], p[2], get_n(1L), get_n(1L)); - break; - case C_LRATIO: - e1 = pe_v_pratio(v, ptn, p[1], p[1], p[2], cp_poly(P1(ptn)), cp_poly(P2(ptn))); - break; - case 100://C_MRATIO: - e1 = pe_v_pratio(v, ptn, p[1], p[1], p[2], cp_poly(P1(ptn)), - c_pplus(P1(ptn), P2(ptn))); - break; - case C_PRATIO: - e1 = pe_v_pratio(v, ptn, p[1], p[2], p[3], cp_poly(P1(ptn)), cp_poly(P2(ptn))); - break; - case 71: /* tratio */ - e1 = pe_v_tratio(v, ptn, p[1], p[2], p[3], cp_poly(P1(ptn)), cp_poly(P2(ptn))); - break; - - case C_O_L: /* on-line */ - e1 = pe_v_pratio(v, ptn, p[1], p[1], p[2], get_m(mk_var(-1, p[1], ptn, p[1], p[2])), get_n(1L)); - break; - case C_O_T: /*on-tline*/ - String s = ("t_{" + ANAME(ptn) + "}"); - e1 = pe_v_tratio(v, ptn, p[1], p[2], p[3], get_s(s.toCharArray()), get_n(1L)); - break; - case C_O_P: /* on-pline */ - e1 = pe_v_pratio(v, ptn, p[1], p[2], p[3], get_m(mk_var(-1, p[1], ptn, p[3], p[4])), get_n(1L)); - break; -// case C_O_C: /* on-circle */ -// break; - case C_O_A: /* on-aline */ - e1 = pe_v_tratio(v, ptn, p[2], p[2], p[1], - ptimes(get_n(-4L), trim_a(p[3], p[4], p[4], p[5])), - trim_g(p[3], p[4], p[4], p[5])); - break; - case C_I_LL: /* intersection-ll */ - e1 = pe_v_ipp(v, ptn, p[1], p[1], p[2], p[3], p[3], p[4]); -/* - switch(v.nm) - { case 1: - e1 = pe_r_ill(v,v.pt[1],v.pt[0],v.pt[3],v.pt[2],ptn,p[1],p[2],p[3],p[4]); - break; - case 2: - e1 = pe_a_ill(v,v.pt[0],v.pt[1],v.pt[2],v.pt[3],ptn,p[1],p[2],p[3],p[4]); - break; - case 3: - e1 = pe_g_ill(v,v.pt[0],v.pt[1],v.pt[2],v.pt[3],ptn,p[1],p[2],p[3],p[4]); - break; - case 4: - e1 = pe_vec_ill(v,v.pt[0],v.pt[1],ptn,p[1],p[2],p[3],p[4]); - break; - } -*/ - break; - case C_FOOT: /* foot */ - e1 = pe_v_ipt(v, ptn, p[2], p[2], p[3], p[1], p[2], p[3]); -/* switch(v.nm) - { case 1: - e1 = pe_r_foot(v,v.pt[1],v.pt[0],v.pt[3],v.pt[2],ptn,p[1],p[2],p[3]); - break; - case 2: - e1 = pe_a_foot(v,v.pt[0],v.pt[1],v.pt[2],v.pt[3],ptn,p[1],p[2],p[3]); - break; - case 3: - e1 = pe_g_foot(v,v.pt[0],v.pt[1],v.pt[2],v.pt[3],ptn,p[1],p[2],p[3]); - break; - } -*/ - break; - case C_I_TT: /* intersection-tt */ - switch (v.nm) - { - case 1: - /* e1 = pe_r_itt(v,v.pt[1],v.pt[0],v.pt[3],v.pt[2],ptn,p[1],p[2],p[3],p[4],p[5],p[6]); */ - //sprintf(txt, "%s %s %s", ANAME(ptn), PDSTR(2307), PDSTR(2308)); - gerror(ANAME(ptn) + Cm.s2307 + " " + Cm.s2308); - e1 = null; - break; - case 2: - e1 = pe_a_itt(v, v.pt[0], v.pt[1], v.pt[2], v.pt[3], ptn, p[1], p[2], p[3], p[4], p[5], p[6]); - break; - case 3: - e1 = pe_g_itt(v, v.pt[0], v.pt[1], v.pt[2], v.pt[3], ptn, p[1], p[2], p[3], p[4], p[5], p[6]); - break; - default: - gerror("pe_v_c: itt"); - } - break; - case C_I_LT: /* intersection-lt */ - e1 = pe_v_ipt(v, ptn, p[1], p[1], p[2], p[3], p[4], p[5]); - break; - case C_I_LP: /* intersection-lp */ - e1 = pe_v_ipp(v, ptn, p[1], p[1], p[2], p[3], p[4], p[5]); -/* switch(v.nm) - { case 1: - e1 = pe_r_ilp(v,v.pt[1],v.pt[0],v.pt[3],v.pt[2],ptn,p[1],p[2],p[3],p[4],p[5]); - break; - case 2: - e1 = pe_a_ilp(v,v.pt[0],v.pt[1],v.pt[2],v.pt[3],ptn,p[1],p[2],p[3],p[4],p[5]); - break; - case 3: - e1 = pe_g_ilp(v,v.pt[0],v.pt[1],v.pt[2],v.pt[3],ptn,p[1],p[2],p[3],p[4],p[5]); - break; - } -*/ - break; - case C_I_PP: /* intersection-pp */ - e1 = pe_v_ipp(v, ptn, p[1], p[2], p[3], p[4], p[5], p[6]); - break; - case C_I_PT: /* intersection-pt */ - e1 = pe_v_ipt(v, ptn, p[1], p[2], p[3], p[4], p[5], p[6]); - break; - -/* intersection of line and circle */ - case C_I_LC: /* intersection-lc */ - if (p[2] == p[4]) - e1 = pe_v_ipc(v, ptn, p[2], p[2], p[1], p[3], p[4]); - else if (p[1] == p[4]) - e1 = pe_v_ipc(v, ptn, p[1], p[1], p[2], p[3], p[4]); - //else goto err3; - else - etype = 3; - break; - case C_I_PC: /* intersection-pc */ - if (p[1] == p[5]) - e1 = pe_v_ipc(v, ptn, p[1], p[2], p[3], p[4], p[5]); - //else goto err3; - else - etype = 3; - break; - case C_I_CC: /* intersection-cc */ - if (p[2] != p[4]) - etype = 3; - else - e1 = pe_v_tratio(v, ptn, p[2], p[1], p[3], - ptimes(get_n(-8L), trim_a(p[2], p[1], p[3], p[3])), - trim_g(p[1], p[3], p[3], p[1])); - break; - case C_REF: /* reflection */ - e1 = pe_v_tratio(v, ptn, p[1], p[2], p[3], - ptimes(get_n(-8L), trim_a(p[1], p[2], p[3], p[3])), - trim_g(p[2], p[3], p[3], p[2])); - break; - case C_CENT: /* CENTROID */ - e1 = pe_v_cent(v, ptn, p[1], p[2], p[3]); - break; - case C_ORTH: /* orthocenter */ - switch (v.nm) - { - case 1: -/* e1 = pe_r_orth(v,v.pt[1],v.pt[0],v.pt[3],v.pt[2],ptn,p[1],p[2],p[3]); */ - //goto err3; - etype = 3; - break; - case 2: - e1 = pe_a_orth(v, v.pt[0], v.pt[1], v.pt[2], v.pt[3], ptn, p[1], p[2], p[3]); - break; - case 3: - e1 = pe_g_orth(v, v.pt[0], v.pt[1], v.pt[2], v.pt[3], ptn, p[1], p[2], p[3]); - break; - case 4: - e1 = orth_md(v, ptn, p[1], p[2], p[3]); - break; - } - break; - case C_CIRCUM: /* circumcenter */ - switch (v.nm) - { - case 1: - e1 = pe_r_circum(v, v.pt[1], v.pt[0], v.pt[3], v.pt[2], ptn, p[1], p[2], p[3]); - break; - case 2: - e1 = pe_a_circum(v, v.pt[0], v.pt[1], v.pt[2], v.pt[3], ptn, p[1], p[2], p[3]); - break; - case 3: - e1 = pe_g_circum(v, v.pt[0], v.pt[1], v.pt[2], v.pt[3], ptn, p[1], p[2], p[3]); - break; - case 4: - e1 = circum_md(v, ptn, p[1], p[2], p[3]); - break; - default: - gerror("pe_v_c111"); - } - break; - case C_ICENT1: /* incenter */ - gerror(ANAME(ptn) + " " + Cm.s2311 + " " + Cm.s2312); - e1 = null; - return null; - - case C_ICENT: /* incenter */ - switch (v.nm) - { - case 1: - e1 = pe_r_incent(v, v.pt[1], v.pt[0], v.pt[3], v.pt[2], ptn, p[3], p[1], p[2]); - break; - case 2: - e1 = pe_a_incent(v, v.pt[0], v.pt[1], v.pt[2], v.pt[3], ptn, p[3], p[1], p[2]); - break; - case 3: - e1 = pe_g_incent(v, v.pt[0], v.pt[1], v.pt[2], v.pt[3], ptn, p[3], p[1], p[2]); - break; - case 4: - e1 = incent_md(v, ptn, p[3], p[1], p[2]); - break; - default: - gerror("pe_v_c111"); - } - break; - case C_INVERSION: /* inversion */ - if (xcoll(p[1], p[2], p[3])) - e1 = pe_v_pratio(v, ptn, p[2], p[2], p[3], trim_r(p[2], p[3], p[2], p[1]), get_n(1L)); - else - e1 = pe_v_pratio(v, ptn, p[2], p[2], p[1], - trim_g(p[2], p[3], p[3], p[2]), trim_g(p[2], p[1], p[1], p[2])); - break; - case C_PSQUARE: /* psquare */ - e1 = pe_v_square(v, ptn, p[1], p[2], 1); - break; - case C_NSQUARE: /* nsquare */ - e1 = pe_v_square(v, ptn, p[1], p[2], -1); - break; - case C_PETRIANGLE: /* pe-triangle */ - if (v.nm != 4) - { - gerror(Cm.s2313); - return null; - } - e1 = pe_v_ptri(v, ptn, p[1], p[2]); - break; - -// case C_NETRIANGLE: /* ne-triangle */ -// e1 = pe_v_ntri(v,ptn,p[1],p[2]); -// break; -/* - case -71: // harmonic - e1 = pe_v_pratio(v,ptn,p[2],p[2],p[3], - trim_r(p[2],p[1],p[3],p[1]), - pplus(trim_r(p[2],p[1],p[3],p[1]),get_n(1L))); - break; - case -76: // ps-triangle similar - e1 = pe_v_sim(v,ptn,p[1],p[2],p[3],p[4],p[5]); - -*/ - default: - gerror(ANAME(ptn) + " " + Cm.s2307 + " " + Cm.s2308); - e1 = null; - } - if (etype == 0) - return (e1); - - err3: - gerror(ANAME(ptn) + " " + Cm.s2310); - e1 = null; - return null; - } - - - XTerm pe_pv(XTerm p, int c, int d) - { - Var v1; - ElTerm e1; - XTerm p1, p2, p3; - - if (c > 0) - p1 = get_xt(P1(c).var, null); - else - p1 = vars_in_p(p); - { - //sprintf(txt,"\r\npe_pv: %d %d\r\n",c,d); gprint(txt); pprint(p); - } - while (p1 != null) - { - v1 = p1.var; - if (test_pv(v1, c)) - { - e1 = all_elim.nx; - while ((e1 != null) && (e1.v != v1)) e1 = e1.nx; - if (e1 == null) e1 = pe_v_nc(v1, c); - if (e1 == null) - { - p2 = p1; - p1 = p1.p; - put_x(p2); - continue; - } - p = eprem(p, e1); - if (init_deg > 0) - { - if (e1.p1 == null) - p3 = init_v(cp_poly(e1.p2), e1.v); - else - p3 = cp_poly(e1.p2); - { - last_ds.nx = get_dt(d * init_deg, p3, null); - last_ds = last_ds.nx; - } - } - if (max_termp) - { - int tem = plength(p); - if (tem > max_term) max_term = tem; - } - } - p2 = p1; - p1 = p1.p; - put_x(p2); - } - return (p); - } - - boolean test_pv(Var v, int c) - { - switch (c) - { - case -10: - return (v.nm == 2); - case -11: - return (v.nm == 3 && !(v.pt[1] == v.pt[2] && v.pt[0] == v.pt[3])); - case -12: - return (v.nm > 0); - case -13: - return (v.nm == 3); - case -20: - return (v.nm == 2 || v.nm == 3); - case -21: - return (v.nm == 5); - case -22: - return (v.nm == 6 || v.nm == 7); - case -23: - return (v.nm == 17); - case -30: - return (v.nm == 4 && v.pt[1] != 0); - - } - return (true); - } - - ElTerm pe_v_nc(Var v, int ptn) - { - ElTerm e1 = null; - -/* if (print_geo) { printf("\r\npe_v_nc in \r\n");print_var(v); printf("\r\n"); } */ - if (ptn > 0) return (mk_elim(v, null, P1(ptn))); - switch (ptn) - { - case -10: /* herron */ - e1 = mk_elim(v, null, - pplus(ptimes(get_n(16L), get_v(v, 2, get_n(1L))), - pplus(ptimes(trim_g(v.pt[0], v.pt[2], v.pt[2], v.pt[0]), - trim_g(v.pt[1], v.pt[1], v.pt[3], v.pt[3])), - ptimes(trim_g(v.pt[0], v.pt[1], v.pt[2], v.pt[3]), - trim_g(v.pt[0], v.pt[1], v.pt[2], v.pt[3]))))); - break; - case -11: /* d2s */ - e1 = mk_elim(v, pminus(pplus(trim_g(v.pt[0], v.pt[1], v.pt[1], v.pt[0]), - trim_g(v.pt[2], v.pt[3], v.pt[3], v.pt[2])), - pplus(trim_g(v.pt[1], v.pt[2], v.pt[2], v.pt[1]), - trim_g(v.pt[3], v.pt[0], v.pt[0], v.pt[3]))), - get_n(2L)); - break; - case -12: /* o-xy */ - switch (v.nm) - { - case 2: - e1 = mk_elim(v, area_q(v.pt[0], v.pt[1], v.pt[2], v.pt[3]), get_n(2L)); - break; - case 3: - e1 = mk_elim(v, py_q(v.pt[0], v.pt[1], v.pt[2], v.pt[3]), get_n(1L)); - break; - default: - gerror("pe_v_nc1"); - } - break; - case -13: /* for the circumcenter */ - { - if (xcir3(v.pt[0], v.pt[1], v.pt[2], v.pt[3])) - e1 = mk_elim(v, pminus(trim_g(v.pt[2], v.pt[3], v.pt[3], v.pt[2]), - trim_g(v.pt[1], v.pt[2], v.pt[2], v.pt[1])), - get_n(2L)); - else if (xcir3(v.pt[1], v.pt[0], v.pt[2], v.pt[3])) - e1 = mk_elim(v, pminus(trim_g(v.pt[2], v.pt[3], v.pt[3], v.pt[2]), - trim_g(v.pt[0], v.pt[3], v.pt[3], v.pt[0])), get_n(2L)); - else if (xcir3(v.pt[2], v.pt[0], v.pt[1], v.pt[3])) - e1 = mk_elim(v, pminus(trim_g(v.pt[0], v.pt[1], v.pt[1], v.pt[0]), - trim_g(v.pt[0], v.pt[3], v.pt[3], v.pt[0])), get_n(2L)); - else if (xcir3(v.pt[3], v.pt[0], v.pt[1], v.pt[2])) - e1 = mk_elim(v, pminus(trim_g(v.pt[0], v.pt[1], v.pt[1], v.pt[0]), - trim_g(v.pt[1], v.pt[2], v.pt[2], v.pt[1])), get_n(2L)); - - } - break; - case -20: /* circle */ - e1 = pe_circle(v, v.pt[0], v.pt[1], v.pt[2], v.pt[3]); - break; - case -21: /* chord */ - e1 = mk_elim(v, ptimes(get_m(mk_svar("\\d".toCharArray())), trim_s(v.pt[0], v.pt[1])), get_n(1L)); - break; - case -22: /* sin-cos */ - e1 = pe_sc(v, v.pt[0], v.pt[1]); - break; - case -23: /* sin^2 + cos^2=1 */ - e1 = mk_elim(v, null, pplus3(get_n(-1L), ppower(sc(v.pt[0]), 2), ppower(cc(v.pt[0]), 2))); - break; - case -30: /* vector */ - e1 = mk_elim(v, pminus(trim_vec(v.pt[0], 0), trim_vec(v.pt[1], 0)), get_n(1L)); - break; - default: - gerror("pe_v_nc2"); - } - if (print_geo) - { - gprint("\r\npe_v_nc = \r\n"); - print_elim(e1, (char) 0); - gprint("\r\n"); - } - return (e1); - } - - XTerm geval(Var var, int y, int p) - { - int[] pt = new int[9]; - - for (int i = 0; i < 4; i++) + } + // pro_result = 1; + } + + /** + * Creates a geometric term with the specified coefficients and terms. + * + * @param c1 the first coefficient + * @param p1 the first term + * @param c2 the second coefficient + * @param p2 the second term + */ + void conc_gr(long c1, XTerm p1, long c2, XTerm p2) { + GrTerm gr = mk_gr1(mk_num(c1), p1, mk_num(c2), p2); + gr.c = 0; + last_pr.nx = gr; + last_pr = gr; + } + + /** The head of the elimination term linked list. */ + ElTerm all_elim = new ElTerm(); + + /** + * Creates an elimination term with the specified variable and terms. + * + * @param v the variable + * @param p1 the first term + * @param p2 the second term + * @return the created elimination term + */ + ElTerm mk_elim(Var v, XTerm p1, XTerm p2) { + ElTerm v1 = new ElTerm(); // (el_term )calloc(1,sizeof(el_term)); + v1.v = v; + v1.p1 = p1; + v1.p2 = p2; + v1.nx = all_elim.nx; + all_elim.nx = v1; + return v1; + } + + /** + * Evaluates a geometric expression with the specified variable, integer, and point. + * + * @param var the variable + * @param y the integer + * @param p the point + * @return the evaluated geometric term + */ + XTerm geval(Var var, int y, int p) { + int[] pt = new int[9]; + + for (int i = 0; i < 4; i++) if (var.pt[i] == y) - pt[i] = p; + pt[i] = p; else - pt[i] = var.pt[i]; - switch (var.nm) - { + pt[i] = var.pt[i]; + switch (var.nm) { case 1: case -1: - return (trim_r(pt[0], pt[1], pt[2], pt[3])); + return trim_r(pt[0], pt[1], pt[2], pt[3]); case 2: case -2: - return (trim_a(pt[0], pt[1], pt[2], pt[3])); + return trim_a(pt[0], pt[1], pt[2], pt[3]); case 3: case -3: - return (trim_g(pt[0], pt[1], pt[2], pt[3])); + return trim_g(pt[0], pt[1], pt[2], pt[3]); case 4: case -4: - return (trim_vec(pt[0], pt[1])); + return trim_vec(pt[0], pt[1]); default: - exit(1); - } - return (null); - } - - - XTerm trim_r(int p1, int p2, int p3, int p4) - { - int p; - char sn = 1; -/* if (print_geo) printf("trim_r %d %d %d %d\r\n",p1,p2,p3,p4); */ - if (p1 == p2) return (pzero()); - if (p3 == p4) gerror("rtrim: denominator of ratio is zero.~%"); - if ((p1 == p3) && (p2 == p4)) return (get_n(1L)); - if ((p2 == p3) && (p1 == p4)) return (get_n(-1L)); - if (p1 < p2) - { - sn *= -1; - p = p1; - p1 = p2; - p2 = p; - } - if (p3 < p4) - { - sn *= -1; - p = p3; - p3 = p4; - p4 = p; - } - if (sn == 1) - return (get_m(mk_var(1, p1, p2, p3, p4))); - else - return (neg_poly(get_m(mk_var(1, p1, p2, p3, p4)))); - - } - - XTerm trim_a(int p1, int p2, int p3, int p4) -//int p1,p2,p3,p4; - { - int p; - char sn = 1; -/* if (print_geo) printf("trim_a1 %d %d %d %d\r\n",p1,p2,p3,p4); */ - if (xpara(p1, p3, p2, p4)) return (pzero()); - if (xcoll(p1, p2, p3)) - { + exit(1); + } + return null; + } + + /** + * Trims a geometric term with the specified points. + * + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @param p4 the fourth point + * @return the trimmed geometric term + */ + XTerm trim_a(int p1, int p2, int p3, int p4) { + int p; + char sn = 1; + if (xpara(p1, p3, p2, p4)) return pzero(); + if (xcoll(p1, p2, p3)) { p2 = p1; - } else if (xcoll(p4, p2, p3)) - { + } else if (xcoll(p4, p2, p3)) { p3 = p4; - } else if (xcoll(p4, p1, p3)) - { + } else if (xcoll(p4, p1, p3)) { p4 = p3; - } else if (xcoll(p4, p2, p1)) - { + } else if (xcoll(p4, p2, p1)) { p1 = p4; - } -/* if (print_geo) printf("trim_a2 %d %d %d %d\r\n",p1,p2,p3,p4); */ - if (p1 < p3) - { + } + if (p1 < p3) { sn *= -1; p = p1; p1 = p3; p3 = p; - } - if (p2 < p4) - { + } + if (p2 < p4) { sn *= -1; p = p2; p2 = p4; p4 = p; - } - if (p1 < p2) - { + } + if (p1 < p2) { sn *= -1; p = p1; p1 = p2; @@ -1332,105 +131,53 @@ XTerm trim_a(int p1, int p2, int p3, int p4) p = p3; p3 = p4; p4 = p; - } else if ((p1 == p2) && (p3 < p4)) - { + } else if ((p1 == p2) && (p3 < p4)) { sn *= -1; p = p3; p3 = p4; p4 = p; - } + } - if (p1 == p2) - { + if (p1 == p2) { p2 = p3; p3 = p4; - } else if (p2 == p3) - { - p3 = p4; - } - - if (sn == 1) - return (get_m(mk_var(2, p1, p2, p3, p4))); - else - return (neg_poly(get_m(mk_var(2, p1, p2, p3, p4)))); - } - - XTerm trim_g(int p1, int p2, int p3, int p4) - { - int p; - char sn = 1; -/* if (print_geo) printf("\r\ntrim_g %d %d %d %d\r\n",p1,p2,p3,p4); */ - if (xperp(p1, p3, p2, p4)) return (get_n(0L)); - if (p1 < p3) - { - sn *= -1; - p = p1; - p1 = p3; - p3 = p; - } - if (p2 < p4) - { - sn *= -1; - p = p2; - p2 = p4; - p4 = p; - } - if (p1 < p2) - { - p = p1; - p1 = p2; - p2 = p; - p = p3; - p3 = p4; - p4 = p; - } else if ((p1 == p2) && (p3 < p4)) - { - p = p3; + } else if (p2 == p3) { p3 = p4; - p4 = p; - } - - if (p1 == p2) - { - sn *= -1; - p1 = p3; - p3 = p2; - } else if (p3 == p4) - { - sn *= -1; - p4 = p2; - p2 = p3; - } - //The largest index is either p1 or p2 - if (sn == 1) - return (get_m(mk_var(3, p1, p2, p3, p4))); - else - return (neg_poly(get_m(mk_var(3, p1, p2, p3, p4)))); - } - - XTerm trim_f(int p1, int p2, int p3, int p4) - { - int p; - char sn = 1; - if (print_geo) - { + } + + if (sn == 1) + return get_m(mk_var(2, p1, p2, p3, p4)); + else + return neg_poly(get_m(mk_var(2, p1, p2, p3, p4))); + } + + /** + * Trims a geometric term with the specified points. + * + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @param p4 the fourth point + * @return the trimmed geometric term + */ + XTerm trim_f(int p1, int p2, int p3, int p4) { + int p; + char sn = 1; + if (print_geo) { gprint("trim_a1 " + p1 + p2 + p3 + p4 + "\r\n"); - } - if (xcoll4(p1, p2, p3, p4)) return (pzero()); - if (p1 < p2) - { + } + if (xcoll4(p1, p2, p3, p4)) return pzero(); + if (p1 < p2) { p = p1; p1 = p2; p2 = p; - } - if (p3 < p4) - { + } + if (p3 < p4) { p = p3; p3 = p4; p4 = p; - } - if (p1 < p3) - { + } + if (p1 < p3) { sn *= -1; p = p1; p1 = p3; @@ -1438,56 +185,28 @@ XTerm trim_f(int p1, int p2, int p3, int p4) p = p2; p2 = p4; p4 = p; - } else if ((p1 == p3) && (p2 < p4)) - { + } else if ((p1 == p3) && (p2 < p4)) { sn *= -1; p = p2; p2 = p4; p4 = p; - } - if (sn == 1) - return (get_m(mk_var(10, p1, p2, p3, p4))); - else - return (neg_poly(get_m(mk_var(10, p1, p2, p3, p4)))); - } - - XTerm trim_fl(LLine l1, LLine l2) - { - if (l1 == l2) return (pzero()); - return (trim_f(l1.pt[0], l1.pt[1], l2.pt[0], l2.pt[1])); + } + if (sn == 1) + return get_m(mk_var(10, p1, p2, p3, p4)); + else + return neg_poly(get_m(mk_var(10, p1, p2, p3, p4))); + } + + /** + * Trims a geometric term with the specified lines. + * + * @param l1 the first line + * @param l2 the second line + * @return the trimmed geometric term + */ + @Override + XTerm trim_fl(LLine l1, LLine l2) { + if (l1 == l2) return pzero(); + return trim_f(l1.pt[0], l1.pt[1], l2.pt[0], l2.pt[1]); + } } - - XTerm trim_vec(int p1, int p2) - { - if (p2 == 0) - { - return (get_m(mk_var(4, p1, 0, 0, 0))); - } - if (p1 == p2) return (pzero()); - if (p1 < p2) return (neg_poly(get_m(mk_var(4, p2, p1, 0, 0)))); - return (get_m(mk_var(4, p1, p2, 0, 0))); - } - - XTerm trim_l(int p1, int p2) - { - if (p1 == p2) return (pzero()); - if (p1 < p2) return (neg_poly(get_m(mk_var(5, p2, p1, 0, 0)))); - return (get_m(mk_var(5, p1, p2, 0, 0))); - } - - XTerm trim_s(int p1, int p2) - { - if (p1 == p2) return (pzero()); - if (p1 < p2) return (neg_poly(get_m(mk_var(6, p2, p1, 0, 0)))); - return (get_m(mk_var(6, p1, p2, 0, 0))); - } - - XTerm trim_c(int p1, int p2) - { - if (p1 == p2) return (get_n(1L)); - if (p1 < p2) return (neg_poly(get_m(mk_var(7, p2, p1, 0, 0)))); - return (get_m(mk_var(7, p1, p2, 0, 0))); - } - - -} diff --git a/src/main/java/gprover/AuxPt.java b/src/main/java/gprover/AuxPt.java index 8db79d8f..14bdc5e3 100644 --- a/src/main/java/gprover/AuxPt.java +++ b/src/main/java/gprover/AuxPt.java @@ -3,30 +3,49 @@ import java.util.Vector; /** - * Created by IntelliJ IDEA. - * User: ye - * Date: Oct 4, 2006 - * Time: 7:13:10 PM - * To change this template use File | Settings | File Templates. + * The AuxPt class represents an auxiliary point in a geometric construction. + * It includes methods for managing a list of ProPoint objects and retrieving + * information about the auxiliary point. */ public class AuxPt { - String name; + /** The type of the auxiliary point. */ int type; - Vector vptlist = new Vector(); - String str; + /** The list of ProPoint objects associated with the auxiliary point. */ + Vector vptlist = new Vector<>(); + + /** + * Constructs an AuxPt object with the specified type. + * + * @param t the type of the auxiliary point + */ public AuxPt(int t) { type = t; } + /** + * Gets the constructed point as a string. + * + * @return the constructed point as a string + */ public String getConstructedPoint() { return vptlist.get(0).toString(); } + /** + * Gets the type of the auxiliary point. + * + * @return the type of the auxiliary point + */ public int getAux() { return type; } + /** + * Adds a ProPoint to the list if it is not already present. + * + * @param pt the ProPoint to add + */ public void addAPt(ProPoint pt) { for (int i = 0; i < vptlist.size(); i++) if (pt == vptlist.get(i)) @@ -34,18 +53,34 @@ public void addAPt(ProPoint pt) { vptlist.add(pt); } + /** + * Gets the number of ProPoints in the list. + * + * @return the number of ProPoints in the list + */ public int getPtsNo() { return vptlist.size(); } + /** + * Gets the ProPoint at the specified index. + * + * @param n the index of the ProPoint to retrieve + * @return the ProPoint at the specified index + */ public ProPoint getPtsbyNo(int n) { - return (ProPoint) vptlist.get(n); + return vptlist.get(n); } + /** + * Returns a string representation of the auxiliary point and its associated ProPoints. + * + * @return a string representation of the auxiliary point and its associated ProPoints + */ public String toString() { String s = ""; for (int i = 0; i < vptlist.size(); i++) { - ProPoint pt = (ProPoint) vptlist.get(i); + ProPoint pt = vptlist.get(i); s += pt.getText(); } return "(A" + type + " ): " + s; diff --git a/src/main/java/gprover/CClass.java b/src/main/java/gprover/CClass.java index 5d6646ba..dd70cd21 100644 --- a/src/main/java/gprover/CClass.java +++ b/src/main/java/gprover/CClass.java @@ -1,24 +1,33 @@ +package gprover; /** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2006-2-15 - * Time: 13:28:06 - * To change this template use File | Settings | File Templates. + * The CClass class represents a base class for geometric objects. + * It includes properties for unique identification, depth, type, and text description. */ -package gprover; - public class CClass { + /** The maximum number of geometric objects. */ final public static int MAX_GEO = 40; - public static long id_count = 0; + /** A static counter for generating unique IDs. */ + public static long id_count = 0; + /** The unique ID of the geometric object. */ long id = id_count++; - long dep = Gib.depth; + /** The depth of the geometric object. */ + long dep = Gib.depth; + /** The type of the geometric object. */ int type; + + /** The text description of the geometric object. */ String text; + /** + * Returns a string representation of the geometric object. + * + * @return the text description of the geometric object + */ + @Override public String toString() { return text; } diff --git a/src/main/java/gprover/CNdg.java b/src/main/java/gprover/CNdg.java index 1a93f170..3e9a92f7 100644 --- a/src/main/java/gprover/CNdg.java +++ b/src/main/java/gprover/CNdg.java @@ -1,30 +1,48 @@ package gprover; /** - * Created by IntelliJ IDEA. - * User: ye - * Date: 2008-1-20 - * Time: 19:02:14 - * To change this template use File | Settings | File Templates. + * The CNdg class represents a geometric non-degenerate condition. + * It includes properties for dependent constructions, equivalent conditions, + * existence flag, type, number, points, and a string description. */ public class CNdg { + /** The maximum number of geometric objects. */ final public static int MAX_GEO = 16; - public Object dep; // dependent construction - public Object equ; // equivalent conditions + /** The dependent construction. */ + public Object dep; + + /** The equivalent conditions. */ + public Object equ; + + /** The existence flag. */ public boolean exists = false; + /** The type of the geometric condition. */ public int type; + + /** The number of points. */ public int no = -1; + + /** The array of points. */ public int[] p = new int[MAX_GEO]; + /** The string description of the geometric condition. */ String sd; + /** + * Constructs a CNdg object with default values. + */ public CNdg() { dep = equ = sd = null; type = 0; } + /** + * Gets the maximum integer value from the points array. + * + * @return the maximum integer value from the points array + */ public int getMaxInt() { int n = 0; for (int i = 0; i <= no; i++) { @@ -34,6 +52,11 @@ public int getMaxInt() { return n; } + /** + * Constructs a CNdg object by copying another CNdg object. + * + * @param c1 the CNdg object to copy + */ public CNdg(CNdg c1) { dep = c1.dep; equ = c1.equ; @@ -45,17 +68,35 @@ public CNdg(CNdg c1) { p[i] = c1.p[i]; } + /** + * Returns a string representation of the geometric condition. + * + * @return the string description of the geometric condition + */ public String toString() { return sd; } - public boolean contain2(int a, int b) { // 01, or 23 + /** + * Checks if the condition contains the specified points. + * + * @param a the first point + * @param b the second point + * @return true if the condition contains the specified points, false otherwise + */ + public boolean contain2(int a, int b) { if (a == 0 && b == 0) return true; return p[0] == a && p[1] == b || p[0] == b && p[1] == a || p[2] == a && p[3] == b || p[2] == b && p[3] == a; } + /** + * Checks if the condition contains the specified point. + * + * @param pt the point to check + * @return true if the condition contains the specified point, false otherwise + */ public boolean contain(int pt) { if (pt == 0) return true; @@ -67,6 +108,11 @@ public boolean contain(int pt) { return false; } + /** + * Checks if there are redundant points in the condition. + * + * @return true if there are redundant points, false otherwise + */ public boolean redundentPt() { for (int i = 0; i <= no; i++) { for (int j = i + 1; j <= no; j++) @@ -76,10 +122,20 @@ public boolean redundentPt() { return false; } + /** + * Adds a point to the condition. + * + * @param pt the point to add + */ public void addAPt(int pt) { p[++no] = pt; } + /** + * Adds all points from the specified array to the condition. + * + * @param p1 the array of points to add + */ public void addAllPt(int[] p1) { for (int i = 0; i < p.length; i++) p[i] = 0; @@ -95,6 +151,11 @@ public void addAllPt(int[] p1) { no = i; } + /** + * Gets the redundant point in the condition. + * + * @return the redundant point, or 0 if there are no redundant points + */ public int getRedundentPt() { for (int i = 0; i <= no; i++) { for (int j = i + 1; j <= no; j++) @@ -103,5 +164,4 @@ public int getRedundentPt() { } return 0; } - -} +} \ No newline at end of file diff --git a/src/main/java/gprover/CST.java b/src/main/java/gprover/CST.java index 61ce1f70..c9728ca7 100644 --- a/src/main/java/gprover/CST.java +++ b/src/main/java/gprover/CST.java @@ -2,164 +2,75 @@ import wprover.GExpert; +/** + * The CST class contains constants and utility methods for managing + * geometric constructions and their validations. + * + *

This class provides arrays for construction types, intersection types, + * and conclusion types, along with methods to retrieve indices, generate + * descriptive strings for geometric constructions, and perform various + * validations and conversions. + * + *

The static method {@link #charCons(int, Cons, Cons, Object[])} constructs a new + * construction by combining two given constructions, performing necessary + * validations and point adjustments based on geometric rules. + */ public class CST { - final public static String[] cst = - { - "POINT", - "LINE", - "ON_LINE", - "ON_PLINE", - "ON_TLINE", - "ON_BLINE", - "ON_ALINE", - - "FOOT", - "CIRCLE", - "ON_CIRCLE", - "CIRCUMCENTER", - "ON_RCIRCLE", - - "MIDPOINT", - - "EQDISTANCE", //"ON_RCIRCLE", - "EQANGLE", - - "TRATIO", - "PRATIO", - "NRATIO", - "LRATIO", - - "INVERSION", - "REFLECTION", - "SYM", - - "TRIANGLE", - "QUADRANGLE", - "PENTAGON", - "POLYGON", - "ISO_TRIANGLE", - "R_TRIANGLE", - "EQ_TRIANGLE", - "TRAPEZOID", - "R_TRAPEZOID", - "PARALLELOGRAM", - "LOZENGE", - "RECTANGLE", - "SQUARE", - - "INCENTER", - "ORTHOCENTER", - "CENTROID", - - "CONSTANT", - - "PSQUARE", - "NSQUARE", - "S_ANGLE", - "ANGLE_BISECTOR", - "LC_TANGENT", - "RATIO", - "CCTANGENT", - "ON_SCIRCLE", - "ON_BALINE", - "ON_DCIRCLE", - "EQANGLE3P" - }; - + // Array of geometric construction types + final public static String[] cst = { + "POINT", "LINE", "ON_LINE", "ON_PLINE", "ON_TLINE", "ON_BLINE", "ON_ALINE", + "FOOT", "CIRCLE", "ON_CIRCLE", "CIRCUMCENTER", "ON_RCIRCLE", + "MIDPOINT", "EQDISTANCE", "EQANGLE", "TRATIO", "PRATIO", "NRATIO", "LRATIO", + "INVERSION", "REFLECTION", "SYM", "TRIANGLE", "QUADRANGLE", "PENTAGON", + "POLYGON", "ISO_TRIANGLE", "R_TRIANGLE", "EQ_TRIANGLE", "TRAPEZOID", + "R_TRAPEZOID", "PARALLELOGRAM", "LOZENGE", "RECTANGLE", "SQUARE", + "INCENTER", "ORTHOCENTER", "CENTROID", "CONSTANT", "PSQUARE", "NSQUARE", + "S_ANGLE", "ANGLE_BISECTOR", "LC_TANGENT", "RATIO", "CCTANGENT", + "ON_SCIRCLE", "ON_BALINE", "ON_DCIRCLE", "EQANGLE3P" + }; + // Array of intersection types final public static String[] inters = { - "INTERSECTION_LL", - "INTERSECTION_LP", - "INTERSECTION_LC", - "INTERSECTION_LB", - "INTERSECTION_LT", - "INTERSECTION_LR", - "INTERSECTION_LS", - "INTERSECTION_PP", - "INTERSECTION_PC", - "INTERSECTION_PT", - "INTERSECTION_PB", - "INTERSECTION_TC", - "INTERSECTION_TT", - "INTERSECTION_TB", - "INTERSECTION_BB", - "INTERSECTION_BC", - "INTERSECTION_CC", - "INTERSECTION_CR", - "INTERSECTION_RR", - "INTERSECTION_SS", - "INTERSECTION_AA", - - "INTERSECTION_LA", - "INTERSECTION_PA", - "INTERSECTION_PR", - "INTERSECTION_TA", - "INTERSECTION_TR", - "INTERSECTION_BA", - "INTERSECTION_BR", + "INTERSECTION_LL", "INTERSECTION_LP", "INTERSECTION_LC", "INTERSECTION_LB", + "INTERSECTION_LT", "INTERSECTION_LR", "INTERSECTION_LS", "INTERSECTION_PP", + "INTERSECTION_PC", "INTERSECTION_PT", "INTERSECTION_PB", "INTERSECTION_TC", + "INTERSECTION_TT", "INTERSECTION_TB", "INTERSECTION_BB", "INTERSECTION_BC", + "INTERSECTION_CC", "INTERSECTION_CR", "INTERSECTION_RR", "INTERSECTION_SS", + "INTERSECTION_AA", "INTERSECTION_LA", "INTERSECTION_PA", "INTERSECTION_PR", + "INTERSECTION_TA", "INTERSECTION_TR", "INTERSECTION_BA", "INTERSECTION_BR", "PT_EQUAL" }; + // Array of conclusion types final public static String[] conclusion = { - "COLLINEAR", - "PARALLEL", - "PERPENDICULAR", - "MIDPOINT", - "CYCLIC", - "EQDISTANCE", - "EQANGLE", - "PERP_BISECT", - "TANGENT", - "HARMONIC_PAIR", - "EQ_TRIANGLE", - "SIM_TRIANGLE", - "CON_TRIANGLE", - "EQ_PRODUCT", - "ORTHOCENTER", - "INCENTER", - "RATIO", - "S_ANGLE", - "N_ANGLES", - "N_SEGMENTS" - + "COLLINEAR", "PARALLEL", "PERPENDICULAR", "MIDPOINT", "CYCLIC", + "EQDISTANCE", "EQANGLE", "PERP_BISECT", "TANGENT", "HARMONIC_PAIR", + "EQ_TRIANGLE", "SIM_TRIANGLE", "CON_TRIANGLE", "EQ_PRODUCT", "ORTHOCENTER", + "INCENTER", "RATIO", "S_ANGLE", "N_ANGLES", "N_SEGMENTS" }; - public static String[] s_conc_detail = - { - "Collinear", - "Parallel", - "Perpendicular", - "Midpoint", - "Cyclic", - "Equal Distance", - "Equal Angle", - "Bisect", - "Tangent", - "Harmonic Pair", - "Equilateral Triangle", - "Similiar Triangle", - "Congruent Triangle", - "Equal product", - "Orthocenter", - "Incenter", - "Ratio", - "Special angle", - "Angles Equation", - "Segment Equation" - }; - - private CST() { - } + // Array of detailed conclusion descriptions + public static String[] s_conc_detail = { + "Collinear", "Parallel", "Perpendicular", "Midpoint", "Cyclic", + "Equal Distance", "Equal Angle", "Bisect", "Tangent", "Harmonic Pair", + "Equilateral Triangle", "Similiar Triangle", "Congruent Triangle", + "Equal product", "Orthocenter", "Incenter", "Ratio", "Special angle", + "Angles Equation", "Segment Equation" + }; - public static String get_detail_info(int n, Object[] p) { - return null; - } + // Private constructor to prevent instantiation + private CST() {} + // Constants for index ranges final private static int CONC_INDEX = 70; final private static int INTER_INDEX = 100; - + /** + * Gets the index of a conclusion type. + * @param s The conclusion type as a string. + * @return The index of the conclusion type. + */ public static int getClu(String s) { s = s.toUpperCase(); for (int i = 0; i < conclusion.length; i++) @@ -173,6 +84,11 @@ public static int getClu(String s) { return 0; } + /** + * Gets the index of a detailed conclusion description. + * @param s The detailed conclusion description as a string. + * @return The index of the detailed conclusion description. + */ public static int getClu_D(String s) { for (int i = 0; i < s_conc_detail.length; i++) if (s.equalsIgnoreCase(s_conc_detail[i])) @@ -180,8 +96,12 @@ public static int getClu_D(String s) { return 0; } + /** + * Gets the conclusion or intersection type as a string. + * @param n The index of the type. + * @return The type as a string. + */ public static String getClus(int n) { - int i = n - CONC_INDEX; if (i >= 0 && i < conclusion.length) return conclusion[i]; @@ -196,11 +116,14 @@ public static String getClus(int n) { return inters[i]; } + /** + * Gets the index of a predicate type. + * @param s The predicate type as a string. + * @return The index of the predicate type. + */ public static int get_pred(String s) { - int n = 0; - if (n == 0) for (int i = 0; i < cst.length; i++) if (s.equals(cst[i])) { @@ -215,13 +138,17 @@ public static int get_pred(String s) { break; } - if (n == 0) n = getClu(s); return n; } + /** + * Gets the predicate type as a string. + * @param n The index of the type. + * @return The type as a string. + */ public static String get_preds(int n) { if (n >= 1 && n <= cst.length) return cst[n - 1]; @@ -233,10 +160,23 @@ public static String get_preds(int n) { return getClus(n); } + /** + * Gets a descriptive string for a given type and parameters. + * @param pss The parameters. + * @param t The type. + * @return The descriptive string. + */ public static String getDString(Object[] pss, int t) { return getDString(pss, t, true); } + /** + * Gets a descriptive string for a given type and parameters. + * @param pss The parameters. + * @param t The type. + * @param d Whether to include detailed descriptions. + * @return The descriptive string. + */ public static String getDString(Object[] pss, int t, boolean d) { switch (t) { @@ -615,7 +555,14 @@ public static String getDString(Object[] pss, int t, boolean d) { } } - + /** + * Generates a concatenated String of the non-null elements in the specified subarray. + * + * @param m the starting index (inclusive) + * @param n the ending index (inclusive) + * @param ps the array of Objects + * @return a String containing the concatenation of each non-null element's String representation + */ public static String vprint(int m, int n, Object[] ps) { String s = ""; for (int i = m; i <= n; i++) @@ -624,6 +571,19 @@ public static String vprint(int m, int n, Object[] ps) { return s; } + /** + * Constructs a new construction by combining two given construction objects. + * + *

This method performs the necessary validations and adjustments of point indices + * according to geometric rules. If the primary construction (c1) is null, the method + * uses the secondary construction (c2) as the basis for constructing the new Cons object. + * + * @param pt the reference point index used for adjustments + * @param c1 the primary Cons object; may be null + * @param c2 the secondary Cons object to use if c1 is null + * @param pss the array of point information associated with the construction + * @return the resulting Cons object after combining and validating the constructions + */ public static Cons charCons(int pt, Cons c1, Cons c2, Object[] pss) { if (c1 == null) { c1 = c2; @@ -850,6 +810,15 @@ public static Cons charCons(int pt, Cons c1, Cons c2, Object[] pss) { } + /** + * Adjusts the specification fields of the given construction based on the reference point. + * + *

This method analyzes and modifies the type and point indices of the provided + * construction (c) according to geometric rules and validations. + * + * @param pt the reference point index used for adjustments + * @param c the construction object to be adjusted; may be {@code null} + */ public static void spec(int pt, Cons c) { if (c == null) return; @@ -922,6 +891,15 @@ public static void spec(int pt, Cons c) { } } + /** + * Adds additional point specification data to the given construction. + * + *

This method processes the provided array of point specification data and updates the + * corresponding fields in the construction object accordingly.

+ * + * @param c the construction object to update + * @param pss the array of additional point specification data + */ public static void addPss(Cons c, Object[] pss) { int[] p = c.ps; int i = 0; @@ -936,6 +914,17 @@ public static void addPss(Cons c, Object[] pss) { c.no = i - 1; } + /** + * Revalidates the provided array of point indices based on the reference point and count. + *

+ * This method applies revalidation rules to adjust the point indices in the array + * so that they are consistent with the given reference point. + *

+ * + * @param pt the reference point used for revalidation + * @param p the array of point indices to validate + * @param n the number of valid entries in the point indices array + */ public static void reval(int pt, int[] p, int n) { int n1 = n / 2; boolean c = false; @@ -964,6 +953,14 @@ public static void reval(int pt, int[] p, int n) { reval(pt, p, n1); } + /** + * Adjusts the type code for a line-to-foot construction. + * Applies foot-specific rules and validations on the provided type and point array. + * + * @param t the original type code + * @param p the array of point indices associated with the construction + * @return the adjusted type code after applying the foot-specific rules + */ public static int ge_lt_foot(int t, int[] p) { if (p[1] == p[4] && p[2] == p[5] || p[1] == p[5] && p[2] == p[4]) { p[4] = p[5] = 0; @@ -976,6 +973,18 @@ public static int ge_lt_foot(int t, int[] p) { return t; } + /** + * Validates and adjusts the type code for a construction based on the reference point and its associated point indices. + * + *

This method checks the provided point index array and the initial type code, applying specific geometric rules + * to ensure the correctness of the construction. It returns an adjusted type code reflecting any validations applied, + * or 0 if the validation fails. + * + * @param pt the reference point index used during validation + * @param t1 the initial type code of the construction + * @param p1 an array of point indices associated with the construction (may be modified during validation) + * @return the validated (and possibly adjusted) type code, or 0 if validation fails + */ public static int validate_all(int pt, int t1, int[] p1) { if (t1 == Gib.C_EQDISTANCE || t1 == Gib.CO_CONG) { @@ -991,6 +1000,17 @@ else if (t1 == Gib.CO_PERP || t1 == Gib.C_O_T) return t1; } + /** + * Validates and adjusts the construction type for an angle-related scenario. + * + *

This method checks and modifies the provided point indices array for angle-related constructions, + * applying specific geometric validations. It returns an adjusted type code if the validation is successful, + * or 0 if validation fails.

+ * + * @param pt the reference point index used for validation + * @param ps an array of point indices related to the construction + * @return the validated (and possibly adjusted) type code, or 0 if validation fails + */ public static int validate_ea(int pt, int[] ps) { int t1 = Gib.C_O_A; int i = 0; @@ -1034,6 +1054,17 @@ public static int validate_ea(int pt, int[] ps) { return t1; } + /** + * Validates and adjusts the construction type for a collinearity scenario. + * + *

This method examines the provided array of point indices and determines if they satisfy + * the conditions for defining a collinear construction. It returns the validated type code + * if successful, or 0 if validation fails.

+ * + * @param pt the reference point index used for validation + * @param ps the array of point indices to validate + * @return the validated type code for the collinear construction, or 0 if validation fails + */ public static int validate_coll(int pt, int[] ps) { if (ps[0] < ps[1]) exchange(0, 1, ps); @@ -1044,6 +1075,17 @@ public static int validate_coll(int pt, int[] ps) { return Gib.C_O_L; } + /** + * Validates and adjusts the construction type for a parallel scenario. + * + *

This method examines the array of point indices and validates them according to + * the rules for parallel constructions. It returns the validated type code if the + * validation is successful, or 0 if validation fails. + * + * @param pt the reference point index used during validation + * @param ps the array of point indices associated with the parallel construction + * @return the validated construction type code for a parallel configuration, or 0 if invalid + */ public static int validate_p(int pt, int[] ps) { if (ps[0] < ps[1]) exchange(0, 1, ps); @@ -1056,6 +1098,19 @@ public static int validate_p(int pt, int[] ps) { return Gib.C_O_P; } + /** + * Validates and adjusts the construction type for a perpendicular construction. + * + *

This method examines the provided array of point indices and applies + * perpendicular-specific validation rules. It may reorder or adjust the point indices + * to ensure consistency with the geometric definition of a perpendicular construction. + * If the validation is successful, the method returns the adjusted construction type; + * otherwise, it returns 0.

+ * + * @param pt the reference point index used during validation + * @param ps the array of point indices associated with the construction + * @return the validated (and possibly adjusted) construction type code, or 0 if validation fails + */ public static int validate_t(int pt, int[] ps) { if (ps[0] < ps[1]) exchange(0, 1, ps); @@ -1068,6 +1123,18 @@ public static int validate_t(int pt, int[] ps) { return Gib.C_O_T; } + /** + * Validates and adjusts the construction type for a congruence of distances construction. + * + *

This method examines the provided array of point indices associated + * with a congruence construction (e.g., verifying segment congruence) and applies + * specific validations. It returns an adjusted type code reflecting the outcome of the + * validation, or 0 if validation fails.

+ * + * @param pt the reference point index used for validation + * @param ps the array of point indices associated with the congruence construction + * @return the validated construction type code, or 0 if validation fails + */ public static int validate_cg(int pt, int[] ps) { if (ps[0] < ps[1]) exchange(0, 1, ps); @@ -1086,12 +1153,28 @@ public static int validate_cg(int pt, int[] ps) { return Gib.C_O_R; } + + /** + * Exchanges the elements at indices i and j in the given array. + * + * @param i the index of the first element to exchange + * @param j the index of the second element to exchange + * @param ps the array in which the elements will be swapped + */ public static void exchange(int i, int j, int[] ps) { int t = ps[i]; ps[i] = ps[j]; ps[j] = t; } + + /** + * Creates a copy of the given integer array. + * This method returns a new array containing the same elements as the input array. + * + * @param p the array to copy + * @return a new array that is a copy of p + */ public static int[] pcopy(int[] p) { if (p == null) return null; diff --git a/src/main/java/gprover/CSegs.java b/src/main/java/gprover/CSegs.java index 98681824..d241525f 100644 --- a/src/main/java/gprover/CSegs.java +++ b/src/main/java/gprover/CSegs.java @@ -1,22 +1,30 @@ package gprover; -/** - * Created by IntelliJ IDEA. - * User: ye - * Date: Oct 23, 2006 - * Time: 5:17:01 PM - * To change this template use File | Settings | File Templates. - */ -public class CSegs extends CClass { - public int no; - public int[] p1; - public int[] p2; - CSegs nx; + /** + * The CSegs class represents a collection of geometric segments in a proof. + * It includes properties for the number of segments, arrays of points defining the segments, + * and a reference to the next segment in the list. + */ + public class CSegs extends CClass { + /** The number of segments. */ + public int no; - public CSegs() { - type = no = 0; - p1 = new int[MAX_GEO * 2]; - p2 = new int[MAX_GEO * 2]; - nx = null; - } -} + /** The array of starting points of the segments. */ + public int[] p1; + + /** The array of ending points of the segments. */ + public int[] p2; + + /** The next segment in the list. */ + CSegs nx; + + /** + * Constructs a CSegs object with default values. + */ + public CSegs() { + type = no = 0; + p1 = new int[MAX_GEO * 2]; + p2 = new int[MAX_GEO * 2]; + nx = null; + } + } diff --git a/src/main/java/gprover/Cm.java b/src/main/java/gprover/Cm.java index fcab1a42..975b71dd 100644 --- a/src/main/java/gprover/Cm.java +++ b/src/main/java/gprover/Cm.java @@ -1,110 +1,115 @@ +package gprover; /** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2006-2-16 - * Time: 13:37:35 - * To change this template use File | Settings | File Templates. + * The Cm class contains various constants and utility methods used in geometric proofs. + * It includes string constants for geometric symbols, predicates, and messages, + * as well as a debug flag and a print method for debugging purposes. */ -package gprover; - -import wprover.GExpert; final public class Cm { - static public boolean isWindows() { - return System.getProperty("os.name").startsWith("Windows"); - } - + /** Hypothesis string constant. */ final public static String s2070 = "(hyp)"; + /** The machine proof string constant. */ final public static String s2072 = "The Machine Proof"; + /** Perpendicular sign constant. */ final public static String PERPENDICULAR_SIGN = " ⊥ "; + /** Parallel sign constant. */ final public static String PARALLEL_SIGN = " ∥ "; + /** Triangle sign constant. */ final public static String TRIANGLE_SIGN = "∆"; + /** Angle sign constant. */ final public static String ANGLE_SIGN = "∠"; + /** Equal sign constant. */ final public static String EQUAL_SIGN = " = "; + /** Similar sign constant. */ final public static String SIMILAR_SIGN = " ~ "; + /** Intersect sign constant. */ final public static String INTERSECT_SIGN = " ∩ "; + /** Lines string constant. */ final public static String s2707 = "lines"; + /** Circles in the database string constant. */ final public static String s2713 = "circles in the database."; + /** Similar triangles string constant. */ final public static String s2720 = "similar triangles"; + /** Congruent triangles string constant. */ final public static String s2722 = "congruent triangles"; + /** Because string constant. */ final public static String s2727 = " because "; + /** And string constant. */ final public static String s2728 = " and "; + /** Collinear predicate constant. */ final public static String PC_COLL = "COLLINEAR"; + /** Parallel predicate constant. */ final public static String PC_PARA = "PARALLEL"; + /** Perpendicular predicate constant. */ final public static String PC_PERP = "PERPENDICULAR"; + /** Equal distance predicate constant. */ final public static String PC_CONG = "EQDISTANCE"; + /** Equal angle predicate constant. */ final public static String PC_ACONG = "EQANGLE"; + /** Cocircle predicate constant. */ final public static String PC_CYCLIC = "COCIRCLE"; + /** Similar triangle predicate constant. */ final public static String PC_STRI = "SIM_TRIANGLE"; + /** Congruent triangle predicate constant. */ final public static String PC_CTRI = "CON_TRIANGLE"; + /** Midpoint predicate constant. */ final public static String PC_MIDP = "MIDPOINT"; - // predicate. - + /** Point predicate constant. */ final public static String P_POINT = "POINT"; + /** WPT string constant. */ final public static String DR_WPT = "WPT"; - //////////////// + /** Only full-angles allowed message constant. */ final public static String s2810 = "\r\n\r\nOnly full-angles are allowd in this case"; + /** Conclusion cannot be represented with full-angles message constant. */ final public static String s2811 = "\r\nConclusion cannot be represented with full-angles.\r\n"; + /** Cannot solve problem with full-angles message constant. */ final public static String s2812 = "\r\nCannot solve this problem with full-angles.\r\n"; - /// ----------------------------------------- + /** Index string constant. */ final public static String s1993 = "Index"; - //-------------area-------------------------------------- + /** The statement is true message constant. */ final public static String s2300 = "\r\n\r\nThe statement is true.\r\n\r\n"; - final public static String s2301 = "\r\n\\rnThe statement is false.\r\n\r\n"; - final public static String s2302 = "Conclusion not fund:"; - final public static String s2303 = "A new point"; - final public static String s2304 = "is introduced by construction\r\n"; - final public static String s2305 = "The new conclusion is: "; - final public static String s2306 = "EQ_RATIO"; - final public static String s2307 = "Construction for point"; - final public static String s2308 = "is not allowd in area method.\r\n"; - - final public static String s2310 = "In the area method, the lines and circles must meet in one point"; - final public static String s2311 = "construction INCENTER is not allowed in the prover.\r\n"; - final public static String s2312 = "Please use construction:\r\n construct a vertex from the incenter and two other vertex.\r\n"; - final public static String s2313 = "In the area method, PTRIANGLE can be used only when the conclusion is about vectors."; - final public static String s2314 = "\r\n Proving failed. Statement is not proved."; + /** No proof exists message constant. */ final public static String s2220 = "\r\nThere exists no proof.\r\n"; + /** Conclusion message constant. */ final public static String s2221 = "The conclusion is: "; + /** Equivalent message constant. */ final public static String s2222 = "This is equivalent to: "; + /** Eliminating common factors message constant. */ final public static String s2223 = "Eliminating the common factors: "; + /** Geometric quantities used in proof message constant. */ final public static String s2225 = "\r\nThe geometric quantities used in the proof.\r\n"; + /** Eliminate variables message constant. */ final public static String s2226 = "Eliminate variables"; - - final public static String sfe_exp_error = "The conclusion can not be translated to full-angle expression."; - - final public static String getFError(int n) { - if (n == 1) - return sfe_exp_error; - return GExpert.getLanguage("Failed to prove this theorem with Full Angle Method.") + "\n"; - } - + /** Debug flag. */ final public static boolean DEBUG = false; - final public static void print(String s) { + /** + * Prints the specified string if the debug flag is set. + * + * @param s the string to print + */ + public static void print(String s) { if (DEBUG) System.out.println(s); } - - -} +} \ No newline at end of file diff --git a/src/main/java/gprover/Cond.java b/src/main/java/gprover/Cond.java index 39de4118..a637676b 100644 --- a/src/main/java/gprover/Cond.java +++ b/src/main/java/gprover/Cond.java @@ -11,59 +11,125 @@ import java.util.Vector; +/** + * Represents a condition in the proof structure. + * It contains details like rule, predicate, step number, description, + * proof structure and related attributes. + */ public class Cond { + /** Maximum number of geometric elements. */ final public static int MAX_GEO = 16; - protected int rule = 0; // the rule being used in this step (theorems or lemmas) + /** The rule being used in this step (theorems or lemmas). */ + protected int rule = 0; + /** Predicate identifier. */ public int pred; - public int no; // the number of the current step + /** The number of the current step. */ + public int no; + /** Array of geometric elements. */ public int[] p; + /** Structure holding different geometric entities. */ public UStruct u; - public Cond nx, cd; // nx: next - public String sd = null; // step description - public Vector vlist = null; // the list of the direct steps in this node + /** Next condition. */ + public Cond nx; + /** Additional condition. */ + public Cond cd; + /** Step description. */ + public String sd = null; + /** List of the direct steps in this node. */ + public Vector vlist = null; + /** Depth of the condition, initialized from Gib.depth. */ public long dep = Gib.depth; + /** + * Retrieves the step description. + * + * @return the step description text + */ public String getText() { return sd; } + /** + * Sets the step description. + * + * @param s the new description text + */ public void setText(String s) { sd = s; } + /** + * Retrieves the current step number. + * + * @return the step number + */ public int getNo() { return no; } + /** + * Retrieves the current rule. + * + * @return the rule applied + */ public int getRule() { return rule; } + /** + * Sets the rule from the related facts in the internal structure. + */ public void getRuleFromeFacts() { rule = u.get_lemma(); } + /** + * Sets the current rule. + * + * @param r the rule to be set + */ public void setRule(int r) { rule = r; } + /** + * Retrieves the condition from the internal structure. + * + * @return the condition pointer (PCO) + */ public Cond getPCO() { return u.get_co(); } + /** + * Returns the step description as the string representation. + * + * @return the step description + */ public String toString() { return sd; } + /** + * Prepends the step description with a language specific "To Prove:" message. + */ public void setCondToBeProveHead() { sd = GExpert.getLanguage("To Prove:") + " " + sd; } + /** + * Constructs a condition with a given predicate. + * + * @param t the predicate + */ public Cond(int t) { this(); pred = t; } + /** + * Default condition constructor that initializes required fields. + */ public Cond() { pred = no = 0; p = new int[MAX_GEO]; @@ -71,17 +137,26 @@ public Cond() { nx = null; } + /** + * Constructs a condition optionally initializing the geometric array. + * + * @param r if true, initializes the geometric array; otherwise leaves it null + */ public Cond(boolean r) { pred = no = 0; if (r) p = new int[MAX_GEO]; else p = null; - u = new UStruct(); nx = null; } + /** + * Copy constructor for creating a duplicate of a given condition. + * + * @param co the condition to copy + */ public Cond(Cond co) { pred = co.pred; no = co.no; @@ -94,6 +169,11 @@ public Cond(Cond co) { sd = null; } + /** + * Adds a condition as a direct child. + * + * @param co the condition to add + */ public void addcond(Cond co) { rule = 0; if (co == null) return; @@ -102,6 +182,12 @@ public void addcond(Cond co) { vlist.add(co); } + /** + * Adds a condition with a specified rule. + * + * @param r the rule value to set + * @param co the condition to add + */ public void addcond(int r, Cond co) { rule = r; if (co == null) return; @@ -110,19 +196,36 @@ public void addcond(int r, Cond co) { vlist.add(co); } + /** + * Adds all conditions from a given vector. + * + * @param v the vector containing conditions to add + */ public void add_allco(Vector v) { if (v == null) return; if (vlist == null) vlist = new Vector(); vlist.addAll(v); - } + /** + * Adds two conditions as direct children with a specified rule. + * + * @param lm the rule value to set + * @param co1 the first condition to add + * @param co2 the second condition to add + */ public void addcond(int lm, Cond co1, Cond co2) { rule = lm; addcond(co1, co2); } + /** + * Adds two conditions as direct children. + * + * @param co1 the first condition to add + * @param co2 the second condition to add + */ public void addcond(Cond co1, Cond co2) { rule = 0; if (vlist == null) @@ -131,23 +234,41 @@ public void addcond(Cond co1, Cond co2) { if (co2 != null) vlist.add(co2); } + /** + * Retrieves the attributes associated with the condition. + * + * @return a CClass representing the condition's attributes + */ public CClass get_attr() { return u.get_attr(); } + /** + * Determines the type of the condition's conclusion. + * + * @return 1 if the internal structure is null; 2 if the condition obtained from the structure is null; otherwise 0 + */ public int get_conc_type() { if (u.isnull()) // Hype return 1; - else if (u.get_co() == null) // Obviousely + else if (u.get_co() == null) // Obviously return 2; else return 0; } + /** + * Dummy method for rule processing. Implementation pending. + */ public void gRule() { } } +/** + * Represents a structure holding various geometric elements. + * This class contains fields for different types of geometric data and provides + * methods for comparing, copying, and retrieving attributes from the stored elements. + */ class UStruct { MidPt md; LLine ln; @@ -163,6 +284,13 @@ class UStruct { Polygon pg; LList ns; + /** + * Compares this UStruct to another UStruct for equality. + * Equality is defined as all corresponding fields referring to the same object. + * + * @param u1 the UStruct to compare with + * @return true if all fields are equal; false otherwise + */ public boolean equal(UStruct u1) { return md == u1.md @@ -180,6 +308,11 @@ public boolean equal(UStruct u1) { && ns == u1.ns; } + /** + * Checks if all the fields in this UStruct are null. + * + * @return true if every field is null; false otherwise + */ public boolean isnull() { return md == null @@ -197,6 +330,9 @@ public boolean isnull() { && ns == null; } + /** + * Sets all fields in this UStruct to null. + */ public void setnull() { md = null; ln = null; @@ -213,6 +349,11 @@ public void setnull() { ns = null; } + /** + * Copies all field values from the specified UStruct into this UStruct. + * + * @param us the UStruct to copy from + */ public void cpv(UStruct us) { md = us.md; pn = us.pn; @@ -229,6 +370,9 @@ public void cpv(UStruct us) { ns = us.ns; } + /** + * Constructs an empty UStruct with all fields initialized to null. + */ public UStruct() { md = null; ln = null; @@ -245,6 +389,11 @@ public UStruct() { ns = null; } + /** + * Retrieves the type of the first non-null geometric element. + * + * @return the type if found; -1 if no element is present + */ public int get_type() { if (md != null) return md.type; if (ln != null) return ln.type; @@ -262,6 +411,11 @@ public int get_type() { return -1; } + /** + * Retrieves the lemma value from the first non-null geometric element. + * + * @return the lemma if found; -1 if no element is present + */ public int get_lemma() { if (md != null) return md.lemma; if (ln != null) return ln.lemma; @@ -278,6 +432,11 @@ public int get_lemma() { return -1; } + /** + * Retrieves the attributes from the first non-null geometric element. + * + * @return the attributes as a CClass; null if no element is found + */ public CClass get_attr() { if (md != null) return md; if (ln != null) return ln; @@ -291,10 +450,14 @@ public CClass get_attr() { if (at != null) return at; if (pg != null) return pg; if (atn != null) return atn; - return null; } + /** + * Retrieves the condition (Cond) associated with the first non-null geometric element. + * + * @return the associated Cond; null if no element is found + */ Cond get_co() { if (md != null) return md.co; if (ln != null) return ln.co; @@ -308,10 +471,14 @@ Cond get_co() { if (at != null) return at.co; if (pg != null) return pg.co; if (atn != null) return atn.co; - return null; } + /** + * Retrieves the step number from the first non-null geometric element that contains it. + * + * @return the step number if found; -1 otherwise + */ public int get_no() { //if (d != null) return d.no; //if (md != null) return md.no; @@ -320,13 +487,18 @@ public int get_no() { //if (tn != null) return tn.no; if (cr != null) return cr.no; //if (as != null) return as.no; -// if (st != null) return st.no; -// if (cg != null) return cg.no; + //if (st != null) return st.no; + //if (cg != null) return cg.no; //if (ra != null) return ra.no; return -1; } - + /** + * Sets the type of the first non-null geometric element to the specified value. + * + * @param t the new type value + * @return 0 after setting the type + */ public int set_type(int t) { if (md != null) md.type = t; @@ -354,7 +526,5 @@ else if (atn != null) atn.type = t; return 0; } - - } diff --git a/src/main/java/gprover/CongSeg.java b/src/main/java/gprover/CongSeg.java index a10b85b8..ee54837e 100644 --- a/src/main/java/gprover/CongSeg.java +++ b/src/main/java/gprover/CongSeg.java @@ -1,25 +1,41 @@ -/** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2006-2-14 - * Time: 21:35:00 - * To change this template use File | Settings | File Templates. - */ package gprover; +/** + * The CongSeg class represents a congruent segment in a geometric proof. + * It includes properties for lemma, condition, points, types, and the next segment. + */ public class CongSeg extends CClass { + /** The lemma associated with the congruent segment. */ int lemma; + + /** The condition associated with the congruent segment. */ Cond co; + + /** The first point of the segment. */ public int p1; + + /** The second point of the segment. */ public int p2; + + /** The third point of the segment. */ public int p3; + + /** The fourth point of the segment. */ public int p4; - public int t1,t2; + /** The first type of the segment. */ + public int t1; + + /** The second type of the segment. */ + public int t2; + /** The next congruent segment in the list. */ CongSeg nx; + /** + * Constructs a CongSeg object with default values. + */ public CongSeg() { type = lemma = 0; t1 = t2 = 1; diff --git a/src/main/java/gprover/Cons.java b/src/main/java/gprover/Cons.java index c8fdd98d..dd4c5f46 100644 --- a/src/main/java/gprover/Cons.java +++ b/src/main/java/gprover/Cons.java @@ -2,20 +2,41 @@ import wprover.GExpert; +/** + * The Cons class represents a geometric construction in a proof. + * It includes properties for type, points, and descriptions, + * as well as methods for managing and retrieving information about the construction. + */ public class Cons { + /** The maximum length of the points array. */ final public static int MAXLEN = 16; + /** The unique identifier of the construction. */ int id = 0; + + /** The type of the construction. */ public int type = 0; + + /** The number of points in the construction. */ int no = 0; + + /** The flag indicating if the construction is a conclusion. */ boolean conc = false; + /** The array of point identifiers. */ public int[] ps; + + /** The array of point objects. */ public Object[] pss; + /** The string description of the construction. */ private String sd = null; - + /** + * Constructs a Cons object with the specified type. + * + * @param t the type of the construction + */ public Cons(int t) { type = t; ps = new int[MAXLEN]; @@ -24,6 +45,11 @@ public Cons(int t) { conc = false; } + /** + * Constructs a Cons object by copying another Cons object. + * + * @param c the Cons object to copy + */ public Cons(Cons c) { this(c.type); @@ -39,21 +65,41 @@ public Cons(Cons c) { sd = c.sd; } - + /** + * Gets the number of points in the construction. + * + * @return the number of points in the construction + */ int getPts() { for (int i = 0; i < ps.length; i++) if (ps[i] == 0) return i; return ps.length; } + /** + * Sets the unique identifier of the construction. + * + * @param id the unique identifier to set + */ public void setId(int id) { this.id = id; } + /** + * Gets the unique identifier of the construction. + * + * @return the unique identifier of the construction + */ public int getId() { return id; } + /** + * Checks if the construction contains the specified point. + * + * @param pt the point to check + * @return true if the construction contains the specified point, false otherwise + */ public boolean contains(int pt) { for (int i = 0; i < ps.length; i++) if (pt == ps[i]) @@ -61,14 +107,11 @@ public boolean contains(int pt) { return false; } - - public int getPtIndex(int pt) { - for (int i = 0; i < ps.length; i++) - if (pt == ps[i]) - return i; - return -1; - } - + /** + * Gets the last point in the construction. + * + * @return the last point in the construction + */ public int getLastPt() { int pt = 0; for (int i = 0; i < ps.length; i++) @@ -77,6 +120,12 @@ public int getLastPt() { return pt; } + /** + * Constructs a Cons object with the specified type and length. + * + * @param t the type of the construction + * @param len the length of the points array + */ public Cons(int t, int len) { type = t; ps = new int[len + 1]; @@ -84,7 +133,11 @@ public Cons(int t, int len) { no = -1; } - + /** + * Adds a point to the construction. + * + * @param n the point to add + */ public void add_pt(int n) { if (n == 0) return; @@ -92,10 +145,21 @@ public void add_pt(int n) { ps[++no] = n; } + /** + * Adds a point object to the construction. + * + * @param s the point object to add + */ public void add_pt(Object s) { pss[++no] = s; } + /** + * Adds a point to the construction at the specified index. + * + * @param n the point to add + * @param id the index to add the point at + */ public void add_pt(int n, int id) { if (ps.length <= id) { // TODO. Handle this. @@ -105,6 +169,12 @@ public void add_pt(int n, int id) { ps[no = id] = n; } + /** + * Adds a point object to the construction at the specified index. + * + * @param s the point object to add + * @param id the index to add the point object at + */ public void add_pt(Object s, int id) { if (pss.length <= id) { // TODO. Handle this. @@ -114,7 +184,11 @@ public void add_pt(Object s, int id) { pss[no = id] = s; } - + /** + * Returns a string representation of the construction. + * + * @return the string description of the construction + */ public String toString() { if (sd == null) { String s = ""; @@ -137,6 +211,11 @@ public String toString() { return sd; } + /** + * Returns an extended string representation of the construction. + * + * @return the extended string description of the construction + */ public String toStringEx() { if (sd == null) { String s = ""; @@ -156,10 +235,21 @@ public String toStringEx() { return sd; } + /** + * Sets the string description of the construction. + * + * @param s the string description to set + */ public void setText(String s) { sd = s; } + /** + * Gets the print text of the construction. + * + * @param isSelected the flag indicating if the construction is selected + * @return the print text of the construction + */ public String getPrintText(boolean isSelected) { if (sd == null) { String s = ""; @@ -181,41 +271,82 @@ public String getPrintText(boolean isSelected) { return sd; } + /** + * Trims the string to the specified length. + * + * @param st the string to trim + * @param len the length to trim to + * @return the trimmed string + */ public String trim(String st, int len) { if (st.length() > len) return st.substring(0, len) + "..."; return st; } + /** + * Trims the string to the default length. + * + * @param st the string to trim + * @return the trimmed string + */ public String trim(String st) { return trim(st, 32); } + /** + * Revalidates the construction. + */ public void revalidate() { if (this.type == Gib.CO_NANG || this.type == Gib.CO_NSEG) return; sd = null; } - + /** + * Sets the conclusion flag of the construction. + * + * @param r the conclusion flag to set + */ public void set_conc(boolean r) { conc = r; } + /** + * Checks if the construction is a conclusion. + * + * @return true if the construction is a conclusion, false otherwise + */ public boolean is_conc() { return type >= 50 && type < 100 && conc; } + /** + * Gets the point object at the specified index. + * + * @param n the index to get the point object from + * @return the point object at the specified index + */ public Object getPTN(int n) { if (n < 0 || n >= pss.length) return null; return pss[n]; } + /** + * Returns a short string representation of the construction. + * + * @return the short string description of the construction + */ public String toSString() { return CST.getDString(pss, type); } + /** + * Returns a detailed string representation of the construction. + * + * @return the detailed string description of the construction + */ public String toDString() { String s = CST.getDString(pss, type); if (conc) @@ -225,6 +356,11 @@ public String toDString() { return s; } + /** + * Returns a detailed string representation of the construction without trimming. + * + * @return the detailed string description of the construction without trimming + */ public String toDDString() { String s = CST.getDString(pss, type, false); if (conc) @@ -232,6 +368,12 @@ public String toDDString() { return s; } + /** + * Copies the specified Cons object. + * + * @param c the Cons object to copy + * @return the copied Cons object + */ public static Cons copy(Cons c) { Cons c1 = new Cons(c.type, c.no); for (int i = 0; i < c1.no; i++) { @@ -243,8 +385,12 @@ public static Cons copy(Cons c) { return c1; } - - /////////////////////////////////////////////////////////////////// + /** + * Replaces the specified point with another point in the construction. + * + * @param a the point to replace + * @param b the point to replace with + */ public void replace(int a, int b) { for (int i = 0; i <= no; i++) { if (ps[i] == a) @@ -252,6 +398,12 @@ public void replace(int a, int b) { } } + /** + * Checks if the construction is equal to another construction. + * + * @param c the construction to compare + * @return true if the constructions are equal, false otherwise + */ public boolean isEqual(Cons c) { if (c.type != type) return false; @@ -264,6 +416,9 @@ public boolean isEqual(Cons c) { return true; } + /** + * Reorders the points in the construction based on the type. + */ public void reorder() { switch (type) { case Gib.C_O_L: @@ -274,11 +429,9 @@ public void reorder() { case Gib.C_O_P: case Gib.C_O_T: reorder2(); - break; case Gib.C_I_EQ: reorder1(0, 1); - break; case Gib.C_CIRCUM: reorder1(1, 2); @@ -288,6 +441,12 @@ public void reorder() { } } + /** + * Reorders two points in the construction. + * + * @param m the first point index + * @param n the second point index + */ public void reorder1(int m, int n) { if (m == n) return; @@ -298,6 +457,9 @@ public void reorder1(int m, int n) { } } + /** + * Reorders the points in the construction for specific types. + */ public void reorder2() { reorder1(0, 1); reorder1(2, 3); @@ -311,6 +473,12 @@ public void reorder2() { } } + /** + * Gets the point less than the specified point in the construction. + * + * @param n the point to compare + * @return the point less than the specified point + */ public int getLessPt(int n) { int k = 0; @@ -320,5 +488,4 @@ public int getLessPt(int n) { } return k; } - -} +} \ No newline at end of file diff --git a/src/main/java/gprover/DTerm.java b/src/main/java/gprover/DTerm.java index 2e68d64d..9f5687dc 100644 --- a/src/main/java/gprover/DTerm.java +++ b/src/main/java/gprover/DTerm.java @@ -1,31 +1,39 @@ package gprover; /** - * Created by IntelliJ IDEA. - * User: yezheng - * Date: 2006-5-4 - * Time: 11:32:44 - * To change this template use File | Settings | File Templates. + * The DTerm class represents a term in a polynomial with a specific degree. + * It includes properties for the degree, the term itself, the next term in the list, + * and a string representation of the term. */ +public class DTerm { + /** The degree of the term. */ + public int deg; -public class DTerm -{ - public int deg; //degree - public XTerm p; //A term - public DTerm nx; // All next terms. + /** The term itself. */ + public XTerm p; - public String text; + /** The next term in the list. */ + public DTerm nx; - public DTerm() - { - deg = 0; - p = null; - nx = null; - text = null; - } + /** The string representation of the term. */ + public String text; - public String toString() - { - return text; - } + /** + * Constructs a DTerm object with default values. + */ + public DTerm() { + deg = 0; + p = null; + nx = null; + text = null; + } + + /** + * Returns the string representation of the term. + * + * @return the string representation of the term + */ + public String toString() { + return text; + } } diff --git a/src/main/java/gprover/ElTerm.java b/src/main/java/gprover/ElTerm.java index f02878c8..a13901f5 100644 --- a/src/main/java/gprover/ElTerm.java +++ b/src/main/java/gprover/ElTerm.java @@ -3,16 +3,11 @@ import java.util.Vector; /** - * Created by IntelliJ IDEA. - * User: yezheng - * Date: 2006-4-17 - * Time: 13:17:41 - * To change this template use File | Settings | File Templates. + * The ElTerm class represents an element term in the geometric theorem + * proving framework. It encapsulates the term type, its associated variable, + * geometric expressions (XTerm instances), conditions, and linked terms. */ public class ElTerm { - final public static int EL_CYCLIC = 11; - final public static int EL_PARA = 2; - final public static int EL_PERP = 3; public int etype = 0; public Var v; public XTerm p1, p2, p; @@ -23,67 +18,95 @@ public class ElTerm { public ElTerm et; - public ElTerm() { - int k = 0; - } + /** + * Constructs an ElTerm object with default values. + */ + public ElTerm() { + int k = 0; + } - public void setText(String s) { - text = s; - } + /** + * Sets the text description of the element term. + * + * @param s the text description to set + */ + public void setText(String s) { + text = s; + } - public String toString() { - return text; - } + /** + * Returns the string representation of the element term. + * + * @return the string representation of the element term + */ + public String toString() { + return text; + } - public Vector getAllxterm() { - Vector v = new Vector(); - v.add(p); + /** + * Gets all XTerm objects associated with the element term. + * + * @return a vector of all XTerm objects + */ + public Vector getAllxterm() { + Vector v = new Vector(); + v.add(p); - XTerm x = p1; - while (x != null) { - v.add(x); - DTerm d = x.ps; - if (d != null) - d = d.nx; - if (d != null) - x = d.p; - else - break; - } - - if (v.size() > 0) { - x = (XTerm) v.get(0); - x.cutMark(); - } - return v; - } + XTerm x = p1; + while (x != null) { + v.add(x); + DTerm d = x.ps; + if (d != null) + d = d.nx; + if (d != null) + x = d.p; + else + break; + } - public int getEType() { - return etype; - } + if (v.size() > 0) { + x = (XTerm) v.get(0); + x.cutMark(); + } + return v; + } - public Vector getAllCond() { - Vector v = new Vector(); - if (co != null) { - Cond c = co; - while (c != null) { - v.add(c); - c = c.nx; + /** + * Gets the type of the element term. + * + * @return the type of the element term + */ + public int getEType() { + return etype; } - } - if (et != null) { - ElTerm e = et; - while (e != null) { - if (e.co != null) { - Cond c = e.co; + + /** + * Gets all Cond objects associated with the element term. + * + * @return a vector of all Cond objects + */ + public Vector getAllCond() { + Vector v = new Vector(); + if (co != null) { + Cond c = co; while (c != null) { v.add(c); c = c.nx; } } - e = e.nx; + if (et != null) { + ElTerm e = et; + while (e != null) { + if (e.co != null) { + Cond c = e.co; + while (c != null) { + v.add(c); + c = c.nx; + } + } + e = e.nx; + } + } + return v; } - } - return v; - } } diff --git a/src/main/java/gprover/Elim.java b/src/main/java/gprover/Elim.java index 0ad28fbe..5d834084 100644 --- a/src/main/java/gprover/Elim.java +++ b/src/main/java/gprover/Elim.java @@ -1,2883 +1,260 @@ package gprover; /** - * Created by IntelliJ IDEA. - * User: yezheng - * Date: 2006-4-20 - * Time: 14:41:03 - * To change this template use File | Settings | File Templates. + * The Elim class provides methods for trimming geometric terms under various constraints. + * It extends the Gr class. */ public class Elim extends Gr { - - ElTerm all_elim; - DTerm ds_set, last_ds; - - ElTerm mk_elim(Var v, XTerm p1, XTerm p2) - { - ElTerm v1 = new ElTerm(); - v1.v = v; - v1.p1 = p1; - v1.p2 = p2; - v1.nx = all_elim.nx; - all_elim.nx = v1; - return (v1); - } - - ElTerm lratio_md1(Var var, int y, int u, int v, XTerm p1, XTerm p2, XTerm q1, XTerm q2) - { - if (print_geo) - { - gprint("\nlratio_md1" + y + " " + u + " " + v); - print_var(var, 0); - gprint("\n"); - pprint(p1); - pprint(p2); - pprint(q1); - pprint(q2); - } - if (eq_poly(p2, q2)) - { /*put_p(q2); */ - return (mk_elim(var, pplus(ptimes(geval(var, y, v), p1), - ptimes(geval(var, y, u), q1)), p2)); - } else - { - return (mk_elim(var, pplus(ptimes3(geval(var, y, v), p1, cp_poly(q2)), - ptimes3(geval(var, y, u), q1, cp_poly(p2))), - ptimes(cp_poly(p2), cp_poly(q2)))); - } - } - -//var = (py a y y c) - ElTerm lratio_md2(Var var, int y, int u, int v, XTerm p1, XTerm p2, XTerm q1, XTerm q2) - { - return (mk_elim(var, - pplus3(ptimes(geval(var, y, v), ptimes(cp_poly(p1), cp_poly(q2))), - ptimes(geval(var, y, u), ptimes(cp_poly(q1), cp_poly(p2))), - ptimes(trim_g(v, v, u, u), ptimes(cp_poly(p1), cp_poly(q1)))), - ptimes(cp_poly(p2), cp_poly(q2)))); - } - - - ElTerm pratio_md1(Var var, int y, int w, int u, int v, XTerm p1, XTerm p2) - { - - return (mk_elim(var, - pplus(ptimes(geval(var, y, w), cp_poly(p2)), - ptimes(cp_poly(p1), geval1(var, y, v, u))), - cp_poly(p2))); - } - - XTerm geval1(Var var, int y, int v, int u) - { - switch (var.nm) - { - case 2: - case -2: - return (trim_a(v, var.pt[1], u, var.pt[3])); - case 3: - case -3: - return (trim_g(v, var.pt[1], u, var.pt[3])); - case 4: - case -4: - return (trim_vec(v, u)); -/* case 4: case -4: return(pminus(trim_vec(v,0),trim_vec(u,0))); */ - default: - gprint("geval11\n"); - exit(1); - } - return (null); - } - - ElTerm pratio_md2(Var var, int y, int w, int u, int v, XTerm p1, XTerm p2) - { - return (mk_elim(var, - pplus4(ptimes3(geval(var, y, w), cp_poly(p2), cp_poly(p2)), - pminus(ptimes3(geval(var, y, v), cp_poly(p1), cp_poly(p2)), - ptimes3(geval(var, y, u), cp_poly(p1), cp_poly(p2))), - ptimes4(get_n(2L), trim_g(w, u, u, v), cp_poly(p1), cp_poly(p2)), - ptimes3(trim_g(v, v, u, u), cp_poly(p1), pminus(cp_poly(p2), cp_poly(p1)))), - ptimes(cp_poly(p2), cp_poly(p2)))); - } - - - ElTerm pe_v_pratio(Var var, int y, int w, int u, int v, XTerm p1, XTerm p2) - { - if (print_geo) - { - gprint("pratio: \n"); - pprint(p1); - pprint(p2); - } - switch (var.nm) - { - case 1: - return (pe_r_pratio(var, var.pt[0], var.pt[1], var.pt[2], var.pt[3], y, w, u, v, p1, p2)); - case 2: - return (pe_a_pratio(var, var.pt[0], var.pt[1], var.pt[2], var.pt[3], y, w, u, v, p1, p2)); - case 3: - return (pe_g_pratio(var, var.pt[0], var.pt[1], var.pt[2], var.pt[3], y, w, u, v, p1, p2)); - case 4: - if (w == u) - return (lratio_md1(var, y, u, v, p1, p2, pminus(cp_poly(p2), cp_poly(p1)), cp_poly(p2))); - else - return (pratio_md1(var, y, w, u, v, p1, p2)); - default: - gerror("pe_v_ipp: (" + var.nm + ")" + "is not a proper variable."); - - } - return (null); - } - - ElTerm pe_r_pratio(Var var, int n2, int n1, int d2, int d1, int y, int w, int u, int v, XTerm p1, XTerm p2) - { - if (print_geo) gprint("pe_r_pratio: " + n1 + n2 + d1 + d2 + y + w + u + v); - if ((n2 == y) && (d2 == y)) - { - if (xcoll(n1, w, y)) - return (mk_elim(var, - pplus(ptimes(cp_poly(p2), trim_r(n1, w, u, v)), cp_poly(p1)), - pplus(ptimes(cp_poly(p2), trim_r(d1, w, u, v)), cp_poly(p1)))); - else if (xcoll(w, u, v)) - return (mk_elim(var, trim_a(n1, n1, u, v), trim_a(d1, d1, u, v))); - else - return (mk_elim(var, trim_a(n1, u, w, v), trim_a(d1, u, w, v))); - } else if (n2 == y) - { - if (xcoll(n1, w, y)) - return (mk_elim(var, - pplus(ptimes(cp_poly(p2), trim_r(n1, w, u, v)), cp_poly(p1)), - ptimes(cp_poly(p2), trim_r(d1, d2, u, v)))); - else if (xcoll(w, u, v)) - return (mk_elim(var, trim_a(n1, n1, u, v), trim_a(d1, u, d2, v))); - else - return (mk_elim(var, trim_a(n1, u, w, v), trim_a(d1, u, d2, v))); - } else if (d2 == y) - { - return (rev_elim(pe_r_pratio(var, d2, d1, n2, n1, y, w, u, v, p1, p2))); - } else - { - exit(1); - } - return (null); - } - - ElTerm pe_a_pratio(Var var, int n1, int n2, int n3, int n4, int y, int w, int u, int v, XTerm p1, XTerm p2) - { - ElTerm e1; - - if (xpara(n2, n4, u, v)) - { - return (mk_elim(var, trim_a(w, n2, n3, n4), get_n(1L))); - } - - if (n3 == n4 && xpara(y, n2, u, v)) - { - n3 = n2; - } - if (xpara(y, n3, u, v)) - { - return (mk_elim(var, ptimes(trim_a(u, n2, v, n4), - pminus(ptimes(trim_r(n3, w, v, u), cp_poly(p2)), - cp_poly(p1))), - p2)); - } - - if ((w == u) && ((p1.var == null && p2.var == null))) - { - e1 = lratio_md1(var, y, u, v, p1, p2, c_pminus(p2, p1), cp_poly(p2)); - } else - e1 = pratio_md1(var, y, w, u, v, p1, p2); - return (e1); - } - - ElTerm pe_g_pratio(Var var, int n1, int n2, int n3, int n4, int y, int w, int u, int v, XTerm p1, XTerm p2) - { - ElTerm e1; - int n; - XTerm q1, q2; - Var v1; - - q1 = get_n(1L); - q2 = get_n(1L); - if (n1 == y && xperp(n2, n4, u, v)) - { - n1 = n2; - n2 = w; - n = n3; - n3 = n4; - n4 = n; - } - if (n1 == y && xperp(n2, n4, u, v)) - { - n1 = n2; - n2 = w; - n = n3; - n3 = n4; - n4 = n; - } - - if (n2 == y && xpara(n2, n4, u, v)) - { - n = n1; - n1 = n2; - n2 = n; - n = n3; - n3 = n4; - n4 = n; - } - if (n1 == y && xpara(n1, n3, u, v)) - { - q1 = ptimes(q1, pminus(ptimes(trim_r(n3, w, v, u), cp_poly(p2)), cp_poly(p1))); - q2 = ptimes(q2, cp_poly(p2)); - n1 = n2; - n3 = n4; - n2 = u; - n4 = v; - } - if (n1 == y && xpara(n1, n3, u, v)) - { - q1 = ptimes(q1, pminus(ptimes(trim_r(n3, w, v, u), cp_poly(p2)), cp_poly(p1))); - q2 = ptimes(q2, cp_poly(p2)); - n1 = n2; - n3 = n4; - n2 = u; - n4 = v; - } - - if (n2 == y && n3 == y) - { - if (w == u) - e1 = lratio_md2(var, y, u, v, p1, p2, c_pminus(p2, p1), cp_poly(p2)); - else - e1 = pratio_md2(var, y, w, u, v, p1, p2); - } else if (n1 == y) - { - v1 = mk_var(3, n1, n2, n3, n4); - if (w == u) - e1 = lratio_md1(v1, y, u, v, p1, p2, c_pminus(p2, p1), cp_poly(p2)); - else - e1 = pratio_md1(v1, y, w, u, v, p1, p2); - e1.v = var; - } else - { - e1 = mk_elim(var, trim_g(n1, n2, n3, n4), get_n(1L)); - } - - e1.p1 = ptimes(e1.p1, q1); - e1.p2 = ptimes(e1.p2, q2); - return (e1); - } - - ElTerm pe_v_ipp(Var var, int y, int w, int u, int v, int r, int p, int q) - { - int n; - if (w == v) - { - n = u; - u = v; - v = n; - } - if (r == q) - { - n = p; - p = q; - q = n; - } - if (w == u && w > v) - { - w = v; - v = u; - u = w; - } - if (r == p && r > q) - { - r = q; - q = p; - p = r; - } - if (r > w) - { - n = w; - w = r; - r = n; - n = u; - u = p; - p = n; - n = v; - v = q; - q = n; - } - switch (var.nm) - { - case 1: - return (pe_r_ipp(var, var.pt[1], var.pt[0], var.pt[3], var.pt[2], y, w, u, v, r, p, q)); - case 2: - return (pe_a_ipp(var, var.pt[0], var.pt[1], var.pt[2], var.pt[3], y, w, u, v, r, p, q)); - case 3: - return (pe_g_ipp(var, var.pt[0], var.pt[1], var.pt[2], var.pt[3], y, w, u, v, r, p, q)); - case 4: - if (w == u) - return (lratio_md1(var, y, u, v, - trim_a(u, p, r, q), trim_a(u, p, v, q), - trim_a(v, q, r, p), trim_a(u, p, v, q))); - else - return (pratio_md1(var, y, w, u, v, trim_a(w, p, r, q), trim_a(u, p, v, q))); - default: - gerror("pe_v_ipp: (" + var.nm + ")" + "is not a proper variable."); - } - return (null); - } - - ElTerm pe_r_ipp(Var var, int n1, int n2, int d1, int d2, int y, int w, int u, int v, int r, int p, int q) - { - int n; - if (print_geo) - gprint("pe_r_ipp: " + n1 + n2 + d1 + d2 + y + w + u + v + r + p + q); - if (xpara(n1, n2, u, v)) - { - n = w; - w = r; - r = n; - n = u; - u = p; - p = n; - n = v; - v = q; - q = n; - } - if ((n2 == y) && d2 == y) - return (mk_elim(var, trim_a(n1, u, w, v), trim_a(d1, u, w, v))); - else if (n2 == y) - return (mk_elim(var, trim_a(n1, u, w, v), trim_a(d1, u, d2, v))); - else if (d2 == y) - return (mk_elim(var, trim_a(n1, u, n2, v), trim_a(d1, u, w, v))); - else - exit(1); - return (null); - } - - ElTerm pe_a_ipp(Var var, int n1, int n2, int n3, int n4, int y, int w, int u, int v, int r, int p, int q) - { - int n; - - if (r == n2 || r == n3 || r == n4) - { - n = w; - w = r; - r = n; - n = u; - u = p; - p = n; - n = v; - v = q; - q = n; - } - - if (xpara(n2, n4, u, v)) - { - return (mk_elim(var, trim_a(w, n2, n3, n4), get_n(1L))); - } - if (xpara(n2, n4, p, q)) - { - return (mk_elim(var, trim_a(r, n2, n3, n4), get_n(1L))); - } - - if (n3 == n4 && xpara(y, n2, u, v)) - { - n3 = n2; - } - if (xpara(y, n3, u, v)) - { - return (mk_elim(var, ptimes(trim_a(u, n2, v, n4), trim_a(n3, q, r, p)), trim_a(v, q, u, p))); - } - if (n3 == n4 && xpara(y, n2, p, q)) - { - n3 = n2; - } - if (xpara(y, n3, p, q)) - { - return (mk_elim(var, ptimes(trim_a(p, n2, q, n4), trim_a(n3, u, w, v)), trim_a(q, u, p, v))); - } - - if (xcoll(w, u, v) && (xpara(u, n3, n2, n4) || xpara(v, n3, n2, n4))) - return (lratio_md1(var, y, u, v, - trim_a(u, p, r, q), trim_a(u, p, v, q), - trim_a(v, q, r, p), trim_a(u, p, v, q))); - if (xcoll(r, p, q) && (xpara(p, n3, n2, n4) || xpara(q, n3, n2, n4))) - return (lratio_md1(var, y, p, q, - trim_a(p, u, w, v), trim_a(p, u, q, v), - trim_a(q, v, w, u), trim_a(p, u, q, v))); - if (w == u) - return (lratio_md1(var, y, u, v, - trim_a(u, p, r, q), trim_a(u, p, v, q), - trim_a(v, q, r, p), trim_a(u, p, v, q))); - return (pratio_md1(var, y, w, u, v, trim_a(w, p, r, q), trim_a(u, p, v, q))); - } - - ElTerm pe_g_ipp(Var var, int n1, int n2, int n3, int n4, int y, int w, int u, int v, int r, int p, int q) - { - int n; - Var v1; - ElTerm e1; - XTerm p1, p2; - - p1 = get_n(1L); - p2 = get_n(1L); - if (n1 == y && xperp(n2, n4, u, v)) - { - n1 = n2; - n2 = w; - n = n3; - n3 = n4; - n4 = n; - } else if (n2 == y && xperp(n1, n3, u, v)) - { - n2 = w; - } - if (n1 == y && xperp(n2, n4, u, v)) - { - n1 = n2; - n2 = w; - n = n3; - n3 = n4; - n4 = n; - } - if (n1 == y && xperp(n2, n4, p, q)) - { - n1 = n2; - n2 = r; - n = n3; - n3 = n4; - n4 = n; - } else if (n2 == y && xperp(n1, n3, p, q)) - { - n2 = r; - } - if (n1 == y && xperp(n2, n4, p, q)) - { - n1 = n2; - n2 = r; - n = n3; - n3 = n4; - n4 = n; - } - - if (n2 == y && xpara(n2, n4, u, v)) - { - n = n1; - n1 = n2; - n2 = n; - n = n3; - n3 = n4; - n4 = n; - } - if (n1 == y && xpara(n1, n3, u, v)) - { - p1 = ptimes(p1, trim_a(n3, p, r, q)); - p2 = ptimes(p2, trim_a(v, p, u, q)); - n1 = n2; - n3 = n4; - n2 = u; - n4 = v; - } - if (n1 == y && xpara(n1, n3, u, v)) - { - p1 = ptimes(p1, trim_a(n3, p, r, q)); - p2 = ptimes(p2, trim_a(v, p, u, q)); - n1 = n2; - n3 = n4; - n2 = u; - n4 = v; - } - if (n2 == y && xpara(n2, n4, p, q)) - { - n = n1; - n1 = n2; - n2 = n; - n = n3; - n3 = n4; - n4 = n; - } - if (n1 == y && xpara(n1, n3, p, q)) - { - p1 = ptimes(p1, trim_a(n3, u, w, v)); - p2 = ptimes(p2, trim_a(q, u, p, v)); - n1 = n2; - n3 = n4; - n2 = p; - n4 = q; - } - if (n1 == y && xpara(n1, n3, p, q)) - { - p1 = ptimes(p1, trim_a(n3, u, w, v)); - p2 = ptimes(p2, trim_a(q, u, p, v)); - n1 = n2; - n3 = n4; - n2 = p; - n4 = q; - } - - if (n2 == y && n3 == y) - { - if (w == u) - e1 = lratio_md2(var, y, u, v, - trim_a(u, p, r, q), trim_a(u, p, v, q), - trim_a(v, q, r, p), trim_a(u, p, v, q)); - else - e1 = pratio_md2(var, y, w, u, v, trim_a(w, p, r, q), trim_a(u, p, v, q)); - } else if (n1 == y) - { - v1 = mk_var(-3, n1, n2, n3, n4); - if (w == u) - { - e1 = lratio_md1(v1, y, u, v, - trim_a(u, p, r, q), trim_a(u, p, v, q), - trim_a(v, q, r, p), trim_a(u, p, v, q)); - } else - { - e1 = pratio_md1(v1, y, w, u, v, trim_a(w, p, r, q), trim_a(u, p, v, q)); - } - e1.v = var; - } else - { - e1 = mk_elim(var, trim_g(n1, n2, n3, n4), get_n(1L)); - } - - e1.p1 = ptimes(e1.p1, p1); - e1.p2 = ptimes(e1.p2, p2); - return (e1); - } - - - ElTerm pe_r_ill(Var var, int n1, int n2, int d1, int d2, int y, int u, int v, int i, int j) - { - int n0; - - if (n2 == y) - { - if (xcoll(n1, u, v)) - { - n0 = i; - i = u; - u = n0; - n0 = j; - j = v; - v = n0; - } - if (d2 == y) - return (mk_elim(var, trim_a(n1, u, v, v), trim_a(d1, u, v, v))); - else - return (mk_elim(var, trim_a(n1, u, v, v), trim_a(d1, u, d2, v))); - } else if (d2 == y) - { - return (rev_elim(pe_r_ill(var, d1, d2, n1, n2, y, u, v, i, j))); - } else - { - exit(1); - } - return (null); - } - - ElTerm pe_a_ill(Var var, int n1, int n2, int n3, int n4, int y, int u, int v, int i, int j) - { - int n; - if (v < u) - { - n = u; - u = v; - v = n; - } - if (j < i) - { - n = i; - i = j; - j = n; - } - if (j < v) - { - n = u; - u = i; - i = n; - n = v; - v = j; - j = n; - } - - if (xpara(n2, n4, u, v)) - { - return (mk_elim(var, trim_a(u, n2, n3, n4), get_n(1L))); - } - if (xpara(n2, n4, i, j)) - { - return (mk_elim(var, trim_a(i, n2, n3, n4), get_n(1L))); - } - - if (n3 == n4 && xcoll(u, v, n2)) - { - n3 = n2; - } - if (xcoll(u, v, n3)) - { - return (mk_elim(var, ptimes(trim_a(u, n2, v, n4), trim_a(n3, i, j, j)), trim_a(v, i, u, j))); - } - if (n3 == n4 && xcoll(i, j, n2)) - { - n3 = n2; - } - if (xcoll(i, j, n3)) - { - return (mk_elim(var, ptimes(trim_a(i, n2, j, n4), trim_a(n3, u, v, v)), trim_a(j, u, i, v))); - } - - if (xpara(u, n3, n2, n4) || xpara(v, n3, n2, n4)) - { - return (lratio_md1(var, y, u, v, - trim_a(u, i, j, j), trim_a(u, i, v, j), - trim_a(v, j, i, i), trim_a(u, i, v, j))); - } - if (xpara(i, n3, n2, n4) || xpara(j, n3, n2, n4)) - { - return (lratio_md1(var, y, i, j, - trim_a(i, u, v, v), trim_a(i, u, j, v), - trim_a(j, v, u, u), trim_a(i, u, j, v))); - } - return (lratio_md1(var, y, u, v, - trim_a(u, i, j, j), trim_a(u, i, v, j), - trim_a(v, j, i, i), trim_a(u, i, v, j))); - } - - ElTerm pe_g_ill(Var var, int n1, int n2, int n3, int n4, int y, int u, int v, int i, int j) - { - int n; - ElTerm e1; - XTerm p1, p2; - Var v1; - - if (v < u) - { - n = u; - u = v; - v = n; - } - if (j < i) - { - n = i; - i = j; - j = n; - } - if (j < v) - { - n = u; - u = i; - i = n; - n = v; - v = j; - j = n; - } - - p1 = get_n(1L); - p2 = get_n(1L); - if (n1 == y && xperp(n2, n4, u, v)) - { - n1 = n2; - n2 = u; - n = n3; - n3 = n4; - n4 = n; - } - if (n1 == y && xperp(n2, n4, u, v)) - { - n1 = n2; - n2 = u; - n = n3; - n3 = n4; - n4 = n; - } - if (n1 == y && xperp(n2, n4, i, j)) - { - n1 = n2; - n2 = i; - n = n3; - n3 = n4; - n4 = n; - } - if (n1 == y && xperp(n2, n4, i, j)) - { - n1 = n2; - n2 = i; - n = n3; - n3 = n4; - n4 = n; - } - - - if (n2 == y && xcoll(u, v, n4)) - { - n = n1; - n1 = n2; - n2 = n; - n = n3; - n3 = n4; - n4 = n; - } - if (n1 == y && xcoll(u, v, n3)) - { - p1 = ptimes(p1, trim_a(n3, i, j, j)); - p2 = ptimes(p2, trim_a(v, i, u, j)); - n1 = n2; - n3 = n4; - n2 = u; - n4 = v; - } - if (n1 == y && xcoll(u, v, n3)) - { - p1 = ptimes(p1, trim_a(n3, i, j, j)); - p2 = ptimes(p2, trim_a(v, i, u, j)); - n1 = n2; - n3 = n4; - n2 = u; - n4 = v; - } - - if (n2 == y && xcoll(i, j, n4)) - { - n = n1; - n1 = n2; - n2 = n; - n = n3; - n3 = n4; - n4 = n; - } - if (n1 == y && xcoll(i, j, n3)) - { - p1 = ptimes(p1, trim_a(n3, u, v, v)); - p2 = ptimes(p2, trim_a(j, u, i, v)); - n1 = n2; - n3 = n4; - n2 = i; - n4 = j; - } - if (n1 == y && xcoll(i, j, n3)) - { - p1 = ptimes(p1, trim_a(n3, u, v, v)); - p2 = ptimes(p2, trim_a(j, u, i, v)); - n1 = n2; - n3 = n4; - n2 = i; - n4 = j; - } - - if (n2 == y && n3 == y) - { - e1 = lratio_md2(var, y, u, v, - trim_a(u, i, j, j), trim_a(u, i, v, j), - trim_a(v, j, i, i), trim_a(u, i, v, j)); - } else if (n1 == y) - { - if (n3 == i || n3 == j || xperp(i, n3, n2, n4) || xperp(j, n3, n2, n4)) - { - n = u; - u = i; - i = n; - n = v; - v = j; - j = n; - } - v1 = mk_var(3, n1, n2, n3, n4); - e1 = lratio_md1(v1, y, u, v, - trim_a(u, i, j, j), trim_a(u, i, v, j), - trim_a(v, j, i, i), trim_a(u, i, v, j)); - e1.v = var; - } else - { - e1 = mk_elim(var, trim_g(n1, n2, n3, n4), get_n(1L)); - } - - e1.p1 = ptimes(e1.p1, p1); - e1.p2 = ptimes(e1.p2, p2); - return (e1); - } - - - ElTerm pe_vec_ill(Var var, int n1, int n2, int y, int u, int v, int i, int j) - { - int n; - - if (v < u) - { - n = u; - u = v; - v = n; - } - if (j < i) - { - n = i; - i = j; - j = n; - } - if (j < v) - { - n = u; - u = i; - i = n; - n = v; - v = j; - j = n; - } - - return (lratio_md1(var, y, u, v, - trim_a(u, i, j, j), trim_a(u, i, v, j), - trim_a(v, j, i, i), trim_a(u, i, v, j))); - } - - ElTerm pe_r_ilp(Var var, int n1, int n2, int d1, int d2, int y, int u, int v, int r, int p, int q) - { - - if ((n2 == y) && (d2 == y)) - { - if (xcoll(n1, u, v)) - return (mk_elim(var, trim_a(n1, p, r, q), trim_a(d1, p, r, q))); - else - return (mk_elim(var, trim_a(n1, u, v, v), trim_a(d1, u, v, v))); - } - if (n2 == y) - { - if (xcoll(n1, u, v)) - return (mk_elim(var, trim_a(n1, p, r, q), trim_a(d1, p, d2, q))); - else if (xcoll(d2, u, v)) - return (mk_elim(var, trim_a(n1, u, v, v), trim_a(d1, u, v, v))); - else if (xcoll(d1, u, v)) - return (mk_elim(var, trim_a(n1, u, v, v), trim_a(d2, v, u, u))); - else - return (mk_elim(var, trim_a(n1, u, v, v), trim_a(d1, u, d2, v))); - } else if (d2 == y) - { - return (rev_elim(pe_r_ilp(var, d1, d2, n1, n2, y, u, v, r, p, q))); - } else - { - exit(1); - } - return (null); - } - - ElTerm pe_a_ilp(Var var, int n1, int n2, int n3, int n4, int y, int u, int v, int r, int p, int q) - { - int n; - if (v < u) - { - n = u; - u = v; - v = n; - } - if (xpara(n2, n4, u, v)) - { - return (mk_elim(var, trim_a(u, n2, n3, n4), get_n(1L))); - } - if (xpara(n2, n4, p, q)) - { - return (mk_elim(var, trim_a(r, n2, n3, n4), get_n(1L))); - } - - if (n3 == n4 && xcoll(u, v, n2)) - { - n3 = n2; - } - if (xcoll(u, v, n3)) - { - return (mk_elim(var, ptimes(trim_a(u, n2, v, n4), trim_a(n3, p, r, q)), trim_a(v, p, u, q))); - } - if (xpara(u, n3, n2, n4) || xpara(v, n3, n2, n4)) - { - return (lratio_md1(var, y, u, v, - trim_a(u, p, r, q), trim_a(u, p, v, q), - trim_a(v, q, r, p), trim_a(u, p, v, q))); - } - - if (n3 == n4 && xpara(y, n2, p, q)) - { - n3 = n2; - } - if (xpara(y, n3, p, q)) - { - return (mk_elim(var, ptimes(trim_a(p, n2, q, n4), trim_a(n3, u, v, v)), trim_a(q, u, p, v))); - } - return (lratio_md1(var, y, u, v, - trim_a(u, p, r, q), trim_a(u, p, v, q), - trim_a(v, q, r, p), trim_a(u, p, v, q))); - } - - ElTerm pe_g_ilp(Var var, int n1, int n2, int n3, int n4, int y, int u, int v, int r, int p, int q) - { - int n; - Var v1; - ElTerm e1; - XTerm p1, p2; - if (v < u) - { - n = u; - u = v; - v = n; - } - p1 = get_n(1L); - p2 = get_n(1L); - if (n1 == y && xperp(n2, n4, u, v)) - { - n1 = n2; - n2 = u; - n = n3; - n3 = n4; - n4 = n; - } - if (n1 == y && xperp(n2, n4, u, v)) - { - n1 = n2; - n2 = u; - n = n3; - n3 = n4; - n4 = n; - } - if (n1 == y && xperp(n2, n4, p, q)) - { - n1 = n2; - n2 = r; - n = n3; - n3 = n4; - n4 = n; - } - if (n1 == y && xperp(n2, n4, p, q)) - { - n1 = n2; - n2 = r; - n = n3; - n3 = n4; - n4 = n; - } - if (n1 == y && xcoll(u, v, n3)) - { - p1 = ptimes(p1, trim_a(n3, p, r, q)); - p2 = ptimes(p2, trim_a(v, p, u, q)); - n1 = n2; - n3 = n4; - n2 = u; - n4 = v; - } - if (n1 == y && xcoll(u, v, n3)) - { - p1 = ptimes(p1, trim_a(n3, p, r, q)); - p2 = ptimes(p2, trim_a(v, p, u, q)); - n1 = n2; - n3 = n4; - n2 = u; - n4 = v; - } - if (n1 == y && xpara(n1, n3, p, q)) - { - p1 = ptimes(p1, trim_a(n3, u, v, v)); - p2 = ptimes(p2, trim_a(q, u, p, v)); - n1 = n2; - n3 = n4; - n2 = p; - n4 = q; - } - if (n1 == y && xpara(n1, n3, p, q)) - { - p1 = ptimes(p1, trim_a(n3, u, v, v)); - p2 = ptimes(p2, trim_a(q, u, p, v)); - n1 = n2; - n3 = n4; - n2 = p; - n4 = q; - } - if (n2 == y && n3 == y) - { - e1 = lratio_md2(var, y, u, v, - trim_a(u, p, r, q), trim_a(u, p, v, q), - trim_a(v, q, r, p), trim_a(u, p, v, q)); - } else if (n1 == y) - { - v1 = mk_var(3, n1, n2, n3, n4); - e1 = lratio_md1(v1, y, u, v, - trim_a(u, p, r, q), trim_a(u, p, v, q), - trim_a(v, q, r, p), trim_a(u, p, v, q)); - e1.v = var; - } else - { - e1 = mk_elim(var, trim_g(n1, n2, n3, n4), get_n(1L)); - } - - e1.p1 = ptimes(e1.p1, p1); - e1.p2 = ptimes(e1.p2, p2); - return (e1); - } - - - ////////////////////////////////////////// - -/* trim functions */ -/* -xterm *mk_trim (v) -var *v; -{ var *v1; - int i; - - v1 = all_var.nx; - while ((v1 != null) && !(eq_var(v,v1))) { v1 = v1.nx;} - if (v1 == null) - { v1=(var *)calloc(1,sizeof(var)); - v1.nm = v.nm; - for (i=0;i<9;i++) v1.pt[i] = v.pt[i]; - v1.nx = null; - last_var.nx = v1; last_var = v1; - } - return(get_m(v1)); -} -*/ - ///////////////////////////////////////////////////////////////from area.cpp trim function. - XTerm geval(Var var, int y, int p) - { - int k; - int i, pt[]; - pt = new int[9]; - - for (i = 0; i < 4; i++) - if (var.pt[i] == y) - pt[i] = p; - else - pt[i] = var.pt[i]; - switch (var.nm) - { - case 1: - case -1: - return (trim_r(pt[0], pt[1], pt[2], pt[3])); - case 2: - case -2: - return (trim_a(pt[0], pt[1], pt[2], pt[3])); - case 3: - case -3: - return (trim_g(pt[0], pt[1], pt[2], pt[3])); - case 4: - case -4: - return (trim_vec(pt[0], pt[1])); - default: - exit(1); - } - return (null); - } - - - XTerm trim_r(int p1, int p2, int p3, int p4) -//int p1,p2,p3,p4; - { - int p; - char sn = 1; -/* if (print_geo) printf("trim_r %d %d %d %d\r\n",p1,p2,p3,p4); */ - if (p1 == p2) return (pzero()); - if (p3 == p4) gerror("rtrim: denominator of ratio is zero.~%"); - if ((p1 == p3) && (p2 == p4)) return (get_n(1L)); - if ((p2 == p3) && (p1 == p4)) return (get_n(-1L)); - if (p1 < p2) - { - sn *= -1; - p = p1; - p1 = p2; - p2 = p; - } - if (p3 < p4) - { - sn *= -1; - p = p3; - p3 = p4; - p4 = p; - } - if (sn == 1) - return (get_m(mk_var(1, p1, p2, p3, p4))); - else - return (neg_poly(get_m(mk_var(1, p1, p2, p3, p4)))); - - } - - XTerm trim_a(int p1, int p2, int p3, int p4) - { - int p; - char sn = 1; - if (xpara(p1, p3, p2, p4)) return (pzero()); - if (xcoll(p1, p2, p3)) - { - p2 = p1; - } else if (xcoll(p4, p2, p3)) - { - p3 = p4; - } else if (xcoll(p4, p1, p3)) - { - p4 = p3; - } else if (xcoll(p4, p2, p1)) - { - p1 = p4; - } - if (p1 < p3) - { - sn *= -1; - p = p1; - p1 = p3; - p3 = p; - } - if (p2 < p4) - { - sn *= -1; - p = p2; - p2 = p4; - p4 = p; - } - if (p1 < p2) - { - sn *= -1; - p = p1; - p1 = p2; - p2 = p; - p = p3; - p3 = p4; - p4 = p; - } else if ((p1 == p2) && (p3 < p4)) - { - sn *= -1; - p = p3; - p3 = p4; - p4 = p; - } - - if (p1 == p2) - { - p2 = p3; - p3 = p4; - } else if (p2 == p3) - { - p3 = p4; - } - - if (sn == 1) - return (get_m(mk_var(2, p1, p2, p3, p4))); - else - return (neg_poly(get_m(mk_var(2, p1, p2, p3, p4)))); - } - - XTerm trim_g(int p1, int p2, int p3, int p4) - { - int p; - char sn = 1; -/* if (print_geo) printf("\r\ntrim_g %d %d %d %d\r\n",p1,p2,p3,p4); */ - if (xperp(p1, p3, p2, p4)) return (get_n(0L)); - if (p1 < p3) - { - sn *= -1; - p = p1; - p1 = p3; - p3 = p; - } - if (p2 < p4) - { - sn *= -1; - p = p2; - p2 = p4; - p4 = p; - } - if (p1 < p2) - { - p = p1; - p1 = p2; - p2 = p; - p = p3; - p3 = p4; - p4 = p; - } else if ((p1 == p2) && (p3 < p4)) - { - p = p3; - p3 = p4; - p4 = p; - } - - if (p1 == p2) - { - sn *= -1; - p1 = p3; - p3 = p2; - } else if (p3 == p4) - { - sn *= -1; - p4 = p2; - p2 = p3; - } - //The largest index is either p1 or p2 - if (sn == 1) - return (get_m(mk_var(3, p1, p2, p3, p4))); - else - return (neg_poly(get_m(mk_var(3, p1, p2, p3, p4)))); - } - - XTerm trim_f(int p1, int p2, int p3, int p4) - { - int p; - char sn = 1; - if (xcoll4(p1, p2, p3, p4)) return (pzero()); - if (p1 < p2) - { - p = p1; - p1 = p2; - p2 = p; - } - if (p3 < p4) - { - p = p3; - p3 = p4; - p4 = p; - } - if (p1 < p3) - { - sn *= -1; - p = p1; - p1 = p3; - p3 = p; - p = p2; - p2 = p4; - p4 = p; - } else if ((p1 == p3) && (p2 < p4)) - { - sn *= -1; - p = p2; - p2 = p4; - p4 = p; - } - if (sn == 1) - return (get_m(mk_var(10, p1, p2, p3, p4))); - else - return (neg_poly(get_m(mk_var(10, p1, p2, p3, p4)))); - } - - XTerm trim_fl(LLine l1, LLine l2) - { - if (l1 == l2) return (pzero()); - return (trim_f(l1.pt[0], l1.pt[1], l2.pt[0], l2.pt[1])); - } - - XTerm trim_vec(int p1, int p2) - { - if (p2 == 0) - { - return (get_m(mk_var(4, p1, 0, 0, 0))); - } - if (p1 == p2) return (pzero()); - if (p1 < p2) return (neg_poly(get_m(mk_var(4, p2, p1, 0, 0)))); - return (get_m(mk_var(4, p1, p2, 0, 0))); - } - - XTerm trim_l(int p1, int p2) - { - if (p1 == p2) return (pzero()); - if (p1 < p2) return (neg_poly(get_m(mk_var(5, p2, p1, 0, 0)))); - return (get_m(mk_var(5, p1, p2, 0, 0))); - } - - XTerm trim_s(int p1, int p2) - { - if (p1 == p2) return (pzero()); - if (p1 < p2) return (neg_poly(get_m(mk_var(6, p2, p1, 0, 0)))); - return (get_m(mk_var(6, p1, p2, 0, 0))); - } - - XTerm trim_c(int p1, int p2) - { - if (p1 == p2) return (get_n(1L)); - if (p1 < p2) return (neg_poly(get_m(mk_var(7, p2, p1, 0, 0)))); - return (get_m(mk_var(7, p1, p2, 0, 0))); - } - /////////////////////////////////////////////////////////////////////////////////////////////from elimt; - - ElTerm tratio_a_md1(Var v_a, int y, int w, int u, int v, XTerm p1, XTerm p2) - { - return (mk_elim(v_a, - pplus(ptimes3(get_n(4L), cp_poly(p2), geval(v_a, y, w)), - ptimes(cp_poly(p1), trim_g(v, v_a.pt[1], u, v_a.pt[3]))), - ptimes(get_n(4L), cp_poly(p2)))); - } - - ElTerm tratio_g_md1(Var v_a, int y, int w, int u, int v, XTerm p1, XTerm p2) - { - return (mk_elim(v_a, - pplus(ptimes(cp_poly(p2), geval(v_a, y, w)), - ptimes3(get_n(4L), cp_poly(p1), trim_a(u, v_a.pt[1], v, v_a.pt[3]))), - cp_poly(p2))); - } - - ElTerm tratio_md2(Var v_a, int n3, int n4, int y, int w, int u, int v, XTerm p1, XTerm p2) - { - return (mk_elim(v_a, - pplus3(ptimes3(cp_poly(p2), cp_poly(p2), geval(v_a, y, w)), - ptimes4(get_n(-4L), cp_poly(p1), cp_poly(p2), - pplus(trim_a(n3, u, w, v), trim_a(n4, u, w, v))), - ptimes3(cp_poly(p1), cp_poly(p1), trim_g(v, u, u, v))), - ptimes(cp_poly(p2), cp_poly(p2)))); - } - - ElTerm pe_v_tratio(Var v_a, int y, int w, int u, int v, XTerm p1, XTerm p2) - { - if (print_geo) - { //printf("pe_v_tratio. %s %s %s %s\n",ANAME(y),ANAME(w),ANAME(u),ANAME(v)); - print_var(v_a, 0); - gprint("\n"); - pprint(p1); - pprint(p2); - } - switch (v_a.nm) - { - case 1: - return (pe_r_tratio(v_a, v_a.pt[1], v_a.pt[0], v_a.pt[3], v_a.pt[2], y, w, u, v, p1, p2)); - case 2: - return (pe_a_tratio(v_a, v_a.pt[0], v_a.pt[1], v_a.pt[2], v_a.pt[3], y, w, u, v, p1, p2)); - case 3: - return (pe_g_tratio(v_a, v_a.pt[0], v_a.pt[1], v_a.pt[2], v_a.pt[3], y, w, u, v, p1, p2)); - default: - gerror("pe_v_tratio: is not a proper variable.\n"); - } - return (null); - } - - ElTerm pe_r_tratio(Var v_a, int n1, int n2, int n3, int n4, int y, int r, int p, int q, XTerm p1, XTerm p2) - { - if (n2 == y && n4 == y) - { - if (xcoll(n1, r, y)) - return (mk_elim(v_a, - pplus(ptimes3(get_n(4L), cp_poly(p2), trim_a(n1, p, r, q)), - ptimes(cp_poly(p1), trim_g(p, p, q, q))), - pplus(ptimes3(get_n(4L), p2, trim_a(n3, p, r, q)), - ptimes(p1, trim_g(p, p, q, q))))); - else - return (mk_elim(v_a, trim_g(n1, p, r, q), trim_g(n3, p, r, q))); - } else if (n2 == y) - { - if (xcoll(n1, r, y)) - return (mk_elim(v_a, - pplus(ptimes3(get_n(4L), cp_poly(p2), trim_a(n1, p, r, q)), - ptimes(cp_poly(p1), trim_g(p, p, q, q))), - ptimes3(get_n(4L), p2, trim_a(n3, p, n4, q)))); - else - return (mk_elim(v_a, trim_g(n1, p, r, q), trim_g(n3, p, n4, q))); - } else if (n3 == y) - { - return (rev_elim(pe_r_tratio(v_a, n3, n4, n1, n2, y, r, p, q, p1, p2))); - } else - gerror("pe_r_taio"); - return (null); - } - - ElTerm pe_a_tratio(Var v_a, int n1, int n2, int n3, int n4, int y, int w, int u, int v, XTerm p1, XTerm p2) - { - if (xperp(n2, n4, u, v)) return (mk_elim(v_a, trim_a(w, n2, n3, n4), get_n(1L))); - return (tratio_a_md1(v_a, y, w, u, v, p1, p2)); - } - - ElTerm pe_g_tratio(Var v_a, int n1, int n2, int n3, int n4, int y, int w, int u, int v, XTerm p1, XTerm p2) - { - ElTerm e = null; - if (n1 == y && n2 != y) - { - if (xpara(n2, n4, u, v)) return (mk_elim(v_a, trim_g(w, n2, n3, n4), get_n(1L))); - return (tratio_g_md1(v_a, y, w, u, v, p1, p2)); - } - - - if (n2 == y && n3 == y) - { - if (n1 == w && n4 == w) - e = mk_elim(v_a, ptimes3(cp_poly(p1), cp_poly(p1), trim_g(v, u, u, v)), ppower(p2, 2)); - else - e = tratio_md2(v_a, n1, n4, y, w, u, v, p1, p2); - } - return (e); - } - - - ElTerm pe_a_itt1(Var v_a, int n1, int n2, int n3, int y, int o, int u, int v) - { - int n; - if ((n1 == u && n2 == v) || (n1 == v && n2 == u)) - return (mk_elim(v_a, ptimes(trim_g(o, n1, n1, n2), trim_g(o, n2, n2, n1)), - ptimes(get_n(-16L), trim_a(n1, n2, o, o)))); - if ((n1 == o && n2 == v) || (n1 == v && n2 == o)) - { - n = u; - u = v; - v = n; - } - if ((n1 == o && n2 == u) || (n1 == u && n2 == o)) - return (mk_elim(v_a, ptimes(trim_g(n1, n2, n2, n1), trim_g(n1, v, v, n2)), - ptimes(get_n(16L), trim_a(n1, n2, v, v)))); - return (null); - } - - ElTerm pe_a_itt(Var v_a, int n1, int n2, int n3, int n4, int y, int w, int u, int v, int r, int p, int q) - { - int n; - ElTerm e1; - if (xperp(n2, n4, u, v)) return (mk_elim(v_a, trim_a(w, n2, n3, n4), get_n(1L))); - if (xperp(n2, n4, p, q)) return (mk_elim(v_a, trim_a(r, n2, n3, n4), get_n(1L))); - - if (w == v) - { - n = u; - u = v; - v = n; - } - if (r == q) - { - n = p; - p = q; - q = n; - } - if (n3 == n4 && w == r && w == u && r == p) - { - e1 = pe_a_itt1(v_a, n2, n3, n1, y, w, v, q); - if (e1 != null) return (e1); - } - - if (n3 == n4 && xcoll(r, n2, n3)) - { - n3 = n2; - } - if (xpara(r, n3, n2, n4)) - return (tratio_a_md1(v_a, y, r, p, q, trim_g(r, u, w, v), ptimes(get_n(-4L), trim_a(p, u, q, v)))); - return (tratio_a_md1(v_a, y, w, u, v, trim_g(w, p, r, q), ptimes(get_n(-4L), trim_a(u, p, v, q)))); - } - - - ElTerm pe_g_itt1(Var v_a, int n1, int n2, int n3, int y, int o, int u, int v) - { - int n; - if ((n1 == u && n3 == v) || (n1 == v && n3 == u)) - { - return (mk_elim(v_a, ptimes3(trim_g(u, o, o, v), trim_g(o, u, u, v), trim_g(o, v, v, u)), - ptimes3(get_n(-16L), trim_a(o, u, u, v), trim_a(o, u, u, v)))); - } - if ((n1 == o && n3 == v) || (n1 == v && n3 == o) || (n1 == v && n3 == v)) - { - n = u; - u = v; - v = n; - } - if ((n1 == o && n3 == u) || (n1 == u && n3 == o) || (n1 == u && n3 == u)) - { - return (mk_elim(v_a, ptimes3(trim_g(u, o, o, u), trim_g(o, v, v, u), trim_g(o, v, v, u)), - ptimes3(get_n(16L), trim_a(o, u, u, v), trim_a(o, u, u, v)))); - } - if (n1 == o && n3 == o) - { - return (mk_elim(v_a, ptimes3(trim_g(v, o, o, v), trim_g(u, o, o, u), trim_g(v, u, u, v)), - ptimes3(get_n(16L), trim_a(o, u, u, v), trim_a(o, u, u, v)))); - } - return (null); - } - - ElTerm pe_g_itt(Var v_a, int n1, int n2, int n3, int n4, int y, int w, int u, int v, int r, int p, int q) - { - ElTerm e1; - int n; - - if (n1 == y) - { - if (xpara(n2, n4, u, v)) return (mk_elim(v_a, trim_g(w, n2, n3, n4), get_n(1L))); - if (xpara(n2, n4, p, q)) return (mk_elim(v_a, trim_g(r, n2, n3, n4), get_n(1L))); - if (xperp(r, n3, n2, n4)) - return (tratio_g_md1(v_a, y, r, p, q, trim_g(r, u, w, v), ptimes(get_n(-4L), trim_a(p, u, q, v)))); - return (tratio_g_md1(v_a, y, w, u, v, trim_g(w, p, r, q), ptimes(get_n(-4L), trim_a(u, p, v, q)))); - } - if (w == v) - { - n = u; - u = v; - v = n; - } - if (r == q) - { - n = p; - p = q; - q = n; - } - - int sn = 1; -// if (n2==y && n3==y) { n3 = n1; n1 = n2; sn = -1; } - - - if (n2 == y && n3 == y && w == r && w == u && r == p) - { - return (pe_g_itt1(v_a, n1, n2, n4, y, w, v, q)); - } - - if (n2 == y && n3 == y) - e1 = tratio_md2(v_a, n1, n4, y, w, u, v, trim_g(w, p, r, q), ptimes(get_n(-4L), trim_a(u, p, v, q))); - else - return (null); - return e1; - - } - -/* -el_term pe_r_itt (v_a,n1,n2,n3,n4,y,w,u,v,r,p,q) -var v_a; -int n1,n2,n3,n4,y,w,u,v,r,p,q; -{ return(null);} - -*/ - ElTerm pe_v_ipt(Var v_a, int y, int w, int u, int v, int r, int p, int q) - { - int n; - if (w == v) - { - n = u; - u = v; - v = n; - } - if (r == q) - { - n = p; - p = q; - q = n; - } - if (w == u && w > v) - { - w = v; - v = u; - u = w; - } - switch (v_a.nm) - { - case 1: - return (pe_r_ipt(v_a, v_a.pt[1], v_a.pt[0], v_a.pt[3], v_a.pt[2], y, w, u, v, r, p, q)); - - case 2: - return (pe_a_ipt(v_a, v_a.pt[0], v_a.pt[1], v_a.pt[2], v_a.pt[3], y, w, u, v, r, p, q)); - case 3: - return (pe_g_ipt(v_a, v_a.pt[0], v_a.pt[1], v_a.pt[2], v_a.pt[3], y, w, u, v, r, p, q)); - case 4: - if (w == u) - return (lratio_md1(v_a, y, u, v, - trim_g(u, p, r, q), trim_g(u, p, v, q), - trim_g(r, p, v, q), trim_g(u, p, v, q))); - return (pratio_md1(v_a, y, w, u, v, trim_g(w, p, r, q), trim_g(u, p, v, q))); - default: - gerror("pe_v_ipt: is not a proper variable.\n"); - } - return (null); - } - - ElTerm pe_r_ipt(Var v_a, int n1, int n2, int d1, int d2, int y, int w, int u, int v, int r, int p, int q) - { - if (n2 == y && d2 == y) - { - if (xcoll(n1, w, y)) - return (mk_elim(v_a, trim_g(n1, p, r, q), trim_g(d1, p, r, q))); - else - return (mk_elim(v_a, trim_a(n1, u, w, v), trim_a(d1, u, w, v))); - } else if (n2 == y) - { - if (xcoll(n1, w, y)) - return (mk_elim(v_a, trim_g(n1, p, r, q), trim_g(d1, p, d2, q))); - else if (xcoll(n2, p, q) && xcoll(d2, p, q)) - { - return (mk_elim(v_a, trim_a(n1, p, p, q), trim_a(d1, p, p, q))); - } else if (xcoll(n2, p, q) && d2 != y && xcoll(d1, p, q)) - { - return (mk_elim(v_a, trim_a(n1, p, p, q), trim_a(d2, q, q, p))); - } else - return (mk_elim(v_a, trim_a(n1, u, w, v), trim_a(d1, u, d2, v))); - } else if (d2 == y) - { - return (rev_elim(pe_r_ipt(v_a, d1, d2, n1, n2, y, w, u, v, r, p, q))); - } else - exit(1); - return (null); - } - - ElTerm pe_a_ipt(Var v_a, int n1, int n2, int n3, int n4, int y, int w, int u, int v, int r, int p, int q) - { - if (xpara(n2, n4, u, v)) - { - return (mk_elim(v_a, trim_a(w, n2, n3, n4), get_n(1L))); - } - if (xperp(n2, n4, p, q)) - { - return (mk_elim(v_a, trim_a(r, n2, n3, n4), get_n(1L))); - } - - if (n3 == n4 && xpara(y, n2, u, v)) - { - n3 = n2; - } - if (xpara(y, n3, u, v)) - { - return (mk_elim(v_a, ptimes(trim_a(u, n2, v, n4), trim_g(n3, q, r, p)), trim_g(v, q, u, p))); - } - if (w == u || (xcoll(y, u, v) && (xpara(u, n3, n2, n4) || xpara(v, n3, n2, n4)))) - return (lratio_md1(v_a, y, u, v, - trim_g(u, p, r, q), trim_g(u, p, v, q), - trim_g(r, p, v, q), trim_g(u, p, v, q))); - return (pratio_md1(v_a, y, w, u, v, trim_g(w, p, r, q), trim_g(u, p, v, q))); - } - - ElTerm pe_g_ipt(Var v_a, int n1, int n2, int n3, int n4, int y, int w, int u, int v, int r, int p, int q) - { - int n; - ElTerm e1; - XTerm p1, p2; - Var v1; - -// int sn = 1; -// if (n2==y && n3==y) { n3 = n1; n1 = n2; sn = -1; } - - - if (xcoll(y, p, q) && n2 == y && n3 == y && n1 == r && n4 == r) - { - e1 = mk_elim(v_a, ptimes3(get_n(16L), trim_a(r, p, q, q), trim_a(r, p, q, q)), trim_g(p, q, q, p)); - return e1; - } - p1 = get_n(1L); - p2 = get_n(1L); - if (n1 == y && xperp(n2, n4, u, v)) - { - n1 = n2; - n2 = w; - n = n3; - n3 = n4; - n4 = n; - } else if (n2 == y && xperp(n1, n3, u, v)) - { - n2 = w; - } - if (n1 == y && xperp(n2, n4, u, v)) - { - n1 = n2; - n2 = w; - n = n3; - n3 = n4; - n4 = n; - } else if (n2 == y && xperp(n1, n3, u, v)) - { - n2 = w; - } - - if (n1 == y && xpara(n2, n4, p, q)) - { - n1 = n2; - n2 = r; - n = n3; - n3 = n4; - n4 = n; - } else if (n2 == y && xpara(n1, n3, p, q)) - { - n2 = r; - } - if (n1 == y && xpara(n2, n4, p, q)) - { - n1 = n2; - n2 = r; - n = n3; - n3 = n4; - n4 = n; - } else if (n2 == y && xpara(n1, n3, p, q)) - { - n2 = r; - } - - - if (n2 == y && xpara(n2, n4, u, v)) - { - n = n1; - n1 = n2; - n2 = n; - n = n3; - n3 = n4; - n4 = n; - } - if (n1 == y && xpara(n1, n3, u, v)) - { - p1 = ptimes(p1, trim_g(n3, p, r, q)); - p2 = ptimes(p2, trim_g(v, p, u, q)); - n1 = n2; - n3 = n4; - n2 = u; - n4 = v; - } - if (n1 == y && xpara(n1, n3, u, v)) - { - p1 = ptimes(p1, trim_g(n3, p, r, q)); - p2 = ptimes(p2, trim_g(v, p, u, q)); - n1 = n2; - n3 = n4; - n2 = u; - n4 = v; - } - - if (n2 == y && n3 == y) - { - if (xperp(n1, n3, p, q) && xperp(n2, n4, p, q)) - { - e1 = mk_elim(v_a, - ptimes4(get_n(-16L), trim_a(n3, u, w, v), trim_a(n4, u, w, v), trim_g(p, p, q, q)), - ptimes(trim_g(p, u, q, v), trim_g(p, u, q, v))); - } else - e1 = pratio_md2(v_a, y, w, u, v, trim_g(w, p, r, q), trim_g(u, p, v, q)); - } else if (n1 == y) - { - v1 = mk_var(3, n1, n2, n3, n4); - if (w == u || (xcoll(y, u, v) && (xpara(u, n3, n2, n4) || xpara(v, n3, n2, n4)))) - e1 = lratio_md1(v1, y, u, v, - trim_g(u, p, r, q), trim_g(u, p, v, q), - trim_g(r, p, v, q), trim_g(u, p, v, q)); - else - e1 = pratio_md1(v1, y, w, u, v, trim_g(w, p, r, q), trim_g(u, p, v, q)); - e1.v = v_a; - } else - { - e1 = mk_elim(v_a, trim_g(n1, n2, n3, n4), get_n(1L)); - } - e1.p1 = ptimes(e1.p1, p1); - e1.p2 = ptimes(e1.p2, p2); -// if (e1 && sn==-1) e1.p2 = neg_poly(e1.p2); - return (e1); - } - - ElTerm pe_v_ipc(Var v_a, int y, int w, int u, int v, int o, int p) - { - if (print_geo) gprint("\nCP " + " " + y + " " + w + " " + u + " " + v + " " + o + " " + p); - switch (v_a.nm) - { - case 1: - return (pe_r_ipc(v_a, v_a.pt[1], v_a.pt[0], v_a.pt[3], v_a.pt[2], y, w, u, v, o, p)); - case 2: - return (pe_a_ipc(v_a, v_a.pt[0], v_a.pt[1], v_a.pt[2], v_a.pt[3], y, w, u, v, o, p)); - case 3: - return (pe_g_ipc(v_a, v_a.pt[0], v_a.pt[1], v_a.pt[2], v_a.pt[3], y, w, u, v, o, p)); - case 4: - if (w == u) - return (lratio_md1(v_a, y, u, v, - ptimes(get_n(2L), trim_g(u, u, o, v)), trim_g(u, u, v, v), - pminus(trim_g(u, o, o, u), trim_g(v, o, o, v)), trim_g(u, u, v, v))); - return (pratio_md1(v_a, y, w, u, v, pplus(trim_g(w, u, o, v), trim_g(w, u, o, v)), trim_g(u, u, v, v))); - default: - gerror("pe_v_ipc: is not a proper variable.\n"); - } - return (null); - } - - ElTerm pe_r_ipc(Var v_a, int n1, int n2, int d1, int d2, int y, int w, int u, int v, int o, int p) - { - if (print_geo) gprint("\nr_icp: " + " " + y + " " + w + " " + u + " " + v + " " + o + " " + p); - if (w != p) gerror("pe_r_ipc"); - if (n2 == y && d2 == y) - { - if (xcoll(n1, w, y)) - return (mk_elim(v_a, - pplus(trim_g(n1, u, o, v), trim_g(w, u, o, v)), - pplus(trim_g(d1, u, o, v), trim_g(w, u, o, v)))); - else - return (mk_elim(v_a, trim_a(n1, u, w, v), trim_a(d1, u, w, v))); - } else if (n2 == y) - { - if (xcoll(n1, w, y)) - return (mk_elim(v_a, pplus(trim_g(n1, u, o, v), trim_g(w, u, o, v)), trim_g(d1, u, d2, v))); - else - return (mk_elim(v_a, trim_a(n1, u, w, v), trim_a(d1, u, d2, v))); - } else if (d2 == y) - { - return (rev_elim(pe_r_ipc(v_a, d1, d2, n1, n2, y, w, u, v, o, p))); - } else - exit(1); - return (null); - } - - ElTerm pe_a_ipc(Var v_a, int n1, int n2, int n3, int n4, int y, int w, int u, int v, int o, int p) - { - if (w != p) gerror("pe_r_ipc"); - - if (xpara(n2, n4, u, v)) - { - return (mk_elim(v_a, trim_a(w, n2, n3, n4), get_n(1L))); - } - - if (n3 == n4 && n2 == w) - { - n3 = n2; - } - if (n3 == w) - return (mk_elim(v_a, - ptimes3(get_n(2), trim_g(w, v, o, u), trim_a(u, n2, v, n4)), - trim_g(u, u, v, v))); - if (n3 == n4 && xpara(n1, n2, u, v)) - { - n3 = n2; - } - if (n1 == y && xpara(n1, n3, u, v)) - { - return (mk_elim(v_a, - ptimes(pminus(trim_g(n3, o, o, n3), trim_g(w, o, o, w)), trim_a(u, n2, v, n4)), - trim_g(u, n3, v, w))); - } - if (w == u) - return (lratio_md1(v_a, y, u, v, - ptimes(get_n(2L), trim_g(u, u, o, v)), trim_g(u, u, v, v), - pminus(trim_g(u, o, o, u), trim_g(v, o, o, v)), trim_g(u, u, v, v))); - return (pratio_md1(v_a, y, w, u, v, pplus(trim_g(w, u, o, v), trim_g(w, u, o, v)), trim_g(u, u, v, v))); - } - - - ElTerm pe_g_ipc(Var v_a, int n1, int n2, int n3, int n4, int y, int w, int u, int v, int o, int p) - { - int n; - Var v1; - ElTerm e1; - XTerm p1, p2; - ElTerm e; - -// int sn = 1; -// if (n2==y && n3==y) { n3 = n1; n1 = n2; sn = -1; } - - if (n2 == y && n3 == y && n1 == o && n4 == o) - { - e1 = mk_elim(v_a, trim_g(n3, p, p, n4), get_n(1L)); - return (e1); - } - - p1 = get_n(1L); - p2 = get_n(1L); - if (n1 == y && xperp(n2, n4, u, v)) - { - n1 = n2; - n2 = w; - n = n3; - n3 = n4; - n4 = n; - } else if (n2 == y && xperp(n1, n3, u, v)) - { - n2 = w; - } - if (n1 == y && xperp(n2, n4, u, v)) - { - n1 = n2; - n2 = w; - n = n3; - n3 = n4; - n4 = n; - } - - if (n2 == y && n4 == w) - { - n = n1; - n1 = n2; - n2 = n; - n = n3; - n3 = n4; - n4 = n; - } - if (n1 == y && n3 == w) - { - p1 = ptimes3(p1, get_n(2), trim_g(w, v, o, u)); - p2 = ptimes(p2, trim_g(u, u, v, v)); - n1 = n2; - n3 = n4; - n2 = u; - n4 = v; - } - if (n1 == y && n3 == w) - { - p1 = ptimes3(p1, get_n(2), trim_g(w, v, o, u)); - p2 = ptimes(p2, trim_g(u, u, v, v)); - n1 = n2; - n3 = n4; - n2 = u; - n4 = v; - } -/* if (n2 == y && xpara(n2,n4,u,v)) {n=n1;n1=n2;n2=n; n=n3;n3=n4;n4=n; } - if (n1 == y && xpara(n1,n3,u,v)) - { p1 = ptimes(p1,pminus(trim_g(n3,o,o,n3),trim_g(w,o,o,w))); - p2 = ptimes(p2,trim_g(u,n3,v,w)); - n1=n2;n3=n4;n2=u,n4=v; - } - if (n1 == y && xpara(n1,n3,u,v)) - { p1 = ptimes(p1,pminus(trim_g(n3,o,o,n3),trim_g(w,o,o,w))); - p2 = ptimes(p2,trim_g(u,n3,v,w)); - n1=n2;n3=n4;n2=u,n4=v; - } -*/ - if (n2 == y && n3 == y) - { - if (w == u) - e1 = lratio_md2(v_a, y, u, v, - ptimes(get_n(2L), trim_g(u, u, o, v)), trim_g(u, u, v, v), - pminus(trim_g(u, o, o, u), trim_g(v, o, o, v)), trim_g(u, u, v, v)); - else - e1 = pratio_md2(v_a, y, w, u, v, ptimes(get_n(2L), trim_g(w, u, o, v)), trim_g(u, u, v, v)); - } else if (n1 == y) - { - v1 = mk_var(3, n1, n2, n3, n4); - if (w == u) - e1 = lratio_md1(v1, y, u, v, - ptimes(get_n(2L), trim_g(u, u, o, v)), trim_g(u, u, v, v), - pminus(trim_g(u, o, o, u), trim_g(v, o, o, v)), trim_g(u, u, v, v)); - else - e1 = pratio_md1(v1, y, w, u, v, ptimes(get_n(2L), trim_g(w, u, o, v)), trim_g(u, u, v, v)); - e1.v = v_a; - } else - { - e1 = mk_elim(v_a, trim_g(n1, n2, n3, n4), get_n(1L)); - } - - e1.p1 = ptimes(e1.p1, p1); - e1.p2 = ptimes(e1.p2, p2); -// if (e1 && sn==-1) e1.p2 = neg_poly(e1.p2); - return (e1); - } - - - ElTerm pe_r_foot(Var v_a, int n1, int n2, int d1, int d2, int y, int p, int u, int v) - { - int n; - ElTerm e1 = null; - if (v < u) - { - n = u; - u = v; - v = n; - } - if (print_geo) gprint("pe_r_foot: " + " " + n1 + " " + n2 + " " + d1 + " " + d2 + " " + y + " " + p + " " + u + " " + v); - if (n2 == y) - { - if (xcoll(d2, u, v) && xperp(d1, d2, u, v)) - e1 = mk_elim(v_a, trim_a(n1, u, v, v), trim_a(d1, u, v, v)); - else if (d2 == y) - { - if (xcoll(n1, u, v)) - { - if (u > n1 && u > d1) - e1 = mk_elim(v_a, trim_g(n1, n1, p, d1), trim_g(d1, n1, p, d1)); - else - e1 = mk_elim(v_a, trim_g(n1, u, p, v), trim_g(d1, u, p, v)); - } else - e1 = mk_elim(v_a, trim_a(n1, u, v, v), trim_a(d1, u, v, v)); - } else if (xcoll(n1, u, v)) - { - e1 = mk_elim(v_a, trim_g(n1, u, p, v), trim_g(d1, u, d2, v)); - } else - { - e1 = mk_elim(v_a, trim_a(n1, u, v, v), trim_a(d1, u, d2, v)); - } - } else if (d2 == y) - { - e1 = rev_elim(pe_r_foot(v_a, d1, d2, n1, n2, y, p, u, v)); - } else - gerror("pe_r_foot"); - return (e1); - } - - ElTerm pe_a_foot(Var v_a, int n1, int n2, int n3, int n4, int y, int p, int u, int v) - { - int n; - if (v < u) - { - n = u; - u = v; - v = n; - } - if (xperp(n2, n4, u, v)) - { - return (mk_elim(v_a, trim_a(p, n2, n3, n4), get_n(1L))); - } - if (xpara(n2, n4, u, v)) - { - return (mk_elim(v_a, trim_a(u, n2, n3, n4), get_n(1L))); - } - if (n3 == n4 && xcoll(u, v, n2)) - { - n3 = n2; - } - if (xcoll(u, v, n3)) - { - return (mk_elim(v_a, ptimes(trim_a(u, n2, v, n4), trim_g(n3, u, p, v)), trim_g(v, u, u, v))); - } - return (lratio_md1(v_a, y, u, v, - trim_g(p, u, u, v), trim_g(u, v, v, u), - trim_g(p, v, v, u), trim_g(u, v, v, u))); - } - - ElTerm pe_g_foot(Var v_a, int n1, int n2, int n3, int n4, int y, int p, int u, int v) - { - int n; - Var v1; - ElTerm e1; - XTerm p1, p2; - -// int sn = 1; -// if (n2==y && n3==y) { n3 = n1; n1 = n2; sn = -1; } - - if (print_geo) gprint("pe_g_foot: " + " " + n1 + " " + n2 + " " + n3 + " " + n4 + " " + y + " " + p + " " + u + " " + v); - if (v < u) - { - n = u; - u = v; - v = n; - } - - if (n2 == y && n3 == y && n1 == p && n4 == p) - { - e1 = mk_elim(v_a, ptimes(get_n(-16L), ptimes(trim_a(p, u, v, v), trim_a(p, u, v, v))), - trim_g(u, u, v, v)); - return (e1); - } - - p1 = get_n(1L); - p2 = get_n(1L); - if (n1 == y && xperp(n2, n4, u, v)) - { - n1 = n2; - n2 = u; - n = n3; - n3 = n4; - n4 = n; - } else if (n2 == y && xperp(n1, n3, u, v)) - { - n2 = u; - } - if (n1 == y && xperp(n2, n4, u, v)) - { - n1 = n2; - n2 = u; - n = n3; - n3 = n4; - n4 = n; - } - if (n1 == y && xpara(n2, n4, u, v)) - { - n1 = n2; - n2 = p; - n = n3; - n3 = n4; - n4 = n; - } else if (n2 == y && xpara(n1, n3, u, v)) - { - n2 = p; - } - if (n1 == y && xpara(n2, n4, u, v)) - { - n1 = n2; - n2 = p; - n = n3; - n3 = n4; - n4 = n; - } - if (print_geo) gprint("pe_g_foot: " + " " + n1 + " " + n2 + " " + n3 + " " + n4 + " " + y + " " + p + " " + u + " " + v); - - if (n1 == y && xcoll(u, v, n3)) - { - p1 = ptimes(p1, trim_g(n3, v, p, u)); - p2 = ptimes(p2, trim_g(u, u, v, v)); - n1 = n2; - n3 = n4; - n2 = u; - n4 = v; - } - if (n1 == y && xcoll(u, v, n3)) - { - p1 = ptimes(p1, trim_g(n3, v, p, u)); - p2 = ptimes(p2, trim_g(u, u, v, v)); - n1 = n2; - n3 = n4; - n2 = u; - n4 = v; - } - - if (n2 == y && n3 == y) - { - e1 = lratio_md2(v_a, y, u, v, - trim_g(p, u, u, v), trim_g(u, v, v, u), - trim_g(p, v, v, u), trim_g(u, v, v, u)); - } else if (n1 == y) - { - v1 = mk_var(3, n1, n2, n3, n4); - e1 = lratio_md1(v1, y, u, v, - trim_g(p, u, u, v), trim_g(u, v, v, u), - trim_g(p, v, v, u), trim_g(u, v, v, u)); - e1.v = v_a; - } else - { - e1 = mk_elim(v_a, trim_g(n1, n2, n3, n4), get_n(1L)); - } - - e1.p1 = ptimes(e1.p1, p1); - e1.p2 = ptimes(e1.p2, p2); -// if(e1 && sn==-1) e1.p2 = neg_poly(e1.p2); - return (e1); - } - - - ////////////////////////////////////////////////elimm.cpp - XTerm trim_fa(int p1, int p2, int p3) -//int p1,p2,p3; - { - if (xcoll(p1, p2, p3)) return (pzero()); - if ((p1 == 3 && p2 == 2) || (p1 == 2 && p2 == 3)) return (trim_a(p1, p2, p3, p3)); - return (get_m(mk_var(-2, p1, p2, p3, p3))); - } - - XTerm fpt_a(int n1, int n2, int n3) -//int n1,n2,n3; - { - XTerm p1; - p1 = ptimes(trim_fa(n1, 2, 1), trim_fa(n2, 3, 1)); - p1 = pplus(p1, ptimes(trim_fa(n2, 2, 1), trim_fa(n3, 3, 1))); - p1 = pplus(p1, ptimes(trim_fa(n3, 2, 1), trim_fa(n1, 3, 1))); - p1 = pminus(p1, ptimes(trim_fa(n3, 2, 1), trim_fa(n2, 3, 1))); - p1 = pminus(p1, ptimes(trim_fa(n2, 2, 1), trim_fa(n1, 3, 1))); - p1 = pminus(p1, ptimes(trim_fa(n1, 2, 1), trim_fa(n3, 3, 1))); - return (p1); - } - - ElTerm pe_a_fpt(Var v_a, int n1, int n2, int n3, int n4) -//var v_a; -//int n1,n2,n3,n4; + /** + * Trims a ratio geometric term based on four point parameters. + * + * @param p1 the first point parameter + * @param p2 the second point parameter + * @param p3 the third point parameter + * @param p4 the fourth point parameter + * @return the trimmed ratio term as an XTerm + */ + XTerm trim_r(int p1, int p2, int p3, int p4) { - XTerm p0, p1, p2; - if (n3 == n4 && n3 == 1 && (n2 == 2 || n2 == 3)) + int p; + char sn = 1; + /* if (print_geo) printf("trim_r %d %d %d %d\r\n",p1,p2,p3,p4); */ + if (p1 == p2) return (pzero()); + if (p3 == p4) gerror("rtrim: denominator of ratio is zero.~%"); + if ((p1 == p3) && (p2 == p4)) return (get_n(1L)); + if ((p2 == p3) && (p1 == p4)) return (get_n(-1L)); + if (p1 < p2) { - return (mk_elim(v_a, get_m(mk_var(-2, n1, n2, n3, n4)), get_n(1L))); + sn *= (char) -1; + p = p1; + p1 = p2; + p2 = p; } - if (n3 == n4 && n2 == 3 && n3 == 2) + if (p3 < p4) { - p1 = pminus(trim_a(3, 2, 1, 1), trim_fa(n1, 2, 1)); - p1 = pplus(p1, trim_fa(n1, 3, 1)); - return (mk_elim(v_a, p1, get_n(1L))); + sn *= (char) -1; + p = p3; + p3 = p4; + p4 = p; } - - if (n3 == n4) - p1 = fpt_a(n1, n2, n3); - else - p1 = pplus(fpt_a(n1, n2, n3), fpt_a(n1, n3, n4)); - p0 = trim_a(1, 2, 3, 3); - p2 = pdiv(cp_poly(p1), p0); - if (p2 == null) return (mk_elim(v_a, p1, p0)); - put_p(p1); - put_p(p0); - return (mk_elim(v_a, p2, get_n(1L))); - } - - ElTerm pe_v_fpt(Var v, int pt) -//var v; -//int pt; - { - ElTerm e1 = null; - if (v.nm == 2) e1 = pe_a_fpt(v, v.pt[0], v.pt[1], v.pt[2], v.pt[3]); - return (e1); - } - - XTerm x(int n) - { - if (n == 1 || n == 2) return (get_n(0L)); - String s = "x_" + n; - return (get_m(mk_svar(s.toCharArray()))); - } - - XTerm y(int n) - { - if (n == 1) return (get_n(0L)); - String s = "y_" + n; - return (get_m(mk_svar(s.toCharArray()))); - } - - XTerm area_t(int n1, int n2, int n3) - { - return (pplus3(pminus(ptimes(x(n1), y(n2)), ptimes(x(n2), y(n1))), - pminus(ptimes(x(n2), y(n3)), ptimes(x(n3), y(n2))), - pminus(ptimes(x(n3), y(n1)), ptimes(x(n1), y(n3))))); - } - - XTerm area_q(int n1, int n2, int n3, int n4) - { - return (pplus(area_t(n1, n2, n3), area_t(n1, n3, n4))); - } - - XTerm dis_xy(int n1, int n2) -//int n1,n2; - { - if (n1 == n2) - return (get_n(0L)); + if (sn == 1) + return (get_m(mk_var(1, p1, p2, p3, p4))); else - return (pplus(ppower(pminus(x(n1), x(n2)), 2), ppower(pminus(y(n1), y(n2)), 2))); - } - - XTerm py_q(int n1, int n2, int n3, int n4) -//int n1,n2,n3,n4; - { - return (pminus(pplus(dis_xy(n1, n2), dis_xy(n3, n4)), - pplus(dis_xy(n2, n3), dis_xy(n4, n1)))); + return (neg_poly(get_m(mk_var(1, p1, p2, p3, p4)))); } - XTerm oarea(int p1, int p2, int p3) -//int p1,p2,p3; + /** + * Trims an angle geometric term based on four point parameters. + * + * @param p1 the first point parameter + * @param p2 the second point parameter + * @param p3 the third point parameter + * @param p4 the fourth point parameter + * @return the trimmed angle term as an XTerm + */ + XTerm trim_a(int p1, int p2, int p3, int p4) { - int n; - if (xcir2(p2, p1, p3)) - { - n = p1; - p1 = p2; - p2 = p3; - p3 = n; - } - if (xcir2(p3, p1, p2)) + int p; + char sn = 1; + if (xpara(p1, p3, p2, p4)) return (pzero()); + if (xcoll(p1, p2, p3)) { - n = p1; - p1 = p3; - p3 = p2; - p2 = n; - } - return (ptimes4(get_m(mk_svar("\\d".toCharArray())), get_m(mk_svar("\\d".toCharArray())), trim_s(p2, p3), trim_c(p2, p3))); - } - - XTerm opy(int p1, int p2, int p3) - { - if (p1 == p2) return (pzero()); - if (p3 == p2) return (pzero()); - if (xcir2(p1, p2, p3)) return (ptimes3(get_n(2L), trim_l(p2, p3), trim_l(p2, p3))); - if (xcir2(p3, p2, p1)) return (ptimes3(get_n(2L), trim_l(p2, p1), trim_l(p2, p1))); - return (pminus(ptimes(get_m(mk_svar("\\d".toCharArray())), get_m(mk_svar("\\d".toCharArray()))), - ptimes3(get_n(2L), trim_l(p1, p3), trim_l(p1, p3)))); - } - - ElTerm pe_circle(Var v_a, int p1, int p2, int p3, int p4) - { - int n; - if (v_a.nm == 2) + p2 = p1; + } else if (xcoll(p4, p2, p3)) { - if (xcir4(0, p1, p2, p3, p4)) - return (mk_elim(v_a, - pminus(ptimes3(trim_l(p1, p2), trim_l(p2, p4), trim_l(p4, p1)), - ptimes3(trim_l(p3, p2), trim_l(p2, p4), trim_l(p4, p3))), - ptimes(get_n(2L), get_m(mk_svar("\\d".toCharArray()))))); - else if (p1 == p2) - return (mk_elim(v_a, oarea(p1, p3, p4), get_n(4L))); - else if (xcir3(p1, p2, p3, p4) || xcir3(p3, p1, p2, p4)) - return (mk_elim(v_a, pplus(oarea(p1, p2, p3), oarea(p1, p3, p4)), get_n(4L))); - else - return (mk_elim(v_a, pplus(oarea(p2, p3, p4), oarea(p2, p4, p1)), get_n(4L))); - } - if (v_a.nm == 3) + p3 = p4; + } else if (xcoll(p4, p1, p3)) { - if (p3 == p4) - { - n = p1; - p1 = p3; - p3 = n; - n = p2; - p2 = p4; - p4 = n; - } - if (xcir4(0, p1, p2, p3, p4)) - return (mk_elim(v_a, - pminus(ptimes4(get_n(2L), trim_l(p2, p1), trim_l(p2, p4), trim_c(p1, p4)), - ptimes4(get_n(2L), trim_l(p2, p3), trim_l(p2, p4), trim_c(p3, p4))), - get_n(1L))); - else if (p2 == p3) - return (mk_elim(v_a, opy(p1, p2, p4), get_n(2L))); - else if (xcir3(p2, p1, p3, p4) || xcir3(p4, p1, p2, p3)) - return (mk_elim(v_a, pminus(opy(p1, p2, p4), opy(p3, p2, p4)), get_n(2L))); - else - return (mk_elim(v_a, pminus(opy(p2, p1, p3), opy(p4, p1, p3)), get_n(2L))); - } - gerror("pe_circle"); - return (null); - } - - XTerm sc(int n) -//int n; - { - if (n == 1) return (get_n(0L)); - return (get_m(mk_var(16, n, 0, 0, 0))); - } - - XTerm cc(int n) -//int n; - { - if (n == 1) return (get_n(1L)); - return (get_m(mk_var(17, n, 0, 0, 0))); - } - - ElTerm pe_sc(Var v_a, int p1, int p2) -//var v_a; -//int p1,p2; - { - if (v_a.nm == 6) + p4 = p3; + } else if (xcoll(p4, p2, p1)) { - return (mk_elim(v_a, pminus(ptimes(sc(p2), cc(p1)), ptimes(sc(p1), cc(p2))), get_n(1L))); + p1 = p4; } - if (v_a.nm == 7) + if (p1 < p3) { - return (mk_elim(v_a, pplus(ptimes(cc(p1), cc(p2)), ptimes(sc(p2), sc(p1))), get_n(1L))); + sn *= (char) -1; + p = p1; + p1 = p3; + p3 = p; } - gerror("pe_sc"); - return (null); - } - - - ElTerm pe_v_bline(Var v_a, int y, int u, int v) -//var v_a; -//int y,u,v; - { - int n; - if (u > v) + if (p2 < p4) { - n = u; - u = v; - v = n; + sn *= (char) -1; + p = p2; + p2 = p4; + p4 = p; } - if (v_a.nm == 3) - return (pe_g_3bline(v_a, v_a.pt[0], v_a.pt[1], v_a.pt[2], v_a.pt[3], y, u, v)); - gerror("11111111111"); - return (null); - } - - ElTerm pe_g_3bline(Var v_a, int n1, int n2, int n3, int n4, int y, int u, int v) - { - if (n1 == v) - { - return (mk_elim(v_a, get_m(mk_var(-3, n1, n2, n3, n4)), get_n(1L))); - } else if (n3 == y && n2 == y && n1 == u && n4 == u) - { - return (mk_elim(v_a, get_m(mk_var(-3, n1, n2, n3, n4)), get_n(1L))); - } else if (n3 == y && n2 == y && n1 == v && n4 == v) - { - return (mk_elim(v_a, get_m(mk_var(-3, n3, u, u, n2)), get_n(1L))); - } else if (n3 == y && n2 == y && n1 == v && n4 == u) - { - return (mk_elim(v_a, pplus(trim_g(v, u, u, v), - ptimes(get_n(2L), get_m(mk_var(-3, y, y, u, u)))), - get_n(-2L))); - } else if (n1 == y && n2 == v && n3 == u && n4 == u) + if (p1 < p2) { - return (mk_elim(v_a, trim_g(v, v, u, u), get_n(2L))); - } else if (n1 == y && n2 == v && n3 == v && n4 == u) + sn *= (char) -1; + p = p1; + p1 = p2; + p2 = p; + p = p3; + p3 = p4; + p4 = p; + } else if ((p1 == p2) && (p3 < p4)) { - return (mk_elim(v_a, trim_g(v, u, u, v), get_n(2L))); + sn *= (char) -1; + p = p3; + p3 = p4; + p4 = p; } - gerror("pe_g_3bline"); - return (null); - } - ElTerm pe_v_square(Var v_a, int p1, int p2, int p3, int sn) -//var v_a; -//int p1,p2,p3,sn; - { - if (v_a.nm != 4) return (pe_v_tratio(v_a, p1, p2, p2, p3, get_n(1L * sn), get_n(1L))); - if (v_a.pt[1] == 0) + if (p1 == p2) { - return (mk_elim(v_a, - pplus(trim_vec(p2, 0), - ptimes3(get_n(1L * sn), get_s("i".toCharArray()), trim_vec(p3, p2))), - get_n(1L))); - } else + p2 = p3; + p3 = p4; + } else if (p2 == p3) { - return (mk_elim(v_a, - pplus(trim_vec(p2, v_a.pt[1]), - ptimes3(get_n(1L * sn), get_s("i".toCharArray()), trim_vec(p3, p2))), - get_n(1L))); + p3 = p4; } - } - ElTerm pe_v_ptri(Var v_a, int p1, int p2, int p3) -//var v_a; -//int p1,p2,p3; - { - if (v_a.pt[1] == 0) - { - return (mk_elim(v_a, - pplus(ptimes3(get_n(-1L), get_s("w".toCharArray()), trim_vec(p2, 0)), - ptimes4(get_n(-1L), get_s("w".toCharArray()), get_s("w".toCharArray()), trim_vec(p3, 0))), - get_n(1L))); - } else - { - return (mk_elim(v_a, - pplus3(ptimes3(get_n(-1L), get_s("w".toCharArray()), trim_vec(p2, 0)), - ptimes4(get_n(-1L), get_s("w".toCharArray()), get_s("w".toCharArray()), trim_vec(p3, 0)), - ptimes(get_n(-1L), trim_vec(v_a.pt[1], 0))), - get_n(1L))); - } + if (sn == 1) + return (get_m(mk_var(2, p1, p2, p3, p4))); + else + return (neg_poly(get_m(mk_var(2, p1, p2, p3, p4)))); } - ElTerm pe_v_ntri(Var v_a, int p1, int p2, int p3) -//var v_a; -//int p1,p2,p3; + /** + * Trims a geometric term based on perpendicularity constraints. + * + * @param p1 the first point parameter + * @param p2 the second point parameter + * @param p3 the third point parameter + * @param p4 the fourth point parameter + * @return the trimmed geometric term as an XTerm + */ + XTerm trim_g(int p1, int p2, int p3, int p4) { - if (v_a.nm != 4) + int p; + char sn = 1; + /* if (print_geo) printf("\r\ntrim_g %d %d %d %d\r\n",p1,p2,p3,p4); */ + if (xperp(p1, p3, p2, p4)) return (get_n(0L)); + if (p1 < p3) { - gerror("pe_ntri"); + sn *= (char) -1; + p = p1; + p1 = p3; + p3 = p; } - if (v_a.pt[1] == 0) - { - return (mk_elim(v_a, - pplus(ptimes3(get_n(-1L), get_s("w".toCharArray()), trim_vec(p3, 0)), - ptimes4(get_n(-1L), get_s("w".toCharArray()), get_s("w".toCharArray()), trim_vec(p2, 0))), - get_n(1L))); - } else + if (p2 < p4) { - return (mk_elim(v_a, - pplus3(ptimes3(get_n(-1L), get_s("w".toCharArray()), trim_vec(p3, 0)), - ptimes4(get_n(-1L), get_s("w".toCharArray()), get_s("w".toCharArray()), trim_vec(p2, 0)), - ptimes(get_n(-1L), trim_vec(v_a.pt[1], 0))), - get_n(1L))); + sn *= (char) -1; + p = p2; + p2 = p4; + p4 = p; } - } - - ElTerm pe_v_sim(Var v_a, int p1, int p2, int p3, int q1, int q2, int q3) -//var v_a; -//int p1,p2,p3,q1,q2,q3; - { - if (v_a.nm != 4) gerror("pe_v_sim"); - if (v_a.pt[1] == 0) + if (p1 < p2) { - return (mk_elim(v_a, - pplus(ptimes(trim_vec(p2, 0), trim_vec(q2, q3)), - ptimes(trim_vec(q2, q1), trim_vec(p2, p3))), - trim_vec(q2, q3))); - } else + p = p1; + p1 = p2; + p2 = p; + p = p3; + p3 = p4; + p4 = p; + } else if ((p1 == p2) && (p3 < p4)) { - return (mk_elim(v_a, - pplus3(ptimes3(get_n(-1L), trim_vec(q2, q3), trim_vec(v_a.pt[1], 0)), - ptimes(trim_vec(p2, 0), trim_vec(q2, q3)), - ptimes(trim_vec(q1, q2), trim_vec(p2, p3))), - trim_vec(q2, q3))); + p = p3; + p3 = p4; + p4 = p; } - } - - /////////////////////////////////////////////////////////////////////////elima.cpp - ElTerm radius_e = new ElTerm(); - - ElTerm rcir(int a, int b, int c) - { - radius_e.v = mk_svar("x".toCharArray()); - radius_e.p1 = ptimes3(trim_g(a, b, b, a), trim_g(a, c, c, a), trim_g(b, c, c, b)); - radius_e.p2 = ptimes3(get_n(64L), trim_a(a, b, c, c), trim_a(a, b, c, c)); - return (radius_e); - } - - ElTerm pe_v_cent(Var v_a, int y, int a, int b, int c) - { - int n; - XTerm p; - if (v_a.nm == 2 || - (v_a.nm == 3 && v_a.pt[0] == y && v_a.pt[1] != y) || - v_a.nm == 4) - { - return (mk_elim(v_a, pplus(geval(v_a, y, a), - pplus(geval(v_a, y, b), geval(v_a, y, c))), get_n(3L))); - } else if (v_a.nm == 3 && v_a.pt[1] == y && v_a.pt[2] == y) + if (p1 == p2) { - p = pplus(geval(v_a, y, a), pplus(geval(v_a, y, b), geval(v_a, y, c))); - p = ptimes(get_n(3L), p); - p = pplus(p, pplus3(trim_g(a, a, b, b), trim_g(a, a, c, c), trim_g(b, b, c, c))); - return (mk_elim(v_a, p, get_n(9L))); - } else if (v_a.nm == 1) + sn *= (char) -1; + p1 = p3; + p3 = p2; + } else if (p3 == p4) { - if (v_a.pt[0] == y && v_a.pt[2] == y) - { - if (xcoll(c, y, v_a.pt[1])) - { - n = c; - c = b; - b = n; - } - if (xcoll(c, y, v_a.pt[1])) - { - n = c; - c = a; - a = n; - } - return (mk_elim(v_a, - pplus(trim_a(a, a, c, v_a.pt[1]), trim_a(b, b, c, v_a.pt[1])), - pplus(trim_a(a, a, c, v_a.pt[3]), trim_a(b, b, c, v_a.pt[3])))); - } else if (v_a.pt[0] == y) - { - return (mk_elim(v_a, - pplus(trim_a(a, a, c, v_a.pt[1]), trim_a(b, b, c, v_a.pt[1])), - ptimes(get_n(3L), trim_a(c, c, v_a.pt[2], v_a.pt[3])))); - } else if (v_a.pt[2] == y) - { - return (mk_elim(v_a, - ptimes(get_n(3L), trim_a(c, c, v_a.pt[0], v_a.pt[1])), - pplus(trim_a(a, a, c, v_a.pt[3]), trim_a(b, b, c, v_a.pt[3])))); - } + sn *= (char) -1; + p4 = p2; + p2 = p3; } - gerror("pe_v_cent"); - return (null); - } - - - ElTerm orth_md(Var v_a, int y, int a, int b, int c) - { - return (mk_elim(v_a, - pplus3(ptimes3(geval(v_a, y, a), trim_g(a, b, b, c), trim_g(a, c, c, b)), - ptimes3(geval(v_a, y, b), trim_g(b, a, a, c), trim_g(b, c, c, a)), - ptimes3(geval(v_a, y, c), trim_g(c, a, a, b), trim_g(c, b, b, a))), - ptimes3(get_n(16L), trim_a(a, b, c, c), trim_a(a, b, c, c)))); - } - -/* -el_term *pe_r_orth (v_a,n1,n2,n3,n4,y,a,b,c) -var *v_a; -int n1,n2,n3,n4,y,a,b,c; -{ gerror("pe_r_orth"); return(null);} - -*/ - - ElTerm pe_a_orth(Var v_a, int n1, int n2, int n3, int n4, int y, int a, int b, int c) -//var v_a; -//int n1,n2,n3,n4,y,a,b,c; - { - if (n1 != y) gerror("pe_a_orth"); - if (xperp(n2, n4, a, b)) - return (mk_elim(v_a, trim_a(c, n2, n3, n4), get_n(1L))); - else if (xperp(n2, n4, a, c)) - return (mk_elim(v_a, trim_a(b, n2, n3, n4), get_n(1L))); - else if (xperp(n2, n4, b, c)) - return (mk_elim(v_a, trim_a(a, n2, n3, n4), get_n(1L))); + //The largest index is either p1 or p2 + if (sn == 1) + return (get_m(mk_var(3, p1, p2, p3, p4))); else - return (orth_md(v_a, y, a, b, c)); - } - - ElTerm pe_g_orth(Var v_a, int n1, int n2, int n3, int n4, int y, int a, int b, int c) - { - ElTerm e1, rr; - int n; - XTerm r1, r2, r3, r4; - - e1 = null; - if (n1 == y && n2 != y) - { - if (xpara(n2, n4, a, b)) - e1 = mk_elim(v_a, trim_g(c, n2, n3, n4), get_n(1L)); - else if (xpara(n2, n4, a, c)) - e1 = mk_elim(v_a, trim_g(b, n2, n3, n4), get_n(1L)); - else if (xpara(n2, n4, b, c)) - e1 = mk_elim(v_a, trim_g(a, n2, n3, n4), get_n(1L)); - else - e1 = orth_md(v_a, y, a, b, c); - } else if (n2 == y && n3 == y) - { - if (n1 == n4 && (n1 == a || n1 == b || n1 == c)) - { - if (n1 == b) - { - n = a; - a = b; - b = n; - } - if (n1 == c) - { - n = a; - a = c; - c = n; - } - e1 = mk_elim(v_a, - ptimes3(trim_g(b, b, c, c), trim_g(b, a, a, c), trim_g(b, a, a, c)), - ptimes3(get_n(-16L), trim_a(a, b, c, c), trim_a(a, b, c, c))); - } else if (n1 == n4 && xcir3(n1, a, b, c)) - { - rr = rcir(a, b, c); - e1 = mk_elim(v_a, - pplus4(ptimes(get_n(9L), rr.p1), - ptimes(trim_g(a, a, b, b), cp_poly(rr.p2)), - ptimes(trim_g(b, b, c, c), cp_poly(rr.p2)), - ptimes(trim_g(a, a, c, c), cp_poly(rr.p2))), - rr.p2); - } else if ((n1 == a || n1 == b || n1 == c) && (n4 == a || n4 == b || n4 == c)) - { - e1 = mk_elim(v_a, - ptimes3(trim_g(a, b, b, c), trim_g(a, c, c, b), trim_g(b, a, a, c)), - ptimes3(get_n(-16L), trim_a(a, b, c, c), trim_a(a, b, c, c))); - } else - { - r1 = ptimes(trim_g(c, b, b, a), trim_g(c, a, a, b)); - r2 = ptimes(trim_g(b, a, a, c), trim_g(b, c, c, a)); - r3 = ptimes(trim_g(a, b, b, c), trim_g(a, c, c, b)); - r4 = ptimes3(get_n(16L), trim_a(a, b, c, c), trim_a(a, b, c, c)); - e1 = mk_elim(v_a, pplus(pplus3(ptimes3(cp_poly(r1), cp_poly(r3), trim_g(a, a, c, c)), - ptimes3(cp_poly(r2), cp_poly(r3), trim_g(a, a, b, b)), - ptimes3(cp_poly(r1), cp_poly(r2), trim_g(b, b, c, c))), - pplus3(ptimes3(cp_poly(r1), cp_poly(r4), trim_g(n1, c, c, n4)), - ptimes3(cp_poly(r2), cp_poly(r4), trim_g(n1, b, b, n4)), - ptimes3(cp_poly(r3), cp_poly(r4), trim_g(n1, a, a, n4)))), - ptimes(cp_poly(r4), cp_poly(r4))); - } - } else - gerror("pe_g_orth"); - return (e1); - } - - - ElTerm circum_md(Var v_a, int y, int a, int b, int c) - { - return (mk_elim(v_a, - pplus3(ptimes3(geval(v_a, y, a), trim_g(b, c, c, b), trim_g(b, a, a, c)), - ptimes3(geval(v_a, y, b), trim_g(a, c, c, a), trim_g(a, b, b, c)), - ptimes3(geval(v_a, y, c), trim_g(a, b, b, a), trim_g(a, c, c, b))), - ptimes3(get_n(32L), trim_a(a, b, c, c), trim_a(a, b, c, c)))); + return (neg_poly(get_m(mk_var(3, p1, p2, p3, p4)))); } - ElTerm pe_a_circum(Var v_a, int n1, int n2, int n3, int n4, int y, int a, int b, int c) + /** + * Trims a geometric term based on four point parameters, typically representing line intersections. + * + * @param p1 the first point parameter + * @param p2 the second point parameter + * @param p3 the third point parameter + * @param p4 the fourth point parameter + * @return the trimmed term as an XTerm + */ + XTerm trim_f(int p1, int p2, int p3, int p4) { - int n; - if (xperp(n2, n4, b, c)) - { - n = a; - a = c; - c = n; - } - if (xperp(n2, n4, a, c)) + int p; + char sn = 1; + if (xcoll4(p1, p2, p3, p4)) return (pzero()); + if (p1 < p2) { - n = b; - b = c; - c = n; + p = p1; + p1 = p2; + p2 = p; } - if (xperp(n2, n4, a, b)) - return (mk_elim(v_a, pplus(trim_a(a, n2, n3, n4), trim_a(b, n2, n3, n4)), get_n(2L))); - if (n3 == n4 && (xcir5(y, n2, n3, a, b, c))) + if (p3 < p4) { - if (a != n2 && a != n3) - n = a; - else if (b != n2 && b != n3) - n = b; - else - n = c; - return (mk_elim(v_a, - ptimes(trim_g(n2, n3, n3, n2), trim_g(n2, n, n, n3)), - ptimes(get_n(32L), trim_a(n, n2, n3, n4)))); + p = p3; + p3 = p4; + p4 = p; } - return (circum_md(v_a, y, a, b, c)); - } - - ElTerm pe_g_circum(Var v_a, int n1, int n2, int n3, int n4, int y, int a, int b, int c) - { - ElTerm e1; - XTerm r1, r2, r3, r4; - - e1 = null; - if (n1 == y && n2 != y) - { - if (xcir2(y, n2, n4)) - { - e1 = mk_elim(v_a, pplus(trim_g(n2, n2, n3, n4), trim_g(n4, n2, n3, n4)), get_n(2L)); - } else - e1 = circum_md(v_a, y, a, b, c); - } else if (n2 == y && n3 == y) - { - if (n1 == n4 && xcir4(y, n1, a, b, c)) - { - e1 = rcir(a, b, c); - e1 = mk_elim(v_a, e1.p1, e1.p2); - } else if (xcir5(y, n1, n4, a, b, c)) - { - r1 = ptimes3(trim_g(a, b, b, a), trim_g(a, c, c, a), trim_g(b, c, c, b)); - r2 = ptimes3(get_n(64L), trim_a(a, b, c, c), trim_a(a, b, c, c)); - e1 = mk_elim(v_a, - pplus(ptimes(get_n(2L), r1), - ptimes(trim_g(n1, n1, n4, n4), r2)), - ptimes(get_n(2L), cp_poly(r2))); - } else - { - r1 = ptimes(trim_g(a, b, b, a), trim_g(a, c, c, b)); - r2 = ptimes(trim_g(a, c, c, a), trim_g(a, b, b, c)); - r3 = ptimes(trim_g(b, c, c, b), trim_g(b, a, a, c)); - r4 = ptimes3(get_n(32L), trim_a(a, b, c, c), trim_a(a, b, c, c)); - e1 = mk_elim(v_a, - pplus(pplus3(ptimes3(cp_poly(r1), cp_poly(r3), trim_g(a, a, c, c)), - ptimes3(cp_poly(r2), cp_poly(r3), trim_g(a, a, b, b)), - ptimes3(cp_poly(r1), cp_poly(r2), trim_g(b, b, c, c))), - pplus3(ptimes3(cp_poly(r1), cp_poly(r4), trim_g(n3, c, c, n4)), - ptimes3(cp_poly(r2), cp_poly(r4), trim_g(n3, b, b, n4)), - ptimes3(cp_poly(r3), cp_poly(r4), trim_g(n3, a, a, n4)))), - ptimes(cp_poly(r4), cp_poly(r4))); - } - } else - gerror("pe-g-circum2"); - return (e1); - } - - - ElTerm pe_r_circum(Var v_a, int n1, int n2, int d1, int d2, int y, int a, int b, int c) - { - int a1 = 0, b1 = 0, c1 = 0; - if (a == n1 || a == n2 || a == d1 || a == d2) a1 = a; - if (b == n1 || b == n2 || b == d1 || b == d2) b1 = b; - if (c == n1 || c == n2 || c == d1 || c == d2) c1 = c; - if (c1 != 0 && !(a1 != 0)) - { - a1 = c; - b1 = b; - } else if (c1 != 0 && !(b1 != 0)) + if (p1 < p3) { - a1 = c; - b1 = a; - } else + sn *= (char) -1; + p = p1; + p1 = p3; + p3 = p; + p = p2; + p2 = p4; + p4 = p; + } else if ((p1 == p3) && (p2 < p4)) { - a1 = a; - b1 = b; + sn *= (char) -1; + p = p2; + p2 = p4; + p4 = p; } - - - if (n2 == y) - { - if (d2 == y) - return (mk_elim(v_a, - pplus(trim_g(n1, a1, a1, b1), trim_g(n1, a1, b1, b1)), - pplus(trim_g(d1, a1, a1, b1), trim_g(d1, a1, b1, b1)))); - else - return (mk_elim(v_a, - pplus(trim_g(n1, a1, a1, b1), trim_g(n1, a1, b1, b1)), - ptimes(get_n(2L), trim_g(d1, a1, d2, b1)))); - } else if (d2 == y) - return (rev_elim(pe_r_circum(v_a, d1, d2, n1, n2, y, a, b, c))); + if (sn == 1) + return (get_m(mk_var(10, p1, p2, p3, p4))); else - gerror("pe-r-circum1"); - return (null); - } - - - ElTerm incent_md(Var v_a, int y, int i, int a, int b) - { - return (mk_elim(v_a, - pplus3(ptimes4(get_n(-2L), geval(v_a, y, i), trim_g(i, a, a, b), trim_g(i, b, b, a)), - ptimes3(geval(v_a, y, a), trim_g(i, a, a, b), trim_g(b, i, i, b)), - ptimes3(geval(v_a, y, b), trim_g(i, b, b, a), trim_g(a, i, i, a))), - ptimes(trim_g(a, i, i, b), trim_g(a, b, b, a)))); - } - - ElTerm pe_a_incent(Var v_a, int n1, int n2, int n3, int n4, int y, int i, int a, int b) - { - return (incent_md(v_a, y, i, a, b)); + return (neg_poly(get_m(mk_var(10, p1, p2, p3, p4)))); } - ElTerm pe_g_incent(Var v_a, int n1, int n2, int n3, int n4, int y, int i, int a, int b) + /** + * Trims a geometric term derived from two lines. + * + * @param l1 the first line + * @param l2 the second line + * @return the trimmed term as an XTerm + */ + XTerm trim_fl(LLine l1, LLine l2) { - ElTerm e1; - int n, sn; - XTerm r1, r2, r3, r4, r5, r6, ar; - e1 = null; - sn = 1; - if (n1 == y && n2 != y) - { - if (n3 == n4) - { - n = n2; - n2 = n4; - n4 = n; - sn = -1; - } - if (n2 == n3 && n4 == b) - { - n = a; - a = b; - b = n; - } - if (n2 == n3 && n2 == i && n4 == a) - { - e1 = mk_elim(v_a, - ptimes4(get_n(16L), trim_g(i, a, a, i), trim_a(i, a, a, b), trim_a(i, a, a, b)), - ptimes(trim_g(a, b, b, a), trim_g(a, i, i, b))); - if (sn == -1) e1.p1 = neg_poly(e1.p1); - } else - e1 = incent_md(v_a, y, i, a, b); - } else if (n2 == y && n3 == y) - { - r1 = trim_g(i, a, a, b); - r2 = trim_g(i, b, b, a); - r3 = trim_g(a, i, i, b); - r4 = trim_g(i, a, a, i); - r5 = trim_g(i, b, b, i); - r6 = trim_g(a, b, b, a); - ar = trim_a(a, i, i, b); - if (n1 == i && n4 == i) - { - e1 = mk_elim(v_a, - ptimes4(ptimes(get_n(16L), r4), r5, ar, cp_poly(ar)), - ptimes3(r3, cp_poly(r3), r6)); - put_p(r1); - put_p(r2); - } else if (n1 == a && n4 == a) - { - e1 = mk_elim(v_a, ptimes4(r4, cp_poly(r4), r2, cp_poly(r2)), - ptimes4(get_n(1L), r6, r3, cp_poly(r3))); - put_p(r1); - put_p(r5); - } else if (n1 == b && n4 == b) - { - e1 = mk_elim(v_a, ptimes4(r5, cp_poly(r5), r1, cp_poly(r1)), - ptimes4(get_n(1L), r6, r3, cp_poly(r3))); - put_p(r2); - put_p(r4); - } else if ((n1 == a && n4 == b) || (n1 == b && n4 == a)) - { - e1 = mk_elim(v_a, - ptimes3(r1, r2, pminus(ptimes(r4, r5), ptimes3(get_n(2L), r3, cp_poly(r3)))), - ptimes3(cp_poly(r3), cp_poly(r3), r6)); - } else if ((n1 == a && n4 == i) || (n1 == i && n4 == a)) - { - e1 = mk_elim(v_a, ptimes4(ptimes(get_n(-16L), r4), r2, ar, cp_poly(ar)), - ptimes3(r6, r3, cp_poly(r3))); - put_p(r1); - put_p(r5); - } else if ((n1 == b && n4 == i) || (n1 == i && n4 == b)) - { - e1 = mk_elim(v_a, ptimes4(ptimes(get_n(16L), r5), r1, ar, cp_poly(ar)), - ptimes3(r6, r3, cp_poly(r3))); - put_p(r2); - put_p(r4); - } else - { - e1 = mk_elim(v_a, - pminus(pplus3(ptimes(ptimes3(get_n(-2L), r1, r2), - ptimes3(cp_poly(r1), r5, trim_g(a, i, i, a))), - ptimes(ptimes3(cp_poly(r1), cp_poly(r5), cp_poly(r2)), - ptimes(r4, trim_g(a, b, b, a))), - ptimes(ptimes3(get_n(-2L), cp_poly(r1), cp_poly(r2)), - ptimes3(cp_poly(r2), cp_poly(r4), trim_g(b, i, i, b)))), - pplus3(ptimes(ptimes3(get_n(-2L), cp_poly(r1), cp_poly(r2)), - ptimes3(r3, r6, trim_g(n1, i, i, n1))), /* check trig_g */ - ptimes(ptimes3(cp_poly(r1), cp_poly(r5), cp_poly(r3)), - ptimes(cp_poly(r6), trim_g(n1, a, a, n1))), - ptimes(ptimes3(cp_poly(r2), cp_poly(r4), cp_poly(r3)), - ptimes(cp_poly(r6), trim_g(n1, b, b, n1))))), - ptimes4(cp_poly(r3), cp_poly(r3), cp_poly(r6), cp_poly(r6))); - e1.p1 = neg_poly(e1.p1); - } - } else - gerror("pe-g-incent2"); - - return (e1); + if (l1 == l2) return (pzero()); + return (trim_f(l1.pt[0], l1.pt[1], l2.pt[0], l2.pt[1])); } - - ElTerm pe_r_incent(Var v_a, int n1, int n2, int d1, int d2, int y, int i, int a, int b) + /** + * Trims a geometric term representing a vector. + * + * @param p1 the first point parameter + * @param p2 the second point parameter + * @return the trimmed vector term as an XTerm + */ + XTerm trim_vec(int p1, int p2) { - if (n2 == y && d2 == y) - { - return (mk_elim(v_a, - pminus(ptimes(get_n(2L), trim_g(n1, a, a, b)), trim_g(a, b, b, a)), - pminus(ptimes(get_n(2L), trim_g(d1, a, a, b)), trim_g(a, b, b, a)))); - } else if (n2 == y) - { - return (mk_elim(v_a, - pminus(ptimes(get_n(2L), trim_g(n1, a, a, b)), trim_g(a, b, b, a)), - trim_g(d1, a, d2, b))); - } else if (d2 == y) + if (p2 == 0) { - return (rev_elim(pe_r_incent(v_a, d1, d2, n1, n2, y, i, a, b))); - } else - gerror("pe_r_incenter"); - return (null); + return (get_m(mk_var(4, p1, 0, 0, 0))); + } + if (p1 == p2) return (pzero()); + if (p1 < p2) return (neg_poly(get_m(mk_var(4, p2, p1, 0, 0)))); + return (get_m(mk_var(4, p1, p2, 0, 0))); } } diff --git a/src/main/java/gprover/Full.java b/src/main/java/gprover/Full.java index 27363bc5..5e19b4dc 100644 --- a/src/main/java/gprover/Full.java +++ b/src/main/java/gprover/Full.java @@ -3,6 +3,9 @@ import java.util.Vector; +/** + * Implements full angle proof processes and geometric elimination. + */ public class Full extends Elim { int max_term; @@ -14,11 +17,16 @@ public class Full extends Elim { XTerm conc_p1, conc_p2; boolean print_conc = false; - + /** + * Constructs a new Full object. + */ public Full() { P_STATUS = 0; } + /** + * Proves the geometric configuration using full elimination logic. + */ void prove_full() { GrTerm gr1; DTerm ps1; @@ -35,7 +43,7 @@ void prove_full() { dbase(); fconc(); if (qerror) return; - boolean first = true; + boolean first = true; do { co_db.nx = null; @@ -99,6 +107,9 @@ void prove_full() { print_fend(); } + /** + * Initializes the geometric database by searching for midpoints, lines, circles, and angles. + */ void dbase() { MidPt md; PLine pn; @@ -127,15 +138,27 @@ void dbase() { } } + /** + * Checks if the provided term is non-polynomial. + * + * @param p the term to check. + * @return true if the term has no associated variable; false otherwise. + */ boolean npoly(XTerm p) { return (p.var == null); } + /** + * Prints terminal details based on the print_conc flag. + */ void print_t() { if (print_conc) gprint(Cm.s2300); } + /** + * Prints the final conclusion of the proof. + */ void print_fend() { DTerm ps1; XTerm p1; @@ -148,6 +171,14 @@ else if (print_conc) { } } + /** + * Constructs and links a new geometric term in the proof chain. + * + * @param c1 the first constant. + * @param p1 the first term. + * @param c2 the second constant. + * @param p2 the second term. + */ void conc_gr(long c1, XTerm p1, long c2, XTerm p2) { if (p1 != null && p1.getPV() < 0) p1 = this.neg_poly(p1); @@ -158,10 +189,18 @@ void conc_gr(long c1, XTerm p1, long c2, XTerm p2) { last_pr = gr; } + /** + * Executes the default full angle concatenation process. + */ void fconc() { fconc(conc); } + /** + * Executes the full angle concatenation based on the provided condition. + * + * @param conc the condition with the predicate and associated parameters. + */ void fconc(Cond conc) { switch (conc.pred) { case CO_COLL: @@ -199,13 +238,11 @@ void fconc(Cond conc) { /* constants8 */ conc_gr(1L, pminus(conc_p1, conc_p2), 0L, null); break; - case CO_PBISECT: conc_gr(1L, pminus(trim_f(conc.p[0], conc.p[1], conc.p[1], conc.p[2]), - trim_f(conc.p[1], conc.p[2], conc.p[2], conc.p[0])), + trim_f(conc.p[1], conc.p[2], conc.p[2], conc.p[0])), 0L, null); break; - case CO_CONG: fconc_cong(conc.p[0], conc.p[1], conc.p[2], conc.p[3]); break; @@ -218,10 +255,22 @@ void fconc(Cond conc) { } } + /** + * Returns the error type encountered during proof processing. + * + * @return the error type code. + */ public int getErrorType() { return ertype; } + /** + * Processes the collinearity condition for full angle concatenation. + * + * @param a first geometric parameter. + * @param b second geometric parameter. + * @param c third geometric parameter. + */ public void fconc_coll(int a, int b, int c) { if (a < b) { int k = a; @@ -236,6 +285,15 @@ public void fconc_coll(int a, int b, int c) { conc_gr(1L, trim_f(a, b, a, c), 0L, null); } + /** + * Processes the congruence condition for full angle concatenation. + * + * @param a first geometric parameter. + * @param b second geometric parameter. + * @param c third geometric parameter. + * @param d fourth geometric parameter. + * @return true if the congruence condition was successfully processed; false otherwise. + */ public boolean fconc_cong(int a, int b, int c, int d) { int l, m, n; if (a == c) { @@ -258,13 +316,19 @@ public boolean fconc_cong(int a, int b, int c, int d) { conc_gr(1L, null, 1L, null); return false; } - conc_gr(1L, pminus(trim_f(l, m, m, n), trim_f(m, n, n, l)), 0L, null); return true; } - //////////////////////////////////////////////////////////////////////////////////////////////// - + /** + * Constructs an elimination term using a variable and two XTerm operands. + * Reorders the variable if necessary and computes the metric. + * + * @param v the variable + * @param p1 the first XTerm operand + * @param p2 the second XTerm operand + * @return the constructed elimination term + */ ElTerm mk_felim(Var v, XTerm p1, XTerm p2) { ElTerm e1 = new ElTerm(); if (this.var_reOrder(v)) { @@ -279,6 +343,17 @@ ElTerm mk_felim(Var v, XTerm p1, XTerm p2) { return (e1); } + /** + * Constructs an elimination term using a variable and two XTerm operands, + * and scales the resulting term by a factor if necessary. + * + * @param v the variable + * @param p1 the first XTerm operand + * @param p2 the second XTerm operand + * @param n the scaling factor; if not 1, the term is multiplied by this factor + * @param t the elimination type + * @return the scaled elimination term + */ ElTerm mk_felim(Var v, XTerm p1, XTerm p2, int n, int t) { ElTerm e = mk_felim(v, p1, p2, t); if (n != 1) @@ -286,54 +361,30 @@ ElTerm mk_felim(Var v, XTerm p1, XTerm p2, int n, int t) { return e; } - + /** + * Constructs an elimination term using a variable and two XTerm operands, + * and sets its elimination type. + * + * @param v the variable + * @param p1 the first XTerm operand + * @param p2 the second XTerm operand + * @param t the elimination type to set + * @return the elimination term with the specified type + */ ElTerm mk_felim(Var v, XTerm p1, XTerm p2, int t) { ElTerm el = mk_felim(v, p1, p2); el.etype = t; return el; } - ElTerm mk_feliminator(Var v, XTerm p1, XTerm p2, int t) { - ElTerm e1 = new ElTerm(); - e1.etype = t; - e1.v = v; - e1.p1 = p1; - e1.p2 = p2; - e1.p = get_m(v); - e1.co = co_db.nx; - return (e1); - } - - ElTerm elim_qcs(XTerm p) { // NO USAGE. - Var v1 = p.var; - LLine ln1 = fadd_ln(v1.pt[0], v1.pt[1]); - LLine ln2 = fadd_ln(v1.pt[2], v1.pt[3]); - - co_db.nx = null; - int p1, p2, p3, p4; - p1 = v1.pt[0]; - p2 = v1.pt[1]; - p3 = v1.pt[2]; - p4 = v1.pt[3]; - boolean t = false; - if (ln1.pt[0] < v1.pt[0] && ln1.pt[1] < v1.pt[0]) { - add_codb(CO_COLL, ln1.pt[0], ln1.pt[1], v1.pt[0], v1.pt[1], 0, 0, 0, 0); - p1 = ln1.pt[0]; - p2 = ln1.pt[1]; - t = true; - } - if (ln2.pt[0] < v1.pt[2] && ln2.pt[1] < v1.pt[2]) { - add_codb(CO_COLL, ln2.pt[0], ln2.pt[1], v1.pt[2], v1.pt[3], 0, 0, 0, 0); - p3 = ln2.pt[0]; - p4 = ln2.pt[1]; - t = true; - } - if (t) - return mk_felim(p.var, trim_f(p1, p2, p3, p4), get_n(1), 1); - - return null; - } - + /** + * Attempts the elimination procedure (query type 7) on the provided XTerm. + * Iterates through subterms to identify a valid elimination candidate based on + * geometric relationships. + * + * @param p the XTerm to process + * @return the resulting elimination term if a valid candidate is found; null otherwise + */ ElTerm elim_q7(XTerm p) { LLine ln1, ln2, ln3, ln4; XTerm p1 = p; @@ -352,7 +403,8 @@ ElTerm elim_q7(XTerm p) { while (ps2 != null) { XTerm p2 = ps2.p; - if (npoly(p2)) break;//goto l2; + if (npoly(p2)) + break; Var v2 = p2.var; ln3 = fadd_ln(v2.pt[0], v2.pt[1]); ln4 = fadd_ln(v2.pt[2], v2.pt[3]); @@ -382,7 +434,6 @@ ElTerm elim_q7(XTerm p) { add_codb(CO_COLL, v1.pt[2], v1.pt[3], v2.pt[2], v2.pt[3], 0, 0, 0, 0); return (mk_felim(p1.var, get_m(p2.var), get_n(1L), 1)); } - if (ln2 == ln4 && ln_less(ln3, ln2)) { co_db.nx = null; add_codb(CO_COLL, v1.pt[2], v1.pt[3], v2.pt[2], v2.pt[3], 0, 0, 0, 0); @@ -392,7 +443,6 @@ ElTerm elim_q7(XTerm p) { r = 1; return (mk_felim(p1.var, pplus(get_m(p2.var), xt), get_n(1L), r)); } - if (ln1 == ln3) { co_db.nx = null; add_codb(CO_COLL, v1.pt[0], v1.pt[1], v2.pt[0], v2.pt[1], 0, 0, 0, 0); @@ -401,7 +451,6 @@ ElTerm elim_q7(XTerm p) { if (pzerop(xt)) r = 1; return (mk_felim(p1.var, pplus(get_m(p2.var), xt), get_n(1L), r)); - } } ps2 = p2.ps; @@ -409,35 +458,54 @@ ElTerm elim_q7(XTerm p) { } ps1 = p1.ps; ps1 = ps1.nx; - if (ps1 == null) return (null); + if (ps1 == null) + return (null); p1 = ps1.p; } } + /** + * Attempts the elimination procedure (query type 8) on the provided XTerm. + * Verifies collinearity of the term's sub-elements before processing. + * + * @param p1 the XTerm to process + * @return the resulting elimination term if successful; null otherwise + */ ElTerm elim_q8(XTerm p1) { DTerm ps1; XTerm p2; Var v1, v2; LLine ln1, ln2; - if (p1 == null || npoly(p1)) return (null); + if (p1 == null || npoly(p1)) + return (null); v1 = p1.var; ln1 = fadd_ln(v1.pt[0], v1.pt[1]); ps1 = p1.ps; ps1 = ps1.nx; - if (ps1 == null) return (null); + if (ps1 == null) + return (null); p2 = ps1.p; - if (npoly(p2)) return (null); + if (npoly(p2)) + return (null); v2 = p2.var; ln2 = fadd_ln(v2.pt[0], v2.pt[1]); - if (ln1 != ln2) return (null); + if (ln1 != ln2) + return (null); { co_db.nx = null; add_codb(CO_COLL, v1.pt[0], v1.pt[1], v2.pt[0], v2.pt[1], 0, 0, 0, 0); - return (mk_felim(p1.var, pplus(get_m(p2.var), trim_f(v2.pt[2], v2.pt[3], v1.pt[2], v1.pt[3])), get_n(1L), RF_ADDITION)); //addition. + return (mk_felim(p1.var, pplus(get_m(p2.var), trim_f(v2.pt[2], v2.pt[3], v1.pt[2], v1.pt[3])), get_n(1L), RF_ADDITION)); } } + /** + * Processes an XTerm by applying modulus to its coefficient. + * Traverses subterms until a non-polynomial term is encountered and applies the modulus. + * + * @param p the XTerm to process + * @return the processed XTerm with its coefficient modified + */ XTerm fpoly(XTerm p) { DTerm ps1, ps2; XTerm p1, p2; @@ -450,7 +518,8 @@ XTerm fpoly(XTerm p) { while (true) { ps1 = p1.ps; ps2 = ps1.nx; - if (ps2 == null) return (p); + if (ps2 == null) + return (p); p2 = ps2.p; if (!npoly(p2)) p1 = p2; @@ -467,60 +536,74 @@ XTerm fpoly(XTerm p) { return (p); } - ElTerm mk_felim11(Var v, int a, int b, int c, int d, int o, int p1, int p2, int o1) { // <[ab, cd] = <[o1p1,o1,p2] -// co_db.nx = null; -// -// cond c1 = add_codb(CO_COLL, o, p1, a, b, 0, 0, 0, 0); -// cond c2 = add_codb(CO_COLL, o, p2, c, d, 0, 0, 0, 0); -// el_term e1 = null; -// if (c1.pred != 0 || c2.pred != 0) { -// e1 = mk_felim(v, trim_f(o, p1, o, p2), get_n(1L), 0); -// co_db.nx = null; -// add_codb(CO_CYCLIC, 0, o, o1, p1, p2, 0, 0, 0); -// el_term e2 = mk_felim(new var(10, o, p1, o, p2), trim_f(o1, p1, o1, p2), get_n(1), 9); -// e1.nx = e2; -// co_db.nx = null; -// } else { -// add_codb(CO_CYCLIC, 0, o, o1, p1, p2, 0, 0, 0); -// } -// el_term el = (mk_felim(v, trim_f(o1, p1, o1, p2), get_n(1L), 9)); -// el.et = e1; -// return el; + /** + * Constructs an elimination term for cyclic configurations. + * Sets up conditions based on collinearity and cyclic properties. + * + * @param v the variable associated with the term + * @param a first parameter for collinearity + * @param b second parameter for collinearity + * @param c third parameter for collinearity + * @param d fourth parameter for collinearity + * @param o origin or reference parameter + * @param p1 first point parameter + * @param p2 second point parameter + * @param o1 additional reference parameter + * @return the elimination term constructed for the cyclic case + */ + ElTerm mk_felim11(Var v, int a, int b, int c, int d, int o, int p1, int p2, int o1) { co_db.nx = null; add_codb(CO_CYCLIC, 0, o, o1, p1, p2, 0, 0, 0); Cond c1 = add_codb(CO_COLL, o, p1, a, b, 0, 0, 0, 0); Cond c2 = add_codb(CO_COLL, o, p2, c, d, 0, 0, 0, 0); -// el_term e1 = null; -// if (c1.pred != 0 || c2.pred != 0) { -// e1 = mk_felim(v, trim_f(o, p1, o, p2), get_n(1L), 0); -// co_db.nx = null; -// el_term e2 = mk_felim(new var(10, o, p1, o, p2), trim_f(o1, p1, o1, p2), get_n(1), 9); -// e1.nx = e2; -// co_db.nx = null; -// } else { -// add_codb(CO_CYCLIC, 0, o, o1, p1, p2, 0, 0, 0); -// } ElTerm el = (mk_felim(v, trim_f(o1, p1, o1, p2), get_n(1L), RF_INSCRIBE)); co_db.nx = null; return el; } - ElTerm mk_felim6(Var v, int a, int b, int c, int d) { // para + /** + * Constructs an elimination term for parallel configurations. + * Registers the parallel condition before creating the elimination term. + * + * @param v the variable associated with the term + * @param a first parameter for the parallel condition + * @param b second parameter for the parallel condition + * @param c third parameter for the parallel condition + * @param d fourth parameter for the parallel condition + * @return the elimination term representing the parallel condition + */ + ElTerm mk_felim6(Var v, int a, int b, int c, int d) { co_db.nx = null; add_codb(CO_PARA, a, b, c, d, 0, 0, 0, 0); ElTerm e1 = mk_felim(v, get_n(0L), get_n(1L), 3); return e1; } + /** + * Constructs an elimination term for a perpendicular configuration. + * + * @param v the variable associated with the term + * @param a first parameter for the perpendicular configuration + * @param b second parameter for the perpendicular configuration + * @param c third parameter for the perpendicular configuration + * @param d fourth parameter for the perpendicular configuration + * @return the elimination term constructed for the perpendicular configuration + */ ElTerm mk_felim7(Var v, int a, int b, int c, int d) { co_db.nx = null; add_codb(CO_PERP, a, b, c, d, 0, 0, 0, 0); return mk_felim(v, get_n(1L), get_n(1L), 4); } + /** + * Attempts to eliminate a geometric term using various strategies. + * + * @param v the variable associated with the term + * @return the resulting elimination term if a strategy succeeds; otherwise, null + */ ElTerm elim_f(Var v) { ElTerm e1 = null; int a, b, c, d; @@ -561,8 +644,17 @@ ElTerm elim_f(Var v) { return (e1); } + /** + * Processes an elimination based on a line configuration. + * + * @param v the variable associated with the term + * @param a first geometric parameter + * @param b second geometric parameter + * @param c third geometric parameter + * @param d fourth geometric parameter + * @return the elimination term constructed from the line configuration; null if not applicable + */ ElTerm elim_f_ln(Var v, int a, int b, int c, int d) { - LLine ln1 = fd_ln(a, b); if (ln1 != null && a > ln1.pt[1]) { co_db.nx = null; @@ -572,8 +664,17 @@ ElTerm elim_f_ln(Var v, int a, int b, int c, int d) { return (null); } + /** + * Performs elimination based on a parallel line configuration. + * + * @param v the variable associated with the term + * @param a first geometric parameter + * @param b second geometric parameter + * @param c third geometric parameter + * @param d fourth geometric parameter + * @return the elimination term constructed from the parallel line configuration; null if not found + */ ElTerm elim_f_pn(Var v, int a, int b, int c, int d) { - LLine ln1 = fd_ln(a, b); PLine pn1 = fd_pn(a, b); if (pn1 == null) return (null); @@ -593,13 +694,21 @@ ElTerm elim_f_pn(Var v, int a, int b, int c, int d) { return (null); } - - ElTerm elim_f_tn(Var v, int a, int b, int c, int d) // could be more tn lines. - { + /** + * Performs elimination based on a tn-line configuration. + * + * @param v the variable associated with the term + * @param a first geometric parameter + * @param b second geometric parameter + * @param c third geometric parameter + * @param d fourth geometric parameter + * @return the elimination term constructed from the tn-line configuration; null if not applicable + */ + ElTerm elim_f_tn(Var v, int a, int b, int c, int d) { LLine ln2; LLine ln1 = fd_ln(a, b); TLine tn1 = fd_tn(ln1); -// if (tn1 == null) return (null); + // if (tn1 == null) return (null); if (tn1 != null) { if (tn1.l1 == ln1) ln2 = tn1.l2; @@ -643,7 +752,16 @@ ElTerm elim_f_tn(Var v, int a, int b, int c, int d) // could be more tn lines return (null); } - + /** + * Processes the cyclic configuration for elimination. + * + * @param v the variable associated with the term + * @param a first geometric parameter + * @param b second geometric parameter + * @param c third geometric parameter + * @param d fourth geometric parameter + * @return the elimination term constructed from the cyclic configuration; null if not applicable + */ ElTerm elim_f_cir1(Var v, int a, int b, int c, int d) { int o, p1, p2, p3, p4; LLine ln3, ln4, ln5, ln6; @@ -748,13 +866,23 @@ else if (rel == null) } } } - if (rel != null) return rel; - l1: - cr = cr.nx; + if (rel != null) return rel; + l1: + cr = cr.nx; + } + return (null); } - return (null); - } + /** + * Processes the cyclic configuration (version 2) for elimination. + * + * @param v the variable associated with the term + * @param a first geometric parameter + * @param b second geometric parameter + * @param c third geometric parameter + * @param d fourth geometric parameter + * @return the elimination term constructed from the second cyclic configuration; null if not applicable + */ ElTerm elim_f_cir2(Var v, int a, int b, int c, int d) { ACir cr1, cr2; int p1, p2, p3, p4; @@ -820,6 +948,19 @@ ElTerm elim_f_cir2(Var v, int a, int b, int c, int d) { return (null); } + /** + * Performs elimination based on a cyclic circle configuration (variant 3). + * + * This method searches through cyclic configurations in the circle list and + * attempts to form an elimination term based on inter-line relationships. + * + * @param v the variable associated with the elimination term + * @param a the first geometric parameter + * @param b the second geometric parameter + * @param c the third geometric parameter + * @param d the fourth geometric parameter + * @return the elimination term constructed from the cyclic configuration or null if not applicable + */ ElTerm elim_f_cir3(Var v, int a, int b, int c, int d) { ACir cr1; int o, p1, p2, p3, p4; @@ -889,6 +1030,19 @@ ElTerm elim_f_cir3(Var v, int a, int b, int c, int d) { return (null); } + /** + * Performs elimination based on a cyclic circle configuration (variant 4). + * + * This method searches through cyclic configurations in the circle list and + * attempts to form an elimination term using midpoint and line intersection strategies. + * + * @param v the variable associated with the elimination term + * @param a the first geometric parameter + * @param b the second geometric parameter + * @param c the third geometric parameter + * @param d the fourth geometric parameter + * @return the elimination term constructed from the cyclic configuration or null if not applicable + */ ElTerm elim_f_cir4(Var v, int a, int b, int c, int d) { ACir cr1; int o, p1, p2, p3, p4; @@ -940,7 +1094,7 @@ ElTerm elim_f_cir4(Var v, int a, int b, int c, int d) { ln_less((fadd_ln(p2, p3)), ln1)) { co_db.nx = null; add_codb(CO_CYCLIC, o, p1, p2, p3, 0, 0, 0, 0); //r33 - return (mk_felim(v, pplus3(trim_f(p1, o, p1, p3), trim_f(p2, p3, c, d), get_n(1L)), //r28 + return (mk_felim(v, pplus3(trim_f(p1, o, p1, p3), trim_f(p2, p3, c, d), get_n(1L)), get_n(1L), RF_18)); } if (ln_less((fadd_ln(p3, o)), ln1) && @@ -958,6 +1112,19 @@ ElTerm elim_f_cir4(Var v, int a, int b, int c, int d) { return (null); } + /** + * Performs elimination based on center configurations. + * + * This method iterates through line points and configuration constraints to + * determine centers (such as orthocenters or incenters) for constructing an elimination term. + * + * @param v the variable associated with the elimination term + * @param a the first geometric parameter + * @param b the second geometric parameter + * @param c the third geometric parameter + * @param d the fourth geometric parameter + * @return the elimination term constructed from center-based elimination or null if not applicable + */ ElTerm elim_f_center(Var v, int a, int b, int c, int d) { LLine ln1, ln2; int p1, p2; @@ -975,7 +1142,7 @@ ElTerm elim_f_center(Var v, int a, int b, int c, int d) { for (k = 1; k <= cons_no; k++) for (l = 1; l <= cons_no; l++) { - //orthocenter k p1 p2 l / + // orthocenter k p1 p2 l if (k < l && p1 < p2 && k != p1 && k != p2 && l != p1 && l != p2 && xperp(p1, k, p2, l) && xperp(p2, k, p1, l) && ln_less((fadd_ln(k, l)), ln1)) { @@ -984,8 +1151,8 @@ ElTerm elim_f_center(Var v, int a, int b, int c, int d) { return (mk_felim(v, pplus(trim_f(k, l, c, d), get_n(1L)), get_n(1L), RF_ORTH)); } - /* incenter (p1) p2 k l */ - /*gprint("cen1: %s %s %s %s\r\n",ANAME(p1),ANAME(p2),ANAME(k),ANAME(l)); */ + /* incenter (p1) p2 k l */ + /* gprint("cen1: %s %s %s %s\r\n",ANAME(p1),ANAME(p2),ANAME(k),ANAME(l)); */ if (k < l && k != p1 && k != p2 && l != p1 && l != p2 && xacong(k, l, p1, p1, l, p2) && xacong(l, k, p1, p1, k, p2) && ln_less((fadd_ln(k, p2)), ln1) && @@ -1007,6 +1174,18 @@ ElTerm elim_f_center(Var v, int a, int b, int c, int d) { return (null); } + /** + * Performs elimination based on angle configurations. + * + * This method processes the angle and congruence relationships to form an elimination term. + * + * @param v the variable associated with the elimination term + * @param a the first geometric parameter + * @param b the second geometric parameter + * @param c the third geometric parameter + * @param d the fourth geometric parameter + * @return the elimination term constructed from angle-based configurations or null if not applicable + */ ElTerm elim_f_ans(Var v, int a, int b, int c, int d) { LLine l1, l2, ln0, ln1, ln2; Angles as; @@ -1077,6 +1256,22 @@ ElTerm elim_f_ans(Var v, int a, int b, int c, int d) { return (null); } + /** + * Performs elimination based on combined geometric configurations involving circles and lines. + * + *

+ * This method takes a variable containing four geometric points and attempts to construct an elimination + * term by evaluating a series of geometric constraints. It uses helper methods such as + * inter_lc, ln_less, on_ln, on_cir, xperp, + * and xpara to verify perpendicular, parallel, and cyclic conditions among lines and circles. + * The method iterates through the circle lists and applies different elimination strategies. + * When a valid geometric configuration is detected, it creates and returns the corresponding elimination term. + * Otherwise, it returns null. + *

+ * + * @param v the variable containing four geometric points used to derive lines and circles + * @return the constructed elimination term if a valid configuration is identified; null otherwise + */ ElTerm elim_d(Var v) { LLine ln1, ln2; ACir cr, cr1; @@ -1273,7 +1468,18 @@ else if (ln_less(fadd_ln(p3, p2), ln1)) { return (null); } - ElTerm elim_t(Var v) { +/** + * Performs elimination based on a t-based strategy. + * + *

This method handles elimination cases that require t-based processing. + * It applies specific geometric transformations and validations to compute + * the corresponding elimination term.

+ * + * @param v the variable containing geometric term data + * @return the computed elimination term using the t-based strategy, or + * null if no appropriate elimination can be performed + */ +ElTerm elim_t(Var v) { LLine ln1, ln2; ACir cr; int p1, p2, p3; @@ -1308,7 +1514,20 @@ ElTerm elim_t(Var v) { return (null); } - ElTerm elim_tri(Var v) { +/** + * Performs triangle elimination. + * + *

+ * This method processes elimination based on triangle configurations. + * It evaluates the geometric relationships between triangle vertices to + * compute the corresponding elimination term. + *

+ * + * @param v the variable containing triangle points data + * @return the elimination term constructed from the triangle configuration, + * or null if no appropriate elimination can be performed + */ +ElTerm elim_tri(Var v) { int a = v.pt[0]; int b = v.pt[1]; int c = v.pt[2]; @@ -1338,7 +1557,20 @@ ElTerm elim_tri(Var v) { } /////froem area - XTerm eprem(XTerm p, ElTerm e) { +/** + * Performs pre-elimination computations on an XTerm using the specified elimination term. + * + *

This method applies an elimination strategy by processing the given XTerm + * in conjunction with an elimination term. The transformation rules and constraints + * applied within the method lead to a modified XTerm that encapsulates specific geometric + * relationships or configurations. The exact processing is defined by the elimination + * scheme used in the overall geometric computation.

+ * + * @param p the original XTerm input for pre-elimination processing + * @param e the elimination term that guides the computation + * @return the resulting XTerm after processing or null if the computation is not applicable + */ +XTerm eprem(XTerm p, ElTerm e) { XTerm p1, p2, p3; if (e == null) return p; p2 = get_n(1L); @@ -1362,28 +1594,55 @@ XTerm eprem(XTerm p, ElTerm e) { return (p1); } - ////////////////////////////////////////////////////////////////////// - // print - boolean pr_elim = true; - - public boolean canExpressedAsFullAngle() { - return proof.nx != null; - } - - public boolean isProvedTrue() { - if (last_pr != null && last_pr.isZero()) return true; - return false; - } +/** + * Returns true if a full angle proof is expressed. + * + * @return true if the full angle proof head exists, false otherwise. + */ +public boolean canExpressedAsFullAngle() { + return proof.nx != null; +} - public GrTerm getFullAngleProofHead() { +/** + * Determines if the proof has been established as true. + * + * @return true if last_pr is non-null and equals zero, false otherwise. + */ +public boolean isProvedTrue() { + if (last_pr != null && last_pr.isZero()) return true; + return false; +} - GrTerm gt = proof.nx; - if (gt == null) return null; - while (gt != null) { - if (gt.ps1 != null) - myprint_p1(gt.ps1.p, true); - ElTerm el = gt.el; - if (el != null) { +/** + * Retrieves the head of the full angle proof. + * + * This method iterates through the proof elements while printing intermediate + * proof components. It processes both primary and linked elimination terms. + * + * @return the first element in the full angle proof chain, or null if none exists. + */ +public GrTerm getFullAngleProofHead() { + GrTerm gt = proof.nx; + if (gt == null) return null; + while (gt != null) { + if (gt.ps1 != null) + myprint_p1(gt.ps1.p, true); + ElTerm el = gt.el; + if (el != null) { + myprint_p1(el.p1, true); + myprint_p1(el.p2, true); + myprint_p1(el.p, true); + Cond co = el.co; + while (co != null) { + this.show_pred(co); + do_pred(co); + //forw_pred(co); + co = co.nx; + } + } + if (el != null) { + el = el.et; + while (el != null) { myprint_p1(el.p1, true); myprint_p1(el.p2, true); myprint_p1(el.p, true); @@ -1391,158 +1650,96 @@ public GrTerm getFullAngleProofHead() { while (co != null) { this.show_pred(co); do_pred(co); - //forw_pred(co); + // forw_pred(co); co = co.nx; } + el = el.nx; } - if (el != null) { - el = el.et; - while (el != null) { - myprint_p1(el.p1, true); - myprint_p1(el.p2, true); - myprint_p1(el.p, true); - Cond co = el.co; - while (co != null) { - this.show_pred(co); - do_pred(co); - // forw_pred(co); - co = co.nx; - } - el = el.nx; - } - } - - gt = gt.nx; } - - return proof.nx; + gt = gt.nx; } + return proof.nx; +} - public boolean print_prooftext() // added MAY 4th 2006 - { - char mk = 0; - - GrTerm gr1 = proof.nx; - if (gr1 == null) return false; - - while (gr1 != null) { - if (gr1.c == -1) { - this.setPrintToString(); - DTerm dt = gr1.ps; - print_ps(dt, mk); - dt.text = this.getPrintedString(); - } else if (gr1.c == -2) { - } else if (gr1.c == 0) { - } else { - ElTerm el = gr1.el; - print_elims(el, mk); - } - - if (gr1.c == 0) { - } else { - } - +/** + * Prints the proof text. + * + * This method iterates through all proof terms and prints their associated + * elimination information. It assembles the printed proof text by processing + * both display and elimination terms. + * + * @return true if proof text printing succeeds, false otherwise. + */ +public boolean print_prooftext() // added MAY 4th 2006 +{ + char mk = 0; + GrTerm gr1 = proof.nx; + if (gr1 == null) return false; + while (gr1 != null) { + if (gr1.c == -1) { this.setPrintToString(); - print_gr(gr1, mk); - gr1.text = this.getPrintedString(); - gr1 = gr1.nx; - } - return true; - } - - void print_proof(char mk) { - GrTerm gr1 = proof.nx; - - if (gr1 == null) { - gprint(Cm.s2220); - return; - } - gprint(Cm.s2221); - //docc(3); - gprint(Cm.s2222); - gprint(" "); - { // print the gr as an equation - //for area, vector, and full-angle - if (num_zop(gr1.c1)) { - gprint("0"); - } else if (gr1.ps1 == null) { - //sprintf(txt, "%ld", gr1.c1); - gprint("" + gr1.c1); - } else if (num_unit(gr1.c1)) - print_ps(gr1.ps1, mk); - else { - num_show(gr1.c1); - print_ps(gr1.ps1, mk); - } - gprint(" = "); - if (num_zop(gr1.c2)) { - gprint("0"); - } else if (gr1.ps2 == null) { - //sprintf(txt, "%ld", gr1.c2); - gprint("" + gr1.c2); - } else if (num_unit(gr1.c2)) - print_ps(gr1.ps2, mk); - else { - num_show(gr1.c2); - print_ps(gr1.ps2, mk); - } + DTerm dt = gr1.ps; + print_ps(dt, mk); + dt.text = this.getPrintedString(); + } else if (gr1.c == -2) { + } else if (gr1.c == 0) { + } else { + ElTerm el = gr1.el; + print_elims(el, mk); } - - gprint(Cm.s2072); - gprint("\r\n\r\n"); - - gprint("\r\n"); - while (gr1 != null) { - if (pr_elim) { - if (gr1.c == -1) { - gprint(Cm.s2223); - print_ps(gr1.ps, mk); - gprint("\r\n\r\n"); - } else if (gr1.c == -2) { - } else if (gr1.c == 0) { - } else { - print_elims(gr1.el, mk); - gprint("\r\n"); - } - } - if (gr1.c == 0) { - } else { - gprint(" = "); - } - - print_gr(gr1, mk); - gprint("\r\n"); - gr1 = gr1.nx; + if (gr1.c == 0) { + } else { } - gprint("\r\n"); + this.setPrintToString(); + print_gr(gr1, mk); + gr1.text = this.getPrintedString(); + gr1 = gr1.nx; } + return true; +} - - void print_elims(ElTerm el, char mk) { +/** + * Recursively prints elimination terms. + * + * This method prints the elimination term provided and then recursively processes + * any linked elimination terms. It sets the printed text for each elimination element. + * + * @param el the elimination term to print + * @param mk a marker character used during the printing process + */ +void print_elims(ElTerm el, char mk) { // gprint(Cm.s2224); - if (el == null) - return; - + if (el == null) + return; + this.setPrintToString(); + print_elim(el, mk); + el.setText(this.getPrintedString()); + print_elims(el.et, mk); +// gprint("\r\n"); + for (el = el.nx; el != null; el = el.nx) { this.setPrintToString(); print_elim(el, mk); el.setText(this.getPrintedString()); - print_elims(el.et, mk); - -// gprint("\r\n"); - for (el = el.nx; el != null; el = el.nx) { - this.setPrintToString(); - print_elim(el, mk); - el.setText(this.getPrintedString()); - print_elims(el.et, mk); - } } +} static GrTerm el_gr = new GrTerm(); static DTerm el_d1 = new DTerm(); static DTerm el_d2 = new DTerm(); + /** + * Prints the elimination term information. + *

+ * If the elimination term is null or its associated variable has a negative index, + * the method returns without printing. Depending on whether the elimination term has + * a first polynomial (p1) or not, the method prints the appropriate representation. + *

+ * + * @param e the elimination term to be printed + * @param mk the marker character used during printing + */ void print_elim(ElTerm e, char mk) { XTerm p1, p2; Var v; @@ -1578,7 +1775,7 @@ void print_elim(ElTerm e, char mk) { p1 = e.p1; p2 = e.p2; // pprint(p1); - // pprint(p2); + // pprint(p2); if (p1.var == null) { el_gr.c1 = p1.c; el_gr.ps1 = null; @@ -1608,22 +1805,27 @@ void print_elim(ElTerm e, char mk) { } } - void print_all_vars() { - Var e1; - - gprint(Cm.s2225); - e1 = all_var.nx; - while (e1 != null) { - print_var(e1, 0); - gprint("\r\n"); - e1 = e1.nx; - } - } - + /** + * Recursively checks whether a geometric term's polynomial parts are regular. + * + * @param gr the geometric term to check + * @return true if both polynomial parts (ps1 and ps2) are regular, false otherwise + */ boolean rgr(GrTerm gr) { return (rps(gr.ps1) && rps(gr.ps2)); } + /** + * Recursively checks whether the given polynomial term is regular. + *

+ * A regular term requires that each associated variable has an index of 1, that + * its subsequent term (ps) contains only one element, and that this recursively + * holds for all subsequent terms. + *

+ * + * @param ps1 the polynomial term to check + * @return true if the term is regular, false otherwise + */ boolean rps(DTerm ps1) { DTerm ps2; XTerm p1; @@ -1642,7 +1844,17 @@ boolean rps(DTerm ps1) { return (true); } - + /** + * Prints a geometric term. + *

+ * The method prints the term based on its coefficients and polynomial parts. + * Depending on whether the term represents a fraction, an integer, or a combination, + * it formats the output accordingly. + *

+ * + * @param gr the geometric term to print + * @param mk a marker character used during printing + */ void print_gr(GrTerm gr, char mk) { boolean rg; long n; @@ -1710,12 +1922,33 @@ void print_gr(GrTerm gr, char mk) { } } + /** + * Displays a numeric fraction. + *

+ * The numerator and denominator are shown separated by a forward slash. + *

+ * + * @param c1 the numerator value + * @param c2 the denominator value + * @param mk a marker character used during printing + */ void show_num2(long c1, long c2, char mk) { num_show(c1); gprint("/"); num_show(c2); } + /** + * Prints a polynomial expression represented by a DTerm. + *

+ * If the term has a degree of 1, it is printed normally or with parentheses if the + * expression requires grouping. For higher degree terms, the term is printed with + * an exponent notation. + *

+ * + * @param dp1 the polynomial term to print + * @param mk a marker character used during printing + */ void print_ps(DTerm dp1, char mk) { if (dp1 == null) gprint(""); @@ -1737,7 +1970,6 @@ void print_ps(DTerm dp1, char mk) { } else { gprint("("); print_p(dp1.p, mk); - //sprintf(txt, ")^{%d}", dp1.deg); gprint(")^{" + dp1.deg + "}"); } dp1 = dp1.nx; @@ -1745,28 +1977,17 @@ void print_ps(DTerm dp1, char mk) { } } - boolean chord_p(XTerm p) { - Var v; - if (npoly(p)) return (true); - v = p.var; - return (v.nm == 5); - } - - - /////////////////////////////////// - Vector getAllterms(XTerm p1) { - - Vector list = new Vector(); - if (p1 == null) - return list; - if (p1.var == null) return list; - list.add(p1); - return list; - } - - + /** + * Prints an XTerm (mathematical expression) with its variable and coefficient. + *

+ * Constant terms without an associated variable are printed in an angle-signed format. + * For non-constant terms, the method processes the polynomial parts recursively. + *

+ * + * @param p1 the XTerm to be printed + * @param first true if this is the first term (affects sign formatting), false otherwise + */ public void myprint_p1(XTerm p1, boolean first) { - this.setPrintToString(); DTerm dp1, dp2; XTerm xp1; @@ -1809,19 +2030,11 @@ public void myprint_p1(XTerm p1, boolean first) { myprint_p1(dp2.p, false); } - GrTerm mk_el_gr(ElTerm el) { -// gr_term gr1 = mk_gr(mk_num(1L), get_dt(1, p1, null), mk_num(0L), null, 99, null); -// -// el_term e1 = el.et; -// while (e1 != null) { -// xterm p1 = get_m(el.v); -// p1 = eprem(cp_poly(p1), e1); -// fpoly(p1); -// } -// return gr; - return null; - } - + /** + * Counts the number of variable instances. + * + * @return the total number of variables in the linked list starting at all_var.nx + */ int getvarNum() { Var v = all_var.nx; int t = 0; @@ -1832,6 +2045,11 @@ int getvarNum() { return t; } + /** + * Counts the number of line instances. + * + * @return the total number of lines in the linked list starting at all_ln.nx + */ int getlnNum() { LLine ln = all_ln.nx; int t = 0; @@ -1842,6 +2060,16 @@ int getlnNum() { return t; } + /** + * Reorders the points in the given variable. + * + *

If the first point is less than the second, they are swapped. + * Similarly, if the third point is less than the fourth, they are swapped. + * Additional reordering is performed if necessary, and the method returns a flag indicating if any reordering took place.

+ * + * @param v the variable whose points are to be reordered + * @return true if reordering occurred; false otherwise + */ boolean var_reOrder(Var v) { int p1, p2, p3, p4, p; boolean sr = false; @@ -1883,6 +2111,19 @@ boolean var_reOrder(Var v) { return sr; } + /** + * Trims the line segments based on the intersection of two lines. + * + *

This method retrieves two lines from two pairs of points and checks whether they intersect. + * If an intersection is found, the endpoints are adjusted accordingly. + * Finally, an XTerm is generated using the trimmed endpoints.

+ * + * @param p1 the first coordinate of the first point + * @param p2 the second coordinate of the first point + * @param p3 the first coordinate of the second point + * @param p4 the second coordinate of the second point + * @return the XTerm representing the trimmed line segments + */ XTerm trim_full(int p1, int p2, int p3, int p4) { int t = 0; @@ -1894,29 +2135,46 @@ XTerm trim_full(int p1, int p2, int p3, int p4) { if (p3 != t && p4 != t) p4 = t; } else if (ln1 == null && ln2 != null) { - + // When ln1 is absent and ln2 is present, no adjustment is performed. } return trim_f(p1, p2, p3, p4); } + /** + * Sets the flag to show details. + * + *

This static method controls whether detailed information should be displayed.

+ * + * @param d the boolean value to set for showing details + */ public static void set_showdetai(boolean d) { show_detail = d; } - ////////////////////////////////////////////////////////////////////////////////////// - //////////////NDGS /** - * ********************************************** + * Determines if a given type represents a valid construction. + * + *

The type is considered valid if it falls within specific ranges and does not require freeCS.

+ * + * @param type the construction type to check + * @return true if the type is a construction type; false otherwise */ - // V1. Constructions. - // V2. Initial NDGS - // V3. Simplified. - // V4 Final NDGS. public boolean isConstructionType(int type) { return (type > 0 && type < 50 || type > 100 && type < 150) && !freeCS(type); } + /** + * Populates the provided vectors with non-degenerate geometry constraints (NDGs) from constructions. + * + *

This method iterates through constructions, adds valid constructions to the first vector, + * initializes and filters NDGs, deduces additional constraints, and finally updates the provided vectors.

+ * + * @param v1 a vector for constructions used as NDG constraints + * @param v2 a vector for initial NDGs + * @param v3 a vector for filtered NDGs + * @param v4 a vector for deduced NDGs + */ public void get_ndgs(Vector v1, Vector v2, Vector v3, Vector v4) { // cndg int n = cns_no; @@ -1927,8 +2185,8 @@ public void get_ndgs(Vector v1, Vector v2, Vector v3, Vector v4) { // cndg } vndgs.clear(); - init_ndgs(v2); // Init NDGS. - filter_ndg(v2, v3); // Remove rudundent NDGS. + init_ndgs(v2); // Init NDGs. + filter_ndg(v2, v3); // Remove redundant NDGs. ndg_deduction(v3, v4); filter_ndg(v4); filter_ndg(vndgs); @@ -1938,7 +2196,17 @@ public void get_ndgs(Vector v1, Vector v2, Vector v3, Vector v4) { // cndg v4.addAll(vndgs); } - + /** + * Creates and adds a non-isotropic NDG constraint based on two points. + * + *

This method checks that the points are different and valid. + * It creates a new CNdg for non-isotropic constraints and adds it to the provided vector.

+ * + * @param a the first point + * @param b the second point + * @param v1 the vector to which the NDG is added + * @return the created CNdg object, or null if the points are identical or invalid + */ protected CNdg add_n_isotropic(int a, int b, Vector v1) { if (a == b) return null; @@ -1960,6 +2228,20 @@ protected CNdg add_n_isotropic(int a, int b, Vector v1) { return n; } + /** + * Creates and adds an NDG constraint representing parallelism or perpendicularity. + * + *

This method reorders four points if needed and creates a corresponding NDG + * depending on the specified type. The resulting constraint is then added to the vector.

+ * + * @param type the type of NDG (e.g. NDG_PARA for parallel or NDG_PERP for perpendicular) + * @param a the first point of the first line + * @param b the second point of the first line + * @param c the first point of the second line + * @param d the second point of the second line + * @param v1 the vector to which the NDG is added + * @return the created CNdg object + */ protected CNdg add_n_pt(int type, int a, int b, int c, int d, Vector v1) { if (a > b) { int t = a; @@ -2001,6 +2283,18 @@ protected CNdg add_n_pt(int type, int a, int b, int c, int d, Vector v1) { return n; } + /** + * Creates and adds a collinearity NDG constraint based on three points. + * + *

This method reorders the three points to ensure a proper order for establishing collinearity, + * then creates a new CNdg representing the collinearity constraint and adds it to the given vector.

+ * + * @param a the first point + * @param b the second point + * @param c the third point + * @param v1 the vector to which the NDG is added + * @return the created CNdg object + */ protected CNdg add_n_coll(int a, int b, int c, Vector v1) { if (a > b) { int t = a; @@ -2030,6 +2324,14 @@ protected CNdg add_n_coll(int a, int b, int c, Vector v1) { return n; } + /** + * Initializes non-degenerate geometry constraints (NDGs) from existing constructions. + * + *

This method iterates through all constructions, creates appropriate NDG constraints based on + * the type of each construction, and associates dependencies with the NDGs when modifications occur.

+ * + * @param v1 the vector to be populated with NDG constraints + */ public void init_ndgs(Vector v1) { CNdg nd; @@ -2057,7 +2359,6 @@ public void init_ndgs(Vector v1) { case C_I_PP: add_n_pt(NDG_PARA, c.ps[2], c.ps[3], c.ps[5], c.ps[6], v1); break; - case C_I_TT: add_n_pt(NDG_PARA, c.ps[2], c.ps[3], c.ps[5], c.ps[6], v1); break; @@ -2069,7 +2370,7 @@ public void init_ndgs(Vector v1) { case C_O_C: break; case C_CIRCLE: - add_n_coll(c.ps[1], c.ps[2], c.ps[3], v1); ///...../...???? + add_n_coll(c.ps[1], c.ps[2], c.ps[3], v1); break; case C_PARALLELOGRAM: add_coll_para(c, v1); @@ -2083,19 +2384,16 @@ public void init_ndgs(Vector v1) { nd = add_ndg_neq(c.ps[1], c.ps[2]); this.add_ndgs(nd, v1); break; - - /////Special for aline. - case C_I_PA: { CNdg dx = add_n_pt(NDG_PARA, c.ps[2], c.ps[3], c.ps[4], c.ps[5], v1); if (dx != null) dx.exists = true; - add_n_neq(c.ps[4], c.ps[5], vndgs); add_n_neq(c.ps[6], c.ps[7], vndgs); add_n_neq(c.ps[8], c.ps[9], vndgs); - XTerm xt = pplus(trim_f(c.ps[2], c.ps[3], c.ps[4], c.ps[5]), trim_f(c.ps[6], c.ps[7], c.ps[7], c.ps[8])); + XTerm xt = pplus(trim_f(c.ps[2], c.ps[3], c.ps[4], c.ps[5]), + trim_f(c.ps[6], c.ps[7], c.ps[7], c.ps[8])); xt = add_deduction(xt); addxtermndg(xt, vndgs); } @@ -2108,7 +2406,8 @@ public void init_ndgs(Vector v1) { add_n_neq(c.ps[3], c.ps[4], vndgs); add_n_neq(c.ps[5], c.ps[6], vndgs); add_n_neq(c.ps[6], c.ps[7], vndgs); - XTerm xt = pplus(trim_f(c.ps[1], c.ps[2], c.ps[3], c.ps[4]), trim_f(c.ps[7], c.ps[6], c.ps[6], c.ps[5])); + XTerm xt = pplus(trim_f(c.ps[1], c.ps[2], c.ps[3], c.ps[4]), + trim_f(c.ps[7], c.ps[6], c.ps[6], c.ps[5])); xt = add_deduction(xt); addxtermndg(xt, vndgs); } @@ -2124,7 +2423,8 @@ public void init_ndgs(Vector v1) { add_n_neq(c.ps[6], c.ps[7], vndgs); add_n_neq(c.ps[8], c.ps[9], vndgs); add_n_neq(c.ps[9], c.ps[10], vndgs); - XTerm xt = pplus(trim_f(c.ps[3], c.ps[4], c.ps[4], c.ps[5]), trim_f(c.ps[1], c.ps[2], c.ps[6], c.ps[7])); + XTerm xt = pplus(trim_f(c.ps[3], c.ps[4], c.ps[4], c.ps[5]), + trim_f(c.ps[1], c.ps[2], c.ps[6], c.ps[7])); xt = pplus(xt, trim_f(c.ps[10], c.ps[9], c.ps[9], c.ps[8])); xt = add_deduction(xt); addxtermndg(xt, vndgs); @@ -2141,11 +2441,30 @@ public void init_ndgs(Vector v1) { } + /** + * Adds a non-equality NDG constraint for the given points. + * + *

This method creates an NDG constraint of type NDG_NEQ (or equivalent) for points a and b, + * then adds it to the provided vector.

+ * + * @param a the first point index + * @param b the second point index + * @param v1 the vector to add the NDG constraint + */ public void add_n_neq(int a, int b, Vector v1) { CNdg nd = add_ndg_neq(a, b); this.add_ndgs(nd, v1); } + /** + * Creates and adds a collinearity constraint in parallel form based on a construction. + * + *

This method determines the highest point value from the construction's point array, then + * selects the three remaining points to build a collinearity NDG constraint and adds it to vector v1.

+ * + * @param cs the construction containing the points + * @param v1 the vector to add the NDG constraint + */ public void add_coll_para(Cons cs, Vector v1) { int a, b; @@ -2173,6 +2492,16 @@ else if (c3 < 0 && i != b) add_n_coll(c1, c2, c3, v1); } + /** + * Deduces angle-based NDG constraints and processes them. + * + *

This method handles a given CNdg constraint by checking if all associated points are free. + * If so, it directly duplicates the constraint into vector v4; otherwise, it computes an XTerm deduction + * based on the NDG type and adds related non-equality constraints.

+ * + * @param c the CNdg constraint to analyze + * @param v4 the vector in which the deduced NDG constraints are stored + */ public void angle_deduction(CNdg c, Vector v4) { if (c == null) return; @@ -2217,18 +2546,16 @@ public void angle_deduction(CNdg c, Vector v4) { } } - - protected void add_deduction(int a, int b, int c, int d, Vector v4) { - XTerm x = trim_f(a, b, c, d); - XTerm x1 = add_deduction(x); - if (pzerop(pminus(cp_poly(x), cp_poly(x1)))) { - - } else { - - } - - } - + /** + * Checks and adds a non-equality constraint between two points if not already present. + * + *

This method iterates over the vector v4 to determine if an equivalent NDG constraint exists. + * If none is found, a new NDG constraint (NDG_NEQ) for the pair of points is created and added.

+ * + * @param a the first point index + * @param b the second point index + * @param v4 the vector containing NDG constraints + */ protected void add_neqTo(int a, int b, Vector v4) { for (int i = 0; i < v4.size(); i++) { CNdg d = (CNdg) v4.get(i); @@ -2252,6 +2579,15 @@ protected void add_neqTo(int a, int b, Vector v4) { add_ndgs(d, v4); } + /** + * Checks whether all points in the given CNdg constraint are free. + * + *

This method iterates over the points associated with the constraint and calls freeCSP + * for each one. It returns false as soon as any point is not free.

+ * + * @param d the CNdg constraint to check + * @return true if all points are free; false otherwise + */ protected boolean ck_allFree(CNdg d) { if (d == null) return true; @@ -2262,8 +2598,16 @@ protected boolean ck_allFree(CNdg d) { return true; } + /** + * Performs angle deduction on the given XTerm. + * + *

If the XTerm has an associated variable, angle-based deduction is applied followed by + * a final deduction adjustment.

+ * + * @param x the XTerm to deduct + * @return the resulting XTerm after deduction + */ protected XTerm add_deduction(XTerm x) { - if (x.var == null) return x; @@ -2272,6 +2616,14 @@ protected XTerm add_deduction(XTerm x) { return xt; } + /** + * Applies a final deduction adjustment to an XTerm. + * + *

If the factor computed by fcc is negative, the XTerm is multiplied by -1.

+ * + * @param p1 the XTerm to adjust + * @return the adjusted XTerm + */ protected XTerm final_deduction(XTerm p1) { if (p1 == null) return p1; @@ -2282,8 +2634,15 @@ protected XTerm final_deduction(XTerm p1) { return p1; } + /** + * Filters out redundant NDG constraints in the given vector. + * + *

This method compares each NDG constraint in the vector with the others and removes any + * that are equal or less significant than another constraint.

+ * + * @param v4 the vector containing NDG constraints to filter + */ protected void filter_ndg(Vector v4) { - for (int i = 0; i < v4.size(); i++) { CNdg d = (CNdg) v4.get(i); for (int j = i + 1; j < v4.size(); j++) { @@ -2301,11 +2660,18 @@ protected void filter_ndg(Vector v4) { } } } - } + /** + * Filters and merges NDG constraints from vector v2 into vector v3. + * + *

This method iterates over the constraints in v2 and checks against those in v3. + * If an equivalent or less significant constraint exists, it merges or sets an equivalence link.

+ * + * @param v2 the source vector of NDG constraints + * @param v3 the target vector for filtered NDG constraints + */ protected void filter_ndg(Vector v2, Vector v3) { - for (int i = 0; i < v2.size(); i++) { CNdg d = (CNdg) v2.get(i); boolean added = false; @@ -2333,16 +2699,33 @@ protected void filter_ndg(Vector v2, Vector v3) { } } + /** + * Adds an NDG constraint to the specified vector. + * + *

This helper method ensures the NDG constraint is valid (non-null), initializes its string + * representation by calling get_ndgstr, and then adds it to the vector.

+ * + * @param d the NDG constraint to add + * @param vlist the vector where the NDG constraint is stored + */ protected void add_ndgs(CNdg d, Vector vlist) { if (d == null) return; get_ndgstr(d); - - vlist.add(d); } + /** + * Compares two NDG constraints to determine if the first is less significant than the second. + * + *

For non-equality NDGs, if the second constraint is of type NDG_COLL and contains both points + * of the first constraint, the first is considered less significant.

+ * + * @param n1 the first NDG constraint + * @param n2 the second NDG constraint + * @return true if n1 is less significant than n2; false otherwise + */ protected boolean ndg_less(CNdg n1, CNdg n2) { if (n1.type == NDG_NEQ || n1.type == NDG_NON_ISOTROPIC) { if (n2.type == NDG_COLL) { @@ -2353,6 +2736,16 @@ protected boolean ndg_less(CNdg n1, CNdg n2) { return false; } + /** + * Checks whether two NDG constraints are equal. + * + *

This method first compares their types (allowing for NDG_NEQ and NDG_NON_ISOTROPIC to be equivalent), + * then verifies that the number of points and the point values are identical.

+ * + * @param n1 the first NDG constraint + * @param n2 the second NDG constraint + * @return true if the two constraints are equal; false otherwise + */ protected boolean ndg_eq(CNdg n1, CNdg n2) { if (n1.type != n2.type) { if ((n1.type == NDG_NEQ || n1.type == NDG_NON_ISOTROPIC) @@ -2371,6 +2764,15 @@ protected boolean ndg_eq(CNdg n1, CNdg n2) { return true; } + /** + * Converts an XTerm into an NDG constraint and adds its printed representation. + * + *

This method first converts the XTerm into a corresponding NDG constraint via xterm2ndg, + * then updates its string representation using the printing methods.

+ * + * @param x the XTerm to convert and add + * @param v4 the vector where the NDG information is stored + */ protected void addxtermndg(XTerm x, Vector v4) { if (x == null) return; @@ -2382,6 +2784,16 @@ protected void addxtermndg(XTerm x, Vector v4) { } + /** + * Converts an XTerm into NDG constraints and adds them to the provided list. + *

+ * Depending on the term number of the XTerm, the method delegates to a helper method + * to generate the appropriate NDG constraints. + *

+ * + * @param x the XTerm to convert + * @param vlist the vector where the generated NDG constraints will be added + */ protected void xterm2ndg(XTerm x, Vector vlist) { if (x == null || x.var == null) return; @@ -2392,9 +2804,18 @@ protected void xterm2ndg(XTerm x, Vector vlist) { xterm_1term(x, vlist); else if (n == 1) xterm_2term(x, vlist); - } + /** + * Processes an XTerm with one term to generate NDG constraints. + *

+ * The method examines the factor computed by {@code fcc(x)} and based on its value, + * creates and adds NDG constraints using parallel, perpendicular, or triple PI rules. + *

+ * + * @param x the XTerm to process + * @param vlist the vector where the generated NDG constraints will be added + */ protected void xterm_1term(XTerm x, Vector vlist) { long n = fcc(x); @@ -2422,6 +2843,16 @@ protected void xterm_1term(XTerm x, Vector vlist) { } } + /** + * Creates a Triple PI NDG constraint from the specified variable. + *

+ * It initializes the NDG using the points from the variable and reorders them, + * setting the number of points to 3. + *

+ * + * @param v the variable containing the points for the NDG constraint + * @return the constructed Triple PI NDG constraint + */ protected CNdg add_ndg_triplePI(Var v) { CNdg n = new CNdg(); n.type = NDG_TRIPLEPI; @@ -2436,7 +2867,16 @@ protected CNdg add_ndg_triplePI(Var v) { return n; } - + /** + * Processes an XTerm with two terms to generate NDG constraints. + *

+ * The method examines the second term of the XTerm and creates congruency or collinearity NDGs + * based on the sign of the factor computed by {@code fcc} for the second term. + *

+ * + * @param x the XTerm to process + * @param vlist the vector where the generated NDG constraints will be added + */ protected void xterm_2term(XTerm x, Vector vlist) { long n = fcc(x); if (x.ps != null) { @@ -2448,7 +2888,7 @@ protected void xterm_2term(XTerm x, Vector vlist) { Var v1 = x.var; Var v2 = x1.var; - if (v2 != null) { // v2 != null 0) { if (v1.pt[2] == v2.pt[2] && v1.pt[3] == v2.pt[3]) { @@ -2478,8 +2916,7 @@ protected void xterm_2term(XTerm x, Vector vlist) { } } } - } else // n.p[1]) { - int d = n.p[0]; - n.p[0] = n.p[1]; - n.p[1] = d; - } } + /** + * Reorders the points in an NDG constraint (with three points) into ascending order. + * + * @param n the NDG constraint whose points are to be reordered + */ protected void reorder3(CNdg n) { for (int i = 0; i < 2; i++) { - int d = n.p[i]; if (d > n.p[i + 1]) { n.p[i] = n.p[i + 1]; @@ -2516,6 +2944,14 @@ protected void reorder3(CNdg n) { } } + /** + * Reorders two pairs of points in an NDG constraint so that each pair is in ascending order. + *

+ * In addition, it ensures that the first pair is sorted relative to the second pair. + *

+ * + * @param n the NDG constraint whose points are to be reordered + */ protected void reorder22(CNdg n) { if (n.p[0] > n.p[1]) { int d = n.p[0]; @@ -2539,6 +2975,16 @@ protected void reorder22(CNdg n) { } } + /** + * Creates a non-equality NDG constraint for two points. + *

+ * Returns null if both points are identical. + *

+ * + * @param a the first point index + * @param b the second point index + * @return the NDG non-equality constraint, or null if the points are identical + */ protected CNdg add_ndg_neq(int a, int b) { if (a == b) return null; @@ -2557,113 +3003,15 @@ protected CNdg add_ndg_neq(int a, int b) { return n; } - protected void parse_ndg_neq(int a, int b, Vector v4) { - if (a == b) - return; - - if (a > b) { - int c = a; - a = b; - b = c; - } - - if (APT(a) == null && APT(b) == null) return; - - if (freeCSP(a) && freeCSP(b)) { - CNdg n = new CNdg(); - n.type = NDG_NON_ISOTROPIC; - n.p[0] = a; - n.p[1] = b; - n.no = 1; - add_ndgs(n, v4); - } else { - XTerm x = parseNEQ(a, b, v4); - if (x != null) - addxtermndg(x, v4); - } - } - - private XTerm parseNEQ(int a, int b, Vector v2) { - - for (int i = 0; i < v2.size(); i++) { - CNdg n = (CNdg) v2.get(i); - if (n.type == NDG_NEQ || n.type == NDG_NON_ISOTROPIC) { - { - XTerm x1 = parseNEQ(a, b, n.p[0], n.p[1], v2); - if (x1 != null) - return x1; - } - } else if (n.type == NDG_COLL) { - { - XTerm x1 = parseNEQ(a, b, n.p[0], n.p[1], v2); - if (x1 != null) - return x1; - x1 = parseNEQ(a, b, n.p[0], n.p[2], v2); - if (x1 != null) - return x1; - x1 = parseNEQ(a, b, n.p[1], n.p[2], v2); - if (x1 != null) - return x1; - } - } - } - return null; - } - - - private XTerm parseNEQ(int a, int b, int a1, int b1, Vector v2) { - if (a == a1 || a == b1) return null; - if (b == a1 || b == b1) return null; - if (!freeCSP(a1) || !freeCSP(b1)) - return null; - if (check_coll(a1, b1, a) || check_coll(a1, b1, b)) - return null; - - XTerm x1 = pminus(trim_f(a, a1, a1, b1), trim_f(b, a1, a1, b1)); - XTerm x2 = pminus(trim_f(a, b1, a1, b1), trim_f(b, b1, a1, b1)); - this.setPrintToScreen(); - - this.pprint(x1); - this.pprint(x2); - - x1 = angle_deduction(x1); - x2 = angle_deduction(x2); - if (eq_poly(x1, x2)) return x1; - x2 = this.neg_poly(x2); - if (eq_poly(x1, x2)) return x1; - this.pprint(x1); - this.pprint(x2); - return null; - } - - private void addPairsToList(Object o, Object o1, Vector v) { - int n = v.size() / 2; - for (int i = 0; i < n; i++) { - if (o == v.get(2 * i) && o1 == v.get(2 * i + 1)) - return; - if (o1 == v.get(2 * i) && o == v.get(2 * i + 1)) - return; - } - v.add(o); - v.add(o1); - } - - public int getFreeSemiFix(int index) { - ProPoint pt = APT(index); - if (pt == null) - return 0; - - int n = 0; - for (int i = 1; i <= cns_no; i++) { - Cons c = allcns[i]; - if (c.ps[0] == index && !freeCS(c.type)) { - n++; - } - } - - return n; - } - + /** + * Checks whether the point at the given index is free from constraints. + *

+ * It retrieves the associated point object and checks its construction type. + *

+ * + * @param index the index of the point to check + * @return true if the point is free; false otherwise + */ public boolean freeCSP(int index) { ProPoint pt = APT(index); if (pt == null) @@ -2681,11 +3029,31 @@ public boolean freeCSP(int index) { return freeCS(type); } + /** + * Determines if the given construction type represents a free state. + *

+ * A type is considered free if it matches one of the basic construction types. + *

+ * + * @param t the construction type to check + * @return true if the type is free; false otherwise + */ public boolean freeCS(int t) { return t == 0 || t == C_POINT || t == C_LINE || t == C_TRIANGLE || t == C_QUADRANGLE || t == C_PENTAGON || t == C_POLYGON || t == C_CIRCLE; } + /** + * Creates a collinearity NDG constraint from three points. + *

+ * The points are reordered to ensure proper ordering. If redundant, then null is returned. + *

+ * + * @param a the first point index + * @param b the second point index + * @param c the third point index + * @return the NDG collinearity constraint, or null if the points are redundant + */ protected CNdg add_ndg_coll(int a, int b, int c) { CNdg n = new CNdg(); n.type = NDG_COLL; @@ -2700,6 +3068,18 @@ protected CNdg add_ndg_coll(int a, int b, int c) { else return n; } + /** + * Creates a congruency NDG constraint based on four points. + *

+ * The points are reordered; if the set of points is redundant, null is returned. + *

+ * + * @param a the first point index of the first segment + * @param b the second point index of the first segment + * @param c the first point index of the second segment + * @param d the second point index of the second segment + * @return the NDG congruency constraint, or null if the points are redundant + */ protected CNdg add_ndg_cong(int a, int b, int c, int d) { CNdg n = new CNdg(); n.type = NDG_CONG; @@ -2715,11 +3095,29 @@ protected CNdg add_ndg_cong(int a, int b, int c, int d) { else return null; } - + /** + * Creates a parallel NDG constraint using the points of a given variable. + * + * @param v the variable containing the points for the constraint + * @return the NDG parallel constraint + */ protected CNdg add_ndg_para(Var v) { return add_ndg_para(v.pt[0], v.pt[1], v.pt[2], v.pt[3]); } + /** + * Creates a parallel NDG constraint based on four point indices. + *

+ * The points are reordered to ascending order; if the set is redundant, + * an alternative collinearity constraint is constructed instead. + *

+ * + * @param a the first point index of the first segment + * @param b the second point index of the first segment + * @param c the first point index of the second segment + * @param d the second point index of the second segment + * @return the NDG parallel constraint, or an alternative NDG constraint if redundant + */ protected CNdg add_ndg_para(int a, int b, int c, int d) { CNdg n = new CNdg(); n.type = NDG_PARA; @@ -2748,10 +3146,28 @@ protected CNdg add_ndg_para(int a, int b, int c, int d) { return n; } + /** + * Creates a perpendicular NDG constraint using the points of a given variable. + * + * @param v the variable containing the points for the constraint + * @return the NDG perpendicular constraint + */ protected CNdg add_ndg_perp(Var v) { return add_ndg_perp(v.pt[0], v.pt[1], v.pt[2], v.pt[3]); } + /** + * Creates a perpendicular NDG constraint based on four point indices. + *

+ * If the two segments are identical, a non-isotropic NDG constraint is created instead. + *

+ * + * @param a the first point index of the first segment + * @param b the second point index of the first segment + * @param c the first point index of the second segment + * @param d the second point index of the second segment + * @return the NDG perpendicular constraint, or a non-isotropic constraint when applicable + */ protected CNdg add_ndg_perp(int a, int b, int c, int d) { CNdg n = new CNdg(); n.type = NDG_PERP; @@ -2771,6 +3187,12 @@ protected CNdg add_ndg_perp(int a, int b, int c, int d) { } + /** + * Sets the string representation (sd) of the given NDG constraint (d) based on its type + * and associated points. Depending on the type, constructs a descriptive message. + * + * @param d the NDG constraint for which the string representation is set + */ protected void get_ndgstr(CNdg d) { String sd = ""; switch (d.type) { @@ -2804,10 +3226,12 @@ protected void get_ndgstr(CNdg d) { int a, b; if (d.p[0] == n) a = d.p[1]; - else a = d.p[0]; + else + a = d.p[0]; if (d.p[2] == n) b = d.p[3]; - else b = d.p[2]; + else + b = d.p[2]; sd = Cm.ANGLE_SIGN + "[" + ANAME(a) + ANAME(n) + ANAME(b) + "] != (n*PI) / 3 (n = 0, 1, 2, 3 ..)"; @@ -2818,8 +3242,15 @@ protected void get_ndgstr(CNdg d) { d.sd = sd; } + /** + * Performs angle deduction on the given XTerm. This method initializes necessary properties + * and iteratively attempts to eliminate terms using various elimination methods. At the end, + * it optimizes the term based on triangle configurations. + * + * @param p1 the XTerm on which angle deduction is performed + * @return the resulting XTerm after angle deduction + */ protected XTerm angle_deduction(XTerm p1) { - ertype = 0; pro_type = PRO_FULL; max_term = 0; @@ -2827,11 +3258,11 @@ protected XTerm angle_deduction(XTerm p1) { qerror = false; last_pr = proof = new GrTerm(); dbase(); - if (qerror) return null; + if (qerror) + return null; ElTerm e1 = null; do { - if (npoly(p1)) { return p1; } @@ -2857,12 +3288,18 @@ protected XTerm angle_deduction(XTerm p1) { } } while (e1 != null); - p1 = opt_tri(p1); return p1; } - + /** + * Optimizes the given XTerm by detecting and processing triangle configurations. + * It compares factors from the current term and its subterm to determine if any adjustment + * such as scaling or subtraction should be applied. + * + * @param x the XTerm to be optimized + * @return the optimized XTerm + */ public XTerm opt_tri(XTerm x) { long n = fcc(x); if (x.ps != null) { @@ -2880,7 +3317,6 @@ public XTerm opt_tri(XTerm x) { p1 = ptimes(this.get_n(n), p1); return pminus(x, p1); } - } else if (v1.pt[0] == v2.pt[2] && v1.pt[1] == v2.pt[3]) { XTerm p1 = pplus(get_m(v1), get_m(v2)); p1 = pminus(p1, trim_f(v2.pt[0], v2.pt[1], v1.pt[2], v1.pt[3])); @@ -2911,25 +3347,39 @@ public XTerm opt_tri(XTerm x) { return x; } - //////////////////////////////////////////////////////////////////////////////// - //ndg deduction. + /** + * Performs NDG (non-degeneracy) deduction on a set of NDG constraints. + * For each constraint in the source vector v3, if the constraint is marked as existing + * or if all its points are free, it is directly added or duplicated into the target vector v4. + * Otherwise, angle deduction is applied. + * + * @param v3 the source vector of NDG constraints + * @param v4 the target vector to store the deduced NDG constraints + */ public void ndg_deduction(Vector v3, Vector v4) { - for (int i = 0; i < v3.size(); i++) { CNdg d = (CNdg) v3.get(i); if (d.exists) { + // Existing NDG constraints are skipped. } else if (ck_allFree(d)) { CNdg d1 = new CNdg(d); v4.add(d1); - } else + } else { angle_deduction(d, v4); + } } } - + /** + * Compares two NDG constraints based on their maximum integer values. + * + * @param d1 the first NDG constraint + * @param d2 the second NDG constraint + * @return a positive value if d1 > d2, a negative value if d1 < d2, or zero if they are equal + */ public int compare(CNdg d1, CNdg d2) { - if (d1 == d2) return 0; - + if (d1 == d2) + return 0; int n1 = d1.getMaxInt(); int n2 = d2.getMaxInt(); if (n1 > n2) @@ -2939,6 +3389,12 @@ public int compare(CNdg d1, CNdg d2) { return 0; } + /** + * Sorts a vector of NDG constraints in ascending order based on their significance. + * It uses the compare method to insert each constraint into its correct position in the vector. + * + * @param v4 the vector containing NDG constraints to be sorted + */ public void sortVector(Vector v4) { for (int i = 1; i < v4.size(); i++) { CNdg d = (CNdg) v4.get(i); @@ -2954,6 +3410,17 @@ public void sortVector(Vector v4) { } } + /** + * Parses non-equality and non-isotropic NDG constraints from the given vector. + *

+ * This method sorts the input vector of NDG constraints, filters out those + * constraints that are non-equality (NDG_NEQ) or non-isotropic (NDG_NON_ISOTROPIC) + * and have both points free, and then processes the remaining constraints. + * The remaining constraints are added to a global NDG list after being updated. + *

+ * + * @param v4 the vector containing NDG constraints to be parsed + */ public void parse_neq(Vector v4) { sortVector(v4); @@ -2971,7 +3438,7 @@ public void parse_neq(Vector v4) { i--; } -// vndgs.clear(); + // vndgs.clear(); vndgs.addAll(v4); for (int i = 0; i < v5.size(); i++) { @@ -2987,6 +3454,15 @@ public void parse_neq(Vector v4) { return; } + /** + * Recursively updates the string documentation (SD) for the provided NDG constraint structure. + *

+ * For each constraint in the structure, the method updates its point string array and resets its text. + * The method also recurses into any child constraint sets. + *

+ * + * @param dd the NDG constraint structure to update + */ private void updateSD(NdgCs dd) { if (dd == null) return; @@ -3003,7 +3479,18 @@ private void updateSD(NdgCs dd) { updateSD(dd.child[i]); } - public NdgCs getCS(CNdg d) {// d : type of neq. + /** + * Constructs and returns an NDG constraint set (NdgCs) associated with the given inequality constraint. + *

+ * The method iterates through existing constraints and gathers those related to + * the points of the provided constraint. The collected constraints are then added + * to a new NdgCs structure and updated. + *

+ * + * @param d the NDG inequality constraint used as a basis for gathering related constraints + * @return the constructed NDG constraint set (NdgCs) + */ + public NdgCs getCS(CNdg d) { int n = d.getMaxInt(); NdgCs c = new NdgCs(); @@ -3038,6 +3525,11 @@ public NdgCs getCS(CNdg d) {// d : type of neq. return dd; } + /** + * Updates the point string array (pss) of the specified constraint using the global points array. + * + * @param c the constraint whose point string array is to be updated + */ private void updatePSS(Cons c) { if (c == null) return; @@ -3047,6 +3539,15 @@ private void updatePSS(Cons c) { } } + /** + * Recursively adds all constraints related to the constraint at index nx into the provided NDG constraint set. + *

+ * For each point within the constraint, the method checks previous constraints for related ones and adds them. + *

+ * + * @param nx the index of the current constraint in the global constraints array + * @param d the NDG constraint set (NdgCs) where related constraints are added + */ private void add_RelatedCnsToDg(int nx, NdgCs d) { Cons c = allcns[nx]; @@ -3070,6 +3571,15 @@ private void add_RelatedCnsToDg(int nx, NdgCs d) { d.add(nx, c); } + /** + * Adds the provided constraint to the given NDG constraint set. + *

+ * Based on the type of the constraint, it may clone the constraint or generate additional constraints. + *

+ * + * @param c the constraint to be added + * @param d the NDG constraint set (NdgCs) that will include the constraint + */ public void addConsToNdgcs(Cons c, NdgCs d) { if (c == null) return; @@ -3124,6 +3634,19 @@ public void addConsToNdgcs(Cons c, NdgCs d) { } } + /** + * Creates a new constraint with 7 points and adds it to the specified NDG constraint set. + * + * @param type the type of the new constraint + * @param a the first point index + * @param b the second point index + * @param c the third point index + * @param d the fourth point index + * @param e the fifth point index + * @param f the sixth point index + * @param g the seventh point index + * @param d1 the NDG constraint set (NdgCs) where the new constraint will be added + */ public void add_cons(int type, int a, int b, int c, int d, int e, int f, int g, NdgCs d1) { Cons c1 = new Cons(type); c1.add_pt(a); @@ -3137,6 +3660,16 @@ public void add_cons(int type, int a, int b, int c, int d, int e, int f, int g, d1.add(c1); } + /** + * Creates a new constraint with 4 points and adds it to the specified NDG constraint set. + * + * @param type the type of the new constraint + * @param a the first point index + * @param b the second point index + * @param c the third point index + * @param d the fourth point index + * @param d1 the NDG constraint set (NdgCs) where the new constraint will be added + */ public void add_cons(int type, int a, int b, int c, int d, NdgCs d1) { Cons c1 = new Cons(type); c1.add_pt(a); @@ -3147,6 +3680,17 @@ public void add_cons(int type, int a, int b, int c, int d, NdgCs d1) { d1.add(c1); } + /** + * Checks whether the specified constraint is recursively valid with respect to the given NDG type. + *

+ * Depending on the type of the constraint, it recursively checks if related NDG constraints already exist. + *

+ * + * @param c the constraint to check + * @param cs the NDG constraint set (NdgCs) in which the check is performed + * @param type the NDG type against which the constraint is validated + * @return true if the constraint is valid; false otherwise + */ public boolean ck_right(Cons c, NdgCs cs, int type) { if (c == null || cs == null) return true; @@ -3164,11 +3708,19 @@ public boolean ck_right(Cons c, NdgCs cs, int type) { return true; } + /** + * Removes NDG constraint set nodes that have no constraints from the provided NDG structure. + *

+ * This method recursively traverses the child NDG constraint sets and nullifies any reference that + * does not contain constraints. + *

+ * + * @param c the NDG constraint set (NdgCs) from which null nodes will be removed + */ private void rm_null_ndgcs(NdgCs c) { if (c == null) return; - int n = c.getCSindex(); for (int i = 0; i <= n; i++) { NdgCs cc = c.child[i]; @@ -3190,6 +3742,15 @@ private void rm_null_ndgcs(NdgCs c) { } } + /** + * Removes extraneous constraints from the given NDG constraint set. + *

+ * At a leaf node, this method nullifies any constraints that are marked as extraneous. + * For non-leaf nodes, the method recurses through each child NDG constraint set. + *

+ * + * @param c the NDG constraint set (NdgCs) from which extraneous constraints will be removed + */ private void rm_excons(NdgCs c) { if (c == null) return; @@ -3211,6 +3772,14 @@ private void rm_excons(NdgCs c) { } } + /** + * Checks if the constraint at the given index in the NDG constraint set is extraneous + * by comparing it with the corresponding constraint at the root of the constraint set. + * + * @param cs the NDG constraint set + * @param index the index of the constraint to check + * @return true if the constraint is considered extraneous; false otherwise + */ private boolean cons_ex(NdgCs cs, int index) { Cons c = cs.allcns[index]; @@ -3225,6 +3794,15 @@ private boolean cons_ex(NdgCs cs, int index) { return c1.isEqual(c); } + /** + * Recursively checks constraints in an NDG constraint set for consistency. + * For leaf nodes, it verifies each constraint against its expected conditions; + * for non-leaf nodes, it cleans up inconsistent child sets. + * + * @param c the NDG constraint set to check + * @param type the type identifier for the check; usage depends on the context + * @return true if the constraint set is consistent; false otherwise + */ public boolean ck_right(NdgCs c, int type) { if (c == null) return true; @@ -3232,7 +3810,6 @@ public boolean ck_right(NdgCs c, int type) { NdgCs[] css = c.child; int a = c.getCSindex(); if (a < 0) { // leaf node. - for (int i = 0; i <= c.no; i++) { if (c.allcns[i] == null) continue; @@ -3255,6 +3832,13 @@ public boolean ck_right(NdgCs c, int type) { return true; } + /** + * Parses non-equality and non-isotropic NDG constraints by replacing point indices, + * reordering constraints, and invoking further parsing, cleanup, and optimization steps. + * + * @param nd the NDG constraint to be parsed + * @return the updated NDG constraint set after parsing + */ public NdgCs parse_neq(CNdg nd) { NdgCs c = getCS(nd); NdgCs cx = new NdgCs(c); @@ -3277,9 +3861,9 @@ public NdgCs parse_neq(CNdg nd) { } parseStep(cx); ck_leaf(c); - rm_excons(c); // remove exists cons - rm_null_ndgcs(c); // remove ndgcs without child. - ck_right(c, 1); // remove cons which is contradict with its parents. + rm_excons(c); // remove existing constraints + rm_null_ndgcs(c); // remove NDG sets without children + ck_right(c, 1); // remove constraints contradicting with parents int n1 = c.getCSindex(); ck_right(c, 0); if (n1 >= 0 && c.getCSindex() < 0) @@ -3289,9 +3873,13 @@ public NdgCs parse_neq(CNdg nd) { return c; } - //////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////// - + /** + * Compares two constraints based on their last point and type. + * + * @param c1 the first constraint + * @param c2 the second constraint + * @return a positive integer if c1 > c2, a negative integer if c1 < c2, or 0 if they are equal + */ private int compare(Cons c1, Cons c2) { if (c1 == null) { if (c2 == null) @@ -3314,6 +3902,13 @@ private int compare(Cons c1, Cons c2) { return 0; } + /** + * Reorders constraints within an NDG constraint set. + * For leaf nodes, it sorts the constraints in ascending order; + * for non-leaf nodes, it recursively reorders each child set. + * + * @param c the NDG constraint set to reorder + */ private void cons_reorder(NdgCs c) { if (c == null) return; @@ -3325,7 +3920,6 @@ private void cons_reorder(NdgCs c) { c.allcns[i] = c.allcns[j]; c.allcns[j] = null; } - } else { if (c.allcns[j] != null) { if (compare(c.allcns[i], c.allcns[j]) > 0) { @@ -3345,6 +3939,12 @@ private void cons_reorder(NdgCs c) { } } + /** + * Checks whether an NDG constraint set is a leaf node. + * A node is considered a leaf if it has no child NDG constraint sets. + * + * @param c the NDG constraint set to check + */ private void ck_leaf(NdgCs c) { if (c == null) return; @@ -3357,8 +3957,12 @@ private void ck_leaf(NdgCs c) { } } + /** + * Recursively removes non-leaf NDG constraint set nodes that are not required. + * + * @param c the NDG constraint set from which non-leaf nodes will be removed + */ private void rm_nleaf(NdgCs c) { - if (c == null || c.leaf) return; @@ -3375,23 +3979,28 @@ private void rm_nleaf(NdgCs c) { for (int i = 0; i <= n; i++) { rm_nleaf(c.child[i]); } - } } - private boolean parseStep(NdgCs c) { // Main Process of Parsing. + /** + * Main process for parsing constraints within the NDG constraint set. + * This method performs optimization, redundant constraint removal, and processes + * constraints based on their maximum index. + * + * @param c the NDG constraint set to parse + * @return true if parsing completes successfully; otherwise, false + */ + private boolean parseStep(NdgCs c) { if (c == null) return true; - - opt_cons(c); // reorder. P to L + opt_cons(c); // reorder constraints (P to L) rm_redundent(c); if (c.getNotNullNum() <= 1) return true; int max = c.getMaxCnsInt(); - int n = c.no; for (int i = 0; i <= n; i++) { Cons c1 = c.allcns[i]; @@ -3402,7 +4011,6 @@ private boolean parseStep(NdgCs c) { // Main Process of Parsing. for (int j = i + 1; j <= n; j++) { Cons c2 = c.allcns[j]; - if (c2 == null) continue; if (c2.getLastPt() != max) @@ -3432,20 +4040,28 @@ private boolean parseStep(NdgCs c) { // Main Process of Parsing. break; } break; - - case C_CIRCUM: { + case C_CIRCUM: switch (c2.type) { case C_CIRCUM: parse_ndg_circums(c, c1, c2); break; } - } + break; } } } return true; } + /** + * Processes cyclic NDG constraints by identifying collinear points among + * the constraints and generating additional equality constraints as needed. + * + * @param c the NDG constraint set containing the constraints + * @param c1 the first constraint to compare + * @param c2 the second constraint to compare + * @return false after processing is complete + */ private boolean parse_ndg_circums(NdgCs c, Cons c1, Cons c2) { int o = c1.ps[0]; @@ -3475,9 +4091,8 @@ private boolean parse_ndg_circums(NdgCs c, Cons c1, Cons c2) { switch (cx.type) { case C_O_L: if (xcoll(pp[i], pp[j], pp[k])) { - if (!ck_recursive_ndg(1, c, NDG_NEQ, pp[i], pp[j], 0, 0)) { - NdgCs nc1 = new NdgCs(c); // ! Collinear A, B, C + NdgCs nc1 = new NdgCs(c); // ! Collinear A, B, C nc1.parent = c; c.addChild(nc1); Cons cc = new Cons(C_I_EQ); @@ -3487,9 +4102,8 @@ private boolean parse_ndg_circums(NdgCs c, Cons c1, Cons c2) { ndg_pteq_added(cc, nc1); parseStep(nc1); } - if (!ck_recursive_ndg(1, c, NDG_NEQ, pp[i], pp[k], 0, 0)) { - NdgCs nc1 = new NdgCs(c); // ! Collinear A, B, C + NdgCs nc1 = new NdgCs(c); // ! Collinear A, B, C nc1.parent = c; c.addChild(nc1); Cons cc = new Cons(C_I_EQ); @@ -3499,9 +4113,8 @@ private boolean parse_ndg_circums(NdgCs c, Cons c1, Cons c2) { ndg_pteq_added(cc, nc1); parseStep(nc1); } - if (!ck_recursive_ndg(1, c, NDG_NEQ, pp[i], pp[j], 0, 0)) { - NdgCs nc1 = new NdgCs(c); // ! Collinear A, B, C + NdgCs nc1 = new NdgCs(c); // ! Collinear A, B, C nc1.parent = c; c.addChild(nc1); Cons cc = new Cons(C_I_EQ); @@ -3519,14 +4132,16 @@ private boolean parse_ndg_circums(NdgCs c, Cons c1, Cons c2) { } } } - return false; } - private boolean onOneCons(int a, int b, Cons c1) { - return c1.contains(a) && c1.contains(b); - } - + /** + * Adds point p to the array pp if it is not already present. + * The method fills the first available zero slot. + * + * @param p the point index to add + * @param pp the array of point indices + */ private void addPtNoRedunent(int p, int[] pp) { for (int i = 0; i < pp.length; i++) { if (pp[i] == p) @@ -3538,6 +4153,15 @@ private void addPtNoRedunent(int p, int[] pp) { } } + /** + * Parses NDG constraints of type LL by comparing two constraints and creating new NDG constraint sets. + * It creates new equality or collinearity constraints based on the matched point indices. + * + * @param c the NDG constraint set + * @param c1 the first constraint to compare + * @param c2 the second constraint to compare + * @return true if parsing takes place; false otherwise + */ private boolean parse_ndg_ll(NdgCs c, Cons c1, Cons c2) { int n1 = c1.getLastPt(); @@ -3566,9 +4190,8 @@ private boolean parse_ndg_ll(NdgCs c, Cons c1, Cons c2) { } else return false; - //if (ck_recursive_ndg(c, NDG_COLL, m, a, b, 0)) { - NdgCs nc1 = new NdgCs(c); // ! Collinear A, B, C + NdgCs nc1 = new NdgCs(c); // Collinear A, B, C nc1.parent = c; c.addChild(nc1); Cons cc = new Cons(C_I_EQ); @@ -3581,7 +4204,7 @@ private boolean parse_ndg_ll(NdgCs c, Cons c1, Cons c2) { } if (!ck_recursive_ndg(1, c, NDG_COLL, m, a, b, 0)) { - NdgCs nc2 = new NdgCs(c); // Collinear M A B; A != B + NdgCs nc2 = new NdgCs(c); // Collinear M A B; A != B nc2.parent = c; c.addChild(nc2); Cons cc = new Cons(C_O_L); @@ -3593,9 +4216,8 @@ private boolean parse_ndg_ll(NdgCs c, Cons c1, Cons c2) { parseStep(nc2); } - if (!ck_recursive_ndg(1, c, NDG_NEQ, a, b, 0, 0)) { - NdgCs nc3 = new NdgCs(c); // A = B. + NdgCs nc3 = new NdgCs(c); // A = B. nc3.parent = c; c.addChild(nc3); Cons cc = new Cons(C_I_EQ); @@ -3610,7 +4232,20 @@ private boolean parse_ndg_ll(NdgCs c, Cons c1, Cons c2) { return true; } - + /** + * Recursively checks for an NDG constraint that meets the specified parameters. + * In global mode (type 0) the search is performed in the global NDG list, + * while in recursive mode (type 1) the search goes through the current constraint set's parent chain. + * + * @param type the check mode (0 for global, 1 for recursive search) + * @param cs the NDG constraint set to check within + * @param t the NDG type to check (e.g. NDG_COLL, NDG_NEQ) + * @param a the first point index involved in the constraint + * @param b the second point index involved in the constraint + * @param c the third point index, or 0 if not used + * @param d the fourth point index, or 0 if not used + * @return true if a matching NDG constraint is found; false otherwise + */ private boolean ck_recursive_ndg(int type, NdgCs cs, int t, int a, int b, int c, int d) { if (type == 0) { @@ -3630,7 +4265,6 @@ private boolean ck_recursive_ndg(int type, NdgCs cs, int t, int a, int b, int c, if (dd == null) return false; - while (cs != null) { if (cs.nd != null && ck_ndg(t, a, b, c, d, cs.nd)) return true; @@ -3640,6 +4274,19 @@ private boolean ck_recursive_ndg(int type, NdgCs cs, int t, int a, int b, int c, return false; } + /** + * Checks if the provided NDG constraint (dd) satisfies the condition for the given NDG type. + * For collinearity (NDG_COLL), it checks if the constraint contains the three specified points. + * For inequality types (NDG_NEQ or NDG_NON_ISOTROPIC), it checks if the constraint contains the two specified points. + * + * @param t the NDG type to evaluate (e.g. NDG_COLL, NDG_NEQ) + * @param a the first point index + * @param b the second point index + * @param c the third point index, or 0 if not applicable + * @param d the fourth point index, or 0 if not applicable + * @param dd the NDG constraint to check + * @return true if the NDG constraint meets the criteria; false otherwise + */ private boolean ck_ndg(int t, int a, int b, int c, int d, CNdg dd) { boolean r = false; @@ -3648,28 +4295,29 @@ private boolean ck_ndg(int t, int a, int b, int c, int d, CNdg dd) { if (dd.type == NDG_COLL) { r = dd.contain(a) && dd.contain(b) && dd.contain(c); } else if (dd.type == NDG_NEQ || dd.type == NDG_NON_ISOTROPIC) { -// int n = 0; -// if (dd.contain(a)) -// n++; -// if (dd.contain(b)) -// n++; -// if (dd.contain(c)) -// n++; -// r = n >= 2; + // Condition for NDG_NEQ or NDG_NON_ISOTROPIC is omitted. } break; case NDG_NEQ: case NDG_NON_ISOTROPIC: if (dd.type == NDG_COLL) r = dd.contain(a) && dd.contain(b); - else if (dd.type == NDG_NEQ || dd.type == NDG_NON_ISOTROPIC) { + else if (dd.type == NDG_NEQ || dd.type == NDG_NON_ISOTROPIC) r = dd.contain(a) && dd.contain(b); - } break; } return r; } + /** + * Parses NDG constraints of type LT by comparing two constraints and creating new constraint sets. + * This method adjusts point orders and generates equality constraints when necessary. + * + * @param c the NDG constraint set + * @param c1 the first constraint to compare + * @param c2 the second constraint to compare + * @return true if parsing proceeded; false otherwise + */ private boolean parse_ndg_lt(NdgCs c, Cons c1, Cons c2) { int n1 = c1.getLastPt(); @@ -3711,11 +4359,10 @@ private boolean parse_ndg_lt(NdgCs c, Cons c1, Cons c2) { int x = a; a = b; b = x; - } // b = n1; - + } { - NdgCs nc2 = new NdgCs(c); // OtherWise. + NdgCs nc2 = new NdgCs(c); // Otherwise. nc2.parent = c; c.addChild(nc2); Cons cc2 = new Cons(C_I_EQ); @@ -3728,7 +4375,7 @@ private boolean parse_ndg_lt(NdgCs c, Cons c1, Cons c2) { } if (!ck_recursive_ndg(1, c, NDG_NEQ, m, b, 0, 0)) { - NdgCs nc2 = new NdgCs(c); // OtherWise. + NdgCs nc2 = new NdgCs(c); // Otherwise. nc2.parent = c; c.addChild(nc2); Cons cc2 = new Cons(C_I_EQ); @@ -3738,11 +4385,17 @@ private boolean parse_ndg_lt(NdgCs c, Cons c1, Cons c2) { ndg_pteq_added(cc2, nc2); nc2.nd = null; parseStep(nc2); - } return true; } + /** + * Updates the NDG constraint set by replacing occurrences of one point with another in all constraints. + * This method is used when a new equality constraint is added. + * + * @param c the newly added equality constraint + * @param d the NDG constraint set to update + */ private void ndg_pteq_added(Cons c, NdgCs d) { int m = c.ps[0]; int a = c.ps[1]; @@ -3755,6 +4408,13 @@ private void ndg_pteq_added(Cons c, NdgCs d) { d.add(c); } + /** + * Incorporates a collinearity NDG constraint into the provided NDG constraint set. + * This method updates related constraints by replacing point indices when necessary. + * + * @param c the collinearity constraint to add + * @param d the NDG constraint set to update + */ private void ndg_coll_added(Cons c, NdgCs d) { int m = c.ps[0]; int a = c.ps[1]; @@ -3776,7 +4436,7 @@ private void ndg_coll_added(Cons c, NdgCs d) { } break; case C_O_T: - case C_O_P: { + case C_O_P: if (c2.ps[0] == m) { if (c2.ps[1] == a) c2.ps[0] = b; @@ -3798,150 +4458,23 @@ else if (c2.ps[0] == b) else if (c2.ps[2] == b) c2.ps[3] = a; } - } - break; + break; } c2.reorder(); - } d.add(c); } -// private boolean parseStep(ndgcs c, int i, int j) { -// cons c1 = c.allcns[i]; -// cons c2 = c.allcns[j]; -// -// if (c1 == null || c2 == null) { -// return false; -// } -// -// int n1 = c1.getLastPt(); -// int n2 = c2.getLastPt(); -// -// switch (c1.type) { -// case C_O_L: { -// switch (c2.type) { -// case C_O_L: -// if (n1 == n2) { -// int m, a, b; -// if (c1.ps[1] == c2.ps[1]) { -// m = c1.ps[1]; -// a = c1.ps[2]; -// b = c2.ps[2]; -// } else if (c1.ps[1] == c2.ps[2]) { -// m = c1.ps[1]; -// a = c1.ps[2]; -// b = c2.ps[1]; -// } else if (c1.ps[2] == c2.ps[1]) { -// m = c1.ps[1]; -// a = c1.ps[1]; -// b = c2.ps[2]; -// } else if (c1.ps[2] == c2.ps[2]) { -// m = c1.ps[2]; -// a = c1.ps[1]; -// b = c2.ps[1]; -// } else -// break; -// -// parse_rpt_ndgs(n1, m, c); -// -// if (!ck_diff(a, b)) { -// ndgcs nc1 = new ndgcs(c); -// cndg d = new cndg(); -// d.type = NDG_NEQ; -// d.no = 1; -// d.p[0] = a; -// d.p[1] = b; -// nc1.nd = d; -// c.addChild(nc1); -// parse_neq1(nc1); -// } -// return true; -// } -// -// case C_O_T: -// int m, a, b; -// if (c2.ps[0] == c2.ps[2]) { -// m = c2.ps[0]; -// a = c2.ps[1]; -// b = c2.ps[3]; -// } else if (c2.ps[1] == c2.ps[2]) { -// m = c2.ps[1]; -// a = c2.ps[0]; -// b = c2.ps[3]; -// } else if (c2.ps[1] == c2.ps[3]) { -// m = c2.ps[1]; -// a = c2.ps[0]; -// b = c2.ps[2]; -// } else if (c2.ps[0] == c2.ps[3]) { -// m = c2.ps[0]; -// a = c2.ps[1]; -// b = c2.ps[2]; -// } else -// break; -// if (!(c1.contains(m) && c1.contains(a) && c1.contains(b))) -// break; -// int x = a; -// if (x < b) -// x = b; -// if (x < m) { -// int t = x; -// x = m; -// m = t; -// } -// parse_rpt_ndgs(x, m, c); -// break; -// } -// break; -// } -// } -// return false; -// } - - public void parse_rpt_ndgs(int m, int a, NdgCs c) { - if (m == a) - return; - if (m < a) { - int t = m; - m = a; - a = t; - } - - NdgCs nc1 = new NdgCs(c); - nc1.parent = c; - c.addChild(nc1); - nc1.replace(m, a); - opt_cons(nc1); - rm_redundent(nc1); - nc1.rm_common(); - parseStep(nc1); - } - - - private boolean ck_diff(int a, int b) { - for (int i = 0; i < vndgs.size(); i++) { - CNdg d = (CNdg) vndgs.get(i); - switch (d.type) { - case NDG_COLL: - if (d.contain(a) && d.contain(b)) - return true; - break; - case NDG_NEQ: - case NDG_NON_ISOTROPIC: - if (d.contain(a) && d.contain(b)) - return true; - case NDG_PARA: - case NDG_PERP: - if (d.contain2(a, b)) - return true; - break; - } - } - return false; - } - + /** + * Optimizes constraints within the provided NDG constraint set. + *

+ * This method iterates over each constraint, attempts to optimize it using the + * overloaded opt_cons method, and applies equality replacements if modifications occur. + *

+ * + * @param c the NDG constraint set to optimize + */ private void opt_cons(NdgCs c) { - while (true) { boolean r = true; @@ -3974,7 +4507,18 @@ private void opt_cons(NdgCs c) { } } - + /** + * Attempts to optimize a single constraint within the given NDG constraint set. + *

+ * The method simplifies or converts the constraint based on its type. + * For instance, certain conditions on C_O_P may result in converting it to C_O_L, + * while a C_O_T constraint may be simplified to an equality constraint. + *

+ * + * @param cs the NDG constraint set containing the constraint + * @param c the constraint to optimize + * @return true if the constraint was modified; false otherwise + */ private boolean opt_cons(NdgCs cs, Cons c) { if (c == null) return false; @@ -4043,6 +4587,18 @@ private boolean opt_cons(NdgCs cs, Cons c) { return false; } + /** + * Adds an equality constraint between two points into the specified NDG constraint set. + *

+ * If no existing equality constraint is found for the given non-zero points, + * this method creates a new equality constraint (C_I_EQ) relating the two points. + *

+ * + * @param a the first point index + * @param b the second point index + * @param c the NDG constraint set where the equality constraint will be added + * @return true if a new equality constraint was added; false otherwise + */ private boolean add_eq(int a, int b, NdgCs c) { if (a == b) return false; @@ -4072,6 +4628,15 @@ private boolean add_eq(int a, int b, NdgCs c) { return true; } + /** + * Removes redundant constraints from the provided NDG constraint set. + *

+ * This method first removes constraints flagged as redundant based on internal criteria, + * and then eliminates duplicate constraints by comparing existing constraints. + *

+ * + * @param c the NDG constraint set from which redundant constraints will be removed + */ private void rm_redundent(NdgCs c) { for (int i = 0; i <= c.no; i++) { Cons c1 = c.allcns[i]; @@ -4093,6 +4658,16 @@ private void rm_redundent(NdgCs c) { } } + /** + * Checks if a given constraint is redundant. + *

+ * The redundancy is determined based on the type of the constraint and comparisons + * of its point indices, such as duplicated points in a collinearity or perpendicular constraint. + *

+ * + * @param c the constraint to evaluate + * @return true if the constraint is considered redundant; false otherwise + */ private boolean cons_redundent(Cons c) { switch (c.type) { case C_O_L: @@ -4108,6 +4683,16 @@ private boolean cons_redundent(Cons c) { return false; } + /** + * Determines whether a constraint type is considered related to construction operations. + *

+ * The method returns false for fundamental geometric element types (e.g., point, triangle, etc.) + * and for types within a specific range, indicating that additional construction steps are not required. + *

+ * + * @param t the constraint type identifier + * @return true if the constraint type is construction-related; false otherwise + */ public boolean construct_related(int t) { if (t == C_POINT || t == C_TRIANGLE || t == C_POLYGON || t == C_QUADRANGLE || t == C_PENTAGON || t == C_LINE || t == C_CIRCLE) @@ -4117,9 +4702,18 @@ public boolean construct_related(int t) { return true; } - + /** + * Recursively adds NDG constraints from the provided NDG constraint set. + *

+ * For non-leaf nodes, the method traverses each child NDG set to add constraints. + * For leaf nodes, it attempts to add an NDG constraint based on the first non-null constraint encountered. + *

+ * + * @param d the NDG constraint set to process + * @param no the iteration limit based on the number of constraints in the set + * @return true if any NDG constraint was successfully added; false otherwise + */ private boolean addNdg(NdgCs d, int no) { - boolean r = false; int n = d.getCSindex(); @@ -4138,15 +4732,35 @@ private boolean addNdg(NdgCs d, int no) { for (int i = 0; i <= d.no; i++) { Cons c1 = d.allcns[i]; if (c1 != null) { - if (addNdg(c1)) { + if (addNdg(c1)) added = true; - } break; } } return added; } + /** + * Adds NDG constraint(s) for the specified geometric constraint. + * + *

+ * This method inspects the type of the provided constraint and adds the corresponding + * NDG constraint as follows: + *

+ *
    + *
  • C_O_L: Invokes add_n_coll to add a collinearity NDG constraint.
  • + *
  • C_O_P: Invokes add_ndg_para to add a parallelism NDG constraint and + * then registers it with add_ndgs.
  • + *
  • C_O_T: Invokes add_ndg_perp to add a perpendicularity NDG constraint and + * then registers it with add_ndgs.
  • + *
  • C_I_EQ: Invokes add_ndg_neq to add an equality NDG constraint and + * then registers it with add_ndgs.
  • + *
  • For any other constraint type, the method returns false without modification.
  • + *
+ * + * @param c the constraint to process for adding the corresponding NDG constraints + * @return true if the constraint was processed for NDG addition; false otherwise + */ private boolean addNdg(Cons c) { switch (c.type) { case C_O_L: @@ -4174,6 +4788,4 @@ private boolean addNdg(Cons c) { } private Vector vndgs = new Vector(); - - } diff --git a/src/main/java/gprover/GDD.java b/src/main/java/gprover/GDD.java index 6305e17e..949605ea 100644 --- a/src/main/java/gprover/GDD.java +++ b/src/main/java/gprover/GDD.java @@ -8,8 +8,20 @@ package gprover; +/** + * A class representing the geometric deduction system. + *

+ * This class extends GDDBase and implements additional algorithms for + * geometric constructions, predicate validations, and search operations used in + * the deduction process. + *

+ */ public class GDD extends GDDBase { + /** + * Performs the fixed point computation for the geometric deduction system. + * Processes all pending conditions, adjusts parameters, and collects results. + */ void fixpoint() { d_base = 0; test_ra = null; @@ -86,7 +98,11 @@ void fixpoint() { } /* Searching */ - + /** + * Searches for parallel line configurations within the specified PLine. + * + * @param pn the PLine in which to search. + */ final void search_pn(PLine pn) { if (pn == null) return; @@ -154,7 +170,11 @@ final void search_pn_coll(PLine pn) { } } - + /** + * Searches for line collisions within the specified PLine. + * + * @param pn the PLine to inspect. + */ final void search_pn_mds(PLine pn) { MidPt md = all_md.nx; @@ -166,6 +186,12 @@ final void search_pn_mds(PLine pn) { } } + /** + * Searches within a PLine for configurations based on the provided midpoint. + * + * @param pn the PLine in which to search. + * @param md the midpoint used for finding connections. + */ final void search_pn_md(PLine pn, MidPt md) { add_codb(CO_MIDP, md.m, md.a, md.b, 0, 0, 0, 0, 0); @@ -219,6 +245,12 @@ final void search_pn_md(PLine pn, MidPt md) { } } + /** + * Searches for additional line intersections and processes parallel connections. + * + * @param ln1 the first line. + * @param ln2 the second line. + */ final void search_pn_1(LLine ln1, LLine ln2) { if (ln1 == null) { // TODO. Handle this. @@ -249,19 +281,11 @@ final void search_pn_1(LLine ln1, LLine ln2) { } - final void search_pn_md(PLine pn1, LLine ln1, LLine ln2) { - MidPt md = all_md.nx; - if (md == null) return; - - add_codb(CO_MIDP, md.m, md.a, md.b, 0, 0, 0, 0, 0); - for (; md != null; md = md.nx) { - if (!ch_dep(md.dep)) break; - lm_md_connection(md, ln1, ln2); - lm_parallelogram(md, ln1, ln2); - } - pop_codb(); - } - + /** + * Searches for configurations in the given PLine based on TLine intersections. + * + * @param pn the PLine to search within. + */ final void search_pn_tns(PLine pn) { TLine tn = all_tn.nx; while (tn != null) { @@ -272,6 +296,12 @@ final void search_pn_tns(PLine pn) { } } +/** + * Searches for circle intersections within the provided PLine. + * Finds intersection points between each line in the PLine and the given circle. + * + * @param pn the PLine to search for circle intersections + */ public void search_pn_cr(PLine pn) { LLine l1, l2; ACir cr; @@ -299,6 +329,12 @@ public void search_pn_cr(PLine pn) { } + /** + * Processes a TLine for potential geometric relations. + * Checks intersections between the two lines forming the TLine and performs several searches. + * + * @param tn the TLine to process + */ final void search_tn(TLine tn) { co_db.nx = null; @@ -321,6 +357,12 @@ final void search_tn(TLine tn) { search_tn0(tn); } + /** + * Refines a TLine by attempting to adjust its defining lines. + * Replaces any degenerate line with a valid one if necessary, then adds a perpendicular condition. + * + * @param tn the TLine to adjust + */ final void search_tn0(TLine tn) { LLine ln1, ln2; if (tn.type == 0) return; @@ -341,6 +383,12 @@ final void search_tn0(TLine tn) { } } + /** + * Initiates the search for isosceles configurations in a TLine. + * Utilizes the intersection of the lines to search for isosceles triangle–like conditions. + * + * @param tn the TLine to search for isosceles configurations in + */ final void search_tn_iso(TLine tn) { int p = inter_lls(tn.l1, tn.l2); if (p == 0) return; @@ -348,6 +396,13 @@ final void search_tn_iso(TLine tn) { search_tn_iso1(p, tn.l2, tn.l1); } + /** + * Searches for isosceles or congruent configurations in a pair of lines with a shared intersection. + * + * @param p the common intersection point from the first line pair + * @param l1 the first line to check + * @param l2 the second line to check + */ final void search_tn_iso1(int p, LLine l1, LLine l2) { int p1, p2, p3; for (int i = 0; i <= l1.no; i++) @@ -391,6 +446,15 @@ final void search_tn_iso1(int p, LLine l1, LLine l2) { } + /** + * Processes circle-related configurations for a TLine. + * Searches for tangent conditions and square formations with respect to a circle. + * + * @param ln1 the first line of the TLine + * @param ln2 the second line of the TLine + * @param m the intersection point of ln1 and ln2 + * @param tn the source TLine being processed + */ final void search_tn_crs(LLine ln1, LLine ln2, int m, TLine tn) { int p2, p3, m2, m3; ACir cr = all_cir.nx; @@ -417,29 +481,37 @@ final void search_tn_crs(LLine ln1, LLine ln2, int m, TLine tn) { } } - - final private void search_tn_dim(TLine tn, int m, ACir cr) { - if (m == 0 || !on_cir(m, cr)) return; - LLine l1 = tn.l1; - LLine l2 = tn.l2; - int p1 = inter_lc1(l1, cr, m); - if (p1 == 0) return; - int p2 = inter_lc1(l2, cr, m); - if (p2 == 0) return; - - } - + /** + * Searches for midpoint configurations associated with a TLine. + * Iterates over all midpoints to find relevant relations with the given TLine. + * + * @param tn the TLine to search for midpoint relations + */ final void search_tn_mds(TLine tn) { for (MidPt md = all_md.nx; md != null && ch_dep(md.dep); md = md.nx) search_tn_md(tn, md); } + /** + * Searches through all TLine entries and, for each valid TLine, + * invokes search_tn_md with the given midpoint. + * + * @param md the midpoint used to relate TLine configurations + */ final void search_md_tns(MidPt md) { for (TLine tn = all_tn.nx; tn != null && tn.nx != null && ch_dep(tn.dep); tn = tn.nx) if (tn.type != 0) search_tn_md(tn, md); } + /** + * Processes a TLine with respect to a given midpoint. + * Determines the intersection of the TLine's defining lines and, + * if appropriate, adds midpoint-related constructions. + * + * @param tn the TLine to process + * @param md the midpoint used for validation and configuration + */ final void search_tn_md(TLine tn, MidPt md) { LLine ln1 = tn.l1; LLine ln2 = tn.l2; @@ -465,6 +537,12 @@ final void search_tn_md(TLine tn, MidPt md) { } } + /** + * Iterates through all available PLine entries and searches for + * TLine intersections within each PLine that meet the dependency criteria. + * + * @param tn the TLine serving as search criteria for parallel configurations + */ final void search_tn_pns(TLine tn) { PLine pn; pn = all_pn.nx; @@ -475,6 +553,14 @@ final void search_tn_pns(TLine tn) { } } + /** + * Searches for angle relationships between two TLine entities. + * Iterates over all angle configurations to determine additional + * angle-related constructions. + * + * @param tn1 the first TLine + * @param tn2 the second TLine + */ final void serach_tn2_as(TLine tn1, TLine tn2) { Angles as = all_as.nx; if (tn1.type == 0) return; @@ -486,6 +572,16 @@ final void serach_tn2_as(TLine tn1, TLine tn2) { } } + /** + * Processes interactions between a TLine and all other TLine entries. + * Evaluates perpendicular and cyclic configurations based on the + * intersections of the defining lines and applies necessary constructions. + * + * @param tn the source TLine to compare + * @param ln1 one of the lines defining the source TLine + * @param ln2 the other line defining the source TLine + * @param p1 the intersection point of ln1 and ln2 + */ final void search_tn_tn(TLine tn, LLine ln1, LLine ln2, int p1) { TLine tn1; PLine pn; @@ -563,6 +659,13 @@ final void search_tn_tn(TLine tn, LLine ln1, LLine ln2, int p1) { } } + /** + * Searches for various circle configurations within the specified circle. + * Evaluates diameter conditions, inscribed angle relationships, + * and parallel intersections related to the circle. + * + * @param cr1 the circle to process + */ final void search_cr(ACir cr1) { int p1, p2, p3, p4, i, j, k; co_db.nx = null; @@ -623,6 +726,13 @@ final void search_cr(ACir cr1) { adj_cir1(cr1); } + /** + * Searches for midpoint configurations related to the given circle. + * If the circle's center coincides with a midpoint, constructs the appropriate + * cyclic configurations based on the circle and the midpoint's endpoints. + * + * @param cr the circle to process for midpoint relationships + */ final void search_cr_md(ACir cr) { MidPt md = all_md.nx; if (cr.pt[1] == 0) return; @@ -649,6 +759,13 @@ final void search_cr_md(ACir cr) { } } + /** + * Searches for additional circle line intersections within a PLine. + * + * @param cr1 the circle to search intersections with + * @param p1 the first point index defining the line + * @param p2 the second point index defining the line + */ final void search_cr_pn(ACir cr1, int p1, int p2) { int i, p3, p4; LLine l1, l2; @@ -666,7 +783,12 @@ final void search_cr_pn(ACir cr1, int p1, int p2) { } } - + /** + * Searches for tangent configurations between the given circle and a TLine. + * + * @param cr1 the circle to check for tangency conditions + * @param tn the TLine used for searching tangent intersections + */ final void search_cr_tan(ACir cr1, TLine tn) { if (cr1.o == 0 || cr1.no < 1) return; @@ -709,6 +831,11 @@ final void search_cr_tan(ACir cr1, TLine tn) { } } + /** + * Searches for circle circle intersections between the provided circle and all other circles. + * + * @param cr1 the circle to search for intersections with other circles + */ final void search_cr_cr(ACir cr1) { ACir cr2; int p1, p2; @@ -746,6 +873,13 @@ final void search_cr_cr(ACir cr1) { } } + /** + * Searches for isosceles configurations related to a circle using a line segment defined by two points. + * + * @param cr1 the circle to process + * @param p1 the first point index defining the segment + * @param p2 the second point index defining the segment + */ final void search_cr_iso(ACir cr1, int p1, int p2) { int p3 = fd_pt_md(p1, p2); if (p3 != 0) { @@ -755,6 +889,12 @@ final void search_cr_iso(ACir cr1, int p1, int p2) { } } + /** + * Searches and constructs midpoint related cyclic configurations for the given circle. + * + * @param cr the circle to process + * @param md the midpoint data structure containing endpoints and the midpoint + */ final void search_cr_md(ACir cr, MidPt md) { int o = cr.o; if (o == 0) return; @@ -776,6 +916,11 @@ final void search_cr_md(ACir cr, MidPt md) { } } + /** + * Searches for congruent configurations by evaluating circle properties. + * + * @param cr1 the circle used to search congruence conditions between its intersection points + */ final void search_cr_cg(ACir cr1) { if (cr1.o != 0) { for (int i = 0; i <= cr1.no; i++) @@ -790,6 +935,11 @@ final void search_cr_cg(ACir cr1) { } + /** + * Processes all midpoint related configurations including congruence, parallel, and cyclic conditions. + * + * @param md the midpoint to process + */ final void search_md(MidPt md) { co_db.nx = null; @@ -839,6 +989,11 @@ final void search_md(MidPt md) { } } + /** + * Searches for additional midpoint configurations and connections between different midpoints. + * + * @param md the midpoint from which to search connected midpoint configurations + */ final void search_md_mds(MidPt md) { MidPt md1; @@ -903,6 +1058,11 @@ final void search_md_mds(MidPt md) { } } + /** + * Searches for midpoint-related parallel segment configurations. + * + * @param md the midpoint object containing endpoints for the search + */ final void search_md_pns(MidPt md) { if (!valid(R_PARALLELOGRAM)) return; LLine l0 = fd_ln(md.a, md.b); @@ -914,6 +1074,11 @@ final void search_md_pns(MidPt md) { } } + /** + * Processes an angle object by adjusting and verifying its associated lines. + * + * @param as1 the angle object to process + */ final void search_as(Angles as1) { LLine l1 = as1.l1; LLine l2 = as1.l2; @@ -998,6 +1163,15 @@ final void search_as(Angles as1) { } + /** + * Adjusts the angle based on parallel or perpendicular relationships between provided lines. + * + * @param as the angle object to adjust + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @param l4 the fourth line + */ final void search_as_0(Angles as, LLine l1, LLine l2, LLine l3, LLine l4) { if (ln_para(l1, l2) && l3 != l4) { as.type = 0; @@ -1030,6 +1204,15 @@ final void search_as_0(Angles as, LLine l1, LLine l2, LLine l3, LLine l4) { } } + /** + * Searches for specific angle relations given intersecting lines. + * + * @param p1 the first intersection point + * @param p2 the second intersection point, expected as the intersection of l1 and l3 + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + */ final void search_as_1(int p1, int p2, LLine l1, LLine l2, LLine l3) { if (p1 == 0 || p2 == 0) return; int o = inter_ll(l1, l3); @@ -1093,6 +1276,16 @@ final void search_as_1(int p1, int p2, LLine l1, LLine l2, LLine l3) { } } + /** + * Identifies and processes angle relationships using the inscribed angle theorem and tangency conditions. + * + * @param p1 the first intersection point + * @param p2 the second intersection point + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @param l4 the fourth line + */ final void search_as_2(int p1, int p2, LLine l1, LLine l2, LLine l3, LLine l4) { int o, p3, p4; o = 0; @@ -1129,6 +1322,16 @@ final void search_as_2(int p1, int p2, LLine l1, LLine l2, LLine l3, LLine l4) { } } + /** + * Searches for cyclic angle configurations based on line and circle intersections. + * + * @param p1 the first intersection point + * @param p2 the second intersection point + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @param l4 the fourth line + */ final void search_as_3(int p1, int p2, LLine l1, LLine l2, LLine l3, LLine l4) { int p3, p4, m; if ((p3 = inter_ll(l1, l3)) != 0 && xcir2(p2, p1, p3) && @@ -1153,6 +1356,16 @@ final void search_as_3(int p1, int p2, LLine l1, LLine l2, LLine l3, LLine l4) { } } + /** + * Adjusts angle configurations based on alignment and concurrency of lines. + * + * @param p1 the first reference point from an intersection + * @param p2 the second reference point from an intersection + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @param l4 the fourth line + */ final void lm_43(int p1, int p2, LLine l1, LLine l2, LLine l3, LLine l4) { int p3, p4, o; @@ -1177,6 +1390,16 @@ final void lm_43(int p1, int p2, LLine l1, LLine l2, LLine l3, LLine l4) { } } + /** + * Searches for similar angle configurations and triggers operations to construct congruences. + * + * @param p1 the first intersection point + * @param p2 the second intersection point + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @param l4 the fourth line + */ final void search_as_sim(int p1, int p2, LLine l1, LLine l2, LLine l3, LLine l4) { // if (!valid(R_STRI)) return; int p3, p4, p5, p6; @@ -1237,6 +1460,17 @@ final void search_as_sim(int p1, int p2, LLine l1, LLine l2, LLine l3, LLine l4) } } + /** + * Determines if two triangles are similar based on their vertices. + * + * @param p1 the first vertex of the first triangle + * @param p2 the second vertex of the first triangle + * @param p3 the third vertex of the first triangle + * @param p4 the first vertex of the second triangle + * @param p5 the second vertex of the second triangle + * @param p6 the third vertex of the second triangle + * @return true if the triangles are similar, false otherwise + */ boolean tri_sim(int p1, int p2, int p3, int p4, int p5, int p6) { int p; if (ind_3(p1, p4, p5, p6) != 0 && ind_3(p2, p4, p5, p6) != 0 && ind_3(p3, p4, p5, p6) != 0)//??? @@ -1276,6 +1510,9 @@ boolean tri_sim(int p1, int p2, int p3, int p4, int p5, int p6) { return (false); } + /** + * Iterates through angle objects to perform angle search operations. + */ final void search_as_pt() { Angles as; as = all_as.nx; @@ -1290,6 +1527,18 @@ final void search_as_pt() { } } + /** + * Searches and processes string-based congruency conditions for the provided points. + * + * @param dr a direction flag for processing + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @param p4 the fourth point + * @param p5 the fifth point + * @param p6 the sixth point + * @return true if a congruency condition is met, false otherwise + */ boolean search_st_ct(int dr, int p1, int p2, int p3, int p4, int p5, int p6) { int oldt = tri_type; boolean mk = false; @@ -1314,6 +1563,17 @@ boolean search_st_ct(int dr, int p1, int p2, int p3, int p4, int p5, int p6) { return mk; } + /** + * Searches for congruent segment configurations and processes string congruency scenarios. + * + * @param dr a direction flag for processing + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @param p4 the fourth point + * @param p5 the fifth point + * @param p6 the sixth point + */ void search_st_rg(int dr, int p1, int p2, int p3, int p4, int p5, int p6) { CongSeg rg = fo_rg1(p1, p2, p4, p5); int t1, t2; @@ -1366,6 +1626,11 @@ void search_st_rg(int dr, int p1, int p2, int p3, int p4, int p5, int p6) { } } + /** + * Searches and processes a SimTri structure. + * + * @param st the SimTri instance representing the similar triangle to search + */ final void search_st(SimTri st) { int dr, p1, p2, p3, p4, p5, p6; RatioSeg ra1, ra = null; @@ -1408,6 +1673,11 @@ final void search_st(SimTri st) { pop_codb(); } + /** + * Searches and processes a congruent triangle based on the given SimTri. + * + * @param st the SimTri instance containing triangle data + */ final void search_ct(SimTri st) { tri_type = 1; adj_ct(st); @@ -1441,6 +1711,11 @@ final void search_ct(SimTri st) { pop_codb(); } + /** + * Searches and processes a CongSeg object. + * + * @param cg the CongSeg instance to process + */ final void search_cg(CongSeg cg) { int o, p1, p2, p3, p4; if (cg.t1 == 0 || cg.t2 == 0) { @@ -1508,6 +1783,13 @@ final void search_cg(CongSeg cg) { } + /** + * Searches for an isosceles configuration based on the given points. + * + * @param o the origin point + * @param a the first point defining the base + * @param b the second point defining the base + */ final void search_cg_iso(int o, int a, int b) { MidPt m = fo_md(a, b); if (m != null && m.m != o) { // mid @@ -1547,6 +1829,14 @@ final void search_cg_iso(int o, int a, int b) { } + /** + * Searches for a triangle structure within congruent segments. + * + * @param p1 the first point of the congruency + * @param p2 the second point of the congruency + * @param p3 the third point of the congruency + * @param p4 the fourth point of the congruency + */ final void search_cg_st(int p1, int p2, int p3, int p4) { SimTri st; @@ -1599,7 +1889,11 @@ final void search_cg_st(int p1, int p2, int p3, int p4) { } } - + /** + * Searches for a ratio segment configuration and processes it accordingly. + * + * @param ra the RatioSeg instance containing ratio and segment data + */ final void search_ra(RatioSeg ra) { int n, a1, b1, a2, b2, a3, b3, a4, b4; if (ra.type == 0) return; @@ -1653,45 +1947,11 @@ final void search_ra(RatioSeg ra) { } } - - final void adj_ras(RatioSeg ra) { - if (ra.type == 0) return; - CongSeg cg; - int p1, p2; - int[] p; - test_ra1.cp_ratio(ra); - p = test_ra1.r; - cg = null; - - for (int n = 0; n < 4; n++) { - p1 = p[n * 2 + 1]; - p2 = p[n * 2 + 2]; - - cg = fd_cg2(p1, p2, cg); - while (cg != null) { - if (p1 == cg.p1 && p2 == cg.p2 || p1 == cg.p2 && p2 == cg.p1) { - p[n * 2 + 1] = cg.p3; - p[n * 2 + 2] = cg.p4; - } else { - p[n * 2 + 1] = cg.p1; - p[n * 2 + 2] = cg.p2; - } - - if (!xeq_ratio(p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8])) { // mod here. - - add_codb(CO_CONG, cg.p1, cg.p2, cg.p3, cg.p4, 0, 0, 0, 0); - add_codb(CO_PROD, ra.r[1], ra.r[2], ra.r[3], ra.r[4], ra.r[5], ra.r[6], ra.r[7], ra.r[8]); - add_ra(0, 0, p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8]); - pop_codb(); - pop_codb(); - } - cg = cg.nx; - } - p[n * 2 + 1] = p1; - p[n * 2 + 2] = p2; - } - } - + /** + * Searches and processes the ratio segment for state-specific actions. + * + * @param ra the RatioSeg instance to process + */ final void serach_ra_st(RatioSeg ra) { int a, a1, a2, b, b1, b2; int[] p = ra.r; @@ -1808,6 +2068,9 @@ final void serach_ra_st(RatioSeg ra) { } } + /** + * Searches and processes ratio segments for congruency operations. + */ final void search_ra_cg() { RatioSeg ra; @@ -1851,23 +2114,40 @@ final void search_ra_cg() { } } - /////////////////////////////////////////////////////////////// + /** + * Checks if three points are collinear. + * + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @return true if the points are collinear; false otherwise + */ public boolean mcoll(int p1, int p2, int p3) { return xcoll(p1, p2, p3); } + /** + * Checks if the line formed by p1 and p2 is perpendicular to the line formed by p3 and p4. + * + * @param p1 the first point of the first line + * @param p2 the second point of the first line + * @param p3 the first point of the second line + * @param p4 the second point of the second line + * @return true if the lines are perpendicular; false otherwise + */ public boolean mperp(int p1, int p2, int p3, int p4) { return xperp(p1, p2, p3, p4); } - public boolean mpara(int p1, int p2, int p3, int p4) { - return xpara(p1, p2, p3, p4); - } - - //////////////////////////////////////////////////////////////////// - // added by yezheng 2006.9.26 - - + /** + * Adds an isosceles configuration when three lines concur. + * + * @param lm the identifier to be used for the configuration + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @param m the midpoint to be used in the configuration + */ final void add_iso_3lines_concur(int lm, int p1, int p2, int p3, int m) { if (p1 == m) return; if (check_coll(p1, p2, p3)) { @@ -1883,11 +2163,27 @@ final void add_iso_3lines_concur(int lm, int p1, int p2, int p3, int m) { add_tline(lm, p1, m, p2, p3); } + /** + * Searches for congruent triangle configurations via side‑side‑side relationships. + * + * @param p1 the first point of the first segment + * @param p2 the second point of the first segment + * @param p3 the first point of the second segment + * @param p4 the second point of the second segment + */ public final void search_cg_ct(int p1, int p2, int p3, int p4) { search_cg_ct0(p1, p2, p3, p4); //SSS search_cg_ct0(p3, p4, p1, p2); //SSS } + /** + * Searches for congruent triangle configurations using angle‑angle‑side conditions. + * + * @param p1 the first point of the first segment + * @param p2 the second point of the first segment + * @param p3 the first point of the second segment + * @param p4 the second point of the second segment + */ public final void search_cg_aas(int p1, int p2, int p3, int p4) { for (int i = 1; i <= pts_no; i++) for (int j = 1; j <= pts_no; j++) { @@ -1915,6 +2211,14 @@ public final void search_cg_aas(int p1, int p2, int p3, int p4) { } } + /** + * Searches for congruent triangle configurations with trimmed conditions using SSS. + * + * @param p1 the first reference point + * @param p2 the second reference point + * @param p3 the third reference point + * @param p4 the fourth reference point + */ public final void search_cg_ct0(int p1, int p2, int p3, int p4) { // if (!valid(R_SSS)) return; @@ -2031,6 +2335,16 @@ public final void search_cg_ct0(int p1, int p2, int p3, int p4) { } } + /** + * Searches for similar triangle configurations using corresponding line segments. + * + * @param p1 the reference point from the first triangle + * @param p2 the reference point from the second triangle + * @param ln1 the line data for the first triangle side + * @param ln2 the line data for the second triangle side + * @param ln3 the line data for the third triangle side + * @param ln4 the line data for the alternative configuration side + */ final public void search_as_ct(int p1, int p2, LLine ln1, LLine ln2, LLine ln3, LLine ln4) { // if (!valid(R_SAS)) return; if (p1 == 0 || p2 == 0) return; @@ -2101,7 +2415,14 @@ final public void search_as_ct(int p1, int p2, LLine ln1, LLine ln2, LLine ln3, } } - + /** + * Searches for T-line structures by testing intersections and perpendicular conditions. + * + * @param p1 the first reference point index + * @param ln1 the first line of the primary structure + * @param ln2 the second line of the primary structure + * @param tn1 the candidate T-line structure + */ final public void search_tn_st(int p1, LLine ln1, LLine ln2, TLine tn1) { @@ -2170,6 +2491,14 @@ else if (xcong(p1, t1, p2, t4)) { } + /** + * Searches for congruent triangle configurations by finding midpoints and establishing congruency. + * + * @param p1 the first point index of the first segment + * @param p2 the second point index of the first segment + * @param p3 the first point index of the second segment + * @param p4 the second point index of the second segment + */ final public void search_cg_md(int p1, int p2, int p3, int p4) { int t1 = fd_pt_md(p1, p2); int t2 = fd_pt_md(p3, p4); @@ -2187,14 +2516,11 @@ final public void search_cg_md(int p1, int p2, int p3, int p4) { } } - final public void search_cg_mds(int p1, int p2, int p3, int p4) { - MidPt md = all_md.nx; - while (md != null) { - - md = md.nx; - } - } - + /** + * Searches for congruent segment configurations within the current geometric construction. + * + * @param cg the congruent segment configuration to be evaluated + */ public void search_cgs(CongSeg cg) { CongSeg cg1 = all_cg.nx; while (cg1 != null) { @@ -2210,6 +2536,12 @@ public void search_cgs(CongSeg cg) { search_2cong1(cg); } + /** + * Searches for congruent configurations between two congruent segment structures. + * + * @param cg the first congruent segment configuration + * @param cg1 the second congruent segment configuration + */ public void search_cg_cg(CongSeg cg, CongSeg cg1) { int p1, p2, p3, p4, t1, t2, t3, t4; if (cg == cg1) return; @@ -2275,6 +2607,22 @@ public void search_cg_cg(CongSeg cg, CongSeg cg1) { pop_codb(); } + /** + * Searches for congruent configurations using plus or minus criteria for segment measures. + * + * @param a first point of the first segment + * @param b second point of the first segment + * @param c first point of the second segment + * @param d second point of the second segment + * @param t1 first measure associated with the first segment + * @param t2 second measure associated with the first segment + * @param a1 first point of the alternative segment configuration + * @param b1 second point of the alternative segment configuration + * @param c1 first point of the alternative segment configuration + * @param d1 second point of the alternative segment configuration + * @param t11 first measure associated with the alternative configuration + * @param t22 second measure associated with the alternative configuration + */ public void search_cg__plus_or_minus(int a, int b, int c, int d, int t1, int t2, int a1, int b1, int c1, int d1, int t11, int t22) { int m1, m2, m3, m4, m5, m6; @@ -2329,7 +2677,11 @@ public void search_cg__plus_or_minus(int a, int b, int c, int d, int t1, int t2, pop_codb(); } - + /** + * Searches for configurations where two congruent segments share a common intersection. + * + * @param cg the congruent segment configuration to analyze + */ public void search_2cong1(CongSeg cg) { if (!xcoll4(cg.p1, cg.p2, cg.p3, cg.p4)) return; int p1, p2, p3; @@ -2371,6 +2723,11 @@ public void search_2cong1(CongSeg cg) { } } + /** + * Searches for congruent configurations based on midpoint relationships. + * + * @param md the midpoint structure used for establishing congruence + */ final public void search_md_cong(MidPt md) { MidPt md1 = all_md.nx; while (md1 != null && ch_dep(md1.dep)) { @@ -2390,6 +2747,11 @@ final public void search_md_cong(MidPt md) { } } + /** + * Searches for parallelogram configurations among point-line relationships. + * + * @param pn the candidate point-line configuration + */ public void search_pn_pn(PLine pn) { if (!valid(R_PARALLELOGRAM)) return; if (pn.type == 0 || pn.no <= 0) return; @@ -2448,7 +2810,16 @@ public void search_pn_pn(PLine pn) { } } - + /** + * Searches for SAS (Side-Angle-Side) triangle configurations using the specified points and line segments. + * + * @param p1 the first point identifier + * @param p2 the second point identifier + * @param ln1 the first line segment container + * @param ln2 the second line segment container + * @param ln3 the third line segment container + * @param ln4 the fourth line segment container + */ final public void search_as_st(int p1, int p2, LLine ln1, LLine ln2, LLine ln3, LLine ln4) { //sas for st if (!valid(R_SAS)) return; if (p1 == 0 || p2 == 0) return; @@ -2525,6 +2896,16 @@ final public void search_as_st(int p1, int p2, LLine ln1, LLine ln2, LLine ln3, } } + /** + * Searches for congruent segment triangle states based on the given points and ratio parameters. + * + * @param p1 the first point identifier + * @param p2 the second point identifier + * @param p3 the third point identifier + * @param p4 the fourth point identifier + * @param r1 the first ratio value + * @param r2 the second ratio value + */ public final void search_cg_st0(int p1, int p2, int p3, int p4, int r1, int r2) { // if (!valid(R_SSS) || !valid(R_STRI)) return; @@ -2615,6 +2996,18 @@ public final void search_cg_st0(int p1, int p2, int p3, int p4, int r1, int r2) } } + /** + * Searches for congruent triangles by validating angle equality and congruence conditions. + * + * @param t1 the first triangle base point identifier + * @param t2 the second triangle base point identifier + * @param t3 the third triangle base point identifier + * @param t4 the first point of the second triangle + * @param t5 the second point of the second triangle + * @param t6 the third point of the second triangle + * @param r1 the first ratio value associated with congruence + * @param r2 the second ratio value associated with congruence + */ public void search_cong_st(int t1, int t2, int t3, int t4, int t5, int t6, int r1, int r2) { if (!check_eqangle_t(t2, t1, t1, t3, t5, t4, t4, t6)) return; @@ -2641,6 +3034,17 @@ public void search_cong_st(int t1, int t2, int t3, int t4, int t5, int t6, int r } + /** + * Searches for triangle configurations based on segment congruence and structural properties. + * + * @param dr the directional factor for the configuration + * @param p1 the first point identifier of the triangle + * @param p2 the second point identifier of the triangle + * @param p3 the third point identifier of the triangle + * @param p4 the first point identifier of the second triangle + * @param p5 the second point identifier of the second triangle + * @param p6 the third point identifier of the second triangle + */ public void search_st1(int dr, int p1, int p2, int p3, int p4, int p5, int p6) { if (xcong(p1, p2, p2, p3) && !xcong(p4, p5, p5, p6)) { add_codb(CO_CONG, p1, p2, p2, p3, 0, 0, 0, 0); @@ -2681,12 +3085,17 @@ public void search_st1(int dr, int p1, int p2, int p3, int p4, int p5, int p6) { pop_codb(); } - - public boolean get_at_dr(AngleT at, int p1, int p2) { - if (on_ln(p1, at.l1) && on_ln(p2, at.l2)) return true; - return false; - } - + /** + * Adds structural angle congruency information by comparing two complementary angles from the given points. + * + * @param dr the directional factor for angle assignment + * @param p1 the vertex point of the first angle + * @param p2 a point defining the first angle side + * @param p3 a point defining the other side of the first angle + * @param p4 the vertex point of the second angle + * @param p5 a point defining the second angle side + * @param p6 a point defining the other side of the second angle + */ public void add_stct_at(int dr, int p1, int p2, int p3, int p4, int p5, int p6) { AngleT at1 = fd_at(p2, p1, p3); @@ -2710,6 +3119,11 @@ public void add_stct_at(int dr, int p1, int p2, int p3, int p4, int p5, int p6) } } + /** + * Adjusts similar triangles by checking and adding structural relationships with adjacent triangles. + * + * @param st the simulated triangle whose adjacent configurations are to be adjusted + */ public void adj_st(SimTri st) { SimTri st1 = all_st.nx; tri_type = 0; @@ -2766,6 +3180,11 @@ public void adj_st(SimTri st) { } + /** + * Adjusts complementary triangles by checking and generating new configurations for triangle relationships. + * + * @param st the simulated triangle whose complementary relationships are being adjusted + */ public void adj_ct(SimTri st) { SimTri st1 = all_ct.nx; tri_type = 1; @@ -2822,6 +3241,11 @@ public void adj_ct(SimTri st) { } + /** + * Searches for perpendicular congruent segments in a given congruent segment configuration. + * + * @param cg the congruent segment configuration to be analyzed + */ public void search_tn_cg(CongSeg cg) { int o = 0; int p1 = cg.p1; @@ -2868,7 +3292,11 @@ public void search_tn_cg(CongSeg cg) { } } - + /** + * Searches the given line for valid configurations among congruent segments. + * + * @param ln the line to search through + */ final void search_ln(LLine ln) { if (ln != null && ln.type != 0) { @@ -2919,6 +3347,15 @@ final void search_ln(LLine ln) { } } + /** + * Adjusts the angle subtraction configuration for the given point using four lines. + * + * @param p the reference point identifier + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @param l4 the fourth line + */ public void adj_as0(int p, LLine l1, LLine l2, LLine l3, LLine l4) { if (p == 0) return; @@ -2948,6 +3385,16 @@ public void adj_as0(int p, LLine l1, LLine l2, LLine l3, LLine l4) { } + /** + * Searches and verifies tangent-based angle relationships between two points using four lines. + * + * @param p1 the first point identifier + * @param p2 the second point identifier + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @param l4 the fourth line + */ protected void search_as_tn_as(int p1, int p2, LLine l1, LLine l2, LLine l3, LLine l4) { if (this.isPFull() && d_base == 0) return; @@ -3020,7 +3467,11 @@ protected void search_as_tn_as(int p1, int p2, LLine l1, LLine l2, LLine l3, LLi } } - + /** + * Initiates a comprehensive search for angle congruence relationships. + * + * @param at the angle to be processed + */ public void search_at(AngleT at) { search_at0(at); search_at1(at); @@ -3029,6 +3480,11 @@ public void search_at(AngleT at) { adj_at(at); } + /** + * Searches for tangent-based angle configurations related to the specified angle. + * + * @param at the angle to be evaluated + */ public void search_at_tn(AngleT at) { LLine l1 = at.l1; LLine l2 = at.l2; @@ -3056,6 +3512,11 @@ public void search_at_tn(AngleT at) { } } + /** + * Searches for angle relationships within a tangent line configuration. + * + * @param tn the tangent line configuration + */ public void search_tn_at(TLine tn) { LLine l1 = tn.l1; LLine l2 = tn.l2; @@ -3066,6 +3527,14 @@ public void search_tn_at(TLine tn) { search_tn_ats(l2, l1, p, tn); } + /** + * Searches for tangent angles across two lines with respect to a common intersection point and a tangent line. + * + * @param l1 the first line + * @param l2 the second line + * @param p the intersection point identifier + * @param tn the tangent line configuration + */ public void search_tn_ats(LLine l1, LLine l2, int p, TLine tn) { if (p == 0) return; AngleT at1; @@ -3086,6 +3555,14 @@ public void search_tn_ats(LLine l1, LLine l2, int p, TLine tn) { } + /** + * Adds a triangle configuration based on tangent angle values. + * + * @param p the vertex point identifier + * @param p1 the first adjacent point identifier + * @param p2 the second adjacent point identifier + * @param v the angle value between points p1 and p2 + */ public void add_tri_tn_at(int p, int p1, int p2, int v) // pp1p2 = v; { int lm; @@ -3125,6 +3602,11 @@ public void search_tn_ats(LLine l1, LLine l2, int p, TLine tn) { } } + /** + * Searches for direct angle congruence relationships starting from the provided angle. + * + * @param at the angle to be searched + */ public void search_at0(AngleT at) { AngleT at1 = all_at.nx; while (at1 != null && ch_dep(at1.dep)) { @@ -3134,7 +3616,11 @@ public void search_at0(AngleT at) { } } - + /** + * Searches for alternative angle configurations based on the given angle. + * + * @param at the angle instance to process + */ public void search_at1(AngleT at) { LLine l1 = at.l1; LLine l2 = at.l2; @@ -3161,6 +3647,12 @@ public void search_at1(AngleT at) { } } + /** + * Searches for angle relationships between two angle instances and creates corresponding configurations. + * + * @param at the first angle instance + * @param at1 the second angle instance to compare + */ public void search_at_at(AngleT at, AngleT at1) { if (at == at1) return; LLine l1 = at.l1; @@ -3235,6 +3727,11 @@ public void search_at_at(AngleT at, AngleT at1) { } } + /** + * Searches for angle configurations derived from a congruent segment. + * + * @param cg the congruent segment instance used for calculating angle relationships + */ public void search_rg_at(CongSeg cg) { int t1 = cg.p1; int t2 = cg.p2; @@ -3329,6 +3826,12 @@ public void search_rg_at(CongSeg cg) { } } + /** + * Searches for angle configurations by comparing the given angle with an angle structure. + * + * @param at the base angle instance + * @param as the angle structure to compare against + */ public void search_at_as(AngleT at, Angles as) { LLine l1, l2, l3, l4; l1 = at.l1; @@ -3367,6 +3870,11 @@ public void search_at_as(AngleT at, Angles as) { } } + /** + * Searches for associated angle structures related to the given angle. + * + * @param at the angle instance for which to search related angle associations + */ public void search_at_ass(AngleT at) { Angles as = all_as.nx; @@ -3380,43 +3888,11 @@ public void search_at_ass(AngleT at) { } } - public void add_as_at(Angles as) { - LLine l1 = as.l1; - LLine l2 = as.l2; - LLine l3 = as.l3; - LLine l4 = as.l4; - if (l1 == l2 || xcoll_ln(l1, l2)) return; - if (l3 == l4 || xcoll_ln(l3, l4)) return; - AngleT at1 = fd_at(l1, l2); - AngleT at2 = fd_at(l3, l4); - if (at1 == at2) return; - - AngleT at = null; - if (at1 != null && at2 == null && ch_dep(at1.dep)) { - if (at1.l1 == l1 && at1.l2 == l2) - at = add_at(0, l3, l4, at1.v); - else - at = add_at(0, l4, l3, at1.v); - } else if (at1 == null && at2 != null && ch_dep(at2.dep)) { - if (at2.l1 == l3 && at2.l2 == l4) - at = add_at(0, l1, l2, at2.v); - else - at = add_at(0, l2, l1, at2.v); - } - if (at != null) { - co_xy.nx = null; - Cond co = add_coxy(CO_TANG); - if (at1 != null) - co.u.at = at1; - else if (at2 != null) - co.u.at = at2; - co = add_coxy(CO_ACONG); - co.u.as = as; - at.co = co; - } - } - - + /** + * Adjusts the angle configuration using its defining lines. + * + * @param at the angle instance to adjust + */ public void adj_at(AngleT at) { LLine l1 = at.l1; LLine l2 = at.l2; @@ -3439,12 +3915,11 @@ public void adj_at(AngleT at) { } } - public boolean ck_ateq(int a, int b) { - return a == b || Math.abs(a - b) == A_180; - } - -////////////////////////////////////////////////////// - + /** + * Searches for tangent-based angle configurations associated with the given tangent line. + * + * @param tn the tangent line configuration instance to search within + */ public void search_tn_atn(TLine tn) { if (tn.type == 0) return; @@ -3486,6 +3961,11 @@ public void search_tn_atn(TLine tn) { } } + /** + * Searches for angle configurations based on the provided tangent angle instance. + * + * @param atn the tangent angle instance to process + */ public void search_atn(AngTn atn) { if (atn.type == 0) return; @@ -3496,7 +3976,12 @@ public void search_atn(AngTn atn) { search_atn_at(atn); } - + /** + * Searches for equivalent tangent angle configurations by comparing the provided instance + * with existing tangent angle configurations. + * + * @param atn the tangent angle instance to compare + */ public void search_atn_atn(AngTn atn) { AngTn a1 = all_atn.nx; LLine ln1, ln2, ln3, ln4; @@ -3545,6 +4030,11 @@ public void search_atn_atn(AngTn atn) { } } + /** + * Searches for angle structures associated with the given tangent angle configuration. + * + * @param atn the tangent angle instance for which to search associated angle structures + */ public void search_atn_as(AngTn atn) { Angles as = all_as.nx; while (as != null && ch_dep(as.dep)) { @@ -3558,21 +4048,12 @@ public void search_atn_as(AngTn atn) { } } - public void search_as_atn(Angles as) { - AngTn a1 = all_atn.nx; - - while (a1 != null && ch_dep(a1.dep)) { - if (a1.type == 0) { - a1 = a1.nx; - continue; - } - search_atnas(a1, as.l1, as.l2, as.l3, as.l4, as); - search_atnas(a1, as.l3, as.l4, as.l1, as.l2, as); - a1 = a1.nx; - } - } - - + /** + * Searches through all angle instances and applies tangent angle evaluation with the given tangent angle instance. + * Continues until there are no more dependent angle instances. + * + * @param atn the tangent angle instance used for comparison + */ public void search_atn_at(AngTn atn) { AngleT at = all_at.nx; while (at != null && ch_dep(at.dep)) { @@ -3586,19 +4067,17 @@ public void search_atn_at(AngTn atn) { } - public void search_at_atn(AngleT at) { - AngTn a1 = all_atn.nx; - while (a1 != null && ch_dep(a1.dep)) { - if (a1.type == 0) { - a1 = a1.nx; - continue; - } - search_atatn(at, a1); - a1 = a1.nx; - } - - } - + /** + * Searches for associated tangent angle configurations by comparing the specified tangent angle instance with provided lines and an angles structure. + * Creates new tangent angle associations if the configuration meets criteria. + * + * @param atn the reference tangent angle instance + * @param l1 the first line of the primary configuration + * @param l2 the second line of the primary configuration + * @param l3 the first line of the secondary configuration + * @param l4 the second line of the secondary configuration + * @param as the angles structure used in association comparison + */ public void search_atnas(AngTn atn, LLine l1, LLine l2, LLine l3, LLine l4, Angles as) { LLine ln1, ln2, ln3, ln4, s1, s2, s3, s4; @@ -3665,6 +4144,13 @@ public void search_atnas(AngTn atn, LLine l1, LLine l2, LLine l3, LLine l4, Angl } + /** + * Searches for tangent angle configurations that are complementary to the given angle instance. + * If a valid configuration is found, creates and associates a new angle instance with an adjusted value. + * + * @param at the base angle instance + * @param a1 the tangent angle configuration to compare against + */ public void search_atatn(AngleT at, AngTn a1) { LLine l1 = at.l1; LLine l2 = at.l2; @@ -3701,10 +4187,26 @@ public void search_atatn(AngleT at, AngTn a1) { } } + /** + * Determines if the point p lies within the range defined by points o and o1. + * + * @param p the point to check + * @param o the first endpoint of the range + * @param o1 the second endpoint of the range + * @return true if p lies between o and o1, otherwise false + */ public boolean ptdr(int p, int o, int o1) { return (x_inside(p, o, o1) || x_inside(o1, p, o)); } + /** + * Splits the given line into segments based on the position of point p. + * Returns an array of line segments that are part of the original line and include point p. + * + * @param p the point used to split the line + * @param ln the line to be split + * @return an array of resulting line segments, or null if no valid segments exist + */ LLine[] split_ln(int p, LLine ln) { int o1 = get_lpt1(ln, p); int o2 = get_anti_pt(ln, p, o1); @@ -3751,7 +4253,18 @@ else if (lx2 != null) return ls; } - + /** + * Checks if the combined angles formed by the specified line segments at points p1 and p2 are approximately complementary. + * The method evaluates whether the sum of the absolute angles is close to 90 degrees. + * + * @param p1 the vertex point for the first pair of lines + * @param p2 the vertex point for the second pair of lines + * @param l1 the first line from p1 + * @param l2 the second line from p1 + * @param l3 the first line from p2 + * @param l4 the second line from p2 + * @return true if the summed angle values are approximately 90 degrees, otherwise false + */ public boolean check_llatn(int p1, int p2, LLine l1, LLine l2, LLine l3, LLine l4) { int n1 = get_lpt1(l1, p1); int n2 = get_lpt1(l2, p1); @@ -3765,19 +4278,33 @@ public boolean check_llatn(int p1, int p2, LLine l1, LLine l2, LLine l3, LLine l return false; } -/////////////////////////////////////////////////////////////////////////// -///// nodes; - - + /** + * Initiates the search for non-solved structures within the specified list. + * Skips the search if the last element has already been solved. + * + * @param ns the list of structures to search + */ public void search_ns(LList ns) { if (last_ns.solved) return; search_bk(ns); } + /** + * Initiates a backup search process. + * + * @param ls the list of structures to search + */ public void search_bk(LList ls) { search_bk_as(ls); } + /** + * Searches through the backup structures contained in the specified list. + * + * Iterates over each element in the list and applies transformation based on angle structures. + * + * @param ls the list of structures to process + */ public void search_bk_as(LList ls) { LList last; LLine[] ln1, ln2; @@ -3816,6 +4343,17 @@ public void search_bk_as(LList ls) { } } + /** + * Adds a new angle transformation node to the given list. + * + * Evaluates if the current transformation in the node matches the provided lines, + * and if not, creates a new node with the updated angle transformation. + * + * @param ls the current list of nodes + * @param l1 the first line segment for comparison + * @param l2 the second line segment for comparison + * @param n the index position used for the transformation + */ public void add_ls_et(LList ls, LLine l1, LLine l2, int n) { AngTr tr = ls.md[n].tr; if (tr.l1 == l1 && tr.l2 == l2) return; @@ -3836,6 +4374,15 @@ public void add_ls_et(LList ls, LLine l1, LLine l2, int n) { } } + /** + * Creates and returns a rule representing an equal angle configuration. + * + * Constructs a new rule using the provided angle transformations. + * + * @param t1 the first angle transformation + * @param t2 the second angle transformation + * @return the constructed Rule object representing equal angles + */ public Rule add_rule_eqag(AngTr t1, AngTr t2) { Rule r = new Rule(Rule.EQ_ANGLE); Mnde m1 = new Mnde(); @@ -3848,6 +4395,18 @@ public Rule add_rule_eqag(AngTr t1, AngTr t2) { return r; } + /** + * Creates a new list node as a sub-structure of the existing list. + * + * Copies the given list, updates the angle transformation at the specified index, + * and links the new node to the backup chain. + * + * @param ls the original list of nodes + * @param t1 the original angle transformation + * @param t2 the new angle transformation to be applied + * @param n the index at which the transformation is updated + * @return the newly created list node with the updated transformation + */ public LList add_ls_node_sub(LList ls, AngTr t1, AngTr t2, int n) { LList ls1 = new LList(); ls1.cp(ls); @@ -3857,12 +4416,14 @@ public LList add_ls_node_sub(LList ls, AngTr t1, AngTr t2, int n) { return ls1; } - public LList cp_l_list(LList ls) { - LList ls1 = new LList(); - ls1.type = LList.ANGLE; - return ls1; - } - + /** + * Displays the angle transformation information. + * + * Depending on the available transformation details, prints the angle + * using the corresponding representation. + * + * @param tr the angle transformation to display + */ void show_tr(AngTr tr) { if (tr == null) return; if (tr.t1 != 0 && tr.t2 != 0) diff --git a/src/main/java/gprover/GDDAux.java b/src/main/java/gprover/GDDAux.java index 67758de1..b3ca8e6c 100644 --- a/src/main/java/gprover/GDDAux.java +++ b/src/main/java/gprover/GDDAux.java @@ -1,17 +1,17 @@ package gprover; /** - * Created by IntelliJ IDEA. - * User: ye - * Date: Jan 10, 2007 - * Time: 2:27:35 PM - * To change this template use File | Settings | File Templates. + * GDDAux extends GDD to provide auxiliary processing methods for geometric constructions. */ public class GDDAux extends GDD { /* main entry */ static long time; - + /** + * Initiates auxiliary processing steps. + * + * @return true if the auxiliary processing is successfully initiated. + */ boolean add_aux() { gno = cons_no; ax_backward(); @@ -28,13 +28,23 @@ boolean add_aux() { return true; } - + /** + * Adds an auxiliary point if it does not already exist. + * + * @param ax the auxiliary point to add. + */ public void add_aux(AuxPt ax) { if (aux_exists(ax)) return; vauxpts.add(ax); } + /** + * Checks if the given auxiliary point already exists in the list. + * + * @param ax the auxiliary point to check. + * @return true if the auxiliary point exists, false otherwise. + */ private boolean aux_exists(AuxPt ax) { int n = ax.getPtsNo(); if (n > 1) return false; @@ -49,6 +59,13 @@ private boolean aux_exists(AuxPt ax) { return false; } + /** + * Determines if the auxiliary point contains the specified point. + * + * @param ax the auxiliary point. + * @param pt the point to check. + * @return true if the point is contained within the auxiliary point, false otherwise. + */ private boolean isaux_contpt(AuxPt ax, ProPoint pt) { int n = ax.getPtsNo(); for (int i = 0; i < n; i++) { @@ -59,33 +76,56 @@ private boolean isaux_contpt(AuxPt ax, ProPoint pt) { return false; } + /** + * Compares two points to determine if they are the same. + * + * @param p1 the first point. + * @param p2 the second point. + * @return true if the points are considered the same, false otherwise. + */ private boolean isSamePt(ProPoint p1, ProPoint p2) { if (p1.type != p2.type) return false; return Math.pow(p1.getX() - p2.getX(), 2) + Math.pow(p1.getY() - p2.getY(), 2) < ZERO * ZERO; } - + /** + * Checks if the elapsed time since start exceeds the defined limit. + * + * @return true if the time is over the limit, false otherwise. + */ public boolean time_over() { long t = System.currentTimeMillis() - time; if (t > 200000) return true; return false; } - + /** + * Records the current system time as the start time for timing. + */ public void time_start() { time = System.currentTimeMillis(); } + /** + * Creates a new auxiliary point of the specified type. + * + * @param aux the auxiliary identifier. + * @param type the type of the point. + * @return the created auxiliary point. + */ ProPoint aux_pt(int aux, int type) { ProPoint p = new ProPoint(type); p.aux = aux; return p; } - - //****************************************************************** - + /** + * Adds the given point as an auxiliary point after generating its descriptive string. + * + * @param t the auxiliary identifier. + * @param pt the point to be added. + */ private void add_as_aux(int t, ProPoint pt) { if (pt == null) return; @@ -97,6 +137,15 @@ private void add_as_aux(int t, ProPoint pt) { return; } + /** + * Creates an auxiliary point based on a tangent line configuration. + * + * @param aux the auxiliary identifier. + * @param p1 the first defining point. + * @param p2 the second defining point. + * @param p3 the third defining point. + * @return the created auxiliary point for the tangent line. + */ ProPoint aux_tline(int aux, int p1, int p2, int p3) { ProPoint pt = aux_pt(aux, C_O_T); pt.ps[0] = 0; @@ -107,6 +156,15 @@ ProPoint aux_tline(int aux, int p1, int p2, int p3) { return (pt); } + /** + * Creates an auxiliary tangent line point and adds it to the auxiliary list. + * + * @param aux the auxiliary identifier. + * @param p1 the first defining point. + * @param p2 the second defining point. + * @param p3 the third defining point. + * @return the created auxiliary tangent line point. + */ ProPoint auxpt_tline(int aux, int p1, int p2, int p3) { ProPoint pt = aux_tline(aux, p1, p2, p3); if (pt != null) @@ -114,6 +172,14 @@ ProPoint auxpt_tline(int aux, int p1, int p2, int p3) { return pt; } + /** + * Creates an auxiliary midpoint between two points. + * + * @param aux the auxiliary identifier. + * @param p1 the first point. + * @param p2 the second point. + * @return the created auxiliary midpoint. + */ ProPoint aux_mid(int aux, int p1, int p2) { ProPoint pt = aux_pt(aux, C_MIDPOINT); pt.ps[0] = cons_no; @@ -123,6 +189,14 @@ ProPoint aux_mid(int aux, int p1, int p2) { return (pt); } + /** + * Creates an auxiliary midpoint and adds it to the auxiliary list. + * + * @param aux the auxiliary identifier. + * @param p1 the first point. + * @param p2 the second point. + * @return the created auxiliary midpoint after adding it. + */ ProPoint auxpt_mid(int aux, int p1, int p2) { ProPoint pt = aux_mid(aux, p1, p2); if (pt != null) @@ -130,7 +204,17 @@ ProPoint auxpt_mid(int aux, int p1, int p2) { return pt; } - + /** + * Creates an intersection point for two lines using the provided points. + * The point is computed and validated by cal_ax_ill. + * + * @param aux auxiliary identifier. + * @param p1 first point identifier. + * @param p2 second point identifier. + * @param p3 third point identifier. + * @param p4 fourth point identifier. + * @return the constructed intersection point if valid; otherwise, null. + */ ProPoint aux_ill(int aux, int p1, int p2, int p3, int p4) { ProPoint pt = aux_pt(aux, C_I_LL); pt.ps[0] = cons_no; @@ -143,6 +227,17 @@ ProPoint aux_ill(int aux, int p1, int p2, int p3, int p4) { return null; } + /** + * Creates and adds an intersection point for two lines. + * Computes the point using aux_ill and adds it if valid. + * + * @param aux auxiliary identifier. + * @param p1 first point identifier. + * @param p2 second point identifier. + * @param p3 third point identifier. + * @param p4 fourth point identifier. + * @return the added intersection point if valid; otherwise, null. + */ ProPoint auxpt_ill(int aux, int p1, int p2, int p3, int p4) { ProPoint pt = aux_ill(aux, p1, p2, p3, p4); if (pt != null) @@ -150,6 +245,18 @@ ProPoint auxpt_ill(int aux, int p1, int p2, int p3, int p4) { return pt; } + /** + * Creates an intersection point for a line configuration using five points. + * The point is computed and validated by cal_ax_ilp. + * + * @param aux auxiliary identifier. + * @param p1 first point identifier. + * @param p2 second point identifier. + * @param p3 third point identifier. + * @param p4 fourth point identifier. + * @param p5 fifth point identifier. + * @return the constructed intersection point if valid; otherwise, null. + */ ProPoint aux_ilp(int aux, int p1, int p2, int p3, int p4, int p5) { ProPoint pt = aux_pt(aux, C_I_LP); pt.ps[0] = cons_no; @@ -163,6 +270,18 @@ ProPoint aux_ilp(int aux, int p1, int p2, int p3, int p4, int p5) { return null; } + /** + * Creates and adds an intersection point for a line configuration. + * Computes the point using aux_ilp and adds it if valid. + * + * @param aux auxiliary identifier. + * @param p1 first point identifier. + * @param p2 second point identifier. + * @param p3 third point identifier. + * @param p4 fourth point identifier. + * @param p5 fifth point identifier. + * @return the added intersection point if valid; otherwise, null. + */ ProPoint auxpt_ilp(int aux, int p1, int p2, int p3, int p4, int p5) { ProPoint pt = aux_ilp(aux, p1, p2, p3, p4, p5); if (pt != null) @@ -170,26 +289,16 @@ ProPoint auxpt_ilp(int aux, int p1, int p2, int p3, int p4, int p5) { return pt; } - ProPoint aux_ilt(int aux, int p1, int p2, int p3, int p4, int p5) { - ProPoint pt = aux_pt(aux, C_I_LT); - pt.ps[0] = cons_no; - pt.ps[1] = p1; - pt.ps[2] = p2; - pt.ps[3] = p3; - pt.ps[4] = p4; - pt.ps[5] = p5; - cal_ax_ilt(pt, p1, p2, p3, p4, p5); - - return (pt); - } - - ProPoint auxpt_ilt(int aux, int p1, int p2, int p3, int p4, int p5) { - ProPoint pt = aux_ilt(aux, p1, p2, p3, p4, p5); - if (pt != null) - add_as_aux(aux, pt); - return pt; - } - + /** + * Calculates the foot of the perpendicular from a point onto a line. + * The foot is computed using points p1, p2, and p3 via cal_ax_foot. + * + * @param aux auxiliary identifier. + * @param p1 the point from which the perpendicular is drawn. + * @param p2 the first point defining the line. + * @param p3 the second point defining the line. + * @return the point representing the foot of the perpendicular. + */ ProPoint aux_foot(int aux, int p1, int p2, int p3) { ProPoint pt = aux_pt(aux, C_FOOT); pt.ps[0] = cons_no; @@ -200,6 +309,16 @@ ProPoint aux_foot(int aux, int p1, int p2, int p3) { return (pt); } + /** + * Creates and adds the foot of the perpendicular from a point onto a line. + * Computes the foot using aux_foot and adds it if valid. + * + * @param aux auxiliary identifier. + * @param p1 the point from which the perpendicular is drawn. + * @param p2 the first point defining the line. + * @param p3 the second point defining the line. + * @return the added perpendicular foot point. + */ ProPoint auxpt_foot(int aux, int p1, int p2, int p3) { ProPoint pt = aux_foot(aux, p1, p2, p3); if (pt != null) @@ -207,6 +326,16 @@ ProPoint auxpt_foot(int aux, int p1, int p2, int p3) { return pt; } + /** + * Creates an intersection point between a line and a circle. + * Uses points p1 and p2 along with the circle's center and first point to compute the intersection. + * + * @param aux auxiliary identifier. + * @param p1 first point identifier. + * @param p2 second point identifier. + * @param cr the circle used for the intersection. + * @return the intersection point if successfully computed; otherwise, null. + */ ProPoint aux_ilc(int aux, int p1, int p2, ACir cr) { ProPoint p = aux_pt(aux, C_I_LC); p.ps[0] = cons_no; @@ -220,6 +349,16 @@ ProPoint aux_ilc(int aux, int p1, int p2, ACir cr) { return null; } + /** + * Creates and adds an intersection point between a line and a circle. + * Computes the point using aux_ilc and adds it if valid. + * + * @param aux auxiliary identifier. + * @param p1 first point identifier. + * @param p2 second point identifier. + * @param cr the circle used for the intersection. + * @return the added intersection point if valid; otherwise, null. + */ ProPoint auxpt_ilc(int aux, int p1, int p2, ACir cr) { ProPoint pt = aux_ilc(aux, p1, p2, cr); if (pt != null) @@ -227,6 +366,17 @@ ProPoint auxpt_ilc(int aux, int p1, int p2, ACir cr) { return pt; } + /** + * Calculates the intersection point between a line and a circle using a translation approach. + * The point is computed using p1, p2, and p3 along with the circle’s properties via cal_ax_ipc. + * + * @param aux auxiliary identifier. + * @param p1 first point identifier. + * @param p2 second point identifier. + * @param p3 third point identifier. + * @param cr the circle used for the intersection. + * @return the calculated intersection point if successful; otherwise, null. + */ ProPoint aux_ipc(int aux, int p1, int p2, int p3, ACir cr) { ProPoint pt = aux_pt(aux, C_I_PC); pt.ps[0] = cons_no; @@ -240,6 +390,17 @@ ProPoint aux_ipc(int aux, int p1, int p2, int p3, ACir cr) { return (null); } + /** + * Creates and adds an intersection point between a line and a circle. + * Computes the point using aux_ipc and adds it if valid. + * + * @param aux auxiliary identifier. + * @param p1 first point identifier. + * @param p2 second point identifier. + * @param p3 third point identifier. + * @param cr the circle used for the intersection. + * @return the added intersection point if valid; otherwise, null. + */ ProPoint auxpt_ipc(int aux, int p1, int p2, int p3, ACir cr) { ProPoint pt = aux_ipc(aux, p1, p2, p3, cr); if (pt != null) @@ -247,6 +408,14 @@ ProPoint auxpt_ipc(int aux, int p1, int p2, int p3, ACir cr) { return pt; } + /** + * Computes the circumcenter point of a circle. + * The circumcenter is calculated from the circle's defining points via cal_ax_co. + * + * @param aux auxiliary identifier. + * @param cr the circle for which the circumcenter is computed. + * @return the computed circumcenter point. + */ ProPoint aux_co(int aux, ACir cr) { ProPoint pt = aux_pt(aux, C_CIRCUM); //62 pt.ps[0] = 0; @@ -257,6 +426,14 @@ ProPoint aux_co(int aux, ACir cr) { return (pt); } + /** + * Creates and adds the circumcenter point of a circle. + * Computes the point using aux_co and adds it if valid. + * + * @param aux auxiliary identifier. + * @param cr the circle for which the circumcenter is computed. + * @return the added circumcenter point. + */ ProPoint auxpt_co(int aux, ACir cr) { ProPoint pt = aux_co(aux, cr); if (pt != null) @@ -264,34 +441,18 @@ ProPoint auxpt_co(int aux, ACir cr) { return pt; } - - void ax_predicate() { - int[] p = conc.p; - switch (conc.pred) { - case 0: - return; - case CO_PERP: - { - LLine l1 = fd_ln(p[0], p[1]); - LLine l2 = fd_ln(p[2], p[3]); - if (l1 != null && l2 != null && inter_lls(l1, l2) == 0) { - ProPoint pt = auxpt_ill(1, p[0], p[1], p[2], p[3]); - } - } - break; - default: - break; - } - } - + /** + * Initiates the processing of auxiliary rules. + * This method serves as a placeholder for additional auxiliary rule implementations. + */ void aux_rules() { } - - //////////////////////////////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////////////////////////////////// - + /** + * Iterates through all midpoint structures and processes them by checking for common line conditions + * and applying appropriate auxiliary transformations. + */ void ax_md() { MidPt md = all_md.nx; while (md != null) { @@ -311,6 +472,12 @@ void ax_md() { } } + /** + * Processes point network intersections for the given midpoint. + * It finds relevant lines forming the point network structure and calls further processing methods. + * + * @param md the midpoint structure to process + */ void ax_mdpn(MidPt md) { PLine pn = all_pn.nx; while (pn != null) { @@ -338,6 +505,18 @@ void ax_mdpn(MidPt md) { } } + /** + * Examines global lines and determines if auxiliary intersections should be created based on the + * provided network lines. + * + * @param pn the point network segment being examined + * @param p1 the first reference point + * @param p2 the second reference point + * @param p3 the third reference point + * @param ln1 the first line corresponding to p1 + * @param ln2 the second line corresponding to p2 + * @param ln3 the third line corresponding to p3 + */ void ax_p3m(PLine pn, int p1, int p2, int p3, LLine ln1, LLine ln2, LLine ln3) { int m1, m2, m3; LLine ln; @@ -358,6 +537,15 @@ void ax_p3m(PLine pn, int p1, int p2, int p3, LLine ln1, LLine ln2, LLine ln3) { } } + /** + * Processes overlapping midpoint configurations between two midpoint structures. + * It identifies a common point from the first structure and iterates over global lines to trigger + * auxiliary midpoint creation when needed. + * + * @param md the first midpoint structure + * @param md1 the second midpoint structure for comparison + * @param l1 the line determined by the current configuration + */ void ax_mml(MidPt md, MidPt md1, LLine l1) { int p1, p2; @@ -382,6 +570,13 @@ void ax_mml(MidPt md, MidPt md1, LLine l1) { } } + /** + * Handles mismatched midpoint configurations by evaluating parallel conditions and generating + * auxiliary intersections when specific criteria are met. + * + * @param md the first midpoint structure + * @param md1 the second midpoint structure + */ void ax_mm(MidPt md, MidPt md1) { int m1, m2, p1, p2, p3, p4; p1 = md.a; @@ -423,7 +618,10 @@ void ax_mm(MidPt md, MidPt md1) { } } - + /** + * Iterates through all tangent lines and applies orthogonal transformations + * by processing each non-zero type tangent line. + */ void ax_orth() { TLine tn = all_tn.nx; @@ -437,6 +635,14 @@ void ax_orth() { } } + /** + * Processes orthogonal configurations for a given tangent line and its associated lines. + * If the lines meet the required intersection conditions, auxiliary intersection points are generated. + * + * @param tn1 the primary tangent line to process + * @param ln1 the first line associated with the tangent + * @param ln2 the second line associated with the tangent + */ void ax_orth1(TLine tn1, LLine ln1, LLine ln2) { int a, b, c, h; @@ -468,7 +674,11 @@ void ax_orth1(TLine tn1, LLine ln1, LLine ln2) { } } - + /** + * Processes all TLine elements in the list and applies geometric constructions + * including circle intersections, angle adjustments, midpoint validations, + * and constructing auxiliary points based on line intersections. + */ void ax_tn() { TLine tn = all_tn.nx; while (tn != null) { @@ -488,7 +698,13 @@ void ax_tn() { } } - + /** + * Processes circle intersections for the given TLine. + * Evaluates intersections between the circles and the two lines of the TLine, + * and constructs auxiliary points if the intersection conditions are met. + * + * @param tn the TLine whose circle intersections are to be processed + */ void ax_tn_cr(TLine tn) { int p2, p3, m; LLine ln; @@ -543,7 +759,13 @@ void ax_tn_cr(TLine tn) { } } - + /** + * Processes angle-related transformations for the given TLine. + * Iterates over angle configuration objects and, based on the positional + * relationships of the TLine's segments, constructs auxiliary intersection points. + * + * @param tn the TLine for which angle transformations are evaluated + */ void ax_tn_as(TLine tn) { int p1, p2, p3; LLine ln, n1, n2, l1, l2, l3, l4; @@ -600,6 +822,13 @@ void ax_tn_as(TLine tn) { } } + /** + * Processes midpoint constructions associated with the given TLine. + * Searches through midpoint objects and, if the conditions are met, + * constructs an auxiliary foot point. + * + * @param tn the TLine used for evaluating midpoint intersections + */ void ax_tn_md(TLine tn) { int p1, p2; @@ -641,7 +870,10 @@ void ax_tn_md(TLine tn) { } } - + /** + * Processes all TLine elements to construct perpendicular line intersections. + * Delegates to ax_tn_ln for each TLine's pair of lines. + */ void ax_tn_1() { TLine tn = all_tn.nx; while (tn != null) { @@ -654,6 +886,14 @@ void ax_tn_1() { } } + /** + * Evaluates intersections and geometric relationships between two lines. + * Constructs auxiliary foot points if the specified conditions and + * intersection criteria are satisfied. + * + * @param ln1 the first line used in the intersection check + * @param ln2 the second line used in the intersection check + */ void ax_tn_ln(LLine ln1, LLine ln2) { int p1, p2, p3; @@ -696,6 +936,15 @@ void ax_tn_ln(LLine ln1, LLine ln2) { } } + /** + * Processes candidate intersections between lines within a TLine context. + * Iterates through candidate line groups to construct auxiliary points based + * on midpoint validations and line intersections. + * + * @param tn the TLine context for the operation + * @param ln1 the first line segment involved in the intersection check + * @param ln2 the second line segment involved in the intersection check + */ void ax_tn_21(TLine tn, LLine ln1, LLine ln2) { int p2, p3, p4, p5; int p1 = inter_ll(ln1, ln2); @@ -738,6 +987,11 @@ void ax_tn_21(TLine tn, LLine ln1, LLine ln2) { } } + /** + * Processes all angle transformation objects. + * Iterates through the list of angles and delegates processing + * to specific configuration methods based on the angle type. + */ void ax_as() { Angles as1; LLine l1, l2, l3, l4; @@ -760,6 +1014,16 @@ void ax_as() { } } + /** + * Evaluates the angle transformation for a specific configuration. + * Constructs auxiliary points by verifying intersection points and circle + * conditions for the configuration defined by the provided lines. + * + * @param as the angle transformation object to process + * @param l1 the first line defining the angle + * @param l2 the second line defining the angle + * @param l3 the auxiliary line used for comparative intersection analysis + */ void ax_as_1(Angles as, LLine l1, LLine l2, LLine l3) { int p1, p2, p3, p4; @@ -817,8 +1081,18 @@ void ax_as_1(Angles as, LLine l1, LLine l2, LLine l3) { } -/* [op1,l2]=[l2,op3] */ - + /** + * Processes angle transformations by iterating through candidate points on the given line. + * If the line between p1 and p3 intersects l2, no transformation is applied. + * Otherwise, for each point p2 on l2 (excluding o and midpoints between p1 and p3), + * an auxiliary intersection is recorded. + * + * @param as the current Angles instance + * @param o the reference point to exclude from processing + * @param p1 the first defining point of the line segment + * @param p3 the second defining point of the line segment + * @param l2 the line containing candidate points + */ void ax_at(Angles as, int o, int p1, int p3, LLine l2) { if (inter_ll(l2, fd_ln(p1, p3)) != 0) return; @@ -830,6 +1104,17 @@ void ax_at(Angles as, int o, int p1, int p3, LLine l2) { } } + /** + * Processes paired angle structures by determining intersections between two pairs of lines. + * If valid intersection points exist between l1/l2 and l3/l4 respectively, this method + * initiates further angle processing using ax_as_21. + * + * @param as the current Angles instance + * @param l1 the first line of the first pair + * @param l2 the second line of the first pair + * @param l3 the first line of the second pair + * @param l4 the second line of the second pair + */ void ax_as_2(Angles as, LLine l1, LLine l2, LLine l3, LLine l4) { int p1, p2; if (((p1 = inter_ll(l1, l2)) == 0) || ((p2 = inter_ll(l3, l4)) == 0)) return; @@ -838,6 +1123,20 @@ void ax_as_2(Angles as, LLine l1, LLine l2, LLine l3, LLine l4) { ax_as_21(as, p2, p1, l3, l4, l1, l2); } + /** + * Processes detailed angle transformations based on intersections and circle conditions. + * This method evaluates intersections between l1 and l3 (or l2 and l4) along with additional + * geometric constraints. If the conditions are met and no conflicting line exists, an auxiliary + * intersection is recorded. + * + * @param as the current Angles instance + * @param p1 the intersection point from the first pair of lines + * @param p2 the intersection point from the second pair of lines + * @param l1 the first line of the first pair + * @param l2 the second line of the first pair + * @param l3 the first line of the second pair + * @param l4 the second line of the second pair + */ void ax_as_21(Angles as, int p1, int p2, LLine l1, LLine l2, LLine l3, LLine l4) { int p3, p4, m; @@ -867,6 +1166,12 @@ void ax_as_21(Angles as, int p1, int p2, LLine l1, LLine l2, LLine l3, LLine l4) } } + /** + * Iterates over all circles and applies various circle-related transformations. + * For each circle that is active (non-zero type), this method triggers a sequence of + * operations including center determination, chord and arc processing, tangent and + * diameter handling. + */ void ax_cr() { ACir cr = all_cir.nx; while (cr != null) { @@ -882,6 +1187,13 @@ void ax_cr() { } } + /** + * Processes the diameter of a circle by evaluating candidate lines from the circle's center + * to its boundary points. If a candidate line exists and does not yield an intersection via + * circle-line logic, an auxiliary intersection is registered. + * + * @param cr the circle to be processed + */ void ax_diameter(ACir cr) { for (int i = 0; i <= cr.no; i++) { LLine ln = fd_ln(cr.o, cr.pt[i]); @@ -891,6 +1203,14 @@ void ax_diameter(ACir cr) { } } + /** + * Processes tangent line generation for a circle. + * If the circle's center is valid and the circle contains concave points, + * the method iterates over the circle's points to determine if a tangent line is missing. + * When a point qualifies, a tangent is created. + * + * @param cr1 the circle to be processed for tangency + */ void ax_tan(ACir cr1) { int i; if (cr1.o == 0 || cr1.no <= 1) return; @@ -902,6 +1222,12 @@ void ax_tan(ACir cr1) { } } + /** + * Checks if a given point is part of a predefined concave point set. + * + * @param p the point to check + * @return true if the point is in the concave set, false otherwise + */ boolean in_conc(int p) { for (int i = 0; i <= 7; i++) if (conc.p[i] == p) return (true); return (false); @@ -937,6 +1263,14 @@ void ax_cr_cr(ACir cr1) { } } + /** + * Processes detailed intersection actions between two circles at specified points. + * + * @param cr1 the first circle involved in the intersection + * @param cr2 the second circle involved in the intersection + * @param p1 the first intersection point from circle calculations + * @param p2 the second intersection point from circle calculations + */ void ax_cr_cr1(ACir cr1, ACir cr2, int p1, int p2) { int p3, p4, p5, p6; ProPoint pt1, pt2, pt3, pt4; @@ -969,6 +1303,11 @@ void ax_cr_cr1(ACir cr1, ACir cr2, int p1, int p2) { } } + /** + * Processes circle intersections by evaluating tangent constructions and auxiliary points. + * + * @param cr the circle for which intersections are processed + */ void ax_cr1(ACir cr) { int p1, p2, p3, p4; LLine l1; @@ -997,6 +1336,11 @@ void ax_cr1(ACir cr) { } } + /** + * Verifies and processes tangent intersections for the provided circle. + * + * @param cr the circle used for tangent intersection checking + */ void ax_cr2(ACir cr) { LLine l1; int o = cr.o; @@ -1012,6 +1356,11 @@ void ax_cr2(ACir cr) { } } + /** + * Determines and processes the center of a circle based on intersecting lines and points. + * + * @param cr the circle for which the center is being determined + */ void ax_center(ACir cr) { LLine l1, l2; PLine pn; @@ -1059,7 +1408,9 @@ void ax_center(ACir cr) { } } - + /** + * Processes point network intersections and applies auxiliary transformations. + */ void ax_pn() { int p1, p2, p3, p4; @@ -1116,20 +1467,9 @@ void ax_pn() { } } - public void add_ax_t1() { - CongSeg cg = all_cg.nx; - while (cg != null) { - if (cg.p1 != cg.p3 && cg.p1 != cg.p4 && cg.p2 != cg.p3 && cg.p2 != cg.p4) { - if (!xpara(cg.p1, cg.p2, cg.p3, cg.p4) && !xcong(cg.p1, cg.p3, cg.p2, cg.p4) - && !xcong(cg.p1, cg.p4, cg.p2, cg.p3)) { -// auxpt_ill(0,) - - } - } - cg = cg.nx; - } - } - + /** + * Processes congruence segments within the point network. + */ public void ax_cg() { CongSeg cg = all_cg.nx; while (cg != null) { @@ -1137,11 +1477,9 @@ public void ax_cg() { } } - - - ////////////////////////////////////////////////////////////////////// - //backward; - + /** + * Initiates the backward process based on current configuration in the point network. + */ public void ax_backward() { int[] p = conc.p; @@ -1164,7 +1502,13 @@ public void ax_backward() { } } - + /** + * Processes backward midpoint transformations for the given points. + * + * @param m the midpoint involved in the transformation + * @param p1 the first point component of the midpoint + * @param p2 the second point component of the midpoint + */ public void ax_bk_mid(int m, int p1, int p2) { //1: rotat. @@ -1175,7 +1519,15 @@ public void ax_bk_mid(int m, int p1, int p2) { -//////////////////////////////////////////////////////////////// + /** + * Calculates the Y coordinate on the tangent line for point p1 using p2 and p3. + * Sets the point pt with an X coordinate of 0 and the computed Y coordinate. + * + * @param pt the point to update with the computed coordinate + * @param p1 the reference point for the tangent calculation + * @param p2 the second point used in the calculation + * @param p3 the third point used in the calculation + */ public void cal_ax_tn(ProPoint pt, int p1, int p2, int p3) { double x1 = VPTX(p1); double y1 = VPTY(p1); @@ -1188,6 +1540,14 @@ public void cal_ax_tn(ProPoint pt, int p1, int p2, int p3) { pt.setXY(0, y); } + /** + * Calculates the midpoint of points p1 and p2. + * Updates pt with the computed midpoint coordinates. + * + * @param pt the point to update with the midpoint coordinates + * @param p1 the first point + * @param p2 the second point + */ public void cal_ax_md(ProPoint pt, int p1, int p2) { double x1 = VPTX(p1); double y1 = VPTY(p1); @@ -1196,6 +1556,17 @@ public void cal_ax_md(ProPoint pt, int p1, int p2) { pt.setXY((x1 + x2) / 2, (y1 + y2) / 2); } + /** + * Calculates the intersection point between the lines defined by (p1, p2) and (p3, p4). + * Updates pt with the computed intersection coordinates if valid. + * + * @param pt the point to update with the intersection coordinates + * @param p1 the first point of the first line + * @param p2 the second point of the first line + * @param p3 the first point of the second line + * @param p4 the second point of the second line + * @return true if an intersection point is successfully computed, false otherwise + */ public boolean cal_ax_ill(ProPoint pt, int p1, int p2, int p3, int p4) { double x1 = VPTX(p1); double y1 = VPTY(p1); @@ -1225,6 +1596,15 @@ public boolean cal_ax_ill(ProPoint pt, int p1, int p2, int p3, int p4) { return true; } + /** + * Calculates the foot of the perpendicular from point p1 to the line defined by p2 and p3. + * Updates pt with the computed foot coordinates. + * + * @param pt the point to update with the foot coordinates + * @param p1 the point from which the perpendicular is drawn + * @param p2 the first point defining the line + * @param p3 the second point defining the line + */ public void cal_ax_foot(ProPoint pt, int p1, int p2, int p3) { double x1 = VPTX(p1); double y1 = VPTY(p1); @@ -1240,6 +1620,18 @@ public void cal_ax_foot(ProPoint pt, int p1, int p2, int p3) { pt.setXY(x, y); } + /** + * Calculates the intersection point for a line configuration using points p1, p2, p3, p4, and p5. + * Updates pt with the computed intersection coordinates. + * + * @param pt the point to update with the intersection coordinates + * @param p1 the first reference point + * @param p2 the second reference point + * @param p3 the third reference point + * @param p4 the fourth reference point + * @param p5 the fifth reference point + * @return true if the intersection is successfully computed, false otherwise + */ public boolean cal_ax_ilp(ProPoint pt, int p1, int p2, int p3, int p4, int p5) { double x1 = VPTX(p1); double y1 = VPTY(p1); @@ -1271,33 +1663,15 @@ public boolean cal_ax_ilp(ProPoint pt, int p1, int p2, int p3, int p4, int p5) { return true; } - public void cal_ax_ilt(ProPoint pt, int p1, int p2, int p3, int p4, int p5) { - double x1 = VPTX(p1); - double y1 = VPTY(p1); - double x2 = VPTX(p2); - double y2 = VPTY(p2); - double x3 = VPTX(p3); - double y3 = VPTY(p3); - double x4 = VPTX(p4); - double y4 = VPTY(p4); - double x5 = VPTX(p5); - double y5 = VPTY(p5); - - double xt1 = x2 - x1; - double xt2 = -(y5 - y4); - double yt1 = y2 - y1; - double yt2 = x5 - x4; - if (Math.abs(xt1) > ZERO) { - double x = (xt1 * xt2 * (y3 - y1) + yt1 * x1 * xt2 - yt2 * x3 * xt1) / (yt1 * xt2 - yt2 * xt1); - double y = y1 + (x - x1) * yt1 / xt1; - pt.setXY(x, y); - } else { - double x = x1; - double y = y3 + yt2 * (x - x3) / xt2; - pt.setXY(x, y); - } - } - + /** + * Calculates the center based on the configuration of points p1, p2, and p3. + * Updates pt with the computed center coordinates. + * + * @param pt the point to update with the center coordinates + * @param p1 the first reference point + * @param p2 the second reference point + * @param p3 the third reference point + */ public void cal_ax_co(ProPoint pt, int p1, int p2, int p3) { double x_1 = VPTX(p1); double x_2 = VPTY(p1); @@ -1318,6 +1692,19 @@ public void cal_ax_co(ProPoint pt, int p1, int p2, int p3) { pt.setXY(x, y); } + /** + * Calculates the intersection point between a translated line and a circle. + * The translation is based on the vector from p1 to p2 applied to p3. + * Updates pt with the computed intersection coordinates. + * + * @param pt the point to update with the intersection coordinates + * @param p1 the first reference point for the translation vector + * @param p2 the second reference point for the translation vector + * @param p3 the base point for translation + * @param p4 the first point defining the circle + * @param p5 the second point defining the circle + * @return true if the intersection is successfully computed, false otherwise + */ public boolean cal_ax_ipc(ProPoint pt, int p1, int p2, int p3, int p4, int p5) { double x1 = VPTX(p1); double y1 = VPTY(p1); @@ -1342,6 +1729,18 @@ public boolean cal_ax_ipc(ProPoint pt, int p1, int p2, int p3, int p4, int p5) { return true; } + /** + * Calculates the intersection point between the line defined by p1 and p2 + * and the circle defined by p3 and p4. + * Updates pt with the computed intersection coordinates. + * + * @param pt the point to update with the intersection coordinates + * @param p1 the first point defining the line + * @param p2 the second point defining the line + * @param p3 the first point defining the circle + * @param p4 the second point defining the circle + * @return true if an intersection point is successfully computed, false otherwise + */ public boolean cal_ax_ilc(ProPoint pt, int p1, int p2, int p3, int p4) { double x1 = VPTX(p1); double y1 = VPTY(p1); @@ -1360,6 +1759,21 @@ public boolean cal_ax_ilc(ProPoint pt, int p1, int p2, int p3, int p4) { return true; } + /** + * Computes the intersection points between the line defined by (x1, y1) and (x2, y2) + * and the circle defined by center (x3, y3) with a radius derived from (x4, y4). + * Returns an array containing two intersection points formatted as [t1, m1, t2, m2]. + * + * @param x1 the x-coordinate of the first point on the line + * @param y1 the y-coordinate of the first point on the line + * @param x2 the x-coordinate of the second point on the line + * @param y2 the y-coordinate of the second point on the line + * @param x3 the x-coordinate used as a reference for the circle + * @param y3 the y-coordinate used as a reference for the circle + * @param x4 the x-coordinate used to derive the circle's radius + * @param y4 the y-coordinate used to derive the circle's radius + * @return an array containing the intersection points [t1, m1, t2, m2], or an empty array if there are none + */ double[] cal_inter_lc(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) { double r2 = (y4 - y3) * (y4 - y3) + (x4 - x3) * (x4 - x3); @@ -1399,6 +1813,12 @@ public boolean cal_ax_ilc(ProPoint pt, int p1, int p2, int p3, int p4) { } } + /** + * Generates a descriptive string for the given point based on its type. + * Updates the text attribute of pt with the generated description. + * + * @param pt the point for which the description is generated + */ void auxpt_string(ProPoint pt) { String s = pt.toString(); if (s == null || s.length() == 0) { @@ -1432,6 +1852,12 @@ void auxpt_string(ProPoint pt) { } } + /** + * Generates and returns an auxiliary name for a new point. + * The name is determined based on existing constraint names. + * + * @return the generated auxiliary name + */ protected String fd_aux_name() { char c[] = new char[1];//= new char[3]; int len = 1; diff --git a/src/main/java/gprover/GDDBase.java b/src/main/java/gprover/GDDBase.java index e4019670..69ba0a30 100644 --- a/src/main/java/gprover/GDDBase.java +++ b/src/main/java/gprover/GDDBase.java @@ -6,9 +6,20 @@ * To change this template use File | Settings | File Templates. */ package gprover; - +/** + * Base class for geometric deduction database operations. + */ public class GDDBase extends Gib { + /** + * Returns an index corresponding to the occurrence of a value among three candidates. + * + * @param p the value to match + * @param p1 the first candidate value + * @param p2 the second candidate value + * @param p3 the third candidate value + * @return 1 if p equals p1, 2 if p equals p2, 3 if p equals p3, otherwise 0 + */ final int ind_3(int p, int p1, int p2, int p3) { if (p == p1) return (1); if (p == p2) return (2); @@ -16,6 +27,13 @@ final int ind_3(int p, int p1, int p2, int p3) { return (0); } + /** + * Returns an index corresponding to the occurrence of a value among the first three elements of an array. + * + * @param p the value to match + * @param pp an array of candidate values (must contain at least three elements) + * @return 1 if p equals pp[0], 2 if p equals pp[1], 3 if p equals pp[2], otherwise 0 + */ final int ind_3(int p, int[] pp) { if (p == pp[0]) return (1); if (p == pp[1]) return (2); @@ -23,7 +41,14 @@ final int ind_3(int p, int[] pp) { return (0); } - + /** + * Determines whether the points identified by a, b, and c are collinear and registers the condition if true. + * + * @param a the first point + * @param b the second point + * @param c the third point + * @return true if the points are collinear, false otherwise + */ final boolean ycoll(int a, int b, int c) { boolean i = xcoll(a, b, c); if (i) { @@ -32,14 +57,15 @@ final boolean ycoll(int a, int b, int c) { return (i); } - final boolean ypara(int a, int b, int p, int q) { - boolean i = xpara(a, b, p, q); - if (i) { - add_codb(CO_PARA, a, b, p, q, 0, 0, 0, 0); - } - return (i); - } - + /** + * Determines whether the lines defined by points (a, b) and (p, q) are perpendicular and records the condition if so. + * + * @param a the first point on the first line + * @param b the second point on the first line + * @param p the first point on the second line + * @param q the second point on the second line + * @return true if the lines are perpendicular, false otherwise + */ final boolean yperp(int a, int b, int p, int q) { boolean i = xperp(a, b, p, q); if (i) { @@ -48,6 +74,15 @@ final boolean yperp(int a, int b, int p, int q) { return (i); } + /** + * Checks whether the segments defined by (a, b) and (p, q) are congruent and registers the condition if they are. + * + * @param a the first point of the first segment + * @param b the second point of the first segment + * @param p the first point of the second segment + * @param q the second point of the second segment + * @return true if the segments are congruent, false otherwise + */ final boolean ycong(int a, int b, int p, int q) { boolean i = xcong(a, b, p, q); if (i) { @@ -56,26 +91,25 @@ final boolean ycong(int a, int b, int p, int q) { return (i); } - final boolean yacong(int a, int b, int c, int p, int q, int r) { - boolean i = xacong(a, b, c, p, q, r); - if (i) { - add_codb(CO_ACONG, a, b, b, c, p, q, q, r); - } - return (i); - } - - final boolean ycir2(int o, int a, int b) { - boolean i = xcir2(o, a, b); - if (i) { - add_codb(CO_CYCLIC, o, a, b, 0, 0, 0, 0, 0); - } - return (i); - } - + /** + * Checks if the given identifier is below the current depth or if the point registry is full. + * + * @param id the identifier to check + * @return true if id is less than depth or the point registry is full, false otherwise + */ final boolean ch_dep(long id) { return id < depth || isPFull(); } + /** + * Processes the provided circular arc by adding corresponding conditions for parallelism, cyclicity, and congruence. + * + * @param cr the circular arc used to derive conditions + * @param m1 the first marker or identifier related to the arc + * @param m2 the second marker or identifier related to the arc + * @param p1 the first point used for condition registration + * @param p2 the second point used for condition registration + */ final void add_cr_pn_as(ACir cr, int m1, int m2, int p1, int p2) { int lm = R_CR_P_EQARC; @@ -106,6 +140,15 @@ final void add_cr_pn_as(ACir cr, int m1, int m2, int p1, int p2) { pop_codb(); } + /** + * Applies type 3 processing by adding cyclic, midpoint, and angle conditions based on the given markers and points. + * + * @param m the primary marker + * @param m2 the marker for the first midpoint condition + * @param p2 the point used in cyclic and midpoint conditions + * @param m3 the marker for the second midpoint condition + * @param p3 the point used in cyclic and midpoint conditions + */ final void add_type3(int m, int m2, int p2, int m3, int p3) { int p1; add_codb(CO_CYCLIC, m, p2, p3, 0, 0, 0, 0, 0); @@ -127,22 +170,15 @@ final void add_type3(int m, int m2, int p2, int m3, int p3) { pop_codb(); } - final void add_type4(int m, int m1, int p1, int m2, int p2) { - add_codb(CO_PARA, m1, m2, p1, p2, 0, 0, 0, 0); - add_codb(CO_CYCLIC, m, p1, p2, 0, 0, 0, 0, 0); - add_codb(CO_MIDP, m, m1, m2, 0, 0, 0, 0, 0); - add_cir4(64, 0, m1, m2, p1, p2); - add_ea_pt_t(64, m1, m, p1, p2, m, m2); - add_ea_pt_t(64, m1, p1, m, m, p2, m2); - add_ea_pt_t(64, m2, m, p1, p2, m, m1); - add_ea_pt_t(64, m2, p1, m, m, p2, m1); - pop_codb(); - pop_codb(); - pop_codb(); - } - /* Lemmas */ + /** + * Searches for perpendicular and parallel relationships between a point-based + * line and a t-line, and adds corresponding conditions. + * + * @param pn the point-based line + * @param tn the t-line to be analyzed + */ final void search_pn_tn(PLine pn, TLine tn) { LLine ln, l1, l2; int i; @@ -175,6 +211,14 @@ final void search_pn_tn(PLine pn, TLine tn) { } } + /** + * Establishes a midpoint connection based on a midpoint object and two lines, + * adding necessary conditions if valid. + * + * @param md the midpoint instance containing connection data + * @param l1 the first line for connection + * @param l2 the second line for connection + */ final void lm_md_connection(MidPt md, LLine l1, LLine l2) { int lm = R_MID_CONNECTION; if (!valid(lm)) return; @@ -207,11 +251,25 @@ final void lm_md_connection(MidPt md, LLine l1, LLine l2) { } } + /** + * Checks if the given integer meets connection criteria based on internal state. + * + * @param n the value to be checked + * @return true if the condition is met, false otherwise + */ boolean ch_it(int n) { return ((d_base != 0) ? (n != 0) : ((n) == 1)); } + /** + * Constructs a parallelogram configuration based on a midpoint and two lines, + * adding conditions and lines if the configuration is valid. + * + * @param md the midpoint used for establishing the parallelogram + * @param l1 the first line of the configuration + * @param l2 the second line of the configuration + */ final void lm_parallelogram(MidPt md, LLine l1, LLine l2) { if (!valid(R_PARALLELOGRAM)) return; @@ -261,7 +319,15 @@ final void lm_parallelogram(MidPt md, LLine l1, LLine l2) { } } - + /** + * Establishes a ratio condition based on intersections of lines defined by points. + * + * @param lm the lemma identifier for the ratio condition + * @param p1 the first point of the first line + * @param p2 the second point of the first line + * @param p3 the first point of the second line + * @param p4 the second point of the second line + */ final void lm_RATIO(int lm, int p1, int p2, int p3, int p4) { if (!valid(R_RATIO)) return; @@ -280,19 +346,23 @@ final void lm_RATIO(int lm, int p1, int p2, int p3, int p4) { } } - /////////////////////////////////////////////////////////////////////////// - /// this frome pred.cpp - - final void copy_pred(Cond p1, Cond p2) { - p2.pred = p1.pred; - p2.u.cpv(p1.u); - for (int i = 0; i <= 7; i++) p2.p[i] = p1.p[i]; - } - + /** + * Determines whether two condition nodes are equivalent. + * + * @param n1 the first condition node + * @param n2 the second condition node + * @return true if both nodes are equivalent, false otherwise + */ boolean new_eq(Cond n1, Cond n2) { return (n1.pred == n2.pred && n1.u.equal(n2.u)); } + /** + * Creates a new condition node with a given predicate value. + * + * @param pred the predicate identifier for the condition + * @return a new condition node instance + */ final Cond new_pr(int pred) { Cond nd = new Cond(); nd.pred = pred; @@ -309,6 +379,9 @@ final Cond new_pr(int pred) { return nd; } + /** + * Adjusts the condition list by updating the last condition based on equivalence. + */ final void new_ot() { int i = 0; Cond nd1, nd = all_nd.nx; @@ -324,6 +397,20 @@ final void new_ot() { } } + /** + * Creates and adds a new condition node with specified properties. + * + * @param n the predicate or condition type + * @param p1 the first parameter + * @param p2 the second parameter + * @param p3 the third parameter + * @param p4 the fourth parameter + * @param p5 the fifth parameter + * @param p6 the sixth parameter + * @param p7 the seventh parameter + * @param p8 the eighth parameter + * @return the newly created condition node + */ Cond add_codb(int n, int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8) { // if(p1 == 1 && p2 ==4 && p3 == 1 && p4 == 9) @@ -381,6 +468,9 @@ Cond add_codb(int n, int p1, int p2, int p3, int p4, int p5, int p6, int p7, int } + /** + * Removes the last added condition node from the condition database. + */ final void pop_codb() { Cond co = co_db.nx; if (co != null) { @@ -388,6 +478,12 @@ final void pop_codb() { } /* free((cond *)co); */ } + /** + * Creates and adds a new coordinate condition node with the specified predicate. + * + * @param n the predicate for the coordinate condition + * @return the newly created coordinate condition node + */ Cond add_coxy(int n) { Cond co = new Cond(); co.pred = n; @@ -404,16 +500,11 @@ Cond add_coxy(int n) { return (co); } - final void add_codx(int n, int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8) { - Cond co = add_codb(n, p1, p2, p3, p4, p5, p6, p7, p8); - if (co.pred != 0) { - co_db.nx = co.nx; - co.nx = co_xy.nx; - co_xy.nx = co; - } - } - - + /** + * Creates and adds a new parallel condition node associated with the given predicted line. + * + * @param pn the predicted line to be associated with the parallel condition + */ final void new_para(PLine pn) { Cond nd = new Cond(); nd.pred = CO_PARA; @@ -426,10 +517,14 @@ final void new_para(PLine pn) { } } - ////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - /* geometry predictaes */ - + /** + * Checks if the three specified points are collinear. + * + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @return true if the points are collinear, false otherwise + */ final boolean xcoll(int p1, int p2, int p3) { LLine ln; @@ -440,7 +535,14 @@ final boolean xcoll(int p1, int p2, int p3) { return (ln != null); } - + /** + * Finds and returns the line that contains the three specified points, if such a line exists. + * + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @return the line (LLine) containing the points, or null if none exists + */ final LLine fo_ln3(int p1, int p2, int p3) { LLine ln; ln = all_ln.nx; @@ -453,6 +555,13 @@ final LLine fo_ln3(int p1, int p2, int p3) { return (null); } + /** + * Finds and returns a line that passes through all specified non-zero points in the array. + * + * @param ps an array of points + * @param n the number of indices to check in the array + * @return the line (LLine) if found, or null otherwise + */ final LLine fo_ln(int ps[], int n) ///xxxxx { LLine ln; @@ -474,17 +583,44 @@ final LLine fo_ln(int ps[], int n) ///xxxxx return (null); } + /** + * Checks if the four points satisfy collinearity conditions. + * If the first two points are equal, it delegates to xcoll; otherwise, it ensures collinearity for both + * subsets. + * + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @param p4 the fourth point + * @return true if the relevant points are collinear, false otherwise + */ final boolean xcoll4(int p1, int p2, int p3, int p4) { if (p1 == p2) return (xcoll(p2, p3, p4)); return (xcoll(p1, p2, p3) && xcoll(p1, p2, p4)); } + /** + * Determines whether the two lines defined by the point pairs (p1, p2) and (p3, p4) are parallel. + * + * @param p1 the first point of the first line + * @param p2 the second point of the first line + * @param p3 the first point of the second line + * @param p4 the second point of the second line + * @return true if the lines are parallel, false otherwise + */ final boolean xpara(int p1, int p2, int p3, int p4) { if (p1 == p2 || p3 == p4 || xcoll4(p1, p2, p3, p4)) return (true); return (fo_pn1(p1, p2, p3, p4) != null); } + /** + * Determines whether the two specified lines are parallel. + * + * @param l1 the first line + * @param l2 the second line + * @return true if the lines are parallel, false otherwise + */ final boolean ln_para(LLine l1, LLine l2) { PLine pn; if (l1 == l2) return (true); @@ -512,35 +648,27 @@ final boolean ln_para(LLine l1, LLine l2) { return (false); } - final PLine fo_pn(int p1, int p2, int p3, int p4) { - PLine pn = all_pn.nx; - while (pn != null) { - if (pn.no == 0) { - pn = pn.nx; - continue; - } - for (int i = 0; i <= pn.no; i++) { - if (on_ln(p1, pn.ln[i]) && on_ln(p2, pn.ln[i])) { - for (int j = i + 1; j <= pn.no; j++) - if (on_ln(p3, pn.ln[j]) && on_ln(p4, pn.ln[j])) return (pn); - if (pn.type != 0) return (null); //?? - } else if (on_ln(p3, pn.ln[i]) && on_ln(p4, pn.ln[i])) { - for (int j = i + 1; j <= pn.no; j++) - if (on_ln(p1, pn.ln[j]) && on_ln(p2, pn.ln[j])) return (pn); - if (pn.type != 0) return (null);//?? - } - } - pn = pn.nx; - } - return (null); - } - + /** + * Checks if the two lines defined by the points (p1, p2) and (p3, p4) are perpendicular. + * + * @param p1 the first point of the first line + * @param p2 the second point of the first line + * @param p3 the first point of the second line + * @param p4 the second point of the second line + * @return true if the lines are perpendicular, false otherwise + */ final boolean xperp(int p1, int p2, int p3, int p4) { if (p1 == p2 || p3 == p4) return (true); return fo_tn1(p1, p2, p3, p4) != null; } - + /** + * Determines whether the two specified lines are perpendicular. + * + * @param l1 the first line + * @param l2 the second line + * @return true if the lines are perpendicular, false otherwise + */ final boolean ln_perp(LLine l1, LLine l2) { if (l1 == l2) return false; if (l1 == null) { @@ -567,23 +695,12 @@ final boolean ln_perp(LLine l1, LLine l2) { return (false); } - final TLine fo_tn(int p1, int p2, int p3, int p4) { - LLine ln1, ln2; - TLine tn; - if (p1 == p2 || p3 == p4) return (null); - ln1 = fd_ln(p1, p2); - if (ln1 == null) return (null); - ln2 = fd_ln(p3, p4); - if (ln2 == null) return (null); - tn = all_tn.nx; - while (tn != null) { - if ((tn.l1 == ln1 && tn.l2 == ln2) || (tn.l1 == ln2 && tn.l2 == ln1)) return (tn); - tn = tn.nx; - } - return (null); - } - - + /** + * Searches for an existing circle that is a sub-circle of the given circle. + * + * @param c1 the reference circle (ACir) to compare against + * @return an existing circle that matches, or null if none is found + */ final ACir xcir(ACir c1) { ACir c2; c2 = all_cir.nx; @@ -594,6 +711,16 @@ final ACir xcir(ACir c1) { return (null); } + /** + * Finds and returns a circle based on a specified property and four points. + * + * @param o the circle property or type indicator + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @param p4 the fourth point + * @return the found circle (ACir) or null if none exists + */ final ACir fo_cr(int o, int p1, int p2, int p3, int p4) { test_c.o = o; test_c.no = 3; @@ -604,6 +731,14 @@ final ACir fo_cr(int o, int p1, int p2, int p3, int p4) { return (xcir(test_c)); } + /** + * Checks for the existence of a circle defined by the given property and two points. + * + * @param o the circle property or type indicator + * @param p1 the first point + * @param p2 the second point + * @return true if such a circle exists, false otherwise + */ final boolean xcir2(int o, int p1, int p2) { test_c.o = o; test_c.no = 1; @@ -612,6 +747,15 @@ final boolean xcir2(int o, int p1, int p2) { return (xcir(test_c) != null); } + /** + * Checks for the existence of a circle defined by the given property and three points. + * + * @param o the circle property or type indicator + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @return true if such a circle exists, false otherwise + */ final boolean xcir3(int o, int p1, int p2, int p3) { test_c.o = o; test_c.no = 2; @@ -621,6 +765,16 @@ final boolean xcir3(int o, int p1, int p2, int p3) { return (xcir(test_c) != null); } + /** + * Checks for the existence of a circle defined by the given property and four points. + * + * @param o the circle property or type indicator + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @param p4 the fourth point + * @return true if such a circle exists, false otherwise + */ final boolean xcir4(int o, int p1, int p2, int p3, int p4) { test_c.o = o; test_c.no = 3; @@ -631,21 +785,26 @@ final boolean xcir4(int o, int p1, int p2, int p3, int p4) { return (xcir(test_c) != null); } - final boolean xcir5(int o, int p1, int p2, int p3, int p4, int p5) { - test_c.o = o; - test_c.no = 4; - test_c.pt[0] = p1; - test_c.pt[1] = p2; - test_c.pt[2] = p3; - test_c.pt[3] = p4; - test_c.pt[4] = p5; - return (xcir(test_c) != null); - } - + /** + * Checks if a midpoint exists for the specified segment within the given model. + * + * @param m the model identifier + * @param a the first endpoint of the segment + * @param b the second endpoint of the segment + * @return true if a midpoint exists for the segment, false otherwise + */ final boolean xmid(int m, int a, int b) { return (fo_md(m, a, b) != null); } + /** + * Searches for and returns a midpoint corresponding to the specified model and endpoints. + * + * @param m the model identifier + * @param a the first endpoint + * @param b the second endpoint + * @return the midpoint (MidPt) if found, or null otherwise + */ final MidPt fo_md(int m, int a, int b) { MidPt md = all_md.nx; while (md != null) { @@ -658,6 +817,13 @@ final MidPt fo_md(int m, int a, int b) { return (null); } + /** + * Searches for and returns a midpoint defined by the two specified endpoints. + * + * @param a the first endpoint + * @param b the second endpoint + * @return the midpoint (MidPt) if one exists, or null otherwise + */ final MidPt fo_md(int a, int b) { MidPt md = all_md.nx; while (md != null) { @@ -669,6 +835,17 @@ final MidPt fo_md(int a, int b) { return (null); } + /** + * Determines if the angles defined by points (a, b, c) and (p, q, r) are congruent. + * + * @param a the first point of the first angle + * @param b the vertex of the first angle + * @param c the third point of the first angle + * @param p the first point of the second angle + * @param q the vertex of the second angle + * @param r the third point of the second angle + * @return true if the angles are congruent, false otherwise + */ final boolean xacong(int a, int b, int c, int p, int q, int r) { if (!check_eqangle(a, b, c, p, q, r)) { return false; @@ -683,6 +860,19 @@ final boolean xacong(int a, int b, int c, int p, int q, int r) { return (ln_acong(l1, l2, l3, l4)); } + /** + * Determines if the angles defined by points (a, b, c, d) and (p, q, r, s) are congruent. + * + * @param a the first point of the first angle + * @param b the second point of the first angle + * @param c the third point of the first angle + * @param d the fourth point of the first angle + * @param p the first point of the second angle + * @param q the second point of the second angle + * @param r the third point of the second angle + * @param s the fourth point of the second angle + * @return true if the angles are congruent, false otherwise + */ final boolean xacong(int a, int b, int c, int d, int p, int q, int r, int s) { if (!check_eqangle(a, b, c, d, p, q, r, s)) return false; @@ -695,7 +885,13 @@ final boolean xacong(int a, int b, int c, int d, int p, int q, int r, int s) { return (ln_acong(l1, l2, l3, l4)); } - + /** + * Compares two lines based on their unique identifiers. + * + * @param l1 the first line to compare + * @param l2 the second line to compare + * @return 1 if l1 has a greater id than l2, 0 if they are equal, -1 if l1 has a smaller id than l2 + */ final int line_compare(LLine l1, LLine l2) { if (l1 == null) { // TODO. Handle this. @@ -713,6 +909,16 @@ final int line_compare(LLine l1, LLine l2) { return 0; } + /** + * Retrieves the angle set associated with the given four lines. + * Depending on the current state, a different method is used to generate the angle set. + * + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @param l4 the fourth line + * @return the set of angles (Angles) if found, or null otherwise + */ final Angles fo_las(LLine l1, LLine l2, LLine l3, LLine l4) { Angles as; if (isPFull()) @@ -722,7 +928,16 @@ final Angles fo_las(LLine l1, LLine l2, LLine l3, LLine l4) { return as; } - final Angles fo_las0(LLine l1, LLine l2, LLine l3, LLine l4) //???? + /** + * Determines the angle set for the provided four lines based on available line ordering and comparisons. + * + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @param l4 the fourth line + * @return the angle set (Angles) if found, or null otherwise + */ + final Angles fo_las0(LLine l1, LLine l2, LLine l3, LLine l4) { LLine n1, n2; Angles as; @@ -795,17 +1010,15 @@ final Angles fo_las0(LLine l1, LLine l2, LLine l3, LLine l4) //???? return (null); } - final Angles fo_as(int a, int b, int c, int d, int p, int q, int r, int s) { - LLine l1, l2, l3, l4; - l1 = fd_ln(a, b); - l2 = fd_ln(c, d); - l3 = fd_ln(p, q); - l4 = fd_ln(r, s); - if (l1 == null || l2 == null || l3 == null || l4 == null) return (null); - return (fo_las(l1, l2, l3, l4)); - } - - + /** + * Determines if the angles defined by (l1, l2) and (l3, l4) are congruent. + * + * @param l1 first line of the first angle + * @param l2 second line of the first angle + * @param l3 first line of the second angle + * @param l4 second line of the second angle + * @return true if the angles are congruent, false otherwise + */ final boolean ln_acong(LLine l1, LLine l2, LLine l3, LLine l4) { if (l1 == null || l2 == null || l3 == null || l4 == null) { int k = 0; @@ -828,7 +1041,15 @@ final boolean ln_acong(LLine l1, LLine l2, LLine l3, LLine l4) { return (fo_las(l1, l2, l3, l4) != null); } - + /** + * Checks whether the segments defined by endpoints a, b and p, q are congruent. + * + * @param a first endpoint of the first segment + * @param b second endpoint of the first segment + * @param p first endpoint of the second segment + * @param q second endpoint of the second segment + * @return true if the segments are congruent, false otherwise + */ final boolean xcong(int a, int b, int p, int q) { if (!check_eqdistance(a, b, p, q)) return false; @@ -864,6 +1085,17 @@ final boolean xcong(int a, int b, int p, int q) { return (false); } + /** + * Determines if the segments (a, b) and (p, q) are congruent using specific angle values. + * + * @param a first endpoint of the first segment + * @param b second endpoint of the first segment + * @param p first endpoint of the second segment + * @param q second endpoint of the second segment + * @param t1 first angle factor for congruency check + * @param t2 second angle factor for congruency check + * @return true if the segments are congruent based on the provided ratios, false otherwise + */ final boolean xcong1(int a, int b, int p, int q, int t1, int t2) { CongSeg cg; int o; @@ -903,10 +1135,28 @@ final boolean xcong1(int a, int b, int p, int q, int t1, int t2) { return cg.t1 * t1 == cg.t2 * t2; } + /** + * Checks if the segments (a, b) and (c, d) are congruent using both default and extended methods. + * + * @param a first endpoint of the first segment + * @param b second endpoint of the first segment + * @param c first endpoint of the second segment + * @param d second endpoint of the second segment + * @return true if the segments are congruent by any method, false otherwise + */ final boolean xcong_all(int a, int b, int c, int d) { return xcong(a, b, c, d) || xcong1(a, b, c, d); } + /** + * Checks whether the segments defined by endpoints a, b and p, q are congruent using an alternative ratio approach. + * + * @param a first endpoint of the first segment + * @param b second endpoint of the first segment + * @param p first endpoint of the second segment + * @param q second endpoint of the second segment + * @return true if the segments are congruent, false otherwise + */ final boolean xcong1(int a, int b, int p, int q) { CongSeg cg; int o; @@ -939,6 +1189,15 @@ final boolean xcong1(int a, int b, int p, int q) { return (false); } + /** + * Searches for a congruent segment in the ratio group for segments (a, b) and (p, q). + * + * @param a first endpoint of the first segment + * @param b second endpoint of the first segment + * @param p first endpoint of the second segment + * @param q second endpoint of the second segment + * @return the congruent segment if found, null otherwise + */ final CongSeg fo_rg1(int a, int b, int p, int q) { CongSeg cg = all_rg.nx; while (cg != null) { @@ -948,6 +1207,15 @@ final CongSeg fo_rg1(int a, int b, int p, int q) { return null; } + /** + * Returns the first matching congruent segment from the ratio list based on endpoints (a, b) and (p, q). + * + * @param a first endpoint of the first segment + * @param b second endpoint of the first segment + * @param p first endpoint of the second segment + * @param q second endpoint of the second segment + * @return the congruent segment if present; null otherwise + */ final CongSeg fo_cg1(int a, int b, int p, int q) { CongSeg cg; int o; @@ -970,6 +1238,15 @@ final CongSeg fo_cg1(int a, int b, int p, int q) { return (null); } + /** + * Retrieves a congruent segment from the common group based on endpoints (a, b) and (p, q). + * + * @param a first endpoint of the first segment + * @param b second endpoint of the first segment + * @param p first endpoint of the second segment + * @param q second endpoint of the second segment + * @return the congruent segment if found, null otherwise + */ final CongSeg fo_cg(int a, int b, int p, int q) { CongSeg cg; int o; @@ -992,17 +1269,52 @@ final CongSeg fo_cg(int a, int b, int p, int q) { return (null); } + /** + * Determines whether the triangles defined by points (a, b, c) and (p, q, r) are similar. + * + * @param a first vertex of the first triangle + * @param b second vertex of the first triangle + * @param c third vertex of the first triangle + * @param p first vertex of the second triangle + * @param q second vertex of the second triangle + * @param r third vertex of the second triangle + * @return true if the triangles are similar, false otherwise + */ boolean xsim_tri(int a, int b, int c, int p, int q, int r) { if (!check_simtri(a, b, c, p, q, r)) return false; return (fo_st(1, 0, a, b, c, p, q, r) != null); } + /** + * Determines whether the triangles defined by points (a, b, c) and (p, q, r) are congruent. + * + * @param a first vertex of the first triangle + * @param b second vertex of the first triangle + * @param c third vertex of the first triangle + * @param p first vertex of the second triangle + * @param q second vertex of the second triangle + * @param r third vertex of the second triangle + * @return true if the triangles are congruent, false otherwise + */ boolean xcon_tri(int a, int b, int c, int p, int q, int r) { if (!this.check_simtri(a, b, c, p, q, r)) return false; return (fo_st(0, 0, a, b, c, p, q, r) != null); } + /** + * Finds a similar or congruent triangle structure based on the provided vertices. + * + * @param xsim_2 flag to indicate extended similarity testing + * @param xsim_1 flag to optionally bypass congruency type check + * @param a first vertex of the first triangle + * @param b second vertex of the first triangle + * @param c third vertex of the first triangle + * @param p first vertex of the second triangle + * @param q second vertex of the second triangle + * @param r third vertex of the second triangle + * @return the triangle structure if found, null otherwise + */ SimTri fo_st(int xsim_2, int xsim_1, int a, int b, int c, int p, int q, int r) { SimTri st = (xsim_2 != 0) ? all_st.nx : all_ct.nx; //??? while (st != null) { @@ -1014,6 +1326,19 @@ SimTri fo_st(int xsim_2, int xsim_1, int a, int b, int c, int p, int q, int r) { return (null); } + /** + * Checks if the ratio of lengths between segments (a, b) and (c, d) equals that between (p, q) and (r, s). + * + * @param a first endpoint of the first segment + * @param b second endpoint of the first segment + * @param c first endpoint of the second segment + * @param d second endpoint of the second segment + * @param p first endpoint of the third segment + * @param q second endpoint of the third segment + * @param r first endpoint of the fourth segment + * @param s second endpoint of the fourth segment + * @return true if the ratios are equal, false otherwise + */ boolean xeq_ratio(int a, int b, int c, int d, int p, int q, int r, int s) { if ((xcong(a, b, p, q) && xcong(c, d, r, s)) || (xcong(a, b, c, d) && xcong(p, q, r, s)) || @@ -1022,6 +1347,19 @@ boolean xeq_ratio(int a, int b, int c, int d, int p, int q, int r, int s) { return (fo_ra(a, b, c, d, p, q, r, s) != null); } + /** + * Finds and returns the ratio segment structure that matches the given endpoints. + * + * @param a first endpoint of the first segment + * @param b second endpoint of the first segment + * @param c first endpoint of the second segment + * @param d second endpoint of the second segment + * @param p first endpoint of the third segment + * @param q second endpoint of the third segment + * @param r first endpoint of the fourth segment + * @param s second endpoint of the fourth segment + * @return the matching ratio segment structure if found, null otherwise + */ RatioSeg fo_ra(int a, int b, int c, int d, int p, int q, int r, int s) { RatioSeg ra = all_ra.nx; for (; ra != null; ra = ra.nx) { @@ -1038,7 +1376,13 @@ RatioSeg fo_ra(int a, int b, int c, int d, int p, int q, int r, int s) { return (null); } - + /** + * Compares two lines based on their primary endpoints. + * + * @param l1 the first line to compare + * @param l2 the second line to compare + * @return true if l1 is considered less than l2, false otherwise + */ boolean ln_less(LLine l1, LLine l2) { if (l1 == l2) return (false); if (l1.pt[1] < l2.pt[1]) return (true); @@ -1047,6 +1391,15 @@ boolean ln_less(LLine l1, LLine l2) { return (false); } + /** + * Compares two pairs of lines to determine order. + * + * @param l1 first line of the first pair + * @param l2 second line of the first pair + * @param l3 first line of the second pair + * @param l4 second line of the second pair + * @return true if the second pair is considered less than the first pair, false otherwise + */ boolean l2_less(LLine l1, LLine l2, LLine l3, LLine l4) { LLine ln; if (ln_less(l2, l1)) { @@ -1064,16 +1417,15 @@ boolean l2_less(LLine l1, LLine l2, LLine l3, LLine l4) { return (false); } - - int get_cpt2(ACir c1, int p1, int p2) { - char j; - if (c1 == null) return 0; /// 2006.7.10 - for (j = 0; j <= c1.no; j++) { - if (c1.pt[j] != p1 && c1.pt[j] != p2) return (c1.pt[j]); - } - return (0); - } - + /** + * Returns the third point of circle c1 that is not equal to p1, p2, or p3. + * + * @param c1 the circle to examine + * @param p1 the first point to exclude + * @param p2 the second point to exclude + * @param p3 the third point to exclude + * @return the point number that is different from p1, p2, and p3, or 0 if not found + */ int get_cpt3(ACir c1, int p1, int p2, int p3) { char j; for (j = 0; j <= c1.no; j++) { @@ -1083,6 +1435,13 @@ int get_cpt3(ACir c1, int p1, int p2, int p3) { return (0); } + /** + * Finds the intersection point of two lines if one exists. + * + * @param l1 the first line + * @param l2 the second line + * @return the intersection point number if found, 0 otherwise + */ int inter_ll(LLine l1, LLine l2) { if (l1 == null || l2 == null || l1 == l2) return (0); LLine ln1, ln2; @@ -1105,6 +1464,14 @@ int inter_ll(LLine l1, LLine l2) { return (0); } + /** + * Finds the intersection of two lines that is different from a given point. + * + * @param l1 the first line + * @param l2 the second line + * @param p1 the point to exclude from the intersection result + * @return the intersection point number if found and not equal to p1, 0 otherwise + */ int inter_ll1(LLine l1, LLine l2, int p1) { char i, j; if (l1 == l2) return (0); @@ -1117,6 +1484,13 @@ int inter_ll1(LLine l1, LLine l2, int p1) { return (0); } + /** + * Finds the intersection point between a line and a circle. + * + * @param l1 the line to check for intersection + * @param c1 the circle to check for intersection + * @return the intersection point number if found, 0 otherwise + */ int inter_lc(LLine l1, ACir c1) { char i, j; if (l1 == null || c1 == null) return (0); @@ -1127,6 +1501,14 @@ int inter_lc(LLine l1, ACir c1) { return (0); } + /** + * Returns the intersection point between a line and a circle, excluding a given point. + * + * @param l1 the line to check + * @param c1 the circle to check + * @param p1 the point to exclude + * @return the intersection point or 0 if none + */ int inter_lc1(LLine l1, ACir c1, int p1) { if (l1 == null || c1 == null) return (0); @@ -1137,6 +1519,13 @@ int inter_lc1(LLine l1, ACir c1, int p1) { return (0); } + /** + * Returns the intersection point between two circles. + * + * @param c1 the first circle + * @param c2 the second circle + * @return the intersection point or 0 if none + */ int inter_cc(ACir c1, ACir c2) { char i, j; for (i = 0; i <= c1.no; i++) @@ -1146,6 +1535,14 @@ int inter_cc(ACir c1, ACir c2) { return (0); } + /** + * Returns the intersection point between two circles, excluding a given point. + * + * @param c1 the first circle + * @param c2 the second circle + * @param p1 the point to exclude + * @return the intersection point or 0 if none + */ int inter_cc1(ACir c1, ACir c2, int p1) { char i, j; for (i = 0; i <= c1.no; i++) @@ -1155,28 +1552,13 @@ int inter_cc1(ACir c1, ACir c2, int p1) { return (0); } - int fd_pt_la(int o, int p1, int p2) { - int i, p3; - LLine ln; - ln = fd_ln(p1, p2); - if (ln == null || ln.no <= 1) return (0); - for (i = 0; i <= ln.no; i++) { - p3 = ln.pt[i]; - if (!meq_pt(p3, p1) && !meq_pt(p3, p2) && xacong(p1, o, p3, p3, o, p2)) return (p3); - } - return (0); - } - - int common_pp(PLine pl1, PLine pl2) { - char i, j; - for (i = 0; i <= pl1.no; i++) - for (j = 0; j <= pl2.no; j++) { - if (pl1.ln[i] == pl2.ln[j]) return (1); - } - return (0); - } - - + /** + * Finds the midpoint index for the segment defined by two points. + * + * @param a the first point + * @param b the second point + * @return the midpoint index or 0 if not found + */ int fd_pt_md(int a, int b) { MidPt md = all_md.nx; while (md != null) { @@ -1186,26 +1568,14 @@ int fd_pt_md(int a, int b) { return (0); } - int fd_pt_ref(int a, int o) { - MidPt md = all_md.nx; - while (md != null) { - if (md.m == o && a == md.a) return (md.b); - if (md.m == o && a == md.b) return (md.a); - md = md.nx; - } - return (0); - } - - - MidPt fd_md_ml(int m, LLine l) { - MidPt md = all_md.nx; - while (md != null) { - if (md.m == m && on_ln(md.a, l)) return (md); - md = md.nx; - } - return (null); - } - + /** + * Adds a midpoint for the segment between two points if valid. + * + * @param lm the midpoint lemma or marker + * @param pt the new midpoint + * @param p1 the first endpoint + * @param p2 the second endpoint + */ final void add_mid(int lm, int pt, int p1, int p2) { MidPt md; if (p1 == p2 || !check_mid(pt, p1, p2)) { @@ -1229,6 +1599,13 @@ final void add_mid(int lm, int pt, int p1, int p2) { } } + /** + * Checks if a point is on the given line. + * + * @param p the point to check + * @param ln the line to inspect + * @return true if the point exists on the line; false otherwise + */ boolean on_ln(int p, LLine ln) { int i; if (ln == null) return (false); @@ -1236,6 +1613,13 @@ boolean on_ln(int p, LLine ln) { return (false); } + /** + * Determines if all points of one line are contained within another line. + * + * @param l1 the line to check if it is a subline + * @param l2 the line to be checked against + * @return true if l1 is a subline of l2; false otherwise + */ boolean sub_ln(LLine l1, LLine l2) { int i; if (l1 == null) { @@ -1247,6 +1631,12 @@ boolean sub_ln(LLine l1, LLine l2) { return (true); } + /** + * Adds a point to the line in sorted order. + * + * @param p the point to add + * @param ln the line to which the point is added + */ final void add_pt2l(int p, LLine ln) { int j, i = 0; while (i <= ln.no && ln.pt[i] < p) i++; @@ -1263,6 +1653,13 @@ final void add_pt2l(int p, LLine ln) { } } + /** + * Finds a finite line that contains the two specified points. + * + * @param p1 the first point + * @param p2 the second point + * @return the line containing both points or null if not found + */ LLine fd_ln(int p1, int p2) { LLine ln = all_ln.nx; while (ln != null && !(ln.type != 0 && on_ln(p1, ln) && on_ln(p2, ln))) { @@ -1271,6 +1668,14 @@ LLine fd_ln(int p1, int p2) { return (ln); } + /** + * Finds a finite line that contains the three specified points. + * + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @return the line containing the three points or null if not found + */ LLine fd_ln3(int p1, int p2, int p3) { LLine ln = all_ln.nx; while (ln != null) { @@ -1283,6 +1688,14 @@ LLine fd_ln3(int p1, int p2, int p3) { return (null); } + /** + * Retrieves a line from a parallel structure that contains the specified point. + * + * @param p1 the point to check + * @param p2 the first reference point for the parallel line search + * @param p3 the second reference point for the parallel line search + * @return the line that contains the point or null if not found + */ LLine fd_pline(int p1, int p2, int p3) { int i; PLine pn; @@ -1293,6 +1706,14 @@ LLine fd_pline(int p1, int p2, int p3) { return (null); } + /** + * Retrieves a transversal line associated with the given points. + * + * @param p1 the point to check + * @param p2 the first reference point for the transversal search + * @param p3 the second reference point for the transversal search + * @return the transversal line containing the point or null if not found + */ LLine fd_tline(int p1, int p2, int p3) { LLine ln; TLine tn; @@ -1310,6 +1731,13 @@ LLine fd_tline(int p1, int p2, int p3) { return (null); } + /** + * Searches for a line within a parallel structure that contains the given point. + * + * @param pn the parallel line structure + * @param p the point to check + * @return the line containing the point or null if not found + */ LLine fd_ln_pn1(PLine pn, int p) { int i; if (pn == null) return (null); @@ -1317,15 +1745,12 @@ LLine fd_ln_pn1(PLine pn, int p) { return (null); } - LLine fd_ln1(int p1) { - LLine ln = all_ln.nx; - while (ln != null) { - if (on_ln(p1, ln) && ln.type != 0 && ln.no > 1) return (ln); - ln = ln.nx; - } - return (null); - } - + /** + * Finds a finite line associated with the given line by checking for shared intersection points. + * + * @param l1 the reference line + * @return the associated finite line or null if not found + */ LLine fd_lnl(LLine l1) { LLine ln = all_ln.nx; int p1, p2; @@ -1340,6 +1765,13 @@ LLine fd_lnl(LLine l1) { return (null); } + /** + * Retrieves or constructs a refined line related to the given line based on an exclusion point. + * + * @param l1 the original line + * @param p the exclusion point for refining the line + * @return the refined line or the original line if no refinement is needed + */ LLine fd_ln_rl(LLine l1, int p) { if (l1.type != 0) return l1; @@ -1370,7 +1802,13 @@ LLine fd_ln_rl(LLine l1, int p) { } - + /** + * Creates a new line with the two specified points. + * + * @param p1 the first point + * @param p2 the second point + * @return the newly created line or null if the points are identical + */ LLine add_ln(int p1, int p2) { if (p1 == p2) { @@ -1395,6 +1833,13 @@ LLine add_ln(int p1, int p2) { return (ln); } + /** + * Combines two lines to create a new line that contains points from both. + * + * @param l1 the first line + * @param l2 the second line + * @return the new combined line or null if the combined line is a subline of an existing line + */ LLine add_ln2l(LLine l1, LLine l2) { test_ln.cp_ln(l1); LLine ln = test_ln; @@ -1413,6 +1858,13 @@ LLine add_ln2l(LLine l1, LLine l2) { return ln; } + /** + * Finds an existing line containing the two points or creates a new one if not found. + * + * @param p1 the first point + * @param p2 the second point + * @return the found or newly created line + */ LLine fadd_ln(int p1, int p2) { LLine ln; ln = fd_ln(p1, p2); @@ -1420,7 +1872,13 @@ LLine fadd_ln(int p1, int p2) { return (add_ln(p1, p2)); } - + /** + * Creates a copy of the given line by duplicating its point data. + * The new copy is linked as the last line. + * + * @param ln the line to copy + * @return a new line object that is a copy of ln + */ LLine cp_ln(LLine ln) { LLine ln1; ln1 = new LLine(); @@ -1433,6 +1891,13 @@ LLine cp_ln(LLine ln) { return (ln1); } + /** + * Replaces occurrences of ln1 with ln2 in parallel, perpendicular, and angle relations. + * Updates related structures accordingly. + * + * @param ln1 the original line to be replaced + * @param ln2 the new line to substitute for ln1 + */ final void ch_ln(LLine ln1, LLine ln2) { LLine l1, l2, l3, l4; @@ -1558,6 +2023,15 @@ final void ch_ln(LLine ln1, LLine ln2) { } } + /** + * Adds a line based on three given point identifiers. + * Validates collinearity and either creates a new line or updates an existing one. + * + * @param lm the lemma identifier used for processing + * @param p1 identifier for the first point + * @param p2 identifier for the second point + * @param p3 identifier for the third point + */ final void add_line(int lm, int p1, int p2, int p3) { LLine ln1; if (xcoll(p1, p2, p3)) return; @@ -1586,6 +2060,15 @@ final void add_line(int lm, int p1, int p2, int p3) { ch_lns(ln1); } + /** + * Adds a line for hypothesis purposes, defined by three point identifiers. + * If the line exists, it updates the structure; otherwise, it creates a new one. + * + * @param lm the lemma identifier used for processing + * @param p1 identifier for the first point + * @param p2 identifier for the second point + * @param p3 identifier for the third point + */ final void add_line1(int lm, int p1, int p2, int p3) { // for hypothesis only. if (!check_coll(p1, p2, p3)) { add_checkError(); @@ -1600,6 +2083,12 @@ final void add_line1(int lm, int p1, int p2, int p3) { // for hypothesis on add_line(lm, p1, p2, p3); } + /** + * Processes and adjusts collections of lines. + * Iterates through sub-line relationships to update and merge lines as needed. + * + * @param ln1 the initial line to process and potentially replace with merged data + */ public void ch_lns(LLine ln1) { LLine ln2, ln3, ln4; ln2 = ln1; @@ -1641,12 +2130,25 @@ public void ch_lns(LLine ln1) { last_nd.u.ln = ln2; } + /** + * Checks if the given line is contained within the specified parallel line container. + * + * @param ln the line to check for membership + * @param pn the parallel line container to search + * @return true if ln is part of pn; otherwise, false + */ boolean on_pn(LLine ln, PLine pn) { int i; for (i = 0; i <= pn.no; i++) if (pn.ln[i] == ln) return (true); return (false); } + /** + * Finds the parallel line container associated with the specified line. + * + * @param ln the line for which to locate its parallel container + * @return the parallel line container if found; otherwise, null + */ PLine fd_pnl(LLine ln) { PLine pn; pn = all_pn.nx; @@ -1656,6 +2158,13 @@ PLine fd_pnl(LLine ln) { return (pn); } + /** + * Searches within the parallel line container for a line that contains the specified point. + * + * @param p the point identifier to look for + * @param ln the parallel line container in which to search + * @return the line containing the point if found; otherwise, null + */ LLine fd_lpp2(int p, LLine ln) { PLine pn; pn = all_pn.nx; @@ -1669,12 +2178,26 @@ LLine fd_lpp2(int p, LLine ln) { return (null); } + /** + * Retrieves the parallel line container corresponding to the line defined by two points. + * + * @param p1 identifier for the first point + * @param p2 identifier for the second point + * @return the associated parallel line container if it exists; otherwise, null + */ PLine fd_pn(int p1, int p2) { LLine ln = fd_ln(p1, p2); if (ln == null) return (null); return (fd_pnl(ln)); } + /** + * Finds an alternative parallel line container (different from the given one) that includes the specified line. + * + * @param pn the current parallel line container + * @param ln the line to search for in other containers + * @return another parallel line container if found; otherwise, null + */ PLine fd_pnp(PLine pn, LLine ln) { PLine pn1; pn1 = all_pn.nx; @@ -1684,6 +2207,13 @@ PLine fd_pnp(PLine pn, LLine ln) { return (null); } + /** + * Creates a copy of the given parallel line container. + * Duplicates its type, line array, and other associated properties. + * + * @param pn the parallel line container to copy + * @return a new parallel line container that is a copy of pn + */ PLine cp_pn(PLine pn) { PLine pn1; char i; @@ -1700,6 +2230,12 @@ PLine cp_pn(PLine pn) { return (pn1); } + /** + * Merges two parallel line containers by uniting the lines from pn2 into pn1. + * + * @param pn1 the primary parallel line container to update + * @param pn2 the source container whose lines will be merged into pn1 + */ final void pn_un(PLine pn1, PLine pn2) { for (int i = 0; i <= pn2.no; i++) if (!on_pn(pn2.ln[i], pn1)) { @@ -1716,18 +2252,16 @@ final void pn_un(PLine pn1, PLine pn2) { } } - - final PLine fd_pn(LLine ln1, LLine ln2) { - PLine pn1 = all_pn.nx; - while (pn1 != null) - if (pn1.type != 0 && on_pn(ln1, pn1) && on_pn(ln2, pn1)) - return (pn1); - else - pn1 = pn1.nx; - return null; - } - - + /** + * Adds a parallel line structure using four point identifiers. + * Validates the input and creates a new parallel line container to represent the relation. + * + * @param lm the lemma identifier used for processing + * @param p1 identifier for the first point of the first line + * @param p2 identifier for the second point of the first line + * @param p3 identifier for the first point of the second line + * @param p4 identifier for the second point of the second line + */ final void add_pline(int lm, int p1, int p2, int p3, int p4) { if (!valid(lm)) return; @@ -1766,7 +2300,15 @@ final void add_pline(int lm, int p1, int p2, int p3, int p4) { //adj_pn(pn); } - + /** + * Adds a parallel connection between two lines. + * Creates a new parallel line container if the given lines are not already parallel. + * + * @param lm the lemma identifier used for processing + * @param ln1 the first line in the connection + * @param ln2 the second line in the connection + * @return the newly created parallel line container if the connection is established; otherwise, null + */ PLine add_px(int lm, LLine ln1, LLine ln2) { if (!valid(lm)) return null; @@ -1789,12 +2331,24 @@ PLine add_px(int lm, LLine ln1, LLine ln2) { return (pn); } - + /** + * Checks if the given LLine is one of the defining lines of the specified TLine. + * + * @param ln the line to check + * @param tn the TLine whose defining lines are examined + * @return true if ln equals tn.l1 or tn.l2, false otherwise + */ boolean on_tn(LLine ln, TLine tn) { if ((ln == tn.l1) || (ln == tn.l2)) return (true); return (false); } + /** + * Finds and returns the first non-zero type TLine that uses the given LLine. + * + * @param ln the LLine to search for in TLines + * @return the found TLine, or null if none exists + */ TLine fd_tn(LLine ln) { TLine tn; tn = all_tn.nx; @@ -1808,6 +2362,13 @@ TLine fd_tn(LLine ln) { return (tn); } + /** + * Creates a new TLine from two given LLines. + * + * @param ln1 the first LLine component + * @param ln2 the second LLine component + * @return the newly created TLine + */ TLine add_tn(LLine ln1, LLine ln2) { TLine tn = new TLine(); tn.l1 = ln1; @@ -1820,6 +2381,14 @@ TLine add_tn(LLine ln1, LLine ln2) { return (tn); } + /** + * Adds a TLine based on two LLines if they are valid and not perpendicular. + * + * @param lm the lemma (identifier) associated with the TLine + * @param l1 the first LLine component + * @param l2 the second LLine component + * @return the added TLine, or null if invalid conditions are met + */ final TLine add_tline(int lm, LLine l1, LLine l2) { if (!valid(lm)) return null; @@ -1837,6 +2406,15 @@ final TLine add_tline(int lm, LLine l1, LLine l2) { return tn1; } + /** + * Adds a TLine using point indices by converting them to LLines. + * + * @param lm the lemma (identifier) for the TLine + * @param p1 the first point of the first LLine + * @param p2 the second point of the first LLine + * @param p3 the first point of the second LLine + * @param p4 the second point of the second LLine + */ final void add_tline(int lm, int p1, int p2, int p3, int p4) { if (!valid(lm)) return; @@ -1860,6 +2438,14 @@ final void add_tline(int lm, int p1, int p2, int p3, int p4) { last_nd.u.tn = tn1; } + /** + * Adds a TLine from two LLines with a different coordinate source. + * + * @param lm the lemma (identifier) for the TLine + * @param l1 the first LLine component + * @param l2 the second LLine component + * @return the newly added TLine, or null if preconditions fail + */ final TLine add_tx(int lm, LLine l1, LLine l2) { if (!valid(lm)) return null; @@ -1877,7 +2463,15 @@ final TLine add_tx(int lm, LLine l1, LLine l2) { return tn1; } - + /** + * Adds a TLine in test mode using input point indices. + * + * @param lm the lemma (identifier) for the TLine + * @param p1 the first point of the first LLine + * @param p2 the second point of the first LLine + * @param p3 the first point of the second LLine + * @param p4 the second point of the second LLine + */ public void add_tline_t(int lm, int p1, int p2, int p3, int p4) { if (!valid(lm)) return; @@ -1904,7 +2498,13 @@ public void add_tline_t(int lm, int p1, int p2, int p3, int p4) { last_nd.u.tn = tn1; } - + /** + * Checks if a given point is contained in the specified circle. + * + * @param a the point to check; zero is always considered valid + * @param cr the circle in which to check for the point + * @return true if the point is found in the circle, or if a is zero; false otherwise + */ boolean on_cir(int a, ACir cr) { char i; if (a == 0) return (true); @@ -1912,13 +2512,13 @@ boolean on_cir(int a, ACir cr) { return (false); } - int eq_cir(int o, int a, ACir cr) { - char i; - if (cr.o != o) return (0); - for (i = 0; i <= cr.no; i++) if (cr.pt[i] == a) return (1); - return (0); - } - + /** + * Determines whether all points of the first circle are contained in the second circle. + * + * @param c1 the circle whose points are to be checked + * @param c2 the circle to check against + * @return true if c1 is a subset of c2, false otherwise + */ boolean sub_cir(ACir c1, ACir c2) { char i; if (c1.o == c2.o || c1.o == 0) { @@ -1930,32 +2530,14 @@ boolean sub_cir(ACir c1, ACir c2) { return (false); } - boolean circle_p(int ptn) { - char i; - ACir c1 = all_cir.nx; - if (ptn < 3) return (false); - - if (ptn == 3 && ATYPE(3) == C_POINT && ATYPE(2) == C_POINT - && ATYPE(1) == C_POINT) - return (false); - for (i = 1; i <= ptn; i++) - if (!(ATYPE(i) == C_POINT || ATYPE(i) == C_O_C || ATYPE(i) == C_CIRCLE || ATYPE(i) == C_CIRCUM)) - return (false); - - while (c1 != null) { - for (i = 1; i <= ptn; i++) - if (i != c1.o && !(on_cir(i, c1))) { - break; - } else - return true; - l1: - c1 = c1.nx; - } - - Cm.print("function : circle_p. careful! "); - return (false); - } - + /** + * Searches for a circle that contains all three specified points. + * + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @return the identifier of the found circle if all points belong to it; otherwise, zero + */ int fd_co(int p1, int p2, int p3) { ACir c2; c2 = all_cir.nx; @@ -1966,6 +2548,13 @@ int fd_co(int p1, int p2, int p3) { return (0); } + /** + * Finds a circle with the specified center identifier that contains a given point. + * + * @param o the center identifier to match + * @param p the point to check for within the circle + * @return the found circle, or null if none match + */ ACir fd_cr_op(int o, int p) { ACir c2 = all_cir.nx; while (c2 != null) { @@ -1975,6 +2564,14 @@ ACir fd_cr_op(int o, int p) { return (null); } + /** + * Retrieves a circle that contains three specified points. + * + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @return the found circle containing all three points, or null if none exists + */ ACir fd_cr_p3(int p1, int p2, int p3) { ACir c2 = all_cir.nx; while (c2 != null) { @@ -1984,6 +2581,12 @@ ACir fd_cr_p3(int p1, int p2, int p3) { return (null); } + /** + * Finds and returns a circle that is similar to the given circle by matching common points. + * + * @param c1 the circle to compare + * @return a matching circle based on shared center or common points, or null if none is found + */ ACir fd_cir(ACir c1) { ACir c2; char i, j; @@ -2002,21 +2605,12 @@ ACir fd_cir(ACir c1) { return (null); } - ACir fd_cir(int o, int a) { - if (o == 0 || a == 0) return null; - - ACir cr = all_cir.nx; - while (cr != null) { - if (cr.type != 0 && cr.o == o) { - for (int i = 0; i <= cr.no; i++) - if (cr.pt[i] == a) return cr; - } - cr = cr.nx; - } - return null; - - } - + /** + * Adds a point to the specified circle in sorted order if it does not already exist. + * + * @param p the point to add + * @param cr the circle to which the point will be added + */ final void add_pt2c(int p, ACir cr) { int j, i = 0; if (p <= 0) return; @@ -2036,6 +2630,15 @@ final void add_pt2c(int p, ACir cr) { } } + /** + * Creates and adds a new circle with the given lemma, center, and initial two points. + * + * @param lm the lemma (identifier) associated with the circle + * @param o the center identifier of the circle + * @param a the first point defining the circle's boundary + * @param b the second point defining the circle's boundary + * @return the newly created circle, or null if the lemma is invalid + */ ACir add_c2(int lm, int o, int a, int b) { if (!valid(lm)) return null; @@ -2058,6 +2661,12 @@ ACir add_c2(int lm, int o, int a, int b) { return (cr); } + /** + * Creates a copy of the specified circle with the same properties and points. + * + * @param cir the circle to copy + * @return a new circle object that is a copy of cir + */ ACir cp_cr(ACir cir) { ACir cir1; char i; @@ -2074,40 +2683,14 @@ ACir cp_cr(ACir cir) { return (cir1); } - final void adj_cir(ACir cr) { - ACir cr1, cr2, cr3; - Cond co; - char i; - cr1 = cr; - while ((cr2 = fd_cir(cr1)) != null) { - if (sub_cir(cr2, cr1)) { - cr2.type = 0; - } else if (sub_cir(cr1, cr2)) { - cr1.type = 0; - cr1 = cr2; - } else { - cr3 = cp_cr(cr1); - cr1.type = 0; - cr2.type = 0; - if (cr3.o == 0) cr3.o = cr2.o; - for (i = 0; i <= cr2.no; i++) add_pt2c(cr2.pt[i], cr3); - if (cr1.co == null && cr2.co == null) - cr3.co = null; - else { - co_xy.nx = null; - co = add_coxy(CO_CYCLIC); - co.u.cr = cr1; - co = add_coxy(CO_CYCLIC); - co.u.cr = cr2; - cr3.co = co_xy.nx; - } - cr1 = cr3; - } - } - new_pr(CO_CYCLIC); - last_nd.u.cr = cr1; - } - + /** + * Adds a cyclic circle using the specified lemma, origin and two point identifiers. + * + * @param lm the lemma identifier + * @param o the origin or center point identifier + * @param a the first point identifier on the circle + * @param b the second point identifier on the circle + */ final void add_cir2(int lm, int o, int a, int b) { if (!valid(lm)) return; @@ -2118,6 +2701,15 @@ final void add_cir2(int lm, int o, int a, int b) { last_nd.u.cr = cr; } + /** + * Adds a cyclic circle using the specified lemma, origin, two point identifiers and an additional point. + * + * @param lm the lemma identifier + * @param o the origin or center point identifier + * @param a the first point identifier on the circle + * @param b the second point identifier on the circle + * @param c the additional point identifier to be added to the circle + */ final void add_cir3(int lm, int o, int a, int b, int c) { if (!valid(lm)) return; @@ -2132,6 +2724,16 @@ final void add_cir3(int lm, int o, int a, int b, int c) { last_nd.u.cr = cr; } + /** + * Adds a cyclic circle using the specified lemma, origin, two point identifiers and two additional points. + * + * @param lm the lemma identifier + * @param o the origin or center point identifier + * @param a the first point identifier on the circle + * @param b the second point identifier on the circle + * @param c the first additional point identifier to be added to the circle + * @param d the second additional point identifier to be added to the circle + */ final void add_cir4(int lm, int o, int a, int b, int c, int d) { if (!valid(lm)) return; @@ -2149,26 +2751,31 @@ final void add_cir4(int lm, int o, int a, int b, int c, int d) { last_nd.u.cr = cr; } - + /** + * Checks if the given pair of lines match the sides defined in the specified angles structure. + * + * @param l1 the first line + * @param l2 the second line + * @param as the angles structure to compare against + * @return true if the lines match either the first or second half of the angles structure; false otherwise + */ boolean onl_as(LLine l1, LLine l2, Angles as) { if (l1 == as.l1 && l2 == as.l2) return (true); if (l1 == as.l3 && l2 == as.l4) return (true); return (false); } - Angles fd_as(LLine l1, LLine l2) { - Angles as; - for (as = all_as.nx; as != null; as = as.nx) { - if ( - (l1 == as.l1 && l2 == as.l2) || (l1 == as.l2 && l2 == as.l1) || - (l1 == as.l3 && l2 == as.l4) || (l1 == as.l4 && l2 == as.l3) || - (l1 == as.l1 && l2 == as.l3) || (l1 == as.l3 && l2 == as.l1) || - (l1 == as.l2 && l2 == as.l4) || (l1 == as.l4 && l2 == as.l2)) - return (as); - } - return (null); - } - + /** + * Creates a new angles object from the given lemma and four lines representing two pairs of corresponding sides. + * Performs necessary comparisons and adjustments between the lines. + * + * @param lm the lemma identifier + * @param l1 the first line of the first angle pair + * @param l2 the second line of the first angle pair + * @param l3 the first line of the second angle pair + * @param l4 the second line of the second angle pair + * @return the created angles object, or null if the parameters are invalid + */ Angles add_as0(int lm, LLine l1, LLine l2, LLine l3, LLine l4) { if (!valid(lm)) return null; @@ -2266,50 +2873,16 @@ Angles add_as0(int lm, LLine l1, LLine l2, LLine l3, LLine l4) { return (as); } - final void add_co_as(LLine l1, LLine l2, LLine l3, LLine l4) { - int p1, p2, p3, p4, p5, p6, p7, p8; - int a = inter_ll(l1, l2); - int b = inter_ll(l3, l4); - // a = b = 0; - if (a != 0) { - p2 = a; - p3 = a; - if (l1.pt[0] == a) - p1 = l1.pt[1]; - else - p1 = l1.pt[0]; - - if (l2.pt[0] == a) - p4 = l2.pt[1]; - else - p4 = l2.pt[0]; - } else { - p1 = l1.pt[0]; - p2 = l1.pt[1]; - p3 = l2.pt[0]; - p4 = l2.pt[1]; - } - if (b != 0) { - p6 = b; - p7 = b; - if (l3.pt[0] == b) - p5 = l3.pt[1]; - else - p5 = l3.pt[0]; - - if (l4.pt[0] == b) - p8 = l4.pt[1]; - else - p8 = l4.pt[0]; - } else { - p5 = l3.pt[0]; - p6 = l3.pt[1]; - p7 = l4.pt[0]; - p8 = l4.pt[1]; - } - add_codx(CO_ACONG, p1, p2, p3, p4, p5, p6, p7, p8); - } - + /** + * Checks and adjusts the given angles structure based on the provided four lines. + * Modifies the angles type and associates new conditions if necessary. + * + * @param as the angles structure to check and adjust + * @param l1 the first line of the first angle pair + * @param l2 the second line of the first angle pair + * @param l3 the first line of the second angle pair + * @param l4 the second line of the second angle pair + */ final void ck_as(Angles as, LLine l1, LLine l2, LLine l3, LLine l4) { co_xy.nx = null; if (ln_para(l1, l2) && l3 != l4) { @@ -2338,6 +2911,12 @@ final void ck_as(Angles as, LLine l1, LLine l2, LLine l3, LLine l4) { co_xy.nx = null; } + /** + * Creates and returns a new condition object associated with the given angles structure. + * + * @param as the angles structure for which the condition is created + * @return the newly created condition object + */ final Cond add_acoxy(Angles as) { co_xy.nx = null; Cond c = add_coxy(CO_ACONG); @@ -2345,6 +2924,13 @@ final Cond add_acoxy(Angles as) { return c; } + /** + * Adjusts the specified angles structure based on the provided type flag. + * Iterates over existing angles objects and applies necessary adjustments. + * + * @param t the type flag indicating the adjustment mode + * @param as the angles structure to adjust + */ final void adj_as(int t, Angles as) { if (as == null) return; if (as.type == 0) return; @@ -2378,6 +2964,14 @@ else if (t == 0) { } } + /** + * Adjusts tangency relationships for the specified angles structure by comparing + * the tangency lines associated with its component lines using the given markers. + * + * @param m1 a marker or point identifier used for tangency adjustment + * @param m2 a marker or point identifier used for tangency adjustment + * @param as the angles structure whose tangency relationships are to be adjusted + */ public void adj_as_tn(int m1, int m2, Angles as) { if (m1 == 0 || m2 == 0) return; @@ -2393,6 +2987,13 @@ public void adj_as_tn(int m1, int m2, Angles as) { } + /** + * Searches and adjusts transversal angles based on the provided t-lines. + * + * @param tn1 the first transversal line + * @param tn2 the second transversal line + * @param as the angle set to update + */ public void search_as_tn1(TLine tn1, TLine tn2, Angles as) { if (tn1 == null || tn2 == null) return; @@ -2402,31 +3003,16 @@ public void search_as_tn1(TLine tn1, TLine tn2, Angles as) { adj_as_plus(tn2.l1, tn2.l2, tn1.l2, tn1.l1, as); } - final void adj_bisector(LLine l1, LLine l2, LLine l3, LLine l4, Angles r1, Angles r2) { - LLine ln1, ln2, ln3, ln4, ln5, ln6; - if (l2 == l3) { - ln1 = l1; - ln2 = l2; - ln3 = l4; - } else if (l1 == l4) { - ln1 = l2; - ln2 = l1; - ln3 = l3; - } else - return; - if (r1.l2 == r1.l3) { - ln1 = r1.l1; - ln2 = r1.l2; - ln3 = r1.l4; - } else if (l1 == l4) { - ln1 = r1.l2; - ln2 = r1.l1; - ln3 = r1.l3; - } else - return; - - } - + /** + * Adjusts angles based on the line configuration in the given angle sets. + * + * @param l1 the first line in the configuration + * @param l2 the second line in the configuration + * @param l3 the third line in the configuration + * @param l4 the fourth line in the configuration + * @param r1 the primary angle set + * @param r2 the secondary angle set + */ final void adj_as1(LLine l1, LLine l2, LLine l3, LLine l4, Angles r1, Angles r2) { Cond co; LLine t1, t2; @@ -2477,6 +3063,16 @@ else if (isPFull()) { } } + /** + * Adjusts angles using an alternative line pairing. + * + * @param l1 the first line in the configuration + * @param l2 the second line in the configuration + * @param l3 the third line in the configuration + * @param l4 the fourth line in the configuration + * @param r1 the primary angle set + * @param r2 the secondary angle set + */ final void adj_as2(LLine l1, LLine l2, LLine l3, LLine l4, Angles r1, Angles r2) { Cond co; LLine t1, t2; @@ -2503,6 +3099,15 @@ final void adj_as2(LLine l1, LLine l2, LLine l3, LLine l4, Angles r1, Angles r2) } } + /** + * Attempts to combine line segments and adjust angles based on additional angle information. + * + * @param l1 the first line in the initial pair + * @param l2 the second line in the initial pair + * @param l3 the first line in the alternate pair + * @param l4 the second line in the alternate pair + * @param r1 the reference angle set + */ final void adj_as_plus(LLine l1, LLine l2, LLine l3, LLine l4, Angles r1) { @@ -2599,22 +3204,46 @@ final void adj_as_plus(LLine l1, LLine l2, LLine l3, LLine l4, Angles r1) { } + /** + * Retrieves a line that matches the endpoints of two given line pairs. + * + * @param l1 the first line of the first pair + * @param l2 the second line of the first pair + * @param l3 the first line of the second pair + * @param l4 the second line of the second pair + * @return the matching line if found; otherwise, null + */ public LLine get_82l0(LLine l1, LLine l2, LLine l3, LLine l4) { if (l1 == l4) return l1; if (l2 == l3) return l2; return null; } - public LLine get_82l1(LLine l1, LLine l2, LLine l) { - if (l1 == l) return l2; - if (l2 == l) return l1; - return null; - } - + /** + * Creates an angle point using the intersection of line segments. + * + * @param lm lemma identifier + * @param a first endpoint of the first line + * @param b second endpoint of the first line + * @param c additional parameter for the first line + * @param p first endpoint of the second line + * @param q second endpoint of the second line + * @param r additional parameter for the second line + */ final void add_ea_pt(int lm, int a, int b, int c, int p, int q, int r) { add_ea_ln(lm, fadd_ln(a, b), fadd_ln(b, c), fadd_ln(p, q), fadd_ln(q, r)); } + /** + * Adds an angle by combining four lines if the configuration is valid. + * + * @param lm lemma identifier + * @param l1 the first line of the first pair + * @param l2 the second line of the first pair + * @param l3 the first line of the second pair + * @param l4 the second line of the second pair + * @return the constructed angle set or null if invalid + */ final Angles add_ea_ln(int lm, LLine l1, LLine l2, LLine l3, LLine l4) { if (d_base == 1) return null; @@ -2626,7 +3255,18 @@ final Angles add_ea_ln(int lm, LLine l1, LLine l2, LLine l3, LLine l4) { return as; } - + /** + * Determines if a set of points belongs to the specified similar triangle configuration. + * + * @param p1 first point of the first triangle + * @param p2 second point of the first triangle + * @param p3 third point of the first triangle + * @param p first point of the second triangle + * @param q second point of the second triangle + * @param r third point of the second triangle + * @param st the similar triangle to compare against + * @return true if the points match the triangle configuration; false otherwise + */ boolean on_st(int p1, int p2, int p3, int p, int q, int r, SimTri st) { //?????????????????? for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) @@ -2641,7 +3281,18 @@ boolean on_st(int p1, int p2, int p3, int p, int q, int r, SimTri st) { return (false); } - + /** + * Adds a pair of triangles based on provided vertex configurations. + * + * @param lm lemma identifier + * @param dr direction flag + * @param a first vertex of the first triangle + * @param b second vertex of the first triangle + * @param c third vertex of the first triangle + * @param p first vertex of the second triangle + * @param q second vertex of the second triangle + * @param r third vertex of the second triangle + */ final void add_stri(int lm, int dr, int a, int b, int c, int p, int q, int r) { if (!valid(lm)) return; @@ -2699,7 +3350,14 @@ final void add_stri(int lm, int dr, int a, int b, int c, int p, int q, int r) { return; } - + /** + * Checks if a line defined by two points is part of the provided congruency segment. + * + * @param p1 the first point of the line + * @param p2 the second point of the line + * @param cg the congruency segment to check + * @return true if the line is on the congruency segment; false otherwise + */ final boolean on_cg(int p1, int p2, CongSeg cg) { int i; if (p2 < p1) { @@ -2711,6 +3369,16 @@ final boolean on_cg(int p1, int p2, CongSeg cg) { return (false); } + /** + * Checks if the lines defined by two pairs of points form the provided congruency segment. + * + * @param p1 the first point of the first line + * @param p2 the second point of the first line + * @param p3 the first point of the second line + * @param p4 the second point of the second line + * @param cg the congruency segment to check + * @return true if the points form the congruency segment; false otherwise + */ final boolean on_cg(int p1, int p2, int p3, int p4, CongSeg cg) { int i; if (p2 < p1) { @@ -2728,22 +3396,12 @@ final boolean on_cg(int p1, int p2, int p3, int p4, CongSeg cg) { return (false); } - - final CongSeg fd_cg2(int p1, int p2, CongSeg cg) { - CongSeg cg1 = all_cg.nx; - boolean f = false; - while (cg1 != null) { - if (cg1.type != 0) { - if (cg1 == cg) - f = true; - else if ((f || cg == null) && on_cg(p1, p2, cg1)) return (cg1); - } - cg1 = cg1.nx; - } - return (null); - } - - + /** + * Adjusts congruency segments by comparing the specified congruency with others. + * + * @param c flag indicating which congruency list to traverse + * @param cg the reference congruency segment + */ final void adj_cg(int c, CongSeg cg) { CongSeg cg1 = (c == 1) ? all_cg.nx : all_rg.nx; @@ -2783,7 +3441,23 @@ final void adj_cg(int c, CongSeg cg) { } } - + /** + * Searches for and creates a congruency by comparing endpoints and ratios of two segments. + * + * @param a first endpoint of the first segment + * @param b second endpoint of the first segment + * @param c third endpoint of the first segment + * @param d fourth endpoint of the first segment + * @param a1 first endpoint of the second segment + * @param b1 second endpoint of the second segment + * @param c1 third endpoint of the second segment + * @param d1 fourth endpoint of the second segment + * @param k1 first ratio component of the first segment + * @param k2 second ratio component of the first segment + * @param k3 first ratio component of the second segment + * @param k4 second ratio component of the second segment + * @return true if a valid congruency is found or established; false otherwise + */ final boolean search_cg3(int a, int b, int c, int d, int a1, int b1, int c1, int d1, int k1, int k2, int k3, int k4) { int t1, t2, t3, t4, m1, m2; @@ -2836,13 +3510,18 @@ final boolean search_cg3(int a, int b, int c, int d, int a1, int b1, int c1, int return true; } - final int get_coll43(int a, int b, int c, int d) { - if (a == b || a == c || a == d) return a; - if (b == c || b == d) return b; - if (c == d) return c; - return 0; - } - + /** + * Adds a congruency segment based on two lines and their ratio components. + * + * @param lm lemma identifier + * @param l_no line number flag + * @param a the first point of the first line + * @param b the second point of the first line + * @param p the first point of the second line + * @param q the second point of the second line + * @param t1 first ratio component + * @param t2 second ratio component + */ final void add_cong(int lm, int l_no, int a, int b, int p, int q, int t1, int t2) { CongSeg cg; if (!valid(lm)) return; @@ -2925,6 +3604,16 @@ final void add_cong(int lm, int l_no, int a, int b, int p, int q, int t1, int t2 last_nd.u.cg = cg; } + /** + * Adds a congruency segment for two lines without specifying ratio components. + * + * @param lm lemma identifier + * @param l_no line number flag + * @param a the first point of the first line + * @param b the second point of the first line + * @param p the first point of the second line + * @param q the second point of the second line + */ final void add_cong(int lm, int l_no, int a, int b, int p, int q) { CongSeg cg; if (a == b || p == q) return; @@ -2981,6 +3670,19 @@ final void add_cong(int lm, int l_no, int a, int b, int p, int q) { last_nd.u.cg = cg; } + /** + * Adds a congruence segment based on the provided point indices and lemma. + * + * @param lm the lemma identifier + * @param p1 first point index of the first segment + * @param p2 second point index of the first segment + * @param p3 first point index of the second segment + * @param p4 second point index of the second segment + * @param a first point index of the first congruence pair + * @param b second point index of the first congruence pair + * @param p first point index of the second congruence pair + * @param q second point index of the second congruence pair + */ final void add_cong1(int lm, int p1, int p2, int p3, int p4, int a, int b, int p, int q) { CongSeg cg; Cond co; @@ -3050,6 +3752,15 @@ final void add_cong1(int lm, int p1, int p2, int p3, int p4, int a, int b, int p last_nd.u.cg = cg; } + /** + * Determines the index for a ratio segment based on point congruence. + * + * @param a first point index + * @param b second point index + * @param ra the ratio segment reference + * @param m mode indicator affecting the returned index + * @return an integer representing the determined index + */ int ind_ra(int a, int b, RatioSeg ra, int m) { int c = 0; if (xcong(a, b, ra.r[1], ra.r[2])) { @@ -3064,6 +3775,21 @@ int ind_ra(int a, int b, RatioSeg ra, int m) { return (c); } + /** + * Adds a ratio segment if the ratio parameters pass the validity checks. + * + * @param lm the lemma identifier + * @param o an origin or operator parameter + * @param a first point index of the first ratio pair + * @param b second point index of the first ratio pair + * @param c first point index of the second ratio pair + * @param d second point index of the second ratio pair + * @param p first point index of the third ratio pair + * @param q second point index of the third ratio pair + * @param r first point index of the fourth ratio pair + * @param s second point index of the fourth ratio pair + * @return the created RatioSeg object, or null if the check fails + */ RatioSeg add_ra(int lm, int o, int a, int b, int c, int d, int p, int q, int r, int s) { RatioSeg ra; Cond co; @@ -3124,6 +3850,11 @@ RatioSeg add_ra(int lm, int o, int a, int b, int c, int d, int p, int q, int r, return (ra); } + /** + * Adjusts the ratio segments by comparing with all existing segments and reconciling differences. + * + * @param ra the starting RatioSeg to adjust + */ final void adj_ra(RatioSeg ra) { RatioSeg r1; int i1, i2, i3, i4; @@ -3170,6 +3901,18 @@ final void adj_ra(RatioSeg ra) { test_ra = last_ra; } + /** + * Adjusts a ratio segment relation using the specified ratio parameters and indices. + * + * @param a first point index of the first ratio pair + * @param b second point index of the first ratio pair + * @param c first point index of the second ratio pair + * @param d second point index of the second ratio pair + * @param i1 indicator for the first ratio selection in r1 + * @param i2 indicator for the second ratio selection in r1 + * @param r1 the ratio segment to be adjusted + * @param r2 a related ratio segment used for adjustment context + */ final void adj_ra1(int a, int b, int c, int d, int i1, int i2, RatioSeg r1, RatioSeg r2) { int p, q, r, s; Cond co; @@ -3233,6 +3976,17 @@ final void adj_ra1(int a, int b, int c, int d, int i1, int i2, RatioSeg r1, Rati } } + /** + * Adjusts a ratio segment relation based on a single indicator and updates connection information. + * + * @param a first point index of the first ratio pair + * @param b second point index of the first ratio pair + * @param c first point index of the second ratio pair + * @param d second point index of the second ratio pair + * @param i1 indicator dictating the selection of ratio components in r1 + * @param r1 the ratio segment to be adjusted + * @param r2 a related ratio segment for context + */ final void adj_ra2(int a, int b, int c, int d, int i1, RatioSeg r1, RatioSeg r2) { int p, q, r, s; Cond co; @@ -3265,11 +4019,35 @@ final void adj_ra2(int a, int b, int c, int d, int i1, RatioSeg r1, RatioSeg r2) } } + /** + * Adds a ratio segment if no equivalent ratio exists. + * + * @param lm the lemma identifier + * @param o an origin or operator parameter + * @param a first point index of the first ratio pair + * @param b second point index of the first ratio pair + * @param c first point index of the second ratio pair + * @param d second point index of the second ratio pair + * @param p first point index of the third ratio pair + * @param q second point index of the third ratio pair + * @param r first point index of the fourth ratio pair + * @param s second point index of the fourth ratio pair + */ final void add_ratio(int lm, int o, int a, int b, int c, int d, int p, int q, int r, int s) { if (xeq_ratio(a, b, c, d, p, q, r, s)) return; add_ra(lm, o, a, b, c, d, p, q, r, s); } + /** + * Adds a ratio segment using only four points by inferring the remaining ratio components. + * + * @param lm the lemma identifier + * @param o an origin or operator parameter + * @param a first point index + * @param b second point index + * @param c third point index + * @param d fourth point index + */ final void add_ratioo(int lm, int o, int a, int b, int c, int d) { if (!xeq_ratio(o, a, o, c, o, b, o, d)) add_ra(lm, 1, o, a, o, c, o, b, o, d); @@ -3287,16 +4065,22 @@ final void add_ratioo(int lm, int o, int a, int b, int c, int d) { add_ra(lm, 1, o, c, c, a, o, d, d, b); } + /** + * Checks if two points are equal. + * + * @param p1 the first point index + * @param p2 the second point index + * @return true if points are equal, false otherwise + */ boolean meq_pt(int p1, int p2) { return p1 == p2; } - final void free_dbase() { - init_dbase(); - } - -//////////////////////////////////////////////////////////// - + /** + * Processes and validates all conclusions. + * + * @return true if all conclusions are processed successfully + */ public boolean sbase() { for (int i = 1; i <= cns_no; i++) { if (!isConclusion(i)) @@ -3306,6 +4090,11 @@ public boolean sbase() { return true; } + /** + * Sets the example context for the theorem by initializing various parameters. + * + * @param tm the geometric term containing the example information + */ final public void setExample(GTerm tm) { gt = tm; cons_no = tm.getCons_no(); @@ -3316,7 +4105,11 @@ final public void setExample(GTerm tm) { pts_no = tm.getPointsNum(); } - + /** + * Sets the conclusion condition. + * + * @param tco the condition object containing conclusion data + */ final public void setConc(Cond tco) { if (tco == null) return; @@ -3342,24 +4135,25 @@ final public void setConc(Cond tco) { } } - - public void add_nln(int[] p, int n) { - for (int i = 0; i < n; i++) - fadd_ln(p[i * 2], p[i * 2 + 1]); - } - - + /** + * Processes the individual conclusion for the specified index. + * + * @param ptn the conclusion index + * @return true after processing the conclusion + */ public boolean do_i_cons(int ptn) { do_pd(ptn, allcns[ptn].type, allcns[ptn].ps); return true; } - public boolean do_i_ln(int ptn) { - do_pdln(ptn, allcns[ptn].type, allcns[ptn].ps); - return true; - } - - + /** + * Processes the predicate for a given conclusion based on its type and parameters. + * + * @param ptn the conclusion index + * @param t the type of predicate + * @param p an array of parameters associated with the predicate + * @return true if the predicate is processed successfully; false otherwise + */ public boolean do_pd(int ptn, int t, int[] p) { if (t == 0) return true; switch (t) { @@ -3575,7 +4369,11 @@ public boolean do_pd(int ptn, int t, int[] p) { } - + /** + * Adds a circle defined by the provided parameters. + * + * @param p an array containing circle parameters; p[2] must be non-zero + */ public void add_cir_n(int p[]) { if (p[2] == 0) return; @@ -3592,122 +4390,42 @@ public void add_cir_n(int p[]) { } } + /** + * Adds a line angle ratio by drawing lines between the provided endpoints and establishing + * squared ratio relationships. + * + * @param p1 the first point index + * @param p2 the second point index + * @param p3 the third point index + * @param p4 the fourth point index + * @param t1 the first ratio value (to be squared) + * @param t2 the second ratio value (to be squared) + */ public void add_laratio(int p1, int p2, int p3, int p4, int t1, int t2) { add_line1(0, p1, p2, p3); add_line1(0, p1, p2, p4); add_cong(0, 0, p1, p2, p3, p4, t1 * t1, t2 * t2); } + /** + * Adds a congruence relation between segments based on the provided endpoints and squared ratio values. + * + * @param p1 the first point index of the first segment + * @param p2 the second point index of the first segment + * @param p3 the first point index of the second segment + * @param p4 the second point index of the second segment + * @param t1 the first ratio value (to be squared) + * @param t2 the second ratio value (to be squared) + */ public void add_ratio(int p1, int p2, int p3, int p4, int t1, int t2) { add_cong(0, 0, p1, p2, p3, p4, t1 * t1, t2 * t2); } - public boolean do_pdln(int ptn, int t, int[] p) { - if (t == 0) return true; - switch (t) { - case C_POINT: - break; - case C_CONSTANT: - break; - case C_MIDPOINT: - break; - case C_FOOT: // foot - fadd_ln(p[0], p[1]); - break; - case C_O_C: - break; - case C_O_L: - fadd_ln(p[1], p[2]); - break; - case C_O_T: - add_nln(p, 2); - break; - case C_O_P: - add_nln(p, 2); - break; - case C_EQANGLE: - case C_O_A: - fadd_ln(p[0], p[1]); - fadd_ln(p[1], p[2]); - fadd_ln(p[3], p[4]); - fadd_ln(p[4], p[5]); - break; - case C_O_R: - break; - case C_O_B: - break; - case C_NSQUARE: - break; - case C_PSQUARE: - break; - case C_I_CC: - break; - case C_CIRCUM: - break; - case C_ORTH: - fadd_ln(p[0], p[1]); - fadd_ln(p[0], p[2]); - fadd_ln(p[0], p[3]); - fadd_ln(p[1], p[2]); - fadd_ln(p[1], p[3]); - fadd_ln(p[2], p[3]); - break; - case C_PETRIANGLE: - fadd_ln(p[0], p[1]); - fadd_ln(p[1], p[2]); - fadd_ln(p[2], p[3]); - break; - case C_NETRIANGLE: - break; - case C_REF: //Point wrpt POINT - fadd_ln(p[1], p[2]); - break; - case C_SYM: // Point wrpt LINE - add_nln(p, 2); - break; - case C_ICENT: - break; - case C_PRATIO: - add_nln(p, 2); - break; - case C_TRATIO: - add_nln(p, 2); - break; - case C_EQDISTANCE: - add_nln(p, 2); - break; - case C_SANGLE: - fadd_ln(p[0], p[1]); - fadd_ln(p[1], p[2]); - break; - case C_LRATIO: - break; - case C_NRATIO: - break; - case C_LINE: - fadd_ln(p[0], p[1]); - break; - case C_TRIANGLE: - case C_ISO_TRI: - case C_R_TRI: - case C_EQ_TRI: - case C_QUADRANGLE: - case C_PENTAGON: - case C_POLYGON: - case C_TRAPEZOID: - case C_R_TRAPEZOID: - case C_PARALLELOGRAM: - case C_LOZENGE: - case C_RECTANGLE: - case C_SQUARE: - add_pg_ln(p); - break; - default: - return false; - } - return true; - } - + /** + * Adds a polygon line by connecting the series of points in a loop. + * + * @param p an array of point indices representing the polygon vertices; a zero value indicates termination + */ public void add_pg_ln(int[] p) { int t = p[0]; if (t == 0) return; @@ -3719,13 +4437,22 @@ public void add_pg_ln(int[] p) { fadd_ln(p[0], t); } - + /** + * Adds a trapezoid by drawing the primary lines for its shape. + * + * @param p an array of 4 vertex indices representing the trapezoid + */ public void add_r_trapezoid(int[] p) { add_pline(0, p[0], p[1], p[2], p[3]); add_tline(0, p[0], p[1], p[0], p[3]); add_tline(0, p[0], p[3], p[2], p[3]); } + /** + * Adds a parallelogram by drawing its outline, congruencies, and structural elements. + * + * @param p an array of 4 vertex indices representing the parallelogram + */ public void add_parallelogram(int[] p) { add_pline(0, p[0], p[1], p[2], p[3]); add_pline(0, p[0], p[3], p[1], p[2]); @@ -3736,6 +4463,11 @@ public void add_parallelogram(int[] p) { add_stri(0, 1, p[0], p[1], p[3], p[2], p[3], p[1]); } + /** + * Adds a lozenge by drawing its lines and congruencies. + * + * @param p an array of 4 vertex indices representing the lozenge + */ public void add_lozenge(int[] p) { add_pline(0, p[0], p[1], p[2], p[3]); add_pline(0, p[0], p[3], p[1], p[2]); @@ -3749,6 +4481,11 @@ public void add_lozenge(int[] p) { add_stri(0, 1, p[0], p[1], p[3], p[2], p[3], p[1]); } + /** + * Adds a rectangle by drawing its outline, tangents, congruencies, and structural elements. + * + * @param p an array of 4 vertex indices representing the rectangle + */ public void add_rectangle(int[] p) { add_pline(0, p[0], p[1], p[2], p[3]); add_pline(0, p[0], p[3], p[2], p[1]); @@ -3763,6 +4500,11 @@ public void add_rectangle(int[] p) { add_stri(0, 1, p[0], p[1], p[3], p[2], p[3], p[1]); } + /** + * Adds a square by drawing its lines, tangents, congruencies, and angle structures. + * + * @param p an array of 4 vertex indices representing the square + */ public void add_square(int[] p) { add_pline(0, p[0], p[1], p[2], p[3]); add_pline(0, p[0], p[3], p[2], p[1]); @@ -3807,6 +4549,12 @@ public void add_square(int[] p) { } + /** + * Adds an auxiliary point based on the provided ProPoint type. + * + * @param pt the ProPoint object containing point and type information + * @return true if the auxiliary point is added successfully; false otherwise + */ public boolean add_auxpt(ProPoint pt) { int[] p = pt.ps; @@ -3849,6 +4597,14 @@ public boolean add_auxpt(ProPoint pt) { return true; } + /** + * Performs a predicate operation based on the given type. + * + * @param p1 the array of points and parameters (first element is used as predicate target) + * @param mk the predicate type code + * @param ptn the predicate target (overwritten by the first element of p1) + * @return true if the predicate action is executed successfully, false otherwise + */ public boolean do_pred2(int[] p1, int mk, int ptn) { ptn = p1[0]; int[] p = new int[p1.length]; @@ -4021,60 +4777,12 @@ public boolean do_pred2(int[] p1, int mk, int ptn) { return true; } - final public void add_square(ProPoint p) { - - - int i = 0; - for (; allpts[i + 1] != p; i++) ; - ProPoint p1 = allpts[i]; - - if (!(p1.ps[1] == p.ps[1] && p1.ps[2] == p.ps[2] || p1.ps[1] == p.ps[2] && p1.ps[2] == p.ps[1])) return; - - { - int a = p1.ps[0]; - int b = p1.ps[1]; - int c = p1.ps[2]; - int d = p.ps[0]; - add_at(0, a, b, c, A_90); - add_at(0, b, c, d, A_90); - add_at(0, c, d, a, A_90); - add_at(0, d, a, b, A_90); - add_at(0, a, b, d, A_45); - add_at(0, a, d, b, A_45); - add_at(0, a, c, d, A_45); - add_at(0, a, c, b, A_45); - add_at(0, c, b, d, A_45); - add_at(0, c, d, b, A_45); - add_at(0, c, a, b, A_45); - add_at(0, c, a, d, A_45); - } - - - if (p.type == C_PSQUARE && p1.type == C_NSQUARE || p.type == C_NSQUARE && p1.type == C_PSQUARE) { - if (p1.ps[1] == p.ps[2] && p1.ps[2] == p.ps[1]) { - int a = p1.ps[0]; - int b = p1.ps[1]; - int c = p1.ps[2]; - int d = p.ps[0]; - add_pline(0, a, b, c, d); - add_pline(0, a, d, b, c); - - add_tline(0, a, b, b, c); - add_tline(0, b, c, c, d); - add_tline(0, c, d, d, a); - add_tline(0, a, b, a, d); - - add_cong(0, 0, a, b, b, c); - add_cong(0, 0, a, b, c, d); - add_cong(0, 0, a, b, a, d); - add_cong(0, 0, b, c, c, d); - add_cong(0, 0, b, c, a, d); - add_cong(0, 0, c, d, a, d); - } - } - - } - + /** + * Adds an equilateral triangle using the specified points. + * + * @param ptn the identifier or index used for the triangle + * @param ps an array containing the triangle's vertex points + */ final public void add_e_triangle(int ptn, int[] ps) { int a = ps[0]; int b = ps[1]; @@ -4116,6 +4824,16 @@ final public void add_e_triangle(int ptn, int[] ps) { } } + /** + * Checks whether a triangle with vertices a, b, and c exists in the given STris, + * considering all permutations of the vertices. + * + * @param a first vertex + * @param b second vertex + * @param c third vertex + * @param st the STris instance to search + * @return the index of the matching triangle if found; otherwise, -1 + */ final public int on_sts1(int a, int b, int c, STris st) { int p, q, r; for (int i = 0; i <= st.no; i++) { @@ -4134,6 +4852,15 @@ final public int on_sts1(int a, int b, int c, STris st) { return -1; } + /** + * Checks for the existence of a triangle with vertices a, b, and c, in the given order, within a STris. + * + * @param a first vertex + * @param b second vertex + * @param c third vertex + * @param st the STris instance to search + * @return the index of the triangle if it exists; otherwise, -1 + */ final public int on_sts(int a, int b, int c, STris st) { int p, q, r; for (int i = 0; i <= st.no; i++) { @@ -4147,6 +4874,15 @@ final public int on_sts(int a, int b, int c, STris st) { return -1; } + /** + * Adds a triangle with vertices a, b, and c to the specified STris if it does not already exist. + * + * @param d a multiplier or descriptor value for the triangle + * @param a first vertex + * @param b second vertex + * @param c third vertex + * @param st the STris instance to which the triangle will be added + */ final public void add_to_sts(int d, int a, int b, int c, STris st) { if (on_sts1(a, b, c, st) >= 0) return; @@ -4158,7 +4894,13 @@ final public void add_to_sts(int d, int a, int b, int c, STris st) { st.p3[n] = c; } - + /** + * Merges triangle data from the secondary STris into the primary one, based on a specified index. + * + * @param s the primary STris instance + * @param s1 the secondary STris instance to merge from + * @param t the index within the secondary STris used for merging + */ final public void cb_sts(STris s, STris s1, int t) { s1.type = 0; @@ -4198,6 +4940,12 @@ final public void cb_sts(STris s, STris s1, int t) { } + /** + * Attempts to add a SimTri to an existing STris structure. + * + * @param t the SimTri object representing the triangle to be added + * @return true if the list was updated successfully, false otherwise + */ final public boolean add_sts1(SimTri t) { STris st = null; @@ -4264,6 +5012,11 @@ final public boolean add_sts1(SimTri t) { return true; } + /** + * Adds a SimTri object to the appropriate STris structure or creates a new STris if necessary. + * + * @param st the SimTri object representing the triangle to add + */ final public void add_sts(SimTri st) { if (add_sts1(st)) return; @@ -4292,6 +5045,9 @@ final public void add_sts(SimTri st) { return; } + /** + * Collects and organizes triangles from all SimTri objects into STris structures. + */ public void collect_sts() { SimTri st = all_st.nx; tri_type = 0; @@ -4310,13 +5066,25 @@ public void collect_sts() { } } - /////////////////////////////////////////////////////////////////////// + /** + * Adds a connection between two points into the specified CSegs. + * + * @param p1 the first point + * @param p2 the second point + * @param cg the CSegs instance where the connection is added + */ public void add_to_cg(int p1, int p2, CSegs cg) { cg.no++; cg.p1[cg.no] = p1; cg.p2[cg.no] = p2; } + /** + * Merges connections from one CSegs instance into another. + * + * @param cg the primary CSegs instance + * @param cg1 the secondary CSegs instance to merge from + */ public void cb_cgs(CSegs cg, CSegs cg1) { cg1.type = 0; for (int i = 0; i <= cg1.no; i++) { @@ -4325,12 +5093,28 @@ public void cb_cgs(CSegs cg, CSegs cg1) { } } + /** + * Checks whether a connection between two points exists within the given CSegs. + * + * @param p1 the first point + * @param p2 the second point + * @param cgs the CSegs instance to check + * @return true if the connection exists, false otherwise + */ public boolean on_cgs(int p1, int p2, CSegs cgs) { for (int i = 0; i <= cgs.no; i++) if (p1 == cgs.p1[i] & p2 == cgs.p2[i]) return true; return false; } + /** + * Adds a connection between two pairs of points, merging with existing connections if applicable. + * + * @param p1 the first point of the first pair + * @param p2 the second point of the first pair + * @param p3 the first point of the second pair + * @param p4 the second point of the second pair + */ public void add_cgs(int p1, int p2, int p3, int p4) { CSegs cg = all_cgs.nx; boolean t1, t2; @@ -4385,8 +5169,15 @@ else if (p3 == cg.p1[i] && p4 == cg.p2[i]) } - - ///////////////////////////////////// + /** + * Finds a PLine object that contains both line segments defined by the given points. + * + * @param p the first point of the first line segment + * @param q the second point of the first line segment + * @param r the first point of the second line segment + * @param s the second point of the second line segment + * @return the matching PLine if found; otherwise, null + */ final PLine fo_pn1(int p, int q, int r, int s) { PLine pn = all_pn.nx; boolean r1, r2; @@ -4404,6 +5195,17 @@ final PLine fo_pn1(int p, int q, int r, int s) { } + /** + * Finds a TLine object that matches the given line segments. + * + * If any parameter is zero, this method returns null. + * + * @param p1 the first point of the first line segment + * @param p2 the second point of the first line segment + * @param p3 the first point of the second line segment + * @param p4 the second point of the second line segment + * @return the matching TLine if found; otherwise, null + */ final TLine fo_tn1(int p1, int p2, int p3, int p4) { if (p1 == 0 || p2 == 0 || p3 == 0 || p4 == 0) return null; @@ -4417,6 +5219,22 @@ final TLine fo_tn1(int p1, int p2, int p3, int p4) { return tn; } + /** + * Finds an Angles object matching the given configuration of lines. + * + * This method checks various combinations of lines in the Angles object using on_ln. + * Additional checks are applied when isPFull() returns true. + * + * @param a the first point for the first line + * @param b the second point for the first line + * @param c the first point for the second line + * @param d the second point for the second line + * @param p the first point for the third line + * @param q the second point for the third line + * @param r the first point for the fourth line + * @param s the second point for the fourth line + * @return the matching Angles object if found; otherwise, null + */ final Angles fo_as1(int a, int b, int c, int d, int p, int q, int r, int s) { Angles as = all_as.nx; while (as != null) { @@ -4436,6 +5254,16 @@ final Angles fo_as1(int a, int b, int c, int d, int p, int q, int r, int s) { return null; } + /** + * Determines whether the given LLine contains exactly the two specified points. + * + * This method counts the occurrences of the points in the LLine. + * + * @param p the first point + * @param q the second point + * @param ln the LLine to check + * @return true if the line contains both points exactly; otherwise, false + */ boolean on_ln(int p, int q, LLine ln) { int i, n; @@ -4447,23 +5275,15 @@ boolean on_ln(int p, int q, LLine ln) { return (n == 2); } - LLine fd_ln1(int p1, int p2, LLine lnx) { - LLine ln = all_ln.nx; - - while (ln != null) { - if (lnx != null && ln != lnx) - ln = ln.nx; - else if (lnx != null && ln == lnx) { - ln = ln.nx; - lnx = null; - } else if (on_ln(p1, ln) && on_ln(p2, ln)) - break; - else - ln = ln.nx; - } - return (ln); - } - + /** + * Searches for an LLine that is a super-line of the given line and contains the specified additional point. + * + * The method expects the found LLine to match the required point count. + * + * @param ln the base LLine to be contained + * @param p the additional point to be present in the super-line + * @return the matching LLine if found; otherwise, null + */ public LLine fd_ln_lp(LLine ln, int p) { // a line contian ln, and p , no others. int n = 0; if (on_ln(p, ln)) @@ -4479,6 +5299,20 @@ public LLine fd_ln_lp(LLine ln, int p) { // a line contian ln, and p , no other return null; } + /** + * Checks whether a circle defined by the given set of points exists. + * + * This method initializes test parameters using the provided points and verifies the existence + * of a corresponding circle. + * + * @param o a parameter for the circle (e.g. origin) + * @param a the first point + * @param b the second point + * @param c the third point + * @param d the fourth point + * @param e the fifth point + * @return true if the circle exists; otherwise, false + */ final public boolean xcir_n(int o, int a, int b, int c, int d, int e) { test_c.no = -1; test_c.o = o; @@ -4493,6 +5327,14 @@ final public boolean xcir_n(int o, int a, int b, int c, int d, int e) { return false; } + /** + * Adjusts the specified ACir object based on sub-circle or overlapping conditions. + * + * This method iterates through related circles and updates their types and associated properties + * when sub-circle relationships are detected. + * + * @param cr the ACir object to adjust + */ final void adj_cir1(ACir cr) { ACir cr1, cr2, cr3; Cond co; @@ -4531,6 +5373,13 @@ final void adj_cir1(ACir cr) { } } + /** + * Searches for an LLine that exactly contains the two specified points and has exactly one segment. + * + * @param p1 the first point + * @param p2 the second point + * @return the matching LLine if found; otherwise, null + */ public LLine fd_ln1(int p1, int p2) { LLine ln = all_ln.nx; while (ln != null) { @@ -4542,7 +5391,18 @@ public LLine fd_ln1(int p1, int p2) { return ln; } - + /** + * Creates and adds a PLine connecting two line segments defined by the given points. + * + * This method validates the parameters, checks for necessary conditions such as non-collinearity, + * updates or creates required LLine objects, and constructs a new PLine based on the provided points. + * + * @param lm the lemma or identifier for the PLine + * @param p1 the first point of the first segment + * @param p2 the second point of the first segment + * @param p3 the first point of the second segment + * @param p4 the second point of the second segment + */ final void add_pline1(int lm, int p1, int p2, int p3, int p4) { PLine pn; if (!valid(lm)) return; @@ -4618,6 +5478,14 @@ final void add_pline1(int lm, int p1, int p2, int p3, int p4) { } + /** + * Adjusts the configuration of the specified PLine based on its constituent lines. + * + * This method refines the composition of the PLine by evaluating its associated LLine segments, + * updating their states, and readjusting the PLine properties if necessary. + * + * @param pn the PLine to adjust + */ final void adj_pn(PLine pn) { PLine pn1, pn2, pn3; Cond co; @@ -4698,58 +5566,16 @@ final void adj_pn(PLine pn) { } } - final void add_as_codb(LLine l1, LLine l2, LLine l3, LLine l4) { - int p1, p2, p3, p4, p5, p6, p7, p8; - int a = inter_ll(l1, l2); - int b = inter_ll(l3, l4); - - if (a != 0) { - p2 = a; - p3 = a; - if (l1.pt[0] == a) - p1 = l1.pt[1]; - else - p1 = l1.pt[0]; - - if (l2.pt[0] == a) - p4 = l2.pt[1]; - else - p4 = l2.pt[0]; - } else { - p1 = l1.pt[0]; - p2 = l1.pt[1]; - p3 = l2.pt[0]; - p4 = l2.pt[1]; - } - if (b != 0) { - p6 = b; - p7 = b; - if (l3.pt[0] == b) - p5 = l3.pt[1]; - else - p5 = l3.pt[0]; - - if (l4.pt[0] == b) - p8 = l4.pt[1]; - else - p8 = l4.pt[0]; - } else { - p5 = l3.pt[0]; - p6 = l3.pt[1]; - p7 = l4.pt[0]; - p8 = l4.pt[1]; - } - add_codb(CO_ACONG, p1, p2, p3, p4, p5, p6, p7, p8); - } - - /////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////// - // traditional prove - - + /** + * Creates an Angles object using the four provided lines. + * + * @param lm the lemma identifier + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @param l4 the fourth line + * @return the constructed Angles object, or null if the input is invalid + */ Angles add_as_t(int lm, LLine l1, LLine l2, LLine l3, LLine l4) { if (l1 == l2 && l3 == l4) return null; if (!valid(lm)) return null; @@ -4812,6 +5638,17 @@ Angles add_as_t(int lm, LLine l1, LLine l2, LLine l3, LLine l4) { return (as); } + /** + * Checks whether the given sets of three points satisfy the congruence conditions. + * + * @param a first point of the first segment + * @param b second point of the first segment + * @param c third point of the first segment + * @param p first point of the second segment + * @param q second point of the second segment + * @param r third point of the second segment + * @return true if the conditions for congruence hold; false otherwise + */ final boolean xacongt(int a, int b, int c, int p, int q, int r) { LLine l1, l2, l3, l4; l1 = fd_ln(a, b); @@ -4826,6 +5663,19 @@ final boolean xacongt(int a, int b, int c, int p, int q, int r) { return (this.fo_as1_t(a, b, b, c, p, q, q, r) != null); } + /** + * Finds and returns an Angles object that matches the specified endpoints from four lines. + * + * @param a the first endpoint of the first line + * @param b the second endpoint of the first line + * @param c the first endpoint of the second line + * @param d the second endpoint of the second line + * @param p the first endpoint of the third line + * @param q the second endpoint of the third line + * @param r the first endpoint of the fourth line + * @param s the second endpoint of the fourth line + * @return the matching Angles object, or null if none is found + */ final Angles fo_as1_t(int a, int b, int c, int d, int p, int q, int r, int s) { Angles as = all_as.nx; @@ -4839,17 +5689,15 @@ final Angles fo_as1_t(int a, int b, int c, int d, int p, int q, int r, int s) { return null; } - Angles fd_as_t(LLine l1, LLine l2) { - Angles as; - for (as = all_as.nx; as != null; as = as.nx) { - if ( - (l1 == as.l1 && l2 == as.l2) || (l1 == as.l2 && l2 == as.l1) || - (l1 == as.l3 && l2 == as.l4) || (l1 == as.l4 && l2 == as.l3)) - return (as); - } - return (null); - } - + /** + * Retrieves an Angles object using four specified lines. + * + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @param l4 the fourth line + * @return the matching Angles object, or null if no match is found + */ final Angles fo_las_t(LLine l1, LLine l2, LLine l3, LLine l4) { Angles as = all_as.nx; while (as != null) { @@ -4862,6 +5710,16 @@ final Angles fo_las_t(LLine l1, LLine l2, LLine l3, LLine l4) { return (null); } + /** + * Adds an Angles object from the provided lines based on the project state. + * + * @param lm the lemma identifier + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @param l4 the fourth line + * @return the added Angles object + */ public Angles add_as(int lm, LLine l1, LLine l2, LLine l3, LLine l4) { if (isPFull()) return add_as0(lm, l1, l2, l3, l4); @@ -4869,6 +5727,17 @@ public Angles add_as(int lm, LLine l1, LLine l2, LLine l3, LLine l4) { return add_as_t(lm, l1, l2, l3, l4); } + /** + * Adds an inscribed angle point using the provided parameters. + * + * @param lm the lemma identifier + * @param a the first point on the first line + * @param b the second point on the first line + * @param c the third point on the first line + * @param p the first point on the second line + * @param q the second point on the second line + * @param r the third point on the second line + */ final void add_ea_pt_t(int lm, int a, int b, int c, int p, int q, int r) { // for inscrible angle. if (d_base == 1) return; @@ -4887,6 +5756,13 @@ final void add_ea_pt_t(int lm, int a, int b, int c, int p, int q, int r) { Angles as = add_as(lm, l1, l2, l3, l4); } + /** + * Adds a new line segment with endpoints a and b. + * + * @param a the first endpoint + * @param b the second endpoint + * @return the new or existing LLine instance, or null if the input is invalid + */ final LLine add_ln_t0(int a, int b) { if (a == 0 || b == 0) return null; @@ -4904,10 +5780,25 @@ final LLine add_ln_t0(int a, int b) { return ln; } + /** + * Fast-adds a line segment using the given endpoints. + * + * @param p1 the first endpoint + * @param p2 the second endpoint + * @return the added LLine object + */ LLine fadd_ln_t(int p1, int p2) { return add_ln_t0(p1, p2); } + /** + * Returns the anti midpoint from a line, excluding the specified endpoints. + * + * @param ln the line to search + * @param p one of the endpoints + * @param p1 the other endpoint + * @return the internal point on the line between p and p1, or 0 if not found + */ public int get_anti_pt(LLine ln, int p, int p1) { // p is imdpoint of x and p1 for (int i = 0; i <= ln.no; i++) { if (ln.pt[i] != p && ln.pt[i] != p1 && (x_inside(p, ln.pt[i], p1))) @@ -4916,7 +5807,13 @@ public int get_anti_pt(LLine ln, int p, int p1) { // p is imdpoint of x and p1 return 0; } - + /** + * Determines whether two lines are collinear. + * + * @param l1 the first line + * @param l2 the second line + * @return true if l1 and l2 are collinear; false otherwise + */ boolean xcoll_ln(LLine l1, LLine l2) { if (l1.type == 0 && l2.type == 0) { int r = 0; @@ -4932,31 +5829,47 @@ boolean xcoll_ln(LLine l1, LLine l2) { l2 = fd_lnl(l2); return l1 == l2; } - //////////////////////////////////////////////////////////////////// - //// for multipul prove. - - ////////////////////////////////////////////////////////////////////////////////// + /** + * Adds an angle (AngleT) by creating it from line segments corresponding to points a, b, and c. + * + * @param lemma the lemma identifier + * @param a the first point of the angle + * @param b the vertex point of the angle + * @param c the third point of the angle + * @param v the angle value + * @return the created AngleT object + */ public AngleT add_at(int lemma, int a, int b, int c, int v) { return add_at(lemma, fadd_ln_t(a, b), fadd_ln_t(b, c), v); } + /** + * Adds an angle (AngleT) by creating it using line segments looked up directly. + * + * @param lemma the lemma identifier + * @param a the first point of the angle + * @param b the vertex point of the angle + * @param c the third point of the angle + * @param v the angle value + * @return the created AngleT object + */ public AngleT add_at0(int lemma, int a, int b, int c, int v) { return add_at(lemma, fd_ln(a, b), fd_ln(b, c), v); } - - public AngleT new_at(int v, int p, LLine l1, LLine l2) { - AngleT at = new AngleT(); - at.v = v; - at.p = p; - at.l1 = l1; - at.l2 = l2; - return at; - } - + /** + * Creates and adds an AngleT instance with the given lemma, lines, and angle value. + * Returns the created AngleT if successful, or null otherwise. + * + * @param lemma the lemma identifier + * @param l1 the first line + * @param l2 the second line + * @param v the angle value + * @return the created AngleT instance or null + */ public AngleT add_at(int lemma, LLine l1, LLine l2, int v) { if (isPFull()) return null; if (!valid(R_AG_SPECIAL)) return null; @@ -5004,21 +5917,53 @@ else if (v <= -A_180) return at; } + /** + * Checks whether the angle formed by points a, b, and c is congruent to the specified angle value. + * + * @param a the first point + * @param b the second point + * @param c the third point + * @param v the angle value to compare + * @return true if the angle is congruent; false otherwise + */ public boolean xatcong(int a, int b, int c, int v) { AngleT at = fo_at(a, b, c); return check_ll_dr(at.p, at.l1, at.l2, v); } + /** + * Determines if the angle formed by the two lines is congruent. + * + * @param l1 the first line + * @param l2 the second line + * @return true if the lines form a congruent angle or are collinear; false otherwise + */ public boolean xatcong(LLine l1, LLine l2) { if (l1 == l2 || xcoll_ln(l1, l2)) return true; return fd_at(l1, l2) != null; } + /** + * Finds an existing AngleT instance based on three points, mapping these points to corresponding lines. + * + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @return the found AngleT instance, or null if none exists + */ public AngleT fd_at(int p1, int p2, int p3) { return fd_at(fd_ln(p1, p2), fd_ln(p2, p3)); } + /** + * Searches for the first AngleT instance that matches the line segments determined by the given points. + * + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @return the found AngleT instance, or null if not found + */ public AngleT fo_at(int p1, int p2, int p3) { AngleT at = all_at.nx; while (at != null) { @@ -5028,6 +5973,13 @@ public AngleT fo_at(int p1, int p2, int p3) { return null; } + /** + * Finds an AngleT instance defined by the two specified lines. + * + * @param l1 the first line + * @param l2 the second line + * @return the found AngleT instance, or null if it does not exist + */ public AngleT fd_at(LLine l1, LLine l2) { if (l1 == null || l2 == null) return null; @@ -5041,55 +5993,42 @@ public AngleT fd_at(LLine l1, LLine l2) { return null; } + /** + * Checks if the angle between the two lines at a specific point approximates the given angle measure. + * + * @param p the vertex point + * @param l1 the first line + * @param l2 the second line + * @param d the expected angle in degrees + * @return true if the measured angle is approximately equal to d degrees; false otherwise + */ public boolean check_ll_dr(int p, LLine l1, LLine l2, int d) { double r = getAngleValue(p, l1, l2); double x = Math.abs(r * A_180 / Math.PI - d); return x < ZERO || Math.abs(x - A_180) < ZERO || Math.abs(x + A_180) < ZERO; } - public int check_ll_type(int a, int b, int c, int d) { - double r = this.getAngleValue(a, b, c); - double x = Math.abs(r * A_180 / Math.PI - d); - if (x < ZERO) return 0; - if (Math.abs(x - A_180) < ZERO) return 1; - return -1; - } - + /** + * Checks if two angle measures are equal or supplementary. + * + * @param t1 the first angle measure + * @param t2 the second angle measure + * @return true if the angles are equal or differ by 180 degrees; false otherwise + */ public boolean check_at_eq(int t1, int t2) { return t1 == t2 || Math.abs(Math.abs(t1 - t2) - A_180) < ZERO; } - //////////////////////////////////////////////////// - // polygon - public void add_polygon(int t, int p[]) { - Polygon pg = new Polygon(t); - for (int i = 0; i < p.length && p[i] != 0; i++) - pg.p[i] = p[i]; - add_pg(pg); - } - - public Polygon fd_trix(int t, int a, int b, int c) { - Polygon pg = all_pg.nx; - while (pg != null) { - if (pg.qtype == t) { - if (pg.p[0] == a && (pg.p[1] == b && pg.p[2] == c || pg.p[1] == c && pg.p[2] == b)) return pg; - if (pg.p[0] == b && (pg.p[1] == a && pg.p[2] == c || pg.p[1] == c && pg.p[2] == a)) return pg; - if (pg.p[0] == c && (pg.p[1] == b && pg.p[2] == a || pg.p[1] == a && pg.p[2] == b)) return pg; - } - pg = pg.nx; - } - return null; - } - - public void add_pg(Polygon pg) { - last_pg.nx = pg; - last_pg = pg; - this.new_pr(pg.qtype); - last_nd.u.pg = pg; - } - - ///////////////////////////////////////////////////////////////////// - + /** + * Searches for an AngTn instance with the specified set of four lines. + * The search considers both direct and reverse orders. + * + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @param l4 the fourth line + * @return the found AngTn instance, or null if not found + */ public AngTn fo_atn(LLine l1, LLine l2, LLine l3, LLine l4) { AngTn atn = all_atn.nx; while (atn != null) { @@ -5104,6 +6043,20 @@ public AngTn fo_atn(LLine l1, LLine l2, LLine l3, LLine l4) { return null; } + /** + * Searches for an AngTn instance matching the provided point-derived line parameters. + * Various order combinations are evaluated. + * + * @param a the first point of the first line + * @param b the second point of the first line + * @param c the first point of the second line + * @param d the second point of the second line + * @param a1 the first point of the third line + * @param b1 the second point of the third line + * @param c1 the first point of the fourth line + * @param d1 the second point of the fourth line + * @return the matching AngTn instance, or null if not found + */ public AngTn fo_atn(int a, int b, int c, int d, int a1, int b1, int c1, int d1) { AngTn atn = all_atn.nx; while (atn != null) { @@ -5120,13 +6073,11 @@ public AngTn fo_atn(int a, int b, int c, int d, int a1, int b1, int c1, int d1) return null; } - - public AngTn add_atn(int lemma, int a, int b, int c, int a1, int b1, int c1) { - if (fo_atn(a, b, b, c, a1, b1, b1, c1) != null) return null; - - return add_atn(lemma, fadd_ln_t(a, b), fadd_ln_t(b, c), fadd_ln_t(a1, b1), fadd_ln_t(b1, c1)); - } - + /** + * Adjusts the given angle tangent node if necessary. + * + * @param atn the AngTn node to adjust + */ public void adj_atn(AngTn atn) { if (atn.type == 0) return; LLine l1 = atn.ln1; @@ -5170,6 +6121,13 @@ public void adj_atn(AngTn atn) { atn.type = 0; } + /** + * Adjusts a specific line segment within the angle tangent node based on a change. + * + * @param ln1 the modified line + * @param ln2 an associated line for adjustment + * @param atn the AngTn node to update + */ final void ch_ln_atn(LLine ln1, LLine ln2, AngTn atn) { if (atn.type == 0) return; LLine l1 = atn.ln1; @@ -5209,6 +6167,16 @@ final void ch_ln_atn(LLine ln1, LLine ln2, AngTn atn) { atn.type = 0; } + /** + * Adds a new angle tangent node using four line objects. + * + * @param lemma the lemma identifier + * @param l1 the first line in the angle configuration + * @param l2 the second line in the angle configuration + * @param l3 the third line in the angle configuration + * @param l4 the fourth line in the angle configuration + * @return the new AngTn object, or null if creation fails + */ public AngTn add_atn(int lemma, LLine l1, LLine l2, LLine l3, LLine l4) { if (isPFull()) return null; if (!valid(R_AG_ATN)) return null; @@ -5275,6 +6243,17 @@ public AngTn add_atn(int lemma, LLine l1, LLine l2, LLine l3, LLine l4) { return atn; } + /** + * Checks the directional relationship between two angles defined by three points each. + * + * @param a the first point of the first angle + * @param b the vertex point of the first angle + * @param c the second point of the first angle + * @param a1 the first point of the second angle + * @param b1 the vertex point of the second angle + * @param c1 the second point of the second angle + * @return 0, 1, 2, or 3 for specific directional configurations, or -1 if false + */ public int check_atn_dr(int a, int b, int c, int a1, int b1, int c1) { double t1 = getAngleValue(a, b, c); double t2 = getAngleValue(a1, b1, c1); @@ -5286,13 +6265,29 @@ public int check_atn_dr(int a, int b, int c, int a1, int b1, int c1) { return -1; // false } - - ///////////////////////////////////////////////////////////////// + /** + * Retrieves the adjusted angle value based on an AngleT object. + * + * @param a the first point for angle calculation + * @param b the vertex point for angle calculation + * @param c the second point for angle calculation + * @param at the AngleT object containing the original angle value + * @return the adjusted angle value + */ public int getAtv(int a, int b, int c, AngleT at) { int v = at.get_val(a, c); return getAtv(a, b, c, v); } + /** + * Computes the adjusted angle value using a given angle value. + * + * @param a the first point for angle calculation + * @param b the vertex point for angle calculation + * @param c the second point for angle calculation + * @param v the initial angle value + * @return the adjusted angle value, or 0 if no adjustment is needed + */ public int getAtv(int a, int b, int c, int v) { double r = getAngleValue(a, b, c) * A_180 / Math.PI; if (v > A_180) @@ -5306,30 +6301,65 @@ public int getAtv(int a, int b, int c, int v) { return 0; } + /** + * Determines if only existing lines should be searched. + * + * @return true if only existing lines are considered, false otherwise + */ public boolean search_only_exists_ln() { return (!R_SEARCH_ALL_LN);// && depth != 0); } - public boolean search_only_exists_ln(int a, int b) { - return (!R_SEARCH_ALL_LN) && fd_ln(a, b) == null; - } - + /** + * Checks whether lines defined by two pairs of points exist. + * + * @param a the first point of the first line + * @param b the second point of the first line + * @param c the first point of the second line + * @param d the second point of the second line + * @return true if at least one corresponding line does not exist, false otherwise + */ public boolean search_only_exists_ln(int a, int b, int c, int d) { return (!R_SEARCH_ALL_LN) && (fd_ln(a, b) == null || fd_ln(c, d) == null); } + /** + * Checks whether lines defined by three pairs of points exist. + * + * @param a the first point of the first line + * @param b the second point of the first line + * @param c the first point of the second line + * @param d the second point of the second line + * @param e the first point of the third line + * @param f the second point of the third line + * @return true if at least one corresponding line does not exist, false otherwise + */ public boolean search_only_exists_ln(int a, int b, int c, int d, int e, int f) { return (!R_SEARCH_ALL_LN) && (fd_ln(a, b) == null || fd_ln(c, d) == null || fd_ln(e, f) == null); } + /** + * Checks if the set of four lines satisfies the search criteria based on intersections. + * + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @param l4 the fourth line + * @return true if the lines meet the search criteria, false otherwise + */ public boolean search_only_exists_ln(LLine l1, LLine l2, LLine l3, LLine l4) { if (!R_AG_ALL && (inter_lls(l1, l2) == 0 || inter_lls(l3, l4) == 0)) return false; return true; } -///////////////////////////////////////////////////////////////////////////////////////////// - + /** + * Processes an array of integers to add nodes for a conclusion. + * Each group of three integers represents properties of one node. + * If an extra integer exists after grouping, it is processed as a separate node. + * + * @param p the array of integers representing node properties (zero-terminated) + */ public void add_nodes(int[] p) { // for conclusion; LList d = new LList(); @@ -5362,12 +6392,23 @@ public boolean search_only_exists_ln(LLine l1, LLine l2, LLine l3, LLine l4) { last_ns = d; } + /** + * Creates and returns a copy of the given node list. + * + * @param ns the original node list to copy + * @return a new node list copied from the provided list + */ public LList cp_nodes(LList ns) { LList d = new LList(); d.cp(ns); return d; } + /** + * Adds the specified node list to the global node list if it is not already present. + * + * @param d the node list to add + */ public void add_nodes(LList d) { if (d == null) return; if (x_list(d)) return; @@ -5376,6 +6417,12 @@ public void add_nodes(LList d) { last_ns = d; } + /** + * Checks whether an equivalent node list already exists in the collection. + * + * @param ls the node list to check + * @return true if an equivalent list exists; false otherwise + */ public boolean x_list(LList ls) { if (ls.nd == 0 && ls.nf == 0) return false; @@ -5387,6 +6434,13 @@ public boolean x_list(LList ls) { return false; } + /** + * Compares two node lists for equality based on their node and factor arrays. + * + * @param ls the first node list + * @param ls1 the second node list + * @return true if both lists are equal; false otherwise + */ public boolean eq_list(LList ls, LList ls1) { if (ls.nd != ls1.nd) return false; for (int i = 0; i < ls.nd; i++) { @@ -5401,6 +6455,14 @@ public boolean eq_list(LList ls, LList ls1) { return true; } + /** + * Determines if two Mnde objects are equivalent. + * Equivalence is based on the type value and, if present, the associated transformation. + * + * @param m1 the first Mnde object + * @param m2 the second Mnde object + * @return true if both Mnde objects are considered equal; false otherwise + */ public boolean eq_mnde(Mnde m1, Mnde m2) { if (m1.t != m2.t) return false; if (m1.tr == null && m2.tr == null) return true; @@ -5409,9 +6471,18 @@ public boolean eq_mnde(Mnde m1, Mnde m2) { if (m1.tr.l1 == m2.tr.l1 && m1.tr.l2 == m2.tr.l2) return true; return false; } - ///////////////////////////////////////////////////////// - + /** + * Retrieves an existing AngTr object matching the specified parameters, + * or creates a new one if none exists. + * + * @param v the angle value + * @param t1 the first transformation parameter + * @param t2 the second transformation parameter + * @param l1 the first line + * @param l2 the second line + * @return an existing or newly created AngTr object based on the parameters + */ public AngTr fadd_tr(int v, int t1, int t2, LLine l1, LLine l2) { AngTr tr = fd_tr(v, l1, l2); if (tr != null) return tr; @@ -5422,6 +6493,14 @@ public AngTr fadd_tr(int v, int t1, int t2, LLine l1, LLine l2) { return t; } + /** + * Creates and returns a new AngTr object with the specified angle value and lines. + * + * @param v the angle value + * @param l1 the first line + * @param l2 the second line + * @return a new AngTr object initialized with the provided parameters + */ public AngTr add_tr(int v, LLine l1, LLine l2) { AngTr tr = new AngTr(); tr.v = v; @@ -5432,6 +6511,14 @@ public AngTr add_tr(int v, LLine l1, LLine l2) { return tr; } + /** + * Searches for an existing AngTr object that matches the specified angle value and lines. + * + * @param v the angle value + * @param l1 the first line + * @param l2 the second line + * @return the matching AngTr object if found; otherwise, null + */ public AngTr fd_tr(int v, LLine l1, LLine l2) { AngTr tr = all_tr.nx; while (tr != null) { diff --git a/src/main/java/gprover/GDDBc.java b/src/main/java/gprover/GDDBc.java index 2d06d75d..b8504463 100644 --- a/src/main/java/gprover/GDDBc.java +++ b/src/main/java/gprover/GDDBc.java @@ -10,18 +10,28 @@ import wprover.GExpert; import java.util.Vector; - + +/** + * GDDBc class handles the geometric proof process and predicate management. + */ public class GDDBc extends GDDAux { + private static Rule test_r = new Rule(0); AuxPt axptc = null; + /** + * Constructs a new GDDBc instance initializing proof status, depth, and check value. + */ public GDDBc() { P_STATUS = 0; depth = 0; ck_value = true; } + /** + * Executes the fixed-point proof process, handling auxiliary points and node list generation. + */ void prove_fix() { axptc = null; @@ -79,24 +89,32 @@ void prove_fix() { } } - - int PTY(Cond x) { - return x.u.get_type(); - } - + /** + * Retrieves the lemma value from the condition. + * + * @param x the condition from which to obtain the lemma + * @return the lemma value associated with the condition + */ int PLM(Cond x) { return (x.u.get_lemma()); } + /** + * Retrieves the condition predicate from the underlying data structure. + * + * @param x the condition used to extract the predicate + * @return the corresponding condition predicate + */ Cond PCO(Cond x) { return (x.u.get_co()); } - int PNO(Cond x) { - return (x.u.get_no()); - } - - + /** + * Creates a copy of the given predicate condition and updates its identifier. + * + * @param co the original condition to copy + * @return a new condition copied from the provided one with updated identifiers + */ Cond cp_pred(Cond co) { Cond c = new_pr(co.pred); co.no = c.no = ++gno; @@ -108,6 +126,12 @@ Cond cp_pred(Cond co) { return (c); } + /** + * Searches for an existing predicate condition equivalent to the given condition. + * + * @param co the condition to search for + * @return the matching condition if found; otherwise, null + */ Cond fd_pred(Cond co) { Cond pr = all_nd.nx; for (; pr != null; pr = pr.nx) { @@ -116,6 +140,12 @@ Cond fd_pred(Cond co) { return (null); } + /** + * Searches for an equivalent predicate condition based on its comparison value. + * + * @param co the condition to search against + * @return the found condition if present; otherwise, null + */ Cond fd_prep(Cond co) { Cond pr = all_nd.nx; for (; pr != null; pr = pr.nx) { @@ -124,7 +154,21 @@ Cond fd_prep(Cond co) { return (null); } - + /** + * Creates and returns a predicate condition using the provided type and point parameters. + * + * @param m the predicate type identifier + * @param n the predicate condition identifier + * @param p1 the first point parameter + * @param p2 the second point parameter + * @param p3 the third point parameter + * @param p4 the fourth point parameter + * @param p5 the fifth point parameter + * @param p6 the sixth point parameter + * @param p7 the seventh point parameter + * @param p8 the eighth point parameter + * @return the constructed predicate condition or null if invalid + */ Cond add_pred(int m, int n, int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8) { tm_pr1.u.setnull(); tm_pr1.pred = n; @@ -176,6 +220,13 @@ Cond add_pred(int m, int n, int p1, int p2, int p3, int p4, int p5, int p6, int } + /** + * Determines the intersection point between two lines. + * + * @param l1 the first line + * @param l2 the second line + * @return the intersection point if it exists; otherwise, 0 + */ int finter_ll(LLine l1, LLine l2) { char i, j; @@ -187,6 +238,14 @@ int finter_ll(LLine l1, LLine l2) { return (0); } + /** + * Determines the intersection point between two lines, excluding a specified point. + * + * @param l1 the first line + * @param l2 the second line + * @param p1 the point to exclude from consideration + * @return the intersection point if valid and not equal to p1; otherwise, 0 + */ int finter_ll1(LLine l1, LLine l2, int p1) { char i, j; if (l1 == l2) return (0); @@ -197,6 +256,9 @@ int finter_ll1(LLine l1, LLine l2, int p1) { return (0); } + /** + * Processes and displays the forward proof for the current condition. + */ void show_fproof() { if (conc_xtrue()) { last_nd = all_nd; @@ -209,7 +271,13 @@ void show_fproof() { } } - + /** + * Processes forward predicates for the specified condition. + * + * Traverses the linked list of conditions and applies appropriate predicate rules. + * + * @param co the starting condition to process + */ void forw_pred(Cond co) { Cond pr1, pr2, pr3; show_dtype = 0; @@ -303,73 +371,16 @@ void forw_pred(Cond co) { } } - public boolean add_pr_coll(Cond pr, Cond pr1) { - if (pr.pred == CO_PERP && PLM(pr) == 11 && pr1.pred == CO_ACONG) { - int i1, i2, k1, k2; - if (xcoll4(pr.p[0], pr.p[1], pr1.p[4], pr1.p[5])) { - i1 = pr1.p[4]; - i2 = pr1.p[5]; - k1 = pr1.p[6]; - k2 = pr1.p[7]; - } else { - k1 = pr1.p[4]; - k2 = pr1.p[5]; - i1 = pr1.p[6]; - i2 = pr1.p[7]; - } - for_c4(pr.p[0], pr.p[1], i1, i2); - for_c4(pr.p[2], pr.p[3], k1, k2); - } else if (pr.pred == CO_ACONG && pr1.pred == CO_CYCLIC && PLM(pr) == 41) { - LLine l1 = fd_ln(pr.p[0], pr.p[1]); - LLine l2 = fd_ln(pr.p[2], pr.p[3]); - LLine l3 = fd_ln(pr.p[4], pr.p[5]); - LLine l4 = fd_ln(pr.p[6], pr.p[7]); - int i1 = finter_ll(l1, l2); - int i2 = finter_ll(l3, l4); - int k1 = finter_ll(l1, l3); - int k2 = finter_ll(l2, l4); - if (sdiff(i1, i2, k1, k2, pr.p)) { - for_c4(pr.p[0], pr.p[1], i1, k1); - for_c4(pr.p[2], pr.p[3], i1, k2); - for_c4(pr.p[4], pr.p[5], i2, k1); - for_c4(pr.p[6], pr.p[7], i2, k2); - Cond prc = add_pred(1, CO_ACONG, i1, k1, i1, k2, i2, k1, i2, k2); - pr.addcond(prc); - return false; - } - } else if (pr.pred == CO_ACONG && pr1.pred == CO_CYCLIC && PLM(pr) == 22) { - if (sdiff(pr1.p[0], pr1.p[1], pr1.p[2], 0, pr.p)) { - LLine l1 = fd_ln(pr.p[0], pr.p[1]); - LLine l2 = fd_ln(pr.p[2], pr.p[3]); - LLine l3 = fd_ln(pr.p[4], pr.p[5]); - LLine l4 = fd_ln(pr.p[6], pr.p[7]); - if (l1 == l4) { - int k1 = finter_ll(l2, l3); - int i1 = finter_ll(l1, l2); - int i2 = finter_ll(l1, l3); - for_c6(pr.p[0], pr.p[1], i1, i2, pr.p[6], pr.p[7]); - for_c4(pr.p[2], pr.p[3], k1, i1); - for_c4(pr.p[4], pr.p[5], k1, i2); - Cond prc = add_pred(1, CO_ACONG, i1, i2, i1, k1, i2, k1, i2, i1); - pr.addcond(prc); - } else { - int k1 = finter_ll(l1, l4); - int i1 = finter_ll(l2, l1); - int i2 = finter_ll(l2, l4); - for_c6(pr.p[2], pr.p[3], i1, i2, pr.p[4], pr.p[5]); - for_c4(pr.p[0], pr.p[1], k1, i1); - for_c4(pr.p[6], pr.p[7], k1, i2); - Cond prc = add_pred(1, CO_ACONG, k1, i1, i1, i2, i1, i2, i2, k1); - pr.addcond(prc); - - } - return false; - } - } - - return true; - } - + /** + * Adds a predicate for a collision based on the given conditions. + * + * Determines the appropriate collision predicate by checking common line intersections + * and adds a corresponding parallel predicate condition. + * + * @param pr the main condition to add to + * @param pr1 the first sub-condition containing line information + * @param pr2 the second sub-condition containing line information + */ public void add_pred_coll(Cond pr, Cond pr1, Cond pr2) { int lemma = PLM(pr); switch (lemma) { @@ -396,6 +407,16 @@ else if (on_ln(pr.p[i], pr.p[j], l2) && on_ln(pr.p[k], l1)) } } + /** + * Adds a predicate for parallelism based on the provided sub-conditions. + * + * Chooses the appropriate rule based on a lemma value and constructs the relevant predicate + * conditions using line or angle data. + * + * @param pr the main condition to add to + * @param pr1 the first sub-condition providing primary predicate data + * @param pr2 the second sub-condition providing supplementary predicate data + */ public void add_pred_para(Cond pr, Cond pr1, Cond pr2) { LLine ln; PLine pn1; @@ -522,6 +543,16 @@ else if (xcoll_ln(fd_ln(pr.p[2], pr.p[3]), pn.ln[i])) } } + /** + * Adds a predicate for perpendicularity based on the given conditions. + * + * Selects the appropriate perpendicularity rule using a lemma value and established geometric + * relationships, then adds the resulting predicate condition. + * + * @param pr the main condition in which the predicate is to be added + * @param pr1 the first sub-condition providing geometric entity information + * @param pr2 the second sub-condition providing geometric entity information + */ public void add_pred_perp(Cond pr, Cond pr1, Cond pr2) { int lm = PLM(pr); @@ -605,6 +636,15 @@ public void add_pred_perp(Cond pr, Cond pr1, Cond pr2) { } } + /** + * Adds a predicate for cyclic configurations based on the given conditions. + * + * Extracts circle information from the sub-conditions and creates cyclic predicate conditions. + * + * @param pr the main condition to add to + * @param pr1 the first sub-condition containing circle data + * @param pr2 the second sub-condition containing circle data + */ public void add_pred_cr(Cond pr, Cond pr1, Cond pr2) { int lm = PLM(pr); switch (lm) { @@ -620,6 +660,15 @@ public void add_pred_cr(Cond pr, Cond pr1, Cond pr2) { } + /** + * Constructs a cyclic predicate condition from the given circle. + * + * Calculates a set of points on the circle and creates a cyclic predicate condition. + * + * @param pr the original condition used to reference predicate parameters + * @param c1 the circle from which cyclic properties are derived + * @return a new predicate condition representing the cyclic property + */ public Cond add_pred_cyclic1(Cond pr, ACir c1) { int[] p = new int[4]; for (int i = 0; i < 4; i++) @@ -647,6 +696,22 @@ public Cond add_pred_cyclic1(Cond pr, ACir c1) { return add_pred(0, CO_CYCLIC, c1.o, p[0], p[1], p[2], p[3], 0, 0, 0); } + /** + * Adds a predicate based on points and two lines. + * + * Determines appropriate points on the provided lines and constructs a predicate condition with + * the supplied parameters. + * + * @param m the mode or additional modifier for the predicate + * @param n the predicate type identifier + * @param p1 the first point reference + * @param p2 the second point reference + * @param l1 the first line for the predicate + * @param p3 the third point reference + * @param p4 the fourth point reference + * @param l2 the second line for the predicate + * @return a new predicate condition based on the given point and line data + */ public Cond add_pred_pntn(int m, int n, int p1, int p2, LLine l1, int p3, int p4, LLine l2) { int m1, m2, m3, m4; @@ -669,6 +734,22 @@ else if (on_ln(p4, l2)) return add_pred(m, n, m1, m2, m3, m4, 0, 0, 0, 0); } + /** + * Adds a predicate based on tangent line intersections. + * + * Determines intersection points or valid points from the two lines and constructs a tangent rule + * predicate with the specified parameters. + * + * @param m the mode or modifier for the predicate + * @param n the predicate type + * @param p1 the first point candidate for line l1 + * @param p2 the second point candidate for line l1 + * @param l1 the first line used to determine the tangent condition + * @param p3 the first point candidate for line l2 + * @param p4 the second point candidate for line l2 + * @param l2 the second line used to determine the tangent condition + * @return a new predicate condition representing the tangent rule + */ public Cond add_pred_tn13(int m, int n, int p1, int p2, LLine l1, int p3, int p4, LLine l2) { int m1, m2, m3, m4; int o = inter_lls(l1, l2); @@ -694,6 +775,15 @@ else if (on_ln(p4, l2)) return add_pred(m, n, m1, m2, m3, m4, 0, 0, 0, 0); } + /** + * Adds a predicate for angle tangency based on the provided conditions. + * + * Uses geometric relationships from the sub-conditions to construct an angle tangency predicate. + * + * @param pr the main condition to which the predicate will be added + * @param pr1 the first sub-condition containing angle information + * @param pr2 the second sub-condition that may provide additional angle data + */ public void add_pred_atn(Cond pr, Cond pr1, Cond pr2) { int lm = PLM(pr); @@ -729,6 +819,23 @@ public void add_pred_atn(Cond pr, Cond pr1, Cond pr2) { } } + /** + * Adds predicates for angle tangency transformations based on paired line configurations. + * + * Compares the relationships between two sets of lines and constructs paired predicates to + * represent angle tangent conditions. + * + * @param pr the main condition to add the predicates to + * @param l1 the first line of the first pair + * @param l2 the second line of the first pair + * @param l3 the first line of the second pair + * @param l4 the second line of the second pair + * @param s1 the first line of the complementary pair + * @param s2 the second line of the complementary pair + * @param s3 the third line used for additional tangent validation + * @param s4 the fourth line used for additional tangent validation + * @return true if the appropriate tangent predicates were added; false otherwise + */ public boolean add_pred_atn_atnas(Cond pr, LLine l1, LLine l2, LLine l3, LLine l4, LLine s1, LLine s2, LLine s3, LLine s4) { if (on_ln4(pr.p, l1, l2, s1, s2)) { @@ -755,6 +862,16 @@ public boolean add_pred_atn_atnas(Cond pr, LLine l1, LLine l2, LLine l3, LLine l return false; } + /** + * Adds an angle tangency predicate based on provided angle transformations. + * + * Analyzes the relationships between two angle-based conditions and constructs corresponding + * tangent predicates. + * + * @param pr the main condition to modify + * @param pr1 the first sub-condition containing angle transformation data + * @param pr2 the second sub-condition containing angle transformation data + */ public void add_pred_at(Cond pr, Cond pr1, Cond pr2) { int lm = PLM(pr); @@ -863,6 +980,13 @@ public void add_pred_at(Cond pr, Cond pr1, Cond pr2) { } } + /** + * Processes the provided conditions and angle structures to add angle predicates. + * + * @param pr the main condition to add predicates to + * @param pr1 the first condition containing angle information + * @param pr2 the second condition containing angle information + */ public void add_pred_as(Cond pr, Cond pr1, Cond pr2) { Angles as1, as2; as1 = as2 = null; @@ -990,6 +1114,13 @@ public void add_pred_as(Cond pr, Cond pr1, Cond pr2) { } } + /** + * Creates angle predicates by comparing two angle structures and adds them to the condition. + * + * @param pr the target condition to add predicates to + * @param as1 the first angle structure + * @param as2 the second angle structure + */ public void add_as82_t(Cond pr, Angles as1, Angles as2) { LLine l1, l2, l3, l4, l5, l6, l7, l8; l1 = as1.l1; @@ -1027,6 +1158,20 @@ public void add_as82_t(Cond pr, Angles as1, Angles as2) { return; } + /** + * Attempts to add angle congruence predicates using candidate lines from two angle structures. + * + * @param pr the condition containing predicate parameters + * @param l1 the first line from the first structure + * @param l2 the second line from the first structure + * @param l3 the first line from the second structure + * @param l4 the second line from the second structure + * @param l5 a candidate line from the first structure of the second angle structure + * @param l6 a candidate line from the first structure of the second angle structure + * @param l7 a candidate line from the second structure of the second angle structure + * @param l8 a candidate line from the second structure of the second angle structure + * @return true if predicates were successfully added; false otherwise + */ public boolean add_as82t1(Cond pr, LLine l1, LLine l2, LLine l3, LLine l4, LLine l5, LLine l6, LLine l7, LLine l8) { @@ -1061,6 +1206,18 @@ public boolean add_as82t1(Cond pr, LLine l1, LLine l2, LLine l3, LLine l4, return true; } + /** + * Retrieves candidate line pairs for predicates based on provided parameters. + * + * @param p the integer array containing predicate parameters + * @param l1 the primary line candidate from the first structure + * @param s1 the secondary candidate line corresponding to l1 + * @param l2 the primary line candidate from the second structure + * @param l3 the secondary line candidate from the third structure + * @param s2 the candidate line corresponding to l3 + * @param l4 a fallback line candidate + * @return an array of two candidate lines if matching lines are found; null otherwise + */ LLine[] get_cond_lns(int[] p, LLine l1, LLine s1, LLine l2, LLine l3, LLine s2, LLine l4) { LLine[] lns = get_cond_ln(p, l1, s1, l2, l3, s2, l4); if (lns != null) return lns; @@ -1073,6 +1230,18 @@ LLine[] get_cond_lns(int[] p, LLine l1, LLine s1, LLine l2, LLine l3, LLine s2, return null; } + /** + * Retrieves candidate lines if all predicate parameters lie on the specified lines. + * + * @param p the integer array of predicate parameters + * @param l1 the first line to check + * @param s1 the candidate line corresponding to l1 + * @param l2 the second line to check + * @param l3 the third line to check + * @param s2 the candidate line corresponding to l3 + * @param l4 the fourth line to check + * @return an array containing two candidate lines if conditions match; null otherwise + */ public LLine[] get_cond_ln(int[] p, LLine l1, LLine s1, LLine l2, LLine l3, LLine s2, LLine l4) { if (!on_ln4(p, l1, l2, l3, l4)) return null; LLine[] ns = new LLine[2]; @@ -1081,10 +1250,27 @@ public LLine[] get_cond_ln(int[] p, LLine l1, LLine s1, LLine l2, LLine l3, LLin return ns; } + /** + * Checks whether each pair of predicate parameters corresponds to a point on the given lines. + * + * @param p the integer array of predicate parameters + * @param l1 the first line for verification + * @param l2 the second line for verification + * @param l3 the third line for verification + * @param l4 the fourth line for verification + * @return true if each predicate parameter pair lies on the corresponding line; false otherwise + */ public boolean on_ln4(int[] p, LLine l1, LLine l2, LLine l3, LLine l4) { return on_ln(p[0], p[1], l1) && on_ln(p[2], p[3], l2) && on_ln(p[4], p[5], l3) && on_ln(p[6], p[7], l4); } + /** + * Processes angle structures to determine appropriate lines and add angle congruence predicates. + * + * @param pr the condition object holding predicate parameters + * @param as1 the first angle structure + * @param as2 the second angle structure + */ public void add_as82(Cond pr, Angles as1, Angles as2) { LLine l1, l2, l3, l4; l1 = l2 = l3 = l4 = null; @@ -1117,6 +1303,18 @@ public void add_as82(Cond pr, Angles as1, Angles as2) { pr.addcond(co1, co2); } + /** + * Creates a tangent predicate using four point parameters and an additional value. + * + * @param m a mode or flag for predicate creation + * @param n a predicate type identifier + * @param p1 the first point of the first pair + * @param p2 the second point of the first pair + * @param p3 the first point of the second pair + * @param p4 the second point of the second pair + * @param p5 an additional parameter influencing the tangent value + * @return a newly created condition representing a tangent predicate + */ public Cond add_pred_4p_tang(int m, int n, int p1, int p2, int p3, int p4, int p5) { int t1, t2, t3; t1 = t2 = t3 = 0; @@ -1140,6 +1338,17 @@ public Cond add_pred_4p_tang(int m, int n, int p1, int p2, int p3, int p4, int p return add_pred(m, n, t1, t2, t3, p5, 0, 0, 0, 0); } + /** + * Determines the angle transformation value based on the provided points and angle transformation objects. + * + * @param p1 the first point for comparison + * @param p2 the second point for comparison + * @param p3 the third point for comparison + * @param p4 the fourth point for comparison + * @param at1 the first angle transformation object + * @param at2 the second angle transformation object + * @return the computed angle value + */ public int get_at2_v(int p1, int p2, int p3, int p4, AngleT at1, AngleT at2) { LLine l1 = at1.l1; LLine l2 = at1.l2; @@ -1156,6 +1365,19 @@ public int get_at2_v(int p1, int p2, int p3, int p4, AngleT at1, AngleT at2) { return 0; } + /** + * Determines a pair of lines based on predicate parameters and candidate line options. + * + * @param a the first integer parameter for the predicate + * @param b the second integer parameter for the predicate + * @param c the third integer parameter for the predicate + * @param d the fourth integer parameter for the predicate + * @param ln1 the first candidate line + * @param ln2 the second candidate line + * @param ln3 the third candidate line + * @param ln4 the fourth candidate line + * @return an array containing two lines if a valid pair is found; null otherwise + */ LLine[] get4lntn(int a, int b, int c, int d, LLine ln1, LLine ln2, LLine ln3, LLine ln4) { LLine[] ls = new LLine[2]; if (on_ln(a, b, ln1) && on_ln(c, d, ln2)) { @@ -1175,6 +1397,11 @@ LLine[] get4lntn(int a, int b, int c, int d, LLine ln1, LLine ln2, LLine ln3, LL return ls; } + /** + * Forwards equal angle predicate if the condition is of type CO_ACONG. + * + * @param pr the condition containing angle parameters + */ void forw_eqangle(Cond pr) { if (pr.pred != Gib.CO_ACONG) return; LLine ln1 = fd_ln(pr.p[0], pr.p[1]); @@ -1189,83 +1416,11 @@ void forw_eqangle(Cond pr) { } } - void for_c4(int p1, int p2, int p3, int p4) { - int[] ps = new int[4]; - int i, p = -1; - - if (p1 != 0 && p1 != p2 && p1 != p3 && p1 != p4) { - p++; - ps[p] = p1; - } - if (p2 != 0 && p2 != p3 && p2 != p4) { - p++; - ps[p] = p2; - } - if (p3 != 0 && p3 != p4) { - p++; - ps[p] = p3; - } - if (p4 != 0) { - p++; - ps[p] = p4; - } - if (p > 1) { - - gprint(Cm.s2707); - gprint("["); - for (i = 0; i <= p; i++) { - gprint(ANAME(ps[i])); - } - gprint(Cm.s2070); - gprint(", "); - } - } - - void for_c6(int p1, int p2, int p3, int p4, int p5, int p6) { - int[] ps = new int[6]; - int i, p = -1; - if (p1 != 0 && p1 != p2 && p1 != p3 && p1 != p4 && p1 != p5 && p1 != p6) { - p++; - ps[p] = p1; - } - if (p2 != 0 && p2 != p3 && p2 != p4 && p2 != p5 && p2 != p6) { - p++; - ps[p] = p2; - } - if (p3 != 0 && p3 != p4 && p3 != p5 && p3 != p6) { - p++; - ps[p] = p3; - } - if (p4 != 0 && p4 != p5 && p4 != p6) { - p++; - ps[p] = p4; - } - if (p5 != 0 && p5 != p6) { - p++; - ps[p] = p5; - } - if (p6 != 0) { - p++; - ps[p] = p6; - } - if (p > 1) { - gprint(Cm.s2707); - gprint("["); - for (i = 0; i <= p; i++) { - gprint(ANAME(ps[i])); - } - gprint("]"); - gprint(Cm.s2070); - gprint(", "); - } - } - - void show_nco(Cond co) { - gprint("(" + co.no + ")"); - show_dtype = 0; - show_pred(co); - } - + /** + * Iterates through all conditions and displays each predicate, including any sub-conditions. + * + * @return true after processing all predicates + */ boolean show_allpred() { Cond co = all_nd.nx; Cond pr1; @@ -1282,7 +1437,12 @@ boolean show_allpred() { return true; } - + /** + * Displays the human-readable form of a given predicate condition. + * + * @param co the condition to display + * @return true after the display has been generated + */ boolean show_pred(Cond co) { switch (co.pred) { case 0: @@ -1531,6 +1691,13 @@ boolean show_pred(Cond co) { return true; } + /** + * Compares two predicate conditions to check for equivalence. + * + * @param co the first condition to compare + * @param pr the second condition to compare + * @return true if both conditions are considered equivalent, false otherwise + */ boolean compare_pred(Cond co, Cond pr) // do_pred(x,x,3) ----------> check two predicate is the same. { if (co.pred != pr.pred) return (false); @@ -1594,6 +1761,12 @@ else if (co.p[0] == pr.p[3] && co.p[1] == pr.p[2] && co.p[2] == pr.p[1] && co.p[ return ex; } + /** + * Checks whether a given predicate is obviously true based on its parameters. + * + * @param co the condition to check + * @return true if the condition meets an obvious criteria, false otherwise + */ boolean check_pred(Cond co) // if it obviousely. { boolean va = false; @@ -1633,6 +1806,11 @@ boolean check_pred(Cond co) // if it obviousely. } + /** + * Processes the predicate condition by executing the corresponding operation based on its type. + * + * @param co the condition to process + */ final void do_pred(Cond co) { switch (co.pred) { @@ -1699,7 +1877,13 @@ final void do_pred(Cond co) { } } - + /** + * Generates a string representation of point names from a condition's parameters. + * + * @param co the condition containing the point parameters + * @param n the starting index of the points in the array + * @return the generated string of point names + */ String show_pts(Cond co, int n) { int i, k; i = k = 0; @@ -1715,29 +1899,15 @@ String show_pts(Cond co, int n) { return s; } - void show_copt(Cond co, int n) { - int i, k; - i = k = 0; - for (i = n; i <= 5; i++) if (co.p[i] != 0) k = i; - - for (i = n; i <= k; i++) { - if (co.p[i] != 0) { - gprint(ANAME(co.p[i])); - if (i != k) gprint(","); - } - } - } - - - boolean sdiff(int a, int b, int c, int d, int ps[]) { - int i; - for (i = 0; i <= 7; i++) { - if (ps[i] == a || ps[i] == b || ps[i] == c || ps[i] == d) continue; - return (true); - } - return (false); - } - + /** + * Compares two arrays of characteristic values to determine if they have the same elements. + * + * @param ch1 the first array of characteristics + * @param n1 the number of valid entries in the first array + * @param ch2 the second array of characteristics + * @param n2 the number of valid entries in the second array + * @return true if both arrays are equal (ignoring order), false otherwise + */ boolean eq_chs(int[] ch1, int n1, int[] ch2, int n2) // Check !! { int id1 = 1; @@ -1764,6 +1934,16 @@ boolean eq_chs(int[] ch1, int n1, int[] ch2, int n2) // Check !! return (true); } + /** + * Retrieves two lines based on the given endpoints from an Angles object's line set. + * + * @param a first point parameter associated with the first line + * @param b second point parameter associated with the first line + * @param c first point parameter associated with the second line + * @param d second point parameter associated with the second line + * @param as the Angles object containing four lines (l1, l2, l3, l4) + * @return an array of two LLine objects if a valid pair is found; otherwise, null + */ LLine[] geti81(int a, int b, int c, int d, Angles as) { LLine l1, l2, l3, l4; l1 = as.l1; @@ -1773,6 +1953,20 @@ LLine[] geti81(int a, int b, int c, int d, Angles as) { return get4ln(l1, l2, l3, l4, a, b, c, d); } + /** + * Determines and returns two complementary LLine objects from the provided four lines + * based on matching endpoint conditions. + * + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @param l4 the fourth line + * @param a first endpoint parameter for matching + * @param b second endpoint parameter for matching + * @param c third endpoint parameter for matching + * @param d fourth endpoint parameter for matching + * @return an array of two LLine objects satisfying the conditions; returns null if none found + */ LLine[] get4ln(LLine l1, LLine l2, LLine l3, LLine l4, int a, int b, int c, int d) { LLine[] ln = new LLine[2]; @@ -1815,6 +2009,16 @@ LLine[] get4ln(LLine l1, LLine l2, LLine l3, LLine l4, int a, int b, int c, int } + /** + * Retrieves a pair of LLine objects from an Angles object based on endpoint criteria. + * + * @param a first endpoint parameter + * @param b second endpoint parameter + * @param c third endpoint parameter + * @param d fourth endpoint parameter + * @param as the Angles object with four lines (l1, l2, l3, l4) + * @return an array of two LLine objects if matching conditions are met; otherwise, null + */ LLine[] geti82(int a, int b, int c, int d, Angles as) { LLine l1, l2, l3, l4; l1 = as.l1; @@ -1848,11 +2052,20 @@ LLine[] geti82(int a, int b, int c, int d, Angles as) { return ln; } + /** + * Determines whether the current conclusion is valid. + * + * @return true if the conclusion satisfies the required geometric conditions; false otherwise + */ boolean conc_xtrue() { return (docc()); } - + /** + * Evaluates the current conclusion by testing various geometric predicates. + * + * @return true if the condition passes the geometric tests; false otherwise + */ boolean docc() { boolean j = false; switch (conc.pred) { @@ -1923,10 +2136,11 @@ boolean docc() { return (j); } - /////////////////////////////////////////// - // pred. - - + /** + * Displays the composite condition by printing concatenated condition information. + * + * @param co the condition object to be displayed + */ void show_cos(Cond co) { if (co != null) { gprint(Cm.s2727); @@ -1947,7 +2161,10 @@ void show_cos(Cond co) { } } - + /** + * Generates textual representations for all geometric entities in the database. + * This includes midpoints, lines, points, circles, angles, and other conditions. + */ public void gen_dbase_text() { this.setPrintToString(); @@ -2045,13 +2262,21 @@ public void gen_dbase_text() { } } - + /** + * Displays the provided condition using the default display format. + * + * @param co the condition object to display + */ void show_co(Cond co) { show_dtype = 0; show_pred(co); } - + /** + * Displays an angle statement from an angle statement object. + * + * @param ast the angle statement object to be displayed + */ public void show_ast(AngSt ast) { gprint(ast.no + "."); if (ast.no < 10) gprint(" "); @@ -2063,6 +2288,11 @@ public void show_ast(AngSt ast) { ast.sd = this.getPrintedString(); } + /** + * Displays the angle represented by an AngleT object, including its line representation and computed value. + * + * @param at the AngleT object containing angle information + */ void show_at(AngleT at) { if (at == null) return; show_agll(at.l1, at.l2); @@ -2076,7 +2306,12 @@ void show_at(AngleT at) { gprint(" = " + ((float) v) / A_TIME); } - //////////////////////////////////////////////////////////// + /** + * Inserts a CClass object into a sorted Vector based on its identifier. + * + * @param obj the CClass object to be inserted + * @param v the Vector collection maintaining sorted CClass objects + */ public void insertVector(CClass obj, Vector v) { if(obj == null) return; @@ -2093,6 +2328,11 @@ public void insertVector(CClass obj, Vector v) { v.add(obj); } + /** + * Returns a Vector containing all MidPt objects with a non-zero type. + * + * @return a Vector of valid MidPt objects + */ public Vector getAll_md() { Vector v = new Vector(); MidPt md = all_md.nx; @@ -2104,6 +2344,11 @@ public Vector getAll_md() { return v; } + /** + * Returns a Vector containing all LLine objects with a non-zero type and at least 2 points. + * + * @return a Vector of valid LLine objects + */ public Vector getAll_ln() { Vector v = new Vector(); LLine ln = all_ln.nx; @@ -2115,6 +2360,11 @@ public Vector getAll_ln() { return v; } + /** + * Returns a Vector containing all PLine objects with a non-zero type. + * + * @return a Vector of valid PLine objects + */ public Vector getAll_pn() { Vector v = new Vector(); PLine pn = all_pn.nx; @@ -2126,6 +2376,11 @@ public Vector getAll_pn() { return v; } + /** + * Returns a Vector containing all TLine objects with a non-zero type. + * + * @return a Vector of valid TLine objects + */ public Vector getAll_tn() { Vector v = new Vector(); TLine tn = all_tn.nx; @@ -2137,6 +2392,11 @@ public Vector getAll_tn() { return v; } + /** + * Returns a Vector containing all ACir objects with a non-zero type and at least 2 points. + * + * @return a Vector of valid ACir objects + */ public Vector getAll_cir() { Vector v = new Vector(); ACir cr = all_cir.nx; @@ -2148,6 +2408,11 @@ public Vector getAll_cir() { return v; } + /** + * Returns a Vector containing all AngSt objects with a non-zero type. + * + * @return a Vector of valid AngSt objects + */ public Vector getAll_as() { Vector v = new Vector(); AngSt ast = all_ast.nx; @@ -2159,6 +2424,11 @@ public Vector getAll_as() { return v; } + /** + * Returns a Vector containing all AngleT objects with a non-zero type. + * + * @return a Vector of valid AngleT objects + */ public Vector getAll_at() { Vector v = new Vector(); AngleT at = all_at.nx; @@ -2170,6 +2440,11 @@ public Vector getAll_at() { return v; } + /** + * Returns a Vector containing all AngTn objects with a non-zero type. + * + * @return a Vector of valid AngTn objects + */ public Vector getAll_atn() { Vector v = new Vector(); AngTn at = all_atn.nx; @@ -2181,7 +2456,11 @@ public Vector getAll_atn() { return v; } - + /** + * Returns a Vector containing all CSegs objects with a non-zero type. + * + * @return a Vector of valid CSegs objects + */ public Vector getAll_cg() { Vector v = new Vector(); CSegs cg = all_cgs.nx; @@ -2193,6 +2472,11 @@ public Vector getAll_cg() { return v; } + /** + * Returns a Vector containing all CongSeg objects with a non-zero type. + * + * @return a Vector of valid CongSeg objects + */ public Vector getAll_rg() { Vector v = new Vector(); CongSeg cg = all_rg.nx; @@ -2204,28 +2488,11 @@ public Vector getAll_rg() { return v; } - public Vector getAll_st() { - Vector v = new Vector(); - SimTri st = all_st.nx; - while (st != null) { - if (st.type != 0 && !xcoll(st.p1[0], st.p1[1], st.p1[2])) - insertVector(st, v); - st = st.nx; - } - return v; - } - - public Vector getAll_ct() { - Vector v = new Vector(); - SimTri ct = all_ct.nx; - while (ct != null) { - if (ct.type != 0 && !xcoll(ct.p1[0], ct.p1[1], ct.p1[2])) - insertVector(ct, v); - ct = ct.nx; - } - return v; - } - + /** + * Returns a Vector containing all RatioSeg objects with a non-zero type. + * + * @return a Vector of valid RatioSeg objects + */ public Vector getAll_ra() { Vector v = new Vector(); RatioSeg ra = all_ra.nx; @@ -2237,6 +2504,11 @@ public Vector getAll_ra() { return v; } + /** + * Returns a Vector containing all STris objects with a non-zero type. + * + * @return a Vector of valid STris objects + */ public Vector getAll_sts() { Vector v = new Vector(); STris sts = all_sts.nx; @@ -2248,6 +2520,11 @@ public Vector getAll_sts() { return v; } + /** + * Returns a Vector containing all STris objects (alternate set) with a non-zero type. + * + * @return a Vector of valid alternate STris objects + */ public Vector getAll_cts() { Vector v = new Vector(); STris sts = all_cts.nx; @@ -2259,6 +2536,15 @@ public Vector getAll_cts() { return v; } + /** + * Searches for a fact based on the specified type and string parameters. + * + * @param t the fact type selector + * @param s1 the first string parameter + * @param s2 the second string parameter + * @param s3 the third string parameter + * @return a Vector containing the matching fact objects + */ public Vector search_a_fact(int t, String s1, String s2, String s3) { int t1 = this.fd_pt(s1); int t2 = this.fd_pt(s2); @@ -2302,6 +2588,13 @@ public Vector search_a_fact(int t, String s1, String s2, String s3) { return v; } + /** + * Retrieves a line if it has at least two points. + * + * @param a the first point parameter + * @param b the second point parameter + * @return the matching line if it exists and meets the criteria; otherwise, null + */ private LLine fd_lnno3(int a, int b) { LLine ln = fd_ln(a, b); if (ln != null && ln.no >= 2) @@ -2309,6 +2602,14 @@ private LLine fd_lnno3(int a, int b) { return null; } + /** + * Searches for angle transformation nodes and adds them to the provided vector. + * + * @param a the first point parameter + * @param b the second point parameter + * @param c the third point parameter + * @param v the vector to collect matching angle transformation nodes + */ private void fo_atn2(int a, int b, int c, Vector v) { AngTn atn = all_atn.nx; @@ -2323,6 +2624,15 @@ else if (on_ln(a, b, atn.ln3) && on_ln(b, c, atn.ln4) || on_ln(a, b, atn.ln4) && } } + /** + * Searches for a triangle matching the given parameters and adds it to the vector. + * + * @param a the first point parameter + * @param b the second point parameter + * @param c the third point parameter + * @param v the vector to collect the matching triangle nodes + * @return always returns null + */ STris fo_tri2(int a, int b, int c, Vector v) { STris st = all_sts.nx; while (st != null) { @@ -2343,6 +2653,14 @@ STris fo_tri2(int a, int b, int c, Vector v) { return null; } + /** + * Searches for and adds congruence or circular segments matching the given points. + * + * @param a the first point parameter + * @param b the second point parameter + * @param v the vector to collect matching segment objects + * @return always returns null + */ CClass fo_cg2(int a, int b, Vector v) { CSegs cgs = all_cgs.nx; @@ -2363,7 +2681,17 @@ CClass fo_cg2(int a, int b, Vector v) { return null; } - /////////////////////////////////////////////////////////////////////////////////////// + /** + * Creates a predicate for angle similarity based on four provided lines. + * + * @param m the predicate type + * @param n the predicate identifier + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @param l4 the fourth line + * @return the constructed predicate object + */ Cond add_as_pred(int m, int n, LLine l1, LLine l2, LLine l3, LLine l4) { int p1, p2, p3, p4, p5, p6, p7, p8; int a = inter_ll(l1, l2); @@ -2395,6 +2723,19 @@ Cond add_as_pred(int m, int n, LLine l1, LLine l2, LLine l3, LLine l4) { return add_pred(m, n, p1, p2, p3, p4, p5, p6, p7, p8); } + /** + * Creates a predicate from point parameters and two lines. + * + * @param m the predicate type + * @param n the predicate identifier + * @param p1 the first point parameter + * @param p2 the second point parameter + * @param p3 the third point parameter + * @param p4 the fourth point parameter + * @param l3 the third line + * @param l4 the fourth line + * @return the constructed predicate object + */ Cond add_as_pred1(int m, int n, int p1, int p2, int p3, int p4, LLine l3, LLine l4) { int p5, p6, p7, p8; int b = inter_ll(l3, l4); @@ -2425,6 +2766,19 @@ Cond add_as_pred1(int m, int n, int p1, int p2, int p3, int p4, LLine l3, LLine return add_pred(m, n, p1, p2, p3, p4, p5, p6, p7, p8); } + /** + * Creates a predicate using a line to derive additional point parameters. + * + * @param m the predicate type + * @param n the predicate identifier + * @param p1 the first point parameter + * @param p2 the second point parameter + * @param l1 the line used to obtain additional point information + * @param p5 the fifth point parameter + * @param p6 the sixth point parameter + * @param l2 the second line used to obtain additional point information + * @return the constructed predicate object + */ Cond add_as_pred1(int m, int n, int p1, int p2, LLine l1, int p5, int p6, LLine l2) { int p3, p4, p7, p8; if (on_ln(p1, l1)) { @@ -2462,6 +2816,21 @@ Cond add_as_pred1(int m, int n, int p1, int p2, LLine l1, int p5, int p6, LLine return add_pred(m, n, p1, p2, p3, p4, p5, p6, p7, p8); } + /** + * Creates a predicate from two pairs of points on two lines by selecting the most likely configuration. + * + * @param m the predicate type + * @param n the predicate identifier + * @param m1 the first candidate point on the first line + * @param m2 the second candidate point on the first line + * @param m3 the first candidate point on the second line + * @param m4 the second candidate point on the second line + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @param l4 the fourth line + * @return the constructed predicate object + */ Cond add_as_pred_12(int m, int n, int m1, int m2, int m3, int m4, LLine l1, LLine l2, LLine l3, LLine l4) { // m1,m2 on l1, m3,m4 on l2; find the most likely predicate int p1, p2, p3, p4, p5, p6, p7, p8; @@ -2503,6 +2872,21 @@ else if (m4 == p2) return add_pred(m, n, l1.pt[0], l1.pt[1], l2.pt[0], l2.pt[1], l3.pt[0], l3.pt[1], l4.pt[0], l4.pt[1]); } + /** + * Creates a predicate from two pairs of points on two lines with a different configuration. + * + * @param m the predicate type + * @param n the predicate identifier + * @param m1 the first candidate point on the first line + * @param m2 the second candidate point on the first line + * @param m3 the first candidate point on the third line + * @param m4 the second candidate point on the third line + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @param l4 the fourth line + * @return the constructed predicate object + */ Cond add_as_pred_13(int m, int n, int m1, int m2, int m3, int m4, LLine l1, LLine l2, LLine l3, LLine l4) { // m1,m2 on l1, m3,m4 on l3; find the most likely predicate int p1, p2, p3, p4, p5, p6, p7, p8; @@ -2548,6 +2932,19 @@ else if (m4 == p6) return add_pred(m, n, l1.pt[0], l1.pt[1], l2.pt[0], l2.pt[1], l3.pt[0], l3.pt[1], l4.pt[0], l4.pt[1]); } + /** + * Creates a predicate from a line and additional point parameters. + * + * @param m the predicate type + * @param n the predicate identifier + * @param l1 the line providing initial point information + * @param p1 the first point parameter on the line + * @param p2 the second point parameter on the line + * @param p5 the fifth point parameter + * @param p6 the sixth point parameter + * @param l2 the second line used for deriving further point information + * @return the constructed predicate object + */ Cond add_as_pred1(int m, int n, LLine l1, int p1, int p2, int p5, int p6, LLine l2) { int p3, p4, p7, p8; if (on_ln(p1, l1)) { @@ -2585,6 +2982,19 @@ Cond add_as_pred1(int m, int n, LLine l1, int p1, int p2, int p5, int p6, LLine return add_pred(m, n, p3, p4, p1, p2, p5, p6, p7, p8); } + /** + * Creates a predicate from two lines and additional point parameters. + * + * @param m the predicate type + * @param n the predicate identifier + * @param p1 the first point parameter + * @param p2 the second point parameter + * @param l1 the first line + * @param l2 the second line + * @param p5 the fifth point parameter + * @param p6 the sixth point parameter + * @return the constructed predicate object + */ Cond add_as_pred1(int m, int n, int p1, int p2, LLine l1, LLine l2, int p5, int p6) { int p3, p4, p7, p8; if (on_ln(p1, l1)) { @@ -2621,6 +3031,19 @@ Cond add_as_pred1(int m, int n, int p1, int p2, LLine l1, LLine l2, int p5, int return add_pred(m, n, p1, p2, p3, p4, p7, p8, p5, p6); } + /** + * Creates an angle transformation predicate based on given point parameters and two lines. + * + * @param m the predicate type + * @param n the predicate identifier + * @param p1 the first point parameter + * @param p2 the second point parameter + * @param p3 the third point parameter + * @param p4 the fourth point parameter + * @param l3 the third line + * @param l4 the fourth line + * @return the constructed predicate object + */ Cond add_as_atn(int m, int n, int p1, int p2, int p3, int p4, LLine l3, LLine l4) { int p5, p6, p7, p8; int b = inter_ll(l3, l4); @@ -2650,6 +3073,19 @@ Cond add_as_atn(int m, int n, int p1, int p2, int p3, int p4, LLine l3, LLine l4 return add_pred(m, n, p1, p2, p3, p4, p5, p6, p7, p8); } + /** + * Creates a predicate using point parameters and two lines for congruence segments. + * + * @param m the predicate type + * @param n the predicate identifier + * @param p1 the first point parameter + * @param p2 the second point parameter + * @param l2 the first line + * @param l3 the second line + * @param p7 the seventh point parameter + * @param p8 the eighth point parameter + * @return the constructed predicate object + */ Cond add_as_pred2(int m, int n, int p1, int p2, LLine l2, LLine l3, int p7, int p8) { int p3, p4, p5, p6; if (on_ln(p1, l2)) { @@ -2688,12 +3124,13 @@ Cond add_as_pred2(int m, int n, int p1, int p2, LLine l2, LLine l3, int p7, int return add_pred(m, n, p1, p2, p3, p4, p5, p6, p7, p8); } -///////////////////////////////////////////////////////////////////////////// -//***************************************************************************** -// adding auxiliary points - - //////////////////////////////////////////////////////////////////////////////////////////////////// - + /** + * Checks if the given condition is valid. Validity depends on whether the predicate is CO_ACONG + * and specific point values satisfy the anti-angle criteria. + * + * @param c the condition to be validated + * @return true if the condition is valid; false otherwise + */ public boolean check_tValid(Cond c) { if (isPFull()) return true; if (c.pred != CO_ACONG) return true; @@ -2704,10 +3141,9 @@ public boolean check_tValid(Cond c) { return true; } -/////////////////////////////////////////////////////////////////////////////////////////////////// -///// for backward chaining. - - + /** + * Parses the global node list, processes sublists, and displays the list content using backup and preview mechanisms. + */ public void parse_llist() { LList ns = all_ns.nx; if (ns == null) return; @@ -2751,7 +3187,12 @@ public void parse_llist() { } } - + /** + * Retrieves the next proof head node list from the global node list. + * + * @param ls the current node list + * @return the next node list for proof head, or null if no further node is available + */ LList get_next_ls_prove_head(LList ls) { LList ns = all_ns.nx; if (ns == null) return null; @@ -2771,6 +3212,11 @@ LList get_next_ls_prove_head(LList ls) { return rs; } + /** + * Displays the list preview by printing the node list and all its associated rules. + * + * @param ls the node list to preview + */ void show_lprv(LList ls) { setPrintToString(); @@ -2787,6 +3233,11 @@ void show_lprv(LList ls) { } } + /** + * Searches for angle splitting opportunities within the given node list and adds corresponding split rules. + * + * @param ls the node list to search for angle splits + */ public void search_ag_split(LList ls) { if (ls.nd == 1) return; @@ -2820,6 +3271,11 @@ public void search_ag_split(LList ls) { } } + /** + * Searches the TLine list for applicable transformations and adds corresponding rules to the given node list. + * + * @param ls the node list to process for transformation rules + */ public void search_t_list(LList ls) { TLine tn = all_tn.nx; @@ -2835,6 +3291,11 @@ public void search_t_list(LList ls) { } } + /** + * Searches the node list for predicate rules based on angle properties and anti-point values, adding matching rules. + * + * @param ls the node list to search for predicate rules + */ public void search_p_list(LList ls) { for (int i = 0; i < ls.nd; i++) { Mnde m = ls.md[i]; @@ -2848,6 +3309,15 @@ public void search_p_list(LList ls) { } } + /** + * Searches the node list for transformation matches based on the given lines and intersection value, + * and adds corresponding tag rules. + * + * @param ls the node list to search + * @param l1 the first line for the search criteria + * @param l2 the second line for the search criteria + * @param v the intersection value used for matching + */ public void search_list_tn(LList ls, LLine l1, LLine l2, int v) { if (v != 0) { for (int i = 0; i < ls.nd; i++) { @@ -2870,24 +3340,13 @@ public void search_list_tn(LList ls, LLine l1, LLine l2, int v) { } } - public void search_p_list(Vector v) { - - for (int i = 0; i < v.size(); i++) { - LList ls = (LList) v.get(i); - - } - } - - public void search_list_ln(LList ls) { - for (int i = 0; i < ls.nd; i++) { - AngTr t = ls.md[i].tr; - if (t.v == ls.pt) { - - } - - } - } - + /** + * Creates and returns a tag rule for an angle based on the intersection of two lines. + * + * @param l1 the first line for the rule + * @param l2 the second line for the rule + * @return a tag rule with angle relations configured + */ public Rule add_rule_tag(LLine l1, LLine l2) { Rule r = new Rule(Rule.T_ANGLE); Mnde m = new Mnde(); @@ -2902,6 +3361,15 @@ public Rule add_rule_tag(LLine l1, LLine l2) { return r; } + /** + * Creates and returns a split-angle rule that partitions an angle into sub-angles using the given lines. + * + * @param v the angle value used for splitting + * @param l1 the first line for the transformation + * @param l2 the second line forming the angle vertex + * @param l3 the third line completing the new angle configuration + * @return a split-angle rule containing the constructed transformations + */ public Rule add_rule_spag(int v, LLine l1, LLine l2, LLine l3) { Rule r = new Rule(Rule.SPLIT_ANGLE); Mnde m = new Mnde(); @@ -2920,6 +3388,12 @@ public Rule add_rule_spag(int v, LLine l1, LLine l2, LLine l3) { return r; } + /** + * Creates a P_ANGLE rule using the provided angle transformation. + * + * @param t the angle transformation containing the angle value and associated lines + * @return a new Rule object of type P_ANGLE + */ public Rule add_rule_p_ag(AngTr t) { int v = t.v; @@ -2948,8 +3422,15 @@ public Rule add_rule_p_ag(AngTr t) { return r; } - - + /** + * Creates an EX_ANGLE rule based on three lines forming an angle. + * + * @param v the angle value + * @param l1 the first line + * @param l2 the second line + * @param l3 the third line + * @return a new Rule object of type EX_ANGLE, or null if a valid intersection is not found + */ public Rule add_rule_exag(int v, LLine l1, LLine l2, LLine l3) { Rule r = new Rule(Rule.EX_ANGLE); Mnde m = new Mnde(); @@ -2973,8 +3454,12 @@ public Rule add_rule_exag(int v, LLine l1, LLine l2, LLine l3) { return r; } - private static Rule test_r = new Rule(0); - + /** + * Subtracts matching nodes from the provided node list using the specified rule. + * + * @param ls the original node list + * @param r the rule to apply for subtracting matching nodes + */ public void list_sub(LList ls, Rule r) { if (r == null) return; @@ -3023,14 +3508,11 @@ public void list_sub(LList ls, Rule r) { } - public boolean equal_md(Mnde m1, Mnde m2) { - if (m1.tr == null && m2.tr == null) { - if (m1.t == m2.t) return true; - return false; - } - return false; - } - + /** + * Retrieves a vector of node lists sorted by their point counts. + * + * @return a Vector containing sorted node lists + */ public Vector getPVector() { Vector v = new Vector(); LList ns = all_ns.nx; @@ -3048,6 +3530,11 @@ public Vector getPVector() { return v; } + /** + * Displays a single node list in a formatted manner. + * + * @param ls the node list to be displayed + */ public void show_llist(LList ls) { for (int i = 0; i < ls.nd; i++) { Mnde m = ls.md[i]; @@ -3075,10 +3562,11 @@ public void show_llist(LList ls) { } -// public void show_rule(rule r) { -// if (r.type == rule.) -// } - + /** + * Displays all node lists contained in the provided vector. + * + * @param v a vector containing node lists to be displayed + */ public void show_llists(Vector v) { for (int i = 0; i < v.size(); i++) { @@ -3087,6 +3575,11 @@ public void show_llists(Vector v) { } } + /** + * Displays the Mnde object either by showing its transformation or its angle value. + * + * @param m the Mnde object to be displayed + */ public void show_mnde(Mnde m) { if (m.tr == null) @@ -3095,28 +3588,11 @@ public void show_mnde(Mnde m) { show_tr(m.tr); } - - void show_bk_list(LList ls) { - - setPrintToString(); - if (ls == null) return; - while (ls != null) { - show_llist(ls); - ls.text = this.getPrintedString(); - show_rule(ls.rl[0]); - - ls = ls.fr; - } - } - - LList fd_nx_list(LList ls) { - if (ls == null) return all_ns.nx; - LList ls1 = all_ns.nx; - while (ls1 != ls) - ls1 = ls1.nx; - return ls1.nx; - } - + /** + * Parses a backup list of node lists, updating rules and transformations as needed. + * + * @param ls the starting node list for the backup parsing process + */ void parse_bk_list(LList ls) { Vector v = new Vector(); while (ls != null) { @@ -3183,7 +3659,13 @@ void parse_bk_list(LList ls) { } } - + /** + * Searches the node list for an angle transformation matching the specified transformation. + * + * @param t the target angle transformation to find + * @param ls the node list to search for a matching transformation + * @return the matching AngTr object if found; otherwise, null + */ public AngTr find_tr_in_ls(AngTr t, LList ls) { for (int i = 0; i < ls.nd; i++) { AngTr t1 = ls.md[i].tr; @@ -3192,6 +3674,11 @@ public AngTr find_tr_in_ls(AngTr t, LList ls) { return null; } + /** + * Displays the provided rule in a formatted manner. + * + * @param r the rule to be displayed + */ void show_rule(Rule r) { if (r == null) return; diff --git a/src/main/java/gprover/GTerm.java b/src/main/java/gprover/GTerm.java index 5f1ac26d..395c2a90 100644 --- a/src/main/java/gprover/GTerm.java +++ b/src/main/java/gprover/GTerm.java @@ -8,6 +8,18 @@ * JGEX supports loading and saving scripts in a simple textual format. * Among the examples, these files have no extension (see, e.g. 3_JAR/simson). * This class can load and save them. + * * Represents geometric constructions and their associated operations. + * * + * *

This class encapsulates the management of points, construction steps, + * * and constraints within a geometric theorem proving framework. + * * It provides methods for adding, retrieving, and processing geometric data, + * * including the generation of non-degenerate and prerequisite constraints. + * * Fundamental operations include loading, saving, and validating the structure + * * of geometric constructions.

+ * * + * *

Utilize this class to perform geometric analyses and manipulations necessary + * * for automated theorem proving and geometric constraint solving within the + * * framework.

*/ public class GTerm { @@ -29,13 +41,18 @@ public class GTerm { private Vector ccons = new Vector(); private Vector ncons = new Vector(); + /** + * Constructs a new GTerm instance. + */ public GTerm() { } - public Vector getCgs() { - return ccons; - } - + /** + * Returns the constraint at the specified index from the constraint vector. + * + * @param n the 0-based index of the constraint to retrieve + * @return the constraint at index n, or null if n is out of range + */ public Cons getCons(int n) { int n1 = gcons.size(); if (n < 0 || n >= n1) @@ -43,6 +60,11 @@ public Cons getCons(int n) { return (Cons) gcons.get(n); } + /** + * Returns a vector containing non degenerate constraints. + * + * @return a vector of CNdg objects representing non degenerate constraints + */ public Vector getNcons() { Vector v = new Vector(); @@ -64,6 +86,12 @@ else if (c.type == Gib.CO_PERP) return v; } + /** + * Generates a string description for the specified CNdg object based on the provided parameters. + * + * @param dg the CNdg object to update with its description + * @param pss the array of parameters used for generating the description + */ public void generateSd(CNdg dg, Object[] pss) { switch (dg.type) { case Gib.NDG_COLL: @@ -82,18 +110,21 @@ public void generateSd(CNdg dg, Object[] pss) { } + /** + * Returns the vector containing all constraints. + * + * @return the vector of constraint objects + */ public Vector getCons() { return gcons; } - public Vector getPureCons() { - Vector v = new Vector(); - int n = gcons.size(); - for (int i = 1; i < n - 1; i++) - v.add(gcons.get(i)); - return v; - } - + /** + * Copies all constraints into the given array, starting at index 1. + * + * @param cn the array in which to store the constraint objects + * @return the number of constraints copied + */ public int setAllcons(Cons[] cn) { for (int i = 0; i < gcons.size(); i++) { Cons c = (Cons) gcons.get(i); @@ -102,6 +133,12 @@ public int setAllcons(Cons[] cn) { return gcons.size(); } + /** + * Copies all points into the given array, starting at index 1. + * + * @param pp the array in which to store the point objects + * @return the number of points copied + */ public int setAllpts(ProPoint[] pp) { for (int i = 0; i < gpoints.size(); i++) { ProPoint p = (ProPoint) gpoints.get(i); @@ -110,10 +147,20 @@ public int setAllpts(ProPoint[] pp) { return gpoints.size(); } + /** + * Returns the number of points in the construction. + * + * @return the number of points + */ public int getPointsNum() { return gpoints.size(); } + /** + * Returns a vector containing the names of all points. + * + * @return a vector of point names + */ public Vector getAllptsText() { Vector v = new Vector(); @@ -124,15 +171,29 @@ public Vector getAllptsText() { return v; } + /** + * Returns the number of constraints (as derived from the points vector). + * + * @return the number of constraints + */ public int getCons_no() { return gpoints.size(); } - + /** + * Returns the current conclusion condition. + * + * @return the Cond object representing the conclusion + */ public Cond getConc() { return conc; } + /** + * Retrieves the conclusion constraint if it exists. + * + * @return the conclusion constraint, or null if none exists + */ public Cons getConclusion() { int s = gcons.size(); if (s == 0) return null; @@ -142,6 +203,12 @@ public Cons getConclusion() { return null; } + /** + * Sets the conclusion constraint and updates the underlying condition. + * + * @param c the conclusion constraint to set + * @return true if the conclusion was set successfully, false otherwise + */ public boolean setConclusion(Cons c) { int s = gcons.size(); @@ -177,15 +244,31 @@ public boolean setConclusion(Cons c) { return true; } + /** + * Returns the name of the construction. + * + * @return the construction name + */ public String getName() { return name; } + /** + * Sets the name for the construction. + * + * @param s the name to set + */ public void setName(String s) { name = s; } - + /** + * Reads an A-term from the provided BufferedReader. + * + * @param in the BufferedReader to read from + * @return true if the term is successfully read; false otherwise + * @throws IOException if an I/O error occurs + */ public boolean readAterm(BufferedReader in) throws IOException { Vector glines = new Vector(); int status = 0; @@ -255,6 +338,13 @@ public boolean readAterm(BufferedReader in) throws IOException { return true; } + /** + * Writes the current A-term to the specified FileOutputStream. + * + * @param out the FileOutputStream to write to + * @return true if the A-term is successfully written; false otherwise + * @throws IOException if an I/O error occurs + */ public boolean writeAterm(FileOutputStream out) throws IOException { String sn = name; if (sn == null || sn.length() == 0) @@ -272,6 +362,13 @@ public boolean writeAterm(FileOutputStream out) throws IOException { return true; } + /** + * Reads an A-term from the given DataInputStream. + * + * @param in the DataInputStream to read from + * @return true if the A-term is successfully read; false otherwise + * @throws IOException if an I/O error occurs + */ public boolean readAterm(DataInputStream in) throws IOException { int n = in.readInt(); Vector glines = new Vector(); @@ -286,6 +383,13 @@ public boolean readAterm(DataInputStream in) throws IOException { return true; } + /** + * Writes the current A-term to the provided DataOutputStream using an alternative format. + * + * @param out the DataOutputStream to write to + * @return true if the A-term is successfully written; false otherwise + * @throws IOException if an I/O error occurs + */ public boolean writeAterm2(DataOutputStream out) throws IOException { int n = gcons.size(); out.writeInt(n + 2); @@ -309,6 +413,12 @@ public boolean writeAterm2(DataOutputStream out) throws IOException { return true; } + /** + * Adds a new point with the specified name if it does not already exist. + * + * @param s the name of the point to add + * @return false if the point already exists, otherwise false after adding the point + */ public boolean add_pt(String s) { for (int i = 0; i < gpoints.size(); i++) { ProPoint p = (ProPoint) gpoints.get(i); @@ -320,6 +430,16 @@ public boolean add_pt(String s) { return false; } + /** + * Sets the location for the point matching the given name. + * + * @param sn the name of the point + * @param x the x-coordinate of the point + * @param y the y-coordinate of the point + * @param x1 the first additional coordinate parameter + * @param y1 the second additional coordinate parameter + * @return true if the point location is successfully set; false otherwise + */ public boolean setPtLoc(String sn, double x, double y, int x1, int y1) { for (int i = 0; i < gpoints.size(); i++) { ProPoint p = (ProPoint) gpoints.get(i); @@ -332,6 +452,13 @@ public boolean setPtLoc(String sn, double x, double y, int x1, int y1) { return false; } + /** + * Reads an A-term from the provided DataInputStream while ignoring header lines. + * + * @param in the DataInputStream to read from + * @return true if the A-term is successfully read; false otherwise + * @throws IOException if an I/O error occurs + */ public boolean readAterm2(DataInputStream in) throws IOException { int n = in.readInt(); Vector glines = new Vector(); @@ -346,7 +473,9 @@ public boolean readAterm2(DataInputStream in) throws IOException { return true; } - + /** + * Clears all stored points, construction steps, and resets the construction name. + */ public void clear() { gpoints.clear(); gcons.clear(); @@ -354,20 +483,22 @@ public void clear() { name = null; } - + /** + * Clears current construction data and sets constraints from the given vector. + * + * @param v the vector containing new constraints + */ public void addConsV(Vector v) { this.clear(); gcons.addAll(v); } - public void setGenerated(boolean r) { - generated = r; - } - - public boolean isGenerated() { - return generated; - } - + /** + * Generates the construction based on the provided vector of input lines. + * + * @param glines the vector containing construction lines + * @return true if the generation is successful; false otherwise + */ public boolean generate(Vector glines) { if (generated) return true; @@ -395,7 +526,12 @@ public boolean generate(Vector glines) { return true; } - + /** + * Generates the positions of points using the stored position string. + * Parses the position string, updates each point's coordinates, and sets the position flag. + * + * @return true if the positions were generated successfully or no positions were provided. + */ boolean generate_position() { String s = posString.trim(); if (s == null || s.length() == 0) { @@ -492,11 +628,21 @@ boolean generate_position() { return true; } - + /** + * Adds an auxiliary point to the construction. + * + * @param pt the point to be added. + */ public void addauxedPoint(ProPoint pt) { gpoints.add(pt); } + /** + * Adds an auxiliary constraint to the construction. + * Inserts the constraint appropriately depending on whether a conclusion exists. + * + * @param c the constraint to be added. + */ public void addauxedCons(Cons c) { int n = gcons.size(); if (n == 0) @@ -508,6 +654,11 @@ public void addauxedCons(Cons c) { } } + /** + * Returns the number of constructions excluding the final conclusion if present. + * + * @return the count of constructions. + */ public int getconsNum() { int n = gcons.size() - 1; if (n <= 0) @@ -518,20 +669,36 @@ public int getconsNum() { return n - 1; } + /** + * Determines if the term is animated based on the animation string. + * + * @return true if the term is animated, false otherwise. + */ public boolean isTermAnimated() { return aniString.startsWith("ANI"); } + /** + * Retrieves the animation string for the term. + * + * @return the animation string. + */ public String getAnimateString() { return aniString; } + /** + * Checks if the positions of points have been set. + * + * @return true if positions are set, false otherwise. + */ public boolean isPositionSet() { return is_position_set; } /** * Add a conclusion to the construction. + * * @param ln A script command in the form "SHOW: COLLINEAR P Q R" * @return if the conclusion was added successfully */ @@ -607,6 +774,13 @@ boolean addConclusion(String ln) { return true; } + /** + * Adds a construction condition parsed from the provided script line. + * Handles various types of conditions including point definitions and constraints. + * + * @param ln the script line representing the condition. + * @return true if the condition was added successfully, false otherwise. + */ boolean addCondition(String ln) { String st = ln.trim().substring(0, 4); if (st.equalsIgnoreCase("show")) { @@ -659,6 +833,12 @@ boolean addCondition(String ln) { return true; } + /** + * Retrieves the predicate type corresponding to the provided string. + * + * @param sh the string representing the predicate. + * @return the integer value corresponding to the predicate type. + */ private int getPred(String sh) { int t = CST.get_pred(sh); if (t == 0) @@ -666,9 +846,13 @@ private int getPred(String sh) { return t; } - public void addSquare(String[] list) { - } + /** + * Processes an inter-line constraint. + * Adds a circumcenter point if required before creating the constraint. + * + * @param list the array of parameters representing the constraint. + */ public void addInterLS(String[] list) { if (list.length != 7) { return; @@ -685,6 +869,13 @@ public void addInterLS(String[] list) { this.addCd(Gib.C_I_LS, list); } + + /** + * Processes an inter-segment constraint. + * Adds circumcenter points if needed before creating the constraint. + * + * @param list the array of parameters representing the constraint. + */ public void addInterSS(String[] list) { if (list.length != 8) { return; @@ -709,21 +900,14 @@ public void addInterSS(String[] list) { this.addCd(Gib.C_I_SS, list); } - public void addRatio(int type, String[] list) { - - try { - ProPoint pt = this.addPt(list[1]); - pt.setType(type); - int i = 0; - for (i = 1; i < list.length - 1; i++) - pt.setPS(findPt(list[i]), i - 1); - pt.setPS(Integer.parseInt(list[i]), i - 1); - } catch (NumberFormatException ee) { - Cm.print(ee.getMessage()); - } - - } + /** + * Adds a constant to the construction. + * Creates a new constant constraint using the provided identifier and function. + * + * @param sf the identifier for the constant. + * @param func the function defining the constant. + */ public void addConstant(String sf, String func) { Cons c = new Cons(Gib.C_CONSTANT); @@ -771,6 +955,12 @@ public void addConstant(String sf, String func) { } + /** + * Adds a point to the list and updates the initial point construction if needed. + * + * @param pt the point to be added. + * @return the new total count of points. + */ int addPtToList(ProPoint pt) { gpoints.add(pt); @@ -781,32 +971,11 @@ int addPtToList(ProPoint pt) { return gpoints.size(); } - void addCircle(String[] list) { - for (int i = 1; i <= 3; i++) { - ProPoint pt = new ProPoint(); - pt.name = list[i]; - pt.type = Gib.C_POINT; - addPtToList(pt); - } - - ProPoint pt = new ProPoint(); - pt.name = get_cir_center_name(); - pt.type = Gib.C_CIRCUM; - pt.ps[0] = this.findPt(list[1]); - pt.ps[1] = this.findPt(list[2]); - pt.ps[2] = this.findPt(list[3]); - int o = addPtToList(pt); - - for (int i = 4, j = 0; i < list.length; i++, j++) { - ProPoint pt1 = new ProPoint(); - pt1.name = list[i]; - pt1.type = Gib.C_O_C; - pt1.ps[0] = this.findPt(pt.name); - pt1.ps[1] = this.findPt(list[1]); - addPtToList(pt1); - } - } - + /** + * Generates a unique name for a circle center that does not conflict with existing points. + * + * @return the generated circle center name. + */ String get_cir_center_name() { int i = 1; while (true) { @@ -826,6 +995,12 @@ String get_cir_center_name() { } } + /** + * Retrieves a point based on its 1-based index. + * + * @param x the 1-based index of the point. + * @return the corresponding ProPoint, or null if the index is out of bounds. + */ public ProPoint getProPoint(int x) { if (x <= 0 || x > gpoints.size()) { return null; @@ -833,6 +1008,12 @@ public ProPoint getProPoint(int x) { return ((ProPoint) gpoints.get(x - 1)); } + /** + * Retrieves a construction constraint based on its 1-based index. + * + * @param x the 1-based index of the constraint. + * @return the corresponding Cons object, or null if the index is out of bounds. + */ public Cons getPcons(int x) { if (x <= 0 || x > gcons.size()) { return null; @@ -841,6 +1022,12 @@ public Cons getPcons(int x) { } + /** + * Retrieves the name of a point based on its 1-based index. + * + * @param x the 1-based index of the point. + * @return the point name, or an empty string if the index is invalid. + */ public String getPtName(int x) { if (x <= 0 || x > gpoints.size()) { return ""; @@ -848,7 +1035,9 @@ public String getPtName(int x) { return ((ProPoint) gpoints.get(x - 1)).name; } - + /** + * Recalculates and updates constraint point indexes and conclusion values. + */ public void ge_cpt() { for (int i = 0; i < gcons.size(); i++) { Cons c = (Cons) gcons.get(i); @@ -908,6 +1097,14 @@ else if (this.isStringTypeInt(s)) { } + /** + * Finds the center point index based on three given point names. + * + * @param a the first point name + * @param b the second point name + * @param c the third point name + * @return the index of the center point if found; 0 otherwise + */ int findCenter(String a, String b, String c) { if (a == null || b == null || c == null) { return 0; @@ -934,6 +1131,12 @@ int findCenter(String a, String b, String c) { return 0; } + /** + * Finds the index of the point that matches the specified name. + * + * @param sn the name of the point to search for + * @return the index of the point if found; 0 otherwise + */ int findPt(String sn) { for (int j = 0; j < gpoints.size(); j++) { ProPoint p = (ProPoint) gpoints.get(j); @@ -944,6 +1147,12 @@ int findPt(String sn) { return 0; } + /** + * Adds a new point with the specified name if it does not exist. + * + * @param sn the name of the point to add + * @return the added or existing ProPoint instance + */ ProPoint addPt(String sn) { ProPoint pt; if ((pt = fd_pt(sn)) == null) { @@ -955,6 +1164,12 @@ ProPoint addPt(String sn) { return pt; } + /** + * Retrieves a point with the specified name from the list. + * + * @param sn the name of the point to retrieve + * @return the ProPoint if found; null otherwise + */ protected ProPoint fd_pt(String sn) { for (int i = 0; i < gpoints.size(); i++) { ProPoint pt = (ProPoint) gpoints.get(i); @@ -965,6 +1180,12 @@ protected ProPoint fd_pt(String sn) { return null; } + /** + * Determines whether the provided string represents a valid integer. + * + * @param s the string to check + * @return true if the string is a valid integer representation; false otherwise + */ boolean isStringTypeInt(String s) { if (s == null || s.length() == 0) return false; int i = 0; @@ -977,6 +1198,13 @@ boolean isStringTypeInt(String s) { return true; } + /** + * Creates and adds a constant constraint using the specified type and parameters. + * + * @param type the constraint type + * @param list the array of parameters + * @return the created constant constraint + */ Cons addCd(int type, String[] list) { Cons c = getCd(type, list); if (c != null) @@ -984,6 +1212,11 @@ Cons addCd(int type, String[] list) { return c; } + /** + * Converts the string parameters of the given constraint to point indexes. + * + * @param c the constraint to process + */ public void ge_pss2ps(Cons c) { int i = 0; while (true) { @@ -996,12 +1229,24 @@ public void ge_pss2ps(Cons c) { } + /** + * Updates and adds a non-degenerate constraint if it is not already present. + * + * @param c the constraint to add + */ public void addNdg(Cons c) { ge_pss2ps(c); if (!ncons.contains(c)) ncons.add(c); } + /** + * Creates and adds a non-degenerate constraint from the provided type and parameters. + * + * @param type the constraint type + * @param list the array of parameters + * @return the created non-degenerate constraint + */ Cons addNdg(int type, String[] list) { Cons c = getCd(type, list); if (c != null) @@ -1009,6 +1254,13 @@ Cons addNdg(int type, String[] list) { return c; } + /** + * Creates a constraint based on the provided type and parameter list. + * + * @param type the constraint type + * @param list the array of parameters + * @return the created constraint + */ Cons getCd(int type, String[] list) { int len = list.length; if (len <= 1) @@ -1049,15 +1301,23 @@ Cons getCd(int type, String[] list) { return c; } + /** + * Saves data to the given output stream. + * + * @param out the DataOutputStream to write to + * @return true if the save operation is successful + * @throws IOException if an I/O error occurs + */ boolean Save(DataOutputStream out) throws IOException { out.writeChars("\n"); return true; } - public String NAME(int i) { - return this.getPtName(i); - } - + /** + * Retrieves the text representation of the current conclusion. + * + * @return the conclusion text, or "NO" if no conclusion is set + */ public String getConcText() { Cons c = this.getConclusion(); if (c == null) @@ -1065,10 +1325,18 @@ public String getConcText() { return CST.getDString(c.pss, c.type); } + /** + * Sets the conclusion number. + */ public void setConclusionNo() { } + /** + * Checks if a valid conclusion exists in the construction. + * + * @return true if the last condition type is within the valid range (>= 50 and < 100); false otherwise. + */ public boolean hasConclusion() { int n = gcons.size(); if (n == 0) @@ -1078,6 +1346,12 @@ public boolean hasConclusion() { } + /** + * Determines whether the point identified by the given index is free. + * + * @param n the 1-based index of the point to check. + * @return true if the point is not used as the last element in any constraint; false otherwise. + */ public boolean isFreePoint(int n) { for (int i = 0; i < gcons.size(); i++) { Cons c = (Cons) gcons.get(i); @@ -1092,6 +1366,11 @@ public boolean isFreePoint(int n) { // return false; } + /** + * Returns a string representation of the construction. + * + * @return the name of the construction if available; otherwise, the default string representation. + */ public String toString() { if (name != null) { return name; @@ -1100,11 +1379,11 @@ public String toString() { } } - /** - * **************pc****************** + * Processes and returns a vector of processed constraints. + * + * @return a vector containing the processed constraints. */ - public Vector pc() { Vector vlist = new Vector(); Vector v = new Vector(); @@ -1179,13 +1458,9 @@ else if (c.is_conc()) return vlist; } - private void showNCMessage(Cons c1, Cons c2) { - String s1 = c1.toDString(); - if (c2 != null) - s1 += "\n" + c2.toDString(); - JOptionPane.showMessageDialog(null, "NOT CONSTRUCTIVE\n" + s1); - } - + /** + * Aggregates and computes all circle constraints from the current constraint data. + */ public void getAllCircles() { Vector v = ccons; @@ -1202,8 +1477,7 @@ public void getAllCircles() { addccc(c2.ps[2], c2.ps[3], c1); v.remove(j); r = true; - } else - if (c1.ps[k * 2] == c2.ps[2] && c1.ps[k * 2 + 1] == c2.ps[3] || c1.ps[k * 2] == c2.ps[3] && c1.ps[k * 2 + 1] == c2.ps[2]) { + } else if (c1.ps[k * 2] == c2.ps[2] && c1.ps[k * 2 + 1] == c2.ps[3] || c1.ps[k * 2] == c2.ps[3] && c1.ps[k * 2 + 1] == c2.ps[2]) { addccc(c2.ps[0], c2.ps[1], c1); v.remove(j); r = true; @@ -1249,6 +1523,14 @@ else if (c.ps[k * 2 + 1] == c.ps[j]) } } + /** + * Adds a circle constraint between the two specified points to the provided constraint, + * if the connection does not already exist. + * + * @param a the first point index. + * @param b the second point index. + * @param cs the constraint to which the circle condition is added. + */ public void addccc(int a, int b, Cons cs) { int n = (cs.no + 1) / 2; for (int i = 0; i < n; i++) { @@ -1260,6 +1542,12 @@ public void addccc(int a, int b, Cons cs) { cs.no += 2; } + /** + * Adds prerequisite equality constraints based on the given type and associated points. + * + * @param t the constraint type. + * @param p an array of point indices representing the constraint. + */ public void add_preq(int t, int[] p) { switch (t) { case Gib.C_O_C: @@ -1329,6 +1617,14 @@ public void add_preq(int t, int[] p) { } } + /** + * Adds an equality constraint equating the distances between the two pairs of points. + * + * @param a the first point index of the first pair. + * @param b the second point index of the first pair. + * @param c the first point index of the second pair. + * @param d the second point index of the second pair. + */ public void add_eqcons(int a, int b, int c, int d) { Cons cs = new Cons(Gib.C_EQDISTANCE, 100); cs.add_pt(a); @@ -1338,7 +1634,13 @@ public void add_eqcons(int a, int b, int c, int d) { ccons.add(cs); } - + /** + * Retrieves and removes the first constraint in the vector that contains the specified point. + * + * @param pt the point identifier to search for in the constraints. + * @param v the vector of constraints to search through. + * @return the constraint that contains the point, or null if no such constraint exists. + */ public Cons getcons(int pt, Vector v) { for (int i = 0; i < v.size(); i++) { Cons c = (Cons) v.get(i); @@ -1350,6 +1652,12 @@ public Cons getcons(int pt, Vector v) { return null; } + /** + * Generates all non-degenerate constraints from the given vector. + * + * @param v the vector of constraints from which to generate non-degenerate constraints. + * @return a vector containing all non-degenerate constraints. + */ public Vector getAllNdgs(Vector v) { Vector v1 = new Vector(); @@ -1360,6 +1668,12 @@ public Vector getAllNdgs(Vector v) { return v1; } + /** + * Generates non-degenerate constraints based on the specified constraint and adds them to the provided vector. + * + * @param c the original constraint used as a basis for generating non-degenerate constraints. + * @param v the vector to which the generated constraints will be added. + */ public void generateCons(Cons c, Vector v) { switch (c.type) { @@ -1501,9 +1815,7 @@ public void generateCons(Cons c, Vector v) { case Gib.C_TRAPEZOID: case Gib.C_R_TRAPEZOID: case Gib.C_LOZENGE: - case Gib.C_RECTANGLE: - - { + case Gib.C_RECTANGLE: { Cons c1 = this.getNDG_COLL(c.ps[0], c.ps[1], c.ps[2], c.pss[0], c.pss[1], c.pss[2]); addNDG(c1, v); break; @@ -1526,14 +1838,19 @@ public void generateCons(Cons c, Vector v) { } } - public Cons getNDG_AA(Cons c) { - if (c.type != Gib.C_I_AA) - return null; - return null; - - } - - + /** + * Creates a non-degenerate parallel constraint from the provided points and associated objects. + * + * @param t1 the first point identifier. + * @param t2 the second point identifier. + * @param t3 the third point identifier. + * @param t4 the fourth point identifier. + * @param o1 the first associated object. + * @param o2 the second associated object. + * @param o3 the third associated object. + * @param o4 the fourth associated object. + * @return a Cons object representing the non-degenerate parallel constraint, or null if conditions are not met. + */ public Cons getNDG_PARA(int t1, int t2, int t3, int t4, Object o1, Object o2, Object o3, Object o4) { if (t1 > t2) { int t = t1; @@ -1586,6 +1903,19 @@ public Cons getNDG_PARA(int t1, int t2, int t3, int t4, Object o1, Object o2, Ob } + /** + * Creates a non-degenerate perpendicular constraint based on the provided points and associated objects. + * + * @param t1 the first point identifier. + * @param t2 the second point identifier. + * @param t3 the third point identifier. + * @param t4 the fourth point identifier. + * @param o1 the first associated object. + * @param o2 the second associated object. + * @param o3 the third associated object. + * @param o4 the fourth associated object. + * @return a Cons object representing the non-degenerate perpendicular constraint. + */ public Cons getNDG_PERP(int t1, int t2, int t3, int t4, Object o1, Object o2, Object o3, Object o4) { if (t1 > t2) { int t = t1; @@ -1633,6 +1963,17 @@ public Cons getNDG_PERP(int t1, int t2, int t3, int t4, Object o1, Object o2, Ob return c1; } + /** + * Creates a non-degenerate collinearity constraint from the given point identifiers and associated objects. + * + * @param t1 the first point identifier. + * @param t2 the second point identifier. + * @param t3 the third point identifier. + * @param o1 the first associated object. + * @param o2 the second associated object. + * @param o3 the third associated object. + * @return a Cons object representing the non-degenerate collinearity constraint, or null if any two points are equal. + */ public Cons getNDG_COLL(int t1, int t2, int t3, Object o1, Object o2, Object o3) { if (t1 == t2 || t1 == t3 || t2 == t3) return null; Cons c1 = new Cons(Gib.NDG_COLL); @@ -1672,6 +2013,15 @@ public Cons getNDG_COLL(int t1, int t2, int t3, Object o1, Object o2, Object o3) } + /** + * Creates a non-degenerate non-isotropic constraint from two point identifiers and their associated objects. + * + * @param t1 the first point identifier. + * @param t2 the second point identifier. + * @param o1 the first associated object. + * @param o2 the second associated object. + * @return a Cons object representing the non-degenerate non-isotropic constraint. + */ public Cons getNDG_NON_ISOTROPIC(int t1, int t2, Object o1, Object o2) { Cons c1 = new Cons(Gib.NDG_NON_ISOTROPIC); if (t1 > t2) { @@ -1690,6 +2040,15 @@ public Cons getNDG_NON_ISOTROPIC(int t1, int t2, Object o1, Object o2) { return c1; } + /** + * Creates a non-degenerate inequality constraint based on two point identifiers and associated objects. + * + * @param t1 the first point identifier. + * @param t2 the second point identifier. + * @param o1 the first associated object. + * @param o2 the second associated object. + * @return a Cons object representing the non-degenerate inequality constraint. + */ public Cons getNDG_NEQ(int t1, int t2, Object o1, Object o2) { if (t1 > t2) { int t = t1; @@ -1707,6 +2066,13 @@ public Cons getNDG_NEQ(int t1, int t2, Object o1, Object o2) { return c1; } + /** + * Adds a non-degenerate constraint to the specified vector. + * If a similar constraint exists, it avoids duplication or replaces the existing one. + * + * @param c the non-degenerate constraint to add. + * @param v the vector in which the constraint is to be added. + */ public void addNDG(Cons c, Vector v) { if (c == null) return; @@ -1722,6 +2088,13 @@ public void addNDG(Cons c, Vector v) { v.add(c); } + /** + * Checks if the first non-degenerate constraint is considered contained within the second. + * + * @param c the constraint to check for containment. + * @param c1 the constraint that may contain the first. + * @return true if the first constraint is contained within the second, false otherwise. + */ public boolean NDG_Contains(Cons c, Cons c1) // c < c1 { diff --git a/src/main/java/gprover/Gib.java b/src/main/java/gprover/Gib.java index bb5fef85..b6d0ef28 100644 --- a/src/main/java/gprover/Gib.java +++ b/src/main/java/gprover/Gib.java @@ -6,6 +6,15 @@ import java.util.Vector; +/** + * The Gib class provides functionality for geometric computations, + * including operations on angles, lines, circles, triangles, and other + * geometric constructions. + * + *

This class is a central component within the geometric prover system, + * facilitating the creation, manipulation, and evaluation of various geometric + * entities and their relationships.

+ */ public class Gib { //********************pred types************************* @@ -339,12 +348,8 @@ public class Gib { protected Cond conc = new Cond(); protected int cons_no = 0; - //***************************end of inputs****************** - protected final static int PFULL = 0; - protected final static int PTRADITION = 1; - //*****************************othres*********************** final protected static ACir test_c = new ACir(); final protected static LLine test_ln = new LLine(); @@ -366,8 +371,10 @@ public class Gib { protected StringBuffer sout = null; protected boolean DEBUG = true; - //*****************************end of othres*********************** - + /** + * Initializes the rule configuration. + * Sets all rules to true and then disables specific rules. + */ public static void initRules() { for (int i = 0; i < RValue.length; i++) RValue[i] = true; @@ -382,6 +389,10 @@ public static void initRules() { } + /** + * Constructs a new Gib instance. + * Initializes all internal data structures and sets default values. + */ public Gib() { co_db = new Cond(); @@ -418,6 +429,10 @@ public Gib() { gt = null; } + /** + * Initializes the database. + * Resets various lists, counters, and clears auxiliary collections. + */ public void init_dbase() { depth = 0; @@ -493,38 +508,44 @@ public void init_dbase() { tm_pr1 = new Cond(); } + /** + * Validates the provided index. + * + * @param i the index to check + * @return true if the index is within valid bounds; false otherwise + */ boolean valid(int i) { if (i == 0 || i > 100) return true; if (i < 0 || i >= RValue.length) return false; return RValue[i - 1]; } - Cond add_e_codb(int n, int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8) { - Cond co = new Cond(); - - co.pred = n; - co.no = 0; - co.u.ln = null; - co.p[0] = p1; - co.p[1] = p2; - co.p[2] = p3; - co.p[3] = p4; - co.p[4] = p5; - co.p[5] = p6; - co.p[6] = p7; - co.p[7] = p8; - co.cd = co_db.nx; - return co; - } - + /** + * Retrieves the x-coordinate of the point at the specified index. + * + * @param p the index of the point in the array + * @return the x-coordinate of the point + */ final double VPTX(int p) { return allpts[p].x; } + /** + * Retrieves the y-coordinate of the point at the specified index. + * + * @param p the index of the point in the array + * @return the y-coordinate of the point + */ final double VPTY(int p) { return allpts[p].y; } + /** + * Retrieves the name of the point at the specified index. + * + * @param p the index of the point in the array + * @return the name of the point, or null if the index is negative + */ final String ANAME(int p) { if (p < 0) return null; @@ -539,6 +560,12 @@ final String ANAME(int p) { return null; } + /** + * Searches for a point by its name. + * + * @param s the name to search for + * @return the index of the point if found; otherwise, 0 + */ final int SPT(String s) { if (s == null || s.length() == 0) return 0; @@ -549,28 +576,11 @@ final int SPT(String s) { return 0; } -// final double get_ptx(int i) { -// Pro_point pt = allpts[i]; -// if (pt != null) -// return pt.x; -// else { -// //####### -// //Cm.print(i + " error"); -// return 0.0; -// } -// } -// -// final double get_pty(int i) { -// Pro_point pt = allpts[i]; -// if (pt != null) -// return pt.y; -// else { -// //####### -// //Cm.print(i + " error"); -// return 0.0; -// } -// } - + /** + * Counts the number of defined properties among various entities. + * + * @return the total count of properties + */ final int getNumberofProperties() { int n = 0; MidPt md = all_md.nx; @@ -667,6 +677,12 @@ final int getNumberofProperties() { return n; } + /** + * Retrieves the point at the specified index. + * + * @param i the index of the point in the array + * @return the ProPoint at the specified index + */ final ProPoint APT(int i) { ProPoint pt = allpts[i]; if (pt == null) { @@ -675,22 +691,33 @@ final ProPoint APT(int i) { return pt; } - final int ATYPE(int p, int t) { - return (allpts)[p].type = t; - } - + /** + * Returns the type of the point at the given index. + * + * @param t the index of the point in the array + * @return the type of the point + */ final int ATYPE(int t) { return (allpts)[t].type; } - final int AUX(int p, int t) { - return (allpts)[p].aux = t; - } - + /** + * Retrieves an auxiliary point index from the given point. + * + * @param p the index of the point in the array + * @param i the auxiliary index within the point + * @return the auxiliary point index + */ final int APTS(int p, int i) { return ((allpts)[p].ps[i]); } + /** + * Returns the x-coordinate of the point at the given index. + * + * @param p the index of the point in the allpts array + * @return the x-coordinate of the point, or 0.0 if the point is null + */ final double aptx(int p) { if (allpts[p] != null) return allpts[p].x; @@ -700,6 +727,12 @@ final double aptx(int p) { } } + /** + * Returns the y-coordinate of the point at the given index. + * + * @param p the index of the point in the allpts array + * @return the y-coordinate of the point, or 0.0 if the point is null + */ final double apty(int p) { if (allpts[p] != null) return allpts[p].y; @@ -709,24 +742,35 @@ final double apty(int p) { } } + /** + * Checks if the specified index corresponds to a conclusion. + * + * @param n the index in the allcns array + * @return true if the conclusion exists and is valid; false otherwise + */ final boolean isConclusion(int n) { if (allcns[n] != null) return allcns[n].is_conc(); return false; } - final XTerm P1(int p) { - return null; - } - - final XTerm P2(int p) { - return null; - } - + /** + * Finds the point index by its name. + * + * @param s the name of the point + * @return the index of the point if found; 0 otherwise + */ public int fd_pt(String s) { return SPT(s); } + /** + * Finds a point by its coordinates. + * + * @param x the x-coordinate to match + * @param y the y-coordinate to match + * @return the point if one exists within tolerance; null otherwise + */ public ProPoint fd_pt(double x, double y) { double m, n; for (int i = 1; i <= pts_no; i++) { @@ -738,24 +782,35 @@ public ProPoint fd_pt(double x, double y) { return null; } + /** + * Sets the print mode to output to a string buffer. + */ void setPrintToString() { printype = 1; sout = new StringBuffer();//""; } - void setPrintToScreen() { - printype = 0; - sout = new StringBuffer();//""; - } - + /** + * Disables printing output. + */ public void setNoPrint() { printype = -1; } + /** + * Returns the string buffer containing the file proof. + * + * @return the string buffer with the proof content + */ StringBuffer getFileProve() { return sout; } + /** + * Retrieves and resets the printed output string. + * + * @return the printed output as a string + */ String getPrintedString() { if (sout == null) return ""; String s = sout.toString(); @@ -763,11 +818,21 @@ String getPrintedString() { return s; } + /** + * Prints an error message if debugging is enabled. + * + * @param s the error message to print + */ void eprint(String s) { if (Cm.DEBUG) System.out.println(s); } + /** + * Prints a general message based on the current print type. + * + * @param s the message to print + */ void gprint(String s) { if (printype == 0) { if (Cm.DEBUG) @@ -778,31 +843,50 @@ void gprint(String s) { } } + /** + * Prints a debug message if debugging is enabled. + * + * @param s the debug message to print + */ void debug_print(String s) { if (DEBUG) Cm.print(s); } + /** + * Checks if the proof status is full. + * + * @return true if the proof status is full; false otherwise + */ public boolean isPFull() { return P_STATUS == 0; } - public boolean isPTra() { - return P_STATUS == 1; - } - + /** + * Exits the application with the specified error id. + * + * @param id the error id for the exit process + */ public void gexit(int id) { gprint("exit " + id); Cm.print("Error, exit " + id); } - void gdb_help() { - } - + /** + * Displays the parallel line information. + * + * @param pn the PLine object representing parallel lines + */ void show_pn(PLine pn) { gprint(pn_string(pn)); } + /** + * Returns a formatted string representing the parallel lines in a PLine. + * + * @param pn the PLine object containing lines to be formatted + * @return the formatted string of parallel lines + */ String pn_string(PLine pn) { String s = ""; for (int i = 0; i <= pn.no; i++) { @@ -813,10 +897,23 @@ String pn_string(PLine pn) { return s; } + /** + * Displays the string representation of the given line. + * + * @param ln the LLine object to display + * @param nk flag indicating whether to translate as collinear + */ void show_ln(LLine ln, boolean nk) { gprint(ln_string(ln, nk)); } + /** + * Returns a formatted string representing the line. + * + * @param ln the LLine object to convert to string + * @param nk flag indicating whether to use collinearity translation + * @return the formatted string of the line + */ String ln_string(LLine ln, boolean nk) { int i; if (ln == null) @@ -832,6 +929,12 @@ String ln_string(LLine ln, boolean nk) { } } + /** + * Returns a formatted string representing the perpendicular relationship of a TLine. + * + * @param tn the TLine object to convert to string + * @return the formatted string indicating perpendicularity + */ String tn_string(TLine tn) { LLine l1, l2; @@ -844,10 +947,20 @@ String tn_string(TLine tn) { return s; } + /** + * Displays the formatted string for the given TLine. + * + * @param tn the TLine object representing perpendicular lines + */ void show_tn(TLine tn) { gprint(tn_string(tn)); } + /** + * Displays the angle represented by an AngTn object as a combination of two angle components. + * + * @param atn the AngTn object containing two sets of line pairs forming an angle + */ void show_atn(AngTn atn) { show_agll(atn.ln1, atn.ln2); gprint(" + "); @@ -855,6 +968,11 @@ void show_atn(AngTn atn) { gprint(" = 90"); } + /** + * Displays the segments contained in a CSegs object. + * + * @param cg the CSegs object holding congruent segments + */ void show_cseg(CSegs cg) { if (cg.no < 0) { gprint("NULL"); @@ -867,6 +985,11 @@ void show_cseg(CSegs cg) { } } + /** + * Displays the congruent segment information for the given CongSeg object. + * + * @param cg the CongSeg object containing congruence data + */ void show_cg(CongSeg cg) { if (cg == null) { Cm.print("cong_seg is null"); @@ -920,10 +1043,27 @@ void show_cg(CongSeg cg) { } } + /** + * Prints the formatted angle string for the angle defined by four points. + * + * @param p1 the first vertex of the angle + * @param p2 the second vertex of the angle + * @param p3 the third vertex of the angle + * @param p4 the fourth vertex of the angle + */ void print_fang(int p1, int p2, int p3, int p4) { gprint(get_fang_str(p1, p2, p3, p4)); } + /** + * Returns a formatted string representing an angle defined by four points. + * + * @param p1 the first vertex of the angle + * @param p2 the second vertex of the angle + * @param p3 the third vertex of the angle + * @param p4 the fourth vertex of the angle + * @return the formatted angle string + */ String get_fang_str(int p1, int p2, int p3, int p4) { int p0; @@ -950,11 +1090,23 @@ String get_fang_str(int p1, int p2, int p3, int p4) { } + /** + * Returns the name of the point identified by its index. + * + * @param p the index of the point + * @return the name of the point, or an empty string if the index is zero + */ final String pt_name(int p) { if (p != 0) return (APT(p).name); else return (""); } + /** + * Displays the angle between two lines by determining their intersection point. + * + * @param ln1 the first LLine object + * @param ln2 the second LLine object + */ final public void show_agll(LLine ln1, LLine ln2) { // overrited. int n = inter_lls(ln1, ln2); if (n == 0) @@ -966,6 +1118,11 @@ final public void show_agll(LLine ln1, LLine ln2) { // overrited. } } + /** + * Displays a formatted representation of an angle expressed by an Angles object. + * + * @param as the Angles object containing the angle representation + */ final void show_as(Angles as) { if (as == null) return; show_agll(as.l1, as.l2); @@ -973,16 +1130,32 @@ final void show_as(Angles as) { show_agll(as.l3, as.l4); } + /** + * Returns a formatted string representing the midpoint relationship. + * + * @param md the MidPt object containing midpoint data + * @return the formatted midpoint string + */ final String md_print(MidPt md) { String st = GExpert.getTranslationViaGettext("{0} is the midpoint of {1}", ANAME(md.m), ANAME(md.a) + ANAME(md.b)); return st; } + /** + * Displays a formatted representation of the midpoint. + * + * @param md the midpoint to be displayed + */ final void show_md(MidPt md) { gprint(md_print(md)); } + /** + * Displays a formatted representation of the ratio segment. + * + * @param ra the ratio segment to be displayed + */ final void show_ra(RatioSeg ra) { if (show_dtype != 0) { gprint("[" + ra.type + "]:"); @@ -993,6 +1166,12 @@ final void show_ra(RatioSeg ra) { gprint(str); } + /** + * Returns a string representation of the circle. + * + * @param cr the circle object + * @return the formatted circle string + */ final String cr_string(ACir cr) { char i; if (cr == null) { @@ -1015,10 +1194,20 @@ final String cr_string(ACir cr) { return GExpert.getTranslationViaGettext("Circle {0}", s); } + /** + * Displays the circle using its string representation. + * + * @param cr the circle object to be displayed + */ final void show_cr(ACir cr) { gprint(cr_string(cr)); } + /** + * Displays a formatted representation of the similar triangle. + * + * @param st the similar triangle to be displayed + */ final void show_ct(SimTri st) { gprint(Cm.s2722); if (show_dtype != 0) { @@ -1030,15 +1219,11 @@ final void show_ct(SimTri st) { gprint(s); } - final void show_st(SimTri st) { - gprint(Cm.s2720); - - String s = "[" + st.dr + "." + - ANAME(st.p1[0]) + ANAME(st.p1[1]) + ANAME(st.p1[2]) + - "." + ANAME(st.p2[0]) + ANAME(st.p2[1]) + ANAME(st.p2[2]) + "] "; - gprint(s); - } - + /** + * Displays a formatted representation of a set of similar triangles. + * + * @param st the set of similar triangles to be displayed + */ final void show_sts(STris st) { String s = ""; int i = 0; @@ -1050,17 +1235,33 @@ final void show_sts(STris st) { gprint(s); } - + /** + * Exits the system with the specified exit status. + * + * @param v the exit status code + */ final public void exit(int v) { Cm.print("System exit: " + v); System.exit(v); } + /** + * Prints an error message and terminates the program. + * + * @param s the error message to display before exiting + */ final public void gerror(String s) { Cm.print("Error: " + s); System.exit(0); } + /** + * Returns a common point between two lines, or 0 if none exists. + * + * @param l1 the first line + * @param l2 the second line + * @return the common point of the two lines, or 0 if there is no intersection + */ final int inter_lls(LLine l1, LLine l2) { int i, j; if (l1 == null || l2 == null) return (0); @@ -1072,6 +1273,13 @@ final int inter_lls(LLine l1, LLine l2) { return (0); } + /** + * Returns the first point from the line that is not equal to the specified point. + * + * @param l1 the line to search + * @param p1 the point to be excluded + * @return the first point in the line that differs from p1, or 0 if none found + */ final int get_lpt1(LLine l1, int p1) { char j; for (j = 0; j <= l1.no; j++) { @@ -1080,6 +1288,14 @@ final int get_lpt1(LLine l1, int p1) { return (0); } + /** + * Returns the first point from the line that is different from both specified points. + * + * @param l1 the line to search + * @param p1 the first point to be excluded + * @param p2 the second point to be excluded + * @return the first point in the line that differs from both p1 and p2, or 0 if none found + */ final int get_lpt2(LLine l1, int p1, int p2) { char j; for (j = 0; j <= l1.no; j++) { @@ -1088,6 +1304,12 @@ final int get_lpt2(LLine l1, int p1, int p2) { return (0); } + /** + * Returns the default condition for the specified geometric class. + * + * @param cc the geometric class object + * @return a default condition associated with the provided class, or null if unsupported + */ final public Cond getDefaultCond(CClass cc) { Cond co = new Cond(); co.pred = 0; @@ -1208,6 +1430,17 @@ final public Cond getDefaultCond(CClass cc) { //show /////////////////////////////////// + /** + * Computes the orientation of two triangles defined by their vertices. + * + * @param p1 the first point of the first triangle + * @param p2 the second point of the first triangle + * @param p3 the third point of the first triangle + * @param p4 the first point of the second triangle + * @param p5 the second point of the second triangle + * @param p6 the third point of the second triangle + * @return 1 if the triangles share the same orientation, -1 otherwise + */ int check_tri_dr(int p1, int p2, int p3, int p4, int p5, int p6) { double r1 = (aptx(p2) - aptx(p1)) * (apty(p3) - apty(p1)) - (aptx(p3) - aptx(p1)) * (apty(p2) - apty(p1)); @@ -1221,34 +1454,91 @@ int check_tri_dr(int p1, int p2, int p3, int p4, int p5, int p6) { return -1; } + /** + * Disables further checking and logs a check error. + */ final void add_checkError() { ck_value = false; gprint("On Check Error!"); } + /** + * Determines whether the three given points are collinear. + * + * @param p1 index of the first point + * @param p2 index of the second point + * @param p3 index of the third point + * @return true if the points are collinear; false otherwise + */ final boolean check_coll(int p1, int p2, int p3) { return Math.abs((apty(p2) - apty(p1)) * (aptx(p3) - aptx(p1)) - (aptx(p2) - aptx(p1)) * (apty(p3) - apty(p1))) < ZERO; } + /** + * Determines whether the four given points are collinear by checking if both + * the third and fourth points lie on the line through the first two points. + * + * @param p1 index of the first point + * @param p2 index of the second point + * @param p3 index of the third point + * @param p4 index of the fourth point + * @return true if all points are collinear; false otherwise + */ final boolean check_coll(int p1, int p2, int p3, int p4) { return check_coll(p1, p2, p3) && check_coll(p1, p2, p4); } + /** + * Checks whether two lines are parallel. + * + * @param l1 the first line + * @param l2 the second line + * @return true if the lines are parallel; false otherwise + */ final boolean check_para(LLine l1, LLine l2) { return check_para(l1.pt[0], l1.pt[1], l2.pt[0], l2.pt[1]); } + /** + * Checks whether two segments defined by their endpoints are parallel. + * + * @param p1 index of the first point of the first segment + * @param p2 index of the second point of the first segment + * @param p3 index of the first point of the second segment + * @param p4 index of the second point of the second segment + * @return true if the segments are parallel; false otherwise + */ final boolean check_para(int p1, int p2, int p3, int p4) { return Math.abs((apty(p2) - apty(p1)) * (aptx(p4) - aptx(p3)) - (aptx(p2) - aptx(p1)) * (apty(p4) - apty(p3))) < ZERO; } + /** + * Determines whether two segments defined by their endpoints are perpendicular. + * + * @param p1 index of the first point of the first segment + * @param p2 index of the second point of the first segment + * @param p3 index of the first point of the second segment + * @param p4 index of the second point of the second segment + * @return true if the segments are perpendicular; false otherwise + */ final boolean check_perp(int p1, int p2, int p3, int p4) { return Math.abs((apty(p2) - apty(p1)) * (apty(p4) - apty(p3)) + (aptx(p4) - aptx(p3)) * (aptx(p2) - aptx(p1))) < ZERO; } + /** + * Checks if the angles formed by points (p1, p2, p3) and (p4, p5, p6) are equal. + * + * @param p1 index of the vertex for the first angle + * @param p2 index of the first arm point for the first angle + * @param p3 index of the second arm point for the first angle + * @param p4 index of the vertex for the second angle + * @param p5 index of the first arm point for the second angle + * @param p6 index of the second arm point for the second angle + * @return true if the two angles are equal within a tolerance; false otherwise + */ protected boolean check_eqangle(int p1, int p2, int p3, int p4, int p5, int p6) { if (p1 == 0 || p2 == 0 || p3 == 0 || p4 == 0 || p5 == 0 || p6 == 0) { Cm.print("null point in eqangle"); @@ -1257,11 +1547,35 @@ protected boolean check_eqangle(int p1, int p2, int p3, int p4, int p5, int p6) return Math.abs(getAngleValue(p1, p2, p2, p3) - getAngleValue(p4, p5, p5, p6)) < ZERO; } + /** + * Checks whether the sum of the two angles defined by the given points equals 90°. + * + * @param p1 index of the vertex for the first angle + * @param p2 index of an arm point for the first angle + * @param p3 index of the other arm point for the first angle + * @param p4 index of the vertex for the second angle + * @param p5 index of an arm point for the second angle + * @param p6 index of the other arm point for the second angle + * @return true if the sum of angles is 90° (within tolerance); false otherwise + */ protected boolean check_atn(int p1, int p2, int p3, int p4, int p5, int p6) { double r = getAngleValue(p1, p2, p3) + getAngleValue(p4, p5, p6); return Math.abs(r - Math.PI / 2) < ZERO || Math.abs(r + Math.PI / 2) < ZERO; } + /** + * Checks if two angles defined by four points are equal or supplementary. + * + * @param p1 index of the first point of the first angle + * @param p2 index of the second point of the first angle + * @param p3 index of the third point of the first angle + * @param p4 index of the fourth point of the first angle + * @param p5 index of the first point of the second angle + * @param p6 index of the second point of the second angle + * @param p7 index of the third point of the second angle + * @param p8 index of the fourth point of the second angle + * @return true if the angles are equal or supplementary (within tolerance); false otherwise + */ protected boolean check_eqangle(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8) { if (p1 == 0 || p2 == 0 || p3 == 0 || p4 == 0 || p5 == 0 || p6 == 0) { Cm.print("null point in eqangle"); @@ -1273,6 +1587,19 @@ protected boolean check_eqangle(int p1, int p2, int p3, int p4, int p5, int p6, return r < ZERO || Math.abs(r - Math.PI) < ZERO; } + /** + * Checks if two angle values computed via a transformed approach are equal. + * + * @param p1 index of the first point of the first angle + * @param p2 index of the second point of the first angle + * @param p3 index of the third point of the first angle + * @param p4 index of the fourth point of the first angle + * @param p5 index of the first point of the second angle + * @param p6 index of the second point of the second angle + * @param p7 index of the third point of the second angle + * @param p8 index of the fourth point of the second angle + * @return true if the absolute transformed angle values are equal (within tolerance); false otherwise + */ protected boolean check_eqangle_t(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8) { if (p1 == 0 || p2 == 0 || p3 == 0 || p4 == 0 || p5 == 0 || p6 == 0) { Cm.print("Check EQANgle ==0"); @@ -1285,12 +1612,28 @@ protected boolean check_eqangle_t(int p1, int p2, int p3, int p4, int p5, int p6 return r < ZERO; } + /** + * Determines whether the angle formed by three points is a right angle (90°). + * + * @param p1 index of the vertex of the angle + * @param p2 index of the first arm point + * @param p3 index of the second arm point + * @return true if the angle is 90° (within tolerance); false otherwise + */ public boolean check_angle_ls_90(int p1, int p2, int p3) { double r1 = getAngleValue(p1, p2, p3); return Math.abs(Math.abs(r1) - Math.PI / 2) < ZERO; } + /** + * Determines if a point lies strictly between two other points along both axes. + * + * @param p1 index of the point to test + * @param p2 index of the first boundary point + * @param p3 index of the second boundary point + * @return true if p1 is inside the interval defined by p2 and p3; false otherwise + */ protected boolean x_inside(int p1, int p2, int p3) { double r1 = ((aptx(p1) - aptx(p2)) * (aptx(p1) - aptx(p3))); double r2 = ((apty(p1) - apty(p2)) * (apty(p1) - apty(p3))); @@ -1300,6 +1643,17 @@ protected boolean x_inside(int p1, int p2, int p3) { return false; } + /** + * Computes an angle value using transformed points. + * + * The method considers special ordering of the points to compute the appropriate angle. + * + * @param p1 index of the first point + * @param p2 index of the second point + * @param p3 index of the third point + * @param p4 index of the fourth point + * @return the computed angle value + */ protected double getAngleValue_t(int p1, int p2, int p3, int p4) { int p0; if (p1 == p4) { @@ -1324,6 +1678,17 @@ protected double getAngleValue_t(int p1, int p2, int p3, int p4) { return getAngleValue(p1, p2, p3, p4); } + /** + * Checks if the distance between two pairs of points are equal after scaling. + * + * @param p1 index of the first point of the first segment + * @param p2 index of the second point of the first segment + * @param p3 index of the first point of the second segment + * @param p4 index of the second point of the second segment + * @param t1 scaling factor for the first segment + * @param t2 scaling factor for the second segment + * @return true if the scaled distances are equal (within tolerance); false otherwise + */ protected boolean check_eqdistance(int p1, int p2, int p3, int p4, double t1, double t2) { double x1 = aptx(p1); double y1 = apty(p1); @@ -1339,6 +1704,15 @@ protected boolean check_eqdistance(int p1, int p2, int p3, int p4, double t1, do return Math.abs(r) < ZERO; } + /** + * Checks if the distances between two pairs of points are equal. + * + * @param p1 index of the first point of the first segment + * @param p2 index of the second point of the first segment + * @param p3 index of the first point of the second segment + * @param p4 index of the second point of the second segment + * @return true if the distances are equal (within tolerance); false otherwise + */ protected boolean check_eqdistance(int p1, int p2, int p3, int p4) { double x1 = aptx(p1); double y1 = apty(p1); @@ -1352,14 +1726,45 @@ protected boolean check_eqdistance(int p1, int p2, int p3, int p4) { - Math.pow(x4 - x3, 2) - Math.pow(y4 - y3, 2)) < ZERO; } + /** + * Validates whether the ratio of the squared lengths of two segments remain equal. + * + * @param a index of the first point of the first segment + * @param b index of the second point of the first segment + * @param c index of the first point of the second segment + * @param d index of the second point of the second segment + * @param p index of the first point of the third segment + * @param q index of the second point of the third segment + * @param r index of the first point of the fourth segment + * @param s index of the second point of the fourth segment + * @return true if the products of squared lengths are equal (within tolerance); false otherwise + */ protected boolean check_ratio(int a, int b, int c, int d, int p, int q, int r, int s) { return Math.abs(length2(a, b) * length2(r, s) - length2(c, d) * length2(p, q)) < ZERO; } + /** + * Checks if two pairs of points are equal regardless of order. + * + * @param p1 the first point of the first pair + * @param p2 the second point of the first pair + * @param p3 the first point of the second pair + * @param p4 the second point of the second pair + * @return true if the pairs (p1, p2) and (p3, p4) are equal in any order, false otherwise + */ public boolean ck_4peq(int p1, int p2, int p3, int p4) { return p1 == p3 && p2 == p4 || p1 == p4 && p2 == p3; } + /** + * Evaluates directional compatibility between two segments defined by two pairs of points. + * + * @param p1 the first point of the first segment + * @param p2 the second point of the first segment + * @param p3 the first point of the second segment + * @param p4 the second point of the second segment + * @return true if the segments satisfy specific directional conditions, false otherwise + */ public boolean ck_dr(int p1, int p2, int p3, int p4) { double x1 = aptx(p1); double y1 = apty(p1); @@ -1374,6 +1779,13 @@ public boolean ck_dr(int p1, int p2, int p3, int p4) { return (r1 > 0 && r2 > 0) || (r1 == 0 && r2 > 0) || (r1 > 0 && r2 == 0); } + /** + * Calculates the squared Euclidean distance between two points. + * + * @param p1 the first point + * @param p2 the second point + * @return the squared distance between p1 and p2 + */ protected double length2(int p1, int p2) { double x1 = aptx(p1); double y1 = apty(p1); @@ -1382,10 +1794,26 @@ protected double length2(int p1, int p2) { return Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2); } + /** + * Computes the angle value at the middle point defined by three points. + * + * @param p1 the first point + * @param p2 the vertex point where the angle is measured + * @param p3 the third point + * @return the angle value at p2 (in radians) + */ protected double getAngleValue(int p1, int p2, int p3) { return getAngleValue(p1, p2, p3, p2); } + /** + * Determines the angle formed at a common point by two lines. + * + * @param p the intersection point of the lines + * @param l1 the first line + * @param l2 the second line + * @return the angle between l1 and l2 at point p (in radians) + */ protected double getAngleValue(int p, LLine l1, LLine l2) { int a, b; if (p == l1.pt[0]) @@ -1399,6 +1827,15 @@ protected double getAngleValue(int p, LLine l1, LLine l2) { return getAngleValue(a, p, b, p); } + /** + * Checks if the angle formed by three points is approximately equal to a given value. + * + * @param a the first point + * @param b the vertex point where the angle is measured + * @param c the third point + * @param v the target angle value in degrees + * @return true if the measured angle is approximately equal to v, false otherwise + */ protected boolean check_ateq(int a, int b, int c, int v) { double r = getAngleValue(a, b, c); double x = Math.abs(r * A_180 / Math.PI - v); @@ -1409,16 +1846,15 @@ protected boolean check_ateq(int a, int b, int c, int v) { return d; } - protected boolean check_tn_eq(LLine l1, LLine l2, LLine l3, LLine l4, int p1, int p2) { - double r = getAngleValue(p1, l1, l2); - double r1 = getAngleValue(p2, l3, l4); - if (Math.abs(r - r1) < 0.01) return true; - if (Math.abs(Math.abs(r - r1) - Math.PI) < ZERO) - return false; - else - return false; - } - + /** + * Computes the angle difference between the lines defined by two point pairs. + * + * @param p1 the first point of the first line + * @param p2 the second point of the first line + * @param p3 the first point of the second line + * @param p4 the second point of the second line + * @return the difference between the angles (in radians) of the two lines + */ protected double getAngleValue(int p1, int p2, int p3, int p4) { if (p1 == 0 || p2 == 0 || p3 == 0 || p4 == 0) { int k = 0; @@ -1467,6 +1903,17 @@ protected double getAngleValue(int p1, int p2, int p3, int p4) { return dr; } + /** + * Checks whether the triangles defined by the given points are similar. + * + * @param p1 first vertex of the first triangle + * @param p2 second vertex of the first triangle + * @param p3 third vertex of the first triangle + * @param p4 first vertex of the second triangle + * @param p5 second vertex of the second triangle + * @param p6 third vertex of the second triangle + * @return true if the triangles are similar based on their side ratios, false otherwise + */ boolean check_simtri(int p1, int p2, int p3, int p4, int p5, int p6) { double r1 = getRatio(p1, p2, p4, p5); @@ -1476,6 +1923,17 @@ boolean check_simtri(int p1, int p2, int p3, int p4, int p5, int p6) { return (Math.abs(r1 - r2) < ZERO) && (Math.abs(r1 - r3) < ZERO); } + /** + * Checks whether two triangles are congruent by comparing side ratios and one corresponding side length. + * + * @param p1 first vertex of the first triangle + * @param p2 second vertex of the first triangle + * @param p3 third vertex of the first triangle + * @param p4 first vertex of the second triangle + * @param p5 second vertex of the second triangle + * @param p6 third vertex of the second triangle + * @return true if the triangles are congruent, false otherwise + */ boolean check_congtri(int p1, int p2, int p3, int p4, int p5, int p6) { double r1 = getRatio(p1, p2, p4, p5); @@ -1486,6 +1944,14 @@ boolean check_congtri(int p1, int p2, int p3, int p4, int p5, int p6) { (Math.abs(length2(p1, p2) - length2(p4, p5)) < ZERO); } + /** + * Determines if the first point is the midpoint of the segment defined by the other two points. + * + * @param p1 the point to test as the midpoint + * @param p2 the first endpoint of the segment + * @param p3 the second endpoint of the segment + * @return true if p1 is the midpoint of p2 and p3, false otherwise + */ boolean check_mid(int p1, int p2, int p3) { double x1 = aptx(p1); double y1 = apty(p1); @@ -1496,13 +1962,28 @@ boolean check_mid(int p1, int p2, int p3) { return Math.abs(x2 + x3 - 2 * x1) < ZERO && Math.abs(y2 + y3 - 2 * y1) < ZERO; } + /** + * Calculates the ratio of the squared distances between two pairs of points. + * + * @param p1 the first point of the first segment + * @param p2 the second point of the first segment + * @param p3 the first point of the second segment + * @param p4 the second point of the second segment + * @return the ratio of the squared distance between (p1, p2) and (p3, p4) + */ double getRatio(int p1, int p2, int p3, int p4) { double r1 = (Math.pow(aptx(p1) - aptx(p2), 2) + Math.pow(apty(p1) - apty(p2), 2)) / (Math.pow(aptx(p3) - aptx(p4), 2) + Math.pow(apty(p3) - apty(p4), 2)); return r1; } - + /** + * Computes the integer square root of a number. + * Returns the square root if the number is a perfect square; otherwise, returns -1. + * + * @param n the number to compute the square root of + * @return the integer square root if it exists; -1 otherwise + */ int Sqrt(int n) { int i = 1; while (i * i < n) @@ -1512,6 +1993,18 @@ int Sqrt(int n) { } + /** + * Checks if two triangles, defined by three vertex points each, are identical. + * The comparison is independent of the vertex order. + * + * @param p1 vertex of the first triangle + * @param p2 vertex of the first triangle + * @param p3 vertex of the first triangle + * @param q1 vertex of the second triangle + * @param q2 vertex of the second triangle + * @param q3 vertex of the second triangle + * @return true if the triangles are the same; false otherwise + */ final public boolean same_tri(int p1, int p2, int p3, int q1, int q2, int q3) { if ( p1 == q1 && (p2 == q2 && p3 == q3 || p2 == q3 && p3 == q2) || @@ -1521,19 +2014,10 @@ final public boolean same_tri(int p1, int p2, int p3, int q1, int q2, int q3) { return false; } - - public void add_ast(Angles as) { - AngSt ast = all_ast.nx; - while (ast != null) { - if (ast.addAngle(as)) - return; - ast = ast.nx; - } - ast = new AngSt(); - ast.addAngle(as); - return; - } - + /** + * Collects angle expressions into a collection. + * Processes the global list of angle objects and groups unique angle expressions. + */ public void collect_angst() { Vector v = new Vector(); @@ -1563,6 +2047,13 @@ public void collect_angst() { } } + /** + * Adds an angle expression to a new angle structure. + * Updates the global angle structure list with the provided angle. + * + * @param ag the angle expression to add + * @param v a vector used for collecting angle structures + */ public void addAngst(Angles ag, Vector v) { AngSt a = new AngSt(); a.addAngle(ag); @@ -1570,6 +2061,12 @@ public void addAngst(Angles ag, Vector v) { last_ast = a; } + /** + * Attempts to insert an angle expression into the existing angle structure list. + * + * @param ag the angle expression to insert + * @return true if the angle was merged with an existing structure; false otherwise + */ public boolean insertAngle(Angles ag) { if (ag.l1 == ag.l3 && ag.l2 == ag.l4 || ag.l1 == ag.l2 && ag.l3 == ag.l4) return true; @@ -1584,6 +2081,13 @@ public boolean insertAngle(Angles ag) { return false; } + /** + * Finds and returns the angle structure that contains the specified lines. + * + * @param l1 the first line to search within angle structures + * @param l2 the second line to search within angle structures + * @return the angle structure containing the lines, or null if not found + */ public AngSt fd_ast(LLine l1, LLine l2) { AngSt ast = all_ast.nx; while (ast != null) { @@ -1592,9 +2096,14 @@ public AngSt fd_ast(LLine l1, LLine l2) { } return null; } - //////////////////////////////////////////////////////////////////////////////////// - /// auxpoint list + /** + * Computes the greatest common divisor (GCD) of two long integers using the Euclidean algorithm. + * + * @param l1 the first number + * @param l2 the second number + * @return the GCD of the two numbers + */ long gcd(long l1, long l2) { long l; if (l1 < 0L) { @@ -1622,11 +2131,13 @@ long gcd(long l1, long l2) { protected Vector vauxpts = new Vector(); protected Vector vauxptf = new Vector(); - int get_auxptn() { - return vauxpts.size(); - } - - final public static void setValue(int n, boolean v) { + /** + * Sets the boolean flag at a given index in a shared values array. + * + * @param n the 1-based index of the value to set + * @param v the boolean value to set + */ + public static void setValue(int n, boolean v) { RValue[n - 1] = v; } } diff --git a/src/main/java/gprover/Gr.java b/src/main/java/gprover/Gr.java index a44c6b59..36802c3e 100644 --- a/src/main/java/gprover/Gr.java +++ b/src/main/java/gprover/Gr.java @@ -1,197 +1,22 @@ package gprover; + /** - * Created by IntelliJ IDEA. - * User: yezheng - * Date: 2006-4-17 - * Time: 15:02:14 - * To change this template use File | Settings | File Templates. + * Represents group related polynomial operations. */ public class Gr extends Poly { - ElTerm rev_elim(ElTerm v) - { - XTerm p; - p = v.p1; - v.p1 = v.p2; - v.p2 = p; - return (v); - } - - -/* ps operations */ - DTerm ps_member(XTerm p, DTerm ps) - { - for (; ps != null; ps = ps.nx) { - if (eq_poly(p, ps.p)) return (ps); - } - return (null); - } - - DTerm ps_inter(DTerm ps1, DTerm ps2) - { - DTerm ps, ps0, ps3; - - if (ps1 == null) - return (null); - else if (ps2 == null) - return (null); - else { - ps = new DTerm(); - ps.nx = null; - ps0 = ps; - while (ps1 != null) { - ps3 = ps_member(ps1.p, ps2); - if (ps3 != null) { - ps0.nx = get_dt(min((ps1.deg), (ps3.deg)), cp_poly(ps1.p), null); - ps0 = ps0.nx; - } - ps1 = ps1.nx; - } - return (ps.nx); - } - } - - DTerm ps_diff2(DTerm ps1, DTerm ps2) /*destructive for ps1 */ - { - DTerm ps, ps0, ps3; - - if (ps1 == null) - return (null); - else if (ps2 == null) - return (ps1); - else { - ps = new DTerm(); - ps.nx = ps1; - while (ps2 != null) { - ps0 = ps; - ps3 = ps0.nx; - while ((ps3 != null) && !(eq_poly(ps2.p, ps3.p))) { - ps0 = ps3; - ps3 = ps3.nx; - } - if (ps3 != null) { - ps3.deg -= ps2.deg; - if (ps3.deg <= 0) { - ps0.nx = ps3.nx; - put_p(ps3.p); - put_d(ps3); - } - } - ps2 = ps2.nx; - } - return (ps.nx); - } - } - - DTerm ps_append(DTerm ps1, DTerm ps2) - { - DTerm ps; - if (ps1 == null) - return (ps2); - else if (ps2 == null) - return (ps1); - else { - for (ps = ps1; ps.nx != null; ps = ps.nx) { - } - ps.nx = ps2; - return (ps1); - } - } - - DTerm ps_diff(DTerm ps1, DTerm ps2) - { - DTerm ps, ps0; - ps = new DTerm(); - if (ps1 == null) return (null); - if (ps2 == null) return (ps1); - { - ps.nx = ps1; - ps0 = ps; - while (ps1 != null) { - if (ps_member(ps1.p, ps2) != null) { - ps0.nx = ps1.nx; - put_p(ps1.p); - put_d(ps1); - ps1 = ps0.nx; - } else { - ps0 = ps1; - ps1 = ps0.nx; - } - } - return (ps.nx); - } - } - - DTerm ps_union(DTerm ps1, DTerm ps2) -//dterm ps1, ps2; - { - if (ps1 == null) return (ps2); - if (ps2 == null) return (ps1); - ps2 = ps_diff(ps2, ps1); - return (ps_append(ps1, ps2)); - } - - int ps_term1(DTerm dp) { - int k = 0; - for (DTerm ps = dp; ps != null; ps = ps.nx) { - if (!npoly(ps.p)) k++; - } - return k; - } - - - XTerm ps_plus(DTerm dp) - { - XTerm p1; - DTerm dp1; - - p1 = get_n(0L); - while (dp != null) { - if (dp.deg <= 0) { - put_p(dp.p); - } else if (dp.deg == 1) - p1 = pplus(p1, dp.p); - else - p1 = pplus(p1, ppower(dp.p, dp.deg)); - dp1 = dp; - dp = dp.nx; - put_d(dp1); - } - return (p1); - } - - XTerm ps_times(DTerm dp) - { - XTerm p1; - DTerm dp1; - - p1 = get_n(1L); - while (dp != null) { - if (dp.deg <= 0) { - put_p(dp.p); - } else if (dp.deg == 1) - p1 = ptimes(p1, dp.p); - else - p1 = ptimes(p1, ppower(dp.p, dp.deg)); - dp1 = dp; - dp = dp.nx; - put_d(dp1); - } - return (p1); - } - -/* gr operations */ - - GrTerm cp_gr(GrTerm gr) - { - GrTerm gr1 = mk_gr(gr.c1, gr.ps1, gr.c2, gr.ps2, gr.c, gr.nx); - if (gr.c == 0) - gr1.ps = gr.ps; - else - gr1.el = gr.el; - return (gr1); - } + /** + * Creates a new GrTerm object with the specified parameters. + * + * @param c1 the first coefficient + * @param ps1 the first polynomial term + * @param c2 the second coefficient + * @param ps2 the second polynomial term + * @param c the constant term + * @param nx the next GrTerm in the list + * @return the created GrTerm object + */ GrTerm mk_gr(long c1, DTerm ps1, long c2, DTerm ps2, int c, GrTerm nx) { GrTerm gr = new GrTerm(); gr.c1 = c1; @@ -203,6 +28,15 @@ GrTerm mk_gr(long c1, DTerm ps1, long c2, DTerm ps2, int c, GrTerm nx) { return (gr); } + /** + * Creates a new GrTerm object with the specified coefficients and polynomial terms. + * + * @param c1 the first coefficient + * @param p1 the first polynomial term + * @param c2 the second coefficient + * @param p2 the second polynomial term + * @return the created GrTerm object + */ GrTerm mk_gr1(long c1, XTerm p1, long c2, XTerm p2) { GrTerm gr; gr = new GrTerm(); @@ -220,340 +54,4 @@ GrTerm mk_gr1(long c1, XTerm p1, long c2, XTerm p2) { gr.ps = null; return (gr); } - - int gr_length(GrTerm gr) - { - DTerm ps; - int k, m = 0; - for (ps = gr.ps1; ps != null; ps = ps.nx) { - k = plength(ps.p); - if (k > m) m = k; - } - for (ps = gr.ps2; ps != null; ps = ps.nx) { - k = plength(ps.p); - if (k > m) m = k; - } - return (m); - } - - void put_gr(GrTerm gr) - { - DTerm ps, ps1; - ps = gr.ps1; - while (ps != null) { - ps1 = ps; - ps = ps.nx; - put_p(ps1.p); - put_d(ps1); - } - ps = gr.ps2; - while (ps != null) { - ps1 = ps; - ps = ps.nx; - put_p(ps1.p); - put_d(ps1); - } - if (gr.c == -1) { - ps = gr.ps; - while (ps != null) { - ps1 = ps; - ps = ps.nx; - put_p(ps1.p); - put_d(ps1); - } - } else if (gr.c > 0) { - ElTerm el, e1; - el = gr.el; - while (el != null) { - put_p(el.p1); - put_p(el.p2); - e1 = el; - el = el.nx; - //free((el_term)e1); - } - } - //free((gr_term)gr); - } - - -/* simplification */ - static DTerm ps_d1, ps_d2; - - GrTerm simp_gr(GrTerm gr) { - DTerm ps0, ps1, ps2, ps3; - XTerm p1, p2; - GrTerm gr0; - - if (num_zop(gr.c1) && num_zop(gr.c2)) return (null); - - ps1 = ps_simp(cp_pols(gr.ps1)); - ps2 = ps_simp(cp_pols(gr.ps2)); - - /*printf("simplfi_gr\n"); - print_gr(gr); - printf("\n sps1: ()"); print_ps(ps1); - printf("\n sps2: ()"); print_ps(ps2); printf("\n"); - */ - ps0 = null; - if ((num_zop(gr.c1) || pzerop(ps1.p)) && - (num_zop(gr.c2) || pzerop(ps2.p))) { - put_ps(ps1); - put_ps(ps2); - gr0 = mk_gr(mk_num(0L), null, mk_num(0L), null, -2, null); - gr0.ps = null; - } else if (num_zop(gr.c1) || pzerop(ps1.p)) { - put_ps(ps1); - gr0 = mk_gr(mk_num(0L), null, mk_num(1L), ps2, -2, null); - gr0.ps = null; - if (ps_term1(ps2) <= ps_term1(gr.ps2)) { - put_ps(ps2); - return (null); - } - } else if (num_zop(gr.c2) || pzerop(ps2.p)) { - put_ps(ps2); - if (ps_term1(ps1) <= ps_term1(gr.ps1)) { - put_ps(ps1); - return (null); - } - gr0 = mk_gr(mk_num(1L), ps1, mk_num(0L), null, -2, null); - gr0.ps = null; - } else { - ps1 = get_dt(1, get_num(gr.c1), ps1); - ps2 = get_dt(1, get_num(gr.c2), ps2); - ps3 = ps_div(ps1, ps2); - if (ps3 != null) { - ps1 = ps_d1; - ps2 = ps_d2; - ps0 = ps_append(ps0, ps3); - } - ps3 = ps_div(ps2, ps1); - if (ps3 != null) { - ps2 = ps_d1; - ps1 = ps_d2; - ps0 = ps_append(ps0, ps3); - } - if (ps0 == null) { - put_ps(ps1); - put_ps(ps2); - return (null); - } - p1 = ps1.p; - p2 = ps2.p; - gr0 = mk_gr(p1.c, ps1.nx, p2.c, ps2.nx, -1, null); - gr0.ps = ps0; - } - /*printf("\nsimplfi_gr out:\n"); print_gr(gr0);printf("\n"); */ - return (gr0); - } - - DTerm ps_div(DTerm ps1, DTerm ps2) - { - DTerm ps_1, ps_0, ps00, ps02, ps3, ps4; - XTerm p1, p2; - int d; - long c; - -/* printf("\nps_div\n");print_ps(ps1); printf("\n\n");print_ps(ps2); */ - - if (ps1 == null || ps2 == null) return (null); - ps_0 = new DTerm(); - ps_0.nx = null; - ps00 =ps_0; - - ps4 = ps2; - ps02 = ps2; - while (ps02.nx != null) ps02 = ps02.nx; - ps_1 = new DTerm(); - while (ps4 != null) { - ps3 = ps1; - ps_1.nx = null; - do { - if (ps3.deg > 0) { - if (npoly(ps3.p) && npoly(ps4.p)) { - p1 = ps3.p; - p2 = ps4.p; - c = num_gcd(p1.c, p2.c); - if (!num_unit(c)) { - d = min(ps4.deg, ps3.deg); - ps4.deg -= d; - ps3.deg -= d; - ps00.nx = get_dt(d, get_num(c), null); - ps00 = ps00.nx; - if (!num_eq(p1.c, c)) { - ps_1.nx = get_dt(d, get_num(num_d(p1.c, c)), ps_1.nx); - } - if (!num_eq(p2.c, c)) { - ps02.nx = get_dt(d, get_num(num_d(p2.c, c)), null); - ps02 = ps02.nx; - } - } - } else if (npoly(ps3.p)) { - } else if (npoly(ps4.p)) { - } else { - p1 = pdiv(cp_poly(ps3.p), ps4.p); - if (p1 != null) { - d = min(ps4.deg, ps3.deg); - ps4.deg -= d; - ps3.deg -= d; - ps00.nx = get_dt(d, cp_poly(ps4.p), null); - ps00 = ps00.nx; - if (p1.var == null) { - if (!num_unit(p1.c)) { - gerror("ps_div\n"); - return null; - } - put_x(p1); - } else - ps_1.nx = get_dt(d, p1, ps_1.nx); - } - } - } - ps3 = ps3.nx; - } while (ps3 != null && ps4.deg > 0); - if (ps_1.nx != null) { - ps1 = ps_red(ps_append(ps1, ps_1.nx)); - } - ps4 = ps4.nx; - } - - if (ps_0.nx == null) { - return (null); - } - ps_d1 = ps_red(ps1); - ps_d2 = ps_red(ps2); - return (ps_0.nx); - } - - DTerm ps_red(DTerm ps) - { - DTerm ps_t, ps1, ps2, ps3; - XTerm p1; - long c = mk_num(1L); - ps_t = new DTerm(); - ps_t.nx = ps; - ps1 =ps_t; - ps2 = ps1.nx; - while (ps2 != null) { - if (ps2.deg <= 0) { - ps3 = ps2; - ps2 = ps2.nx; - ps1.nx = ps2; - put_p(ps3.p); - put_d(ps3); - } else if (npoly(ps2.p)) { - p1 = ps2.p; - c = num_t(c, lpower(p1.c, ps2.deg)); - ps3 = ps2; - ps2 = ps2.nx; - ps1.nx = ps2; - put_p(ps3.p); - put_d(ps3); - } else { - ps1 = ps2; - ps2 = ps2.nx; - } - } - return (get_dt(1, get_num(c), ps_t.nx)); - } - - DTerm ps_simp(DTerm ps) - { - DTerm ps_t, ps0, ps1, ps2, ps3; - XTerm p1; - int sn = 1; - ps_t = new DTerm(); - ps_t.nx = null; - ps1 = ps_t; - while (ps != null) { - ps2 = vfactor(ps.p); - p1 = ps2.p; - if (num_zop(p1.c)) { - ps3 = ps2.nx; - put_x(p1); - put_d(ps2); - sn = 0; - } else if (num_unit(p1.c)) { - ps3 = ps2.nx; - put_x(p1); - put_d(ps2); - } else { - ps3 = ps2; - } - while (ps3 != null) { - ps3.deg *= ps.deg; - ps2 = ps_t.nx; - while ((ps2 != null) && !(eq_poly(ps2.p, ps3.p))) ps2 = ps2.nx; - if (ps2 != null) { - put_p(ps3.p); - ps2.deg += ps3.deg; - ps0 = ps3; - ps3 = ps3.nx; - put_d(ps0); - } else { - ps1.nx = ps3; - ps1 = ps3; - ps3 = ps3.nx; - ps1.nx = null; - } - } - ps2 = ps; - ps = ps.nx; - put_d(ps2); - } - if (sn == 0) { - put_ps(ps_t.nx); - return (get_dt(1, get_n(0L), null)); - } - if (ps_t.nx == null) ps_t.nx = get_dt(1, get_n(1L), null); - return (ps_t.nx); - } - -/*destructive for p*/ - DTerm vfactor(XTerm p) { - DTerm ps, ps1, ps2; - XTerm p1; - int d1; - long c = mk_num(1L); - - ps = new DTerm(); - ps.nx = null; - ps1 = ps; - p1 = p; - while (p1.var != null) { - d1 = mdeg(p, p1.var); -/* printf("pdeg: %d\n",d1); */ - if (d1 > 0) { - ps1.nx = get_dt(d1, get_m(p1.var), null); - ps1 = ps1.nx; - } - ps2 = p1.ps; - p1 = ps2.p; - } - if (ps.nx != null) { - p1 = ps_times(cp_pols(ps.nx)); - p = pdiv(p, p1); - put_p(p1); - } - if (p.var == null) { - c = p.c; - put_x(p); - } else { - c = lcontent(p); - if (num_nunit(c)) { - p1 = get_n(-1L); - p = ptimes(p, p1); - } else if (!num_unit(c)) { - p1 = get_num(c); - p = pcdiv(p, p1); - put_x(p1); - } - ps1.nx = get_dt(1, p, null); - ps1 = ps1.nx; - } - ps2 = get_dt(1, get_num(c), ps.nx); - ps.nx = ps2; - return (ps.nx); - } - - } diff --git a/src/main/java/gprover/GrTerm.java b/src/main/java/gprover/GrTerm.java index c1ffef11..138a50b5 100644 --- a/src/main/java/gprover/GrTerm.java +++ b/src/main/java/gprover/GrTerm.java @@ -3,11 +3,9 @@ import java.util.Vector; /** - * Created by IntelliJ IDEA. - * User: yezheng - * Date: 2006-4-17 - * Time: 13:16:18 - * To change this template use File | Settings | File Templates. + * The GrTerm class represents a geometric term in the theorem proving framework. + * It includes properties for coefficients, polynomial terms, construction type, + * elimination terms, simplifiers, and a linked list of geometric terms. */ public class GrTerm { @@ -27,28 +25,39 @@ public class GrTerm { public String text = ""; + /** + * Returns the text representation of this geometric term. + * + * @return the text representing this geometric term. + */ public String toString() { return text; } - public DTerm getps1() { - return ps1; - } - - public XTerm getds1() { - if (ps1 != null) - return ps1.p; - else return null; - } - + /** + * Sets the PTN (property tracking number) for this term. + * + * @param n the new PTN value. + */ public void setPTN(int n) { ptn = n; } + /** + * Retrieves the PTN (property tracking number) of this term. + * + * @return the current PTN value. + */ public int getPTN() { return ptn; } + /** + * Checks whether this geometric term is equivalent to zero. + * Determines zero based on the first polynomial term or its coefficient. + * + * @return true if the term is zero; false otherwise. + */ public boolean isZero() { if (ps1 == null) { if (c1 == 0) @@ -60,6 +69,12 @@ public boolean isZero() { return false; } + /** + * Retrieves all XTerm objects from the first polynomial term. + * Cuts the mark from the first XTerm in the resulting list. + * + * @return a vector containing all XTerm objects. + */ public Vector getAllxterm() { Vector v = new Vector(); if (ps1 != null && ps1.p != null) { @@ -81,6 +96,11 @@ public Vector getAllxterm() { return v; } + /** + * Retrieves all variables present in the first and second polynomial terms. + * + * @return a vector containing all variables. + */ public Vector getAllvars() { Vector v = new Vector(); getPSVar(v, ps1); @@ -88,6 +108,12 @@ public Vector getAllvars() { return v; } + /** + * Collects variables recursively from a chain of DTerm objects and adds them to the provided vector. + * + * @param v the vector to which variables are added. + * @param d the DTerm chain to process. + */ void getPSVar(Vector v, DTerm d) { while (d != null) { getPVar(v, d.p); @@ -95,12 +121,17 @@ void getPSVar(Vector v, DTerm d) { } } + /** + * Retrieves a variable from an XTerm and its associated DTerm chain, + * adding them to the provided vector. + * + * @param v the vector to which the variable is added. + * @param x the XTerm from which the variable is retrieved. + */ void getPVar(Vector v, XTerm x) { if (x == null) return; if (x.var != null) v.add(x.var); getPSVar(v, x.ps); } - - } diff --git a/src/main/java/gprover/Incenter.java b/src/main/java/gprover/Incenter.java index 8de0583f..a878503e 100644 --- a/src/main/java/gprover/Incenter.java +++ b/src/main/java/gprover/Incenter.java @@ -1,22 +1,26 @@ +package gprover; /** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2006-2-14 - * Time: 21:32:05 - * To change this template use File | Settings | File Templates. + * Represents an incenter(the center of the incircle) in a geometric proof. + * This class extends the CClass and includes properties for lemma, coordinates, and a reference to the next incenter. */ -package gprover; -public class Incenter extends CClass -{ - // int type; +public class Incenter extends CClass { + /** The lemma associated with the incenter. */ int lemma; + + /** The coordinate of the incenter. */ int co; + + /** The indices of the points forming the incenter. */ int i, a, b, c; + + /** The next incenter in the list. */ Incenter nx; - public Incenter() - { + /** + * Constructs an Incenter object with default values. + */ + public Incenter() { type = lemma = 0; i = a = b = c = 0; co = 0; diff --git a/src/main/java/gprover/LLine.java b/src/main/java/gprover/LLine.java index 16a8141b..4d9e48b3 100644 --- a/src/main/java/gprover/LLine.java +++ b/src/main/java/gprover/LLine.java @@ -1,12 +1,14 @@ + +package gprover; /** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2006-2-14 - * Time: 21:32:37 - * To change this template use File | Settings | File Templates. + * Represents a geometric line in the construction. + *

+ * The class extends CClass and is used to model a line in a geometric context. + * It includes properties such as a lemma identifier, a condition object, + * an integer number to uniquely identify the line, an array of point indices, + * and a reference to another LLine (for linked constructs). + *

*/ -package gprover; - public class LLine extends CClass { int lemma; @@ -15,6 +17,9 @@ public class LLine extends CClass { public int[] pt; LLine nx; + /** + * Constructs an LLine object with default values. + */ public LLine() { type = lemma = no = 0; co = null; @@ -22,7 +27,11 @@ public LLine() { nx = null; } - + /** + * Copies the properties of another LLine object to this one. + * + * @param l1 the LLine object to copy from + */ public void cp_ln(LLine l1) { lemma = l1.lemma; co = null; @@ -32,6 +41,12 @@ public void cp_ln(LLine l1) { nx = null; } + /** + * Checks if the line contains a specific point. + * + * @param n the point to check + * @return true if the line contains the point, false otherwise + */ public boolean containPt(int n) { if (n == 0) return false; for (int i = 0; i < MAX_GEO; i++) @@ -39,6 +54,13 @@ public boolean containPt(int n) { return false; } + /** + * Finds the intersection point of two lines. + * + * @param l1 the first line + * @param l2 the second line + * @return the intersection point, or 0 if there is no intersection + */ public static int inter_lls(LLine l1, LLine l2) { if (l1 == null || l2 == null || l1 == l2) return (0); if (l1 == l2) return 0; @@ -50,6 +72,13 @@ public static int inter_lls(LLine l1, LLine l2) { return (0); } + /** + * Gets a point from the line that is not equal to the specified point. + * + * @param l1 the line + * @param p1 the point to exclude + * @return a point from the line that is not equal to p1, or 0 if no such point exists + */ public static int get_lpt1(LLine l1, int p1) { for (int j = 0; j <= l1.no; j++) { if (l1.pt[j] != p1) return (l1.pt[j]); @@ -57,6 +86,12 @@ public static int get_lpt1(LLine l1, int p1) { return (0); } + /** + * Checks if a point is on the line. + * + * @param p the point to check + * @return true if the point is on the line, false otherwise + */ final public boolean on_ln(int p) { for (int i = 0; i <= no; i++) if (pt[i] == p) diff --git a/src/main/java/gprover/LList.java b/src/main/java/gprover/LList.java index 766c0b3a..46631d50 100644 --- a/src/main/java/gprover/LList.java +++ b/src/main/java/gprover/LList.java @@ -1,32 +1,58 @@ package gprover; /** - * Created by IntelliJ IDEA. - * User: ye - * Date: Nov 19, 2006 - * Time: 9:27:45 PM - * To change this template use File | Settings | File Templates. + * Represents a list of geometric elements. + * This class extends the CClass and includes properties for different types of elements, rules, and methods to manipulate them. */ public class LList extends CClass { + /** Constant value representing a value type. */ final public static int VALUE = 0; + + /** Constant value representing a line type. */ final public static int LINE = 1; + + /** Constant value representing an angle type. */ final public static int ANGLE = 2; + /** Maximum number of elements. */ final public static int MAX_MDE = 10; + /** Indicates if the list is solved. */ boolean solved = false; + /** The type of the list. */ int type = -1; + + /** Array of Mnde objects representing the elements. */ public Mnde[] md; + + /** Array of Mnde objects representing the elements. */ public Mnde[] mf; - public int nd, nf; - int npt, pt; + /** Number of elements in md. */ + public int nd; + + /** Number of elements in mf. */ + public int nf; + + /** Number of points. */ + int npt; + + /** Point value. */ + int pt; + + /** Array of Rule objects representing the rules. */ public Rule[] rl; + + /** Reference to the first LList object. */ public LList fr; - LList nx; + /** Reference to the next LList object. */ + LList nx; + /** + * Constructs an LList object with default values. + */ public LList() { md = new Mnde[MAX_MDE]; mf = new Mnde[MAX_MDE]; @@ -34,6 +60,11 @@ public LList() { nd = nf = 0; } + /** + * Gets the number of points and updates the npt and pt fields. + * + * @return the number of points + */ public int get_npt() { int num = 0; int t = 0; @@ -55,6 +86,11 @@ public int get_npt() { return num; } + /** + * Copies the properties of another LList object to this one. + * + * @param ls the LList object to copy from + */ public void cp(LList ls) { type = ls.type; nd = ls.nd; @@ -67,18 +103,13 @@ public void cp(LList ls) { mf[i] = new Mnde(); mf[i].cp(ls.mf[i]); } - - } - - public void sub1(AngTr t1, AngTr t2) { - for (int i = 0; i < nd; i++) { - if (md[i].tr == t1) { - md[i].tr = t2; - return; - } - } } + /** + * Adds an Mnde object to the md array. + * + * @param m the Mnde object to add + */ public void add_md(Mnde m) { if (m == null) return; @@ -88,23 +119,36 @@ public void add_md(Mnde m) { nd = i + 1; } + /** + * Adds an Mnde object to the mf array. + * + * @param m the Mnde object to add + */ public void add_mf(Mnde m) { if (m == null) return; int i; for (i = 0; i < MAX_MDE && mf[i] != null; i++) ; mf[i] = m; nf = i + 1; - } + /** + * Adds a Rule object to the rl array. + * + * @param r the Rule object to add + */ public void add_rule(Rule r) { int i; for (i = 0; i < MAX_MDE && rl[i] != null; i++) ; rl[i] = r; } + /** + * Returns a string representation of the LList object. + * + * @return a string representation of the LList object + */ public String toString() { return text; } - -} +} \ No newline at end of file diff --git a/src/main/java/gprover/Main.java b/src/main/java/gprover/Main.java index d802bddb..0bbf41bc 100644 --- a/src/main/java/gprover/Main.java +++ b/src/main/java/gprover/Main.java @@ -3,24 +3,36 @@ import java.io.*; import java.util.Vector; - /** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2006-2-15 - * Time: 17:20:04 - * To change this template use File | Settings | File Templates. + * The main class for the GProver application. + * This class contains the main method and handles the reading of geometric terms, + * processing them, and outputting the results. */ +@Deprecated public class Main { + + /** + * The main method that serves as the entry point of the application. + * + * @param args the command line arguments + */ + public static void main(String[] args) { + main1(args); + } + + /** + * The main logic of the application. + * Reads geometric terms from files, processes them, and outputs the results. + * + * @param args the command line arguments + */ public static void main1(String[] args) { try { - String user_directory = System.getProperty("user.dir"); String sp = File.separator; String dr = user_directory + sp + "examples"; File file = new File(dr); - Vector vm = new Vector(); readThems(file, vm); for (int id = 0; id < vm.size(); id++) { @@ -67,7 +79,6 @@ public static void main1(String[] args) { if (ff.exists()) { ff.delete(); fp = new FileOutputStream(ff, true); - } else { ff.createNewFile(); fp = new FileOutputStream(ff, false); @@ -76,9 +87,6 @@ public static void main1(String[] args) { DataOutputStream out = new DataOutputStream(fp); gt.Save(out); - //db.setPrintToString(); - //db.show_fproof(); - //out.writeBytes(db.getFileProve().append("\n********************************\n").toString()); out.close(); } else { f++; @@ -93,133 +101,19 @@ public static void main1(String[] args) { } } - static void proveGDD(GTerm gt) { - - } - - public static void main(String[] args) { - main1(args); - } - - static void proveFull() { - try { - String user_directory = System.getProperty("user.dir"); - String sp = File.separator; - String dr = user_directory + sp + "ex"; - File file = new File(dr); - - - Vector vm = new Vector(); - readThems(file, vm); - for (int id = 0; id < vm.size(); id++) { - GTerm gt = (GTerm) vm.get(id); - System.out.print(id + " : " + gt.getName() + "\t\t"); - if (id % 4 == 0) - Cm.print("\n"); - - - } - - int t = 0; - int f = 0; - int n = 0; - Cm.print("\n\n************************\n"); - - Vector tlist = new Vector(); - long t1 = System.currentTimeMillis(); - Full full = new Full(); - int nt = 0; - for (int id = 0; id < vm.size(); id++) { - Full.set_showdetai(false); - - - full.init_dbase(); - - GTerm gt = (GTerm) vm.get(id); - full.setExample(gt); - full.sbase(); - full.setNoPrint(); - - if (id == 482) { - System.gc(); - } - full.prove_full(); - if (full.isProvedTrue()) { - FileOutputStream fp; - String drec = (dr + sp + "proved"); - File ff = new File(drec + sp + gt.getName() + ".rtf"); - - if (ff.exists()) { - ff.delete(); - fp = new FileOutputStream(ff, true); - - } else { - ff.createNewFile(); - fp = new FileOutputStream(ff, false); - } - if (fp == null) return; - DataOutputStream out = new DataOutputStream(fp); - - boolean s = false; - GrTerm gr = full.getFullAngleProofHead(); - while (gr != null) { - ElTerm e = gr.el; - if (e == null) { - gr = gr.nx; - continue; - } - while (e != null) { - Cond c = e.co; - full.setPrintToString(); - while (c != null) { - full.setConc(c); - if (full.docc()) { - full.show_fproof(); - Cond conc = full.all_nd.nx; - int nx = 0; - while (conc != null) { - nx++; - conc = conc.nx; - } - if (nx > 1) { - s = true; - System.out.print("(" + nx + ")"); - // full.show_fproof(); - out.writeBytes(full.getFileProve().append("\n********************************\n").toString()); - } - } - c = c.nx; - } - e = e.nx; - } - gr = gr.nx; - - } - if (s) { - gt.Save(out); - } - out.close(); - nt ++; - System.out.print(id + " : " + gt.getName() + "\t\ttrue\n"); - - } else { - // System.out.print(id + " : " + gt.getName() + "\t\tfalse\n"); - } - } - Cm.print("Total :" +vm.size() +", and true: " +nt); - } catch (IOException ee) { - - } - - } - + /** + * Reads geometric terms from files and adds them to a vector. + * + * @param file the directory containing the files + * @param v the vector to store the geometric terms + * @throws IOException if an I/O error occurs + */ static void readThems(File file, Vector v) throws IOException { File[] sf = file.listFiles(new FileFilter() { public boolean accept(File pathname) { String nm = pathname.getName(); return !(nm.contains(".")); } - }); for (int i = 0; i < sf.length; i++) { if (sf[i].isDirectory()) @@ -237,13 +131,4 @@ public boolean accept(File pathname) { } } } - - - static int inputInt() throws IOException { - byte[] bm = new byte[10]; - System.in.read(bm); - String sid = new String(bm).trim(); - int dd = Integer.parseInt(sid); - return dd; - } -} +} \ No newline at end of file diff --git a/src/main/java/gprover/Main2.java b/src/main/java/gprover/Main2.java index 12772a12..b5ef1776 100644 --- a/src/main/java/gprover/Main2.java +++ b/src/main/java/gprover/Main2.java @@ -1,100 +1,61 @@ -/** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2006-2-18 - * Time: 21:26:51 - * To change this template use File | Settings | File Templates. - */ package gprover; import javax.swing.*; import java.io.*; + +/** + * Main entry point for the application. + * + *

+ * This class demonstrates file selection from a specific directory, reading data using a custom term reader, + * initializing a database, processing the example, computing a fixpoint and displaying a full proof. + * The file chooser is set to the "examples" directory relative to the user's current working directory. + * If the file selection is cancelled, the application exits. + *

+ */ +@Deprecated public class Main2 { + /** + * Main method to run the application. + * + * @param args Command line arguments (not used). + */ + @Deprecated public static void main(String[] args) { -// final public static int CM_EX_PARA = 1; -// final public static int CM_EX_ORTH = 2; -// final public static int CM_EX_SIMSON = 3; -// final public static int CM_EX_SQ = 4; -// final public static int CM_EX_PAPPUS = 5; -// final public static int CM_EX_PEDAL = 6; -// final public static int CM_EX_MIQ1 = 7; - + // Get the user's current directory. String user_directory = System.getProperty("user.dir"); + // Get the file separator specific to the operating system. String sp = File.separator; + // Construct the path to the "examples" directory. String dr = user_directory + sp + "examples"; + + // Initialize a file chooser with the current directory set to the examples folder. JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(dr)); int result = chooser.showOpenDialog(null); + + // Exit if the file chooser is cancelled. if (result == JFileChooser.CANCEL_OPTION) return; + + // Create an instance of GTerm to process the selected file. GTerm gt = new GTerm(); try { + // Read the term from the selected file. gt.readAterm(new BufferedReader(new FileReader(chooser.getSelectedFile()))); + + // Initialize database and process the example. GDDBc db = new GDDBc(); db.init_dbase(); -// db.proc_exam(gdd.CM_EX_PARA); - db.setExample(gt); db.sbase(); -// do { -// fixpoint(); -// last_nd = &all_nd; -// all_nd.nx = NULL; -// if (!conc_xtrue()) { -// if (print_geo) gprint("\n\n Beginning make auxillary points\n"); -// add_aux(); -// if (print_geo) { -// show_cons(); -// show_nds(); -// } -// } -// } while (all_nd.nx != NULL); - db.fixpoint(); - //db.show_dbase((char)0); -// db.size_of_dbase('c'); db.show_fproof(); - -// if (true) -// { -// FileOutputStream fp; -// String drec = (dr + sp); -// File ff = new File(drec + sp + gt.name + ".txt"); -// -// if (ff.exists()) -// { -// fp = new FileOutputStream(ff, true); -// -// } else -// { -// ff.createNewFile(); -// fp = new FileOutputStream(ff, false); -// } -// if (fp == null) return; -// DataOutputStream out = new DataOutputStream(fp); -// gt.Save(out); -// -//// db.setPrintToFile(); -// db.show_fproof((char) 1); -// db.show_dbase((char) 0); -// // out.writeBytes(db.getFileProve() + "\n********************************\n"); -// out.close(); -// -//// gt.print(); -//// db.show_fproof((char) 1); -// CMisc.print(gt.name + " " + "is true"); -// } else -// { db.show_dbase((char)0); -// CMisc.print(gt.name + " " + "is false"); -// } - - //db.show_dbase((char) 0); } catch (IOException ee) { + // Print any IOExceptions encountered during file reading or processing. System.err.println("IOException " + ee.toString()); } - - //CMisc.print(Cm.s2077); } } diff --git a/src/main/java/gprover/MathBase.java b/src/main/java/gprover/MathBase.java index cc02a0a6..66cd71a8 100644 --- a/src/main/java/gprover/MathBase.java +++ b/src/main/java/gprover/MathBase.java @@ -1,13 +1,17 @@ package gprover; /** - * Created by IntelliJ IDEA. - * User: yezheng - * Date: 2006-4-14 - * Time: 13:47:59 - * To change this template use File | Settings | File Templates. + * Provides basic arithmetic, string, and array manipulation methods. */ public class MathBase extends GDDBc { + + /** + * Compares two character arrays lexicographically. + * + * @param p1 the first character array + * @param p2 the second character array + * @return a negative, zero, or positive integer as p1 is less than, equal to, or greater than p2 + */ int strcmp(char[] p1, char[] p2) { int l1, l2; if (p1 == null && p2 == null) @@ -28,6 +32,13 @@ else if (p1 == null) return -1; } + /** + * Compares two strings lexicographically. + * + * @param s1 the first string + * @param s2 the second string + * @return a negative, zero, or positive integer as s1 is less than, equal to, or greater than s2 + */ int strcmp(String s1, String s2) { if (s1 != null) return s1.compareTo(s2); @@ -37,6 +48,13 @@ else if (s2 == null) return -1; } + /** + * Copies the source character array to the destination array. + * + * @param p the destination character array + * @param s the source character array + * @return true if the copy was successful + */ boolean strcpy(char[] p, char[] s) { if (s == null) return true; @@ -48,106 +66,205 @@ boolean strcpy(char[] p, char[] s) { return true; } + /** + * Determines if the given XTerm represents a number. + * + * @param p the XTerm to check + * @return true if p represents a number, false otherwise + */ boolean numberp(XTerm p) { return (p.var == null); } + /** + * Determines if the given XTerm represents a polynomial. + * + * @param p the XTerm to check + * @return true if p represents a polynomial, false otherwise + */ boolean npoly(XTerm p) { return (p.var == null); } + /** + * Determines if the given XTerm represents zero. + * + * @param p the XTerm to check + * @return true if p represents zero, false otherwise + */ boolean pzerop(XTerm p) { return ((p.var == null) && (num_zop(p.c))); } + /** + * Determines if the given XTerm represents the unit value 1. + * + * @param p the XTerm to check + * @return true if p represents 1, false otherwise + */ boolean unitp(XTerm p) { return ((p.var == null) && (p.c == mk_num(1L))); } + /** + * Determines if the given XTerm represents the negative unit value -1. + * + * @param p the XTerm to check + * @return true if p represents -1, false otherwise + */ boolean nunitp(XTerm p) { return ((p.var == null) && (p.c == mk_num(-1L))); } + /** + * Checks whether the given number is zero. + * + * @param x the number to check + * @return true if x is zero, false otherwise + */ boolean num_zop(long x) { return (x) == 0L; } + /** + * Checks whether the given number is positive. + * + * @param x the number to check + * @return true if x is positive, false otherwise + */ boolean num_posp(long x) { return (x) > 0L; } + /** + * Checks whether the given number is negative. + * + * @param x the number to check + * @return true if x is negative, false otherwise + */ boolean num_negp(long x) { return x < 0L; } + /** + * Creates a numeric representation from a long value. + * + * @param x the input value + * @return the numeric representation of x + */ long mk_num(long x) { return x; } - long num_m(long x, long y) { - return ((x) - (y)); - } - + /** + * Computes the sum of two numbers. + * + * @param x the first number + * @param y the second number + * @return the sum of x and y + */ long num_p(long x, long y) { return x + y; } + /** + * Computes the product of two numbers. + * + * @param x the first number + * @param y the second number + * @return the product of x and y + */ long num_t(long x, long y) { return x * y; } + /** + * Computes the integer division of one number by another. + * + * @param x the dividend + * @param y the divisor + * @return the quotient of x divided by y + */ long num_d(long x, long y) { return x / y; } + /** + * Returns the negation of the given number. + * + * @param x the number to negate + * @return the negated value of x + */ long num_neg(long x) { return -x; } - long num_gcd(long x, long y) { - return lgcd((x), (y)); - } - - long num_p3(long x, long y, long z) { - return ((x) + (y) + (z)); - } - - long num_t3(long x, long y, long z) { - return ((x) * (y) * (z)); - } - + /** + * Computes the remainder when one number is divided by another. + * + * @param x the dividend + * @param y the divisor + * @return the remainder of x divided by y + */ long num_mod(long x, long y) { return ((x) % (y)); } + /** + * Computes the modulus of a number by 2. + * + * @param x the number to evaluate + * @return the remainder of x divided by 2 + */ long num_modt(long x) { return ((x) % 2L); } + /** + * Checks if the given number is the unit value 1. + * + * @param p the number to check + * @return true if p is 1, false otherwise + */ boolean num_unit(long p) { return (p) == 1L; } + /** + * Checks if the given number is the negative unit value -1. + * + * @param p the number to check + * @return true if p is -1, false otherwise + */ boolean num_nunit(long p) { return (p) == (-1L); } - double num_to_f(long x) { - return (double) (x); - } - + /** + * Determines the number of digits in the given number. + * + * @param x the number to evaluate + * @return the number of digits in x + */ long num_digs(long x) { return int_digs(x); } + /** + * Displays the numeric value by converting it to its string representation. + * + * @param x the number to display + */ void num_show(long x) { int_show(x); } - int min(int a, int b) { - return ((a < b) ? (a) : (b)); - } - + /** + * Counts the number of digits in a long integer. + * + * @param x the number to evaluate + * @return the count of digits in x + */ int int_digs(long x) { int i = 0; if (x < 0L) x = -x; @@ -158,14 +275,32 @@ int int_digs(long x) { return (i); } + /** + * Converts a long number to an integer. + * + * @param c the number to convert + * @return the integer representation of c + */ int num_int(long c) { return (int) c; } + /** + * Displays the integer value by printing its string representation. + * + * @param x the number to display + */ void int_show(long x) { gprint(Integer.toString((int) x)); } + /** + * Computes the greatest common divisor of two numbers. + * + * @param l1 the first number + * @param l2 the second number + * @return the greatest common divisor of l1 and l2 + */ long lgcd(long l1, long l2) { long l; if (l1 < 0L) { @@ -186,31 +321,4 @@ long lgcd(long l1, long l2) { } return (l2); } - - - long ngcd(long l1, long l2) { - long n = lgcd(l1, l2); - if (n < 0L) n = -n; - return (n); - } - - long lpower(long l, long n) { - long d = (1L); - if (n <= 0) - return ((1L)); - else { - while (n > 1) { - if (n % 2 == 0) { - n /= 2; - l = num_t(l, l); - } else { - n -= 1; - d = num_t(d, l); - } - } - return (num_t(d, l)); - } - } - - } diff --git a/src/main/java/gprover/MidPt.java b/src/main/java/gprover/MidPt.java index 02076100..c7820a9f 100644 --- a/src/main/java/gprover/MidPt.java +++ b/src/main/java/gprover/MidPt.java @@ -1,21 +1,28 @@ +package gprover; /** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2006-2-14 - * Time: 21:31:33 - * To change this template use File | Settings | File Templates. + * Represents a midpoint in a geometric construction. + * This class extends CClass and includes properties for lemma, conditions, and coordinates. */ -package gprover; -public class MidPt extends CClass -{ -// int type; +public class MidPt extends CClass { + // int type; // Commented out type field + + /** The lemma associated with the midpoint. */ int lemma; + + /** The condition associated with the midpoint. */ Cond co; + + /** The coordinates of the midpoint. */ public int m, a, b; + + /** Reference to the next MidPt object. */ MidPt nx; - public MidPt() - { + + /** + * Constructs a MidPt object with default values. + */ + public MidPt() { type = lemma = m = a = b = 0; co = null; nx = null; diff --git a/src/main/java/gprover/Mnde.java b/src/main/java/gprover/Mnde.java index 091f14e1..8ad2dafe 100644 --- a/src/main/java/gprover/Mnde.java +++ b/src/main/java/gprover/Mnde.java @@ -1,24 +1,30 @@ package gprover; /** - * Created by IntelliJ IDEA. - * User: ye - * Date: Nov 17, 2006 - * Time: 5:00:43 PM - * To change this template use File | Settings | File Templates. + * Represents a geometric construction node. */ public class Mnde { int t, type; public AngTr tr; Mnde nx; + + /** + * Constructs a Mnde object with default values. + */ public Mnde() { t = 1; type = 0; tr = null; nx = null; - + } + + /** + * Copies the values from another Mnde object to this object. + * + * @param m the Mnde object to copy from + */ public void cp(Mnde m) { t = m.t; diff --git a/src/main/java/gprover/NdgCs.java b/src/main/java/gprover/NdgCs.java index 93bc572c..330904d3 100644 --- a/src/main/java/gprover/NdgCs.java +++ b/src/main/java/gprover/NdgCs.java @@ -1,28 +1,51 @@ package gprover; - +/** + * Represents a node in a geometric construction tree. + */ public class NdgCs { + /** The parent node. */ NdgCs parent = null; + + /** The geometric condition associated with this node. */ CNdg nd = null; - int ntype = 0; // 0. Normal, 1. exists. + + /** The type of the node (0 for normal, 1 for exists). */ + int ntype = 0; + + /** Indicates if this node is a leaf. */ boolean leaf = false; + + /** Indicates if this node is valid. */ boolean valid = true; + /** The index of the last constraint added. */ int no = -1; + + /** The child nodes of this node. */ NdgCs[] child = new NdgCs[3]; - Cons[] allcns = new Cons[100]; + /** The constraints associated with this node. */ + Cons[] allcns = new Cons[100]; + /** + * Adds a constraint to this node. + * + * @param c the constraint to add + */ public void add(Cons c) { if (c != null) { allcns[++no] = c; } } - + /** + * Gets the maximum constraint index. + * + * @return the maximum constraint index + */ public int getMaxCnsInt() { int n = 0; - for (int i = 0; i <= no; i++) { if (allcns[i] == null) continue; @@ -33,12 +56,23 @@ public int getMaxCnsInt() { return n; } + /** + * Adds a constraint at a specific index. + * + * @param i the index + * @param c the constraint to add + */ public void add(int i, Cons c) { if (c != null) { allcns[i] = c; } } + /** + * Gets the number of non-null constraints. + * + * @return the number of non-null constraints + */ public int getNotNullNum() { int k = 0; for (int i = 0; i <= no; i++) { @@ -48,6 +82,11 @@ public int getNotNullNum() { return k; } + /** + * Adds a child node to this node. + * + * @param c the child node to add + */ public void addChild(NdgCs c) { for (int i = 0; i < child.length; i++) { if (child[i] == null) { @@ -57,6 +96,12 @@ public void addChild(NdgCs c) { } } + /** + * Replaces a point in all constraints. + * + * @param m the point to replace + * @param n the new point + */ public void replace(int m, int n) { for (int i = 0; i <= no; i++) { Cons c1 = allcns[i]; @@ -65,23 +110,13 @@ public void replace(int m, int n) { } } - public void sort() { - - for (int i = 0; i <= no; i++) { - Cons c1 = allcns[i]; - for (int j = 0; j < i; j++) { - Cons c2 = allcns[j]; - if (c1 != null && c2 != null && compare(c1, c2) < 0) { - for (int k = i - 1; k >= j; k--) - allcns[k + 1] = allcns[k]; - allcns[j] = c1; - break; - } - } - } - - } - + /** + * Compares two constraints. + * + * @param c1 the first constraint + * @param c2 the second constraint + * @return a negative integer, zero, or a positive integer as the first constraint is less than, equal to, or greater than the second + */ public static int compare(Cons c1, Cons c2) { int n1 = c1.getLastPt(); int n2 = c2.getLastPt(); @@ -92,15 +127,20 @@ public static int compare(Cons c1, Cons c2) { return -1; return compare1(c1, c2, n1); } - if (n1 > n2) return 1; - return 0; } - private static int compare1(Cons c1, Cons c2, int n) // euql type; - { + /** + * Helper method to compare two constraints with equal types. + * + * @param c1 the first constraint + * @param c2 the second constraint + * @param n the point index to compare + * @return a negative integer, zero, or a positive integer as the first constraint is less than, equal to, or greater than the second + */ + private static int compare1(Cons c1, Cons c2, int n) { while (n > 0) { int n1 = c1.getLessPt(n); int n2 = c2.getLessPt(n); @@ -113,27 +153,14 @@ public static int compare(Cons c1, Cons c2) { return 0; } - public void rm_common() { - for (int i = 0; i <= no; i++) { - Cons c = allcns[i]; - if (c == null) - continue; - for (int j = 0; j < i; j++) { - Cons c1 = allcns[j]; - if (c1 != null && c1.isEqual(c)) { - allcns[i] = null; - break; - } - } - } - } - + /** + * Reduces the constraints by replacing points. + */ public void reduce() { if (nd == null) return; int a = nd.p[0]; int b = nd.p[1]; - if (nd.type == Gib.NDG_NEQ || nd.type == Gib.NDG_NON_ISOTROPIC) { for (int i = 0; i <= no; i++) { Cons c = allcns[i]; @@ -145,18 +172,17 @@ public void reduce() { } } - public void reorder() { - for (int i = 0; i <= no; i++) { - Cons c = allcns[i]; - if (c == null) - continue; - c.reorder(); - } - } - + /** + * Constructs an empty NdgCs object. + */ public NdgCs() { } + /** + * Constructs a NdgCs object by copying another NdgCs object. + * + * @param c the NdgCs object to copy + */ public NdgCs(NdgCs c) { parent = c.parent; nd = c.nd; @@ -167,6 +193,11 @@ public NdgCs(NdgCs c) { } } + /** + * Gets the index of the last non-null child. + * + * @return the index of the last non-null child + */ public int getCSindex() { int a = -1; for (int d = 0; d < child.length; d++) { @@ -175,4 +206,4 @@ public int getCSindex() { } return a; } -} +} \ No newline at end of file diff --git a/src/main/java/gprover/PLine.java b/src/main/java/gprover/PLine.java index c70b1fa4..016507fb 100644 --- a/src/main/java/gprover/PLine.java +++ b/src/main/java/gprover/PLine.java @@ -1,12 +1,8 @@ -/** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2006-2-14 - * Time: 21:33:19 - * To change this template use File | Settings | File Templates. - */ package gprover; +/** + * Constructs a Mnde object with default values. + */ public class PLine extends CClass { int lemma; Cond co; @@ -15,6 +11,12 @@ public class PLine extends CClass { PLine nx; + /** + * Constructs a PLine object with two lines. + * + * @param l1 the first line + * @param l2 the second line + */ public PLine(LLine l1, LLine l2) { this(); ln[0] = l1; @@ -22,6 +24,9 @@ public PLine(LLine l1, LLine l2) { no = 1; } + /** + * Constructs a PLine object with default values. + */ public PLine() { type = lemma = no = 0; co = null; diff --git a/src/main/java/gprover/Poly.java b/src/main/java/gprover/Poly.java index f9efef60..ba2f5210 100644 --- a/src/main/java/gprover/Poly.java +++ b/src/main/java/gprover/Poly.java @@ -1,6 +1,12 @@ package gprover; +/** + * The Poly class extends MathBase and provides implementations + * for various polynomial operations such as addition, subtraction, + * multiplication, division, and remainder computation. + * It also supports simplification and printing functionalities for polynomials. + */ public class Poly extends MathBase { /* initials */ public static int PRO_VEC = 330; @@ -16,24 +22,46 @@ public class Poly extends MathBase { int pro_type = 0; Var all_var, last_var; +/** + * Initializes the polynomial by setting up the initial variable. + */ void init_poly() { all_var = new Var(); last_var = all_var; all_var.nx = null; } + /** + * Constructs a Poly object and initializes it. + */ public Poly() { init_poly(); } + /** + * Creates a new XTerm object. + * + * @return a new XTerm object + */ XTerm get_x() { return (new XTerm()); } + /** + * Creates a new DTerm object. + * + * @return a new DTerm object + */ DTerm get_d() { return (new DTerm()); } + /** + * Creates a new XTerm object representing a number. + * + * @param n the number to represent + * @return a new XTerm object representing the number + */ XTerm get_n(long n) { XTerm p1; p1 = get_x(); @@ -42,6 +70,12 @@ XTerm get_n(long n) { return (p1); } + /** + * Creates a new XTerm object representing a number. + * + * @param n the number to represent + * @return a new XTerm object representing the number + */ XTerm get_num(long n) { XTerm p1; p1 = get_x(); @@ -50,6 +84,13 @@ XTerm get_num(long n) { return (p1); } + /** + * Creates a new XTerm object with a variable and a DTerm. + * + * @param v the variable + * @param dp1 the DTerm + * @return a new XTerm object + */ XTerm get_xt(Var v, DTerm dp1) { XTerm xp1; xp1 = get_x(); @@ -58,10 +99,12 @@ XTerm get_xt(Var v, DTerm dp1) { return (xp1); } - XTerm get_s(char[] ch) { - return (get_m(mk_svar(ch))); - } - + /** + * Creates a new XTerm object representing a monomial. + * + * @param vn the variable + * @return a new XTerm object representing the monomial + */ XTerm get_m(Var vn) { DTerm dp1; XTerm xp1; @@ -74,6 +117,14 @@ XTerm get_m(Var vn) { } } + /** + * Creates a new XTerm object representing a variable raised to a power. + * + * @param v the variable + * @param d the degree + * @param p the polynomial term + * @return a new XTerm object + */ XTerm get_v(Var v, int d, XTerm p) { DTerm dp1; XTerm xp1; @@ -88,7 +139,14 @@ else if (d == 0) } } - + /** + * Creates a new DTerm object. + * + * @param d the degree + * @param xp1 the XTerm + * @param dp1 the next DTerm + * @return a new DTerm object + */ DTerm get_dt(int d, XTerm xp1, DTerm dp1) { DTerm d1; d1 = get_d(); @@ -98,12 +156,27 @@ DTerm get_dt(int d, XTerm xp1, DTerm dp1) { return (d1); } + /** + * Placeholder method for handling DTerm objects. + * + * @param dpt the DTerm object + */ void put_d(DTerm dpt) { } + /** + * Placeholder method for handling XTerm objects. + * + * @param xpt the XTerm object + */ void put_x(XTerm xpt) { } + /** + * Handles the given XTerm object and its associated DTerm objects. + * + * @param p1 the XTerm object + */ void put_p(XTerm p1) { DTerm dp1, dp2; if (p1 != null) { @@ -122,6 +195,11 @@ void put_p(XTerm p1) { } } + /** + * Handles the given DTerm objects. + * + * @param dp0 the head of the DTerm list + */ void put_ps(DTerm dp0) { DTerm dp1; while (dp0 != null) { @@ -132,12 +210,24 @@ void put_ps(DTerm dp0) { } } -/* xtermnomials */ - + /** + * Checks if two numbers are equal. + * + * @param c1 the first number + * @param c2 the second number + * @return true if the numbers are equal, false otherwise + */ boolean num_eq(long c1, long c2) { return c1 == c2; } + /** + * Checks if two polynomial terms are equal. + * + * @param p1 the first polynomial term + * @param p2 the second polynomial term + * @return true if the polynomial terms are equal, false otherwise + */ boolean eq_poly(XTerm p1, XTerm p2) { if ((p1.var == null) && (p2.var == null)) return (num_eq(p1.c, p2.c)); @@ -147,6 +237,13 @@ else if (p1.var != p2.var) return (eq_pols(p1.ps, p2.ps)); } + /** + * Checks if two lists of polynomial terms are equal. + * + * @param dp1 the first list of polynomial terms + * @param dp2 the second list of polynomial terms + * @return true if the lists of polynomial terms are equal, false otherwise + */ boolean eq_pols(DTerm dp1, DTerm dp2) { while ((dp1 != null) && (dp2 != null)) { if ((dp1.deg != dp2.deg) || @@ -159,6 +256,12 @@ boolean eq_pols(DTerm dp1, DTerm dp2) { return (dp1 == dp2); } + /** + * Creates a copy of the given polynomial term. + * + * @param p1 the polynomial term to copy + * @return a copy of the polynomial term + */ XTerm cp_poly(XTerm p1) { if (p1.var == null) return (get_num(p1.c)); @@ -166,6 +269,12 @@ XTerm cp_poly(XTerm p1) { return (get_xt(p1.var, cp_pols(p1.ps))); } + /** + * Creates a copy of the given list of polynomial terms. + * + * @param dp1 the list of polynomial terms to copy + * @return a copy of the list of polynomial terms + */ DTerm cp_pols(DTerm dp1) { DTerm dt2, dp2; dt2 = new DTerm(); @@ -179,26 +288,35 @@ DTerm cp_pols(DTerm dp1) { return (dt2.nx); } + /** + * Creates a new XTerm object representing zero. + * + * @return a new XTerm object representing zero + */ XTerm pzero() { return (get_n(0L)); } -/* -int pclass(p) -xterm *p; -{ if (numberp(p)) return(0); - else return(p.var); -} */ - - int ldeg(XTerm p) -//xterm p; - { + /** + * Gets the leading degree of the polynomial term. + * + * @param p the polynomial term + * @return the leading degree of the polynomial term + */ + int ldeg(XTerm p) { DTerm dp1; if (p.var == null) return (0); dp1 = p.ps; return (dp1.deg); } + /** + * Gets the degree of the polynomial term with respect to a variable. + * + * @param p the polynomial term + * @param v the variable + * @return the degree of the polynomial term with respect to the variable + */ int pdeg(XTerm p, Var v) { int tem, md; DTerm dp1; @@ -215,6 +333,13 @@ int pdeg(XTerm p, Var v) { return (md); } + /** + * Gets the minimum degree of the polynomial term with respect to a variable. + * + * @param p the polynomial term + * @param v the variable + * @return the minimum degree of the polynomial term with respect to the variable + */ int mdeg(XTerm p, Var v) { int tem, md; DTerm ps1; @@ -235,7 +360,12 @@ int mdeg(XTerm p, Var v) { return (md); } - + /** + * Gets the leading coefficient of the polynomial term. + * + * @param p the polynomial term + * @return the leading coefficient of the polynomial term + */ long lcc(XTerm p) { DTerm dp1; while (p.var != null) { @@ -245,13 +375,24 @@ long lcc(XTerm p) { return (p.c); } - + /** + * Gets the first coefficient of the polynomial term. + * + * @param p the polynomial term + * @return the first coefficient of the polynomial term + */ long fcc(XTerm p) { return (lcc(p)); } static long lcc_p; + /** + * Computes the content (greatest common divisor) of the polynomial coefficients. + * + * @param p the polynomial term + * @return the content of the polynomial as an integer + */ int lcontent(XTerm p) { lcc_p = mk_num(0L); lcont1(p); @@ -259,6 +400,11 @@ int lcontent(XTerm p) { return (int) (lcc_p); } + /** + * Recursively computes and updates the content based on the polynomial's coefficients. + * + * @param p the polynomial term + */ void lcont1(XTerm p) { DTerm ps1; if (p.var == null) { @@ -272,6 +418,12 @@ void lcont1(XTerm p) { } } + /** + * Retrieves the initial term of the polynomial. + * + * @param p the polynomial term + * @return the initial term of the polynomial or null if not applicable + */ XTerm init(XTerm p) { DTerm dp1; if (p.var == null) return (null); @@ -279,6 +431,12 @@ XTerm init(XTerm p) { return (dp1.p); } + /** + * Retrieves a copy of the initial term of the polynomial. + * + * @param p the polynomial term + * @return a copy of the first term of the polynomial or null if not applicable + */ XTerm cp_init(XTerm p) { DTerm dp1; if (p.var == null) return (null); @@ -286,11 +444,25 @@ XTerm cp_init(XTerm p) { return (cp_poly(dp1.p)); } - + /** + * Initializes the polynomial with respect to the specified variable. + * + * @param p the polynomial term + * @param v the variable used for initialization + * @return the initialized polynomial term for the given variable + */ XTerm init_v(XTerm p, Var v) { return (pinit(p, v, pdeg(p, v))); } + /** + * Adjusts the polynomial by removing lower degree parts relative to the specified variable. + * + * @param p the polynomial term + * @param v the variable for initialization + * @param d the degree threshold + * @return the modified polynomial after initialization + */ XTerm pinit(XTerm p, Var v, int d) { DTerm dt, dp0, dp1, dp2; if (p.var == null) { @@ -337,12 +509,12 @@ XTerm pinit(XTerm p, Var v, int d) { return (psimp(p, dt.nx)); } - XTerm cp_rem(XTerm p) -//xterm p; - { - return (rem(cp_poly(p))); - } - + /** + * Computes the remainder of the polynomial by removing its first term. + * + * @param p the polynomial term + * @return the polynomial remainder as an XTerm + */ XTerm rem(XTerm p) //xterm p; { @@ -358,16 +530,12 @@ XTerm rem(XTerm p) return (psimp(p, dp2)); } - int mono_pol(XTerm p) { - DTerm ps; - while (p.var != null) { - ps = p.ps; - if (ps.nx != null) return (0); - p = ps.p; - } - return (1); - } - + /** + * Calculates the number of immediate terms in the polynomial. + * + * @param p the polynomial term + * @return the count of terms linked directly to the polynomial + */ int tlength(XTerm p) { DTerm dp1; int count = 0; @@ -383,17 +551,12 @@ int tlength(XTerm p) { return (count); } - int mlength(XTerm p) { - DTerm dp1; - int count = 0; - if (p.var != null) { - count++; - dp1 = p.ps; - p = dp1.p; - } - return (count); - } - + /** + * Computes the total number of subterms within the polynomial. + * + * @param p the polynomial term + * @return the total length of the polynomial, including nested subterms + */ int plength(XTerm p) { DTerm dp1; int count = 0; @@ -412,6 +575,12 @@ else if (p.var == null) return (count); } + /** + * Computes the length of the DTerm linked list representing differential terms. + * + * @param dp1 the head of the DTerm list + * @return the total number of DTerm nodes + */ int dlength(DTerm dp1) { int count = 0; while (dp1 != null) { @@ -421,26 +590,13 @@ int dlength(DTerm dp1) { return (count); } - boolean pless(XTerm p1, XTerm p2) { - if ((p1.var == null) && (p2.var == null)) - return (false); - else if (p1.var == null) - return (true); - else if (p2.var == null) - return (false); - else if (p1.var == p2.var) { - if (ldeg(p1) < ldeg(p2)) - return (true); - else if (ldeg(p1) > ldeg(p2)) - return (false); - else - return (plength(p1) < plength(p2)); - } else if (vless(p1.var, p2.var)) - return (true); - else - return (false); - } - + /** + * Compares two polynomial terms for ordering. + * + * @param p1 the first polynomial term + * @param p2 the second polynomial term + * @return true if the first polynomial is considered less than the second; false otherwise + */ boolean pls(XTerm p1, XTerm p2) { int k1, k2; if ((p1.var == null) && (p2.var == null)) @@ -466,6 +622,13 @@ else if (ldeg(p1) > ldeg(p2)) return (false); } + /** + * Simplifies the polynomial by updating its terms with the provided DTerm list. + * + * @param p1 the polynomial term to simplify + * @param dp0 the DTerm list used for simplification + * @return the simplified polynomial term + */ XTerm psimp(XTerm p1, DTerm dp0) { XTerm p; if (dp0 == null) { @@ -483,22 +646,15 @@ XTerm psimp(XTerm p1, DTerm dp0) { return (p1); } - - int bad_poly(XTerm p) { - DTerm ps; - if (p.var == null) return (bad_num(p.c)); - for (ps = p.ps; ps != null; ps = ps.nx) { - if (bad_poly(ps.p) != 0) return (1); - } - return (0); - } - - int bad_num(long n) { - return 0; - } - /* Polynomial Plus: destructive */ + /** + * Adds two polynomial terms. + * + * @param p1 the first polynomial term + * @param p2 the second polynomial term + * @return the sum of p1 and p2 as a new polynomial term + */ XTerm pplus(XTerm p1, XTerm p2) { DTerm dp1; XTerm xp1; @@ -533,6 +689,13 @@ XTerm pplus(XTerm p1, XTerm p2) { return (pcplus(p2, p1)); } + /** + * Merges two lists of polynomial terms represented as DTerm linked lists. + * + * @param dp1 the first DTerm list + * @param dp2 the second DTerm list + * @return the merged DTerm list representing the summed polynomial parts + */ DTerm pplus1(DTerm dp1, DTerm dp2) { DTerm firstd, dp0, dp3; @@ -572,7 +735,13 @@ DTerm pplus1(DTerm dp1, DTerm dp2) { return (firstd.nx); } - // c < p2 + /** + * Adds a constant polynomial term to a polynomial represented by a DTerm chain. + * + * @param c the constant polynomial term to add + * @param p2 the polynomial term (as an XTerm) to which to add the constant + * @return the resulting polynomial term after addition + */ XTerm pcplus(XTerm c, XTerm p2) { DTerm dp1, dp2; dp2 = new DTerm(); @@ -596,12 +765,25 @@ XTerm pcplus(XTerm c, XTerm p2) { /* Polynomial difference: destructive */ + /** + * Subtracts the second polynomial term from the first polynomial term destructively. + * + * @param p1 the polynomial term from which to subtract + * @param p2 the polynomial term to subtract + * @return the resulting polynomial term after subtraction + */ XTerm pminus(XTerm p1, XTerm p2) { XTerm q1; q1 = neg_poly(p2); return (pplus(p1, q1)); } + /** + * Negates a polynomial term destructively. + * + * @param p the polynomial term to negate + * @return the negated polynomial term + */ XTerm neg_poly(XTerm p) { DTerm dp1; if (p.var == null) { @@ -618,6 +800,13 @@ XTerm neg_poly(XTerm p) { /* polynomial times: destructive */ + /** + * Multiplies two polynomial terms destructively. + * + * @param p1 the first polynomial term + * @param p2 the second polynomial term + * @return the product polynomial term + */ XTerm ptimes(XTerm p1, XTerm p2) { DTerm dp1; if (p1.var == null) { @@ -648,6 +837,13 @@ XTerm ptimes(XTerm p1, XTerm p2) { return (pctimes(p2, p1)); } + /** + * Multiplies two DTerm polynomial parts and accumulates the result. + * + * @param dp1 the first DTerm list + * @param dp2 the second DTerm list + * @return the resulting DTerm list from the multiplication + */ DTerm ptimes1(DTerm dp1, DTerm dp2) //dterm dp1,dp2; { @@ -680,6 +876,13 @@ DTerm ptimes1(DTerm dp1, DTerm dp2) return (dp0); } + /** + * Multiplies a constant polynomial term with a polynomial represented as an XTerm. + * + * @param c the constant polynomial term + * @param p the polynomial term to multiply + * @return the resulting polynomial term after multiplication + */ XTerm pctimes(XTerm c, XTerm p) //xterm c,p; { @@ -693,6 +896,13 @@ XTerm pctimes(XTerm c, XTerm p) return (p); } + /** + * Raises a polynomial term to the specified integer power. + * + * @param p the polynomial term + * @param n the exponent + * @return the polynomial term raised to the power n + */ XTerm ppower(XTerm p, int n) { XTerm pp1 = get_n(1L); if (n <= 0) { @@ -711,6 +921,13 @@ XTerm ppower(XTerm p, int n) { return (ptimes(pp1, p)); } + /** + * Performs polynomial division when the divisor is a unit. + * + * @param p1 the dividend polynomial term + * @param p2 the divisor polynomial term + * @return the resulting polynomial term representing the remainder after division + */ XTerm ppdiv(XTerm p1, XTerm p2) { XTerm p3; if (unitp(p2)) return (p1); @@ -725,8 +942,14 @@ XTerm ppdiv(XTerm p1, XTerm p2) { /* polynomial division: destructive for p1 */ + /** + * Divides the first polynomial term by the second polynomial term destructively. + * + * @param p1 the dividend polynomial term + * @param p2 the divisor polynomial term + * @return the resulting polynomial term after division, or null if division is not possible + */ XTerm pdiv(XTerm p1, XTerm p2) -//xterm p1, p2; { DTerm dp1; @@ -768,9 +991,14 @@ XTerm pdiv(XTerm p1, XTerm p2) return (null); } - + /** + * Divides a polynomial term by a constant polynomial term. + * + * @param p the polynomial term to be divided + * @param c the constant polynomial term divisor + * @return the resulting polynomial term after division, or null if division is not possible + */ XTerm pcdiv(XTerm p, XTerm c) -//xterm p,c; { DTerm dp1; for (dp1 = p.ps; dp1 != null; dp1 = dp1.nx) { @@ -783,6 +1011,14 @@ XTerm pcdiv(XTerm p, XTerm c) return (p); } + /** + * Divides the polynomial represented by dp1 by dp2. + * Returns the quotient as a new DTerm or null if the division fails. + * + * @param dp1 the dividend polynomial as a DTerm structure + * @param dp2 the divisor polynomial as a DTerm structure + * @return the quotient polynomial as a DTerm, or null if division is not exact + */ DTerm pdiv1(DTerm dp1, DTerm dp2) { DTerm fird, qterm, dp0, dp3, dp4; XTerm lcf, qp; @@ -840,6 +1076,13 @@ DTerm pdiv1(DTerm dp1, DTerm dp2) { char init_deg; + /** + * Computes the polynomial remainder (prem) of p1 with respect to p2. + * + * @param p1 the dividend polynomial as an XTerm structure + * @param p2 the divisor polynomial as an XTerm structure + * @return the remainder polynomial as an XTerm, or a zero polynomial if p2 is null + */ XTerm prem(XTerm p1, XTerm p2) { init_deg = 0; if (p2.var == null) { @@ -852,6 +1095,14 @@ XTerm prem(XTerm p1, XTerm p2) { return (prem_var(p1, p2, p2.var)); } + /** + * Computes the polynomial remainder when both p1 and p2 share the same variable. + * Uses an evaluation-based approach. + * + * @param p1 the dividend polynomial as an XTerm structure + * @param p2 the divisor polynomial as an XTerm structure with the same variable as p1 + * @return the remainder polynomial as an XTerm, or null if the division is not exact + */ XTerm prem_ev(XTerm p1, XTerm p2) { DTerm dt1, dp1, dp2, dp3, dp4; XTerm ip1, ip2, pp1, pp2; @@ -926,6 +1177,14 @@ XTerm prem_ev(XTerm p1, XTerm p2) { return (null); } + /** + * Computes the polynomial remainder for p1 with respect to p2 when they have different variable orderings. + * + * @param p1 the dividend polynomial as an XTerm structure + * @param p2 the divisor polynomial as an XTerm structure + * @param v the variable used for division operations + * @return the remainder polynomial as an XTerm, or a zero polynomial if division is complete + */ XTerm prem_var(XTerm p1, XTerm p2, Var v) { XTerm ip0, ip1, ip2, u1, u2, v2; int deg1, deg2; @@ -970,57 +1229,45 @@ XTerm prem_var(XTerm p1, XTerm p2, Var v) { return (p1); } - void xerror(char ch) -//char *ch; - { - Cm.print("\n\n Syntax error:\n\n"); - // Cm.print(ch); - Cm.print("\n\n Please check your input.\n"); - } - -/* print polynomials */ - -// public void gprint(String s) -// { -// System.out.print(s); -// } - - void dprint(DTerm dp1) { - if (dp1 == null) - gprint("null\r\n"); - else { - while (dp1 != null) { - gprint("\r\n"); - print_ind(dp1.p); - gprint("\r\n"); - if (plength(dp1.p) < 20) pprint(dp1.p); - dp1 = dp1.nx; - } - } - } - + /** + * Prints the polynomial in a compact form. + * + * @param p1 the polynomial to be printed as an XTerm structure + */ final void xprint(XTerm p1) { print_p(p1, (char) 0); } + /** + * Prints the polynomial followed by a newline. + * + * @param p1 the polynomial to be printed as an XTerm structure + */ void pprint(XTerm p1) { print_p(p1, (char) 0); gprint("\r\n"); } - void eprint(XTerm p1) { - print_p(p1, (char) 0); - gprint("=0\r\n"); - } - static int char_no; - void print_p(XTerm p1, char mk) // print_pp1 + /** + * Prints the polynomial with a specified marker for formatting. + * + * @param p1 the polynomial to be printed as an XTerm structure + * @param mk the marker character to use during printing + */ + void print_p(XTerm p1, char mk) { char_no = 0; print_p1(p1, mk); } + /** + * Helper method that prints the polynomial in detailed format. + * + * @param p1 the polynomial to be printed as an XTerm structure + * @param mk the marker character used for formatting + */ void print_p1(XTerm p1, char mk) { DTerm dp1; XTerm xp1, xp2; @@ -1137,6 +1384,11 @@ else if (p1.var == null) { } + /** + * Prints the index information of the given polynomial. + * + * @param p the polynomial as an XTerm structure whose index is to be printed + */ void print_ind(XTerm p) { Var v; if (p == null) @@ -1161,44 +1413,40 @@ else if (pzerop(p)) { } - XTerm c_pplus(XTerm x, XTerm y) { - return pplus(cp_poly(x), cp_poly(y)); - } - - XTerm c_pminus(XTerm x, XTerm y) { - return pminus(cp_poly(x), cp_poly(y)); - } - - XTerm c_ptimes(XTerm x, XTerm y) { - return ptimes(cp_poly(x), cp_poly(y)); - } - - XTerm c_pdiv(XTerm x, XTerm y) { - return pdiv(cp_poly(x), y); - } - + /** + * Adds three polynomial terms. + * + * @param x the first polynomial term + * @param y the second polynomial term + * @param z the third polynomial term + * @return the sum of the three polynomial terms + */ XTerm pplus3(XTerm x, XTerm y, XTerm z) { return pplus(x, pplus(y, z)); } - XTerm ptimes3(XTerm x, XTerm y, XTerm z) { - return ptimes(x, ptimes(y, z)); - } - + /** + * Adds four polynomial terms. + * + * @param x the first polynomial term + * @param y the second polynomial term + * @param z the third polynomial term + * @param w the fourth polynomial term + * @return the sum of the four polynomial terms + */ XTerm pplus4(XTerm x, XTerm y, XTerm z, XTerm w) { return pplus(pplus(x, y), pplus(z, w)); } - XTerm ptimes4(XTerm x, XTerm y, XTerm z, XTerm w) { - return ptimes(ptimes(x, y), ptimes(z, w)); - } - -//----------------------------------------- -//-----------------------------------------var.cpp - - static Var svar = new Var(); + /** + * Compares two Var objects for equality based on their type and contents. + * + * @param v1 the first Var object + * @param v2 the second Var object + * @return true if the two variables are considered equal, false otherwise + */ boolean eq_var(Var v1, Var v2) { int i; if (v1.nm == 0 || v1.nm == 99) { @@ -1212,6 +1460,12 @@ boolean eq_var(Var v1, Var v2) { return (false); } + /** + * Creates a copy of the given Var object. + * + * @param v the Var object to copy + * @return a new Var object that is a copy of v + */ Var cp_var(Var v) { Var v1; int i; @@ -1225,6 +1479,12 @@ Var cp_var(Var v) { return (v1); } + /** + * Retrieves an existing Var object equal to the given one or adds a new one. + * + * @param v the Var object to add or look up + * @return an existing Var equal to v or a new copy if not found + */ Var ad_var(Var v) { Var v1; char i; @@ -1242,6 +1502,16 @@ Var ad_var(Var v) { return (v1); } + /** + * Constructs and adds a new Var object using the given parameters. + * + * @param nm the variable identifier + * @param p1 the first parameter + * @param p2 the second parameter + * @param p3 the third parameter + * @param p4 the fourth parameter + * @return the resulting Var object + */ Var mk_var(int nm, int p1, int p2, int p3, int p4) { svar.nm = nm; svar.pt[0] = p1; @@ -1251,22 +1521,13 @@ Var mk_var(int nm, int p1, int p2, int p3, int p4) { return (ad_var(svar)); } - Var mk_svar(char[] nm) { - char i; - for (i = 0; i < 9; i++) svar.p[i] = 0; - svar.nm = 0; - strcpy(svar.p, nm); - return (ad_var(svar)); - } - - Var mk_cvar(char[] nm) { - char i; - for (i = 0; i < 9; i++) svar.p[i] = 0; - strcpy(svar.p, nm); - svar.nm = 99; - return (ad_var(svar)); - } - + /** + * Creates a new "w" Var object by initializing its parameters to zero + * and setting its identifier based on the provided number. + * + * @param nm the input number determining the variable type + * @return the newly created Var object + */ Var mk_wvar(int nm) { for (int i = 0; i < 4; i++) svar.pt[i] = 0; if (nm > 0) @@ -1279,7 +1540,14 @@ Var mk_wvar(int nm) { return (ad_var(svar)); } - + /** + * Compares two integer arrays element-wise from index 0 to n. + * + * @param a1 the first integer array + * @param a2 the second integer array + * @param n the last index (inclusive) to compare + * @return 1 if the first differing element in a1 is less than in a2, otherwise 0 + */ int ials(int a1[], int a2[], int n) { char i; for (i = 0; i <= n; ++i) { @@ -1290,6 +1558,13 @@ int ials(int a1[], int a2[], int n) { return (0); } + /** + * Determines the maximum point value from a Var object's point array + * based on the variable type. + * + * @param v the Var object to evaluate + * @return the maximum value among the relevant point entries + */ int lpt(Var v) { int k = v.pt[0]; if (v.nm == 1) { @@ -1300,6 +1575,13 @@ int lpt(Var v) { return (k); } + /** + * Compares two Var objects for ordering based on type and point values. + * + * @param v1 the first Var object + * @param v2 the second Var object + * @return true if v1 is considered less than v2, false otherwise + */ boolean vless(Var v1, Var v2) { int m, l1, l2; @@ -1388,6 +1670,12 @@ else if (v1.nm < v2.nm) return (m != 0); } + /** + * Extracts a linked list of unique variables present in the given polynomial term. + * + * @param p the polynomial term represented as an XTerm + * @return the head of a linked list of distinct Var objects from p + */ XTerm vars_in_p(XTerm p) { DTerm ps1; XTerm p0, p1, p2; @@ -1432,14 +1720,12 @@ XTerm vars_in_p(XTerm p) { return (p0); } - - void print_vars(Var v, char mk) { - while (v != null) { - print_var(v, mk); - v = v.nx; - } - } - + /** + * Prints the variable using a specific format determined by its type and mode. + * + * @param v the Var object to print + * @param mk the mode flag determining the format + */ void print_var(Var v, int mk) { switch (v.nm) { case 0: @@ -1596,263 +1882,13 @@ void print_var(Var v, int mk) { } } -// void print_fang(int p1, int p2, int p3, int p4) -// { -// int p0; -// if (p1 == p4) -// { -// p0 = p4; -// p4 = p3; -// p3 = p0; -// } else if (p2 == p3) -// { -// p0 = p1; -// p1 = p2; -// p2 = p0; -// } else if (p2 == p4) -// { -// p0 = p1; -// p1 = p2; -// p2 = p0; -// p0 = p4; -// p4 = p3; -// p3 = p0; -// } -//// sprintf(txt, "%s[%s%s,%s%s]", Cm.s2078), -//// pt_name(p1), pt_name(p2), pt_name(p3), pt_name(p4)); -// gprint(Cm.s2078 + "["); -// } - + /** + * Prints a point identifier using the established naming conventions. + * + * @param p the point identifier + */ void print_pt(int p) { //sprintf(txt,"%s",pt_name(p)); gprint(pt_name(p)); } - -/////--------------------------------------------------getp.cpp - - static DTerm p_stk = new DTerm(); - public static int gno; - - public XTerm rd_pol(String sterm[]) { - - gno = 0; - int nterm = sterm.length; - DTerm ps1; - - p_stk.nx = null; - if (strcmp(sterm[gno], "-") == 0 || strcmp(sterm[gno], "+") == 0) { - p_stk.nx = get_dt(1, get_n(0L), p_stk.nx); - } - - - ps1 = p_stk.nx; - while (gno < nterm && strcmp(sterm[gno], ";") != 0 && - strcmp(sterm[gno], "=") != 0 && strcmp(sterm[gno], ".") != 0)// && (in_hyp == 0 || (ps1 != null && !(ps1.nx == null && ps1.deg == 1)))) - { - - if (strcmp(sterm[gno], "(") == 0) { - if (ps1 != null && ps1.deg == 1) { - do_it(6); - gno--; - } - p_stk.nx = get_dt(2, null, p_stk.nx); - gno++; - if (strcmp(sterm[gno], "-") == 0 || strcmp(sterm[gno], "+") == 0) { - p_stk.nx = get_dt(1, get_n(0L), p_stk.nx); - } - } else if (strcmp(sterm[gno], ")") == 0) { - do_it(3); - } else if (strcmp(sterm[gno], "+") == 0) { - do_it(4); - } else if (strcmp(sterm[gno], "-") == 0) { - do_it(5); - } else if (strcmp(sterm[gno], "*") == 0) { - do_it(6); - } else if (strcmp(sterm[gno], "/") == 0) { - do_it(7); - } else if (strcmp(sterm[gno], "^") == 0) { - do_it(8); - } else if (num_ch(sterm[gno])) { - if (ps1 != null && ps1.deg == 1) { - do_it(6); - } - p_stk.nx = get_dt(1, get_n(ch2num(sterm[gno])), p_stk.nx); - gno++; - } else { - if (ps1 != null && ps1.deg == 1) - do_it(6); - else - gno++; - p_stk.nx = get_dt(1, get_m(mk_svar(sterm[gno - 1].toCharArray())), p_stk.nx); - } - ps1 = p_stk.nx; - } - - if (gno > nterm) { - gerror(" expression error\n"); - return (null); - } - do_it(0); - return (ps1.p); - } - - - public void doother(String[] sterm) { - // if (strcmp(sterm[gno], Cm.s3000) == 0) { - //cannot dela with (RATIO B F F C)<- -// p_stk.nx = get_dt(1, trim_r(fptno(gno + 1), fptno(gno + 2), fptno(gno + 3), fptno(gno + 4)), p_stk.nx); -// gno += 5; -// } else if (strcmp(sterm[gno], Cm.s3001) == 0) { -// //gao need -// p_stk.nx = get_dt(1, trim_f(fptno(gno + 1), fptno(gno + 2), fptno(gno + 3), fptno(gno + 4)), p_stk.nx); -// gno += 5; -// } else if (strcmp(sterm[gno], Cm.s3002) == 0) { -// if (strcmp(sterm[gno + 4], ")") == 0) { -// p_stk.nx = get_dt(1, trim_a(fptno(gno + 1), fptno(gno + 2), fptno(gno + 3), fptno(gno + 3)), p_stk.nx); -// gno += 4; -// } else if (strcmp(sterm[gno + 5], ")") == 0) { -// p_stk.nx = get_dt(1, trim_a(fptno(gno + 1), fptno(gno + 2), fptno(gno + 3), fptno(gno + 4)), p_stk.nx); -// gno += 5; -// } else -// gerror("area is not proper"); -// } else if (strcmp(sterm[gno], Cm.s3008) == 0) { -// if (strcmp(sterm[gno + 4], ")") == 0) { -// p_stk.nx = get_dt(1, trim_g(fptno(gno + 1), fptno(gno + 2), fptno(gno + 2), fptno(gno + 3)), p_stk.nx); -// gno += 4; -// } else if (strcmp(sterm[gno + 5], ")") == 0) { -// p_stk.nx = get_dt(1, trim_g(fptno(gno + 1), fptno(gno + 2), fptno(gno + 3), fptno(gno + 4)), p_stk.nx); -// gno += 5; -// } else -// gerror("py is not proper"); -// } else if (strcmp(sterm[gno], Cm.s3003) == 0) { -// p_stk.nx = get_dt(1, trim_g(fptno(gno + 1), fptno(gno + 2), fptno(gno + 2), fptno(gno + 1)), p_stk.nx); -// gno += 3; -// } else if (strcmp(sterm[gno], Cm.s3004) == 0) { -// if (strcmp(sterm[gno + 2], ")") == 0) { -// p_stk.nx = get_dt(1, trim_vec(fptno(gno + 1), 0), p_stk.nx); -// gno += 2; -// } else if (strcmp(sterm[gno + 3], ")") == 0) { -// p_stk.nx = get_dt(1, trim_vec(fptno(gno + 1), fptno(gno + 2)), p_stk.nx); -// gno += 3; -// } else -// gerror("vector is not proper"); -// } else if (strcmp(sterm[gno], Cm.s3009) == 0) { -// p_stk.nx = get_dt(1, trim_l(fptno(gno + 1), fptno(gno + 2)), p_stk.nx); -// gno += 3; -// } else if (strcmp(sterm[gno], Cm.s3005) == 0) { -// p_stk.nx = get_dt(1, -// ptimes(trim_r(fptno(gno + 3), fptno(gno + 1), fptno(gno + 3), fptno(gno + 2)), -// trim_r(fptno(gno + 4), fptno(gno + 2), fptno(gno + 4), fptno(gno + 1))), -// p_stk.nx); -// gno += 5; -// } else if (num_ch(sterm[gno])) { -// if (ps1 != null && ps1.deg == 1) { -// do_it(6); -// } -// p_stk.nx = get_dt(1, get_n(ch2num(sterm[gno])), p_stk.nx); -// gno++; -// } else { -// if (ps1 != null && ps1.deg == 1) -// do_it(6); -// else -// gno++; -// p_stk.nx = get_dt(1, get_m(mk_svar(sterm[gno - 1])), p_stk.nx); -// } - } - - void do_it(int op) { - DTerm ps1, ps2, ps3; - XTerm p1; - int deg; - - - ps1 = p_stk.nx; - if (ps1 == null) { - p_stk.nx = get_dt(op, null, p_stk.nx); - return; - } - - if (ps1.deg == 2) { - if (op == 3) { - p_stk.nx = ps1.nx; - put_d(ps1); - } else - p_stk.nx = get_dt(op, null, p_stk.nx); - gno++; - return; - } - - if (ps1.deg != 1) gerror("expresion error 13"); - ps2 = ps1.nx; - while (ps2 != null && ps2.deg >= op) { - ps3 = ps2.nx; - if (ps3 == null) { - if (ps2.deg != 2) gerror("expression error 14"); - ps1.nx = ps2.nx; - put_d(ps2); - } else if (ps3.deg == 2) { - if (ps2.deg == 4) - ps1.p = neg_poly(ps1.p); - else if (ps2.deg != 3) gerror("expression error15"); - ps1.nx = ps3.nx; - put_d(ps3); - put_d(ps2); - } else if (ps2.deg == 4) { - ps1.p = pplus(ps1.p, ps3.p); - ps1.nx = ps3.nx; - put_d(ps2); - put_d(ps3); - } else if (ps2.deg == 5) { - ps1.p = pminus(ps3.p, ps1.p); - ps1.nx = ps3.nx; - put_d(ps2); - put_d(ps3); - } else if (ps2.deg == 6) { - ps1.p = ptimes(ps1.p, ps3.p); - ps1.nx = ps3.nx; - put_d(ps2); - put_d(ps3); - } else if (ps2.deg == 8) { - p1 = ps1.p; - if (p1.var != null) gerror("expression error"); - deg = num_int(p1.c); - ps1.p = ppower(ps3.p, deg); - ps1.nx = ps3.nx; - put_d(ps2); - put_d(ps3); - } else { - gerror("expression error 99"); - return; - } - ps2 = ps1.nx; - } - if (op == 3) { - if (ps2 == null || ps2.deg != 2) gerror("expression error 17"); - ps1.nx = ps2.nx; - put_d(ps2); - gno++; - } else if (op > 3) { - p_stk.nx = get_dt(op, null, p_stk.nx); - gno++; - } - - } - - - boolean num_ch(String sn) { - byte[] ch = sn.getBytes(); - int i = 0; - if (ch[i] == '-') - i++; - else if (ch[i] == '+') i++; - while (i < ch.length && ch[i] != '\0') { - if (ch[i] < '0' || ch[i] > '9') return (false); - i++; - } - return (true); - } - - long ch2num(String sn) { - return Integer.parseInt(sn); - } } diff --git a/src/main/java/gprover/Polygon.java b/src/main/java/gprover/Polygon.java index 316529da..ef69e7f5 100644 --- a/src/main/java/gprover/Polygon.java +++ b/src/main/java/gprover/Polygon.java @@ -1,11 +1,7 @@ package gprover; /** - * Created by IntelliJ IDEA. - * User: ye - * Date: Nov 6, 2006 - * Time: 10:22:42 PM - * To change this template use File | Settings | File Templates. + * Represents a polygon in a geometric construction. */ public class Polygon extends CClass { int lemma; @@ -16,10 +12,19 @@ public class Polygon extends CClass { Polygon nx; + /** + * Constructs a Polygon object with default values. + */ public Polygon() { lemma = o = 0; co = null; } + + /** + * Constructs a Polygon object with a specified type. + * + * @param t the type of the polygon + */ public Polygon(int t) { qtype = t; lemma = o = 0; diff --git a/src/main/java/gprover/ProPoint.java b/src/main/java/gprover/ProPoint.java index 92a00c61..b5e16c31 100644 --- a/src/main/java/gprover/ProPoint.java +++ b/src/main/java/gprover/ProPoint.java @@ -1,12 +1,14 @@ -/** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2006-2-15 - * Time: 14:18:38 - * To change this template use File | Settings | File Templates. - */ package gprover; +/** + * Represents a point used in geometric constructions. + *

+ * This class stores geometric properties including coordinates, + * auxiliary data, and arrays that represent point states. + * It provides methods for setting point attributes and retrieving + * coordinate information. + *

+ */ public class ProPoint { final public static int MAX_GEO = 30; @@ -30,10 +32,6 @@ public ProPoint(int t) { type = t; } - public int getAux() { - return aux; - } - void setPS(int value, int index) { if (type1 == 0) { if (ps.length <= index) { @@ -60,30 +58,6 @@ void setType(int t) { type1 = t; } - void set(int Type, int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8) { - if (type == 0) { - type = Type; - ps[0] = p1; - ps[1] = p2; - ps[2] = p3; - ps[3] = p4; - ps[4] = p5; - ps[5] = p6; - ps[6] = p7; - ps[7] = p8; - } else { - type1 = Type; - ps[0] = p1; - ps[1] = p2; - ps[2] = p3; - ps[3] = p4; - ps[4] = p5; - ps[5] = p6; - ps[6] = p7; - ps[7] = p8; - } - } - public ProPoint(int t, String s) { type = t; name = s; @@ -147,17 +121,11 @@ public String getName() { return name; } + @Override public String toString() { return name; } - public void add_nd(Cond c) { - if (co == null) - co = c; - c.nx = co; - co = c; - } - public String getText() { return text; } diff --git a/src/main/java/gprover/Prover.java b/src/main/java/gprover/Prover.java index 4f4958e2..21ee9c18 100644 --- a/src/main/java/gprover/Prover.java +++ b/src/main/java/gprover/Prover.java @@ -2,20 +2,36 @@ import java.util.Vector; - +/** + * The Prover class provides static methods for performing geometric proofs and computations. + * It manages the state of geometric terms and interacts with the geometric database. + * + *

This class is not instantiable.

+ */ public class Prover { private static GDDBc db = null; private static Full dbfull = null; private static GTerm gt = null; private static boolean aux = false; + /** + * Private constructor to prevent instantiation. + */ private Prover() { } + /** + * Sets the global geometric term. + * + * @param g the geometric term to set + */ public static void set_gterm(GTerm g) { gt = g; } + /** + * Resets the internal database and state. + */ public static void reset() { db = null; dbfull = null; @@ -23,29 +39,55 @@ public static void reset() { aux = false; } + /** + * Executes a fixpoint computation on the current geometric term. + */ public static void run() { fixpoint(gt); } + /** + * Retrieves the name of the point corresponding to the specified identifier. + * + * @param t the point identifier + * @return the point name, or "null" if the database is not initialized + */ public static String get_pt_name(int t) { if (db == null) return "null"; return db.ANAME(t); } + /** + * Retrieves the identifier of the point corresponding to the specified name. + * + * @param s the point name + * @return the point identifier, or 0 if the database is not initialized + */ public static int get_pt_id(String s) { if (db == null) return 0; return db.SPT(s); } + /** + * Retrieves the total number of properties in the database. + * + * @return the number of properties, or 0 if the database is not initialized + */ public static int getNumberofProperties() { if (db == null) return 0; return db.getNumberofProperties(); } + /** + * Initializes the database and performs a fixpoint computation using the provided geometric term. + * + * @param gt the geometric term used for the computation + * @return true if the fixpoint computation is successful, false otherwise + */ public static boolean fixpoint(GTerm gt) { try { db = new GDDBc(); @@ -61,6 +103,11 @@ public static boolean fixpoint(GTerm gt) { return true; } + /** + * Attempts to prove the current geometric term. + * + * @return true if the proof is successful, false otherwise + */ public static boolean prove() { try { aux = false; @@ -88,11 +135,22 @@ public static boolean prove() { } } + /** + * Retrieves the constructed auxiliary point if one was created during the proof. + * + * @return the auxiliary point if available, or null otherwise + */ public static AuxPt getConstructedAuxPoint() { if (!aux) return null; return db.axptc; } + /** + * Attempts to prove the provided geometric condition. + * + * @param co the condition to prove + * @return true if the condition is successfully proved, false otherwise + */ public static boolean prove(Cond co) { try { if (db == null) @@ -111,19 +169,27 @@ public static boolean prove(Cond co) { } } - public static boolean isfixed() { - return db != null; - } - + /** + * Retrieves the current geometric database. + * + * @return the current GDDBc instance + */ public static GDDBc get_gddbase() { return db; } + /** + * Sets the global database to the full geometric base. + */ public static void setGIB() { db = dbfull; } - + /** + * Returns the head of the proof condition. + * + * @return the current proof condition head as a Cond object, or null if the database is not initialized. + */ public static Cond getProveHead() { try { if (db != null) { @@ -139,23 +205,46 @@ public static Cond getProveHead() { } + /** + * Retrieves the next proof head in the given list. + * + * @param ls the current list of proof heads + * @return the next LList proof head from the database + */ public static LList getProveHead_ls(LList ls) { return db.get_next_ls_prove_head(ls); } + /** + * Searches for a fact matching the provided criteria. + * + * @param t the type of fact to search for + * @param s1 the first search parameter + * @param s2 the second search parameter + * @param s3 the third search parameter + * @return a Vector of matching facts + */ public static Vector search_a_fact(int t, String s1, String s2, String s3) { return db.search_a_fact(t, s1, s2, s3); } -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - + /** + * Retrieves and displays the full conclusion from the geometric term. + * + * @return the full conclusion as a Cond object + */ public static Cond getFullconc() { Cond co = gt.getConc(); dbfull.show_pred(co); return co; } + /** + * Proves the full angle expression for the specified geometric term. + * + * @param gt the geometric term to prove + * @return the GrTerm representing the full angle proof head, or null if proof fails + */ public static GrTerm proveFull(GTerm gt) { try { @@ -178,6 +267,16 @@ public static GrTerm proveFull(GTerm gt) { } } + /** + * Retrieves all nondiscussed geometric statements and stores them in the provided vectors. + * + * @param gt the geometric term to process + * @param v1 vector to store the first group of statements + * @param v2 vector to store the second group of statements + * @param v3 vector to store the third group of statements + * @param v4 vector to store the fourth group of statements + * @return true if the nondiscussed statements were successfully retrieved; false otherwise + */ public static boolean getAllNdgs(GTerm gt, Vector v1, Vector v2, Vector v3, Vector v4) { try { Prover.gt = gt; @@ -195,10 +294,11 @@ public static boolean getAllNdgs(GTerm gt, Vector v1, Vector v2, Vector v3, Vect } } - public static boolean isFullAngleProvedTrue() { - return dbfull.isProvedTrue(); - } - + /** + * Returns the result of the full angle proof. + * + * @return 0 if the proof is successful, 1 if it fails, or 2 if it cannot be expressed as a full angle expression + */ public static int getPFullResult() { if (dbfull.isProvedTrue()) { return 0; // true @@ -207,48 +307,21 @@ public static int getPFullResult() { else return 2; // can not be expressed as full angle expression. } + /** + * Retrieves the error type code from the full angle proof. + * + * @return an integer representing the error type + */ public static int getErrorType() { return dbfull.getErrorType(); } - public static void showFullPred(Cond co) { - try { - Cond c = new Cond(co); - dbfull.conc = c; - if (dbfull.docc()) - dbfull.show_fproof(); - dbfull.print_prooftext(); - return; - } catch (Exception e) { - System.out.println("Exception on gprover.Prover: \n" + e.getMessage()); - return; - } - } - - public static int getAngleNum() { - if (dbfull == null) return 0; - return dbfull.getvarNum(); - } - - public static int getLnNum() { - if (dbfull == null) return 0; - return dbfull.getlnNum(); - } - + /** + * Displays the condition text for the given proof condition. + * + * @param co the condition to be displayed + */ public static void showCondTextF(Cond co) { dbfull.show_pred(co); } - - public static void showCondText(Cond co) { - if (db != null) - db.show_pred(co); - } - - public static GrTerm proveArea(Vector v) { - return null; - } - - ///////////////////////////////////////////////////// - /// angle deduction. - } diff --git a/src/main/java/gprover/RatioSeg.java b/src/main/java/gprover/RatioSeg.java index 973cb986..4b6c11c5 100644 --- a/src/main/java/gprover/RatioSeg.java +++ b/src/main/java/gprover/RatioSeg.java @@ -1,12 +1,8 @@ -/** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2006-2-14 - * Time: 21:35:50 - * To change this template use File | Settings | File Templates. - */ package gprover; +/** + * Represents a ratio segment in a geometric construction. + */ public class RatioSeg extends CClass { // int type; int lemma; @@ -14,18 +10,16 @@ public class RatioSeg extends CClass { public int[] r; RatioSeg nx; + /** + * The Prover class provides static methods for performing geometric proofs and computations. + * It manages the state of geometric terms and interacts with the geometric database. + * + *

This class is not instantiable.

+ */ public RatioSeg() { type = lemma = 0; co = null; r = new int[MAX_GEO]; nx = null; } - - public void cp_ratio(RatioSeg ra) { - lemma = ra.lemma; - for (int i = 0; i <= 8; i++) - r[i] = ra.r[i]; - } - - } diff --git a/src/main/java/gprover/Rule.java b/src/main/java/gprover/Rule.java index b48abb62..289f2362 100644 --- a/src/main/java/gprover/Rule.java +++ b/src/main/java/gprover/Rule.java @@ -1,38 +1,69 @@ package gprover; +/** + * Represents a rule in a geometric construction. + */ public class Rule extends CClass { + /** Constant for split angle type. */ public final static int SPLIT_ANGLE = 0; + + /** Constant for P angle type. */ public final static int P_ANGLE = 1; + + /** Constant for T angle type. */ public final static int T_ANGLE = 2; + + /** Constant for external angle type. */ public final static int EX_ANGLE = 3; - public final static int EQ_ANGLE = 4; + /** Constant for equal angle type. */ + public final static int EQ_ANGLE = 4; + /** The type of the rule. */ int type; + + /** The number associated with the rule. */ int no; + + /** Array of Mnde objects associated with the rule. */ public Mnde[] mr1 = new Mnde[5]; - public Mnde mr; + /** The main Mnde object associated with the rule. */ + public Mnde mr; + /** Reference to the next Rule object. */ Rule nx; + + /** + * Constructs a Rule object with a specified type. + * + * @param t the type of the rule + */ public Rule(int t) { type = t; nx = null; mr = null; } - public void cp_rule(Rule r) - { + /** + * Copies the properties of another Rule object to this Rule object. + * + * @param r the Rule object to copy from + */ + public void cp_rule(Rule r) { type = r.type; no = r.no; - for(int i=0; i <5 ; i++) + for (int i = 0; i < 5; i++) mr1[i] = r.mr1[i]; } - public String toString() - { + /** + * Returns a string representation of the rule. + * + * @return a string representation of the rule + */ + public String toString() { return " because " + text; } - -} +} \ No newline at end of file diff --git a/src/main/java/gprover/Rules.java b/src/main/java/gprover/Rules.java index 3da2f90f..8050b273 100644 --- a/src/main/java/gprover/Rules.java +++ b/src/main/java/gprover/Rules.java @@ -1,5 +1,11 @@ package gprover; +/** + * Rules class holds the translated geometric rules and full angle definitions. + * The arrays defined in this class provide language-specific translations for + * geometric construction rules and full angle definitions. These translations are + * integrated with a gettext-based internationalization system. + */ public class Rules { // All of these translations are now in the keys.pot and *.po files in the gettext system. diff --git a/src/main/java/gprover/STris.java b/src/main/java/gprover/STris.java index b226f5cd..ce826ca0 100644 --- a/src/main/java/gprover/STris.java +++ b/src/main/java/gprover/STris.java @@ -1,11 +1,6 @@ package gprover; - /** - * Created by IntelliJ IDEA. - * User: ye - * Date: Oct 23, 2006 - * Time: 10:45:54 AM - * To change this template use File | Settings | File Templates. + * Constructs a SimTri object with default values. */ public class STris extends CClass { static int MAX_TRI = 300; @@ -18,6 +13,9 @@ public class STris extends CClass { STris nx; + /** + * Constructs an STris object with default values. + */ public STris() { type = 0; dr = new int[300]; diff --git a/src/main/java/gprover/SimTri.java b/src/main/java/gprover/SimTri.java index 14105e58..94e9cff7 100644 --- a/src/main/java/gprover/SimTri.java +++ b/src/main/java/gprover/SimTri.java @@ -1,12 +1,11 @@ -/** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2006-2-14 - * Time: 21:35:25 - * To change this template use File | Settings | File Templates. - */ package gprover; +/** + * Rules class holds the translated geometric rules and full angle definitions. + * The arrays defined in this class provide language-specific translations for + * geometric construction rules and full angle definitions. These translations are + * integrated with a gettext-based internationalization system. + */ public class SimTri extends CClass { int lemma; Cond co; @@ -18,6 +17,9 @@ public class SimTri extends CClass { SimTri nx; + /** + * Constructs a SimTri object with default values. + */ public SimTri() { type = lemma = 0; co = null; diff --git a/src/main/java/gprover/TLine.java b/src/main/java/gprover/TLine.java index 82539a98..e6aca36c 100644 --- a/src/main/java/gprover/TLine.java +++ b/src/main/java/gprover/TLine.java @@ -1,23 +1,28 @@ -/** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2006-2-14 - * Time: 21:33:44 - * To change this template use File | Settings | File Templates. - */ package gprover; +/** + * Constructs an STris object with default values. + */ public class TLine extends CClass { int lemma; Cond co; public LLine l1, l2; TLine nx; + /** + * Constructs a TLine object with specified line segments. + * + * @param l1 the first line segment + * @param l2 the second line segment + */ public TLine(LLine l1, LLine l2) { this.l1 = l1; this.l2 = l2; } + /** + * Constructs a TLine object with default values. + */ public TLine() { type = lemma = 0; co = null; diff --git a/src/main/java/gprover/Var.java b/src/main/java/gprover/Var.java index 1fa309c8..afe48946 100644 --- a/src/main/java/gprover/Var.java +++ b/src/main/java/gprover/Var.java @@ -1,11 +1,8 @@ package gprover; /** - * Created by IntelliJ IDEA. - * User: yezheng - * Date: 2006-4-14 - * Time: 13:31:19 - * To change this template use File | Settings | File Templates. + * The Var class represents a variable in a geometric context. + * It includes properties for the variable's name, points, and a string representation. */ public class Var { int nm; @@ -15,10 +12,20 @@ public class Var { String sd = null; - public Var() { - - } - + /** + * Constructs a Var object with default values. + */ + public Var() { } + + /** + * Constructs a Var object with specified values. + * + * @param n the name of the variable + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @param p4 the fourth point + */ public Var(int n, int p1, int p2, int p3, int p4) { nm = n; pt[0] = p1; @@ -27,28 +34,19 @@ public Var(int n, int p1, int p2, int p3, int p4) { pt[3] = p4; } - public void revert() { - int k = pt[0]; - pt[0] = pt[2]; - pt[2] = k; - - k = pt[1]; - pt[1] = pt[3]; - pt[3] = k; - } - - public Var(Var v) { - nm = v.nm; - pt[0] = v.p[0]; - pt[1] = v.p[1]; - pt[2] = v.p[2]; - pt[3] = v.p[3]; - } - + /** + * Returns the string representation of the variable. + * + * @return the string representation of the variable + */ + @Override public String toString() { return sd; } + /** + * Constructs a TLine object with default values. + */ public void setString(String s) { sd = s; } diff --git a/src/main/java/gprover/Wu.java b/src/main/java/gprover/Wu.java deleted file mode 100644 index 6c68e612..00000000 --- a/src/main/java/gprover/Wu.java +++ /dev/null @@ -1,895 +0,0 @@ -package gprover; - -/** - * Created by IntelliJ IDEA. - * User: ye - * Date: Jan 9, 2007 - * Time: 12:08:27 PM - * To change this template use File | Settings | File Templates. - */ -public class Wu extends Poly { - static boolean div_factor = true; - static boolean del_linear = false; - static char pri_ind; - static XTerm[] inits; - DTerm l_set, div_set, tri_set, conc_set, conc_cp; - boolean print_pind; - int max_termp, max_term, vec_co = 0; - - - void prove_wu() { - DTerm dp1, dp2; - - get_divs(); - l_set.nx = null; - lt_set(); - tri_set.nx = prem_ps_asc(tri_set.nx, l_set.nx); - dp1 = conc_set.nx; - while (dp1 != null) { - dp1.p = prem_asc(dp1.p, l_set.nx); - dp1 = dp1.nx; - } - - dp1 = tri_set.nx; - while (dp1 != null) { - dp1.p = cprim(dp1.p); - dp1 = dp1.nx; - } - dp1 = conc_set.nx; - while (dp1 != null) { - dp1.p = cprim(dp1.p); - dp1 = dp1.nx; - } - - if (print_pind && l_set.nx != null) { -// gprint(Cm.s2830); -// dprint(l_set.nx); -// gprint(Cm.s2831); -// dprint(tri_set.nx); -// gprint(Cm.s2832); -// dprint(conc_set.nx); - } - - pri_ind = 1; - if (print_pind) { -// gprint(Cm.s2833)); - } - - - dp1 = conc_set.nx; - if (print_pind) { - print_ind(dp1.p); - gprint("\r\n"); - } - for (; dp1 != null; dp1 = dp1.nx) { - dp1.deg = 1; - dp2 = prem_asc_p(dp1.p, tri_set.nx); - dp1.p = null; - if (dp2 == null) { - dp1.deg = 1; - } else { - dp1.deg = 0; - put_ps(dp2); - } - } - show_conc(); - } - - void show_conc() { - DTerm dp1 = conc_set.nx; - int count = 1; - while (dp1 != null) { - if (dp1.deg == 0) count = 0; - dp1 = dp1.nx; - } - //gprint("\n***************The results****************\n"); - if (count != 0) { -// pro_result = 1; -// gprint("\r\n"); -// gprint(Cm.s2050)); - } else { -// pro_result = -1; -// gprint("\r\n"); -// if (irr_thm()) -// gprint(Cm.s2056)); -// else -// gprint(Cm.s2051)); - - } - } - - - void get_divs() { - char i, k; - DTerm dp1, dp2; - - for (i = 0; i < 50; i++) inits[i] = null; - k = 2; - dp1 = tri_set.nx; - if (dp1 == null) return; - dp2 = dp1.nx; - while (dp2 != null) { - if ((dp1.deg == 1) && (dp2.deg == 2)) { - inits[++k] = cp_init(dp1.p); - dp2.deg = k; - } else - dp2.deg = 0; - dp1 = dp2; - dp2 = dp2.nx; - } - } - - void lt_set() { - DTerm dp1, dp2, dp3; - dp1 = tri_set; - dp2 = dp1.nx; - l_set.nx = null; - dp3 = l_set; - while (dp2 != null) { - if (del_linear && (ldeg(dp2.p) == 1) && (numberp(init(dp2.p)))) { - dp1.nx = dp2.nx; - dp3.nx = dp2; - dp3 = dp3.nx; - dp2 = dp1.nx; - } else if (plength(dp2.p) > 2) { - dp1 = dp2; - dp2 = dp1.nx; - } else if (ldeg(dp2.p) != 1) { - dp1 = dp2; - dp2 = dp1.nx; - } else { - dp1.nx = dp2.nx; - dp3.nx = dp2; - dp3 = dp2; - dp2 = dp1.nx; - } - } - dp3.nx = null; - } - - XTerm prem_asc(XTerm p, DTerm asc) { - DTerm dp1; - for (dp1 = asc; dp1 != null; dp1 = dp1.nx) { - p = cprim(prem(p, dp1.p)); - } - return (p); - } - - DTerm prem_ps_asc(DTerm ps, DTerm asc) { - DTerm dt1, dp1, dp2; - if (asc == null) return (ps); - - dt1 = new DTerm(); - dt1.nx = ps; - dp1 = dt1; - dp2 = dp1.nx; - while (dp2 != null) { - dp2.p = mv_nfact(prem_asc(dp2.p, asc)); - if (pzerop(dp2.p)) { - dp1.nx = dp2.nx; - put_x(dp2.p); - put_d(dp2); - dp2 = dp1.nx; - } else { - dp1 = dp2; - dp2 = dp1.nx; - } - } - return (dt1.nx); - } - -/* prem-asc_p: the branching version */ - DTerm prem_asc_p(XTerm p, DTerm asc) -//xterm p; -//dterm asc; - { - XTerm a1, p1, p2; - DTerm dt1, dp1, dp2, dp3; - int tem; - - if (p == null) return (null); - if (pzerop(p)) { - put_p(p); - return (null); - } else if (p.var == null) { - return (get_dt(0, p, null)); - } - - dt1 = new DTerm(); - dt1.nx = get_dt(1, p, null); - /*at.deg=0; at.nx=asc; asc0= &at; */ - for (; asc != null; asc = asc.nx) { - a1 = asc.p; -// pprint(a1);gprint(" 1\r\n"); - dp1 = dt1; - dp2 = dp1.nx; - while (dp2 != null) { - p1 = dp2.p; - //pprint(p1);gprint(" 2\r\n"); - //sprintf(txt,"(%d)(%d)\r\n",a1->var,p1->var); - //gprint(txt); - if (pzerop(p1)) { - dp1.nx = dp2.nx; - put_x(p1); - put_d(dp2); - dp2 = dp1.nx; - } else if (p1.var == null) { - dp1 = dp2; - dp2 = dp1.nx; - } else if (p1.var == a1.var) { - /*printf("prem-asc-p1(%d)\n",plength(p1)); */ - p2 = prem_ev(p1, a1); - /*printf("prem-asc-p2(%d)\n",plength(p2)); */ - dp2.p = cprim(p2); - /*printf("prem-asc-p3(%d)\n",plength(dp2->p)); */ - /*dp2->p=cprim(prem_ev(p1,a1)); */ - /* printf("prem-asc-p1\n"); pprint(dp2->p);pprint(a1); */ - if (print_pind && dp2.deg == 1) { - if (pzerop(dp2.p)) { - if (pri_ind == 1) { - print_ind(dp2.p); - gprint("\r\n"); - pri_ind = 0; - } - } else { - print_ind(dp2.p); - gprint("\r\n"); - } - } - if (pzerop(dp2.p)) { - dp1.nx = dp2.nx; - put_x(dp2.p); - put_d(dp2); - dp2 = dp1.nx; - } else { - if (max_termp > 0) { - tem = plength(dp2.p); - if (tem > max_term) max_term = tem; - } - if (div_factor && asc.deg > 2) { -/* printf("1111(%d)\n",asc->deg); pprint(inits[asc->deg]); */ - p2 = mv_mfact(prem_asc(cp_poly(inits[asc.deg]), l_set.nx)); - dp2.p = ppdiv(dp2.p, p2); - put_p(p2); - } - dp1 = dp2; - dp2 = dp1.nx; - } - } else if (vless(a1.var, p1.var)) { - dp3 = p1.ps; - dp3.deg = 1; - while (dp3.nx != null) { - dp3 = dp3.nx; - dp3.deg = 1; - } - dp3.nx = dp2.nx; - dp1.nx = p1.ps; - put_d(dp2); - dp2 = dp1.nx; - put_x(p1); - } else { - dp1 = dp2; - dp2 = dp1.nx; - } - } /* dp2= null */ - /*asc0=asc; */ - } /*asc=null */ - return (dt1.nx); - } - - DTerm nonzerops(DTerm dp) { - DTerm dt1, dp1, dp2; - dt1 = new DTerm(); - dt1.nx = dp; - dp1 = dt1; - dp2 = dp1.nx; - while (dp2 != null) { - if (pzerop(dp2.p)) { - dp1.nx = dp2.nx; - put_x(dp2.p); - put_d(dp2); - dp2 = dp1.nx; - } else { - dp1 = dp2; - dp2 = dp1.nx; - } - } - return (dt1.nx); - } - -/* remove all the numerical factors */ - - XTerm cprim(XTerm p1) { - XTerm pp1; - int i; - if (pzerop(p1)) - return (p1); - else if (p1.var == null) { - put_p(p1); - return (get_n(1L)); - } else { /*printf("cp1(%d)\n",plength(p1)); */ - i = lcontent(p1); - /*printf("cp2(%d)(%d)\n",type_of(i),fix(i)); */ - if (num_unit(i)) return (p1); - if (num_nunit(i)) { - p1 = ptimes(get_n(-1L), p1); - return (p1); - } - { - pp1 = get_num(i); - p1 = pcdiv(p1, pp1); - put_x(pp1); - return (p1); - } - } - } - - XTerm mv_mfact(XTerm p1) { - XTerm pp1; - if (pzerop(p1)) - return (p1); - else if (p1.var == null) { - put_p(p1); - return (get_n(1L)); - } else { - pp1 = cprim(cp_init(p1)); - if (pp1.var != null) p1 = ppdiv(p1, pp1); - put_p(pp1); - p1 = cprim(p1); - return (p1); - } - } - - XTerm mv_nfact(XTerm p) { - XTerm p1, p2; - int d1; - int c; - if (pzerop(p)) - return (p); - else if (p.var == null) { - put_p(p); - return (get_n(1L)); - } - p1 = vars_in_p(init(p)); - while (p1 != null) { - d1 = mdeg(p, p1.var); - if (d1 > 0) { - p2 = get_v(p1.var, d1, get_n(1L)); - p = pdiv(p, p2); - put_p(p2); - } - p2 = p1; - p1 = p1.p; - put_x(p2); - } - c = lcontent(p); - if (num_nunit(c)) { - p1 = get_num(c); - p = ptimes(p, p1); - } else if (!num_unit(c)) { - p1 = get_num(c); - p = pcdiv(p, p1); - put_x(p1); - } - return (p); - } - - XTerm gq2co(XTerm p) { - Var v; - XTerm p1 = new XTerm(); - v = p.var; - while (v != null && v.nm > 0 && v.nm < 100) { - switch (v.nm) { - case 1: - if (xperp(1, 2, v.pt[0], v.pt[1])) - p1 = pminus(ptimes(get_m(v), pminus(yw(v.pt[3]), yw(v.pt[2]))), - pminus(yw(v.pt[1]), yw(v.pt[0]))); - else - p1 = pminus(ptimes(get_m(v), pminus(xw(v.pt[3]), xw(v.pt[2]))), - pminus(xw(v.pt[1]), xw(v.pt[0]))); - break; - case 2: - p1 = pminus(ptimes(get_m(v), get_n(2)), - pminus(carea(v.pt[0], v.pt[1], v.pt[3]), - carea(v.pt[2], v.pt[1], v.pt[3]))); - break; - case 3: - p1 = pminus(get_m(v), - pminus(pplus(cdis(v.pt[0], v.pt[1]), cdis(v.pt[2], v.pt[3])), - pplus(cdis(v.pt[1], v.pt[2]), cdis(v.pt[3], v.pt[0])))); - break; - case 4: - if (v.pt[1] == 0 && vec_co == 1) { - p1 = pminus(get_m(v), xw(v.pt[0])); - } else if (v.pt[1] == 0) { - p1 = pminus(get_m(v), yw(v.pt[0])); - } else if (vec_co == 1) { - p1 = pminus(get_m(v), pminus(xw(v.pt[1]), xw(v.pt[0]))); - } else { - p1 = pminus(get_m(v), pminus(yw(v.pt[1]), yw(v.pt[0]))); - } - break; - default: - gerror("gq2co"); - } - p = prem_var(p, p1, v); - put_p(p1); - v = p.var; - } - return (p); - } - - - XTerm cdis(int n1, int n2) -//int n1,n2; - { - if (n1 == n2) - return (get_n(0L)); - else - return (pplus(ppower(pminus(xw(n1), xw(n2)), 2), - ppower(pminus(yw(n1), yw(n2)), 2))); - } - - XTerm carea(int n1, int n2, int n3) -//int n1,n2,n3; - { - return (pplus3(pminus(ptimes(xw(n1), yw(n2)), ptimes(xw(n2), yw(n1))), - pminus(ptimes(xw(n2), yw(n3)), ptimes(xw(n3), yw(n2))), - pminus(ptimes(xw(n3), yw(n1)), ptimes(xw(n1), yw(n3))))); - } - - -/* */ - - void eq_l(XTerm q1) { - DTerm dp1; - XTerm pp1; - XTerm p1 = cp_poly(q1); - - pp1 = prem_asc(cp_init(p1), tri_set.nx); - if (pzerop(pp1)) { - dp1 = tri_set.nx; - tri_set.nx = get_dt(0, mv_mfact(rem(p1)), dp1); - } else { - dp1 = tri_set.nx; - tri_set.nx = get_dt(0, mv_mfact(p1), dp1); - } - put_p(pp1); - } - - void eq_ll(XTerm q1, XTerm q2) { - XTerm p3, p4; - XTerm p1 = cp_poly(q1); - XTerm p2 = cp_poly(q2); -/* - printf("\eqll1(%ld)(%ld)\n",p1->var,p2->var); - printf("\neqll2(%d)\n",p1->var==p2->var); - pprint(p1);pprint(p2); -*/ - if (p1.var == p2.var) { - if (pls(p2, p1)) { - p3 = p1; - p1 = p2; - p2 = p3; - } - p4 = prem_asc(cp_init(p1), tri_set.nx); - if (pzerop(p4)) { - p1 = prem(p1, p2); - if (pzerop(p1)) { - gerror("eq_ll: two intersection lines are parallel\n"); - return; - } - tri_set.nx = get_dt(2, mv_mfact(p1), tri_set.nx); - tri_set.nx = get_dt(1, mv_mfact(p2), tri_set.nx); - } else { - p2 = prem(p2, p1); - if (pzerop(p2)) { - gerror("eq_ll: two intersection lines are parallel\n"); - return; - } - tri_set.nx = get_dt(2, mv_mfact(p2), tri_set.nx); - tri_set.nx = get_dt(1, mv_mfact(p1), tri_set.nx); - } - put_p(p4); - } else if (vless(p2.var, p1.var)) { - tri_set.nx = get_dt(0, mv_mfact(p2), tri_set.nx); - tri_set.nx = get_dt(0, mv_mfact(p1), tri_set.nx); - } else { - tri_set.nx = get_dt(0, mv_mfact(p1), tri_set.nx); - tri_set.nx = get_dt(0, mv_mfact(p2), tri_set.nx); - } - } - - void eq_lq(XTerm q1, XTerm q2) { - XTerm p3; - XTerm p1 = cp_poly(q1); - XTerm p2 = cp_poly(q2); - if (p1.var == p2.var) { - p3 = prem_asc(cp_init(p1), tri_set.nx); - if (pzerop(p3)) { - p1 = rem(p1); - tri_set.nx = get_dt(0, mv_mfact(p1), tri_set.nx); - tri_set.nx = get_dt(0, mv_mfact(p2), tri_set.nx); - } else { - p2 = prem(p2, p1); - if (pzerop(p2)) { - gerror("eq_lq: two intersection lines are parallel\n"); - return; - } - tri_set.nx = get_dt(2, mv_mfact(p2), tri_set.nx); - tri_set.nx = get_dt(1, mv_mfact(p1), tri_set.nx); - } - put_p(p3); - } else if (vless(p2.var, p1.var)) { - tri_set.nx = get_dt(0, mv_mfact(p2), tri_set.nx); - tri_set.nx = get_dt(0, mv_mfact(p1), tri_set.nx); - } else { - tri_set.nx = get_dt(0, mv_mfact(p1), tri_set.nx); - tri_set.nx = get_dt(0, mv_mfact(p2), tri_set.nx); - } - } - - void eq_lq1(XTerm q1, XTerm q2, int pt) { - XTerm p3, pp1; - XTerm p1 = cp_poly(q1); - XTerm p2 = cp_poly(q2); - if (p1.var == p2.var) { - p3 = prem_asc(cp_init(p1), tri_set.nx); - if (pzerop(p3)) { - p1 = rem(p1); - p2 = prem(p2, p1); - pp1 = pminus(get_m(p2.var), yw(pt)); - } else { - p2 = prem(p2, p1); - pp1 = pminus(get_m(p2.var), xw(pt)); - } - p2 = pdiv(p2, pp1); - put_p(pp1); - tri_set.nx = get_dt(2, mv_mfact(p2), tri_set.nx); - tri_set.nx = get_dt(1, mv_mfact(p1), tri_set.nx); - put_p(p3); - } else if (vless(p2.var, p1.var)) { - tri_set.nx = get_dt(0, mv_mfact(p2), tri_set.nx); - tri_set.nx = get_dt(0, mv_mfact(p1), tri_set.nx); - } else { - tri_set.nx = get_dt(0, mv_mfact(p1), tri_set.nx); - tri_set.nx = get_dt(0, mv_mfact(p2), tri_set.nx); - } - } - - void eq_qq(XTerm q1, XTerm q2) { - XTerm pp1; - XTerm p1 = cp_poly(q1); - XTerm p2 = cp_poly(q2); - pp1 = pminus(p2, cp_poly(p1)); - p2 = prem(p1, pp1); - tri_set.nx = get_dt(2, p2, tri_set.nx); - tri_set.nx = get_dt(1, pp1, tri_set.nx); - } - - void eq_qq1(XTerm q1, XTerm q2, int pt) { - XTerm pp1, pp2; - XTerm p1 = cp_poly(q1); - XTerm p2 = cp_poly(q2); - pp1 = pminus(p2, cp_poly(p1)); - p2 = prem(p1, pp1); - pp2 = pminus(get_m(p2.var), xw(pt)); - p2 = pdiv(p2, pp2); - put_p(pp2); - tri_set.nx = get_dt(2, mv_mfact(p2), tri_set.nx); - tri_set.nx = get_dt(1, mv_mfact(pp1), tri_set.nx); - } - -// PP eq_lq4(xterm p1, xterm p2, int pt) { -// xterm pp1; -// PP pp; -// if (p1.var == p2.var) { -// p2 = prem(p2, p1); -// pp1 = pminus(get_m(p2.var), xw(pt)); -// p2 = pdiv(p2, pp1); -// put_p(pp1); -// pp.p1 = mv_mfact(p2); -// pp.p2 = mv_mfact(p1); -// } else if (vless(p2.var, p1.var)) { -// pp.p1 = mv_mfact(p2); -// pp.p2 = mv_mfact(p1); -// } else { -// pp.p1 = mv_mfact(p1); -// pp.p2 = mv_mfact(p2); -// } -// return (pp); -// } - - void init_wu() { - int i; - tri_set.nx = null; - l_set.nx = null; - conc_set.nx = null; - div_set.nx = null; - for (i = 1; i < 100; i++) { -// hyp_set[i].p1 = null; -// hyp_set[i].p2 = null; - } - for (i = 0; i < 50; i++) inits[i] = null; - } - - void free_wu() { - DTerm ps1, ps2; - int i; - - put_ps(tri_set.nx); - put_ps(l_set.nx); - ps1 = conc_set.nx; - while (ps1 != null) { - if (ps1.p != null) put_p(ps1.p); - ps2 = ps1.nx; - put_d(ps1); - ps1 = ps2; - } - tri_set.nx = null; - l_set.nx = null; - conc_set.nx = null; - - if (pro_type == PRO_WU) { - for (i = 0; i < 50; i++) { /*printf("(%d)\n", inits[i]); */ - if (inits[i] != null) { - put_p(inits[i]); - inits[i] = null; - } - } - } - if (pro_type == PRO_GB) { - ps1 = div_set.nx; - while (ps1 != null) { - ps2 = ps1; - ps1 = ps1.nx; - put_p(ps2.p); - put_d(ps2); - } - div_set.nx = null; - } -// for (i = 1; i < 100; i++) { -// if (hyp_set[i].p1) put_p(hyp_set[i].p1); -// if (hyp_set[i].p2) put_p(hyp_set[i].p2); -// hyp_set[i].p1 = null; -// hyp_set[i].p2 = null; -// } - } - - - boolean irr_thm() { - int[] p = new int[10]; - - - int j; - boolean th_p = false; - for (int ptn = 1; ptn <= cons_no; ptn++) { - for (j = 0; j <= 5; j++) p[j + 1] = APTS(ptn, j); - switch (ATYPE(ptn)) { - case C_I_LC: - if (p[2] == p[4] || p[1] == p[4]) { - th_p = true; - break; - } - break; - case C_I_PC: - case C_I_TC: - if (p[1] == p[5]) { - th_p = true; - break; - } - break; - case C_I_CC: - if (p[2] != p[4]) { - th_p = true; - break; - } - break; - case C_I_LR: - case C_I_CR: - case C_I_RR: - th_p = true; - break; - } - } - return th_p; - } - - - /////////////////////////////////////////////////////////////////////// - //from eqs.cpp - - XTerm coll(int p1, int p2, int p3) { - XTerm xp1; - xp1 = pminus(ptimes(pminus(yw(p3), yw(p1)), pminus(xw(p2), xw(p1))), - ptimes(pminus(xw(p3), xw(p1)), pminus(yw(p2), yw(p1)))); - return (xp1); - } - - XTerm para(int p1, int p2, int p3, int p4) { - XTerm xp1; - xp1 = pminus(ptimes(pminus(yw(p4), yw(p3)), - pminus(xw(p2), xw(p1))), - ptimes(pminus(xw(p4), xw(p3)), - pminus(yw(p2), yw(p1)))); - return (xp1); - } - - XTerm perp(int p1, int p2, int p3, int p4) -//int p1,p2,p3,p4; - { - XTerm xp1; - xp1 = pplus(ptimes(pminus(yw(p4), yw(p3)), - pminus(yw(p2), yw(p1))), - ptimes(pminus(xw(p4), xw(p3)), - pminus(xw(p2), xw(p1)))); - return (xp1); - } - - XTerm yratio(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8) -//int p1,p2,p3,p4,p5,p6,p7,p8; - { - XTerm xp1; - xp1 = pminus(ptimes(pminus(yw(p4), yw(p3)), - pminus(yw(p6), yw(p5))), - ptimes(pminus(yw(p8), yw(p7)), - pminus(yw(p2), yw(p1)))); - return (xp1); - } - - XTerm xratio(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8) -//int p1,p2,p3,p4,p5,p6,p7,p8; - { - XTerm xp1; - xp1 = pminus(ptimes(pminus(xw(p4), xw(p3)), - pminus(xw(p6), xw(p5))), - ptimes(pminus(xw(p8), xw(p7)), - pminus(xw(p2), xw(p1)))); - return (xp1); - } - - XTerm eqptx(int p1, int p2) { - XTerm xp1; - xp1 = pminus(xw(p1), xw(p2)); - return (xp1); - } - - XTerm eqpty(int p1, int p2) -//int p1,p2; - { - XTerm xp1; - xp1 = pminus(yw(p1), yw(p2)); - return (xp1); - } - - XTerm midx(int p1, int p2, int p3) -//int p1,p2,p3; - { - XTerm xp1; - xp1 = pminus(pplus(xw(p2), xw(p3)), ptimes(get_n(2L), xw(p1))); - return (xp1); - } - - XTerm midy(int p1, int p2, int p3) -//int p1,p2,p3; - { - XTerm xp1; - xp1 = pminus(pplus(yw(p2), yw(p3)), ptimes(get_n(2L), yw(p1))); - return (xp1); - } - - XTerm dist(int p1, int p2) { - XTerm xp1; - xp1 = pplus(ptimes(pminus(yw(p2), yw(p1)), - pminus(yw(p2), yw(p1))), - ptimes(pminus(xw(p2), xw(p1)), - pminus(xw(p2), xw(p1)))); - return (xp1); - } - - XTerm cong(int p1, int p2, int p3, int p4) -//int p1,p2,p3,p4; - { - XTerm xp1; - xp1 = pminus(dist(p1, p2), dist(p3, p4)); - return (xp1); - } - - XTerm acong(int p1, int p2, int p3, int p4, int p5, int p6) -//int p1,p2,p3,p4,p5,p6; - { - XTerm xp1; - xp1 = pminus(ptimes(para(p3, p2, p1, p2), perp(p6, p5, p4, p5)), - ptimes(para(p6, p5, p4, p5), perp(p3, p2, p1, p2))); - return (xp1); - } - - XTerm tcc(int o1, int p1, int o2, int p2) -//int o1,p1,o2,p2; - { - XTerm xp1, rp1, rp2; - rp1 = ptimes(dist(o1, p1), dist(o1, p1)); - rp2 = ptimes(dist(o2, p2), dist(o2, p2)); - rp1 = pplus(rp1, rp2); - xp1 = ptimes(dist(o1, o2), dist(o1, o2)); - xp1 = pplus(rp1, xp1); - - rp1 = ptimes(dist(o1, p1), dist(o2, p2)); - rp1 = pctimes(get_n(-2L), rp1); - xp1 = pplus(xp1, rp1); - - rp1 = ptimes(dist(o1, p1), dist(o1, o2)); - rp1 = pctimes(get_n(-2L), rp1); - xp1 = pplus(xp1, rp1); - - rp1 = ptimes(dist(o2, p2), dist(o1, o2)); - rp1 = pctimes(get_n(-2L), rp1); - xp1 = pplus(xp1, rp1); - - return (xp1); - } - - XTerm pratiox(int y, int w, int u, int v, XTerm p1, XTerm p2) -//int y,w,u,v; -//xterm *p1,*p2; - { - return (pminus(ptimes(p2, pminus(xw(y), xw(w))), - ptimes(p1, pminus(xw(v), xw(u))))); - } - - XTerm pratioy(int y, int w, int u, int v, XTerm p1, XTerm p2) -//int y,w,u,v; -//xterm *p1,*p2; - { - return (pminus(ptimes(p2, pminus(yw(y), yw(w))), - ptimes(p1, pminus(yw(v), yw(u))))); - } - - -// xterm tratioc(int y, int w, int u, int v, xterm p1, xterm p2) -////int y,w,u,v; -////xterm *p1,*p2; -// { -// xterm p0; -// //xterm *trim_a(), *trim_g(); -// p0 = pminus(ptimes3(get_n(4L), p2, trim_a(y, u, w, v)), -// ptimes(p1, trim_g(u, u, v, v))); -// return (p0); -// } - - void print_coor() { - } - - int cx(int n) { - int k; - if (pro_type == PRO_GB && ATYPE(n) == C_POINT) { - if (n == 2) k = -1; else k = -2 * (n - 2); - } else if (pro_type == PRO_GB && ATYPE(n) == C_O_C) { - k = -2 * (n - 2); - } else { - if (n == 2) k = 1; else k = 2 * (n - 2); - } - return (k); - } - - int cy(int n) { - int k; - if (pro_type == PRO_GB && ATYPE(n) == C_POINT) { - k = -2 * (n - 2) - 1; - } else { - k = 2 * (n - 2) + 1; - } - return (k); - } - - XTerm xw(int n) { - if (n == 1) return (get_n(0L)); - return (get_m(mk_wvar(cx(n)))); - } - - XTerm yw(int n) { - if (n == 1 || n == 2) return (get_n(0L)); - return (get_m(mk_wvar(cy(n)))); - } - -} diff --git a/src/main/java/gprover/XTerm.java b/src/main/java/gprover/XTerm.java index b27d221b..89a8bf67 100644 --- a/src/main/java/gprover/XTerm.java +++ b/src/main/java/gprover/XTerm.java @@ -1,11 +1,8 @@ package gprover; + /** - * Created by IntelliJ IDEA. - * User: yezheng - * Date: 2006-5-4 - * Time: 11:32:50 - * To change this template use File | Settings | File Templates. + * Constructs a Var object with default values. */ public class XTerm { public Var var; // variable @@ -14,6 +11,9 @@ public class XTerm { XTerm p; String sd; + /** + * Constructs an XTerm object with default values. + */ public XTerm() { var = null; c = 0; @@ -21,20 +21,39 @@ public XTerm() { p = null; } + /** + * Returns the value of the prefix term. + * + * @return the value of the prefix term + */ public long getPV() { if (ps == null || ps.p == null) return 0; return ps.p.c; } + /** + * Returns the string representation of the term. + * + * @return the string representation of the term + */ + @Override public String toString() { return sd; } + /** + * Removes the leading '+' character from the string representation of the term. + */ public void cutMark() { if (sd != null && sd.trim().startsWith("+")) sd = sd.trim().substring(1); } + /** + * Returns the trimmed string representation of the term without the leading '+' character. + * + * @return the trimmed string representation of the term + */ public String getString() { if (sd == null) return null; String t = sd.trim(); @@ -43,6 +62,11 @@ public String getString() { return t; } + /** + * Returns the number of terms in the linked list of terms. + * + * @return the number of terms in the linked list of terms + */ public int getTermNumber() { XTerm t = this; int n = 0; diff --git a/src/main/java/gprover/package-info.java b/src/main/java/gprover/package-info.java new file mode 100644 index 00000000..f46db082 --- /dev/null +++ b/src/main/java/gprover/package-info.java @@ -0,0 +1,6 @@ +/** + * The gprover package contains the core classes and interfaces related to the + * gprover project. This package serves as the central point + * for the implementation of the proof algorithms and related utilities. + */ +package gprover; \ No newline at end of file diff --git a/src/main/java/maths/BigFraction.java b/src/main/java/maths/BigFraction.java index 440ef0fb..aa7f34be 100644 --- a/src/main/java/maths/BigFraction.java +++ b/src/main/java/maths/BigFraction.java @@ -2,9 +2,10 @@ import java.io.Serializable; import java.math.BigInteger; -import java.math.BigDecimal; - +/** + * Represents a fraction with arbitrary precision using BigInteger. + */ public class BigFraction implements Cloneable, Comparable, Serializable { protected final BigInteger numerator_; protected final BigInteger denominator_; @@ -12,23 +13,30 @@ public class BigFraction implements Cloneable, Comparable, Serializable { final public static BigFraction ZERO = new BigFraction("0/1"); final public static BigFraction ONE = new BigFraction("1/1"); - - public long intNumerator() { - return numerator_.intValue(); - } - - public long intDenominator() { - return denominator_.intValue(); - } - + /** + * Returns the numerator as a BigInteger. + * + * @return the numerator as a BigInteger + */ public BigInteger numerator() { return numerator_; } + /** + * Returns the denominator as a BigInteger. + * + * @return the denominator as a BigInteger + */ public BigInteger denominator() { return denominator_; } + /** + * Constructs a BigFraction with the specified numerator and denominator. + * + * @param num the numerator + * @param den the denominator + */ public BigFraction(BigInteger num, BigInteger den) { boolean numNonnegative = gteq(num, BigInteger.ZERO); @@ -44,34 +52,52 @@ public BigFraction(BigInteger num, BigInteger den) { denominator_ = b.divide(g); } - - public BigFraction(long n) { - this(BigInteger.valueOf(n), BigInteger.valueOf(1)); - } - + /** + * Constructs a BigFraction with the specified BigInteger numerator. + * + * @param b the numerator + */ public BigFraction(BigInteger b) { this(b, BigInteger.valueOf(1)); } + /** + * Copy constructor for BigFraction. + * + * @param f the BigFraction to copy + */ public BigFraction(BigFraction f) { numerator_ = f.numerator(); denominator_ = f.denominator(); } + /** + * Constructs a BigFraction from a string representation. + * + * @param s the string representation of the fraction + */ public BigFraction(String s) { this(new BigInteger(s.substring(0, s.indexOf('/'))), new BigInteger(s.substring(s.indexOf('/') + 1))); } + /** + * Constructs a BigFraction with the specified long numerator and denominator. + * + * @param num the numerator + * @param den the denominator + */ public BigFraction(long num, long den) { this(new BigInteger(Long.toString(num)), new BigInteger(Long.toString(den))); } - //------------------ - // Override toString - //------------------ - + /** + * Returns a string representation of the fraction. + * + * @return the string representation of the fraction + */ + @Override public String toString() { BigInteger b2 = denominator(); @@ -81,42 +107,54 @@ public String toString() { return numerator().toString(); } - //-------------------------------- - // Required to implement Cloneable - //-------------------------------- - + /** + * Creates and returns a copy of this BigFraction. + * + * @return a clone of this BigFraction + */ public Object clone() { return new BigFraction(this); } - //---------------------------- - // Utility comparison routines - //---------------------------- - - private boolean gt(BigInteger x, BigInteger y) { - return x.compareTo(y) > 0; - } - + /** + * Checks if this fraction is greater than or equal to the specified BigInteger. + * + * @param x the first BigInteger + * @param y the second BigInteger + * @return true if x is greater than or equal to y; false otherwise + */ private boolean gteq(BigInteger x, BigInteger y) { return x.compareTo(y) >= 0; } + /** + * Checks if the numerator is greater than or equal to the specified BigInteger. + * + * @param y the BigInteger to compare with + * @return true if the numerator is greater than or equal to y; false otherwise + */ private boolean gteq(BigInteger y) { return numerator_.compareTo(y) >= 0; } + /** + * Checks if this fraction is less than the specified BigInteger. + * + * @param x the first BigInteger + * @param y the second BigInteger + * @return true if x is less than y; false otherwise + */ private boolean lt(BigInteger x, BigInteger y) { return x.compareTo(y) < 0; } - private boolean lteq(BigInteger x, BigInteger y) { - return x.compareTo(y) <= 0; - } - - //------------ - // Get minimum - //------------ + /** + * Returns the minimum of this fraction and the specified fraction. + * + * @param val the fraction to compare with + * @return the minimum fraction + */ public BigFraction min(BigFraction val) { if (compareTo(val) <= 0) { return this; @@ -125,10 +163,12 @@ public BigFraction min(BigFraction val) { } } - //------------ - // Get maximum - //------------ - + /** + * Returns the maximum of this fraction and the specified fraction. + * + * @param val the fraction to compare with + * @return the maximum fraction + */ public BigFraction max(BigFraction val) { if (compareTo(val) > 0) { return this; @@ -137,43 +177,24 @@ public BigFraction max(BigFraction val) { } } - //------------------------------------------------------- - // Convert to BigDecimal - // Rounding mode is any of BigDecimal.ROUND_xxx constants - //------------------------------------------------------- - - public BigDecimal asBigDecimal(int scale, int roundingMode) { - BigDecimal num = new BigDecimal(numerator()); - BigDecimal den = new BigDecimal(denominator()); - return num.divide(den, scale, roundingMode); - } - - //------------------ - // Get negated value - //------------------ - - public BigFraction negate() { - return new BigFraction(numerator().negate(), denominator()); - } - - //--------------------------- - // Get multiplicative inverse - //--------------------------- - - public BigFraction inverse() { - return new BigFraction(denominator(), numerator()); - } - - //---- - // Add - //---- - + /** + * Raises this fraction to the power of the specified integer. + * + * @param d the exponent + * @return the resulting fraction + */ public BigFraction pow(int d) { BigInteger an = numerator(); BigInteger ad = denominator(); return new BigFraction(an.pow(d), (ad.pow(d))); } + /** + * Adds the specified fraction to this fraction. + * + * @param b the fraction to add + * @return the resulting fraction + */ public BigFraction add(BigFraction b) { BigInteger an = numerator(); BigInteger ad = denominator(); @@ -182,38 +203,32 @@ public BigFraction add(BigFraction b) { return new BigFraction(an.multiply(bd).add(bn.multiply(ad)), ad.multiply(bd)); } + /** + * Adds the specified BigInteger to this fraction. + * + * @param n the BigInteger to add + * @return the resulting fraction + */ public BigFraction add(BigInteger n) { return add(new BigFraction(n, BigInteger.ONE)); } + /** + * Adds the specified long value to this fraction. + * + * @param n the long value to add + * @return the resulting fraction + */ public BigFraction add(long n) { return add(new BigInteger(Long.toString(n))); } - //--------- - // Subtract - //--------- - - public BigFraction subtract(BigFraction b) { - BigInteger an = numerator(); - BigInteger ad = denominator(); - BigInteger bn = b.numerator(); - BigInteger bd = b.denominator(); - return new BigFraction(an.multiply(bd).subtract(bn.multiply(ad)), ad.multiply(bd)); - } - - public BigFraction subtract(BigInteger n) { - return subtract(new BigFraction(n, BigInteger.ONE)); - } - - public BigFraction subtract(long n) { - return subtract(new BigInteger(Long.toString(n))); - } - - //--------- - // Multiply - //--------- - + /** + * Multiplies this fraction by the specified fraction. + * + * @param b the fraction to multiply by + * @return the resulting fraction + */ public BigFraction multiply(BigFraction b) { BigInteger an = numerator(); BigInteger ad = denominator(); @@ -222,18 +237,22 @@ public BigFraction multiply(BigFraction b) { return new BigFraction(an.multiply(bn), ad.multiply(bd)); } + /** + * Multiplies this fraction by the specified BigInteger. + * + * @param n the BigInteger to multiply by + * @return the resulting fraction + */ public BigFraction multiply(BigInteger n) { return multiply(new BigFraction(n, BigInteger.ONE)); } - public BigFraction multiply(long n) { - return multiply(new BigInteger(Long.toString(n))); - } - - //------- - // Divide - //------- - + /** + * Divides this fraction by the specified fraction. + * + * @param b the fraction to divide by + * @return the resulting fraction + */ public BigFraction divide(BigFraction b) { BigInteger an = numerator(); BigInteger ad = denominator(); @@ -242,14 +261,21 @@ public BigFraction divide(BigFraction b) { return new BigFraction(an.multiply(bd), ad.multiply(bn)); } + /** + * Divides this fraction by the specified BigInteger. + * + * @param n the BigInteger to divide by + * @return the resulting fraction + */ public BigFraction divide(BigInteger n) { return divide(new BigFraction(n, BigInteger.ONE)); } - public BigFraction divide(long n) { - return divide(new BigInteger(Long.toString(n))); - } - + /** + * Calculates the square root of this fraction if it is non-negative. + * + * @return the square root as a BigFraction, or null if not a perfect square + */ public BigFraction sqrt() { if (!gteq(BigInteger.ZERO)) return null; @@ -263,14 +289,22 @@ public BigFraction sqrt() { return null; } - //--------------------------------- - // Required to implement Comparable - //--------------------------------- + /** + * Checks if the numerator is zero. + * + * @return true if the numerator is zero; false otherwise + */ public boolean isZero() { return numerator().compareTo(BigInteger.ZERO) == 0; } + /** + * Compares this fraction with another object. + * + * @param other the object to compare with + * @return -1, 0, or 1 as this fraction is less than, equal to, or greater than the given object + */ public int compareTo(Object other) { BigFraction b = (BigFraction) (other); BigInteger an = numerator(); @@ -289,31 +323,52 @@ public int compareTo(Object other) { } } + /** + * Compares this fraction with a BigInteger. + * + * @param n the BigInteger to compare with + * @return -1, 0, or 1 as this fraction is less than, equal to, or greater than the given BigInteger + */ public int compareTo(BigInteger n) { Object obj = new BigFraction(n, BigInteger.ONE); return compareTo(obj); } - //---------------- - // Override equals - //---------------- - + /** + * Checks if this fraction is equal to another object. + * + * @param other the object to compare with + * @return true if the fractions are equal; false otherwise + */ public boolean equals(Object other) { return compareTo((BigFraction) other) == 0; } + /** + * Checks if this fraction is equal to a BigInteger. + * + * @param n the BigInteger to compare with + * @return true if equal; false otherwise + */ public boolean equals(BigInteger n) { return compareTo(n) == 0; } + /** + * Checks if this fraction is equal to a long value. + * + * @param n the long value to compare with + * @return true if equal; false otherwise + */ public boolean equals(long n) { return equals(new BigInteger(Long.toString(n))); } - //------------------ - // Override hashCode - //------------------ - + /** + * Returns a hash code for this fraction. + * + * @return the hash code computed from numerator and denominator + */ public int hashCode() { int num = numerator().intValue(); int den = denominator().intValue(); diff --git a/src/main/java/maths/BigSquareRoot.java b/src/main/java/maths/BigSquareRoot.java index 181d7aef..d6795385 100644 --- a/src/main/java/maths/BigSquareRoot.java +++ b/src/main/java/maths/BigSquareRoot.java @@ -3,39 +3,25 @@ import java.math.BigDecimal; import java.math.BigInteger; +/** + * Provides methods to calculate square roots and cube roots with arbitrary precision. + */ public class BigSquareRoot { - private static BigDecimal ZERO = BigDecimal.ZERO; - private static BigDecimal ONE = BigDecimal.ONE; - private static BigDecimal TWO = new BigDecimal("2"); - private static BigDecimal THREE = new BigDecimal("3"); + private static final BigDecimal ZERO = BigDecimal.ZERO; + private static final BigDecimal ONE = BigDecimal.ONE; + private static final BigDecimal TWO = new BigDecimal("2"); public static final int DEFAULT_MAX_ITERATIONS = 50; public static final int DEFAULT_SCALE = 10; private static int maxIterations = DEFAULT_MAX_ITERATIONS; - //--------------------------------------- - // The error is the original number minus - // (sqrt * sqrt). If the original number - // was a perfect square, the error is 0. - //--------------------------------------- - - //------------------- - // Maximum iterations - //------------------- - - private static int getMaxIterations() { - return maxIterations; - } - - private static void setMaxIterations(int maxIterations) { - maxIterations = maxIterations; - } - - //-------------------------- - // Get initial approximation - //-------------------------- - + /** + * Gets an initial approximation for the square root computation. + * + * @param n the BigDecimal for which to compute the initial approximation + * @return the initial guess as a BigDecimal + */ private static BigDecimal getInitialApproximation(BigDecimal n) { BigInteger integerPart = n.toBigInteger(); int length = integerPart.toString().length(); @@ -47,18 +33,25 @@ private static BigDecimal getInitialApproximation(BigDecimal n) { return guess; } - //---------------- - // Get square root - //---------------- - + /** + * Calculates the square root of a BigInteger. + * + * @param n the BigInteger for which to calculate the square root + * @return the square root as a BigDecimal + * @throws IllegalArgumentException if n is non-positive + */ public static BigDecimal get(BigInteger n) { return get(new BigDecimal(n)); } + /** + * Calculates the square root of a BigDecimal. + * + * @param n the BigDecimal for which to calculate the square root + * @return the square root as a BigDecimal + * @throws IllegalArgumentException if n is non-positive + */ private static BigDecimal get(BigDecimal n) { - - // Make sure n is a positive number - if (n.compareTo(ZERO) <= 0) { throw new IllegalArgumentException(); } @@ -73,9 +66,6 @@ private static BigDecimal get(BigDecimal n) { if (length > 20) scale = (length / 2); - // Iterate - - iterations = 0; boolean more = true; BigDecimal error; while (more) { @@ -91,66 +81,24 @@ private static BigDecimal get(BigDecimal n) { } } return guess; - } - //---------------------- - // Get random BigInteger - //---------------------- - - private static BigInteger getRandomBigInteger(int nDigits) { - StringBuffer sb = new StringBuffer(); - java.util.Random r = new java.util.Random(); - for (int i = 0; i < nDigits; i++) { - sb.append(r.nextInt(10)); - } - return new BigInteger(sb.toString()); - } - - //----- - // Test - //----- - -// public static void main(String[] args) { -// -// BigInteger n; -// BigDecimal sqrt; -// BigSquareRoot app = new BigSquareRoot(); -// // Generate a random big integer with a hundred digits -// -// n = BigSquareRoot.getRandomBigInteger(100); -// -// // Build an array of test numbers -// -// String testNums[] = {"9", "30", "720", "1024", n.multiply(n).toString()}; -// -// for (int i = 0; i < testNums.length; i++) { -// n = new BigInteger(testNums[i]); -// if (i > 0) { -// System.out.println("----------------------------"); -// } -// System.out.println("Computing the square root of"); -// System.out.println(n.toString()); -// int length = n.toString().length(); -// if (length > 20) { -// app.setScale(length / 2); -// } -// sqrt = app.get(n); -// BigInteger dd = sqrt.multiply(sqrt).toBigInteger().subtract(n); -// System.out.println("Iterations " + app.getIterations()); -// System.out.println("Sqrt " + sqrt.toString()); -// System.out.println(sqrt.multiply(sqrt).toString()); -// System.out.println(n.toString()); -// System.out.println("Error " + app.getError().toString()); -// } -// -// } - + /** + * Calculates the square root of a BigInteger. + * + * @param b the BigInteger for which to calculate the square root + * @return the square root as a BigDecimal + */ public static BigDecimal sqrt(BigInteger b) { - return get(b); } + /** + * Calculates the integer square root of a BigInteger if it is a perfect square. + * + * @param b the BigInteger for which to calculate the integer square root + * @return the integer square root if perfect; null otherwise + */ public static BigInteger sqrtI(BigInteger b) { BigDecimal b1 = sqrt(b); BigInteger b2 = b1.toBigInteger(); @@ -158,18 +106,4 @@ public static BigInteger sqrtI(BigInteger b) { return b2; return null; } - -// Newton Method to get the cube root on BigIntegers : - - public static BigDecimal CubeRoot(BigDecimal B, int iter) { //????????????? - BigDecimal[] cubique = new BigDecimal[2]; - cubique[0] = B.divide(THREE); - for (int i = 0; i < iter; i++) { - cubique[1] = ((cubique[0].multiply(TWO)).add(B.divide(cubique[0].pow(2)))).divide(THREE); - cubique[0] = cubique[1]; - } - return cubique[0]; - } - - -} +} \ No newline at end of file diff --git a/src/main/java/maths/CharSet.java b/src/main/java/maths/CharSet.java index 990069fb..46d7a4fa 100644 --- a/src/main/java/maths/CharSet.java +++ b/src/main/java/maths/CharSet.java @@ -1,25 +1,38 @@ package maths; -//import wprover.CMisc; - +/** + * Represents a character set for polynomial operations. + */ public class CharSet { final private static boolean DEBUG = false; - private PolyBasic basic = PolyBasic.getInstance(); - private static CharSet charset = new CharSet(); + private final PolyBasic basic = PolyBasic.getInstance(); + private static final CharSet charset = new CharSet(); private static int REDUCE_LEN = 2; + /** + * Returns the debug status. + * + * @return true if debug is enabled; false otherwise + */ public static boolean debug() { return DEBUG; } + /** + * Returns the singleton instance of CharSet. + * + * @return the singleton instance + */ public static CharSet getinstance() { return charset; } - public long freemonos() { - return 0; - } - + /** + * Processes the given polynomial and returns the resulting polynomial. + * + * @param pp the input polynomial + * @return the resulting polynomial + */ public TPoly charset(TPoly pp) { TPoly rm, ch, chend, p, output; output = null; @@ -51,7 +64,6 @@ public TPoly charset(TPoly pp) { chend.setNext(null); rm = tp; - if (ch == chend) { output = basic.ppush(ch.getPoly(), output); } else { @@ -86,11 +98,9 @@ public TPoly charset(TPoly pp) { poly = null; } } - } } -// this.printpoly(output); reduce(output); TPoly tp = reverse(output); if (!cfinished(tp)) @@ -106,15 +116,25 @@ public TPoly charset(TPoly pp) { return tp; } - public TPoly reduce1(TPoly poly) // 1, 2, 3, 4, 5 - { + /** + * Reduces the given polynomial. + * + * @param poly the input polynomial + * @return the reduced polynomial + */ + public TPoly reduce1(TPoly poly) { poly = reverse(poly); reduce(poly); poly = reverse(poly); return poly; } - public void reduce(TPoly poly) { // n ,n-1,,,,,,, 1. + /** + * Reduces the given polynomial in place. + * + * @param poly the input polynomial + */ + public void reduce(TPoly poly) { TPoly p1 = poly; while (p1 != null) { TMono m = p1.poly; @@ -130,7 +150,12 @@ public void reduce(TPoly poly) { // n ,n-1,,,,,,, 1. } } - + /** + * Checks if the given polynomial is finished. + * + * @param pp the input polynomial + * @return true if the polynomial is finished; false otherwise + */ public boolean cfinished(TPoly pp) { if (pp == null) return true; int a = basic.lv(pp.getPoly()); @@ -147,6 +172,11 @@ public boolean cfinished(TPoly pp) { return true; } + /** + * Prints the given polynomial. + * + * @param pp the input polynomial + */ public void printpoly(TPoly pp) { int i = 0; while (pp != null) { @@ -160,6 +190,12 @@ public void printpoly(TPoly pp) { } } + /** + * Reverses the given polynomial. + * + * @param pp the input polynomial + * @return the reversed polynomial + */ public static TPoly reverse(TPoly pp) { if (pp == null) return pp; TPoly out = null; @@ -177,16 +213,5 @@ public static TPoly reverse(TPoly pp) { } } return out; - } - - public TPoly pushpoly(TMono p, TPoly pp) { - TPoly pt; - - pt = new TPoly(); - pt.setNext(pp); - pt.setPoly(p); - return pt; - } - -} +} \ No newline at end of file diff --git a/src/main/java/maths/GMono.java b/src/main/java/maths/GMono.java deleted file mode 100644 index 5982616b..00000000 --- a/src/main/java/maths/GMono.java +++ /dev/null @@ -1,39 +0,0 @@ -package maths; - -/** - * Created by IntelliJ IDEA. - * User: ye - * Date: 2007-5-28 - * Time: 22:11:39 - * To change this template use File | Settings | File Templates. - */ -public class GMono { - public int x = 0; - public int deg = 0; - public BigFraction val = null; - public TMono coef = null; - public TMono next = null; - - public GMono() { - - } - - public GMono(int x, int val, int deg) { - this.x = x; - this.deg = deg; - if (x == 0 || deg == 0) { - this.x = 0; - this.deg = 0; - this.val = new BigFraction(val,1); - } else { - this.coef = new TMono(0, val, 0); - } - - } - - public GMono(int x, TMono coef, int deg) { - this.x = x; - this.deg = deg; - this.coef = coef; - } -} diff --git a/src/main/java/maths/Param.java b/src/main/java/maths/Param.java index b6282295..a6c15c1b 100644 --- a/src/main/java/maths/Param.java +++ b/src/main/java/maths/Param.java @@ -1,57 +1,91 @@ package maths; -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.DataInputStream; - -public class Param { - public static int VARIABLE = 0; - public static int STATIC = 1; - - public int type = 0; - public int xindex; - public double value; - - public boolean Solved = false; - public TMono m = null; - - - public Param() { - } - - public Param(int index, double val) { - xindex = index; - value = val; - } - - public void setParameterStatic() { - type = STATIC; - } - - public String toString() { - String s = "x" + xindex; - if (m != null && m.deg != 1) - s += "^" + m.deg; - return s; - } - - public String getString() { - String s = "x" + xindex; - return s; - } - - public void Save(DataOutputStream out) throws IOException { - out.writeInt(type); - out.writeInt(xindex); - out.writeDouble(value); - out.writeBoolean(Solved); - } - - public void Load(DataInputStream in) throws IOException { - type = in.readInt(); - xindex = in.readInt(); - value = in.readDouble(); - Solved = in.readBoolean(); - } - -} + import java.io.DataOutputStream; + import java.io.IOException; + import java.io.DataInputStream; + + /** + * Represents a parameter with a type, index, value, and optional monomial. + */ + public class Param { + public static int STATIC = 1; + + public int type = 0; + public int xindex; + public double value; + + public boolean Solved = false; + public TMono m = null; + + /** + * Default constructor for Param. + */ + public Param() { + } + + /** + * Constructs a Param with the specified index and value. + * + * @param index the index of the parameter + * @param val the value of the parameter + */ + public Param(int index, double val) { + xindex = index; + value = val; + } + + /** + * Sets the parameter type to static. + */ + public void setParameterStatic() { + type = STATIC; + } + + /** + * Returns a string representation of the parameter. + * + * @return the string representation of the parameter + */ + public String toString() { + String s = "x" + xindex; + if (m != null && m.deg != 1) + s += "^" + m.deg; + return s; + } + + /** + * Returns a string representation of the parameter index. + * + * @return the string representation of the parameter index + */ + public String getString() { + String s = "x" + xindex; + return s; + } + + /** + * Saves the parameter to a DataOutputStream. + * + * @param out the DataOutputStream to write to + * @throws IOException if an I/O error occurs + */ + public void Save(DataOutputStream out) throws IOException { + out.writeInt(type); + out.writeInt(xindex); + out.writeDouble(value); + out.writeBoolean(Solved); + } + + /** + * Loads the parameter from a DataInputStream. + * + * @param in the DataInputStream to read from + * @throws IOException if an I/O error occurs + */ + public void Load(DataInputStream in) throws IOException { + type = in.readInt(); + xindex = in.readInt(); + value = in.readDouble(); + Solved = in.readBoolean(); + } + } \ No newline at end of file diff --git a/src/main/java/maths/PolyBasic.java b/src/main/java/maths/PolyBasic.java index 892d5ae5..26ec1ec4 100644 --- a/src/main/java/maths/PolyBasic.java +++ b/src/main/java/maths/PolyBasic.java @@ -2,13 +2,11 @@ import java.util.Vector; -//import java.util.regex.Pattern; -//import java.math.BigDecimal; -//import java.math.MathContext; import java.math.BigInteger; -//import java.math.RoundingMode; - +/** + * This class provides basic polynomial operations. + */ public class PolyBasic { private static int MAXSTR = 100; final private static double ZERO = 10E-6; @@ -16,19 +14,41 @@ public class PolyBasic { private static boolean BB_STOP = false; private static boolean RM_SCOEF = true; + /** + * Returns the singleton instance of the PolyBasic class. + * + * @return the singleton instance of PolyBasic + */ public static PolyBasic getInstance() { return basic; } + /** + * Sets the BB\_STOP flag. + * + * @param t the new value for the BB\_STOP flag + */ public static void setbbStop(boolean t) { BB_STOP = t; } + /** + * Sets the RM\_SCOEF flag. + * + * @param s the new value for the RM\_SCOEF flag + */ public static void setRMCOEF(boolean s) { RM_SCOEF = s; } - +/** + * Adds two polynomials. + * + * @param p1 the first polynomial + * @param p2 the second polynomial + * @param es a flag indicating whether to perform exact simplification + * @return the resulting polynomial after addition + */ private TMono pp_plus(TMono p1, TMono p2, boolean es) { if (p1 == null) return p2; @@ -100,16 +120,36 @@ private TMono pp_plus(TMono p1, TMono p2, boolean es) { return (poly); } - + /** + * Subtracts one polynomial from another. + * + * @param p1 the first polynomial + * @param p2 the second polynomial + * @return the resulting polynomial after subtraction + */ private TMono pp_minus(TMono p1, TMono p2) { TMono m = pp_plus(p1, cp_times(-1, p2), true); return m; } + /** + * Multiplies a polynomial by a constant. + * + * @param c the constant to multiply by + * @param p1 the polynomial to be multiplied + * @return the resulting polynomial after multiplication + */ public TMono cp_times(long c, TMono p1) { return cp_times(BigInteger.valueOf(c), p1); } + /** + * Multiplies a polynomial by a constant. + * + * @param c the constant to multiply by + * @param p1 the polynomial to be multiplied + * @return the resulting polynomial after multiplication + */ private TMono cp_times(BigInteger c, TMono p1) { if (p1 == null || c.compareTo(BigInteger.ZERO) == 0) return null; if (c.compareTo(BigInteger.ONE) == 0) return p1; @@ -126,6 +166,13 @@ private TMono cp_times(BigInteger c, TMono p1) { return p1; } + /** + * Multiplies two polynomials. + * + * @param p1 the first polynomial + * @param p2 the second polynomial + * @return the resulting polynomial after multiplication + */ private TMono pp_times(TMono p1, TMono p2) //(m X n) { if (p1 == null || p2 == null) return null; @@ -168,6 +215,13 @@ private TMono pp_times(TMono p1, TMono p2) //(m X n) return (poly); } + /** + * Multiplies two monomials. + * + * @param p1 the first monomial + * @param p2 the second monomial + * @return the resulting monomial after multiplication + */ private TMono mp_times(TMono p1, TMono p2) // p1.x <= p2.x { TMono poly = p2; @@ -199,6 +253,12 @@ private TMono mp_times(TMono p1, TMono p2) // p1.x <= p2.x return (poly); } + /** + * Checks if the given polynomial is zero. + * + * @param m the polynomial to check + * @return true if the polynomial is zero, false otherwise + */ public boolean check_zero(TMono m) { if (m == null) return false; if (m.x == 0 && m.value() == 0) return true; @@ -211,16 +271,30 @@ public boolean check_zero(TMono m) { return false; } + /** + * Returns the degree of the given polynomial `p` with respect to the variable `x`. + * + * @param p the polynomial to check + * @param x the variable to check the degree against + * @return the degree of the polynomial with respect to `x` + */ public int deg(TMono p, int x) { if (p.x == x) return p.deg; if (p.x > x) { int d1 = deg(p.coef, x); int d2 = deg(p.next, x); - return d1 > d2 ? d1 : d2; + return Math.max(d1, d2); } return 0; } + /** + * Reduces the given polynomial `m` using the provided parameters `p`. + * + * @param m the polynomial to be reduced + * @param p the array of parameters used for reduction + * @return the reduced polynomial + */ public TMono reduce(TMono m, Param[] p) { if (m == null) return null; @@ -249,7 +323,13 @@ else if (pm.xindex == x) { return m; } - // simplify an tmono to low degree. Note here we don't remove coef. + /** + * Simplifies a polynomial to a lower degree without removing coefficients. + * + * @param m the polynomial to simplify + * @param p the array of parameters used for simplification + * @return the simplified polynomial + */ public TMono simplify(TMono m, Param[] p) { if (m == null) return null; @@ -277,6 +357,13 @@ else if (pm.xindex == x) { return m; } + /** + * Computes the pseudo-remainder of two polynomials. + * + * @param p1 the first polynomial + * @param p2 the second polynomial + * @return the pseudo-remainder of the two polynomials + */ public TMono prem(TMono p1, TMono p2) { if (p1 == null) return p1; @@ -301,6 +388,13 @@ public TMono prem(TMono p1, TMono p2) { return result; } + /** + * Returns the degree of the polynomial `m` with respect to the variable `x`. + * + * @param m the polynomial + * @param x the variable + * @return the degree of the polynomial with respect to `x` + */ private int degree(TMono m, int x) { if (m == null || m.x < x) return 0; @@ -311,59 +405,61 @@ private int degree(TMono m, int x) { return 0; } + /** + * Checks if the pseudo-remainder of two polynomials can be computed. + * + * @param p1 the first polynomial + * @param p2 the second polynomial + * @return true if the pseudo-remainder can be computed, false otherwise + */ private boolean can_prem3(TMono p1, TMono p2) { if (p1 == null || p2 == null) return false; return prem3(p1, p2, false) == null; } + /** + * Computes the pseudo-remainder of two polynomials. + * + * @param p1 the first polynomial + * @param p2 the second polynomial + * @return the pseudo-remainder of the two polynomials + */ private TMono prem3(TMono p1, TMono p2) { return prem3(p1, p2, true); } - private TMono prem3(TMono p1, TMono p2, boolean r /*do all*/) { // p1.x > p2.x. + /** + * Computes the pseudo-remainder of two polynomials. + * + * @param p1 the first polynomial + * @param p2 the second polynomial + * @param r a flag indicating whether to perform all steps + * @return the pseudo-remainder of the two polynomials + */ + private TMono prem3(TMono p1, TMono p2, boolean r) { if (p2 == null) return p1; int x = p2.x; if (x == 0) return p1; TMono[] mm = new TMono[2]; - getm2(p1, p2, mm);//, x, p2.deg, mm); + getm2(p1, p2, mm); boolean rx = false; while (mm[0] != null && mm[1] != null) { -// int d1 = degree(mm[0], x); -// int d2 = degree(p2, x); if (p1 != null) { -// if (d1 >= d2) { -// int dd = d1 - d2; { -// TMono l1 = ptimes(p_copy(mm[0].coef), mm[1]); -// if (rx) { -// print(p1); -// print(p2); -// print(mm[0]); -// print(mm[1]); -// } TMono t1 = pp_times(p1, mm[0]); TMono t2 = pp_times(p_copy(p2), mm[1]); -// if(rx) -// { -// print(t1); -// print(t2); -// } p1 = pp_minus(t1, t2); coefgcd(p1); -// if (rx) { -// print(p1); -// System.out.println("\n"); -// } if (p1 == null) break; } } if (p1 == null) break; mm[0] = mm[1] = null; - getm2(p1, p2, mm);// x, p2.deg, mm); // mm[0]: coef , mm[1]. p.x + getm2(p1, p2, mm); if (!r && mm[1] != null && mm[1].x < p1.x) return p1; @@ -371,7 +467,15 @@ private TMono prem3(TMono p1, TMono p2, boolean r /*do all*/) { // p1.x > p2.x return p1; } - private void getm2(TMono p1, TMono p2, TMono[] mm) {// int x, int deg, TMono[] mm) { + + /** + * Computes the monomials `mm` required for the pseudo-remainder calculation. + * + * @param p1 the first polynomial + * @param p2 the second polynomial + * @param mm an array to store the resulting monomials + */ + private void getm2(TMono p1, TMono p2, TMono[] mm) { if (p1 == null || p2 == null || p1.x < p2.x || p1.x == p2.x && p1.deg < p2.deg) return; @@ -400,24 +504,16 @@ private void getm2(TMono p1, TMono p2, TMono[] mm) {// int x, int deg, TMono[] m if (p1 != null && p1.deg == 0) p1 = p1.coef; } - -// if (p.x > x) { -// while (p != null) { -// getm2(p.coef, x, deg, mm); -// if (mm[0] != null) { -// TMono m = pth(p.x, 1, p.deg); -// mm[1] = ptimes(mm[1], m); -// return; -// } -// p = p.next; -// } -// } else if (p.deg >= deg) { -// mm[0] = p; -// mm[1] = pth(0, 1, 0); -// return; -// } } + + /** + * Computes the pseudo-remainder of two polynomials. + * + * @param p1 the first polynomial + * @param p2 the second polynomial + * @return the pseudo-remainder of the two polynomials + */ private TMono prem1(TMono p1, TMono p2) { if (p1 == null) @@ -448,12 +544,6 @@ else if (p1.x > p2.x) { int d1 = deg(p1); int d2 = deg(p2); if (d1 < d2) { - /*TMono m = p1; //comment by ye. 5.31. - p1 = p2; - p2 = m; - int t = d1; - d1 = d2; - d2 = t;*/ break; } if (d1 >= d2) { @@ -477,12 +567,17 @@ else if (p1.x > p2.x) { while (result != null && result.deg == 0 && result.x != 0) result = result.coef; - -// print(result); return result; } + /** + * Divides the degree of the polynomial `m` by `n` for the variable `x`. + * + * @param m the polynomial to be modified + * @param x the variable whose degree is to be divided + * @param n the divisor for the degree + */ public void div_factor1(TMono m, int x, int n) { if (x > m.x) return; @@ -510,39 +605,11 @@ public void div_factor1(TMono m, int x, int n) { } - public void factor2(TMono m1) { - TMono m = this.get_factor2(m1); - if (m == null) - return; - while (m != null) { - if (m.x != 0) { - this.div_factor1(m1, m.x, m.deg); - } - m = m.coef; - } - } - - public TMono get_factor2(TMono m) { - if (m == null) - return null; - - TMono mx = null; - TMono m1 = m; - long n = 0; - while (m != null) { - if (m.x != 0) - n = factor_contain(m.x, m.deg, m1); - if (n != 0) { - if (mx == null) - mx = new TMono(m.x, 1, (int) n); - else - mx = this.pp_times(mx, new TMono(m.x, 1, (int) n)); - } - m = m.coef; - } - return mx; - } - + /** + * Factors the polynomial `m1` by dividing it by its common factors. + * + * @param m1 the polynomial to be factored + */ public void factor1(TMono m1) { if (!RM_SCOEF) return; @@ -558,6 +625,12 @@ public void factor1(TMono m1) { } } + /** + * Gets the common factors of the polynomial `m`. + * + * @param m the polynomial to get factors from + * @return the common factors of the polynomial + */ public TMono get_factor1(TMono m) { if (m == null) return null; @@ -580,6 +653,14 @@ public TMono get_factor1(TMono m) { return mx; } + /** + * Checks if the polynomial `m` contains the factor `(x, d)`. + * + * @param x the variable of the factor + * @param d the degree of the factor + * @param m the polynomial to check + * @return true if the polynomial contains the factor, false otherwise + */ private boolean m_contain(long x, long d, TMono m) { if (m == null || x > m.x || x == m.x && d > m.deg) return false; @@ -594,6 +675,14 @@ private boolean m_contain(long x, long d, TMono m) { return false; } + /** + * Determines the minimum degree of the factor `(x, n)` contained in the polynomial `m`. + * + * @param x the variable of the factor + * @param n the degree of the factor + * @param m the polynomial to check + * @return the minimum degree of the factor contained in the polynomial + */ private long factor_contain(long x, long n, TMono m) { if (m == null) return n; @@ -622,6 +711,13 @@ else if (t < n) return n; } + /** + * Removes the common factors of the polynomial `p1` using the polynomial `p2`. + * + * @param p1 the polynomial to be factored + * @param p2 the polynomial used for factoring + * @return the factored polynomial + */ public TMono factor_remove(TMono p1, TMono p2) { // p1 ,p2 be destryoed. if (p1 == null || p2 == null || plength(p1) > 1000) return p1; @@ -671,7 +767,13 @@ public TMono factor_remove(TMono p1, TMono p2) { // p1 ,p2 be destryoed. return p1; } - + /** + * Divides the polynomial `m` by the polynomial `d`. + * + * @param m the dividend polynomial + * @param d the divisor polynomial + * @return the quotient polynomial + */ TMono div(TMono m, TMono d) { if (m == null || d == null) return m; @@ -726,6 +828,12 @@ TMono div(TMono m, TMono d) { return result; } + /** + * Creates a copy of the polynomial `p`. + * + * @param p the polynomial to copy + * @return the copied polynomial + */ public TMono p_copy(TMono p) { if (p == null) return null; @@ -739,7 +847,13 @@ public TMono p_copy(TMono p) { } - + /** + * Compares two polynomials. + * + * @param p1 the first polynomial + * @param p2 the second polynomial + * @return -1 if p1 is less than p2, 1 if p1 is greater than p2, 0 if they are equal + */ private int pp_compare(TMono p1, TMono p2) { if (p1 == null && p2 == null) return 0; @@ -758,6 +872,12 @@ private int pp_compare(TMono p1, TMono p2) { return pp_compare(p1.next, p2.next); } + /** + * Pushes a polynomial into a sorted vector. + * + * @param m the polynomial to push + * @param v the vector to push into + */ public void ppush(TMono m, Vector v) { if (m == null) return; @@ -772,6 +892,13 @@ public void ppush(TMono m, Vector v) { v.add(m); } + /** + * Compares two polynomials for sorting. + * + * @param p1 the first polynomial + * @param p2 the second polynomial + * @return -1 if p1 is less than p2, 1 if p1 is greater than p2, 0 if they are equal + */ private int pp_compare2(TMono p1, TMono p2) { if (p1 == null && p2 == null) return 0; @@ -801,84 +928,12 @@ private int pp_compare2(TMono p1, TMono p2) { return n; } - private int pp_compare1(TMono p1, TMono p2) { - if (p1 == null && p2 == null) - return 0; - if (p1 == null && p2 != null) - return -1; - if (p1 != null && p2 == null) - return 1; - int x = Math.max(p1.x, p2.x) + 1; - while (x != 0) { - int x1 = getNextX(x, -1, p1); - int x2 = getNextX(x, -1, p2); - if (x1 > x2) - return 1; - else if (x1 < x2) - return -1; - else { - int d1 = this.getMaxDeg(x1, 1000, -1, p1); - int d2 = this.getMaxDeg(x2, 1000, -1, p2); - if (d1 > d2) - return 1; - else if (d1 < d2) - return -1; - else { - int d = d1; - while (d != 0) { - d1 = this.getMaxDeg(x1, d, -1, p1); - d2 = this.getMaxDeg(x2, d, -1, p2); - if (d1 > d2) - return 1; - else if (d1 < d2) - return -1; - d--; - } - } - x = x1; - } - } - return 1; - } - - private int getNextX(int x, int x1, TMono m) { // x1 < x . - if (m == null) return x1; - if (m.x <= x1) return x1; - while (m != null) { - if (m.x <= x1) return x1; - - if (m.x < x && m.x > x1) - x1 = m.x; - x1 = getNextX(x, x1, m.coef); - m = m.next; - if (m == null) - break; - if (m.deg == 0) - m = m.coef; - } - return x1; - } - - private int getMaxDeg(int x, int dmax, int d, TMono m) { // dd < d , dd > d1; return dd; - if (m == null) return d; - if (m.x < x) return d; - - while (m != null) { - if (m.x < x) return d; - - if (m.x == x && m.deg > d && m.deg < dmax) - d = m.deg; - d = getMaxDeg(x, dmax, d, m.coef); - m = m.next; - if (m == null) - break; - - if (m.deg == 0) - m = m.coef; - } - return d; - } - + /** + * Checks if the given polynomial is an integer. + * + * @param p the polynomial to check + * @return true if the polynomial is an integer, false otherwise + */ private boolean Int(TMono p) { if (p == null) return false; @@ -890,14 +945,11 @@ private boolean Int(TMono p) { return false; } - public void dprint(TMono p, int dx) { - upValueTM(p, -dx); - String s = getExpandedPrint(p); - System.out.println(s); -// print(p); - upValueTM(p, dx); - } - + /** + * Prints the given polynomial. + * + * @param p the polynomial to print + */ public void print(TMono p) { if (p == null) return; @@ -907,15 +959,27 @@ public void print(TMono p) { System.out.print(String_p_print(p, false, true, true)); -// p_print(p, false, true); System.out.print("\n"); } + /** + * Prints the polynomial in a simplified format. + * + * @param p the polynomial to print + */ public void sprint(TMono p) { p_print(p, false, true); } - private void p_print(TMono p, boolean ce, boolean first) { // coefficent ? print "+" of first ? + + /** + * Prints the polynomial in a specified format. + * + * @param p the polynomial to print + * @param ce a flag indicating whether to enclose the polynomial in parentheses + * @param first a flag indicating whether this is the first polynomial in a sequence + */ + private void p_print(TMono p, boolean ce, boolean first) { if (p == null) return; if (p.next == null) ce = false; @@ -946,6 +1010,12 @@ private void p_print(TMono p, boolean ce, boolean first) { // coefficent ? } } + /** + * Prints a monomial in a polynomial. + * + * @param p the monomial to print + * @param first a flag indicating whether this is the first monomial in the polynomial + */ private void m_print(TMono p, boolean first) { if (p.x == 0) { if (first != true) { @@ -981,14 +1051,37 @@ private void m_print(TMono p, boolean first) { } } + + /** + * Creates a new monomial with the specified variable, coefficient, and degree. + * + * @param x the variable of the monomial + * @param c the coefficient of the monomial + * @param d the degree of the monomial + * @return the created monomial + */ public TMono pth(int x, int c, int d) { return new TMono(x, c, d); } + /** + * Creates a new monomial with the specified variable, BigInteger coefficient, and degree. + * + * @param x the variable of the monomial + * @param c the BigInteger coefficient of the monomial + * @param d the degree of the monomial + * @return the created monomial + */ public TMono pth(int x, BigInteger c, int d) { return new TMono(x, c, d); } + /** + * Returns the degree of the given polynomial. + * + * @param p the polynomial + * @return the degree of the polynomial + */ public int deg(TMono p) { if (p == null) { int k = 0; @@ -996,15 +1089,32 @@ public int deg(TMono p) { return p.deg; } + /** + * Returns the leading variable of the given polynomial. + * + * @param p the polynomial + * @return the leading variable of the polynomial + */ public int lv(TMono p) { if (p == null) return 0; return p.x; } + /** + * Returns a zero polynomial. + * + * @return a zero polynomial + */ public TMono pzero() { return null; } + /** + * Returns the length of the given polynomial. + * + * @param m the polynomial + * @return the length of the polynomial + */ public int plength(TMono m) { if (m == null) return 0; @@ -1015,12 +1125,12 @@ public int plength(TMono m) { } } - boolean pzerom(TMono m) { - if (m == null) - return true; - return (!pzerop(m.coef) && m.next == null); - } - + /** + * Checks if the given polynomial is zero. + * + * @param m the polynomial to check + * @return true if the polynomial is zero, false otherwise + */ public boolean pzerop(TMono m) { if (m == null) return true; @@ -1029,7 +1139,13 @@ public boolean pzerop(TMono m) { return pzerop(m.coef) && pzerop(m.next); } - + /** + * Adds a monomial to a polynomial. + * + * @param t the monomial to add + * @param p the polynomial to add to + * @return the resulting polynomial after addition + */ TPoly addpoly(TMono t, TPoly p) { TPoly poly = new TPoly(); poly.setNext(p); @@ -1038,17 +1154,14 @@ TPoly addpoly(TMono t, TPoly p) { return poly; } - TPoly addPolytoList(TPoly pl, TPoly pp) { - if (pl == null) return pp; - - while (pl != null) { - pp = ppush(pl.getPoly(), pp); - pl = pl.getNext(); - } - return pp; - } - - public TPoly ppush(TMono t, TPoly pp) { // n, n-1,,,,,,1. + /** + * Pushes a polynomial into a sorted linked list. + * + * @param t the polynomial to push + * @param pp the linked list to push into + * @return the updated linked list with the polynomial added + */ + public TPoly ppush(TMono t, TPoly pp) { if (t == null) return pp; @@ -1104,6 +1217,13 @@ public TPoly ppush(TMono t, TPoly pp) { // n, n-1,,,,,,1. return pp; } + /** + * Calculates the value of a polynomial given the polynomial and parameters. + * + * @param m the polynomial to calculate + * @param p the array of parameters used in the calculation + * @return the calculated value of the polynomial + */ double calpoly(TMono m, Param[] p) { if (m == null || p == null) return 0.0; @@ -1123,6 +1243,13 @@ public TPoly ppush(TMono t, TPoly pp) { // n, n-1,,,,,,1. } + /** + * Calculates the values of the polynomial `mm` given the parameters `p`. + * + * @param mm the polynomial to calculate + * @param p the array of parameters used in the calculation + * @return an array of calculated values of the polynomial + */ public double[] calculv(TMono mm, Param[] p) { int x, d; double[] result = null; @@ -1210,6 +1337,13 @@ else if (d == 4 && ee != 0) return null; } + /** + * Calculates the values of the polynomial `mm` given the parameters `p` for two variables. + * + * @param mm the polynomial to calculate + * @param p the array of parameters used in the calculation + * @return an array of calculated values of the polynomial + */ public double[] calculv_2v(TMono mm, Param[] p) { if (mm.next != null) return this.calculv(mm.next.coef, p); @@ -1217,11 +1351,16 @@ public double[] calculv_2v(TMono mm, Param[] p) { return null; } -// public double[] calculate_onlinex(TMono mm, param[] p, int dx, int dy) { -// CLine ln = this. - -// } + /** + * Calculates the values of the polynomial `mm` given the parameters `p` for two variables. + * + * @param mm the polynomial to calculate + * @param p the array of parameters used in the calculation + * @param dx the first variable index + * @param dy the second variable index + * @return an array of calculated values of the polynomial + */ public double[] calculate_online(TMono mm, Param[] p, int dx, int dy) { if (mm.deg != 1 && mm.x != dy) return null; @@ -1258,6 +1397,15 @@ public double[] calculate_online(TMono mm, Param[] p, int dx, int dy) { return result; } + /** + * Calculates the values of the polynomial `mm` given the parameters `p` for two variables. + * + * @param mm the polynomial to calculate + * @param p the array of parameters used in the calculation + * @param dx the first variable index + * @param dy the second variable index + * @return an array of calculated values of the polynomial + */ public double[] calculate_oncr(TMono mm, Param[] p, int dx, int dy) { if (mm.deg != 2 && mm.x != dy) return null; @@ -1304,7 +1452,15 @@ public double[] calculate_oncr(TMono mm, Param[] p, int dx, int dy) { return result; } - public double[] calculv2poly(TMono mm1, TMono mm2, Param[] p) //from two poly + /** + * Calculates the values of two polynomials `mm1` and `mm2` given the parameters `p`. + * + * @param mm1 the first polynomial to calculate + * @param mm2 the second polynomial to calculate + * @param p the array of parameters used in the calculation + * @return an array of calculated values of the polynomials + */ + public double[] calculv2poly(TMono mm1, TMono mm2, Param[] p) { int x, d; double[] result; @@ -1362,7 +1518,6 @@ public double[] calculv2poly(TMono mm1, TMono mm2, Param[] p) //from two pol if (result == null || result.length == 0) result = calculv(mm2, p); if (result == null || result.length == 0) { -// System.out.println("parell two line"); return null; } return result; @@ -1370,62 +1525,91 @@ public double[] calculv2poly(TMono mm1, TMono mm2, Param[] p) //from two pol } + /** + * Multiplies two polynomials. + * + * @param p1 the first polynomial + * @param p2 the second polynomial + * @return the product of the two polynomials + */ public TMono pRtimes(TMono p1, TMono p2) { return pp_times(p1, p2); } - public TMono pQtimer(TMono t1, TMono t2, TMono t3, TMono t4) { - return this.pp_times(p_copy(t1), pp_times(p_copy(t2), pp_times(p_copy(t3), p_copy(t4)))); - } - + /** + * Adds two polynomials. + * + * @param p1 the first polynomial + * @param p2 the second polynomial + * @return the sum of the two polynomials + */ public TMono padd(TMono p1, TMono p2) { //add TMono m = (pp_plus(p1, p2, true)); return m; } + /** + * Subtracts the second polynomial from the first polynomial. + * + * @param p1 the first polynomial + * @param p2 the second polynomial + * @return the difference of the two polynomials + */ public TMono pdif(TMono p1, TMono p2) {//minus TMono m = (pp_minus(p1, p2)); return m; } - TMono redundancy(TMono m) { - return m; - } - - boolean isZero(TMono m) { - if (m == null) return true; - if (Int(m)) { - if (m.value() == 0) - return true; - else - return false; - } - - if (m.x != 0 && m.coef == null) return isZero(m.next); - return false; - } - + /** + * Creates a copy of the given polynomial. + * + * @param p the polynomial to copy + * @return the copied polynomial + */ public TMono pcopy(TMono p) { return p_copy(p); } + /** + * Multiplies two polynomials. + * + * @param p1 the first polynomial + * @param p2 the second polynomial + * @return the product of the two polynomials + */ public TMono ptimes(TMono p1, TMono p2) { return pp_times(p1, p2); } + /** + * Multiplies a polynomial by a constant. + * + * @param p the polynomial + * @param c the constant + * @return the product of the polynomial and the constant + */ public TMono pctimes(TMono p, long c) { return cp_times(BigInteger.valueOf(c), p); } - void pr(TMono m) { - print(m); - } - + /** + * Prints the given polynomial. + * + * @param m the polynomial to print + */ public void printpoly(TMono m) { print(m); } + + /** + * Gets the monomial with the minimum degree for the given variable in the polynomial. + * + * @param x the variable + * @param p the polynomial + * @return the monomial with the minimum degree for the given variable + */ TMono getMinV(int x, TPoly p) { TMono poly = null; int exp = 0; @@ -1447,36 +1631,12 @@ TMono getMinV(int x, TPoly p) { } - - public TPoly OptimizePoly(TPoly poly) { - TPoly t = poly; - while (poly != null) { - TMono m = poly.getPoly(); - m = opt(m); - poly.setPoly(m); - poly = poly.getNext(); - } - return t; - } - - TMono opt(TMono m) { - if (m == null) return null; - - if (Int(m)) return m; - - if (m.x <= 3 && m.x > 0) - return null; - - m.coef = opt(m.coef); - m.next = opt(m.next); - - if (m.coef == null && m.deg != 0) m = m.next; - if (isZero(m)) return null; - - return m; - } - - + /** + * Returns the head of the polynomial as a string. + * + * @param m the polynomial + * @return the head of the polynomial as a string + */ public String printHead(TMono m) { if (m == null) return "0"; @@ -1488,11 +1648,22 @@ public String printHead(TMono m) { return "x" + v; } + /** + * Returns a simplified string representation of the polynomial. + * + * @param m the polynomial + * @return the simplified string representation of the polynomial + */ public String printSPoly(TMono m) { return printSPoly(m, MAXSTR); } - + /** + * Returns a string representation of the polynomial with a maximum length. + * + * @param m the polynomial + * @return the string representation of the polynomial with a maximum length + */ public String printNPoly(TMono m) { if (m == null) return ""; @@ -1504,6 +1675,13 @@ public String printNPoly(TMono m) { return s; } + /** + * Returns a string representation of two polynomials with a maximum length. + * + * @param m1 the first polynomial + * @param m2 the second polynomial + * @return the string representation of the two polynomials with a maximum length + */ public String printNPoly(TMono m1, TMono m2) { int n1 = plength(m1); int n2 = plength(m2); @@ -1516,6 +1694,13 @@ public String printNPoly(TMono m1, TMono m2) { return s1 + s2 + " != 0"; } + /** + * Returns a simplified string representation of the polynomial with a specified maximum length. + * + * @param m the polynomial + * @param n the maximum length of the string representation + * @return the simplified string representation of the polynomial with a specified maximum length + */ public String printSPoly(TMono m, int n) { if (m == null) return "0"; @@ -1527,6 +1712,12 @@ public String printSPoly(TMono m, int n) { return s; } + /** + * Returns a string representation of the polynomial with a maximum length. + * + * @param m the polynomial + * @return the string representation of the polynomial with a maximum length + */ public String printMaxstrPoly(TMono m) { int n = MAXSTR; if (m == null) @@ -1538,35 +1729,15 @@ public String printMaxstrPoly(TMono m) { return s; } - public String printSPoly1(TMono m, int n) { - if (m == null) - return ""; - - String s = StringPrint(m); - if (s.length() > n) - return s.substring(0, n) + "...."; - - return s; - } - - public String StringPrint(TMono p) { - StringBuffer buffer = new StringBuffer(); - String_p_print(p, true, buffer); - return buffer.toString(); - } - - public void String_p_print(TMono p, boolean nn, StringBuffer buffer) { - if (p == null) return; - while (p != null) { - if (String_mprint(p.coef, buffer)) - buffer.insert(0, '+'); - buffer.append("x" + p.x + "" + p.deg); - if (p.deg == 0) - p = p.coef; - else p = p.next; - } - } - + /** + * Returns a string representation of the polynomial. + * + * @param p the polynomial + * @param ce a flag indicating whether to enclose the polynomial in parentheses + * @param first a flag indicating whether this is the first polynomial in a sequence + * @param nn a flag indicating whether to include the leading coefficient + * @return the string representation of the polynomial + */ public String String_p_print(TMono p, boolean ce, boolean first, boolean nn) { if (p == null) return ""; if (p.next == null) ce = false; @@ -1606,29 +1777,12 @@ public String String_p_print(TMono p, boolean ce, boolean first, boolean nn) { return s; } - - public boolean String_mprint(TMono m, StringBuffer buffer) { - boolean br = false; - if (m == null) return br; - - if (m.next != null) - br = true; - if (br) - buffer.append("("); - while (m != null) { - String_mprint(m.coef, buffer); - if (String_mprint(m.coef, buffer)) - buffer.insert(0, '+'); - buffer.append(m.x + "" + m.deg); - if (m.deg == 0) - m = m.coef; - else m = m.next; - } - if (br) - buffer.append(")"); - return br; - } - + /** + * Returns a string representation of the polynomial with expanded format. + * + * @param p the polynomial + * @return the string representation of the polynomial with expanded format + */ public String getExpandedPrint(TMono p) { String r = ep_print(p, "", true); if (r != null && (r.endsWith("-") || r.endsWith("+"))) @@ -1636,6 +1790,14 @@ public String getExpandedPrint(TMono p) { return r; } + /** + * Returns a string representation of the polynomial with expanded format. + * + * @param p the polynomial + * @param s the string to append to + * @param f a flag indicating whether this is the first polynomial in a sequence + * @return the string representation of the polynomial with expanded format + */ private String ep_print(TMono p, String s, boolean f) { String st = ""; while (p != null) { @@ -1654,6 +1816,14 @@ private String ep_print(TMono p, String s, boolean f) { return st; } + /** + * Returns a string representation of the polynomial with expanded format. + * + * @param p the polynomial + * @param s the string to append to + * @param f a flag indicating whether this is the first polynomial in a sequence + * @return the string representation of the polynomial with expanded format + */ private String eprint(TMono p, String s, boolean f) { if (p == null) return ""; @@ -1694,6 +1864,13 @@ private String eprint(TMono p, String s, boolean f) { } } + /** + * Returns a string representation of all printed monomials in the polynomial. + * + * @param p the polynomial + * @param b a flag indicating whether to include the leading coefficient + * @return the string representation of all printed monomials in the polynomial + */ public String getAllPrinted(TMono p, boolean b) { int n = MAXSTR; MAXSTR = 1000000; @@ -1724,11 +1901,25 @@ public String getAllPrinted(TMono p, boolean b) { else return s; } + /** + * Returns a string representation of all printed monomials in the polynomial. + * + * @param p the polynomial + * @return the string representation of all printed monomials in the polynomial + */ public String getAllPrinted(TMono p) { return getAllPrinted(p, true); } + /** + * Returns a string representation of the monomial. + * + * @param p the monomial + * @param first a flag indicating whether this is the first monomial in the polynomial + * @param nn a flag indicating whether to include the leading coefficient + * @return the string representation of the monomial + */ private String String_m_print(TMono p, boolean first, boolean nn) { @@ -1774,6 +1965,12 @@ else if (t != 1) return s; } + /** + * Returns the greatest common divisor of the coefficients of the polynomial. + * + * @param p the polynomial + * @return the greatest common divisor of the coefficients of the polynomial + */ public BigInteger coefgcd(TMono p) { if (p == null) return BigInteger.ONE; @@ -1793,6 +1990,13 @@ public BigInteger coefgcd(TMono p) { return c; } + /** + * Divides the coefficients of the polynomial by the given constant. + * + * @param m the polynomial + * @param c the constant to divide by + * @return true if successful, false otherwise + */ private boolean coef_div(TMono m, BigInteger c) { if (m == null) return true; if (m.x == 0) { @@ -1806,23 +2010,24 @@ private boolean coef_div(TMono m, BigInteger c) { } + /** + * Returns the greatest common divisor of two BigInteger values. + * + * @param a the first BigInteger + * @param b the second BigInteger + * @return the greatest common divisor of the two BigInteger values + */ BigInteger gcd(BigInteger a, BigInteger b) { return a.gcd(b); } - private long gcd(long a, long b) { - long t; - - a = Math.abs(a); - b = Math.abs(b); - while (b != 0) { - t = b; - b = a % b; - a = t; - } - return a; - } - + /** + * Returns the greatest common divisor of the coefficients of the polynomial. + * + * @param p the polynomial + * @param c the constant to divide by + * @return the greatest common divisor of the coefficients of the polynomial + */ private BigInteger coefgcd(TMono p, BigInteger c) { if (p == null) return c; @@ -1847,10 +2052,24 @@ private BigInteger coefgcd(TMono p, BigInteger c) { return c; } + /** + * Checks if the given value is close to zero. + * + * @param r the value to check + * @return true if the value is close to zero, false otherwise + */ private boolean ZERO(double r) { return Math.abs(r) < ZERO; } + /** + * Solves a quadratic polynomial equation. + * + * @param aa the coefficient of x^2 + * @param bb1 the coefficient of x + * @param bb2 the constant term + * @return an array of solutions to the equation + */ private double[] poly_solve_quadratic(double aa, double bb1, double bb2) { double[] result; @@ -1884,6 +2103,15 @@ private double[] poly_solve_quadratic(double aa, double bb1, double bb2) { return result; } + /** + * Solves a cubic polynomial equation. + * + * @param a the coefficient of x^3 + * @param b the coefficient of x^2 + * @param c the coefficient of x + * @param d the constant term + * @return an array of solutions to the equation + */ double[] poly_solve_cubic(double a, double b, double c, double d) { double p = (3 * c / a - (b * b / (a * a))) / 3; double q = (2 * Math.pow(b / a, 3) - 9 * b * c / a / a + 27 * d / a) / 27; @@ -1918,6 +2146,12 @@ private double[] poly_solve_quadratic(double aa, double bb1, double bb2) { return null; } + /** + * Calculates the cubic root of a given value. + * + * @param r the value to calculate the cubic root of + * @return the cubic root of the value + */ private double cubic_root(double r) { double r1 = Math.pow(Math.abs(r), 1.0 / 3.0); if (r < 0) @@ -1925,50 +2159,15 @@ private double cubic_root(double r) { return r1; } -// double[] cal_e4(double A, double B, double C, double D, double E, double rt) { -// double a = -3 * B * B / (8 * A * A) + C / A; -// double b = B * B * B / (8 * A * A * A) - B * C / (2 * A * A) + D / A; -// double c = -3 * B * B * B * B / (256 * A * A * A * A) + C * B * B / (16 * A * A * A) - B * D / (4 * A * A) + E / A; -// double p = -a * a / 12 - c; -// double q = -a * a * a / 108 + a * c / 3 - b * b / 8; -// double r = q / 2 + Math.sqrt(q * q / 4 + p * p * p / 27); -// double u = Math.pow(r, 1 / 3.0); -// double y = -5 / 6 * a - u; -// if (Math.abs(u) > ZERO) -// y += p / (3 * u); -// -// double w = Math.sqrt(a + 2 * y); -// double t1 = -(3 * a + 2 * y + 2 * b / w); -// double t2 = -(3 * a + 2 * y - 2 * b / w); -// int n = 0; -// double v1, v2, v3, v4; -// if (t1 < 0 && t2 < 0) -// return null; -// else if (t1 > 0 && t2 > 0) -// n = 4; -// else -// n = 2; -// -// int i = 0; -// double d[] = new double[n]; -// -// if (t1 > 0) { -// v1 = -b / (4 * a) + (w + Math.sqrt(t1)) / 2; -// v2 = -b / (4 * a) + (w - Math.sqrt(t1)) / 2; -// d[i++] = v1 / rt; -// d[i++] = v2 / rt; -// -// } -// -// if (t2 > 0) { -// v3 = -b / (4 * a) + (-w + Math.sqrt(t2)) / 2; -// v4 = -b / (4 * a) + (-w - Math.sqrt(t2)) / 2; -// d[i++] = v3 / rt; -// d[i++] = v4 / rt; -// } -// return d; -// } - + /** + * Solves a quartic polynomial equation. + * + * @param a the coefficient of x^4 + * @param b the coefficient of x^3 + * @param c the coefficient of x^2 + * @param d the coefficient of x + * @return an array of solutions to the equation + */ double[] poly_solve_quartic(double a, double b, double c, double d) { /* * This code is based on a simplification of @@ -2061,16 +2260,6 @@ private double cubic_root(double r) { u[0] = A + B - rc / 3; u[1] = -0.5 * (A + B) - rc / 3; u[2] = -(Math.sqrt(3.0) / 2.0) * mod_diffAB; -// double sgnR = (R >= 0 ? 1 : -1); -// double modR = Math.abs(R); -// double sqrt_disc = Math.sqrt(R2 - Q3); -// double A = -sgnR * Math.pow(modR + sqrt_disc, 1.0 / 3.0); -// double B = Q / A; -// double mod_diffAB = Math.abs(A - B); -// -// u[0] = A + B - rc / 3; -// u[1] = -0.5 * (A + B) - rc / 3; -// u[2] = -(Math.sqrt(3.0) / 2.0) * mod_diffAB; } } @@ -2193,6 +2382,13 @@ private double cubic_root(double r) { ///////////////////////////////////////////////////////////////////////////////////////////////////////// + /** + * Calculates the polynomial value for the given monomial and coefficients. + * + * @param m the monomial + * @param p the coefficients + * @return the polynomial value + */ BigFraction calpoly(TMono m, BigFraction[] p) { if (m == null || p == null) return BigFraction.ZERO; @@ -2216,192 +2412,26 @@ BigFraction calpoly(TMono m, BigFraction[] p) { return r; } - public int check_ndg(TMono m, Param[] pm) // 0. TRUE 1. FALSE 2.CAN NOT Verify, should be checked by floating point calculation. - { - if (m == null) - return 1; - - int x = m.x; - int n = 0; - for (n = 0; n < pm.length; n++) { - Param p = pm[n]; - if (p == null || p.xindex >= x) - break; - } - BigFraction[] bp = new BigFraction[n + 1]; - - int r = ndg_valid(m, pm, bp, 0); - if (r == -1) { - long k = 1; - for (int i = 0; i <= n; i++) { - if (pm[i].m == null) { - bp[i] = bp[i].add(BigInteger.valueOf(2 * k + 1)); - r = ndg_valid(m, pm, bp, 0); - if (r != -1) - return r; - k++; - } - } - } - - for (int i = 0; i < bp.length; i++) - if (bp[i] != null) - System.out.println(bp[i]); - return -1; - } - - public int ndg_valid(TMono m, Param[] pm, BigFraction[] bp, int n) { - for (int i = n; i < bp.length && pm[i] != null; i++) { - Param p = pm[i]; - if (p.m == null) { - if (bp[i] == null) - bp[i] = new BigFraction((long) p.value); - } else { - BigFraction[] bb = calcu_pm(p.m, bp, p); - if (bb == null) // no solution. - return -1; - else if (bb.length == 0) - return 1; // not equal.. - else if (bb.length == 1) - bp[i] = bb[0]; - else { - for (int j = 0; j < bb.length; j++) { - bp[i] = bb[j]; - int b1 = ndg_valid(m, pm, bp, i + 1); - if (b1 != 1) - return b1; - } - } - } - } - boolean r = calpoly(m, bp).compareTo(BigInteger.ZERO) == 0; - if (r) - return 0; - else return 1; - } - - public BigFraction[] calcu_pm(TMono m, BigFraction[] bp, Param pm) { // return null if m.coef == 0 - if (m.deg == 1) { - BigFraction a = calpoly(m.coef, bp); - if (a.isZero()) return null; - - BigFraction b = calpoly(m.next, bp); - BigFraction[] bb = new BigFraction[1]; - bb[0] = b.divide(a).negate(); - return bb; - } else if (m.deg == 2) { - BigFraction a, b, c; - a = calpoly(m.coef, bp); - if (a.isZero()) return null; - m = m.next; - if (m.deg == 1) { - b = calpoly(m.coef, bp); - m = m.next; - } else b = BigFraction.ZERO; - c = calpoly(m.coef, bp); - BigFraction dl = b.multiply(b).subtract(a.multiply(4).multiply(c)); - dl = dl.sqrt(); - if (dl != null) { - BigFraction[] bb = new BigFraction[2]; - bb[0] = (b.negate().add(dl).divide(a.multiply(2))); - bb[1] = (b.negate().subtract(dl).divide(a.multiply(2))); - return bb; - } else return null; - } else if (m.deg == 3) { - BigFraction a, b, c, d; - a = b = c = d = BigFraction.ZERO; - while (m != null) { - BigFraction f = calpoly(m.coef, bp); - switch (m.x) { - case 3: - a = f; - break; - case 2: - b = f; - break; - case 1: - c = f; - break; - case 0: - d = f; - break; - } - m = m.next; - } - if (a.isZero()) return null; - } - return new BigFraction[0]; - } - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - private boolean n2dv(TMono m) { - if (plength(m) != 2) return false; - m = m.next; - if (m == null) return false; - return Int(m.coef); - } - - public TPoly gb_reduce(TPoly poly) { -// return bb_reduce(poly); - return null; - } - - public void nn_reduce(TPoly poly) { - while (poly != null) { - TMono m = poly.poly; - if (n2dv(m)) { - while (m != null && m.x != 0) { - nn_div1(m.x, poly.next); - m = m.coef; - } - } - poly = poly.next; - } - } - - public void nn_div1(int x, TPoly poly) { - - while (poly != null) { - TMono m = poly.poly; - while (true) { - long n = factor_contain(x, 1, m); - if (n > 0) - div_factor1(m, x, (int) n); - else break; - } - poly = poly.next; - } - } - - public TMono g_prem(TMono p1, TMono p2) { -// if (p1 == null) -// return p1; -// if (p2 == null) -// return p1; -// if (p1.x < p2.x) -// return p1; -// -// TMono result = null; -// if (p1.x == p2.x) -// result = prem1(p1, p2); -// else -// result = prem3(p1, p2); -// -// coefgcd(result); -// -// return result; - return null; - } - - + /** + * Reduces the polynomial by dividing it by the leading term of another polynomial. + * + * @param vlist the list of polynomials to reduce + * @param t the time limit for reduction + * @return the reduced polynomial + */ public Vector bb_reduce(Vector vlist, long t) { bb_reduce(vlist, t, false); -// bb_reduce(vlist, t, false); -// bb_reduce(vlist, t, true); - return vlist; } + /** + * Reduces the polynomial by dividing it by the leading term of another polynomial. + * + * @param vlist the list of polynomials to reduce + * @param t the time limit for reduction + * @param s a flag indicating whether to use a special reduction method + * @return the reduced polynomial + */ public Vector bb_reduce(Vector vlist, long t, boolean s) { @@ -2439,7 +2469,6 @@ public Vector bb_reduce(Vector vlist, long t, boolean s) { ppush(m2, vlist); } size = vlist.size(); - // i = size -2; } } if (r) break; @@ -2447,68 +2476,13 @@ public Vector bb_reduce(Vector vlist, long t, boolean s) { return vlist; } - - public void divm(TMono m1, TMono m) { - if (m1 == null || m == null || m1.x <= m.x) return; - - while (m != null && m.x != 0) { - while (true) { - long n = factor_contain(m.x, 1, m1); - if (n > 0) - div_factor1(m1, m.x, (int) n); - else break; - } - m = m.coef; - } - } - - public int get_n_paraent(TMono m) { - if (m == null) - return 0; - int n = 0; - while (m != null) - m = m.coef; - return n; - } - - public TMono sp_reduce(TMono m1, TMono m2) { //m1.x == m2.x - - - while (true) { - - if (m1 == null) return m1; - if (m2 == null) return m1; - if (m1.x != m2.x) - break; - if (m2.coef == null || m2.coef.coef != null) - break; - if (m2.deg != 1) - break; - - // basic.print(m1); - - BigInteger b1 = getLN(m1); - BigInteger b2 = getLN(m2); - - int n = m1.deg; - - BigInteger bc1 = BigInteger.ONE; - BigInteger coefm2 = m2.coef.val; - TMono e = p_copy(m2.next.coef); - e = this.pctimes(e, -1); - - TMono cpm2 = pth(0, 1, 1); - for (int i = 0; i < n; i++) { - bc1 = bc1.multiply(coefm2); - cpm2 = ptimes(cpm2, p_copy(e)); - } - m1 = padd(ptimes(m1.coef, cpm2), this.pctimes(m1.next, bc1.intValue())); -// basic.print(m1); - } - coefgcd(m1); - return m1; - } - + /** + * Reduces the polynomial by dividing it by the leading term of another polynomial. + * + * @param m1 the first polynomial + * @param vlist the list of polynomials to reduce + * @return the reduced polynomial + */ public TMono b_reduce(TMono m1, Vector vlist) { if (m1 == null) return null; @@ -2541,103 +2515,13 @@ public TMono b_reduce(TMono m1, Vector vlist) { return m1; } - private void ppmove(TPoly pp) { - if (pp == null) return; - TMono m = pp.poly; - TPoly tp = pp.next; - while (tp != null) { - TMono mx = tp.poly; - if (pp_compare(m, mx) < 0) { - tp.poly = m; - pp.poly = mx; - pp = tp; - } else break; - - tp = pp.next; - } - } - - private TPoly shink_poly(TPoly poly) { - if (poly == null) return null; - TPoly tp = poly; - while (tp.next != null) { - if (tp.next.poly == null) - tp.next = tp.next.next; - else - tp = tp.next; - } - if (poly.poly != null) - return poly; - return poly.next; - } - - - private int compare(TMono m1, TMono m2) { - if (m1 == null && m2 == null) return 0; - if (m1 == null && m2 != null) return -1; - if (m1 != null && m2 == null) return 1; - - if (m1.x == 0 && m2.x == 0) return 0; - if (m1.x == 0 && m2.x != 0) return -1; - if (m1.x != 0 && m2.x == 0) return 1; - - if (m1.x > m2.x || m1.x == m2.x && m1.deg > m2.deg) - return 1; - if (m1.x == m2.x && m1.deg == m2.deg) - return 0; - - return -1; - } - - private TMono m_head(TMono m) { - if (m == null) - return null; - while (!Int(m)) - m = m.coef; - return pth(0, m.val, 0); - } - -// private TMono bb_divnh(TMono m1, TMono m2) { -// if (m1 == null || m2 == null) return null; -// int n = compare(m1, m2); -// -// if (n < 0) return null; -// -// if (Int(m1) && Int(m2)) -// return new TMono(0, m1.val, 0); -// -// if (n == 0) { -// TMono mx = bb_divn(m1.coef, m2.coef); -// if (mx == null) -// mx = this.m_head(m1); -// return mx; -// } -// -// if (n > 0) { -// if (m1.x == m2.x) { -// TMono mx = bb_divn(m1.coef, m2.coef); -// if (mx == null) -// mx = this.m_head(m1); -// int dd = m1.deg - m2.deg; -// if (dd > 0) -// mx = pp_times(pth(m1.x, 1, dd), mx); -// -// return mx; -// } else { -// TMono mx = bb_divn(m1.coef, m2); -// if (mx != null) { -// int dd = m1.deg; -// if (dd > 0) -// mx = pp_times(pth(m1.x, 1, dd), mx); -// } -// return mx; -// -// } -// -// } -// return null; -// } - + /** + * Divides the leading term of one polynomial by the leading term of another polynomial. + * + * @param m1 the first polynomial + * @param m2 the second polynomial + * @return the result of the division + */ private TMono bb_divnh(TMono m1, TMono m2) { if (m1 == null || m2 == null) return null; @@ -2667,6 +2551,13 @@ else if (dd > 0) return pp_times(pth(m1.x, 1, m1.deg), mx); } + /** + * Divides the leading term of one polynomial by the leading term of another polynomial. + * + * @param m1 the first polynomial + * @param m2 the second polynomial + * @return the result of the division + */ private TMono bb_divn(TMono m1, TMono m2) { // get a term of m1 which diviid leading variable of m2. if (m1 == null || m2 == null) return null; @@ -2715,12 +2606,24 @@ else if (dd > 0) return null; } + + /** + * Prints the given vector of polynomials. + * + * @param v the vector of polynomials to print + */ public void printVpoly(Vector v) { for (int i = 0; i < v.size(); i++) this.print((TMono) v.get(i)); System.out.println("\n"); } + /** + * Computes the Groebner basis for the given vector of polynomials. + * + * @param v the vector of polynomials + * @return the Groebner basis as a vector of polynomials + */ public Vector g_basis(Vector v) { while (true) { bb_reduce(v, System.currentTimeMillis()); @@ -2741,6 +2644,12 @@ public Vector g_basis(Vector v) { return v; } + /** + * Computes the S-polynomials for the given vector of polynomials. + * + * @param vlist the vector of polynomials + * @return the S-polynomials as a vector of polynomials + */ public Vector s_polys(Vector vlist) { Vector v = new Vector(); @@ -2761,27 +2670,24 @@ public Vector s_polys(Vector vlist) { return v; } - private TMono s_poly(TMono m1, TMono m2) { - if (m1.x == m2.x && m1.deg >= m2.deg) { - - } else if (m_contain(m2.x, m2.deg, m1.coef)) { - - } else return null; - - TMono result; - m1 = p_copy(m1); - m2 = p_copy(m2); - if (m1.x == m2.x) { - result = prem1(m1, m2); - } else - result = prem3(m1, m2); - return result; - } - + /** + * Computes the S-polynomial for two given polynomials. + * + * @param m1 the first polynomial + * @param m2 the second polynomial + * @return the S-polynomial of the two polynomials + */ private TMono s_poly1(TMono m1, TMono m2) { return prem4(m1, m2); } + /** + * Computes the S-polynomial for two given polynomials. + * + * @param m1 the first polynomial + * @param m2 the second polynomial + * @return the S-polynomial of the two polynomials + */ private TMono prem4(TMono m1, TMono m2) { if (m1 == null || m2 == null) return null; if (m1.x < m2.x) return m1; @@ -2804,6 +2710,13 @@ private TMono prem4(TMono m1, TMono m2) { return null; } + /** + * Computes the greatest common divisor of two polynomials. + * + * @param m1 the first polynomial + * @param m2 the second polynomial + * @return the greatest common divisor of the two polynomials + */ private TMono gcd_h(TMono m1, TMono m2) { // gcd of m1, m2. (HEAD); if (m1 == null || m2 == null) return null; TMono mx = null; @@ -2832,6 +2745,13 @@ else if (m1.x < m2.x) return mx; } + /** + * Divides the leading term of one polynomial by the leading term of another polynomial. + * + * @param m1 the first polynomial + * @param m the second polynomial + * @return the result of the division + */ private TMono div_gcd(TMono m1, TMono m) { TMono mx = pth(0, 1, 0); @@ -2854,36 +2774,14 @@ private TMono div_gcd(TMono m1, TMono m) { return mx; } - private TMono[] mgcd(TMono m1, TMono m2) { - if (m1 == null || m2 == null) return null; - TMono[] mm = new TMono[2]; - bb_div2n(m1, m2, mm); - return mm; - } - - private void bb_div2n(TMono m1, TMono m2, TMono[] mm) { - if (m1 == null || m2 == null) return; - - while (m1 != null) { - if (m1.x > m2.x) { - bb_div2n(m1.coef, m2, mm); - if (mm[0] != null) { - mm[1] = ptimes(pth(m1.x, 1, m1.deg), mm[1]); - return; - } - } else if (m1.x == m2.x && m1.deg >= m2.deg) { - mm[0] = pth(0, 1, 0); - mm[1] = pth(0, 1, 0); - get_mm(m1, m2, mm); - return; - } else break; - - m1 = m1.next; - if (m1 != null && m1.deg == 0) - m1 = m1.coef; - } - } + /** + * Computes the greatest common divisor of two polynomials and stores the result in the provided array. + * + * @param m1 the first polynomial + * @param m2 the second polynomial + * @param mm the array to store the result + */ private void get_mm(TMono m1, TMono m2, TMono[] mm) { if (m1 == null || m2 == null) return; @@ -2912,6 +2810,12 @@ else if (m1.deg < m2.deg) get_mm(m1, m2, mm); } + /** + * Gets the leading coefficient of a polynomial. + * + * @param m the polynomial + * @return the leading coefficient + */ private BigInteger getLN(TMono m) { if (m == null) return null; while (!Int(m)) @@ -2919,70 +2823,14 @@ private BigInteger getLN(TMono m) { return m.val; } -// public void n_reduce(Vector v1, Vector nlist) { -// for (int i = 0; i < v1.size(); i++) { -// TMono m1 = (TMono) v1.get(i); -// boolean r = false; -// while (true) { -// boolean b = true; -// for (int j = 0; j < nlist.size(); j++) { -// TMono m2 = (TMono) nlist.get(j); -// TMono mm = gcd_h(m1, m2); -// if (mm != null && mm.x != 0) { -// TMono t1 = div_gcd(m1, mm); -// TMono t2 = div_gcd(m2, mm); -// print(m1); -// print(m2); -// m1 = pdif(ptimes(t2, p_copy(m1)), ptimes(t1, p_copy(m2))); -// -// if (CharSet.debug()) { -// print(m1); -// System.out.println("\n"); -// } -// -// r = true; -// b = false; -// } -// } -// if (b) break; -// } -// if (r) { -// v1.remove(i); -// if (m1 == null) -// i--; -// else -// v1.add(i, m1); -// } -// } -// } - - - public TMono ll_gbasis(TMono m1, TMono md, int x, int para) { - if (m1 == null) - return null; - - if (m1.deg == 1) { - TMono m11 = getxm1(x, 1, m1); // u1 - TMono m12 = getxm1(x - 1, 1, m1); // u2 - TMono c11 = pp_times(pth(para, 1, 1), p_copy(m11)); // zu1, - TMono c12 = pp_times(pth(para, 1, 1), p_copy(m12)); // zu2. - - TMono c2 = pth(x, 1, 1); // x1 - TMono t11 = ptimes(c11, p_copy(m1)); // zu1*x1 - TMono t12 = ptimes(c12, p_copy(m12)); // zu2^2 - - TMono t2 = pp_times(c2, p_copy(md)); // x1*md. - - t2 = pdif(t2, t11); - t2 = pp_times(p_copy(m11), t2); - TMono t13 = pp_times(p_copy(m12), pp_times(pth(para, 1, 1), p_copy(m12))); - - - return pdif(t2, pp_times(t13, p_copy(m1))); - } - return null; - } - + /** + * Computes the delta of two polynomials. + * + * @param x the variable + * @param m1 the first polynomial + * @param m2 the second polynomial + * @return the delta of the two polynomials + */ public TMono ll_delta(int x, TMono m1, TMono m2) { if (m1 == null) return null; if (m1.deg == 1) { @@ -3021,23 +2869,14 @@ public TMono ll_delta(int x, TMono m1, TMono m2) { return null; } - public TMono getxm1(int x, TMono m) { - if (m == null) - return null; - - if (m.x == x) - return m.coef; - - while (m.next != null) - m = m.next; - if (m.deg != 0) - return null; - m = m.coef; - if (m.deg == 1 && m.x == x) - return m.coef; - return null; - } - + /** + * Gets the leading coefficient of a polynomial. + * + * @param x the variable + * @param d the degree + * @param m the polynomial + * @return the leading coefficient + */ public TMono getxm1(int x, int d, TMono m) { if (m == null) return null; @@ -3058,6 +2897,12 @@ public TMono getxm1(int x, int d, TMono m) { return null; } + /** + * Updates the value of a polynomial by adding a given value to its coefficients. + * + * @param v the polynomial + * @param dx the value to add + */ public void upValueTM(Vector v, int dx) { if (dx == 0) return; @@ -3067,6 +2912,12 @@ public void upValueTM(Vector v, int dx) { } } + /** + * Updates the value of a polynomial by adding a given value to its coefficients. + * + * @param v the polynomial + * @param dx the value to add + */ public void upValueDM(Vector v, int dx) { for (int i = 0; i < v.size(); i++) { TDono d = (TDono) v.get(i); @@ -3076,6 +2927,12 @@ public void upValueDM(Vector v, int dx) { } } + /** + * Gets the maximum value of x in a vector of polynomials. + * + * @param v the vector of polynomials + * @return the maximum value of x + */ public int getMaxX(Vector v) { int x = 0; @@ -3087,6 +2944,12 @@ public int getMaxX(Vector v) { return x; } + /** + * Updates the value of a polynomial by adding a given value to its coefficients. + * + * @param m the polynomial + * @param dx the value to add + */ public void upValueTM(TMono m, int dx) { if (dx == 0) return; @@ -3107,8 +2970,13 @@ public void upValueTM(TMono m, int dx) { m = m.next; } } - - + + /** + * Checks if the polynomial is finished. + * + * @param v the vector of polynomials + * @return true if the polynomial is finished, false otherwise + */ public boolean gb_finished(Vector v) { for (int i = 0; i < v.size(); i++) { TMono m = (TMono) v.get(i); @@ -3118,6 +2986,11 @@ public boolean gb_finished(Vector v) { return false; } + /** + * Reduces the polynomial by removing terms with degree 0. + * + * @param v the vector of polynomials + */ public void ndg_reduce(Vector v) { for (int i = 0; i < v.size(); i++) { TMono m = (TMono) v.get(i); @@ -3128,7 +3001,13 @@ public void ndg_reduce(Vector v) { } } - + /** + * Gets the conditions for the given vector of polynomials. + * + * @param v the vector of polynomials + * @param dx the value to add + * @return the conditions as a vector of polynomials + */ public Vector getcnds(Vector v, int dx) { Vector v1 = new Vector(); for (int i = 0; i < v.size(); i++) { @@ -3142,93 +3021,14 @@ public Vector getcnds(Vector v, int dx) { return v1; } - public Vector specialTreatment(TMono m1, TMono m2, int dd) { - Vector v = new Vector(); - if (m1 == null) return v; - int x = m1.x; - - if (m1.deg == 1) { - TMono m11 = getxm1(x, 1, m1); - TMono m12 = getxm1(x - 1, 1, m1); - if (m2 == null) { - return v; - } - TMono m21 = getxm1(x, 1, m2); - TMono m22 = getxm1(x - 1, 1, m2); - - - TMono dmm = pdif(ptimes(p_copy(m1), p_copy(m21)), ptimes(p_copy(m11), p_copy(m2))); - dmm = ptimes(pth(dd, 1, 1), dmm); - - TMono dmm1 = pdif(ptimes(p_copy(m1), p_copy(m22)), ptimes(p_copy(m12), p_copy(m2))); - dmm1 = ptimes(pth(dd, 1, 1), dmm1); - v.add(dmm); - v.add(dmm1); - } - return v; - } - - public Vector updateTMM(Vector v, int s, int e, int dx, boolean up) { - Vector v3 = new Vector(); - - for (int i = 0; i < v.size(); i++) { - TMono m = (TMono) v.get(i); - TMono m2 = updateTMM(m, s, e, dx, up); - ppush(m2, v3); - } - return v3; - } - - private TMono updateTMM(TMono m, int s, int e, int dx, boolean up) { - - TMono mx = null; - - if (up) { - while (m != null) { - if (m.x < s && m.x != 0) { - TMono m1 = updateTMM(m.coef, s, e, dx, up); - m1 = ptimes(m1, pth(dx + m.x, 1, m.deg)); - mx = padd(mx, m1); - } else { - if (m.x == 0) { - TMono m1 = pth(0, m.val, m.deg); - mx = padd(mx, m1); - } else { - TMono m1 = updateTMM(m.coef, s, e, dx, up); - if (m.deg != 0) - m1 = ptimes(m1, pth(m.x, 1, m.deg)); - mx = padd(mx, m1); - } - - } - m = m.next; - } - } else { - while (m != null) { - if (m.x > e) { - TMono m1 = updateTMM(m.coef, s, e, dx, up); - m1 = ptimes(m1, pth(m.x - dx, 1, m.deg)); - mx = padd(mx, m1); - } else { - if (m.x == 0) { - TMono m1 = pth(0, m.val, m.deg); - mx = padd(mx, m1); - } else { - TMono m1 = updateTMM(m.coef, s, e, dx, up); - if (m.deg != 0) - m1 = ptimes(m1, pth(m.x, 1, m.deg)); - mx = padd(mx, m1); - } - } - m = m.next; - } - } - return mx; - } - - ////////////////////////////////////////////////////////////////// - //TDono; + /** + * Parses common Dono objects from the given vector of polynomials. + * + * @param v the vector of polynomials + * @param dx the value to add + * @return a vector of parsed Dono objects + */ public Vector parseCommonDono(Vector v, int dx) { Vector v1 = new Vector(); for (int i = 0; i < v.size(); i++) { @@ -3251,6 +3051,11 @@ public Vector parseCommonDono(Vector v, int dx) { return v1; } + /** + * Erases common Dono objects from the given vector of polynomials. + * + * @param v the vector of polynomials + */ public void eraseCommonDono(Vector v) { for (int i = 0; i < v.size(); i++) { TDono d = (TDono) v.get(i); @@ -3266,6 +3071,13 @@ public void eraseCommonDono(Vector v) { } } + /** + * Checks if two monomials are equal. + * + * @param m1 the first monomial + * @param m2 the second monomial + * @return true if the monomials are equal, false otherwise + */ public boolean ck_eq(TMono m1, TMono m2) { while (m1 != null && m2 != null) { if (m1.x != m2.x || m1.deg != m2.deg) @@ -3276,62 +3088,18 @@ public boolean ck_eq(TMono m1, TMono m2) { m2 = m2.next; } - return m1 == m2; // null - } - - public Vector parseDono(Vector v, int dx) { - Vector v1 = new Vector(); - Vector v2 = new Vector(); - - int ldx = 0; - for (int i = 0; i < v.size(); i++) { - TDono d = (TDono) v.get(i); - TMono m = d.p2; - - ldx = getLdx(m, dx); - if (ldx == 0) { - v1.add(d); - } else - v2.add(d); - } - - if (v2.size() == 0) return v1; - - boolean r = true; - - while (true) { - r = true; - - for (int i = 0; i < v2.size(); i++) { - TDono d = (TDono) v2.get(i); - reduceDono(d, v1, dx); - if (getLdx(d.p2, dx) == 0) { - v1.add(d); - v2.remove(d); - i--; - r = false; - } - } - if (r) break; - } - - return v1; - } - - private int getLdx(TMono m, int dx) { - while (m != null) { - - if (m.x > 0 && m.x < dx) - return m.x; - - int n = getLdx(m.coef, dx); - if (n > 0) - return n; - m = m.next; - } - return 0; + return m1 == m2; } + /** + * Checks if the polynomial is less than a given value. + * + * This method only traverses the `coef` chain of the polynomial. + * + * @param m the polynomial + * @param dx the value to compare with + * @return true if the polynomial is less than the given value, false otherwise + */ public boolean ctLessdx1(TMono m, int dx) { while (m != null) { if (m.x > 0 && m.deg > 0 && m.x < dx) @@ -3341,6 +3109,16 @@ public boolean ctLessdx1(TMono m, int dx) { return false; } + + /** + * Checks if the polynomial is less than a given value. + * + * This method traverses both the `coef` and `next` chains of the polynomial and uses recursion. + * + * @param m the polynomial + * @param dx the value to compare with + * @return true if the polynomial is less than the given value, false otherwise + */ public boolean ctLessdx(TMono m, int dx) { int r = 0; @@ -3357,21 +3135,13 @@ public boolean ctLessdx(TMono m, int dx) { return false; } - - private boolean ctLdx(TMono m, int i) { - while (m != null) { - - if (m.x > 0 && m.x == i) - return true; - - boolean n = ctLdx(m.coef, i); - if (n) - return n; - m = m.next; - } - return false; - } - + /** + * Gets the minimum leading degree of a polynomial. + * + * @param m the polynomial + * @param dx the value to compare with + * @return the minimum leading degree, or -1 if not found + */ private int MinLdx(TMono m, int dx) { int r = MinLdx(m); if (r >= dx) @@ -3379,6 +3149,12 @@ private int MinLdx(TMono m, int dx) { return r; } + /** + * Gets the minimum leading degree of a polynomial. + * + * @param m the polynomial + * @return the minimum leading degree + */ private int MinLdx(TMono m) { int r = Integer.MAX_VALUE; @@ -3396,26 +3172,14 @@ private int MinLdx(TMono m) { } - private int MaxLdx(TMono m, int dx) { - int r = 0; - - while (m != null) { - if (m.x == 0) - return -1; - if (m.x < dx) { - if (r < m.x) - r = m.x; - } - - int k = MaxLdx(m.coef, dx); - if (k > 0 && r < k) - r = k; - m = m.next; - } - return r; - } - + /** + * Gets the maximum leading degree of a polynomial. + * + * @param m the polynomial + * @param i the value to compare with + * @return the maximum leading degree + */ private int ctMLdx(TMono m, int i) { // MAX int r = 0; @@ -3439,6 +3203,14 @@ private int ctMLdx(TMono m, int i) { // MAX } + /** + * Reduces the polynomial by dividing it by the leading term of another polynomial. + * + * @param mm the polynomial to reduce + * @param v the vector of polynomials + * @param dx the value to add + * @return the reduced polynomial + */ public TMono reduceMDono(TMono mm, Vector v, int dx) { TMono m = mm; @@ -3461,8 +3233,6 @@ public TMono reduceMDono(TMono mm, Vector v, int dx) { for (int k = 0; k < rd; k++) { m = pp_times(m, p_copy(d1.p2)); } -// dprint(m, 9); -// dprint(m2, 9); TMono dp = basic.p_copy(d1.p1); div_factor1(dp, max, 1); @@ -3485,41 +3255,19 @@ public TMono reduceMDono(TMono mm, Vector v, int dx) { if (BB_STOP) return null; } -// this.print(m); coefgcd(m); } } return m; } - public void reduceDono(TDono d, Vector v, int dx) { - for (int i = 1; i < dx; i++) { - if (!ctLdx(d.p2, i)) - continue; - - int n = i; - - TDono d1 = getDo(v, n); - if (d1 != null) { - TMono m = d.p2; - TMono m2 = this.padd(pp_times(p_copy(d1.p1), p_copy(d1.p2)), p_copy(d1.c)); - TMono mx = bb_divn(m, m2); - if (mx == null) { - m = pp_times(m, p_copy(d1.p2)); - mx = bb_divn(m, m2); - } - - - while (mx != null && mx.x != 0) { - BigInteger b2 = getLN(m2); - m = pdif(cp_times(b2, m), pp_times(mx, p_copy(m2))); - mx = bb_divn(m, m2); - } - d.p2 = m; - } - } - } - + /** + * Gets the Dono object from the given vector of polynomials. + * + * @param v the vector of polynomials + * @param n the value to compare with + * @return the Dono object, or null if not found + */ public TDono getDo(Vector v, int n) { TDono xd = null; int nn = -1; @@ -3544,87 +3292,13 @@ public TDono getDo(Vector v, int n) { return xd; } - - public void d_reduce(TDono d1, Vector vlist) { - if (d1 == null) return; - - TMono m1 = d1.p2; - BigInteger bb = BigInteger.ONE; - - - while (true) { - boolean r = true; - for (int i = 0; i < vlist.size(); i++) { - TMono m2 = (TMono) vlist.get(i); - TMono m = bb_divnh(m1, m2); - while (m != null) { - BigInteger b2 = getLN(m2); - bb.multiply(b2); - m1 = pdif(cp_times(b2, m1), pp_times(m, p_copy(m2))); - if (m1 == null) break; - r = false; - m = bb_divn(m1, m2); - } - } - if (r) break; - } -// d1.p1 = cp_times(bb, d1.p1); - d1.c = cp_times(bb, d1.c); - d1.p2 = m1; - } - - - public void splitDonos(Vector vnn, Vector vnds, int dx) { - Vector vtemp = new Vector(); - - while (true) { - while (vnds.size() != 0) { - TMono tx = getMaxDMono(vnds, dx); -// this.dprint(tx, 9); - - int max = MaxLdx(tx, dx); - int min = MinLdx(tx, dx); - vnds.remove(tx); - - - if (max != min) { - tx = reduceMDono(tx, vnn, dx); - max = MaxLdx(tx, dx); - } - - if (max == min) { - TDono d = splitDono(tx, dx); - if (d != null) - vnn.add(d); - } else { - vtemp.add(tx); - } - } - if (vtemp.size() == 0) - break; - else { - vnds.addAll(vtemp); - vtemp.clear(); - } - } - - } - - public TMono getMaxDMono(Vector vnds, int dx) { - int k = 0; - TMono tx = null; - - for (int i = 0; i < vnds.size(); i++) { - TMono m = (TMono) vnds.get(i); - int x = this.MaxLdx(m, dx); - if (x > k) { - k = x; - tx = m; - } - } - return tx; - } - + /** + * Splits the given monomial into a Dono object. + * + * @param m the monomial + * @param dx the value to add + * @return the Dono object + */ public TDono splitDono(TMono m, int dx) { TMono m1 = m; TMono c = null; @@ -3643,8 +3317,6 @@ public TDono splitDono(TMono m, int dx) { TMono mx = this.pp_minus(p_copy(m), p_copy(c)); - int minX = this.MinLdx(mx, dx); - TMono mo = pth(0, 1, 0); TMono mf = get_factor1(mx); while (mf != null && mf.x != 0) { @@ -3662,33 +3334,5 @@ public TDono splitDono(TMono m, int dx) { return new TDono(mo, mx, c); } - - public void reduceMdo(Vector vrs, int dx) { - for (int i = 0; i < vrs.size(); i++) { - TMono m = (TMono) vrs.get(i); - int max = this.MaxLdx(m, dx); - int min = this.MinLdx(m, dx); - if (max == min) - continue; - - - } - - } - - - public TMono getMono(TDono d) { - TMono m = padd(pp_times(p_copy(d.p1), p_copy(d.p2)), p_copy(d.c)); - coefgcd(m); - if (m == null) - return m; - - if (this.getLN(m).intValue() < 0) { - m = cp_times(-1, m); - return m; - } - return m; - } - } diff --git a/src/main/java/maths/TDono.java b/src/main/java/maths/TDono.java index a5187d16..236265f9 100644 --- a/src/main/java/maths/TDono.java +++ b/src/main/java/maths/TDono.java @@ -1,17 +1,23 @@ package maths; /** - * Created by IntelliJ IDEA. - * User: ye - * Date: 2008-4-7 - * Time: 9:59:11 - * To change this template use File | Settings | File Templates. + * Represents a Dono object which contains three polynomials. + * + *

This class is used to store and manipulate polynomials in the context of + * polynomial operations. Each Dono object consists of three polynomials: p1, p2, and c.

*/ public class TDono { public TMono p1; public TMono p2; public TMono c; + /** + * Constructs a new TDono object with the specified polynomials. + * + * @param p1 the first polynomial + * @param p2 the second polynomial + * @param c the third polynomial + */ public TDono(TMono p1, TMono p2, TMono c) { this.p1 = p1; this.p2 = p2; diff --git a/src/main/java/maths/TMono.java b/src/main/java/maths/TMono.java index 2e6a3f8f..9b68e9e1 100644 --- a/src/main/java/maths/TMono.java +++ b/src/main/java/maths/TMono.java @@ -2,6 +2,9 @@ import java.math.BigInteger; +/** + * Represents a monomial in a polynomial. + */ public class TMono { public int x = 0; public int deg = 0; @@ -9,10 +12,17 @@ public class TMono { public TMono coef = null; public TMono next = null; + /** + * Default constructor. + */ public TMono() { - } + /** + * Returns the value of the monomial. + * + * @return the value of the monomial as a long + */ public long value() { if (val != null) return val.longValue(); @@ -23,6 +33,13 @@ public long value() { } } + /** + * Constructs a monomial with the specified variable, value, and degree. + * + * @param x the variable + * @param val the value + * @param deg the degree + */ public TMono(int x, BigInteger val, int deg) { this.x = x; this.deg = deg; @@ -39,6 +56,13 @@ public TMono(int x, BigInteger val, int deg) { } } + /** + * Constructs a monomial with the specified variable, value, and degree. + * + * @param x the variable + * @param val the value + * @param deg the degree + */ public TMono(int x, int val, int deg) { this.x = x; this.deg = deg; @@ -49,9 +73,15 @@ public TMono(int x, int val, int deg) { } else { this.coef = new TMono(0, val, 0); } - } + /** + * Constructs a monomial with the specified variable, coefficient, and degree. + * + * @param x the variable + * @param coef the coefficient + * @param deg the degree + */ public TMono(int x, TMono coef, int deg) { this.x = x; this.deg = deg; diff --git a/src/main/java/maths/TPoly.java b/src/main/java/maths/TPoly.java index aa449016..2e36a8bd 100644 --- a/src/main/java/maths/TPoly.java +++ b/src/main/java/maths/TPoly.java @@ -1,29 +1,62 @@ package maths; +/** + * Represents a polynomial linked list. + * + *

This class is used to store and manipulate polynomials in a linked list structure. + * Each node in the list contains a polynomial (TMono) and a reference to the next node.

+ */ public class TPoly { public TMono poly; public TPoly next; + /** + * Default constructor. + */ public TPoly() { } + /** + * Returns the next node in the list. + * + * @return the next node + */ public TPoly getNext() { return next; } + /** + * Returns the polynomial of the current node. + * + * @return the polynomial + */ public TMono getPoly() { return poly; } + /** + * Sets the next node in the list. + * + * @param next the next node + */ public void setNext(TPoly next) { this.next = next; } + /** + * Sets the polynomial of the current node. + * + * @param poly the polynomial + */ public void setPoly(TMono poly) { this.poly = poly; } - + /** + * Returns the length of the polynomial linked list. + * + * @return the length of the list + */ public int length() { TPoly tp = this; int i = 0; @@ -33,31 +66,5 @@ public int length() { i++; } return i; - - } - - public long callength() { - TPoly p = this; - long len = 0; - while (p != null) { - long l = p.plength(p.getPoly()) + 1; - len = len + l; - p = p.getNext(); - } - return len; } - - private long plength(TMono p) { - TMono pt; - int i; - - pt = p; - i = -1; - while (pt != null) { - i = i + 1; - pt = pt.next; - } - return i; - } - } diff --git a/src/main/java/maths/package-info.java b/src/main/java/maths/package-info.java new file mode 100644 index 00000000..d2969944 --- /dev/null +++ b/src/main/java/maths/package-info.java @@ -0,0 +1,5 @@ +/** + * This package provides functionalities for mathematical operations. + * It serves as a foundation for further mathematical computations in the project. + */ +package maths; \ No newline at end of file diff --git a/src/main/java/pdf/BoundingBox.java b/src/main/java/pdf/BoundingBox.java index 34d4ba12..72673678 100644 --- a/src/main/java/pdf/BoundingBox.java +++ b/src/main/java/pdf/BoundingBox.java @@ -25,6 +25,10 @@ import java.awt.*; import java.util.*; +/** + * This class represents a bounding box. + * It holds coordinate information and properties used for graphical operations. + */ public class BoundingBox extends Rectangle { /** Percent f line height to space lines */ @@ -81,29 +85,6 @@ public class BoundingBox extends Rectangle /** Link to parent box */ private BoundingBox parent; - - /** - * If this box was the result of a getStringBounds call, this - * array will hold the broken strings - */ - private String[] stringArray; - - /** The string specified in getStringBounds */ - private String fullString; - - /** - * Creates a new BoundingBox instance. - * - * @param p a Point, upper left coords - * @param d a Dimension, used to determine height and width - */ - public BoundingBox(Point p, Dimension d) { - super(p, d); - this.drawingPoint = this.getLocation(); - this.absoluteLocation = this.getLocation(); - } - - /** *

Returns true if this box has a parent. The 'world', or @@ -179,56 +160,6 @@ public void setParent(BoundingBox parent) { } // end if } // end setParent - - - - - /** - *

Get the wrapped strings if this box was from a call to getStringBounds, - * otherwise this method returns null

- * - * @return a String[] array of strings, top to bottom in layout - */ - public String[] getStringArray() { - return stringArray; - } // end getStringArray - - - - /** - *

Set the value of the string array

- * - * @param strArray a String array - * - */ - public void setStringArray(String[] strArray) { - this.stringArray = strArray; - } - - - /** - *

Set the absolute upper left world location point for this box

- * - * @param point a Point value - */ - public void setAbsoluteLocation(Point point) { - this.absoluteLocation = point; - } - - - - /** - *

Returns false if for any reason this box has negative dimensions

- * - * @return true if the box has positive height and width, false otherwise. - */ - public boolean boxExists() { - return (this.getHeight() > 0 && this.getWidth() > 0); - } // end boxExists - - - - /** *

Get the absolute upper left location point for this box

* @@ -237,627 +168,6 @@ public boolean boxExists() { public Point getAbsoluteLocation() { return absoluteLocation; } - - - /** - *

Returns the full string associated with a call to - * getStringBounds

- * - * @return the full string. - */ - public String getFullString() { - return fullString; - } - - - /** - *

Sets the full string associated with getStringBounds

- * - * @param string a String - */ - public void setFullString(String string) { - this.fullString = string; - } - - public BoundingBox getStringBounds(String string, - int hAlign, - int vAlign, - FontMetrics fm, - int padding, - boolean enforce) - throws IllegalArgumentException, StringTooLongException { - // Check to make sure the values passed in are valid - if (!checkHAlign(hAlign)) { - throw new IllegalArgumentException("BoundingBox.getStringBounds, " + - "hAlign invalid : " + hAlign); - } - if (!checkVAlign(vAlign)) { - throw new IllegalArgumentException("BoundingBox.getStringBounds, " + - "vAlign invalid : " + hAlign); - } - if (fm == null) { - throw new IllegalArgumentException("BoundingBox.getStringBounds, " + - "FontMetrics null"); - } - if (string == null) { - throw new IllegalArgumentException("BoundingBox.getStringBounds, " + - "String null"); - } - - // NOTE: For this portion of the method, parent refers - // to this object and child refers to the object about - // to be created. When the absolute point for drawing the - // String is determined, this object's ancestors are checked. - Dimension parentSize = this.getSize(); - - Point childLocation; - Dimension childSize; - - // String ascent, width, height, parent, child width, height - int sa, sw, sh, pw, ph, cw, ch; - - // Child, parent x, y coords for upper left - int cx, cy, px, py; - - sa = fm.getMaxAscent(); - sw = fm.stringWidth(string); - sh = sa + fm.getMaxDescent(); - pw = (int)parentSize.getWidth(); - ph = (int)parentSize.getHeight(); - if (pw < 0) { - throw new StringTooLongException("The parent box has a negative width " + - " (" + pw + ")"); - } - if (ph < 0) { - throw new StringTooLongException("The parent box has a negative height"+ - " (" + ph + ")"); - } - cw = sw + padding*2; - ch = sh + padding*2; - px = (int)this.getX(); - py = (int)this.getY(); - - String[] childStrArray = null; - - if ((cw > pw) || (string.indexOf("\n") != -1)) { - cw = pw - (padding * 2); - childStrArray = createStringArray(string, fm, padding, pw); - ch = getWrappedHeight(childStrArray, fm, padding); - if (ch > ph) { - // If enforce is not true, it means we want the box to - // be returned anyway (along with the strings in the array) - // so we can chop them manually and try again - if (enforce) { - throw new StringTooLongException("The wrapped strings do not " + - "fit into the parent box, pw=" + pw + - ", ph=" + ph + ", ch=" + ch + ", cw=" + cw + - ", string: " + string); - } - } - } - - // Need to have child width and height, and string array set - - // Child location is relative to this (parent) box, not the world - if (vAlign == VERT_ALIGN_TOP) { - cy = 0; - } - else if (vAlign == VERT_ALIGN_CENTER) { - cy = (ph/2) - (ch/2); - } - else { - cy = ph - ch; - } - - if (hAlign == HORIZ_ALIGN_LEFT) { - cx = 0; - } - else if (hAlign == HORIZ_ALIGN_CENTER) { - cx = (pw/2) - (cw/2); - } - else { - cx = pw - cw; - } - - childLocation = new Point(cx, cy); - childSize = new Dimension(cw, ch); - - // Drawing location is based on the baseline of the String, and - // relative to the world, not this box. The drawing point differs - // from the absolute box location because of padding and ascent - int dpx, dpy, abx, aby; - - // If this object also has a parent (maybe grandparents), iterate - // through them and find the absolute 'world' location - int ancestorTranslateX = 0; - int ancestorTranslateY = 0; - - BoundingBox ancestor = this; - while (ancestor.hasParent()) { - BoundingBox oldRef = ancestor; - ancestor = ancestor.getParent(); - // Prevent infinite recursion - if (ancestor == oldRef) { - break; - } - ancestorTranslateX += (int)ancestor.getLocation().getX(); - ancestorTranslateY += (int)ancestor.getLocation().getY(); - } - - // Determine the absolute location for the box - abx = px + cx + ancestorTranslateX; - aby = py + cy + ancestorTranslateY; - - // Determine the absolute drawing point for the String - dpx = abx + padding; - dpy = aby + padding + sa; - - Point drawingPoint = new Point(dpx, dpy); - BoundingBox returnChild = new BoundingBox(childLocation, - childSize, - drawingPoint, - new Point(abx, aby)); - this.add(returnChild); - returnChild.setFullString(string); - returnChild.setStringArray(childStrArray); - return returnChild; - - } // end getStringBounds - - - /** - *

Gets the location of a String after it is adjusted for - * alignment within this box. The point's coordinates are - * either within this box or within the enclosing area.

- * - *

By default, this method enforces string length and throws the - * exception if it is too long

- * - * @param string a String, the String to be placed - * @param hAlign an int, HORIZ_ALIGN_CENTER, - * HORIZ_ALIGN_LEFT, HORIX_ALIGN_RIGHT - * @param vAlign an int, VERT_ALIGN_CENTER, - * VERT_ALIGN_TOP, VERT_ALIGN_BOTTOM - * @param fm a FontMetrics object for this String - * @param padding an int, the padding around the String - * @return a Point, the coords to use in drawString() - * @throws IllegalArgumentException if the args are invalid - * @throws StringTooLongException if the string won't fit - */ - public BoundingBox getStringBounds(String string, - int hAlign, - int vAlign, - FontMetrics fm, - int padding) - throws StringTooLongException, IllegalArgumentException { - return getStringBounds(string, hAlign, vAlign, fm, padding, true); - } // end getStringBounds (enforce true by default) - - - public void drawWrappedString(Graphics g, - FontMetrics fm, - int padding, - int hAlign) - throws IllegalArgumentException, StringTooLongException { - if (getStringArray() == null) { - Point p = getDrawingPoint(); - int xx = (int)p.getX(); - int yy = (int)p.getY(); - g.drawString(getFullString(), xx, yy); - } - else { - int len = stringArray.length; - for (int i = 0; i < len; i++) { - BoundingBox wrappedBox = null; - wrappedBox = getStringBounds(stringArray[i], - hAlign, - BoundingBox.VERT_ALIGN_TOP, - fm, - 0); - Point pp = wrappedBox.getDrawingPoint(); - int xx = (int)pp.getX(); - if (hAlign == BoundingBox.HORIZ_ALIGN_RIGHT) { - xx -= padding; - } - if (hAlign == BoundingBox.HORIZ_ALIGN_LEFT) { - xx += padding; - } - int yy = (int)pp.getY() + padding; - g.drawString(stringArray[i], xx, yy); - subtract(wrappedBox, BoundingBox.SUBTRACT_FROM_BOTTOM); - } - } - } // end drawWrappedString - - - /** - *

Draws lines from the wrapped string until there is no more room and - * then stops. If there is no string or the box is too small for - * anything to be drawn, does nothing

- * - * @param g the Graphics object to draw to - * @param fm the FontMetrics object to use for string sizing - * @param padding the int amount of padding around the string - * @param hAlign the int horizontal alignment - * - */ - public void drawWrappedStringTruncate(Graphics g, - FontMetrics fm, - int padding, - int hAlign) { - - if (getStringArray() == null) { - Point p = getDrawingPoint(); - int xx = (int)p.getX(); - int yy = (int)p.getY(); - if (getFullString() != null) { - g.drawString(getFullString(), xx, yy); - } - else { - System.err.println("getStringArray and getFullString are null"); - } - } - else { - int totalHeight = 0; - int len = stringArray.length; - for (int i = 0; i < len; i++) { - BoundingBox wrappedBox = null; - try { - wrappedBox = getStringBounds(stringArray[i], - hAlign, - BoundingBox.VERT_ALIGN_TOP, - fm, - 0, - false); - totalHeight += (int)wrappedBox.getHeight(); - if (getParent() != null) { - if (totalHeight > (int)(getParent().getHeight())) { - return; - } - } - } - catch (StringTooLongException stle) { - stle.printStackTrace(); - return; - } - wrappedBox.drawChoppedString(g, fm, padding, hAlign); - subtract(wrappedBox, BoundingBox.SUBTRACT_FROM_BOTTOM); - } - } - } // end drawWrappedStringTruncate - - - /** - *

Take the first line of the string (if it is wrapped, otherwise just - * take the whole string) and chop the end of it off to make it fit in the - * box. If the box is smaller than one letter, draw nothing

- * - * @param g the Graphics object to draw to - * @param fm the FontMetrics object to use for string sizing - * @param padding the int amount of padding around the string - * @param hAlign the int horizontal alignment - */ - public void drawChoppedString(Graphics g, - FontMetrics fm, - int padding, - int hAlign) { - - String string = ""; - if (getStringArray() != null) { - string = new String(getStringArray()[0]); - } - else { - string = new String(getFullString()); - } - BoundingBox choppedBox = null; - try { - choppedBox = getStringBounds(string, - hAlign, - VERT_ALIGN_TOP, - fm, - padding); - Point p = choppedBox.getDrawingPoint(); - int x = (int)p.getX(); - int y = (int)p.getY(); - g.drawString(string, x, y); - } - catch (StringTooLongException stle) { - // Doesn't fit - start cutting from the end until it does - StringBuffer buf = new StringBuffer().append(string); - if (buf.length() == 0) { - System.out.println("BoundingBox.drawChoppedString, buf len 0 ??"); - //return; - throw new RuntimeException(); - } - buf.deleteCharAt(buf.length()-1); - while ((fm.stringWidth(buf.toString()) > (int)getWidth()) && - (buf.length() > 0)) { - buf.deleteCharAt(buf.length()-1); - } - - try { - choppedBox = getStringBounds(buf.toString(), - hAlign, - VERT_ALIGN_TOP, - fm, - padding); - Point pp = choppedBox.getDrawingPoint(); - int xx = (int)pp.getX(); - int yy = (int)pp.getY(); - g.drawString(string, xx, yy); - } - catch (StringTooLongException sstle) { - // Must be a really small box! - sstle.printStackTrace(); - } - } - } // end drawChoppedString - - - - - - - - - - /** - *

Get the total height of the box needed to contain the strings in - * the specified array

- */ - private int getWrappedHeight(String[] strings, FontMetrics fm, int padding) { - int ma = fm.getMaxAscent(); - int md = fm.getMaxDescent(); - int sh = ma + md; - int hPad = sh / LINE_SPACING_PERCENTAGE; - sh += hPad; - int total = sh * strings.length; - - return total + (padding*2); - } // end getWrappedHeight - - - - /** - * - *

Make a string array from a string, wrapped to fit the box

- * - *

If the line width is too short, the array is just a - * tokenized version of the string

- * - * @param string - the String to convert to an array - * @param - */ - private String[] createStringArray(String string, - FontMetrics fm, - int padding, - int pw) { - if (string == null) { - System.err.println("Tried createStringArray with null String"); - return null; - } - if (fm == null) { - System.err.println("Tried createStringArray with null FontMetrics"); - } - - int lw = pw - (padding*2); - - - - Vector returnVector = new Vector(); - // Return delimiters as tokens - StringTokenizer st = new StringTokenizer(string, " \t\n\r\f", true); - StringBuffer tempBuffer = new StringBuffer(); - StringBuffer finalBuffer = new StringBuffer(); - - while(st.hasMoreTokens()) { - // Get the next word and add a space after it - String tempString = st.nextToken(); - tempBuffer.append(tempString); - - // If we haven't reached the width with our current - // line, keep adding tokens. Also, check for hard returns - if ((fm.stringWidth(tempBuffer.toString()) < lw) && - (tempBuffer.toString() - .charAt(tempBuffer.toString().length() - 1) != '\n') && - (tempBuffer.toString() - .charAt(tempBuffer.toString().length() - 1) != '\r')) { - finalBuffer.append(tempString); - continue; - } - returnVector.addElement(finalBuffer.toString()); - finalBuffer.delete(0, finalBuffer.length()); - tempBuffer.delete(0, tempBuffer.length()); - if ((tempString.charAt(0) != '\n') && - (tempString.charAt(0) != '\r')) { - tempBuffer.append(tempString); - finalBuffer.append(tempString); - } - continue; - - } // end while - returnVector.addElement(finalBuffer.toString()); - - int len = returnVector.size(); - // Init the class member field stringArray - String[] childStrArray = new String[len]; - for (int i = 0; i < len; i++) { - String curStr = (String)returnVector.get(i); - childStrArray[i] = curStr; - } - - return childStrArray; - - } // end createStringArray - - - - /** - *

Removes the child box from this parent box. The child must - * have this object as its parent or the method does nothing. - * The BoundingBox returned will be cut by an area equal to - * the child area plus the horizontal or vertical strip in - * which it sits, depending on the 'subtractFrom' value passed - * in

- * - * @param child a BoundingBox value - * @param subtractFrom an int, SUBTRACT_FROM_LEFT, - SUBTRACT_FROM_RIGHT, SUBTRACT_FROM_TOP, - SUBTRACT_FROM_BOTTOM - * @return a BoundingBox value - * @see #SUBTRACT_FROM_LEFT - * @see #SUBTRACT_FROM_RIGHT - * @see #SUBTRACT_FROM_TOP - * @see #SUBTRACT_FROM_BOTTOM - */ - public BoundingBox subtract(BoundingBox child, int subtractFrom) { - // First, check to see if the params are valid - if (child == null) { - throw new IllegalArgumentException("BoundingBox.subtract, " - + "BoundingBox child is null"); - } - if (!child.hasParent()) { - throw new IllegalArgumentException("BoundingBox.subtract, " - + "BoundingBox child has no parent"); - } - if (!(child.getParent() == this)) { - throw new IllegalArgumentException("BoundingBox.subtract, " - + "this is not BoundingBox child's parent"); - } - // Now that we know the child is this object's child, we continue - // and check the subtractFrom param - int len = SUBTRACTS.length; - boolean valid = false; - for (int i = 0; i < len; i++) { - if (subtractFrom == SUBTRACTS[i]) { - valid = true; - } - } - if (!valid) { - throw new IllegalArgumentException("BoundingBox.subtract, " - + "subtractFrom invalid: " + subtractFrom); - } - - // Now we know the child is valid, and if the subtractFrom - // preference was invalid, we subtract from the bottom - - // The child should no longer be used, since the parent - // reference will be invalid - child.setParent(null); - - int cx = (int) child.getLocation().getX(); - int cy = (int) child.getLocation().getY(); - int cw = (int) child.getSize().getWidth(); - int ch = (int) child.getSize().getHeight(); - int px = (int) this.getLocation().getX(); - int py = (int) this.getLocation().getY(); - int pw = (int) this.getSize().getWidth(); - int ph = (int) this.getSize().getHeight(); - - switch (subtractFrom) { - case SUBTRACT_FROM_LEFT: - // This will be useful for right-justified Strings in tables - pw = cx; - this.setSize(new Dimension(pw, ph)); - return this; - - case SUBTRACT_FROM_RIGHT: - // This will be useful for left justified Strings in tables - px = px + cw + cx; - pw = pw - cw - cx; - this.setLocation(new Point(px, py)); - this.setSize(new Dimension(pw, ph)); - return this; - - case SUBTRACT_FROM_BOTTOM: - py = py + ch + cy; - ph = ph - ch - cy; - this.setLocation(new Point(px, py)); - this.setSize(new Dimension(pw, ph)); - return this; - - case SUBTRACT_FROM_TOP: - ph = cy; - this.setSize(new Dimension(pw, ph)); - return this; - - default: // Should never happen - break; - } // end switch - return this; - } // end subtract - - - - - /** - *

- * Gets the drawing point to use in Graphics drawing methods. After getting - * a new BoundingBox with getStringBounds(), calling this method will give - * you an absolute point, accounting for alignment and padding, etc, from - * which to start drawing the String - *

- * - *

- * If getStringBounds was not called (this is a parent box), the upper left - * coordinates will be returned (this.getLocation()) - *

- * - * @return a Point - */ - public Point getDrawingPoint() { - return drawingPoint; - } - - - - - private BoundingBox(Point p, - Dimension d, - Point drawingPoint, - Point absolute) { - super(p, d); - this.drawingPoint = drawingPoint; - this.absoluteLocation = absolute; - } - - - /** - *

Checks the horizontal alignment passed into a - * method to make sure it is one of the valid values

- * - * @param hAlign an int value - * @return a boolean value - */ - private boolean checkHAlign(int hAlign) { - int len = HORIZ_ALIGNS.length; - for (int i = 0; i < len; i++) { - if (hAlign == HORIZ_ALIGNS[i]) { - return true; - } - } - return false; - } - - - - /** - *

Checks the vertical alignment passed into a - * method to make sure it is one of the valid values

- * - * @param vAlign an int value - * @return a boolean value - */ - private boolean checkVAlign(int vAlign) { - int len = VERT_ALIGNS.length; - for (int i = 0; i < len; i++) { - if (vAlign == VERT_ALIGNS[i]) { - return true; - } - } - return false; - } - } // end class BoundingBox diff --git a/src/main/java/pdf/PDFDocument.java b/src/main/java/pdf/PDFDocument.java index c4d49141..286d29d6 100644 --- a/src/main/java/pdf/PDFDocument.java +++ b/src/main/java/pdf/PDFDocument.java @@ -26,6 +26,10 @@ import java.util.Vector; +/** + * Represents a PDF document with functionalities to manage PDF objects, + * pages, fonts, images, and document metadata. + */ public class PDFDocument implements Serializable { diff --git a/src/main/java/pdf/PDFXref.java b/src/main/java/pdf/PDFXref.java index 2b2d2913..1bb4cd3a 100644 --- a/src/main/java/pdf/PDFXref.java +++ b/src/main/java/pdf/PDFXref.java @@ -87,6 +87,7 @@ public PDFXref(int id,int offset,int generation) /** * @return The xref in the format of the xref section in the PDF file */ + @Override public String toString() { String of = Integer.toString(offset); diff --git a/src/main/java/pdf/StringTooLongException.java b/src/main/java/pdf/StringTooLongException.java index c125c37a..5dfa8ab6 100644 --- a/src/main/java/pdf/StringTooLongException.java +++ b/src/main/java/pdf/StringTooLongException.java @@ -43,10 +43,12 @@ public StringTooLongException(String msg) { this.msg = msg; } + @Override public String toString() { return msg; } + @Override public String getMessage() { return msg; } diff --git a/src/main/java/pdf/package-info.java b/src/main/java/pdf/package-info.java new file mode 100644 index 00000000..a13a1766 --- /dev/null +++ b/src/main/java/pdf/package-info.java @@ -0,0 +1,5 @@ +/** + * This package serves as the foundation for managing, processing, and generating PDF documents + * within the project. + */ +package pdf; \ No newline at end of file diff --git a/src/main/java/wprover/AboutDialog.java b/src/main/java/wprover/AboutDialog.java index cc85c2cc..c0104e87 100644 --- a/src/main/java/wprover/AboutDialog.java +++ b/src/main/java/wprover/AboutDialog.java @@ -9,16 +9,12 @@ import java.awt.*; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; - /** - * Created by IntelliJ IDEA. - * User: yezheng - * Date: 2006-8-19 - * Time: 11:35:20 - * To change this template use File | Settings | File Templates. + * The `AboutDialog` class represents a custom popup dialog that displays information about the application. + * It extends `JPopupMenu` and implements `MouseListener` to handle mouse events. + * The dialog includes labels, panels, and a text pane with information about the application and its authors. */ public class AboutDialog extends JPopupMenu implements MouseListener { - JLabel b2; Color color = new Color(206, 223, 242); GExpert gx; diff --git a/src/main/java/wprover/AllSolutionDialog.java b/src/main/java/wprover/AllSolutionDialog.java index 5500cf3b..8a1d9ee6 100644 --- a/src/main/java/wprover/AllSolutionDialog.java +++ b/src/main/java/wprover/AllSolutionDialog.java @@ -10,15 +10,6 @@ import java.awt.event.WindowEvent; import java.awt.event.WindowListener; import java.util.Vector; - -/** - * Created by IntelliJ IDEA. - * User: ye - * Date: 2008-8-3 - * Time: 18:30:46 - * To change this template use File | Settings | File Templates. - */ - /** * The `AllSolutionDialog` class provides a dialog for displaying and interacting with * all possible solutions of a given problem within the GExpert application. @@ -297,27 +288,60 @@ public void setVisible(boolean b) { gxInstance.d.repaint(); } + /** + * Invoked when a window has been opened. + * + * @param e the event to be processed + */ public void windowOpened(WindowEvent e) { } + /** + * Invoked when the user attempts to close the window from the window's system menu. + * + * @param e the event to be processed + */ public void windowClosing(WindowEvent e) { } + /** + * Invoked when a window has been closed. + * + * @param e the event to be processed + */ public void windowClosed(WindowEvent e) { } + /** + * Invoked when a window is changed from a normal to a minimized state. + * + * @param e the event to be processed + */ public void windowIconified(WindowEvent e) { } + /** + * Invoked when a window is changed from a minimized to a normal state. + * + * @param e the event to be processed + */ public void windowDeiconified(WindowEvent e) { } + /** + * Invoked when a window is activated. + * + * @param e the event to be processed + */ public void windowActivated(WindowEvent e) { } + /** + * Invoked when a window is deactivated. + * + * @param e the event to be processed + */ public void windowDeactivated(WindowEvent e) { } -} - - +} \ No newline at end of file diff --git a/src/main/java/wprover/AnimateC.java b/src/main/java/wprover/AnimateC.java index 7d400561..0aaeed68 100644 --- a/src/main/java/wprover/AnimateC.java +++ b/src/main/java/wprover/AnimateC.java @@ -3,15 +3,6 @@ import java.io.DataOutputStream; import java.io.IOException; import java.io.DataInputStream; - -/** - * Created by IntelliJ IDEA. - * User: Administrator - * Date: 2005-1-14 - * Time: 13:37:42 - * To change this template use File | Settings | File Templates. - */ - /** * The `AnimateC` class represents the animation control for a geometric object in the GExpert application. * It provides methods to animate a point along a line, circle, or trace path. @@ -255,12 +246,6 @@ public int getInitValue() { return (int) gap; } - public void valueChanged(int v) { - if (onType == 1 || onType == 2) { - gap = v + delta; - } - } - AnimateC(CPoint p, Object obj, double width, double height) { pA = p; onObj = obj; @@ -432,12 +417,6 @@ public boolean onTimer() { return r; } - public void onFailed() { - if (onType == 2) { - sia = -sia; - } - } - /** * Saves the current state of the animation to an output stream. * diff --git a/src/main/java/wprover/AnimatePanel.java b/src/main/java/wprover/AnimatePanel.java index be6d8594..36f49094 100644 --- a/src/main/java/wprover/AnimatePanel.java +++ b/src/main/java/wprover/AnimatePanel.java @@ -292,14 +292,6 @@ public void setStatus() { } } - /** - * Handles window opened events (empty implementation). - * - * @param e the window event - */ - public void windowOpened(WindowEvent e) { - } - /** * Sets the visibility of this panel. * diff --git a/src/main/java/wprover/AttrToCondDialog.java b/src/main/java/wprover/AttrToCondDialog.java index 551d19cd..22e7e125 100644 --- a/src/main/java/wprover/AttrToCondDialog.java +++ b/src/main/java/wprover/AttrToCondDialog.java @@ -10,11 +10,9 @@ import java.awt.*; /** - * Created by IntelliJ IDEA. - * User: ye - * Date: Nov 26, 2006 - * Time: 5:52:40 PM - * To change this template use File | Settings | File Templates. + * AttrToCondDialog is a dialog class that allows users to select geometric attributes + * and convert them into conditions for geometric proofs. + * It provides a graphical interface for selecting points, lines, angles, and triangles. */ public class AttrToCondDialog extends JBaseDialog { final private static int ROW = 5; @@ -149,6 +147,11 @@ public Dimension getPreferredSize() { addComp(); } + /** + * Constructor for creating an AttrToCondDialog for parallel lines. + * @param gx GExpert instance + * @param pn PLine instance + */ public AttrToCondDialog(GExpert gx, PLine pn) { this(gx, "Please select two lines"); @@ -162,6 +165,9 @@ public Dimension getPreferredSize() { addComp(); } + /** + * Adds components to the content pane and sets the dialog properties. + */ public void addComp() { Window gx = this.getOwner(); contentPane.add(topPane); diff --git a/src/main/java/wprover/CAngle.java b/src/main/java/wprover/CAngle.java index e01d7e58..92fa6ed6 100644 --- a/src/main/java/wprover/CAngle.java +++ b/src/main/java/wprover/CAngle.java @@ -8,14 +8,6 @@ import gprover.Cm; -/** - * Created by IntelliJ IDEA. - * User: Administrator - * Date: 2005-1-15 - * Time: 11:22:15 - * To change this template use File | Settings | File Templates. - */ - /** * Class representing an angle in a geometric construction. */ @@ -121,19 +113,6 @@ public boolean isSame(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { return false; } - /** - * Checks if two sets of points are the same. - * - * @param p1 The first point of the first set. - * @param p2 The second point of the first set. - * @param p3 The first point of the second set. - * @param p4 The second point of the second set. - * @return {@code true} if the two sets of points are the same, {@code false} otherwise. - */ - public boolean isSame_m(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { - return false; - } - /** * Constructs a CAngle object with specified lines and points. @@ -311,16 +290,6 @@ public int getRadius() { return radius; } - /** - * Sets the name of the angle. - * - * @param s the name of the angle - */ - public void setAngleName(String s) { - if (ptext != null) - ptext.setText(s); - } - /** * Gets the text associated with the angle. * @@ -358,15 +327,6 @@ public String TypeString() { return m_name; } - /** - * Gets the common intersection point of the two lines forming the angle. - * - * @return the intersection point - */ - public CPoint CrossPoint() { - return CLine.commonPoint(this.lstart, this.lend); - } - /** * Gets the description of the angle. @@ -391,19 +351,6 @@ public CPoint getVertex() { return CLine.commonPoint(this.lstart, this.lend); } - /** - * Gets the common line between two angles if they share a common line. - * - * @param g1 the first angle - * @param g2 the second angle - * @return the common line, or null if there is none - */ - public static CLine getCrossLine(CAngle g1, CAngle g2) { - if (g1.lstart == g2.lstart || g1.lstart == g2.lend) return g1.lstart; - if (g1.lend == g2.lstart || g1.lend == g2.lend) return g1.lend; - return null; - } - /** * Checks if two angles can be considered equal based on their common points and lines. * diff --git a/src/main/java/wprover/CArrow.java b/src/main/java/wprover/CArrow.java index 5e780741..f989eedb 100644 --- a/src/main/java/wprover/CArrow.java +++ b/src/main/java/wprover/CArrow.java @@ -7,11 +7,8 @@ import java.io.DataInputStream; /** - * Created by IntelliJ IDEA. - * User: Administrator - * Date: 2009-12-13 - * Time: 13:43:52 - * To change this template use File | Settings | File Templates. + * Represents an arrow in a geometric drawing. + * The arrow is defined by its starting and ending points, angle, and length. */ public class CArrow extends CClass { public static int ANGLE = 30; diff --git a/src/main/java/wprover/CBoolean.java b/src/main/java/wprover/CBoolean.java index 2ad788d9..b5d46bd3 100644 --- a/src/main/java/wprover/CBoolean.java +++ b/src/main/java/wprover/CBoolean.java @@ -1,11 +1,8 @@ package wprover; /** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2005-9-20 - * Time: 11:16:25 - * To change this template use File | Settings | File Templates. + * Represents a boolean value that can be modified. + * This class is used to encapsulate a boolean value and provide methods to get and set its value. */ public class CBoolean { diff --git a/src/main/java/wprover/CClass.java b/src/main/java/wprover/CClass.java index cbda76b2..b158150c 100644 --- a/src/main/java/wprover/CClass.java +++ b/src/main/java/wprover/CClass.java @@ -7,14 +7,9 @@ import java.io.FileOutputStream; /** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2005-7-8 - * Time: 16:00:08 - * To change this template use File | Settings | File Templates. - * This class serves as the base class for all geometry items. + * CClass is an abstract class representing a geometric object with various properties and methods. + * It serves as a base class for different types of geometric objects. */ -// class as the baseclass for all the geometry item. abstract public class CClass { @@ -317,19 +312,6 @@ void setDrawSelect(Graphics2D g2) { g2.setColor(c); } - /** - * Sets the drawing style for a selected geometry item with a specified width. - * - * @param g2 the Graphics2D object - * @param w the width - */ - void setDrawSelect(Graphics2D g2, int w) { -// float w = (float) drawData.getWidth(m_width); - g2.setStroke(new BasicStroke(w + 5)); - Color c = CMisc.SelectObjectColor; - g2.setColor(c); - } - /** * Sets the drawing style for the geometry item. * @@ -358,63 +340,6 @@ void setDraw(Graphics2D g2) { g2.setPaint(c); } - /** - * Writes a string to the data output stream. - * - * @param out the data output stream - * @param s the string to write - * @throws IOException if an I/O error occurs - */ - public static void WriteString(DataOutputStream out, String s) throws IOException { - out.writeInt(s.length()); - out.writeChars(s); - } - - /** - * Writes the font to the data output stream. - * - * @param out the data output stream - * @param f the font to write - * @throws IOException if an I/O error occurs - */ - public void WriteFont(DataOutputStream out, Font f) throws IOException { - String s = f.getName(); - WriteString(out, s); - out.writeInt(f.getStyle()); - out.writeInt(f.getSize()); - } - - /** - * Reads a string from the data input stream. - * - * @param in the data input stream - * @return the string read from the input stream - * @throws IOException if an I/O error occurs - */ - public static String ReadString(DataInputStream in) throws IOException { - int size = in.readInt(); - if (size == 0) return new String(""); - String s = new String(); - for (int i = 0; i < size; i++) - s += in.readChar(); - return s; - } - - /** - * Reads a font from the data input stream. - * - * @param in the data input stream - * @return the font read from the input stream - * @throws IOException if an I/O error occurs - */ - public Font ReadFont(DataInputStream in) throws IOException { - String name = ReadString(in); - int stye = in.readInt(); - int size = in.readInt(); - - return new Font(name, stye, size); - } - /** * Saves the geometry item to a PostScript file. * diff --git a/src/main/java/wprover/CCoBox.java b/src/main/java/wprover/CCoBox.java index 9d569af2..acd84f2d 100644 --- a/src/main/java/wprover/CCoBox.java +++ b/src/main/java/wprover/CCoBox.java @@ -5,12 +5,8 @@ import java.awt.*; /** - * Created by IntelliJ IDEA. - * User: Administrator - * Date: 2005-3-4 - * Time: 14:25:06 - * To change this template use File | Settings | File Templates. - * This class represents a custom JComboBox for color selection. + * CCoBox is a custom JComboBox that displays color options. + * It allows for the creation of multiple instances and provides methods to manage them. */ public class CCoBox extends JComboBox { private static Vector instanceList = new Vector(); @@ -56,15 +52,6 @@ public void setSelectedIndex(int index) { super.setSelectedIndex(index); } - /** - * Sets the default selected index of the combo box. - * - * @param index the default index - */ - public void setDefaultIndex(int index) { - defaultindex = index; - } - /** * Regenerates all instances of CCoBox. */ diff --git a/src/main/java/wprover/CDialogProve.java b/src/main/java/wprover/CDialogProve.java index f27b5203..9394fecc 100644 --- a/src/main/java/wprover/CDialogProve.java +++ b/src/main/java/wprover/CDialogProve.java @@ -12,13 +12,7 @@ import java.io.File; /** - * Created by IntelliJ IDEA. - * User: Administrator - * Date: 2005-3-4 - * Time: 14:25:06 - * To change this template use File | Settings | File Templates. - * - * This class represents a dialog for proving geometric statements. + * This class represents a dialog for proving geometric terms. */ public class CDialogProve extends JBaseDialog { ProvePane m_cp; @@ -35,16 +29,6 @@ public CDialogProve(GExpert owner) { this.setSize(650, 230); } - /** - * Shows the dialog with the given CProveText. - * - * @param cp the CProveText to display in the dialog - */ - void showDialog(CProveText cp) { - m_cp.setValue(cp); - this.setVisible(true); - } - /** * Sets the selected items in the dialog. * @@ -53,15 +37,6 @@ void showDialog(CProveText cp) { public void setSelect(Vector v) { m_cp.setSelect(v); } - - /** - * Sets the CProveField in the dialog. - * - * @param cpv the CProveField to set - */ - public void setProveField(CProveField cpv) { - m_cp.setProveField(cpv); - } } /** @@ -120,15 +95,6 @@ public Dimension getMaximumSize() { add(createAddressDisplay()); } - /** - * Sets the CProveField for this panel. - * - * @param cpv the CProveField to set - */ - public void setProveField(CProveField cpv) { - Cpv = cpv; - } - /** * Sets the rule list for this panel. */ diff --git a/src/main/java/wprover/CDistance.java b/src/main/java/wprover/CDistance.java index 879589df..624daa17 100644 --- a/src/main/java/wprover/CDistance.java +++ b/src/main/java/wprover/CDistance.java @@ -7,13 +7,8 @@ import java.io.FileOutputStream; /** - * Created by IntelliJ IDEA. - * User: Administrator - * Date: 2005-1-19 - * Time: 10:16:32 - * To change this template use File | Settings | File Templates. - * - * This class represents a geometric distance between two points. + * Represents a distance measurement between two points in a geometric context. + * This class extends CClass and provides methods for drawing, saving, and loading distance measurements. */ public class CDistance extends CClass { diff --git a/src/main/java/wprover/CLine.java b/src/main/java/wprover/CLine.java index 420c07a2..d056dda8 100644 --- a/src/main/java/wprover/CLine.java +++ b/src/main/java/wprover/CLine.java @@ -9,11 +9,7 @@ import java.io.FileOutputStream; /** - * Created by IntelliJ IDEA. - * User: ${Yezheng} - * Date: 2004-12-9 - * Time: 12:25:19 - * To change this template use File | Settings | File Templates. + * Represents a geometric line with various properties and methods. */ public class CLine extends CClass { final public static int LLine = 0; @@ -45,6 +41,12 @@ public class CLine extends CClass { final static int Height = 2000; // should be modified here. +/** + * Draws the line on the given graphics context. + * + * @param g2 the graphics context + * @param selected whether the line is selected + */ public void draw(Graphics2D g2, boolean selected) { if (!isdraw()) return; @@ -84,17 +86,30 @@ public void draw(Graphics2D g2, boolean selected) { } } + /** + * Draws the line on the given graphics context. + * + * @param g2 the graphics context + */ public void draw(Graphics2D g2) { draw(g2, false); } + /** + * Returns the type of the line as a string. + * + * @return the type of the line + */ public String TypeString() { if (m_name == null) return GExpert.getLanguage("Line"); - // String st = Language.getLs(40, "line"); - // if (m_name == null) return st; return GExpert.getTranslationViaGettext("Line {0}", m_name); } + /** + * Returns the simple name of the line. + * + * @return the simple name of the line + */ public String getSimpleName() { CPoint pl[] = this.getTowSideOfLine(); @@ -112,22 +127,40 @@ public String getSimpleName() { return s; } + /** + * Returns the description of the line. + * + * @return the description of the line + */ public String getDescription() { String s = this.getSimpleName(); - // String st = Language.getLs(40, "line "); return GExpert.getTranslationViaGettext("Line {0}", s); - // return st + s; } + /** + * Sets the extent of the line. + * + * @param n the extent to set + */ public void setExtent(int n) { extent = n; } + /** + * Returns the extent of the line. + * + * @return the extent of the line + */ public int getExtent() { return extent; } - /////////////////////////////////////////////////////////////////////////////// + /** + * Draws an ALine. + * + * @param line the line to draw + * @param g2 the graphics context + */ public static void drawALine(CLine line, Graphics2D g2) { if (line.points.size() >= 2) { drawLLine(line, g2); @@ -138,6 +171,12 @@ public static void drawALine(CLine line, Graphics2D g2) { drawXLine(pt.getx(), pt.gety(), k, g2); } + /** + * Draws an ABLine. + * + * @param line the line to draw + * @param g2 the graphics context + */ public static void drawABLine(CLine line, Graphics2D g2) { if (line.points.size() >= 2) { drawLLine(line, g2); @@ -148,6 +187,12 @@ public static void drawABLine(CLine line, Graphics2D g2) { drawXLine(pt.getx(), pt.gety(), k, g2); } + /** + * Draws a TCLine. + * + * @param line the line to draw + * @param g2 the graphics context + */ public static void drawTCLine(CLine line, Graphics2D g2) { if (line.points.size() >= 2) { drawLLine(line, g2); @@ -158,6 +203,12 @@ public static void drawTCLine(CLine line, Graphics2D g2) { drawXLine(pt.getx(), pt.gety(), k, g2); } + /** + * Draws a BLine. + * + * @param line the line to draw + * @param g2 the graphics context + */ public static void drawBLine(CLine line, Graphics2D g2) { if (line.points.size() >= 2) { drawLLine(line, g2); @@ -173,6 +224,12 @@ public static void drawBLine(CLine line, Graphics2D g2) { drawXLine(x, y, k, g2); } + /** + * Draws a CCLine. + * + * @param line the line to draw + * @param g2 the graphics context + */ public static void drawCCLine(CLine line, Graphics2D g2) { if (line.points.size() >= 2) { drawLLine(line, g2); @@ -217,6 +274,12 @@ public static void drawCCLine(CLine line, Graphics2D g2) { g2.drawLine((int) xa, (int) ya, (int) xb, (int) yb); } + /** + * Draws an SLine. + * + * @param line the line to draw + * @param g2 the graphics context + */ public static void drawSLine(CLine line, Graphics2D g2) { if (line.points.size() >= 2) { drawLLine(line, g2); @@ -233,6 +296,14 @@ public static void drawSLine(CLine line, Graphics2D g2) { } + /** + * Draws a line given a point and a slope. + * + * @param x0 the x-coordinate of the point + * @param y0 the y-coordinate of the point + * @param k the slope of the line + * @param g2 the graphics context + */ public static void drawXLine(double x0, double y0, double k, Graphics2D g2) { if (Math.abs(1 / k) < CMisc.ZERO) { double x = x0; @@ -250,6 +321,12 @@ public static void drawXLine(double x0, double y0, double k, Graphics2D g2) { } } + /** + * Draws a TLine. + * + * @param line the line to draw + * @param g2 the graphics context + */ public static void drawTLine(CLine line, Graphics2D g2) { if (line.points.size() >= 2) { drawLLine(line, g2); @@ -263,6 +340,12 @@ public static void drawTLine(CLine line, Graphics2D g2) { drawXLine(p.getx(), p.gety(), -1 / k, g2); } + /** + * Draws a PLine. + * + * @param line the line to draw + * @param g2 the graphics context + */ public static void drawPLine(CLine line, Graphics2D g2) { if (line.points.size() >= 2) { drawLLine(line, g2); @@ -278,6 +361,12 @@ public static void drawPLine(CLine line, Graphics2D g2) { drawXLine(p.getx(), p.gety(), l.getK(), g2); } + /** + * Draws an LLine. + * + * @param line the line to draw + * @param g2 the graphics context + */ public static void drawLLine(CLine line, Graphics2D g2) { CPoint[] pl = line.getMaxMinPoint(); @@ -305,8 +394,13 @@ public static void drawLLine(CLine line, Graphics2D g2) { } } - /// ///////////////////////////////////// - + /** + * Draws a parallel line to the given line through the specified point. + * + * @param line the line to which the parallel line is drawn + * @param pt the point through which the parallel line passes + * @param g2 the graphics context + */ public static void drawPParaLine(CLine line, CPoint pt, Graphics2D g2) { if (line.isVertical()) { double x = pt.getx(); @@ -324,6 +418,13 @@ public static void drawPParaLine(CLine line, CPoint pt, Graphics2D g2) { } } + /** + * Draws a perpendicular line to the given line through the specified point. + * + * @param line the line to which the perpendicular line is drawn + * @param pt the point through which the perpendicular line passes + * @param g2 the graphics context + */ public static void drawTPerpLine(CLine line, CPoint pt, Graphics2D g2) { if (line.isHorizonal()) { double x = pt.getx(); @@ -344,6 +445,11 @@ public static void drawTPerpLine(CLine line, CPoint pt, Graphics2D g2) { } ///////////////////////////////////////////// + /** + * Returns the names of all points on the line. + * + * @return a string containing the names of all points on the line + */ public String getAllPointName() { String s = new String(); for (int i = 0; i < points.size(); i++) { @@ -356,6 +462,12 @@ public String getAllPointName() { return s; } + /** + * Returns the second point on the line that is not the given point. + * + * @param t the point to exclude + * @return the second point on the line, or null if there is no such point + */ public CPoint getSecondPoint(CPoint t) { CPoint p = null; @@ -369,6 +481,11 @@ else if (p != null && p.x1.xindex > pt.x1.xindex && pt != t) return p; } + /** + * Returns the first point on the line. + * + * @return the first point on the line, or null if there is no such point + */ public CPoint getfirstPoint() { CPoint p = null; @@ -383,6 +500,12 @@ else if (p.x1.xindex > pt.x1.xindex) } + /** + * Returns a point on the line that is not the given point. + * + * @param t the point to exclude + * @return a point on the line that is not the given point, or null if there is no such point + */ public CPoint getAPointBut(CPoint t) { for (int i = 0; i < points.size(); i++) { CPoint pt = (CPoint) points.get(i); @@ -391,6 +514,11 @@ public CPoint getAPointBut(CPoint t) { return null; } + /** + * Returns the point on the line with the maximum x-coordinate. + * + * @return the point on the line with the maximum x-coordinate, or null if there is no such point + */ public CPoint getMaxXPoint() { CPoint p = null; @@ -404,6 +532,11 @@ else if (p.getx() < pt.getx()) return p; } + /** + * Checks if the line has two free points at its ends. + * + * @return true if the line has two free points at its ends, false otherwise + */ public boolean isTwoEndFreePoints() { CPoint p1, p2; p1 = p2 = null; @@ -423,48 +556,12 @@ else if (p.x1.xindex < p1.x1.xindex) { return p1.isAFreePoint() && p2.isAFreePoint(); } - public boolean isParallel(CLine line) { - if (type != PLine) - return false; - for (int i = 0; i < cons.size(); i++) { - Constraint cs = (Constraint) cons.get(i); - if (cs.GetConstraintType() != Constraint.PARALLEL) - continue; - CLine line1 = (CLine) cs.getelement(0); - CLine line2 = (CLine) cs.getelement(1); - if (line2 == this) { - CLine l = line1; - line1 = line2; - line2 = l; - } - if (line2 == line) - return true; - if (line2.type == CLine.PLine) - return line2.isParallel(line); - } - return false; - } - - public boolean isVertical(CLine line) { - for (int i = 0; i < cons.size(); i++) { - Constraint cs = (Constraint) cons.get(i); - if (cs.GetConstraintType() != Constraint.PERPENDICULAR) - continue; - CLine line1 = (CLine) cs.getelement(0); - CLine line2 = (CLine) cs.getelement(1); - if (line2 == this) { - CLine l = line1; - line1 = line2; - line2 = l; - } - if (line2 == line && line1 == this) - return true; - return false; - } - - return false; - } - + /** + * Returns the point on the line with the smallest x-index that is not the given point. + * + * @param px the point to exclude + * @return the point on the line with the smallest x-index that is not the given point, or null if there is no such point + */ public CPoint get_Lpt1(CPoint px) { if (px == null) return null; CPoint p1 = null; @@ -478,6 +575,14 @@ else if (p != px && p.x1.xindex < p1.x1.xindex) return p1; } + /** + * Returns the point on the line that forms a vector with the given point and coordinates. + * + * @param px the point to exclude + * @param x the x-coordinate of the vector + * @param y the y-coordinate of the vector + * @return the point on the line that forms a vector with the given point and coordinates, or null if there is no such point + */ public CPoint get_Lptv(CPoint px, double x, double y) { // Vector (x,y),px == (x,y),p if (px == null) return null; CPoint p1 = null; @@ -494,6 +599,11 @@ else if (p != px && p.x1.xindex < p1.x1.xindex) return p1; } + /** + * Returns the two points on the line with the smallest and largest x-index. + * + * @return an array containing the two points on the line with the smallest and largest x-index, or null if there are not enough points + */ public CPoint[] getTowSideOfLine() { CPoint p1, p2; p1 = p2 = null; @@ -516,17 +626,32 @@ else if (p.x1.xindex < p1.x1.xindex) { return pl; } + /** + * Returns the description of the line. + * + * @return the description of the line + */ public String getDiscription() { CPoint[] s = this.getTowSideOfLine(); if (s == null) return m_name; return s[0].m_name + s[1].m_name; } - + /** + * Returns the maximum and minimum points of the line. + * + * @return an array containing the maximum and minimum points, or null if there are less than 2 points + */ public CPoint[] getMaxMinPoint() { return getMaxMinPoint(true); } + /** + * Returns the maximum and minimum points of the line, optionally considering visibility. + * + * @param ckv whether to consider visibility of points + * @return an array containing the maximum and minimum points, or null if there are less than 2 points + */ public CPoint[] getMaxMinPoint(boolean ckv) { if (points.size() < 2) return null; @@ -576,12 +701,24 @@ public CPoint[] getMaxMinPoint(boolean ckv) { return pl; } + /** + * Returns the constraint at the specified index. + * + * @param i the index of the constraint + * @return the constraint at the specified index, or null if the index is out of bounds + */ public Constraint getcons(int i) { if (i >= 0 && i < cons.size()) return (Constraint) cons.get(i); return null; } + /** + * Returns the first constraint of the specified type. + * + * @param t the type of the constraint + * @return the first constraint of the specified type, or null if no such constraint exists + */ public Constraint getconsByType(int t) { for (int i = 0; i < cons.size(); i++) { Constraint c = (Constraint) cons.get(i); @@ -590,28 +727,52 @@ public Constraint getconsByType(int t) { return null; } + /** + * Checks if the line contains the specified points. + * + * @param p1 the first point + * @param p2 the second point + * @return true if the line contains both points, false otherwise + */ public boolean containPTs(CPoint p1, CPoint p2) { return points.contains(p1) && points.contains(p2); } + /** + * Checks if the line contains the specified point. + * + * @param p the point + * @return true if the line contains the point, false otherwise + */ public boolean containPT(CPoint p) { return points.contains(p); } - public int getconsSize() { - return cons.size(); - } - + /** + * Returns the number of points in the line. + * + * @return the number of points in the line + */ public int getPtsSize() { return points.size(); } + /** + * Returns the point at the specified index. + * + * @param n the index of the point + * @return the point at the specified index, or null if the index is out of bounds + */ public CPoint getPoint(int n) { if (n < 0 || n >= points.size()) return null; return (CPoint) points.get(n); } - + /** + * Checks if the line is vertical. + * + * @return true if the line is vertical, false otherwise + */ public boolean isVertical() { if (points.size() >= 2) { CPoint p1 = (CPoint) points.get(0); @@ -651,6 +812,11 @@ public boolean isVertical() { } + /** + * Checks if the line is horizontal. + * + * @return true if the line is horizontal, false otherwise + */ public boolean isHorizonal() { if (this.type == CLine.LLine) { CPoint p1 = (CPoint) points.get(0); @@ -682,6 +848,11 @@ public boolean isHorizonal() { return false; } + /** + * Calculates the slope (k) of the line. + * + * @return the slope of the line + */ public double getK() { if (points.size() >= 2) { CPoint p1 = (CPoint) points.get(0); @@ -800,6 +971,14 @@ else if (k2 < -CMisc.MAX_SLOPE) return 0.0; } + /** + * Calculates the slope (k) for a line defined by three other lines. + * + * @param ln1 the first line + * @param ln2 the second line + * @param ln3 the third line + * @return the calculated slope + */ public static double getALineK(CLine ln1, CLine ln2, CLine ln3) { CPoint lp1[] = ln1.getTowSideOfLine(); CPoint lp2[] = ln2.getTowSideOfLine(); @@ -807,6 +986,17 @@ public static double getALineK(CLine ln1, CLine ln2, CLine ln3) { return getALineK(lp1[0], lp1[1], lp2[0], lp2[1], lp3[0], lp3[1]); } + /** + * Calculates the slope (k) for a line defined by six points. + * + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @param p4 the fourth point + * @param p5 the fifth point + * @param p6 the sixth point + * @return the calculated slope + */ public static double getALineK(CPoint p1, CPoint p2, CPoint p3, CPoint p4, CPoint p5, CPoint p6) { double x1 = p1.getx(); double y1 = p1.gety(); @@ -825,6 +1015,11 @@ public static double getALineK(CPoint p1, CPoint p2, CPoint p3, CPoint p4, CPoin return t1 / t2; } + /** + * Adds a point to the line. + * + * @param a the point to add + */ public void addApoint(CPoint a) { if (a == null) return; for (int i = 0; i < points.size(); i++) @@ -833,25 +1028,33 @@ public void addApoint(CPoint a) { points.add(a); } + /** + * Adds a constraint to the line. + * + * @param cs the constraint to add + */ public void addconstraint(Constraint cs) { if (cs == null) return; if (!cons.contains(cs)) cons.add(cs); } - public void clearpoints() { - points.clear(); - } - - public void setColorType(String c) { - String str = new String(c); - } - + /** + * Constructs a CLine with a specified type. + * + * @param type the type of the line + */ public CLine(int type) { super(CClass.LINE); this.type = type; } + /** + * Constructs a CLine with a specified point and type. + * + * @param A the point + * @param type the type of the line + */ public CLine(CPoint A, int type) { super(CClass.LINE); @@ -859,6 +1062,13 @@ public CLine(CPoint A, int type) { this.type = type; } + /** + * Constructs a CLine with two points and a specified type. + * + * @param A the first point + * @param B the second point + * @param Type the type of the line + */ public CLine(CPoint A, CPoint B, int Type) { super(CClass.LINE); this.addApoint(A); @@ -866,12 +1076,25 @@ public CLine(CPoint A, CPoint B, int Type) { type = Type; } + /** + * Constructs a CLine with two points. + * + * @param A the first point + * @param B the second point + */ public CLine(CPoint A, CPoint B) { super(CClass.LINE); this.addApoint(A); this.addApoint(B); } + /** + * Constructs a CLine with two points and a specified color. + * + * @param A the first point + * @param B the second point + * @param color the color of the line + */ public CLine(CPoint A, CPoint B, String color) { super(CClass.LINE); // this.color = color; @@ -879,6 +1102,13 @@ public CLine(CPoint A, CPoint B, String color) { this.addApoint(B); } + /** + * Constructs a CLine with a name and two points. + * + * @param name the name of the line + * @param A the first point + * @param B the second point + */ public CLine(String name, CPoint A, CPoint B) { super(CClass.LINE); this.m_name=name; @@ -886,7 +1116,13 @@ public CLine(String name, CPoint A, CPoint B) { this.addApoint(B); } - + /** + * Checks if two points are on the same line. + * + * @param A the first point + * @param B the second point + * @return true if both points are on the same line, false otherwise + */ public boolean sameLine(CPoint A, CPoint B) { CPoint p = new CPoint(); int counter = 0; @@ -903,18 +1139,23 @@ public boolean sameLine(CPoint A, CPoint B) { } } + /** + * Checks if a point is on the line. + * + * @param p the point to check + * @return true if the point is on the line, false otherwise + */ public boolean pointOnLine(CPoint p) { return points.contains(p); } - public boolean pointOnLineN(CPoint p) { - return this.distance(p.getx(), p.gety()) < CMisc.ZERO; - } - - public boolean pointOnLine(double x, double y) { - return this.distance(x, y) < CMisc.ZERO; - } - + /** + * Checks if two points are equal. + * + * @param A the first point + * @param B the second point + * @return true if both points are equal, false otherwise + */ public boolean isEqual(CPoint A, CPoint B) { if (A.x1.xindex == B.x1.xindex && A.y1.xindex == B.y1.xindex) return true; @@ -922,17 +1163,17 @@ public boolean isEqual(CPoint A, CPoint B) { return false; } - public CPoint getSideMostPoint(CPoint p, int x, int y) { - CPoint pp = null; - for (int i = 0; i < points.size(); i++) { - CPoint tp = (CPoint) points.get(i); - if ((x - tp.getx()) * (p.getx() - tp.getx()) > 0 || (y - tp.gety()) * (p.gety() - tp.gety()) > 0 - && (pp == null || pp.x1.xindex > tp.x1.xindex)) - pp = tp; - } - return pp; - } - + /** + * Checks if the mouse is on the line. + * + * @param x the x-coordinate of the mouse + * @param y the y-coordinate of the mouse + * @param x1 the x-coordinate of the first point of the line + * @param y1 the y-coordinate of the first point of the line + * @param x2 the x-coordinate of the second point of the line + * @param y2 the y-coordinate of the second point of the line + * @return true if the mouse is on the line, false otherwise + */ public static boolean mouse_on_line(double x, double y, double x1, double y1, double x2, double y2) { double k = -(y2 - y1) / (x2 - x1); @@ -943,6 +1184,14 @@ public static boolean mouse_on_line(double x, double y, double x1, double y1, do return len < CMisc.PIXEPS; } + /** + * Calculates the distance from a point to a line. + * + * @param ln the line + * @param x the x-coordinate of the point + * @param y the y-coordinate of the point + * @return the distance from the point to the line + */ public static double distanceToPoint(CLine ln, double x, double y) { int n = ln.getPtsSize(); @@ -999,12 +1248,16 @@ public static double distanceToPoint(CLine ln, double x, double y) { } - - public static double distanceToPoint(CPoint p, CPoint p1, CPoint p2) { - return distanceToPoint(p.getx(), p.gety(), (p1.getx() - p2.getx()) / (p1.gety() - p2.gety()), p1.getx(), p1.gety()); - - } - + /** + * Calculates the distance from a point to a line given the slope. + * + * @param x1 the x-coordinate of the first point of the line + * @param y1 the y-coordinate of the first point of the line + * @param k the slope of the line + * @param x the x-coordinate of the point + * @param y the y-coordinate of the point + * @return the distance from the point to the line + */ public static double distanceToPoint(double x1, double y1, double k, double x, double y) { k = -k; @@ -1016,6 +1269,13 @@ public static double distanceToPoint(double x1, double y1, double k, double x, d } + /** + * Checks if a point is inside the line segment. + * + * @param x the x-coordinate of the point + * @param y the y-coordinate of the point + * @return true if the point is inside the line segment, false otherwise + */ public boolean inside(double x, double y) { if (this.ext_type == ET_ENDLESS) return true; @@ -1060,6 +1320,14 @@ public boolean inside(double x, double y) { return (e1 <= 0 && e2 <= 0); } + /** + * Checks if a point is inside the line segment within a given tolerance. + * + * @param x the x-coordinate of the point + * @param y the y-coordinate of the point + * @param eps the tolerance + * @return true if the point is inside the line segment within the tolerance, false otherwise + */ public boolean inside(double x, double y, double eps) { if (this.ext_type == ET_ENDLESS) return true; @@ -1105,10 +1373,24 @@ public boolean inside(double x, double y, double eps) { return (e1 <= 0 && e2 <= 0); } + /** + * Checks if a point is near the line. + * + * @param x the x-coordinate of the point + * @param y the y-coordinate of the point + * @return true if the point is near the line, false otherwise + */ public boolean nearline(double x, double y) { // is the point near the line return distanceToPoint(this, x, y) < CMisc.PIXEPS; } + /** + * Selects the line if a point is near it. + * + * @param x the x-coordinate of the point + * @param y the y-coordinate of the point + * @return true if the line is selected, false otherwise + */ public boolean select(double x, double y) { if (!visible) return false; @@ -1120,25 +1402,23 @@ public boolean select(double x, double y) { return false; } + /** + * Calculates the distance from a point to this line. + * + * @param x the x-coordinate of the point + * @param y the y-coordinate of the point + * @return the distance from the point to this line + */ public double distance(double x, double y) { return distanceToPoint(this, x, y); } - public boolean isOnMiddle(double x, double y) { - if (points.size() != 2) - return false; - CPoint p1 = (CPoint) points.get(0); - CPoint p2 = (CPoint) points.get(1); - - double dx = (p1.getx() + p2.getx()) / 2; - double dy = (p1.gety() + p2.gety()) / 2; - if (Math.abs(p1.getx() - p2.getx()) < CMisc.PIXEPS && - Math.abs(p1.gety() - p2.gety()) < CMisc.PIXEPS) - return false; - - return Math.abs(x - dx) < CMisc.PIXEPS && Math.abs(y - dy) < CMisc.PIXEPS; - } - + /** + * Checks if the given point is on the middle of the line. + * + * @param pt the point to check + * @return true if the point is on the middle of the line, false otherwise + */ public boolean pointonMiddle(CPoint pt) { if (points.size() != 2) return false; @@ -1157,6 +1437,11 @@ public boolean pointonMiddle(CPoint pt) { return true; } + /** + * Sets the location of the given point to be on this line. + * + * @param pt the point to set on the line + */ public void pointonline(CPoint pt) { //set the location of the point to line if (this.type == CCLine) return; @@ -1212,6 +1497,13 @@ public void pointonline(CPoint pt) { //set the location of the point to lin } + /** + * Finds the common points between a line and a circle. + * + * @param ln the line + * @param c the circle + * @return an array of common points between the line and the circle + */ public static CPoint[] commonPoint(CLine ln, Circle c) { CPoint t1, t2; t1 = t2 = null; @@ -1243,6 +1535,13 @@ else if (t2 == null) { } } + /** + * Finds the common point between two lines. + * + * @param line0 the first line + * @param line1 the second line + * @return the common point between the two lines, or null if there is no common point + */ public static CPoint commonPoint(CLine line0, CLine line1) { for (int i = 0; i < line0.points.size(); i++) { CPoint p1 = (CPoint) line0.points.get(i); @@ -1256,6 +1555,12 @@ public static CPoint commonPoint(CLine line0, CLine line1) { return null; } + /** + * Checks if this line is the same as another line. + * + * @param line2 the other line to compare + * @return true if the lines are the same, false otherwise + */ public boolean sameLine(CLine line2) { if (line2 == null) return false; if (this.points.size() != line2.points.size()) return false; @@ -1263,6 +1568,15 @@ public boolean sameLine(CLine line2) { return this.points.containsAll(line2.points); } + /** + * Calculates the intersection point of two line segments. + * + * @param p1 the first point of the first line segment + * @param p2 the second point of the first line segment + * @param p3 the first point of the second line segment + * @param p4 the second point of the second line segment + * @return an array containing the x and y coordinates of the intersection point, or null if there is no intersection + */ public static double[] Intersect(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { double result[] = new double[2]; if (Math.abs(p1.getx() - p2.getx()) < CMisc.ZERO) { @@ -1289,10 +1603,23 @@ public static double[] Intersect(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { return result; } + /** + * Checks if a slope is considered vertical. + * + * @param r the slope to check + * @return true if the slope is vertical, false otherwise + */ public static boolean isVerticalSlop(double r) { return Math.abs(r) > CMisc.MAX_SLOPE; } + /** + * Checks if two lines are perpendicular. + * + * @param line0 the first line + * @param line1 the second line + * @return true if the lines are perpendicular, false otherwise + */ public static boolean isPerp(CLine line0, CLine line1) { if (line0 == null || line1 == null) return false; @@ -1306,6 +1633,13 @@ public static boolean isPerp(CLine line0, CLine line1) { return Math.abs(k0 * k1 + 1) < CMisc.ZERO; } + /** + * Calculates the intersection point of two lines. + * + * @param line0 the first line + * @param line1 the second line + * @return an array containing the x and y coordinates of the intersection point, or null if there is no intersection + */ public static double[] Intersect(CLine line0, CLine line1) { if (line0 == null || line1 == null) return null; @@ -1350,6 +1684,13 @@ public static double[] Intersect(CLine line0, CLine line1) { return result; } + /** + * Saves the line to a PostScript file. + * + * @param fp the file output stream + * @param stype the style type + * @throws IOException if an I/O error occurs + */ public void SavePS(FileOutputStream fp, int stype) throws IOException { if (!visible) return; @@ -1362,7 +1703,12 @@ public void SavePS(FileOutputStream fp, int stype) throws IOException { } - + /** + * Saves the line to a data output stream. + * + * @param out the data output stream + * @throws IOException if an I/O error occurs + */ public void Save(DataOutputStream out) throws IOException { super.Save(out); @@ -1384,6 +1730,13 @@ public void Save(DataOutputStream out) throws IOException { out.writeInt(extent); } + /** + * Loads the line from a data input stream. + * + * @param in the data input stream + * @param dp the draw process + * @throws IOException if an I/O error occurs + */ public void Load(DataInputStream in, DrawProcess dp) throws IOException { if (CMisc.version_load_now < 0.01) { m_id = in.readInt(); diff --git a/src/main/java/wprover/CMisc.java b/src/main/java/wprover/CMisc.java index fa166bf4..41639363 100644 --- a/src/main/java/wprover/CMisc.java +++ b/src/main/java/wprover/CMisc.java @@ -9,11 +9,9 @@ import java.net.URL; /** - * Created by IntelliJ IDEA. - * User: Administrator - * Date: 2005-1-8 - * Time: 18:57:22 - * To change this template use File | Settings | File Templates. + * This class contains configuration and utility methods for the application. + * It manages properties such as screen size, background color, font settings, + * and other application-specific settings. */ public class CMisc { final public static double version = 0.053; diff --git a/src/main/java/wprover/CPoint.java b/src/main/java/wprover/CPoint.java index 41f2ae82..ee1b7b17 100644 --- a/src/main/java/wprover/CPoint.java +++ b/src/main/java/wprover/CPoint.java @@ -10,11 +10,9 @@ import java.awt.*; /** - * Created by IntelliJ IDEA. - * User: ${Yezheng} - * Date: 2004-12-9 - * Time: 12:22:43 - * To change this template use File | Settings | File Templates. + * CPoint class represents a point in a 2D space with x and y coordinates. + * It extends the CClass class and implements various methods for drawing, + * saving, and loading the point's properties. */ public class CPoint extends CClass { private int type = 0; @@ -26,22 +24,45 @@ public class CPoint extends CClass { CText ptext; + /** + * Default constructor for the CPoint class. + * Initializes the point with default values and sets the text position. + */ public CPoint() { super(CClass.POINT); ptext = new CText(this, 5, -20, CText.NAME_TEXT); } + /** + * Retrieves the first constraint associated with this point. + * + * @return the first Constraint object, or null if no constraints are present + */ public Constraint getConstraint() { if (cons.size() == 0) return null; return (Constraint) cons.get(0); } + /** + * Constructor for the CPoint class with specified type and coordinates. + * + * @param type the type of the point + * @param X the x-coordinate parameter + * @param Y the y-coordinate parameter + */ public CPoint(int type, Param X, Param Y) { super(type); x1 = X; y1 = Y; } + /** + * Constructor for the CPoint class with specified name and coordinates. + * + * @param Name the name of the point + * @param X the x-coordinate parameter + * @param Y the y-coordinate parameter + */ public CPoint(String Name, Param X, Param Y) { super(CClass.POINT); m_name = Name; @@ -50,7 +71,12 @@ public CPoint(String Name, Param X, Param Y) { ptext = new CText(this, 7, -24, CText.NAME_TEXT); } - + /** + * Constructor for the CPoint class with specified coordinates. + * + * @param X the x-coordinate parameter + * @param Y the y-coordinate parameter + */ public CPoint(Param X, Param Y) { super(CClass.POINT); x1 = X; @@ -58,6 +84,11 @@ public CPoint(Param X, Param Y) { ptext = new CText(this, 7, -24, CText.NAME_TEXT); } + /** + * Retrieves the text associated with this point. + * + * @return the CText object associated with this point + */ public CText getPText() { if (ptext == null) { return new CText(this, 7, -24, CText.NAME_TEXT); @@ -66,9 +97,14 @@ public CText getPText() { } } + /** + * Checks if this point is equal to another object based on the name. + * + * @param obj the object to compare with + * @return true if the names are equal, false otherwise + */ public boolean equals(Object obj) { if (obj == null) { - // CMisc.print("A point without name"); return false; } if (m_name == null || m_name.length() == 0) { @@ -77,13 +113,20 @@ public boolean equals(Object obj) { return m_name.equals(obj.toString()); } + /** + * Stops the flashing effect for this point and its associated text. + */ public void stopFlash() { super.stopFlash(); if (ptext != null) ptext.stopFlash(); - //mode = 0; } + /** + * Sets the flashing state for this point and its associated text. + * + * @param flash true to enable flashing, false to disable + */ public void setInFlashing(boolean flash) { super.setInFlashing(flash); if (ptext != null) { @@ -95,19 +138,41 @@ public void setInFlashing(boolean flash) { } } +/** + * Checks if this point is a fixed point. + * + * @return true if both x and y coordinates are solved, false otherwise + */ public boolean isAFixedPoint() { return x1.Solved && y1.Solved; } + /** + * Checks if this point is a free point. + * + * @return true if both x and y coordinates are not solved, false otherwise + */ public boolean isAFreePoint() { return !x1.Solved && !y1.Solved; } + /** + * Sets the color of this point. + * + * @param c the color to set + */ public void setColor(int c) { super.setColor(c); this.hasSetColor = true; } + /** + * Selects this point if the given coordinates are within a certain distance. + * + * @param x the x-coordinate to check + * @param y the y-coordinate to check + * @return true if the point is selected, false otherwise + */ public boolean select(double x, double y) { if (visible == false) { return false; @@ -120,13 +185,13 @@ public boolean select(double x, double y) { return false; } - public boolean selectText(int x, int y) { - return false; - - } - + /** + * Draws this point on the given graphics context. + * + * @param g2 the graphics context + * @param selected true if the point is selected, false otherwise + */ public void draw(Graphics2D g2, boolean selected) { - int radius = getRadius(); setDrawSelect(g2); int x = (int) getx(); @@ -134,32 +199,51 @@ public void draw(Graphics2D g2, boolean selected) { g2.drawOval(x - radius, y - radius, 2 * radius, 2 * radius); } - public int POINT_RADIUS = CMisc.getPointRadius(); + /** + * Gets the radius of the point. If the radius is not set, it returns the default radius + * based on whether the application is running as an applet or a standalone application. + * + * @return the radius of the point + */ public int getRadius() { int radius = m_radius; -// if (radius < 0) -// radius = CMisc.getPointRadius(); if (radius < 0) { if (CMisc.isApplication()) radius = CMisc.getPointRadius(); else - radius = POINT_RADIUS; //APPLET ONLY + radius = POINT_RADIUS; // APPLET ONLY } return radius; } +/** + * Gets the radius value of the point. + * + * @return the radius value of the point + */ public int getRadiusValue() { return m_radius; } + /** + * Sets the radius of the point. If the given radius is less than or equal to 0, + * it sets the radius to the default value. + * + * @param r the new radius of the point + */ public void setRadius(int r) { if (r <= 0) m_radius = -1; m_radius = r; } + /** + * Draws the point on the given graphics context. + * + * @param g2 the graphics context + */ public void draw(Graphics2D g2) { if (!isdraw()) { return; @@ -179,13 +263,15 @@ public void draw(Graphics2D g2) { g2.setColor(new Color(0, 0, 0)); g2.fillOval(x - radius, y - radius, 2 * radius, 2 * radius); - -// g2.setColor(g2.getBackground()); -// g2.fillOval(x - radius + 1, y - radius + 1, 2 * radius - 2, 2 * radius - 2); setDraw(g2); g2.fillOval(x - radius + 1, y - radius + 1, 2 * radius - 2, 2 * radius - 2); } + /** + * Draws the point with a specific style on the given graphics context. + * + * @param g2 the graphics context + */ public void drawA0(Graphics2D g2) { if (!isdraw()) { return; @@ -200,6 +286,11 @@ public void drawA0(Graphics2D g2) { g2.fillOval(x - radius + 1, y - radius + 1, 2 * radius - 2, 2 * radius - 2); } +/** + * Draws the point and its text on the given graphics context. + * + * @param g2 the graphics context + */ public void draw_wt(Graphics2D g2) { this.drawA0(g2); if (ptext != null) { @@ -207,6 +298,11 @@ public void draw_wt(Graphics2D g2) { } } + /** + * Draws the point with a custom style on the given graphics context. + * + * @param g2 the graphics context + */ public void draw_ct(Graphics2D g2) { int x = (int) getx(); int y = (int) gety(); @@ -220,14 +316,13 @@ public void draw_ct(Graphics2D g2) { g2.drawOval(x - radius, y - radius, 2 * radius, 2 * radius); radius -= 3; g2.drawOval(x - radius, y - radius, 2 * radius, 2 * radius); - - } - - public double distanceTo(CPoint pt) - { - return Math.sqrt(Math.pow(this.getx() - pt.getx(), 2) + Math.pow(this.gety() - pt.gety(), 2)); } + /** + * Returns the type of the point as a string. + * + * @return the type of the point + */ public String TypeString() { String s1 = Language.getLs("Point"); @@ -238,6 +333,11 @@ public String TypeString() { return GExpert.getTranslationViaGettext("Point {0}", m_name); } + /** + * Returns a description of the point. + * + * @return the description of the point + */ public String getDescription() { if (this.isAFreePoint()) { String s1 = Language.getLs("Free Point"); @@ -250,6 +350,9 @@ public String getDescription() { ////////////////////////////////////////////////////// + /** + * Sets the default color of the point based on its solved state. + */ public void setColorDefault() { if (this.hasSetColor) { return; @@ -263,12 +366,24 @@ public void setColorDefault() { } } +/** + * Adds a constraint to the point if it is not already present. + * + * @param cs the constraint to add + */ public void addcstoPoint(Constraint cs) { if (cs != null && !cons.contains(cs)) { cons.add(cs); } } + /** + * Checks if the given x and y coordinates are valid based on the constraints. + * + * @param x the x-coordinate to check + * @param y the y-coordinate to check + * @return true if the coordinates are valid, false otherwise + */ public boolean check_xy_valid(double x, double y) { for (int i = 0; i < cons.size(); i++) { Constraint cs = (Constraint) cons.get(i); @@ -278,8 +393,13 @@ public boolean check_xy_valid(double x, double y) { return true; } + /** + * Checks if this point is equal to another point based on their coordinates. + * + * @param p the point to compare with + * @return true if the points have the same coordinates, false otherwise + */ public boolean isEqual(CPoint p) { - if ((p.x1 == this.x1) && (p.y1 == this.y1)) { return true; } else { @@ -287,6 +407,13 @@ public boolean isEqual(CPoint p) { } } + /** + * Checks if this point is equal to given coordinates based on their indices. + * + * @param x the x-coordinate index to compare + * @param y the y-coordinate index to compare + * @return true if the indices match this point's indices, false otherwise + */ public boolean isEqual(int x, int y) { if ((x == this.x1.xindex) && (y == this.y1.xindex)) { return true; @@ -295,6 +422,13 @@ public boolean isEqual(int x, int y) { } } + /** + * Checks if the given location is the same as this point's location. + * + * @param x the x-coordinate to compare + * @param y the y-coordinate to compare + * @return true if the location matches this point's location, false otherwise + */ public boolean isSame_Location(double x, double y) { if (Math.abs(x - this.getx()) < CMisc.ZERO && Math.abs(y - this.gety()) < CMisc.ZERO) { @@ -303,6 +437,11 @@ public boolean isSame_Location(double x, double y) { return false; } + /** + * Gets the x-coordinate of this point. + * + * @return the x-coordinate of this point + */ public double getx() { if (x1 == null) { CMisc.print("CPoint error,x1 undefined"); @@ -311,14 +450,29 @@ public double getx() { return x1.value; } + /** + * Gets the x-coordinate of the point's text. + * + * @return the x-coordinate of the point's text + */ public int getTx() { return ptext.getX(); } + /** + * Gets the y-coordinate of the point's text. + * + * @return the y-coordinate of the point's text + */ public int getTy() { return ptext.getY(); } + /** + * Gets the y-coordinate of this point. + * + * @return the y-coordinate of this point + */ public double gety() { if (y1 == null) { CMisc.print("CPoint error,y1 undefined"); @@ -327,14 +481,30 @@ public double gety() { return y1.value; } + /** + * Checks if this point is frozen. + * + * @return true if the point is frozen, false otherwise + */ public boolean isFreezed() { return freezed; } + /** + * Sets the frozen state of this point. + * + * @param r the new frozen state + */ public void setFreezed(boolean r) { freezed = r; } + /** + * Sets the x and y coordinates of this point. + * + * @param x the new x-coordinate + * @param y the new y-coordinate + */ public void setXY(double x, double y) { if (true) { x1.value = x; @@ -342,21 +512,36 @@ public void setXY(double x, double y) { } } + /** + * Sets the fill color of this point. + * + * @param index the color index to set + */ public void setFillColor(int index) { this.m_color = index; } + /** + * Returns the string representation of this point. + * + * @return the name of this point + */ public String toString() { return m_name; } + /** + * Saves the PostScript definition of this point to a file. + * + * @param fp the file output stream to write to + * @throws IOException if an I/O error occurs + */ public void SavePS_Define_Point(FileOutputStream fp) throws IOException { String st = m_name; if (st.length() == 0 || st.trim().length() == 0) st = "POINT" + m_id; - String s = '/' + st + " {"; fp.write(s.getBytes()); @@ -366,11 +551,16 @@ public void SavePS_Define_Point(FileOutputStream fp) throws IOException { fp.write(((x1) + " ").getBytes()); - fp.write(((-y1) + - "} def \n").getBytes()); - + fp.write(((-y1) + "} def \n").getBytes()); } + /** + * Saves the PostScript representation of this point to a file. + * + * @param fp the file output stream to write to + * @param stype the style type + * @throws IOException if an I/O error occurs + */ public void SavePS(FileOutputStream fp, int stype) throws IOException { if (visible == false) { return; @@ -390,6 +580,12 @@ public void SavePS(FileOutputStream fp, int stype) throws IOException { fp.write(s.getBytes()); } + /** + * Saves the original PostScript representation of this point to a file. + * + * @param fp the file output stream to write to + * @throws IOException if an I/O error occurs + */ public void SavePsOringinal(FileOutputStream fp) throws IOException { if (visible == false) { return; @@ -410,6 +606,12 @@ public void SavePsOringinal(FileOutputStream fp) throws IOException { fp.write(s.getBytes()); } + /** + * Saves the state of this point to a data output stream. + * + * @param out the data output stream to write to + * @throws IOException if an I/O error occurs + */ public void Save(DataOutputStream out) throws IOException { super.Save(out); out.writeInt(type); @@ -429,6 +631,13 @@ public void Save(DataOutputStream out) throws IOException { out.writeBoolean(freezed); } + /** + * Loads the state of this point from a data input stream. + * + * @param in the data input stream to read from + * @param dp the draw process to use for loading + * @throws IOException if an I/O error occurs + */ public void Load(DataInputStream in, DrawProcess dp) throws IOException { if (CMisc.version_load_now < 0.01) { m_id = in.readInt(); diff --git a/src/main/java/wprover/CPolygon.java b/src/main/java/wprover/CPolygon.java index be37c5d1..0eb0d4fe 100644 --- a/src/main/java/wprover/CPolygon.java +++ b/src/main/java/wprover/CPolygon.java @@ -8,11 +8,8 @@ import java.io.FileOutputStream; /** - * Created by IntelliJ IDEA. - * User: Administrator - * Date: 2005-1-25 - * Time: 20:24:52 - * To change this template use File | Settings | File Templates. + * CPolygon class represents a polygon or circle shape. + * It extends the CClass class and provides methods for drawing, manipulating, and checking properties of the shape. */ public class CPolygon extends CClass { int ftype = 0; // 0: polygon, 1:circle. @@ -29,6 +26,19 @@ public class CPolygon extends CClass { private double area; +/** + * Draws the polygon on the given graphics context with various options. + * + * @param g2 the graphics context + * @param selected true if the polygon is selected, false otherwise + * @param overlap true if the polygon should be drawn with overlap, false otherwise + * @param dx the x-offset for drawing + * @param dy the y-offset for drawing + * @param rotate true if the polygon should be rotated, false otherwise + * @param x the x-coordinate for rotation + * @param y the y-coordinate for rotation + * @param ang the angle of rotation in radians + */ public void draw(Graphics2D g2, boolean selected, boolean overlap, double dx, double dy, boolean rotate, double x, double y, double ang) { if (!isdraw()) return; @@ -75,7 +85,6 @@ public void draw(Graphics2D g2, boolean selected, boolean overlap, double dx, do this.setDraw(g2); - Composite ac = null; if (overlap) { ac = g2.getComposite(); @@ -125,16 +134,32 @@ public void draw(Graphics2D g2, boolean selected, boolean overlap, double dx, do g2.setComposite(ac); } + /** + * Retrieves the element at the specified index in the point list. + * + * @param n the index of the element + * @return the element at the specified index, or null if the index is out of bounds + */ public CClass getElement(int n) { if (n < 0 || n >= pointlist.size()) return null; return (CClass) pointlist.get(n); } + /** + * Retrieves the area of the polygon. + * + * @return the area of the polygon + */ public double getArea() { return area; } + /** + * Checks if all points in the polygon are free points. + * + * @return true if all points are free points, false otherwise + */ public boolean isAllPointsFree() { for (int i = 0; i < pointlist.size(); i++) { CPoint pt = (CPoint) pointlist.get(i); @@ -144,10 +169,28 @@ public boolean isAllPointsFree() { return true; } + /** + * Calculates the signed area of a triangle given its vertex coordinates. + * + * @param x1 the x-coordinate of the first vertex + * @param y1 the y-coordinate of the first vertex + * @param x2 the x-coordinate of the second vertex + * @param y2 the y-coordinate of the second vertex + * @param x3 the x-coordinate of the third vertex + * @return the signed area of the triangle + */ public static double signArea(int x1, int y1, int x2, int y2, int x3, int y3) { return ((x2 - x1) * (y3 - y2) - (y2 - y1) * (x3 - x2)) / 2; } + /** + * Calculates the area of a polygon given its vertex coordinates. + * + * @param xPoints the x-coordinates of the vertices + * @param yPoints the y-coordinates of the vertices + * @param nPoints the number of vertices + * @return the area of the polygon + */ public static double area(int xPoints[], int yPoints[], int nPoints) { if (nPoints < 4) return 0.0; @@ -158,6 +201,12 @@ public static double area(int xPoints[], int yPoints[], int nPoints) { return r; } + /** + * Checks if this polygon is equal to the given circle. + * + * @param c the circle to compare with + * @return true if the polygon is equal to the circle, false otherwise + */ public boolean isEqual(Circle c) { if (c == null) return false; if (ftype != 1) return false; @@ -168,55 +217,62 @@ public boolean isEqual(Circle c) { return c.o == pointlist.get(0) && ((pp[0] == pointlist.get(1) && pp[1] == pointlist.get(2)) || (pp[0] == pointlist.get(2) && pp[1] == pointlist.get(1))); - - } - public void drawAreaText(Graphics2D g2, int xPoints[], int yPoints[], int nPoints) { - if (nPoints < 4) return; - double r = area(xPoints, yPoints, nPoints); - r = Math.abs(r); - - int x, y; - x = y = 0; - - for (int i = 0; i <= nPoints - 2; i++) { - x += xPoints[i]; - y += yPoints[i]; - } - x = x / (nPoints - 1); - y = y / (nPoints - 1); - g2.drawString("Area = " + r, x, y); - } - - public void setShowArea(boolean r) { - showArea = r; - } - - + /** + * Draws the polygon on the given graphics context with the selected option. + * + * @param g2 the graphics context + * @param selected true if the polygon is selected, false otherwise + */ public void draw(Graphics2D g2, boolean selected) { draw(g2, selected, true, 0, 0, false, 0, 0, 0); } + /** + * Draws the polygon on the given graphics context. + * + * @param g2 the graphics context + */ public void draw(Graphics2D g2) { this.draw(g2, false); } + /** + * Retrieves the number of points in the polygon. + * + * @return the number of points in the polygon + */ public int getPtn() { return pointlist.size(); } + /** + * Retrieves the point at the specified index in the point list. + * + * @param n the index of the point + * @return the point at the specified index + */ public CPoint getPoint(int n) { return (CPoint) pointlist.get(n); } + /** + * Default constructor for the CPolygon class. + * Initializes the polygon with default values. + */ public CPolygon() { super(CClass.POLYGON); pt1 = pt2 = null; pdx = pdy = 0; - //m_color =drawData. } + /** + * Constructor for the CPolygon class with a specified circle. + * Initializes the polygon as a circle with the given circle's properties. + * + * @param c the circle to initialize the polygon with + */ public CPolygon(Circle c) { this(); this.ftype = 1; @@ -227,6 +283,14 @@ public CPolygon(Circle c) { pointlist.add(c.o); } +/** + * Sets the dragged points and their offsets. + * + * @param p1 the first dragged point + * @param p2 the second dragged point + * @param x the x-offset + * @param y the y-offset + */ public void setDraggedPoints(CPoint p1, CPoint p2, double x, double y) { pt1 = p1; pt2 = p2; @@ -234,6 +298,9 @@ public void setDraggedPoints(CPoint p1, CPoint p2, double x, double y) { pdy = y; } + /** + * Resets the dragged points and their offsets to null and clears the vector list. + */ public void setDraggedPointsNull() { pt1 = null; pt2 = null; @@ -242,6 +309,11 @@ public void setDraggedPointsNull() { vtrlist.clear(); } + /** + * Copies the properties of the given polygon to this polygon. + * + * @param c the polygon to copy from + */ public void copy(CPolygon c) { super.copy(c); grid = c.grid; @@ -249,19 +321,40 @@ public void copy(CPolygon c) { this.type = c.type; } + /** + * Adds a pair of dragged points to the vector list. + * + * @param p1 the first point + * @param p2 the second point + */ public void addDraggedPoints(CPoint p1, CPoint p2) { vtrlist.add(p1); vtrlist.add(p2); } + /** + * Checks if all points have been dragged. + * + * @return true if all points have been dragged, false otherwise + */ public boolean allDragged() { return vtrlist.size() == (pointlist.size() - 1) * 2; } + /** + * Retrieves the vector list of dragged points. + * + * @return the vector list of dragged points + */ public Vector getDraggedPoints() { return vtrlist; } + /** + * Retrieves the transformed points based on the dragged points. + * + * @return the vector list of transformed points + */ public Vector getTransformedPoints() { Vector vlist = new Vector(); @@ -283,6 +376,12 @@ public Vector getTransformedPoints() { return vlist; } + /** + * Retrieves the polygon type as a string. + * + * @return the polygon type string + * @deprecated Use {@link #getPolygonTypeString(String)} instead. + */ @Deprecated public String getPolygonTypeString() { String ds; @@ -303,9 +402,14 @@ else if (size == 6) } else { return Language.getLs("Circle"); } - } + /** + * Retrieves the polygon type as a string with a specified format. + * + * @param s the format string + * @return the formatted polygon type string + */ public String getPolygonTypeString(String s) { String ds; @@ -325,23 +429,36 @@ else if (size == 6) } else { return GExpert.getTranslationViaGettext("Circle {0}", s); } - } + /** + * Retrieves the polygon type as a string. + * + * @return the polygon type string + * @deprecated Use {@link #getPolygonTypeString(String)} instead. + */ @Deprecated public String TypeString() { return getPolygonTypeString(); } + /** + * Retrieves the polygon type as a string with a specified format. + * + * @param s the format string + * @return the formatted polygon type string + */ public String TypeString(String s) { return getPolygonTypeString(s); } - public boolean containPnt(CPoint p) { - return pointlist.contains(p); - } - - public boolean check_rdeq(Vector v) { // n --- n-1; + /** + * Checks if the polygon is equal to another polygon by comparing their points in a rotated manner. + * + * @param v the vector of points to compare with + * @return true if the polygons are equal, false otherwise + */ + public boolean check_rdeq(Vector v) { if (!visible) return false; int n = pointlist.size(); @@ -369,21 +486,15 @@ public boolean containPnt(CPoint p) { return false; } + /** + * Checks if the polygon is equal to another polygon by comparing their points. + * + * @param v the vector of points to compare with + * @return true if the polygons are equal, false otherwise + */ public boolean check_eq(Vector v) { int n = pointlist.size(); if (n != v.size()) return false; - /* - n--; - int i, j; - - for (i = 0; i < n; i++) { - for (j = 0; j < n; j++) { - if (pointlist.get(i) != v.get((j + i) % n)) - break; - } - if (j == n) - return true; - } */ for (int i = 0; i < n; i++) { if (pointlist.get(i) != v.get(i)) @@ -391,174 +502,210 @@ public boolean check_eq(Vector v) { } return true; } -//////////////////////////////////////////////////////////// - void setType(int type) { - this.type = type; - } - - - int getType() { - return type; - } +/** + * Sets the type of the polygon. + * + * @param type the type of the polygon + */ +void setType(int type) { + this.type = type; +} - void setGrid(int grid) { - this.grid = grid; - } +/** + * Gets the type of the polygon. + * + * @return the type of the polygon + */ +int getType() { + return type; +} - void setSlope(int s) { - this.slope = s; - } +/** + * Sets the grid size for the polygon. + * + * @param grid the grid size + */ +void setGrid(int grid) { + this.grid = grid; +} +/** + * Sets the slope for the polygon. + * + * @param s the slope value + */ +void setSlope(int s) { + this.slope = s; +} - public void setPoints(Vector v) { - pointlist.clear(); - pointlist.addAll(v); - return; - } +/** + * Sets the points of the polygon. + * + * @param v the vector containing the points + */ +public void setPoints(Vector v) { + pointlist.clear(); + pointlist.addAll(v); + return; +} - public boolean addAPoint(CPoint p) { - if (p == null) return false; - if (pointlist.size() > 1 && p == pointlist.get(0)) { - pointlist.add(p); - return true; - } else if (pointlist.contains(p)) - return false; - else - pointlist.add(p); +/** + * Adds a point to the polygon. + * + * @param p the point to add + * @return true if the point was added, false if the point was already in the list or null + */ +public boolean addAPoint(CPoint p) { + if (p == null) return false; + if (pointlist.size() > 1 && p == pointlist.get(0)) { + pointlist.add(p); + return true; + } else if (pointlist.contains(p)) return false; - } - - - public boolean select(double x, double y) { - if (visible == false) return false; - - if (ftype == 0) { - Polygon poly = new Polygon(); + else + pointlist.add(p); + return false; +} - for (int i = 0; i < pointlist.size(); i++) { - CPoint pt = (CPoint) pointlist.get(i); - poly.addPoint((int) pt.getx(), (int) pt.gety()); - } +/** + * Selects the polygon if the given coordinates are within its bounds. + * + * @param x the x-coordinate to check + * @param y the y-coordinate to check + * @return true if the polygon is selected, false otherwise + */ +public boolean select(double x, double y) { + if (visible == false) return false; - return poly.contains(x, y); - } else { - CPoint p1 = (CPoint) pointlist.get(0); - CPoint p2 = (CPoint) pointlist.get(1); - CPoint p3 = (CPoint) pointlist.get(2); - double r = (Math.pow(p2.getx() - p3.getx(), 2) + Math.pow(p2.gety() - p3.gety(), 2)); + if (ftype == 0) { + Polygon poly = new Polygon(); - return Math.pow(x - p1.getx(), 2) + Math.pow(y - p1.gety(), 2) < r; + for (int i = 0; i < pointlist.size(); i++) { + CPoint pt = (CPoint) pointlist.get(i); + poly.addPoint((int) pt.getx(), (int) pt.gety()); } - } + return poly.contains(x, y); + } else { + CPoint p1 = (CPoint) pointlist.get(0); + CPoint p2 = (CPoint) pointlist.get(1); + CPoint p3 = (CPoint) pointlist.get(2); + double r = (Math.pow(p2.getx() - p3.getx(), 2) + Math.pow(p2.gety() - p3.gety(), 2)); - public CPoint getPreviousePoint(CPoint p) { - for (int i = 0; i < pointlist.size() - 1; i++) { - if (p == pointlist.get(i + 1)) - return (CPoint) pointlist.get(i); - } - return null; + return Math.pow(x - p1.getx(), 2) + Math.pow(y - p1.gety(), 2) < r; } +} - public CPoint getNextPoint(CPoint p) { - for (int i = 1; i < pointlist.size(); i++) { - if (p == pointlist.get(i - 1)) - return (CPoint) pointlist.get(i); - } - return null; +/** + * Gets the previous point in the polygon. + * + * @param p the current point + * @return the previous point, or null if not found + */ +public CPoint getPreviousePoint(CPoint p) { + for (int i = 0; i < pointlist.size() - 1; i++) { + if (p == pointlist.get(i + 1)) + return (CPoint) pointlist.get(i); } + return null; +} - public void draw(Graphics2D g2, CPoint p) { - if (visible == false) return; - - if (pointlist.size() == 0) return; - - int n = pointlist.size() + 2; - int[] xpoints = new int[n]; - int[] ypoints = new int[n]; - - for (int i = 0; i < pointlist.size(); i++) { - CPoint pt = (CPoint) pointlist.get(i); - xpoints[i] = (int) pt.getx(); - ypoints[i] = (int) pt.gety(); - } - xpoints[n - 2] = (int) p.getx(); - ypoints[n - 2] = (int) p.gety(); - - CPoint pt = (CPoint) pointlist.get(0); - xpoints[n - 1] = (int) pt.getx(); - ypoints[n - 1] = (int) pt.gety(); - - this.setDraw(g2); - +/** + * Gets the next point in the polygon. + * + * @param p the current point + * @return the next point, or null if not found + */ +public CPoint getNextPoint(CPoint p) { + for (int i = 1; i < pointlist.size(); i++) { + if (p == pointlist.get(i - 1)) + return (CPoint) pointlist.get(i); + } + return null; +} - if (type == 0) - g2.fillPolygon(xpoints, ypoints, n); - else - drawGrid(g2, xpoints, ypoints, n, 0, type); +/** + * Draws the polygon with an additional point on the given graphics context. + * + * @param g2 the graphics context + * @param p the additional point to draw + */ +public void draw(Graphics2D g2, CPoint p) { + if (visible == false) return; - g2.setColor(super.getColor().darker().darker()); + if (pointlist.size() == 0) return; + int n = pointlist.size() + 2; + int[] xpoints = new int[n]; + int[] ypoints = new int[n]; - g2.drawPolygon(xpoints, ypoints, n); + for (int i = 0; i < pointlist.size(); i++) { + CPoint pt = (CPoint) pointlist.get(i); + xpoints[i] = (int) pt.getx(); + ypoints[i] = (int) pt.gety(); + } + xpoints[n - 2] = (int) p.getx(); + ypoints[n - 2] = (int) p.gety(); - g2.drawLine(xpoints[0], ypoints[0], (int) p.getx(), (int) p.gety()); - g2.drawLine(xpoints[n - 1], ypoints[n - 1], (int) p.getx(), (int) p.gety()); + CPoint pt = (CPoint) pointlist.get(0); + xpoints[n - 1] = (int) pt.getx(); + ypoints[n - 1] = (int) pt.gety(); + this.setDraw(g2); - } + if (type == 0) + g2.fillPolygon(xpoints, ypoints, n); + else + drawGrid(g2, xpoints, ypoints, n, 0, type); - public double getCentroidX() { - Vector v = pointlist; + g2.setColor(super.getColor().darker().darker()); - double dx1 = 0; - int n = v.size(); - for (int i = 0; i < n; i++) { - CPoint pt = (CPoint) v.get(i); - dx1 += pt.getx(); - } - dx1 /= n; - return dx1; - } + g2.drawPolygon(xpoints, ypoints, n); - public double getCentroidY() { - Vector v = pointlist; - double dy1 = 0; - int n = v.size(); - for (int i = 0; i < n; i++) { - CPoint pt = (CPoint) v.get(i); - dy1 += pt.gety(); - } - dy1 /= n; - return dy1; - } + g2.drawLine(xpoints[0], ypoints[0], (int) p.getx(), (int) p.gety()); + g2.drawLine(xpoints[n - 1], ypoints[n - 1], (int) p.getx(), (int) p.gety()); +} - public String getDescription() { - String s = new String(); - if (pointlist.size() < 4) return ""; +/** + * Gets the description of the polygon. + * + * @return the description of the polygon + */ +public String getDescription() { + String s = new String(); + if (pointlist.size() < 4) return ""; - int size = pointlist.size() - 1; + int size = pointlist.size() - 1; - for (int i = 0; i < size; i++) { - CClass cc = (CClass) pointlist.get(i); - s += cc.m_name; - } - if (ftype == 0) - return TypeString(s); - else return TypeString("(" + s + ")"); + for (int i = 0; i < size; i++) { + CClass cc = (CClass) pointlist.get(i); + s += cc.m_name; } + if (ftype == 0) + return TypeString(s); + else return TypeString("(" + s + ")"); +} - public Vector drawGrid(Graphics2D g2, int[] xpoints, int[] ypoints, int n, int dtype, int gtype) // type 0: draw ; 1: print ps - { +/** + * Draws a grid pattern on the given graphics context based on the specified points and grid type. + * + * @param g2 the graphics context + * @param xpoints the x-coordinates of the points + * @param ypoints the y-coordinates of the points + * @param n the number of points + * @param dtype the draw type (0: draw, 1: print ps) + * @param gtype the grid type (1: vertical, 2: horizontal, 3: both) + * @return a vector of points if dtype is 1, otherwise null + */ + public Vector drawGrid(Graphics2D g2, int[] xpoints, int[] ypoints, int n, int dtype, int gtype) { Vector vpl = null; if (dtype == 1) vpl = new Vector(); if (n <= 3) return vpl; - double k = Math.tan(slope * Math.PI / 180); int step = this.grid; @@ -707,6 +854,14 @@ else if (dtype == 1) { return vpl; } + /** + * Adds a value to a sorted array and returns the new size of the array. + * + * @param a the value to add + * @param b the array to add the value to + * @param n the current size of the array + * @return the new size of the array + */ private int add_sort(double a, double[] b, int n) { for (int i = 0; i < n; i++) { if (a < b[i]) { @@ -718,9 +873,15 @@ private int add_sort(double a, double[] b, int n) { } b[n] = a; return n + 1; - } + /** + * Saves the polygon as a PostScript file. + * + * @param fp the file output stream + * @param stype the save type + * @throws IOException if an I/O error occurs + */ public void SavePS(FileOutputStream fp, int stype) throws IOException { if (visible == false) return; @@ -739,10 +900,8 @@ public void SavePS(FileOutputStream fp, int stype) throws IOException { ypoints[i] = (int) pt.gety(); } - String s = ""; - if (type == 0) { for (int i = 0; i < pointlist.size() - 1; i++) { CPoint pt = (CPoint) pointlist.get(i); @@ -782,10 +941,14 @@ public void SavePS(FileOutputStream fp, int stype) throws IOException { fp.write(st.getBytes()); this.saveSuper(fp); } - } - + /** + * Saves the polygon data to a data output stream. + * + * @param out the data output stream + * @throws IOException if an I/O error occurs + */ public void Save(DataOutputStream out) throws IOException { super.Save(out); out.writeBoolean(showArea); @@ -801,6 +964,13 @@ public void Save(DataOutputStream out) throws IOException { } } + /** + * Loads the polygon data from a data input stream. + * + * @param in the data input stream + * @param dp the draw process + * @throws IOException if an I/O error occurs + */ public void Load(DataInputStream in, DrawProcess dp) throws IOException { if (CMisc.version_load_now < 0.010) { m_id = in.readInt(); @@ -838,9 +1008,6 @@ else if (m_color == 7) int d = in.readInt(); pointlist.add(dp.getPointById(d)); } - - } } - } diff --git a/src/main/java/wprover/CProperty.java b/src/main/java/wprover/CProperty.java index 052b0bf6..ce2fe514 100644 --- a/src/main/java/wprover/CProperty.java +++ b/src/main/java/wprover/CProperty.java @@ -12,11 +12,8 @@ import java.util.EventObject; /** - * Created by IntelliJ IDEA. - * User: Administrator - * Date: 2005-2-10 - * Time: 19:38:34 - * To change this template use File | Settings | File Templates. + * CProperty is a JPanel that displays property panels for different geometric objects. + * It allows users to modify properties such as color, line type, and line width. */ public class CProperty extends JPanel implements ActionListener { @@ -36,6 +33,13 @@ public class CProperty extends JPanel implements ActionListener { private Panel_arrow parrow; + /** + * Constructor for the CProperty class. + * Initializes the property panels and sets up the layout. + * + * @param dd the DPanel instance + * @param lan the Language instance + */ public CProperty(DPanel dd, Language lan) { d = dd; this.lan = lan; @@ -58,12 +62,24 @@ public CProperty(DPanel dd, Language lan) { this.add(label); } + /** + * Retrieves the language string for the given key. + * + * @param s the key for the language string + * @return the language string + * @deprecated Use {@link GExpert#getLanguage(String)} instead. + */ @Deprecated public String getLanguage(String s) { return GExpert.getLanguage(s); } - + /** + * Sets the panel type based on the given CClass object. + * Updates the layout and adds the appropriate property panel. + * + * @param obj the CClass object + */ public void SetPanelType(CClass obj) { if (obj == null) return; @@ -161,24 +177,30 @@ public void SetPanelType(CClass obj) { this.revalidate(); } + /** + * Handles action events. + * + * @param e the ActionEvent + */ public void actionPerformed(ActionEvent e) { } - public void setPropertyChanged() { - - } - + /** + * Creates a JButton with an icon from the specified image name. + * + * @param imageName the name of the image file + * @return the created JButton + */ public static JButton CreateIconButton(String imageName) { String imgLocation = "images/" + imageName; URL imageURL = GExpert.class.getResource(imgLocation); JButton button = new JButton(); - - if (imageURL != null) { //image found + if (imageURL != null) { // image found button.setIcon(new ImageIcon(imageURL)); - } else { //no image found + } else { // no image found button.setText(imageName); } button.setMaximumSize(new Dimension(20, 18)); @@ -187,6 +209,13 @@ public static JButton CreateIconButton(String imageName) { return button; } + /** + * Creates a JTable with the specified objects. + * + * @param obj1 the first object + * @param obj2 the second object + * @return the created JTable + */ public static JTable createTable(Object obj1, Object obj2) { Object data[][] = {{obj1, obj2}}; String[] sname = {"", ""}; @@ -205,6 +234,9 @@ public static JTable createTable(Object obj1, Object obj2) { } + /** + * Panel for the color, line type and line width properties. + */ class Panel_CS extends JPanel implements ActionListener { DPanel d; @@ -352,6 +384,9 @@ public void paintComponent(Graphics g) { } } + /** + * Panel for the polygon properties. + */ class Panel_Line extends JPanel implements TableModelListener, ActionListener, ChangeListener { DPanel d; CLine line; @@ -473,6 +508,9 @@ else if (line.ext_type == 1) } + /** + * Panel for the circle properties. + */ class Panel_Circle extends JPanel implements TableModelListener { DPanel d; @@ -529,6 +567,9 @@ public void setVariable(Circle c) { } + /** + * Panel for the point properties. + */ class Panel_Point extends JPanel implements TableModelListener { DPanel d; @@ -608,6 +649,9 @@ public void paintComponent(Graphics g) { } } + /** + * Panel for the angle properties. + */ class Panel_Angle extends JPanel implements ActionListener, TableModelListener { DPanel d; JComboBox bcolor; @@ -759,6 +803,9 @@ public void setAgTabel(int n) { } + /** + * Base class for all property panels. + */ class Panel_Base extends JPanel { protected DPanel d; protected TitledBorder border; @@ -776,6 +823,9 @@ public void setBorder(CClass c) { } } + /** + * Panel for the text properties. + */ class Panel_text extends Panel_Base implements TableModelListener { CText tx; JTable table, table1, table2; @@ -886,6 +936,9 @@ public void setVariable(CText t) { } + /** + * Panel for the trace properties. + */ class Panel_trace extends Panel_Base implements TableModelListener { CTrace ts; JTable table, table1; @@ -942,6 +995,9 @@ public void setVariable(CTrace tc) { } } + /** + * Panel for the equation mark properties. + */ class Panel_eqmark extends Panel_Base implements TableModelListener { Cedmark mk; JTable table; @@ -982,6 +1038,9 @@ public void setVariable(Cedmark mc) { } } + /** + * Panel for the polygon properties. + */ class Panel_Polygon extends JPanel implements TableModelListener { DPanel d; @@ -1076,6 +1135,9 @@ public void setVariable(CPolygon c) { } + /** + * Panel for the arrow properties. + */ class Panel_arrow extends Panel_Base implements TableModelListener { CArrow arrow; JTable table; @@ -1116,48 +1178,9 @@ public void setVariable(CArrow mc) { } } - - class DefaultTableModel extends AbstractTableModel { - private Object[][] data; - - public DefaultTableModel(Object[][] o) { - data = o; - } - - public int getColumnCount() { - return 2; - } - - public int getRowCount() { - return data.length; - } - - public String getColumnName(int col) { - return ""; - } - - public Object getValueAt(int row, int col) { - return data[row][col]; - } - - public Class getColumnClass(int c) { - return getValueAt(0, c).getClass(); - } - - public boolean isCellEditable(int row, int col) { - if (col < 1) { - return false; - } else { - return true; - } - } - - public void setValueAt(Object value, int row, int col) { - data[row][col] = value; - fireTableCellUpdated(row, col); - } - } - + /** + * Table model for the property table. + */ class propertyTableModel extends AbstractTableModel { private String[] names = {"", ""}; private Object[][] data = null; @@ -1205,6 +1228,9 @@ public void setValueAt(Object value, int row, int col) { } + /** + * Table model for the point properties. + */ class PointTableModel extends AbstractTableModel { private String[] names = {"", ""}; private Object[][] data = { @@ -1249,6 +1275,9 @@ public void setValueAt(Object value, int row, int col) { } } + /** + * Table model for the line properties. + */ class LineTableModel extends AbstractTableModel { private String[] names = {"", ""}; private Object[][] data = { @@ -1294,7 +1323,9 @@ public void setValueAt(Object value, int row, int col) { } } - + /** + * Table model for the circle properties. + */ class CircleTableModel extends AbstractTableModel { private String[] names = {"", ""}; private Object[][] data = { @@ -1340,6 +1371,9 @@ public void setValueAt(Object value, int row, int col) { } } + /** + * Table model for the polygon properties. + */ class PolygonTableModel extends AbstractTableModel { private String[] names = {"", ""}; private Object[][] data = { @@ -1381,73 +1415,14 @@ public void setValueAt(Object value, int row, int col) { } } + /** + * Rounds a double to two decimal places. + * + * @param r the double to round + * @return the rounded double + */ private double round(double r) { int t = (int) (100 * r); return t / 100.0; } - - class CPropertyTableCellRender implements TableCellRenderer { - TableCellRenderer deditor; - - public Component getTableCellRendererComponent(JTable table, Object value, - boolean isSelected, boolean hasFocus, - int row, int column) { - return deditor.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); - } - - } - - class CPropertyTableCellEditor implements TableCellEditor { - DefaultCellEditor editor; - DefaultCellEditor booleanEditor; - DefaultCellEditor selected; - - public CPropertyTableCellEditor() { - selected = editor = new DefaultCellEditor(new JTextField()); - booleanEditor = new DefaultCellEditor(new JCheckBox()); - } - - public Component getTableCellEditorComponent(JTable table, Object value, - boolean isSelected, - int row, int column) { - if (value instanceof Boolean) { - selected = booleanEditor; - return booleanEditor.getTableCellEditorComponent(table, value, isSelected, row, column); - } - selected = editor; - return editor.getTableCellEditorComponent(table, value, isSelected, row, column); - } - - public void setEditorAt(int row, TableCellEditor editor) { - - } - - public Object getCellEditorValue() { - return selected.getCellEditorValue(); - } - - public boolean stopCellEditing() { - return selected.stopCellEditing(); - } - - public void cancelCellEditing() { - selected.cancelCellEditing(); - } - - public boolean isCellEditable(EventObject anEvent) { - return selected.isCellEditable(anEvent); - } - - public void addCellEditorListener(CellEditorListener l) { - selected.addCellEditorListener(l); - } - - public void removeCellEditorListener(CellEditorListener l) { - selected.removeCellEditorListener(l); - } - - public boolean shouldSelectCell(EventObject anEvent) { - return selected.shouldSelectCell(anEvent); - } - } } \ No newline at end of file diff --git a/src/main/java/wprover/CProveBarPanel.java b/src/main/java/wprover/CProveBarPanel.java index 2710bdca..ccec0f63 100644 --- a/src/main/java/wprover/CProveBarPanel.java +++ b/src/main/java/wprover/CProveBarPanel.java @@ -10,13 +10,9 @@ import java.awt.event.*; /** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2005-8-27 - * Time: 13:25:17 - * To change this template use File | Settings | File Templates. + * CProveBarPanel is a custom panel that contains a toolbar for controlling the proof process. + * It includes buttons for stepping through the proof, playing the animation, and adjusting the speed. */ - public class CProveBarPanel extends FloatableToolBar { ProveBar bar; @@ -24,10 +20,6 @@ public CProveBarPanel(GExpert gx) { this.add(bar = new ProveBar(gx)); } - public void Enable(boolean r) { - bar.Enable(r); - } - public void setValue(int n) { bar.setValue(n); } @@ -58,6 +50,10 @@ public boolean isStepAtEnd() { } } +/** + * ProveBar is a custom toolbar that provides controls for stepping through a proof process. + * It includes buttons for stepping, playing, pausing, and stopping the proof animation. + */ class ProveBar extends JToolBar implements ActionListener, ChangeListener { private GExpert gxInstance; @@ -81,28 +77,10 @@ public ProveBar(GExpert gex) { init(); } - public ProveBar(GExpert gex, DPanel dd, DrawTextProcess dp, PanelProve pproof) { - super(); - gxInstance = gex; - this.dpane = dd; - this.dp = dp; - this.pproof = pproof; - init(); - } - public boolean isRunning() { return timer != null && timer.isRunning(); } - public void Enable(boolean r) { - bx1.setEnabled(r); - bx2.setEnabled(r); - bx3.setEnabled(r); - bx4.setEnabled(r); - bx5.setEnabled(r); - slider.setEnabled(r); - } - public void stop() { if (timer != null) { timer.stop(); @@ -330,10 +308,6 @@ public void adjustSpeed() { dp.setTimerDelay(v); } - public int getTimeDelay() { - return this.getInterval(); - } - public int getInterval() { int v = slider.getValue(); return 300 - v; diff --git a/src/main/java/wprover/CProveField.java b/src/main/java/wprover/CProveField.java index 77da26f1..e0fa847d 100644 --- a/src/main/java/wprover/CProveField.java +++ b/src/main/java/wprover/CProveField.java @@ -10,11 +10,8 @@ import java.io.FileOutputStream; /** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2005-8-25 - * Time: 19:19:11 - * To change this template use File | Settings | File Templates. + * CProveField is a class that represents a field for proving mathematical theorems. + * It handles the display and manipulation of proof steps and conditions. */ public class CProveField { private boolean HEAD = false; @@ -30,78 +27,41 @@ public class CProveField { int rstep = -1; int rmid = 0; + /** + * Default constructor for `CProveField`. + * Initializes the point and vectors for proof steps and conditions. + */ public CProveField() { pt = new Point(20, 20); clist = new Vector(); vlist = new Vector(); } + /** + * Sets the x and y coordinates of the point. + * + * @param x the x-coordinate + * @param y the y-coordinate + */ public void setXY(int x, int y) { pt.setLocation(x, y); } + /** + * Drags the selected proof text by the specified delta values. + * + * @param dx the change in x-coordinate + * @param dy the change in y-coordinate + */ public void drag(double dx, double dy) { if (pselect == null) return; pt.setLocation((int) (pt.getX() + dx), (int) (pt.getY() + dy)); } - public void setCaptain(String sname) { - if (sname == null) return; - if (sname.endsWith(".gex")) - sname = sname.substring(0, sname.length() - 4); - cpname.setMessage(sname); - } - - public CProveField(DrawProcess dp) //undolist; - { - - pt = new Point(20, 20); - - cpname = new CProveText("", "theorem"); - cpname.setFont(new Font("Dialog", Font.PLAIN, 18)); - cpname.setMessageColor(Color.black); - - - clist = new Vector(); - vlist = new Vector(); - pselect = null; - - - Vector vnlist = dp.undolist; - if (vnlist.size() == 0) return; - - int i = 0; - - for (i = 0; i < vnlist.size(); i++) { - UndoStruct un = (UndoStruct) vnlist.get(i); - if (un.m_type == UndoStruct.T_TO_PROVE_NODE) { - CProveText cp = new CProveText(un, GExpert.getTranslationViaGettext("To Prove:") + " "); - vlist.add(cp); - break; - } - - CProveText cp; - if (i == 0) - cp = new CProveText(un, GExpert.getTranslationViaGettext("Given:") + " "); - else - cp = new CProveText(un); - clist.add(cp); - } - int index = 0; - - - i++; - for (; i < vnlist.size(); i++) { - UndoStruct un = (UndoStruct) vnlist.get(i); - CProveText cp = new CProveText(un, index); - vlist.add(cp); - index++; - } - - HEAD = true; - expandAll(); - } - + /** + * Regenerates the index for the proof steps. + * Sets the visibility and index of each proof step based on the `HEAD` flag. + */ public void reGenerateIndex() { if (HEAD) { @@ -130,6 +90,13 @@ public void reGenerateIndex() { } + /** + * Constructor for `CProveField` with a vector of conditions and a head flag. + * Initializes the point, vectors, and proof text based on the head flag. + * + * @param v the vector of conditions + * @param head the head flag indicating the type of proof field + */ public CProveField(Vector v, boolean head) { pt = new Point(20, 20); clist = new Vector(); @@ -168,56 +135,12 @@ public CProveField(Vector v, boolean head) { } - public CProveField(Cond co, boolean head) { - pt = new Point(20, 20); - clist = new Vector(); - vlist = new Vector(); - HEAD = head; - if (head) { - cpname = new CProveText("", "theorem"); - cpname.setFont(new Font("Dialog", Font.PLAIN, 18)); - cpname.setMessageColor(Color.black); - pselect = null; - } - - int i = -1; - CProveText ct = null; - while (co != null) { - if (head && i == -1) - ct = new CProveText(co, GExpert.getLanguage("To Prove:") + " "); - else - ct = new CProveText(null, co, i, true); - i++; - vlist.add(ct); - co = co.nx; - } - this.expandAll(); - - } - - public void genProve(Cond co) { - int i = 0; - CProveText ct = null; - while (co != null) { - ct = new CProveText(null, co, i, false); - i++; - vlist.add(ct); - co = co.nx; - } - } - - public void genCondition(Vector v) { - CProveText ct = null; - for (int i = 0; i < v.size(); i++) { - String s = (String) v.get(i); - if (i == 0) - ct = new CProveText(GExpert.getLanguage("Given:") + " ", s); - else - ct = new CProveText(s); - clist.add(ct); - } - } - + /** + * Constructor for `CProveField` with a vector of undo structures. + * Initializes the point and vectors for proof steps and conditions. + * + * @param ulist the vector of undo structures + */ public CProveField(Vector ulist) { pt = new Point(20, 20); @@ -230,6 +153,10 @@ public CProveField(Vector ulist) { } } + /** + * Expands all proof steps and conditions. + * Sets the visibility of each proof text to expanded. + */ public void expandAll() { for (int i = 0; i < clist.size(); i++) { @@ -244,28 +171,21 @@ public void expandAll() { } - public CProveText getFirstProveNode() { - return (CProveText) clist.get(0); - } - - - public CProveText createANewCommentNode() { - CProveText cp = new CProveText("", "Click to edit here"); - return cp; - } - + /** + * Draws the proof steps on the specified `Graphics2D` context. + * + * @param g2 the `Graphics2D` context to draw on + */ public void draw(Graphics2D g2) { Point p = new Point((int) pt.getX(), (int) pt.getY()); draw(g2, p); } - public int getFontSize() { - if (clist.size() == 0) return 14; - - CProveText cp = (CProveText) clist.get(0); - return cp.getFont().getSize(); - } - + /** + * Sets the font size for all proof texts. + * + * @param size the font size to set + */ public void setFontSize(int size) { for (int i = 0; i < clist.size(); i++) { CProveText cp = (CProveText) clist.get(i); @@ -278,10 +198,21 @@ public void setFontSize(int size) { this.pselect = null; } + /** + * Gets the currently selected proof text. + * + * @return the selected `CProveText` object + */ public CProveText getSelect() { return pselect; } + /** + * Undoes the proof steps to the head. + * + * @param dp the `DrawProcess` context + * @return true if the undo operation was successful + */ public boolean undo_to_head(DrawProcess dp) { if (HEAD) { if (vlist.size() == 0) return false; @@ -324,6 +255,12 @@ public boolean undo_to_head(DrawProcess dp) { return true; } + /** + * Runs the proof steps to the beginning. + * + * @param dp the `DrawProcess` context + * @return true if the operation was successful + */ public boolean run_to_begin(DrawProcess dp) { if (HEAD) { // if (vlist.size() == 0) return false; @@ -362,6 +299,12 @@ public boolean run_to_begin(DrawProcess dp) { return true; } + /** + * Undoes the default action for the proof steps. + * + * @param dp the `DrawProcess` context + * @return true if the undo operation was successful + */ public boolean undo_default(DrawProcess dp) { if (HEAD) { if (vlist.size() == 0) return false; @@ -390,6 +333,12 @@ public boolean undo_default(DrawProcess dp) { return true; } + /** + * Runs the proof to the end. + * + * @param dp the `DrawProcess` context + * @return true if the operation was successful + */ public boolean run_to_end(DrawProcess dp) { while (true) { if (!this.next_prove_step(dp)) { @@ -398,22 +347,12 @@ public boolean run_to_end(DrawProcess dp) { } } - - public void reGenerateAll() { - if (HEAD) - this.reGenerateIndex(); - - for (int i = 0; i < clist.size(); i++) { - CProveText cp = (CProveText) clist.get(i); - cp.regenerateAll(); - } - - for (int i = 0; i < vlist.size(); i++) { - CProveText cp = (CProveText) vlist.get(i); - cp.regenerateAll(); - } - } - + /** + * Redoes the invisible head step for the proof. + * + * @param dp the `DrawProcess` context + * @return the `CProveText` object that was redone, or null if none was found + */ public CProveText redo_invisible_head(DrawProcess dp) { if (vlist.size() == 0) return null; CProveText ct = (CProveText) vlist.get(0); @@ -424,10 +363,12 @@ public CProveText redo_invisible_head(DrawProcess dp) { return null; } - public void resetStep() { - rstep = rmid; - } - + /** + * Advances to the next proof step. + * + * @param dp the `DrawProcess` context + * @return true if the operation was successful + */ public boolean next(DrawProcess dp) { CProveText ct = fd_text(++this.rstep); if (ct != null) { @@ -442,6 +383,12 @@ public boolean next(DrawProcess dp) { return true; } + /** + * Finds the `CProveText` object at the specified index. + * + * @param index the index to search for + * @return the `CProveText` object at the specified index, or null if none was found + */ public CProveText fd_text(int index) { for (int i = 0; i < clist.size(); i++) { CProveText cp = (CProveText) clist.get(i); @@ -457,6 +404,9 @@ public CProveText fd_text(int index) { return null; } + /** + * Sets the default step row for the proof steps. + */ public void setStepRowDefault() { for (int i = 0; i < clist.size(); i++) { CProveText cp = (CProveText) clist.get(i); @@ -469,6 +419,12 @@ public void setStepRowDefault() { } } + /** + * Advances to the next proof step. + * + * @param dp the `DrawProcess` context + * @return true if the operation was successful + */ public boolean next_prove_step(DrawProcess dp) { if (HEAD) { CBoolean find = new CBoolean(false); @@ -489,7 +445,12 @@ public boolean next_prove_step(DrawProcess dp) { return true; } - + /** + * Sets the selected undo step for the proof. + * + * @param u the `UndoStruct` object to set + * @param dp the `DrawProcess` context + */ public void setSelectedUndo(UndoStruct u, DrawProcess dp) { CProveText ct = pselect = findPText(u); Vector vl = new Vector(); @@ -503,6 +464,12 @@ public void setSelectedUndo(UndoStruct u, DrawProcess dp) { } } + /** + * Finds the `CProveText` object for the specified undo structure. + * + * @param un the `UndoStruct` object to search for + * @return the `CProveText` object for the specified undo structure, or null if none was found + */ public CProveText findPText(UndoStruct un) { if (un == null) return null; @@ -530,7 +497,14 @@ public CProveText findPText(UndoStruct un) { return null; } - + /** + * Advances to the next proof step. + * + * @param dp the `DrawProcess` context + * @param cpt the current `CProveText` object + * @param find a boolean indicating whether the step was found + * @return the next `CProveText` object, or null if none was found + */ public CProveText next_prove_step(DrawProcess dp, CProveText cpt, CBoolean find) { for (int i = 0; i < clist.size(); i++) { @@ -549,7 +523,12 @@ public CProveText next_prove_step(DrawProcess dp, CProveText cpt, CBoolean find) return null; } - + /** + * Draws the proof steps. + * + * @param g2 the `Graphics2D` context to draw on + * @param p the current position to draw at + */ public void draw(Graphics2D g2, Point p) { int dx = (int) p.getX(); int dy = (int) p.getY(); @@ -631,10 +610,23 @@ public void draw(Graphics2D g2, Point p) { } } + /** + * Moves the proof steps by the specified x and y coordinates. + * + * @param x the x-coordinate to move by + * @param y the y-coordinate to move by + */ public void move(double x, double y) { pt.setLocation(pt.getX() + (int) x, pt.getY() + (int) y); } + /** + * Handles mouse movement events and returns the `CProveText` object at the specified coordinates. + * + * @param x the x-coordinate of the mouse + * @param y the y-coordinate of the mouse + * @return the `CProveText` object at the specified coordinates, or null if none is found + */ public CProveText mouseMove(double x, double y) { CProveText fd = null; for (int i = 0; i < clist.size(); i++) { @@ -654,6 +646,14 @@ public CProveText mouseMove(double x, double y) { return fd; } + /** + * Selects the `CProveText` object at the specified coordinates. + * + * @param x the x-coordinate of the selection + * @param y the y-coordinate of the selection + * @param on_select a boolean indicating whether the selection is active + * @return the selected `CProveText` object, or null if none is found + */ public CProveText select(double x, double y, boolean on_select) { CProveText sel = null; @@ -683,14 +683,9 @@ public CProveText select(double x, double y, boolean on_select) { return sel; } - public void expandProveNode(double x, double y) { - CProveText cpt = this.select(x, y, true); - - if (cpt != null) { - cpt.expand(); - } - } - + /** + * Clears the selection of all `CProveText` objects. + */ public void clearSelection() { for (int i = 0; i < clist.size(); i++) { CProveText ct = (CProveText) clist.get(i); @@ -704,6 +699,13 @@ public void clearSelection() { } + /** + * Draws a single step of the proof for the specified `CProveText` object. + * + * @param cp the `CProveText` object to draw + * @param p the current position to draw at + * @param g2 the `Graphics2D` context to draw on + */ public void drawAStep(CProveText cp, Point p, Graphics2D g2) { if (!cp.getVisible()) return; @@ -723,13 +725,13 @@ public void drawAStep(CProveText cp, Point p, Graphics2D g2) { } } - public void removeNode(Vector v) { - } - - public boolean removeLast() { - return true; - } - + /** + * Saves the proof text as a PostScript file. + * + * @param fp the `FileOutputStream` to write to + * @param stype the type of save operation + * @throws IOException if an I/O error occurs + */ public void SavePS(FileOutputStream fp, int stype) throws IOException { if (HEAD) { fp.write("%draw proof text\n".getBytes()); @@ -765,7 +767,14 @@ public void SavePS(FileOutputStream fp, int stype) throws IOException { } - /////////////////////////////////////////////////////////// + /** + * Saves the proof text to a `DataOutputStream`. + * + * @param out the `DataOutputStream` to write to + * @param space the amount of space to use for formatting + * @return true if the save operation was successful + * @throws IOException if an I/O error occurs + */ public boolean saveText(DataOutputStream out, int space) throws IOException { if (HEAD) { for (int i = 0; i < vlist.size(); i++) { @@ -782,6 +791,12 @@ public boolean saveText(DataOutputStream out, int space) throws IOException { return true; } + /** + * Saves the state of the `CProveField` to a `DataOutputStream`. + * + * @param out the `DataOutputStream` to write to + * @throws IOException if an I/O error occurs + */ public void Save(DataOutputStream out) throws IOException { out.writeBoolean(HEAD); @@ -806,6 +821,13 @@ public void Save(DataOutputStream out) throws IOException { } + /** + * Loads the state of the `CProveField` from a `DataInputStream`. + * + * @param in the `DataInputStream` to read from + * @param dp the `DrawProcess` context + * @throws IOException if an I/O error occurs + */ public void Load(DataInputStream in, DrawProcess dp) throws IOException { HEAD = in.readBoolean(); @@ -835,6 +857,4 @@ public void Load(DataInputStream in, DrawProcess dp) throws IOException { int py = in.readInt(); pt = new Point(px, py); } - - } diff --git a/src/main/java/wprover/CProveText.java b/src/main/java/wprover/CProveText.java index 0f696fea..da236a34 100644 --- a/src/main/java/wprover/CProveText.java +++ b/src/main/java/wprover/CProveText.java @@ -11,11 +11,8 @@ import java.util.Vector; /** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2005-8-23 - * Time: 21:54:51 - * To change this template use File | Settings | File Templates. + * CProveText is a class that represents a proof text in a graphical user interface. + * It contains methods for drawing the text, handling mouse events, and saving/loading data. */ public class CProveText { final private static int HSpace = 4; @@ -54,51 +51,77 @@ public class CProveText { private String bidx = ""; - - public static void setArrowImage(Image ico) { - arrow = ico; - } - - public static void setDrawPanel(JPanel panel) { - d = panel; - } - + /** + * Sets the expanded state of the proof text. + * + * @param exp true to expand, false to collapse + */ public void setExpanded(boolean exp) { isexpand = exp; } + /** + * Checks if the proof text is expanded. + * + * @return true if expanded, false otherwise + */ public boolean isExpanded() { return isexpand; } + /** + * Retrieves the condition associated with this proof text. + * + * @return the condition + */ public Cond getcond() { return m_co; } + /** + * Default constructor for the CProveText class. + */ public CProveText() { } + /** + * Resets the row counter to zero. + */ public static void resetRow() { D_ROW = 0; } + /** + * Retrieves the current row counter value. + * + * @return the current row counter value + */ public static int getRow() { return D_ROW; } + /** + * Constructor for the CProveText class with specified header and message. + * + * @param s1 the header text + * @param s2 the message text + */ public CProveText(String s1, String s2) { - // objlist = new Vector(); rule = ""; rpath = ""; font = new Font("Dialog", Font.PLAIN, 14); head = s1; msg = s2; - } + /** + * Constructor for the CProveText class with an undo structure and header. + * + * @param un the undo structure + * @param s the header text + */ public CProveText(UndoStruct un, String s) { - // objlist = new Vector(); rule = ""; rpath = ""; font = new Font("Dialog", Font.PLAIN, 14); @@ -106,11 +129,16 @@ public CProveText(UndoStruct un, String s) { msg = un.msg; if (un.m_type == UndoStruct.T_COMBINED_NODE || (un.m_type == UndoStruct.T_PROVE_NODE) && un.childundolist.size() > 0) { cpfield = new CProveField(un.childundolist); - cmsg = cchid;//new Color(34,100,0); + cmsg = cchid; } m_undo = un; } + /** + * Constructor for the CProveText class with a specified message. + * + * @param s the message text + */ public CProveText(String s) { rule = ""; rpath = ""; @@ -119,19 +147,26 @@ public CProveText(String s) { msg = s; } - + /** + * Constructor for the CProveText class with a condition and header. + * + * @param co the condition + * @param s the header text + */ public CProveText(Cond co, String s) { - // objlist = new Vector(); rule = ""; rpath = ""; font = new Font("Dialog", Font.PLAIN, 14); head = s; msg = co.getText(); - //m_undo = un; } + /** + * Constructor for the CProveText class with an undo structure. + * + * @param un the undo structure + */ public CProveText(UndoStruct un) { - // objlist = new Vector(); rule = ""; rpath = ""; font = new Font("Dialog", Font.PLAIN, 14); @@ -139,14 +174,21 @@ public CProveText(UndoStruct un) { msg = un.msg; if (un.m_type == UndoStruct.T_COMBINED_NODE || (un.m_type == UndoStruct.T_PROVE_NODE) && un.childundolist.size() > 0) { cpfield = new CProveField(un.childundolist); - cmsg = cchid;//new Color(34,100,0); + cmsg = cchid; } m_undo = un; } + /** + * Constructor for the CProveText class with a vector, condition, index, and a boolean flag. + * + * @param vl the vector + * @param co the condition + * @param index the index + * @param gc the boolean flag + */ public CProveText(Vector vl, Cond co, int index, boolean gc) { m_co = co; - rule = ""; rpath = ""; font = new Font("Dialog", Font.PLAIN, 14); @@ -208,7 +250,6 @@ public CProveText(Vector vl, Cond co, int index, boolean gc) { } if (nco > 1) { - //dix += ")"; bidx = " " + dix; msg += bidx; } @@ -217,6 +258,12 @@ public CProveText(Vector vl, Cond co, int index, boolean gc) { } } + /** + * Constructor for the CProveText class with an undo structure and index. + * + * @param un the undo structure + * @param index the index + */ public CProveText(UndoStruct un, int index) { rule = ""; rpath = ""; @@ -224,104 +271,212 @@ public CProveText(UndoStruct un, int index) { head = (index + 1) + ": "; msg = un.msg; if (un.m_type == UndoStruct.T_COMBINED_NODE || (un.m_type == UndoStruct.T_PROVE_NODE) && un.childundolist.size() > 0) { - cpfield = new CProveField(un.childundolist); - cmsg = cchid;//new Color(34,100,0); + cmsg = cchid; } m_undo = un; } + /** + * Sets the font size for the proof text. + * + * @param size the font size to set + */ public void setFontSize(int size) { font = new Font(font.getName(), font.getStyle(), size); if (cpfield != null) cpfield.setFontSize(size); } - + /** + * Sets the index for the proof text. + * + * @param index the index to set + */ public void setIndex(int index) { head = (index + 1) + ": "; if (cpfield != null) cpfield.reGenerateIndex(); } + /** + * Sets the visibility of the proof text. + * + * @param v true to make visible, false to hide + */ public void setVisible(boolean v) { visible = v; } + /** + * Checks if the proof text is visible. + * + * @return true if visible, false otherwise + */ public boolean getVisible() { return visible; } + /** + * Retrieves the undo structure associated with this proof text. + * + * @return the undo structure + */ public UndoStruct getUndoStruct() { return m_undo; } + /** + * Retrieves the rectangle representing the bounds of this proof text. + * + * @return the rectangle representing the bounds + */ public Rectangle getRectangle() { return new Rectangle((int) x, (int) y, (int) w, (int) height); } + /** + * Retrieves the color of the caption. + * + * @return the caption color + */ public Color getCaptainColor() { return chead; } + /** + * Sets the rule associated with this proof text. + * + * @param r the rule to set + */ public void setRule(String r) { rule = r; } + /** + * Retrieves the rule associated with this proof text. + * + * @return the rule + */ public String getRule() { return rule; } + /** + * Sets the path to the rule file. + * + * @param path the path to set + */ public void setRulePath(String path) { rpath = path; } + /** + * Retrieves the path to the rule file. + * + * @return the rule path + */ public String getRulePath() { return rpath; } + /** + * Sets the color of the caption. + * + * @param c the color to set + */ public void setCaptainColor(Color c) { chead = c; } + /** + * Retrieves the color of the message. + * + * @return the message color + */ public Color getMessageColor() { return cmsg; } + /** + * Sets the color of the message. + * + * @param c the color to set + */ public void setMessageColor(Color c) { cmsg = c; } + /** + * Retrieves the font used for the proof text. + * + * @return the font + */ public Font getFont() { return font; } + /** + * Sets the font used for the proof text. + * + * @param f the font to set + */ public void setFont(Font f) { font = f; } + /** + * Retrieves the header text. + * + * @return the header text + */ public String getHead() { return head; } + /** + * Sets the header text. + * + * @param s the header text to set + */ public void setHead(String s) { head = s; } + /** + * Retrieves the message text. + * + * @return the message text + */ public String getMessage() { return msg; } + /** + * Sets the message text. + * + * @param s the message text to set + */ public void setMessage(String s) { msg = s + " " + this.bidx; } + /** + * Retrieves the list of objects associated with the undo structure. + * + * @return the list of objects + */ public Vector getObjectList() { if (m_undo == null) return new Vector(); return m_undo.objectlist; } + /** + * Sets the list of objects associated with the undo structure. + * + * @param v the list of objects to set + */ public void setObjectList(Vector v) { if (m_undo != null) { m_undo.objectlist.clear(); @@ -329,52 +484,78 @@ public void setObjectList(Vector v) { } } + /** + * Sets the width of the proof text. + * + * @param ww the width to set + */ public void setWidth(double ww) { width = ww; } + /** + * Retrieves the width of the proof text. + * + * @return the width + */ public double getWidth() { return w; } - public double getHeadLength() { - return whead; - } - + /** + * Sets the x and y coordinates of the proof text. + * + * @param x the x-coordinate to set + * @param y the y-coordinate to set + */ public void setXY(double x, double y) { this.x = x; this.y = y; } + /** + * Retrieves the type string of the proof text. + * + * @return the type string + */ public String TypeString() { return "proof text"; } + /** + * Retrieves the description of the proof text. + * + * @return the description + */ public String getDescription() { return this.TypeString(); } + /** + * Selects the child proof text at the given coordinates. + * + * @param x1 the x-coordinate to check + * @param y1 the y-coordinate to check + * @param onselect a boolean indicating whether to select the child + * @return the selected child proof text, or null if not found + */ public CProveText selectChild(double x1, double y1, boolean onselect) { if (cpfield != null) return cpfield.select(x1, y1, onselect); return null; } + /** + * Clears the selection of the proof text. + */ public void clearSelection() { if (cpfield != null) cpfield.clearSelection(); } - public void expandAll() { - if (this.isexpand) - this.setExpanded(false); - else - this.setExpanded(true); - - if (cpfield != null) - cpfield.expandAll(); - } - + /** + * Expands or collapses the proof text. + */ public void expand() { if (this.isexpand) this.setExpanded(false); @@ -382,6 +563,12 @@ public void expand() { this.setExpanded(true); } + /** + * Redoes the invisible head of the proof text in the draw process. + * + * @param dp the draw process + * @return the proof text with the redone invisible head + */ public CProveText redo_invisible_head(DrawProcess dp) { if (cpfield == null) return this; if (!this.isexpand) return this; @@ -393,12 +580,12 @@ public CProveText redo_invisible_head(DrawProcess dp) { return ct; } - public void regenerateAll() { - if (m_undo != null) { - this.msg = m_undo.msg; - } - } - + /** + * Retrieves the list of flash objects associated with the proof text. + * + * @param v the list to populate with flash objects + * @param dp the draw process + */ public void getFlashObjectList(Vector v, DrawProcess dp) { if (m_undo.m_type != UndoStruct.T_PROVE_NODE) { v.addAll(m_undo.getAllObjects(dp)); @@ -411,12 +598,12 @@ public void getFlashObjectList(Vector v, DrawProcess dp) { v.addAll(m_undo.getAllObjects(dp)); } -// public CProveText next(drawProcess dp) -// { -// - -// } - + /** + * Finds the proof text associated with the given undo structure. + * + * @param un the undo structure to find the proof text for + * @return the proof text associated with the undo structure, or null if not found + */ public CProveText findPText(UndoStruct un) { if (un == null) return null; @@ -428,9 +615,15 @@ public CProveText findPText(UndoStruct un) { return cpfield.findPText(un); } - + /** + * Finds the next proof step in the draw process. + * + * @param dp the draw process + * @param cpt the current proof text + * @param find a boolean indicating whether the proof step has been found + * @return the next proof step, or null if not found + */ public CProveText next_prove_step(DrawProcess dp, CProveText cpt, CBoolean find) { - if (find.getValue() == false) { if (cpt == this) { find.setValue(true); @@ -447,21 +640,24 @@ public CProveText next_prove_step(DrawProcess dp, CProveText cpt, CBoolean find) } } else { if (this.visible) { - if (!this.isexpand || m_undo.m_type == UndoStruct.T_UNDO_NODE)//||m_undo.m_type ==UndoStruct.T_COMBINED_NODE) - { -// dp.redo_step(m_undo); + if (!this.isexpand || m_undo.m_type == UndoStruct.T_UNDO_NODE) { + // dp.redo_step(m_undo); } return this; } else { - { -// dp.redo_step(m_undo); - } + // dp.redo_step(m_undo); return null; } - } } + /** + * Checks if the given coordinates are within the bounds of the proof text. + * + * @param x1 the x-coordinate to check + * @param y1 the y-coordinate to check + * @return true if the coordinates are within the bounds, false otherwise + */ public boolean select(double x1, double y1) { double dx = x1 - x; double dy = y1 - y; @@ -472,10 +668,22 @@ public boolean select(double x1, double y1) { return false; } + /** + * Gets the location for the pop-up menu. + * + * @return the location for the pop-up menu + */ public Point getPopExLocation() { return new Point((int) (ax + 16), (int) (ay + 16)); } + /** + * Handles mouse movement events. + * + * @param x the x-coordinate of the mouse + * @param y the y-coordinate of the mouse + * @return the proof text if the mouse is on the arrow, or null otherwise + */ public CProveText mouseMove(double x, double y) { if (!visible) return null; @@ -490,6 +698,13 @@ public CProveText mouseMove(double x, double y) { return null; } + /** + * Selects all proof texts at the given coordinates. + * + * @param x1 the x-coordinate to check + * @param y1 the y-coordinate to check + * @return the selected proof text, or null if not found + */ public CProveText selectAll(double x1, double y1) { if (this.select(x1, y1)) return this; @@ -499,30 +714,42 @@ public CProveText selectAll(double x1, double y1) { return null; } + /** + * Moves the proof text by the given offsets. + * + * @param dx the x-offset to move by + * @param dy the y-offset to move by + */ public void move(double dx, double dy) { x = x + (int) dx; y = y + (int) dy; } - + /** + * Sets the current position of the proof text. + * + * @param p the point to set the position to + */ public void setCurrentPosition(Point p) { x = p.x; y = p.y; } - + /** + * Gets the next position for the proof text. + * + * @param p the point to set the next position to + */ public void getNextPosition(Point p) { p.setLocation((int) x, (int) (y + height)); } - public Point getNextPositionFromFirstNode() { - return new Point((int) (x + whead), (int) (y + height)); - } - - public double getHeadwidth() { - return whead; - } - + /** + * Runs the proof text to the beginning of the draw process. + * + * @param dp the draw process + * @return true if successful, false otherwise + */ public boolean run_to_begin(DrawProcess dp) { if (m_undo == null) return false; if (cpfield != null) @@ -532,6 +759,12 @@ else if (m_undo.m_type == UndoStruct.T_UNDO_NODE || m_undo.m_type == UndoStruct. return true; } + /** + * Undoes the default action for the proof text. + * + * @param dp the draw process + * @return true if successful, false otherwise + */ public boolean undo_default(DrawProcess dp) { if (m_undo == null) return false; if (cpfield != null) @@ -541,6 +774,12 @@ public boolean undo_default(DrawProcess dp) { return true; } + /** + * Undoes the proof text to the head of the draw process. + * + * @param dp the draw process + * @return true if successful, false otherwise + */ public boolean undo_to_head(DrawProcess dp) { if (m_undo == null) return false; if (cpfield != null) @@ -550,6 +789,12 @@ public boolean undo_to_head(DrawProcess dp) { return true; } + /** + * Draws the proof text with the given selection state. + * + * @param g2 the graphics context + * @param selected true if the proof text is selected, false otherwise + */ public void draw(Graphics2D g2, boolean selected) { if (selected == false) this.draw(g2); @@ -563,12 +808,24 @@ public void draw(Graphics2D g2, boolean selected) { } } + /** + * Draws the child proof text at the given point. + * + * @param g2 the graphics context + * @param p the point to draw the child proof text at + */ public void drawChild(Graphics2D g2, Point p) { if (cpfield != null) { cpfield.draw(g2, p); } } + /** + * Finds the proof text with the given row index. + * + * @param i the row index to find the proof text for + * @return the proof text with the given row index, or null if not found + */ public CProveText fd_text(int i) { if (i == this.m_row) return this; @@ -577,12 +834,20 @@ public CProveText fd_text(int i) { else return null; } + /** + * Sets the step row to the default value. + */ public void setStepRowDefault() { this.m_row = -1; if (cpfield != null) cpfield.setStepRowDefault(); } + /** + * Draws the proof text. + * + * @param g2 the graphics context + */ public void draw(Graphics2D g2) { if (head == null) return; m_row = D_ROW++; @@ -603,7 +868,6 @@ public void draw(Graphics2D g2) { whead = w = tw; if (msg == null || msg.length() == 0) return; - g2.setColor(cmsg); String[] sl = msg.split("\n"); double start = x + tw + HSpace; @@ -625,10 +889,15 @@ public void draw(Graphics2D g2) { g2.drawImage(arrow, (int) (ax), (int) (ay), Color.pink, d); } else g2.drawImage(arrow, (int) ax, (int) ay, d); - } - ////////////////////////////////////////////////////////////////////////// + /** + * Saves the text representation of the proof to the specified data output stream. + * + * @param out the data output stream to write to + * @param space the number of spaces to indent the text + * @throws IOException if an I/O error occurs + */ public void saveText(DataOutputStream out, int space) throws IOException { if (m_undo.m_type == UndoStruct.T_TO_PROVE_NODE || m_undo.m_type == UndoStruct.T_PROVE_NODE) { if (msg != null && msg.length() != 0) { @@ -643,11 +912,17 @@ public void saveText(DataOutputStream out, int space) throws IOException { if (cpfield != null) cpfield.saveText(out, space + 5); } - } - public void SavePS(FileOutputStream fp, int stype, int ntype) throws IOException // 0 0. 1 20. 2 25. - { + /** + * Saves the proof text as a PostScript file. + * + * @param fp the file output stream to write to + * @param stype the style type (0 for color, 1 for gray, 2 for black & white) + * @param ntype the number type (0 for default, 1 for 20 added, 2 for 25 added) + * @throws IOException if an I/O error occurs + */ + public void SavePS(FileOutputStream fp, int stype, int ntype) throws IOException { if (visible == false) return; if (head == null) return; @@ -683,33 +958,52 @@ else if (ntype == 2) cpfield.SavePS(fp, stype); } + /** + * Sets the PostScript color based on the given color and style type. + * + * @param c the color to set + * @param fp the file output stream to write to + * @param stype the style type (0 for color, 1 for gray, 2 for black & white) + * @throws IOException if an I/O error occurs + */ public void SavePsColor(Color c, FileOutputStream fp, int stype) throws IOException { - if (stype == 0) //color - { + if (stype == 0) { // color double r = ((double) (100 * c.getRed() / 255)) / 100; double g = ((double) (100 * c.getGreen() / 255)) / 100; double b = ((double) (100 * c.getBlue() / 255)) / 100; String s = r + " " + r + " " + r; s += " setrgbcolor "; fp.write(s.getBytes()); - } else if (stype == 1) //gray - { + } else if (stype == 1) { // gray String s = ""; double gray = (int) ((0.11 * c.getRed() + 0.59 * c.getGreen() + 0.3 * c.getBlue()) / 2.55) / 100.0; s += " " + gray + " " + gray + " " + gray + " setrgbcolor "; fp.write(s.getBytes()); - } else if (stype == 2) // black & white - { + } else if (stype == 2) { // black & white String s = "0.0 0.0 0.0 setrgbcolor "; fp.write(s.getBytes()); } } + /** + * Writes a string to the specified data output stream. + * + * @param out the data output stream to write to + * @param s the string to write + * @throws IOException if an I/O error occurs + */ public void WriteString(DataOutputStream out, String s) throws IOException { out.writeInt(s.length()); out.writeChars(s); } + /** + * Writes a font to the specified data output stream. + * + * @param out the data output stream to write to + * @param f the font to write + * @throws IOException if an I/O error occurs + */ public void WriteFont(DataOutputStream out, Font f) throws IOException { String s = f.getName(); WriteString(out, s); @@ -717,6 +1011,13 @@ public void WriteFont(DataOutputStream out, Font f) throws IOException { out.writeInt(f.getSize()); } + /** + * Reads a string from the specified data input stream. + * + * @param in the data input stream to read from + * @return the string read from the input stream + * @throws IOException if an I/O error occurs + */ public String ReadString(DataInputStream in) throws IOException { int size = in.readInt(); if (size == 0) return new String(""); @@ -726,15 +1027,27 @@ public String ReadString(DataInputStream in) throws IOException { return s; } + /** + * Reads a font from the specified data input stream. + * + * @param in the data input stream to read from + * @return the font read from the input stream + * @throws IOException if an I/O error occurs + */ public Font ReadFont(DataInputStream in) throws IOException { String name = ReadString(in); int stye = in.readInt(); int size = in.readInt(); return new Font(name, stye, size); - } + /** + * Saves the proof text data to the specified data output stream. + * + * @param out the data output stream to write to + * @throws IOException if an I/O error occurs + */ public void Save(DataOutputStream out) throws IOException { this.WriteString(out, head); this.WriteString(out, msg); @@ -764,11 +1077,16 @@ public void Save(DataOutputStream out) throws IOException { out.writeBoolean(true); out.writeInt(m_undo.m_id); } - } + /** + * Loads the proof text data from the specified data input stream. + * + * @param in the data input stream to read from + * @param dp the draw process + * @throws IOException if an I/O error occurs + */ public void Load(DataInputStream in, DrawProcess dp) throws IOException { - head = this.ReadString(in); msg = this.ReadString(in); if (CMisc.version_load_now >= 0.033) diff --git a/src/main/java/wprover/CStyleDialog.java b/src/main/java/wprover/CStyleDialog.java index bf23bd17..04305d2e 100644 --- a/src/main/java/wprover/CStyleDialog.java +++ b/src/main/java/wprover/CStyleDialog.java @@ -8,6 +8,10 @@ import java.awt.*; import java.util.Vector; +/** + * CStyleDialog is a class that creates a dialog for selecting drawing styles, including color, + * line width, and line type. It is used in the GExpert application. + */ public class CStyleDialog extends FloatableToolBar { public static int CELLWIDTH = 60; int action = -1; @@ -34,6 +38,13 @@ public class CStyleDialog extends FloatableToolBar { JPanel pagColor = null; JPanel topAgPanel = null; + /** + * Constructor for the CStyleDialog class. + * Initializes the dialog with the given GExpert and DPanel instances. + * + * @param gx the GExpert instance + * @param d the DPanel instance + */ public CStyleDialog(GExpert gx, DPanel d) { this.gxInstance = gx; this.d = d; @@ -47,6 +58,9 @@ public CStyleDialog(GExpert gx, DPanel d) { this.add(pcs); } + /** + * Resets the drawing style panels to the current drawing data indices. + */ public void reset() { rColor.index = DrawData.cindex; rStyle.index = DrawData.dindex; @@ -55,10 +69,19 @@ public void reset() { pgColor.index = DrawData.polygoncolor; } - public void setAction(int actionType) ////-1. ByPass Action; 0. defalut; - // 1. Draw Action + point; 2: draw action line + circle - // 3: fill action 4: angle 5: move/select/intersect - { + /** + * Sets the action type for the dialog and updates the layout accordingly. + * + * @param actionType the action type to set + * -1: ByPass Action + * 0: Default + * 1: Draw Action + point + * 2: Draw Action line + circle + * 3: Fill Action + * 4: Angle + * 5: Move/Select/Intersect + */ + public void setAction(int actionType) { reset(); if (actionType == action) return; @@ -101,24 +124,31 @@ public void reset() { case 4: this.removeAll(); this.add(mpanel); - + this.add(pColor); this.add(pStyle); this.add(pWidth); break; default: break; - } this.pack(); } + /** + * Returns the preferred size of the dialog. + * + * @return the preferred size of the dialog + */ public Dimension getPreferredSize() { Dimension dm = super.getPreferredSize(); return dm; } - + /** + * This class is used to create a panel for selecting color, line width, and line type. + * It extends the JPanel class and implements ActionListener to handle action events. + */ class Panel_CS extends JPanel implements ActionListener { DPanel d; @@ -178,7 +208,10 @@ public void paintComponent(Graphics g) { } } - + /** + * This class is used to handle the rendering of the color, line width, and line type + * selection. It extends the JPanel class and implements MouseListener to handle mouse events. + */ class DrawStylePanel extends JPanel implements MouseListener { JLabel label; PopComboRender selector; @@ -287,7 +320,10 @@ public void mouseExited(MouseEvent e) { } } - + /** + * This class is used to handle the rendering of the color, line width, and line type + * selection. It extends the JPanel class and implements MouseListener to handle mouse events. + */ class PopComboRender extends JPanel implements MouseListener { Vector vlist = new Vector(); @@ -355,6 +391,11 @@ public void mouseExited(MouseEvent e) { } } + /** + * This class is used to handle the rendering of the color, line width, and line type + * selection. It extends the ColorComboRender class and implements MouseListener to handle + * mouse events. + */ class PopComboRenderCell extends ColorComboRender implements MouseListener { public PopComboRenderCell(int type, int w, int h) { super(type, w, h); @@ -388,9 +429,11 @@ public void mouseExited(MouseEvent e) { } } - //////////// - /////////////////////////////////////////////////////////////// - + /** + * This class is used to handle the rendering of the color, line width, and line type + * selection. It extends the PopComboRender class and overrides the mousePressed method to + * set the selected index for the corresponding style. + */ class GeneralPopComboRender extends PopComboRender { public GeneralPopComboRender(int type) { super(type); @@ -418,6 +461,11 @@ public void mousePressed(MouseEvent e) { } } + /** + * This class is used to handle the rendering of the polygon fill color selection. + * It extends the PopComboRender class and overrides the mousePressed method to + * set the polygon color when a color is selected. + */ class PolygonFillPopComboRender extends PopComboRender { public PolygonFillPopComboRender(int type) { super(type); @@ -434,41 +482,4 @@ public void mousePressed(MouseEvent e) { pgColor.index = idx; } } - - class AngleFillPopComboRender extends PopComboRender { - public AngleFillPopComboRender(int type) { - super(type); - } - - public void mousePressed(MouseEvent e) { - super.mousePressed(e); - PopComboRenderCell c = (PopComboRenderCell) e.getSource(); - int t = c.type; - int idx = c.index; - DrawData.polygoncolor = idx; - if (pgColor != null) - pgColor.index = idx; - } - } - - class AnglePropertyPanel extends JPanel implements ActionListener { - JComboBox boxType; - - public AnglePropertyPanel() { - this.setLayout(new FlowLayout(FlowLayout.LEFT)); - - Vector v = new Vector(); - v.add("Without Arrow"); - v.add("With Arrow"); - v.add("Multiple Arc"); - v.add("Fill"); - boxType = new JComboBox(v); - this.add(boxType); - boxType.addActionListener(AnglePropertyPanel.this); - } - - public void actionPerformed(ActionEvent e) { - } - } - } diff --git a/src/main/java/wprover/CTMark.java b/src/main/java/wprover/CTMark.java index 15fd9475..9d85b6a1 100644 --- a/src/main/java/wprover/CTMark.java +++ b/src/main/java/wprover/CTMark.java @@ -6,6 +6,10 @@ import java.io.DataOutputStream; import java.io.DataInputStream; +/** + * CTMark is a class that represents a mark on a drawing, defined by two lines. + * It provides methods for drawing the mark, moving it, and saving/loading its state. + */ public class CTMark extends CClass { CLine ln1, ln2; @@ -17,7 +21,9 @@ public class CTMark extends CClass { int pos1x, pos1y, pos2x, pos2y; int pos3x, pos3y, pos4x, pos4y; - + /** + * Default constructor for CTMark. + */ public CTMark() { super(TMARK); m_color = 3; @@ -25,6 +31,12 @@ public CTMark() { m_color = DrawData.RED; } + /** + * Constructs a CTMark with two lines. + * + * @param ln1 the first line + * @param ln2 the second line + */ public CTMark(CLine ln1, CLine ln2) { super(TMARK); @@ -34,18 +46,39 @@ public CTMark(CLine ln1, CLine ln2) { this.ln2 = ln2; } + /** + * Returns the type string of the mark. + * + * @return the type string + */ public String TypeString() { return null; } + /** + * Returns the description of the mark. + * + * @return the description + */ public String getDescription() { return null; } + /** + * Draws the mark using the specified Graphics2D object. + * + * @param g2 the Graphics2D object + */ public void draw(Graphics2D g2) { draw(g2, false); } + /** + * Moves the mark by the specified delta values. + * + * @param dx the delta x value + * @param dy the delta y value + */ void move(double dx, double dy) { double r[] = CLine.Intersect(ln1, ln2); if (r == null || r.length == 0) @@ -64,6 +97,12 @@ else if (len > 10 && len < 40) length = len; } + /** + * Draws the mark using the specified Graphics2D object, with an option to select it. + * + * @param g2 the Graphics2D object + * @param selected whether the mark is selected + */ public void draw(Graphics2D g2, boolean selected) { if (!isdraw()) return; @@ -84,11 +123,25 @@ public void draw(Graphics2D g2, boolean selected) { } } + /** + * Selects the mark based on the specified coordinates. + * + * @param x the x coordinate + * @param y the y coordinate + * @return true if the mark is selected, false otherwise + */ boolean select(double x, double y) { boolean xr = Math.pow(tx - x, 2) + Math.pow(ty - y, 2) < CMisc.PIXEPS * CMisc.PIXEPS; return xr; } + /** + * Saves the mark to a PostScript file. + * + * @param fp the FileOutputStream to write to + * @param stype the stroke type + * @throws IOException if an I/O error occurs + */ public void SavePS(FileOutputStream fp, int stype) throws IOException { if (!visible) return; @@ -101,6 +154,16 @@ public void SavePS(FileOutputStream fp, int stype) throws IOException { } + /** + * Draws the TTFoot mark using the specified Graphics2D object. + * + * @param g2 the Graphics2D object + * @param x the x coordinate + * @param y the y coordinate + * @param p1 the first point + * @param p2 the second point + * @param select whether the mark is selected + */ public void drawTTFoot(Graphics2D g2, double x, double y, CPoint p1, CPoint p2, boolean select) { if (p1 == null || p2 == null) return; @@ -149,7 +212,12 @@ public void drawTTFoot(Graphics2D g2, double x, double y, CPoint p1, CPoint p2, pos4y = (int) (ey); } - + /** + * Saves the mark to a DataOutputStream. + * + * @param out the DataOutputStream to write to + * @throws IOException if an I/O error occurs + */ public void Save(DataOutputStream out) throws IOException { super.Save(out); out.writeInt(ln1.m_id); @@ -157,6 +225,13 @@ public void Save(DataOutputStream out) throws IOException { out.writeInt(length); } + /** + * Loads the mark from a DataInputStream. + * + * @param in the DataInputStream to read from + * @param dp the DrawProcess used for loading + * @throws IOException if an I/O error occurs + */ public void Load(DataInputStream in, DrawProcess dp) throws IOException { super.Load(in, dp); int d = in.readInt(); diff --git a/src/main/java/wprover/CText.java b/src/main/java/wprover/CText.java index 98806062..7e60549f 100644 --- a/src/main/java/wprover/CText.java +++ b/src/main/java/wprover/CText.java @@ -10,11 +10,8 @@ import java.io.FileOutputStream; /** - * Created by IntelliJ IDEA. - * User: Administrator - * Date: 2005-1-26 - * Time: 15:29:29 - * To change this template use File | Settings | File Templates. + * CText is a class that represents a text object in a graphical application. + * It extends the CClass class and provides methods to manipulate and display text. */ public class CText extends CClass { @@ -39,10 +36,20 @@ public class CText extends CClass { private double posX, posY; +/** + * Retrieves the font of this CText object. + * + * @return the font + */ public Font getFont() { return font; } + /** + * Sets the text type and parses the text value. + * + * @param t the text type to set + */ public void setTextType(int t) { type = t; tvalue = CTextValue.parseString(str); @@ -53,49 +60,79 @@ public void setTextType(int t) { m_color = 16; } - public boolean fontsizeChange(int n) { - int size = font.getSize() + n; - if (size <= 5) - return false; - - font = new Font(font.getName(), font.getStyle(), size); - return true; - } - + /** + * Retrieves the font size of this CText object. + * + * @return the font size + */ public int getFontSize() { return font.getSize(); } + /** + * Sets the font to bold. + */ public void setBold() { if (!font.isBold()) font = new Font(font.getName(), Font.BOLD, font.getSize()); } + /** + * Sets the font to plain. + */ public void setPlain() { if (!font.isPlain()) font = new Font(font.getName(), Font.PLAIN, font.getSize()); } + /** + * Sets the font of this CText object. + * + * @param f the font to set + */ public void setFont(Font f) { font = f; } + /** + * Sets the font size of this CText object. + * + * @param n the font size to set + */ public void setFontSize(int n) { if (n != font.getSize()) font = new Font(font.getName(), font.getStyle(), n); } + /** + * Default constructor for the CText class. + * Initializes the text object with default values. + */ public CText() { super(CClass.TEXT); str = new String(); - } + /** + * Sets the x and y coordinates of this CText object. + * + * @param x the x-coordinate to set + * @param y the y-coordinate to set + */ public void setXY(int x, int y) { this.x = x; this.y = y; } + /** + * Constructor for the CText class. + * Initializes the text object with the specified parent, coordinates, and type. + * + * @param f the parent CClass object + * @param dx the x-coordinate offset + * @param dy the y-coordinate offset + * @param type the type of the text + */ public CText(CClass f, double dx, double dy, int type) { super(CClass.TEXT); str = new String(); @@ -107,15 +144,26 @@ public CText(CClass f, double dx, double dy, int type) { father = f; } + /** + * Moves the text object by the specified offsets. + * + * @param dx the x-offset to move by + * @param dy the y-offset to move by + */ public void move(double dx, double dy) { super.move(dx, dy); if (type == NORMAL_TEXT || type == VALUE_TEXT) { x += dx; y += dy; } - } + /** + * Checks if this CText object is equal to another object. + * + * @param obj the object to compare with + * @return true if the objects are equal, false otherwise + */ public boolean equals(Object obj) { if (obj == null) return false; if (!(obj instanceof CText)) return false; @@ -137,6 +185,14 @@ public boolean equals(Object obj) { // font = new Font("Dialog", Font.PLAIN, 14); // } + /** + * Constructor for the CText class. + * Initializes the text object with the specified coordinates and string. + * + * @param x the x-coordinate of the text + * @param y the y-coordinate of the text + * @param s the string content of the text + */ public CText(int x, int y, String s) { super(CClass.TEXT); str = s; @@ -145,7 +201,11 @@ public CText(int x, int y, String s) { this.y = y; } - + /** + * Retrieves the text content of this CText object. + * + * @return the text content + */ public String getText() { if (type == NORMAL_TEXT) return str; @@ -157,15 +217,23 @@ else if (type == VALUE_TEXT) return str; return null; - } + /** + * Sets the text content of this CText object. + * + * @param s the text content to set + */ public void setText1(String s) { str = s; } + /** + * Sets the text content of this CText object based on its type. + * + * @param s the text content to set + */ public void setText(String s) { - if (type == NORMAL_TEXT) str = s; else if (type == NAME_TEXT) @@ -183,42 +251,67 @@ else if (type == CNAME_TEXT) { } } + /** + * Retrieves the string content of this CText object. + * + * @return the string content + */ public String getString() { return str; } + /** + * Retrieves the dimensions of the text as a Dimension object. + * + * @return the dimensions of the text + */ public Dimension getTextDimension() { return new Dimension((int) w, (int) height); } + /** + * Retrieves the x-coordinate of the text. + * + * @return the x-coordinate + */ public int getX() { return x; } + /** + * Retrieves the y-coordinate of the text. + * + * @return the y-coordinate + */ public int getY() { return y; } + /** + * Retrieves the location of the text as a Point object. + * + * @return the location of the text + */ public Point getLocation() { return new Point(x, y); } + /** + * Retrieves the type of this CText object. + * + * @return the type of the text + */ public int getType() { return this.type; } - - public int vlength() { - if (str == null) return 0; - return str.length(); - } - - public void setSvalue(String s) { - svalue = s; - } - public boolean nameTextShown = CMisc.nameTextShown; + /** + * Checks if the text should be drawn based on its visibility and the visibility of its parent. + * + * @return true if the text should be drawn, false otherwise + */ public boolean isdraw() { if (!super.isdraw()) return false; @@ -230,14 +323,18 @@ public boolean isdraw() { return CMisc.nameTextShown; } else { if (type == NAME_TEXT) - return nameTextShown; //APPLET ONLY + return nameTextShown; // APPLET ONLY } return true; } + /** + * Retrieves the x-coordinate for drawing the text. + * + * @return the x-coordinate for drawing + */ public int getSX() { - double lx; - lx = 0; + double lx = 0; if (type == NORMAL_TEXT) { lx = x; } else if (type == NAME_TEXT) { @@ -250,25 +347,31 @@ public int getSX() { return (int) lx; } + /** + * Retrieves the y-coordinate for drawing the text. + * + * @return the y-coordinate for drawing + */ public int getSY() { - double ly; - ly = 0; + double ly = 0; if (type == NORMAL_TEXT) { -// lx = x; ly = y; } else if (type == NAME_TEXT) { CPoint p = (CPoint) father; -// lx = p.getx() + x; ly = p.gety() + y; } else if (type == CNAME_TEXT && CMisc.show_angle_text) { CAngle ag = (CAngle) father; -// lx = ag.getxForString() + x; ly = ag.getyForString() + y; } return (int) ly; } + /** + * Retrieves the value text of this CText object. + * + * @return the value text + */ public String getValueText() { double r = tvalue.dvalue; //CTextValue.calvalue(tvalue, null); String shead = ""; @@ -295,6 +398,11 @@ public String getValueText() { return shead + " = " + r; } + /** + * Draws the text object using the provided Graphics2D context. + * + * @param g2 the Graphics2D context + */ public void draw(Graphics2D g2) { if (!isdraw()) return; @@ -330,12 +438,9 @@ public void draw(Graphics2D g2) { ly = r[1] + y + dy - height / 2; posX = lx; posY = ly; - //lx = ag.getxForString() + x - w / 2; - //ly = ag.getyForString() + y - height / 2; } } else if (type == VALUE_TEXT) { - tstring = getValueText(); lx = x; ly = y; @@ -343,11 +448,9 @@ public void draw(Graphics2D g2) { posY = ly; } - if (tstring == null) return; if (tstring.length() == 0) return; - String[] sl = tstring.split("\n"); g2.setFont(font); super.setDraw(g2); @@ -364,9 +467,14 @@ public void draw(Graphics2D g2) { w = r2.getWidth(); g2.drawString(sl[i], (float) lx, (float) (ly + (i + 1) * h)); } - } + /** + * Draws the text object with a selection highlight using the provided Graphics2D context. + * + * @param g2 the Graphics2D context + * @param select true if the text object is selected, false otherwise + */ public void draw(Graphics2D g2, boolean select) { if (visible == false) return; @@ -404,6 +512,11 @@ public void draw(Graphics2D g2, boolean select) { g2.draw(rc); } + /** + * Retrieves a string representation of the type of this text object. + * + * @return the type string + */ public String TypeString() { if (str == null) return ""; @@ -434,10 +547,24 @@ public String TypeString() { return null; } + /** + * Retrieves a description of this text object. + * + * @return the description + */ public String getDescription() { return this.TypeString(); } + /** + * Checks if the given rectangle defined by (x0, y0) and (x1, y1) intersects with this text object. + * + * @param x0 the x-coordinate of the first corner of the rectangle + * @param y0 the y-coordinate of the first corner of the rectangle + * @param x1 the x-coordinate of the opposite corner of the rectangle + * @param y1 the y-coordinate of the opposite corner of the rectangle + * @return true if the rectangle intersects with this text object, false otherwise + */ public boolean inRect(double x0, double y0, double x1, double y1) { if (x0 > x1) { double r = x0; @@ -449,11 +576,17 @@ public boolean inRect(double x0, double y0, double x1, double y1) { double r = y0; y0 = y1; y1 = r; - } return x0 < x && y0 < y && x1 > x + w && y1 > y + height; } + /** + * Checks if the given point (x1, y1) is within the bounds of this text object. + * + * @param x1 the x-coordinate of the point + * @param y1 the y-coordinate of the point + * @return true if the point is within the bounds, false otherwise + */ public boolean select(double x1, double y1) { if (visible == false) return false; @@ -486,6 +619,12 @@ public boolean select(double x1, double y1) { return false; } + /** + * Drags the text object by the given offsets (dx, dy). + * + * @param dx the x-offset to drag by + * @param dy the y-offset to drag by + */ public void drag(double dx, double dy) { x += dx; y += dy; @@ -509,10 +648,17 @@ public void drag(double dx, double dy) { x -= dx + x1; y -= dy + y1; } - } } + /** + * Drags the text object from the given starting point (x0, y0) by the given offsets (dx, dy). + * + * @param x0 the starting x-coordinate + * @param y0 the starting y-coordinate + * @param dx the x-offset to drag by + * @param dy the y-offset to drag by + */ public void drag(double x0, double y0, double dx, double dy) { if (type == NORMAL_TEXT || type == VALUE_TEXT) drag(dx, dy); @@ -529,7 +675,6 @@ else if (type == NAME_TEXT) { if (len > CMisc.rlength) { this.x = (int) (xp * CMisc.rlength / len); this.y = (int) (yp * CMisc.rlength / len); - } else { this.x += dx; this.y += dy; @@ -547,21 +692,24 @@ else if (type == NAME_TEXT) { if (len > CMisc.rlength) { this.x = (int) (xp * CMisc.rlength / len); this.y = (int) (yp * CMisc.rlength / len); - } else { this.x += dx; this.y += dy; } } - - } + /** + * Saves the text object as a PostScript file. + * + * @param fp the file output stream to write to + * @param stype the style type (0 for color, 1 for gray, 2 for black & white) + * @throws IOException if an I/O error occurs + */ public void SavePS(FileOutputStream fp, int stype) throws IOException { if (!isdraw()) return; if (father != null && !father.isdraw()) return; - String tstring = null; double lx, ly; @@ -611,11 +759,15 @@ public void SavePS(FileOutputStream fp, int stype) throws IOException { } else { fp.write(("mf " + (int) lx + " " + (int) (-ly - 15) + " moveto (" + tstring + ") " + "show\n").getBytes()); } - } + /** + * Saves the text object to the specified data output stream. + * + * @param out the data output stream to write to + * @throws IOException if an I/O error occurs + */ public void Save(DataOutputStream out) throws IOException { - super.Save(out); out.writeInt(type); @@ -642,7 +794,6 @@ public void Save(DataOutputStream out) throws IOException { out.writeInt(s.length); out.write(s, 0, s.length); out.writeInt(father.m_id); - } else if (type == VALUE_TEXT) { s = str.getBytes(); out.writeInt(s.length); @@ -651,12 +802,16 @@ public void Save(DataOutputStream out) throws IOException { out.writeInt(-1); else out.writeInt(father.m_id); } - - } + /** + * Loads the text object from the specified data input stream. + * + * @param in the data input stream to read from + * @param dp the draw process + * @throws IOException if an I/O error occurs + */ public void Load(DataInputStream in, DrawProcess dp) throws IOException { - if (CMisc.version_load_now < 0.010) { m_id = in.readInt(); x = in.readInt(); @@ -707,7 +862,6 @@ else if (m_color == 7) } else { super.Load(in, dp); - type = in.readInt(); x = in.readInt(); y = in.readInt(); @@ -754,10 +908,6 @@ else if (m_color == 7) father = dp.getOjbectById(id); } } - - } - } - } diff --git a/src/main/java/wprover/CTextValue.java b/src/main/java/wprover/CTextValue.java index c24d3a97..38a10c1d 100644 --- a/src/main/java/wprover/CTextValue.java +++ b/src/main/java/wprover/CTextValue.java @@ -3,11 +3,9 @@ import maths.TMono; /** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2005-7-28 - * Time: 13:31:13 - * To change this template use File | Settings | File Templates. + * CTextValue is a class that represents a mathematical expression in a tree structure. + * It can parse a string representation of the expression, evaluate it, and perform various + * mathematical functions. */ public class CTextValue { @@ -50,25 +48,50 @@ public class CTextValue { CTextValue left; CTextValue right; - + /** + * Default constructor for CTextValue. + */ public CTextValue() { } + /** + * Constructor for CTextValue with a specified type. + * + * @param t the type of the CTextValue + */ private CTextValue(int t) { TYPE = t; } - + /** + * Parses a string representation of a mathematical expression into a CTextValue object. + * + * @param str the string representation of the expression + * @return the parsed CTextValue object + */ public static CTextValue parseString(String str) { TMono index = new TMono(0, 0, 0); return parseEntityA(str.toCharArray(), index); } + /** + * Parses a byte array representation of a mathematical expression into a CTextValue object. + * + * @param src the byte array representation of the expression + * @param index the index used for parsing + * @return the parsed CTextValue object + */ public static CTextValue parse(byte[] src, TMono index) { return null; } + /** + * Gets the function index for a given function name. + * + * @param s the function name + * @return the index of the function, or -1 if not found + */ public static int getFunction(String s) { for (int i = 0; i < sfunction.length; i++) { if (s.equalsIgnoreCase(sfunction[i])) @@ -77,6 +100,13 @@ public static int getFunction(String s) { return -1; } + /** + * Parses a function name from the source character array. + * + * @param src the source character array + * @param index the index used for parsing + * @return the parsed function name + */ public static String parseFunction(char[] src, TMono index) { parseSpace(src, index); int i = index.x; @@ -95,7 +125,13 @@ public static String parseFunction(char[] src, TMono index) { return s; } - + /** + * Parses an entity of type A from the source character array. + * + * @param src the source character array + * @param index the index used for parsing + * @return the parsed CTextValue object + */ private static CTextValue parseEntityA(char[] src, TMono index) { CTextValue ct1 = parseEntityB(src, index); @@ -131,6 +167,13 @@ else if (b == '-') return ct1; } + /** + * Parses an entity of type B from the source character array. + * + * @param src the source character array + * @param index the index used for parsing + * @return the parsed CTextValue object + */ private static CTextValue parseEntityB(char[] src, TMono index) { parseSpace(src, index); @@ -164,6 +207,13 @@ else if (b == '/') return ct1; } + /** + * Parses an entity of type C from the source character array. + * + * @param src the source character array + * @param index the index used for parsing + * @return the parsed CTextValue object + */ private static CTextValue parseEntityC(char[] src, TMono index) { // ^ parseSpace(src, index); CTextValue t1 = parseEntityD(src, index); @@ -204,6 +254,13 @@ private static CTextValue parseEntityC(char[] src, TMono index) { // ^ else return t1; } + /** + * Parses an entity of type D from the source character array. + * + * @param src the source character array + * @param index the index used for parsing + * @return the parsed CTextValue object + */ private static CTextValue parseEntityD(char[] src, TMono index) { // (), x1,value. @@ -274,35 +331,13 @@ private static CTextValue parseEntityD(char[] src, TMono index) { // (), x1,valu } - private static char parseByte(char[] src, TMono index) { - parseSpace(src, index); - int i = index.x; - if (i >= src.length) return 0; - - char b = src[i]; - if (b != '+' && b != '-') { - index.x = i; - return 0; - } - index.x++; - - parseSpace(src, index); - return b; - } - - private static char parseByteB(char[] src, TMono index) { - parseSpace(src, index); - int i = index.x; - if (i >= src.length) return 0; - - if (src[i] == '*' || src[i] == '/') { - index.x++; - parseSpace(src, index); - return src[i]; - } - return 0; - } - + /** + * Parses an integer value from the source character array. + * + * @param src the source character array + * @param index the index used for parsing + * @return the parsed integer value + */ private static double parseInt(char[] src, TMono index) { parseSpace(src, index); @@ -339,6 +374,12 @@ else if (step == 0) { return v; } + /** + * Parses and skips spaces in the source character array. + * + * @param src the source character array + * @param index the index used for parsing + */ private static void parseSpace(char[] src, TMono index) { int i = index.x; @@ -352,64 +393,45 @@ private static void parseSpace(char[] src, TMono index) { } - private static String getAString(char[] src, TMono index) { - parseSpace(src, index); - int i = index.x; - String s = new String(); - - if (src == null || i >= src.length) return s; - - while ((src[i] >= 'a' && src[i] <= 'z') || (src[i] >= 'A' && src[i] <= 'Z')) { - s += src[i]; - i++; - if (i >= src.length) break; - } - - if (s.length() != 0) { - index.x = i; - return s; - } - - - if (src[i] == '(' || src[i] == ')' || src[i] == '*' || src[i] == '/' || src[i] == '^') { - s += src[i]; - index.x = i + 1; - return s; - } - - while (src[i] >= '0' && src[i] <= '9') { - s += src[i]; - i++; - if (i >= src.length) break; - - } - if (s.length() != 0) { - index.x = i; - return s; - } - parseSpace(src, index); - - return s; - } - + /** + * Rounds a double value to three decimal places. + * + * @param r the double value to round + * @return the rounded double value + */ public static double roud3(double r) { return Math.round(r * 1000 + 0.1) / 1000.0; } + /** + * Calculates the value of this CTextValue object using the specified DrawProcess. + * + * @param dp the DrawProcess used for calculation + */ public void calculate(DrawProcess dp) { double r = calvalue(this, dp); this.dvalue = roud3(r); } + /** + * Calculates the value of the specified CTextValue object using the specified DrawProcess. + * + * @param ct the CTextValue object to calculate + * @param dp the DrawProcess used for calculation + * @return the calculated double value + */ public static double calvalue(CTextValue ct, DrawProcess dp) { if (ct == null) return 0.0; return dp.calculate(ct); } -// "sin", "cos", "tan", "arcsin", "arccos", "arctan", - - // "abs", "sqrt", "ln", "log", "sgn", "round", "trunc"} - + /** + * Calculates the result of a mathematical function on a given value. + * + * @param n the function index + * @param v the value to apply the function to + * @return the result of the function + */ public static double cal_func(int n, double v) { switch (n) { case 0: diff --git a/src/main/java/wprover/CTrace.java b/src/main/java/wprover/CTrace.java index 49c079bb..da633f17 100644 --- a/src/main/java/wprover/CTrace.java +++ b/src/main/java/wprover/CTrace.java @@ -6,6 +6,10 @@ import java.io.DataInputStream; import java.io.FileOutputStream; +/** + * CTrace is a class that represents a trace of points in a graphical application. + * It extends the CClass class and provides methods to manage and draw the trace. + */ public class CTrace extends CClass { private static final int MAX_POINT = 501; @@ -18,7 +22,11 @@ public class CTrace extends CClass { private boolean dlns; private final static int MAXLEN = 300; - + /** + * Constructs a CTrace object with the specified point. + * + * @param p the point associated with the trace + */ public CTrace(CPoint p) { super(CClass.TRACE); m_name = "Trace of " + p; @@ -28,6 +36,13 @@ public CTrace(CPoint p) { Num = -1; } + /** + * Constructs a CTrace object with the specified points and line. + * + * @param p the point associated with the trace + * @param po the point on the line + * @param o the line associated with the trace + */ public CTrace(CPoint p, CPoint po, CLine o) { super(CClass.TRACE); m_name = "Locus of " + p + " when " + po + " is on" + o; @@ -38,6 +53,13 @@ public CTrace(CPoint p, CPoint po, CLine o) { oObj = o; } + /** + * Constructs a CTrace object with the specified points and circle. + * + * @param p the point associated with the trace + * @param po the point on the circle + * @param o the circle associated with the trace + */ public CTrace(CPoint p, CPoint po, Circle o) { super(CClass.TRACE); m_name = "Locus of " + p + " when " + po + " is on" + o; @@ -48,26 +70,52 @@ public CTrace(CPoint p, CPoint po, Circle o) { oObj = o; } + /** + * Checks if the specified point is the trace point. + * + * @param pt the point to check + * @return true if the specified point is the trace point, false otherwise + */ public boolean isTracePt(CPoint pt) { return point == pt && po == null && oObj == null; } - + /** + * Sets whether to draw lines for the trace. + * + * @param r true to draw lines, false otherwise + */ public void setDLns(boolean r) { dlns = r; } + /** + * Checks if lines are drawn for the trace. + * + * @return true if lines are drawn, false otherwise + */ public boolean isDrawLines() { return dlns; } + /** + * Sets the number of points for the trace. + * + * @param n the number of points + */ public void setNumPts(int n) { if (n < MAX_POINT) Num = n; else Num = MAX_POINT; } + /** + * Draws the trace using the specified Graphics2D object, with an option to select it. + * + * @param g2 the Graphics2D object + * @param selected whether the trace is selected + */ public void draw(Graphics2D g2, boolean selected) { if (!isdraw()) return; @@ -93,6 +141,15 @@ else if (i < Num - 1) } } + /** + * Draws a line segment between two points using the specified Graphics2D object. + * + * @param x the x coordinate of the first point + * @param y the y coordinate of the first point + * @param x1 the x coordinate of the second point + * @param y1 the y coordinate of the second point + * @param g2 the Graphics2D object + */ public void drawALN(int x, int y, int x1, int y1, Graphics2D g2) { if ((x1 < -0 || x1 > 1000) && (x < -0 || x > 1000)) @@ -109,19 +166,41 @@ public void drawALN(int x, int y, int x1, int y1, Graphics2D g2) { g2.drawLine(x, y, x1, y1); } + /** + * Draws the trace using the specified Graphics2D object. + * + * @param g2 the Graphics2D object + */ public void draw(Graphics2D g2) { draw(g2, false); } + /** + * Returns the type string of the trace. + * + * @return the type string of the trace + */ public String TypeString() { if (m_name == null) return "Trace"; return "Trace " + m_name; } + /** + * Returns the description of the trace. + * + * @return the description of the trace + */ public String getDescription() { return "Trace " + point.TypeString(); } + /** + * Selects the trace based on the specified coordinates. + * + * @param x the x coordinate + * @param y the y coordinate + * @return true if the trace is selected, false otherwise + */ public boolean select(double x, double y) { if (!isdraw()) return false; double r2 = CMisc.PIXEPS * CMisc.PIXEPS; @@ -132,6 +211,12 @@ public boolean select(double x, double y) { return false; } + /** + * Moves the trace by the specified delta values. + * + * @param dx the delta x value + * @param dy the delta y value + */ public void move(double dx, double dy) { for (int i = 0; i < Num; i++) { PX[i] += dx; @@ -139,6 +224,13 @@ public void move(double dx, double dy) { } } + /** + * Saves the trace to a PostScript file. + * + * @param fp the FileOutputStream to write to + * @param stype the stroke type + * @throws IOException if an I/O error occurs + */ public void SavePS(FileOutputStream fp, int stype) throws IOException { if (!visible) return; @@ -163,7 +255,12 @@ public void SavePS(FileOutputStream fp, int stype) throws IOException { } } - + /** + * Saves the trace to a DataOutputStream. + * + * @param out the DataOutputStream to write to + * @throws IOException if an I/O error occurs + */ public void Save(DataOutputStream out) throws IOException { super.Save(out); out.writeInt(point.m_id); @@ -194,6 +291,13 @@ public void Save(DataOutputStream out) throws IOException { out.writeBoolean(dlns); } + /** + * Loads the trace from a DataInputStream. + * + * @param in the DataInputStream to read from + * @param dp the DrawProcess used for loading + * @throws IOException if an I/O error occurs + */ public void Load(DataInputStream in, DrawProcess dp) throws IOException { super.Load(in, dp); if (CMisc.version_load_now >= 0.011) { @@ -216,9 +320,13 @@ public void Load(DataInputStream in, DrawProcess dp) throws IOException { } } - /////////////////////////////////////////////////////// - - + /** + * Adds a trace point at the specified index with the given coordinates. + * + * @param i the index to add the trace point + * @param x the x coordinate of the trace point + * @param y the y coordinate of the trace point + */ public void addTracePoint(int i, double x, double y) { PX[i] = (int) x; PY[i] = (int) y; @@ -229,12 +337,12 @@ public void addTracePoint(int i, double x, double y) { } - public void addTracePoint(int x, int y, int i) { - PX[i] = x; - PY[i] = y; - soft(i); - } - + /** + * Adds a trace point with the given coordinates. + * + * @param x the x coordinate of the trace point + * @param y the y coordinate of the trace point + */ public void addTracePoint(int x, int y) { for (int i = 0; i <= Num; i++) @@ -248,7 +356,9 @@ public void addTracePoint(int x, int y) { PY[Num] = y; } - + /** + * Softens the edges of the trace. + */ public void softEdge() { for (int i = 2; i < Num - 1; i++) { @@ -276,17 +386,19 @@ public void softEdge() { } } + /** + * Softens the trace at the specified index. + * + * @param i the index to soften + */ public void soft(int i) { } - - public void trans(double dx, double dy) { - for (int i = 0; i < Num; i++) { - PX[i] += dx; - PY[i] += dy; - } - } - + /** + * Calculates the round length of the trace. + * + * @return the round length of the trace + */ public double Roud_length() { if (Num == 0) return 0.0; @@ -304,29 +416,59 @@ public double Roud_length() { return len; } + /** + * Returns the x coordinate of the trace point at the specified index. + * + * @param i the index of the trace point + * @return the x coordinate of the trace point + */ int getPtxi(int i) { return PX[i]; } + /** + * Returns the y coordinate of the trace point at the specified index. + * + * @param i the index of the trace point + * @return the y coordinate of the trace point + */ int getPtyi(int i) { return PY[i]; } + /** + * Returns the point associated with the trace. + * + * @return the point associated with the trace + */ public CPoint getPoint() { return point; } + /** + * Returns the point on the trace. + * + * @return the point on the trace + */ public CPoint getonPoint() { return po; } + /** + * Returns the object associated with the trace. + * + * @return the object associated with the trace + */ public CClass getOnObject() { return oObj; } + /** + * Returns the number of points in the trace. + * + * @return the number of points in the trace + */ public int getPointSize() { return Num; } - - } diff --git a/src/main/java/wprover/Cedmark.java b/src/main/java/wprover/Cedmark.java index e9e82c7e..02f68b17 100644 --- a/src/main/java/wprover/Cedmark.java +++ b/src/main/java/wprover/Cedmark.java @@ -7,13 +7,8 @@ import java.io.FileOutputStream; /** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2005-8-23 - * Time: 14:50:02 - * To change this template use File | Settings | File Templates. - * - * This class represents an equality mark between two points. + * Represents a Cedmark object, which is a type of equality mark in a geometric drawing. + * It extends the CClass class and provides methods for drawing and saving the equality mark. */ public class Cedmark extends CClass { private static int DEFAULT_LEN = 8; @@ -154,15 +149,6 @@ public void drawALine(double x, double y, double dx, double dy, Graphics2D g2) { g2.drawLine((int) xx1, (int) yy1, (int) xx2, (int) yy2); } - /** - * Draws the equality mark using the given Graphics2D object and a point. - * - * @param g2 the Graphics2D object - * @param d the point - */ - void draw(Graphics2D g2, CPoint d) { - } - /** * Draws the equality mark with the option to highlight if selected. * diff --git a/src/main/java/wprover/Circle.java b/src/main/java/wprover/Circle.java index ee684b22..a92da603 100644 --- a/src/main/java/wprover/Circle.java +++ b/src/main/java/wprover/Circle.java @@ -8,13 +8,7 @@ import java.awt.*; /** - * Created by IntelliJ IDEA. - * User: ${Yezheng} - * Date: 2004-12-9 - * Time: 12:29:48 - * To change this template use File | Settings | File Templates. - * - * This class represents a circle in geometric constructions. + * Represents a geometric circle with various properties and methods. */ public class Circle extends CClass { public static int PCircle = 0; @@ -315,6 +309,13 @@ public Circle(CPoint O, CPoint A, CPoint B, CPoint C) { points.add(C); } +/** + * Constructs a Circle object with the specified center and two points on the circle. + * + * @param O the center of the circle + * @param A the first point on the circle + * @param B the second point on the circle + */ public Circle(CPoint O, CPoint A, CPoint B) { super(CClass.CIRCLE); this.o = O; @@ -322,34 +323,54 @@ public Circle(CPoint O, CPoint A, CPoint B) { points.add(B); } + /** + * Constructs a Circle object with the specified center and one point on the circle. + * + * @param O the center of the circle + * @param A the point on the circle + */ public Circle(CPoint O, CPoint A) { super(CClass.CIRCLE); this.o = O; points.add(A); } + /** + * Constructs a Circle object with the specified type and center. + * + * @param type the type of the circle + * @param O the center of the circle + */ public Circle(int type, CPoint O) { super(CClass.CIRCLE); this.o = O; this.type = type; } + /** + * Adds a constraint to the circle. + * + * @param cs the constraint to add + */ public void addConstraint(Constraint cs) { cons.add(cs); } - public boolean hasPoint(CPoint p) { - for (int i = 0; i < points.size(); i++) { - if (p.isEqual((CPoint) points.get(i))) return true; - } - return false; - } - + /** + * Adds a point to the circle. + * + * @param p the point to add + */ public void addPoint(CPoint p) { if (!points.contains(p)) points.add(p); } + /** + * Adjusts the coordinates of the given point to lie on the circle. + * + * @param p the point to adjust + */ public void pointStickToCircle(CPoint p) { double x = p.getx(); double y = p.gety(); @@ -362,13 +383,27 @@ public void pointStickToCircle(CPoint p) { double y1 = yo + (y - yo) * R / R1; double x1 = xo + (x - xo) * R / R1; p.setXY(x1, y1); - } + /** + * Checks if the given coordinates are on the circle. + * + * @param x the x-coordinate + * @param y the y-coordinate + * @return true if the coordinates are on the circle, false otherwise + */ public boolean on_circle(double x, double y) { return this.select(x, y); } + /** + * Checks if the given coordinates are near the circle within a specified tolerance. + * + * @param x the x-coordinate + * @param y the y-coordinate + * @param eps the tolerance + * @return true if the coordinates are near the circle, false otherwise + */ public boolean nearcircle(double x, double y, double eps) { double ox, oy; ox = o.getx(); @@ -381,18 +416,21 @@ public boolean nearcircle(double x, double y, double eps) { return false; } + /** + * Adjusts the coordinates of the given point to lie on the circle using a smart algorithm. + * + * @param p the point to adjust + */ public void SmartPonc(CPoint p) { - // CPoint pt = (CPoint) points.get(0); double ox, oy, x, y; ox = o.getx(); oy = o.gety(); x = p.getx(); y = p.gety(); - double r = this.getRadius();//Math.sqrt(Math.pow(pt.getx() - ox, 2) + Math.pow(pt.gety() - oy, 2)); + double r = this.getRadius(); double len = Math.sqrt(Math.pow(p.getx() - ox, 2) + Math.pow(p.gety() - oy, 2)); - if (Math.abs(x - o.getx()) < 0.001) { if (y > oy) p.setXY(ox, oy + r); @@ -404,6 +442,13 @@ public void SmartPonc(CPoint p) { } } + /** + * Finds the common points between two circles. + * + * @param c1 the first circle + * @param c2 the second circle + * @return a vector of common points + */ public static Vector CommonPoints(Circle c1, Circle c2) { Vector vlist = new Vector(); for (int i = 0; i < c1.points.size(); i++) { @@ -416,6 +461,12 @@ public static Vector CommonPoints(Circle c1, Circle c2) { return vlist; } + /** + * Checks if the given object is tangent to the circle. + * + * @param obj the object to check + * @return true if the object is tangent to the circle, false otherwise + */ public boolean Tangent(Object obj) { if (obj instanceof CLine) { return true; @@ -434,6 +485,13 @@ public boolean Tangent(Object obj) { return false; } + /** + * Saves the circle to a PostScript file. + * + * @param fp the file output stream + * @param stype the style type + * @throws IOException if an I/O error occurs + */ public void SavePS(FileOutputStream fp, int stype) throws IOException { if (!visible) return; @@ -444,6 +502,12 @@ public void SavePS(FileOutputStream fp, int stype) throws IOException { this.saveSuper(fp); } + /** + * Saves the circle to a data output stream. + * + * @param out the data output stream + * @throws IOException if an I/O error occurs + */ public void Save(DataOutputStream out) throws IOException { super.Save(out); @@ -459,10 +523,15 @@ public void Save(DataOutputStream out) throws IOException { Constraint cs = (Constraint) cons.get(i); out.writeInt(cs.id); } - - } + /** + * Loads the circle from a data input stream. + * + * @param in the data input stream + * @param dp the draw process + * @throws IOException if an I/O error occurs + */ public void Load(DataInputStream in, DrawProcess dp) throws IOException { if (CMisc.version_load_now < 0.010) { m_id = in.readInt(); @@ -483,7 +552,6 @@ else if (m_color == 7) m_dash = drawt.dash; m_width = drawt.width; - type = in.readInt(); int size = in.readInt(); m_name = new String(); @@ -520,10 +588,7 @@ else if (m_color == 7) int dx = in.readInt(); cons.add(dp.getConstraintByid(dx)); } - } - - } diff --git a/src/main/java/wprover/ColorButtonPanel.java b/src/main/java/wprover/ColorButtonPanel.java index 8a792175..998e94bd 100644 --- a/src/main/java/wprover/ColorButtonPanel.java +++ b/src/main/java/wprover/ColorButtonPanel.java @@ -6,16 +6,19 @@ import java.awt.event.MouseListener; /** - * Created by IntelliJ IDEA. - * User: yezheng - * Date: 2006-6-9 - * Time: 9:36:35 - * To change this template use File | Settings | File Templates. + * ColorButtonPanel is a JPanel that displays a color button. When the button is clicked, + * it opens a color menu to allow the user to select a color. */ public class ColorButtonPanel extends JPanel implements MouseListener { private ColorMenu cm = new ColorMenu("color"); + /** + * Constructs a ColorButtonPanel with specified dimensions. + * + * @param x the width of the panel + * @param y the height of the panel + */ public ColorButtonPanel(int x, int y) { this.setBorder(BorderFactory.createLineBorder(Color.black, 1)); @@ -28,11 +31,21 @@ public ColorButtonPanel(int x, int y) this.addMouseListener(this); } + /** + * Returns the ColorMenu associated with this panel. + * + * @return the ColorMenu + */ public ColorMenu getColorMenu() { return cm; } + /** + * Invoked when the mouse button has been clicked (pressed and released) on a component. + * + * @param e the event to be processed + */ public void mouseClicked(MouseEvent e) { int x = e.getX(); @@ -42,26 +55,51 @@ public void mouseClicked(MouseEvent e) cm.show(this, x, y); } + /** + * Invoked when a mouse button has been pressed on a component. + * + * @param e the event to be processed + */ public void mousePressed(MouseEvent e) { } + /** + * Invoked when a mouse button has been released on a component. + * + * @param e the event to be processed + */ public void mouseReleased(MouseEvent e) { } + /** + * Invoked when the mouse enters a component. + * + * @param e the event to be processed + */ public void mouseEntered(MouseEvent e) { } + /** + * Invoked when the mouse exits a component. + * + * @param e the event to be processed + */ public void mouseExited(MouseEvent e) { } + /** + * Sets the background color of the panel to the selected color from the ColorMenu. + * + * @return the new color if the color pane is not null, otherwise null + */ public Color setNewColor() { if (cm.colorPane != null) diff --git a/src/main/java/wprover/ColorComboRender.java b/src/main/java/wprover/ColorComboRender.java index b39d85e6..21efc06e 100644 --- a/src/main/java/wprover/ColorComboRender.java +++ b/src/main/java/wprover/ColorComboRender.java @@ -21,6 +21,13 @@ class ColorComboRender extends JPanel int index = 0; boolean select = false; + /** + * Constructs a ColorComboRender with specified type and dimensions. + * + * @param type the type of the renderer (0 for color, 1 for line width, 2 for line type) + * @param w the width of the renderer + * @param h the height of the renderer + */ public ColorComboRender(int type, int w, int h) { setOpaque(true); this.type = type; @@ -29,6 +36,16 @@ public ColorComboRender(int type, int w, int h) { height = h; } + /** + * Returns the component used for drawing the cell in the list. + * + * @param list the JList we're painting + * @param value the value returned by list.getModel().getElementAt(index) + * @param index the cell's index + * @param isSelected true if the specified cell was selected + * @param cellHasFocus true if the specified cell has the focus + * @return the component that the renderer uses to draw the value + */ public Component getListCellRendererComponent(JList list, Object value, int index, @@ -50,7 +67,11 @@ public Component getListCellRendererComponent(JList list, this.index = selectedIndex; return this; } - + /** + * Paints the component. + * + * @param g the Graphics object to protect + */ public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; if (select) @@ -116,12 +137,21 @@ public void paintComponent(Graphics g) { } + /** + * Returns the component used for drawing the cell in the table. + * + * @param table the JTable we're painting + * @param value the value returned by table.getValueAt(row, column) + * @param isSelected true if the specified cell was selected + * @param hasFocus true if the specified cell has the focus + * @param row the row of the cell to render + * @param column the column of the cell to render + * @return the component that the renderer uses to draw the value + */ public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { select = isSelected; return this; } - - } \ No newline at end of file diff --git a/src/main/java/wprover/ColorMenu.java b/src/main/java/wprover/ColorMenu.java index b9580f47..6225995f 100644 --- a/src/main/java/wprover/ColorMenu.java +++ b/src/main/java/wprover/ColorMenu.java @@ -24,7 +24,7 @@ public ColorMenu(String name) super(name); unselectedBorder = new CompoundBorder(new MatteBorder(1, 1, 1, 1, getBackground()), new BevelBorder(BevelBorder.LOWERED, - Color.white, Color.gray)); + Color.white, Color.gray)); selectedBorder = new CompoundBorder(new MatteBorder(1, 1, 1, 1, Color.red), new MatteBorder(1, 1, 1, 1, getBackground())); activeBorder = new CompoundBorder(new MatteBorder(1, 1, 1, 1, @@ -52,7 +52,11 @@ public ColorMenu(String name) } add(p); } - + /** + * Sets the selected color in the ColorMenu. + * + * @param c the color to be selected + */ public void setColor(Color c) { Object obj = paneTable.get(c); @@ -64,6 +68,11 @@ public void setColor(Color c) colorPane.setSelected(true); } +/** + * Gets the currently selected color in the ColorMenu. + * + * @return the selected color, or null if no color is selected + */ public Color getColor() { if (colorPane == null) @@ -71,10 +80,16 @@ public Color getColor() return colorPane.getColor(); } + /** + * Performs the selection action. This method is intended to be overridden. + */ public void doSelection() { } + /** + * Hides the ColorMenu. + */ public void HideMenu() { this.setVisible(false); @@ -86,37 +101,68 @@ class ColorPane extends JPanel implements MouseListener protected boolean isSelected; +/** + * Constructs a ColorPane with the specified color. + * Sets the background color, border, tooltip text, and registers a MouseListener. + * + * @param c the color of the pane + */ public ColorPane(Color c) { color = c; setBackground(c); setBorder(unselectedBorder); - String msg = "R " + c.getRed() + ", G " + c.getGreen() + ", B " - + c.getBlue(); + String msg = "R " + c.getRed() + ", G " + c.getGreen() + ", B " + c.getBlue(); setToolTipText(msg); addMouseListener(this); } + /** + * Returns the color of the pane. + * + * @return the color of the pane + */ public Color getColor() { return color; } + /** + * Returns the preferred size of the pane. + * + * @return the preferred size of the pane + */ public Dimension getPreferredSize() { return new Dimension(25, 25); } + /** + * Returns the maximum size of the pane. + * + * @return the maximum size of the pane + */ public Dimension getMaximumSize() { return getPreferredSize(); } + /** + * Returns the minimum size of the pane. + * + * @return the minimum size of the pane + */ public Dimension getMinimumSize() { return getPreferredSize(); } + /** + * Sets the selection state of the pane. + * Updates the border based on the selection state. + * + * @param selected the selection state to set + */ public void setSelected(boolean selected) { isSelected = selected; @@ -126,19 +172,40 @@ public void setSelected(boolean selected) setBorder(unselectedBorder); } + /** + * Returns whether the pane is selected. + * + * @return true if the pane is selected, false otherwise + */ public boolean isSelected() { return isSelected; } + /** + * Invoked when a mouse button has been pressed on the pane. + * + * @param e the MouseEvent triggered by the press + */ public void mousePressed(MouseEvent e) { } + /** + * Invoked when the mouse has been clicked on the pane. + * + * @param e the MouseEvent triggered by the click + */ public void mouseClicked(MouseEvent e) { } + /** + * Invoked when a mouse button has been released on the pane. + * Sets the color, clears the selected path, performs the selection action, and hides the menu. + * + * @param e the MouseEvent triggered by the release + */ public void mouseReleased(MouseEvent e) { setColor(color); @@ -147,11 +214,23 @@ public void mouseReleased(MouseEvent e) HideMenu(); } + /** + * Invoked when the mouse enters the pane. + * Sets the border to the active border. + * + * @param e the MouseEvent triggered when entering the pane + */ public void mouseEntered(MouseEvent e) { setBorder(activeBorder); } + /** + * Invoked when the mouse exits the pane. + * Sets the border based on the selection state. + * + * @param e the MouseEvent triggered when exiting the pane + */ public void mouseExited(MouseEvent e) { setBorder(isSelected ? selectedBorder : unselectedBorder); diff --git a/src/main/java/wprover/ConcDialog.java b/src/main/java/wprover/ConcDialog.java index 99294ccd..a4f2ca03 100644 --- a/src/main/java/wprover/ConcDialog.java +++ b/src/main/java/wprover/ConcDialog.java @@ -7,6 +7,10 @@ import java.awt.*; import java.awt.event.*; +/** + * ConcDialog is a dialog for selecting geometric conclusions. + * It allows the user to select points and check geometric properties. + */ public class ConcDialog extends JBaseDialog implements ActionListener, ItemListener { int type = 0; // 0. Conclusion 1. NDGS. final static String[] ts = { @@ -31,7 +35,7 @@ public class ConcDialog extends JBaseDialog implements ActionListener, ItemListe "Special Angle", "Angles Equation", "Segment Equation" - };//CST.s_conc_detail; + }; final public static int CONCLUSION_OK = 0; @@ -53,15 +57,30 @@ public class ConcDialog extends JBaseDialog implements ActionListener, ItemListe private condPane Pane2; + /** + * Sets the type of the dialog. + * + * @param t the type to set + */ public void setType(int t) { this.type = t; } + /** + * Changes the action listener for the OK button. + * + * @param ls the new ActionListener to set + */ public void changeBOKListener(ActionListener ls) { bok.removeActionListener(this); bok.addActionListener(ls); } + /** + * Sets the conclusion in the dialog. + * + * @param c the conclusion to set + */ public void setCns(Cons c) { if (c == null) return; @@ -75,6 +94,12 @@ public void setCns(Cons c) { } } + /** + * Constructs a ConcDialog with the specified GExpert instance and title. + * + * @param gx the GExpert instance + * @param title the title of the dialog + */ public ConcDialog(GExpert gx, String title) { super(gx.getFrame(), title); this.setTitle(title); @@ -83,9 +108,13 @@ public ConcDialog(GExpert gx, String title) { init(); this.setPoints(gx.dp.getPointList()); this.setModal(false); - } + /** + * Sets the value of ltext1 based on the given type. + * + * @param t the type to set + */ private void setLtext1Value(int t) { if (model) return; @@ -104,16 +133,10 @@ private void setLtext1Value(int t) { } } - public ConcDialog(GExpert frame) { - super(frame.getFrame(), "Add Conclusion"); - this.setModal(false); - model = false; - init(); - } - + /** + * Initializes the dialog components. + */ private void init() { - - JPanel contentPane = new JPanel(); contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS)); @@ -124,7 +147,6 @@ private void init() { ic2 = GExpert.createImageIcon("images/ptree/cross.gif"); ic3 = GExpert.createImageIcon("images/ptree/question.gif"); - int len = ts.length; String[] ss = new String[len]; for (int i = 0; i < len; i++) @@ -188,7 +210,6 @@ public Dimension getMaximumSize() { Pane1.add(textPane); cardPane.add(Pane1, "1"); - JPanel bottomPane = new JPanel(); bottomPane.setLayout(new BoxLayout(bottomPane, BoxLayout.X_AXIS)); @@ -205,7 +226,6 @@ public Dimension getMaximumSize() { bclear.setActionCommand("Clear"); bcancel.setActionCommand("Cancel"); - contentPane.add(cardPane); contentPane.add(bottomPane); this.add(contentPane); @@ -221,6 +241,11 @@ public void windowClosing(WindowEvent e) { this.resetAllItem(); } + /** + * Sets the points in the combo boxes. + * + * @param v the vector of points to set + */ public void setPoints(Vector v) { for (int i = 0; i < vlist.size(); i++) { JComboBox b = (JComboBox) vlist.get(i); @@ -242,6 +267,11 @@ public void setPoints(Vector v) { Pane2.setPoints(v); } + /** + * Returns the number of points left to be selected. + * + * @return the number of points left to be selected + */ private int ptLeftTobeSelect() { int n = 0; @@ -260,6 +290,11 @@ private int ptLeftTobeSelect() { return n; } + /** + * Handles item state changes for the combo boxes. + * + * @param e the ItemEvent triggered by the user + */ public void itemStateChanged(ItemEvent e) { if (!this.isVisible()) return; Object source = e.getSource(); @@ -306,19 +341,23 @@ public void itemStateChanged(ItemEvent e) { } } + /** + * Checks if the input is finished. + * + * @return true if the input is finished, false otherwise + */ private boolean inputFinished() { return 0 == ptLeftTobeSelect(); } - private void showTipText() { - - } - + /** + * Selects a point in the combo boxes. + * + * @param p the point to select + */ public void selectAPoint(CPoint p) { - Pane2.selectAPoint(p); - for (int i = 0; i < vlist.size(); i++) { JComboBox b = (JComboBox) vlist.get(i); if (b.isEnabled() && b.getSelectedIndex() < 0) { @@ -333,9 +372,11 @@ public void selectAPoint(CPoint p) { return; } } - } + /** + * Resets all combo boxes and labels. + */ private void resetAllItem() { bok.setEnabled(false); ltext1.setIcon(ic3); @@ -344,7 +385,6 @@ private void resetAllItem() { for (int i = 0; i < vlist.size(); i++) { JComboBox b = (JComboBox) vlist.get(i); b.setSelectedIndex(-1); - } for (int i = 0; i < vlist1.size(); i++) { JComboBox b = (JComboBox) vlist1.get(i); @@ -352,9 +392,13 @@ private void resetAllItem() { } bx1.setSelectedIndex(0); bx2.setSelectedIndex(0); - } + /** + * Returns the number of points required for the selected item. + * + * @return the number of points required + */ private int getStatePointsCount() { switch (bt.getSelectedIndex()) { case 0: @@ -369,7 +413,6 @@ private int getStatePointsCount() { case 5: case 11: case 13: - return 4; case 7: case 8: @@ -382,6 +425,11 @@ private int getStatePointsCount() { return -1; } + /** + * Updates the visibility of combo boxes based on the selected item ID. + * + * @param id the ID of the selected item + */ private void setItemChanged(int id) { switch (id) { case 0: @@ -398,7 +446,6 @@ private void setItemChanged(int id) { case 5: case 11: case 13: - this.setVisibleBox1(4); break; case 7: @@ -409,7 +456,6 @@ private void setItemChanged(int id) { case 12: this.setVisibleBox1(8); break; - } if (id == 13) { setRatioVisible(); @@ -423,16 +469,22 @@ private void setItemChanged(int id) { } } + /** + * Sets the angles in the combo box for special angles. + */ public void setSAngle() { bx1.removeAllItems(); int[] angles = {0, 15, 30, 36, 45, 72, 75, 90, 120, 135, 150, 180}; - for (int i: angles) { + for (int i : angles) { bx1.addItem(i); } bx1.setVisible(true); bx2.setVisible(false); } + /** + * Sets the ratio values in the combo boxes. + */ public void setRatioVisible() { bx1.removeAllItems(); bx2.removeAllItems(); @@ -445,6 +497,11 @@ public void setRatioVisible() { bx2.setVisible(true); } + /** + * Handles action events for the buttons. + * + * @param e the ActionEvent triggered by the user + */ public void actionPerformed(ActionEvent e) { String command = e.getActionCommand(); if (command.equalsIgnoreCase("OK")) { @@ -455,7 +512,6 @@ public void actionPerformed(ActionEvent e) { gxInstance.getpprove().set_conclusion(getProve(), this.checkValid()); else gxInstance.getpprove().add_ndgs(getProve()); - } else if (command.equalsIgnoreCase("Cancel")) { returnValue = CONCLUSION_CANCEL; this.setVisible(false); @@ -465,6 +521,12 @@ public void actionPerformed(ActionEvent e) { } } + /** + * Displays the dialog and returns the result. + * + * @param s the string to select in the combo box + * @return the return value indicating the result of the dialog + */ public int showDialog(String s) { if (model == false) this.setPoints(gxInstance.dp.getPointList()); @@ -478,11 +540,14 @@ public int showDialog(String s) { bt.setSelectedItem(s); ltext.setText(""); return returnValue; - } + /** + * Sets the visibility of the first set of combo boxes based on the number of items. + * + * @param num the number of items to be visible + */ private void setVisibleBox1(int num) { - int k = num / 2; for (int i = 0; i < vlist.size(); i++) { JComboBox obj = (JComboBox) vlist.get(i); @@ -500,6 +565,11 @@ private void setVisibleBox1(int num) { } } + /** + * Sets the visibility of the second set of combo boxes based on the number of items. + * + * @param num the number of items to be visible + */ private void setVisibleBox(int num) { for (int i = 0; i < vlist.size(); i++) { JComboBox obj = (JComboBox) vlist.get(i); @@ -514,13 +584,13 @@ private void setVisibleBox(int num) { } } - private String vs(int id1, int id2) { - if (id1 == 0) - return ((JComboBox) vlist.get(id2)).getSelectedItem().toString(); - else - return ((JComboBox) vlist1.get(id2)).getSelectedItem().toString(); - } - + /** + * Returns the selected point from the combo boxes. + * + * @param id1 the ID of the combo box set (0 or 1) + * @param id2 the index of the combo box within the set + * @return the selected point + */ private CPoint vspt(int id1, int id2) { if (id1 == 0) { return (CPoint) ((JComboBox) vlist.get(id2)).getSelectedItem(); @@ -528,34 +598,23 @@ private CPoint vspt(int id1, int id2) { return (CPoint) ((JComboBox) vlist1.get(id2)).getSelectedItem(); } } -// "Collinear", -// "Parallel", -// "Perpendicular", -// "Midpoint", -// "Cyclic", -// "Equal Distance", -// "Equal Angle", -// -// "Similiar Triangle", -// "Congruent Triangle", -// "Equalateral Triangle", -// -// "Bisect", -// "Tangent", -// -// "Equal Product", -// "Ratio", -// -// "Special Angle", -// "Angles Equation", -// "Segment Equation" + /** + * Checks if the selected item is valid. + * + * @return true if the selected item is valid, false otherwise + */ public boolean checkValid() { int id = bt.getSelectedIndex(); return checkValid(id); - } + /** + * Checks if the selected item with the given ID is valid. + * + * @param id the ID of the selected item + * @return true if the selected item is valid, false otherwise + */ public boolean checkValid(int id) { switch (id) { case 0: // COLLINEAR @@ -572,12 +631,10 @@ public boolean checkValid(int id) { return DrawBase.check_eqdistance(vspt(0, 0), vspt(0, 1), vspt(1, 0), vspt(1, 1)); case 6: return DrawBase.check_eqangle(vspt(0, 0), vspt(0, 1), vspt(0, 2), vspt(0, 3), vspt(1, 0), vspt(1, 1), vspt(1, 2), vspt(1, 3)); - case 7: //Similiar Triangle return DrawBase.check_simtri(vspt(0, 0), vspt(0, 1), vspt(0, 2), vspt(1, 0), vspt(1, 1), vspt(1, 2)); case 8: //Congruent Triangle return DrawBase.check_congtri(vspt(0, 0), vspt(0, 1), vspt(0, 2), vspt(1, 0), vspt(1, 1), vspt(1, 2)); - case 9: //Equilateral Triangle return DrawBase.check_eqdistance(vspt(0, 0), vspt(0, 1), vspt(0, 1), vspt(0, 2)) && DrawBase.check_eqdistance(vspt(0, 0), vspt(0, 1), vspt(0, 0), vspt(0, 2)); @@ -585,7 +642,6 @@ public boolean checkValid(int id) { return DrawBase.check_bisect(vspt(0, 0), vspt(0, 1), vspt(0, 2)); case 11: //Tangent return DrawBase.check_perp(vspt(0, 0), vspt(0, 1), vspt(0, 2), vspt(0, 1)); - case 12: { //Eq_product double d1 = DrawBase.sdistance(vspt(0, 0), vspt(0, 1)); double d2 = DrawBase.sdistance(vspt(0, 2), vspt(0, 3)); @@ -598,12 +654,16 @@ public boolean checkValid(int id) { int t2 = getRatioValue(2); return DrawBase.check_eqdistance(vspt(0, 0), vspt(0, 1), vspt(1, 0), vspt(1, 1), t1, t2); } - } return false; } - + /** + * Returns the ratio value from the combo box. + * + * @param id the ID of the combo box (1 or 2) + * @return the ratio value + */ private int getRatioValue(int id) { if (id == 1) { String s1 = bx1.getSelectedItem().toString(); @@ -616,25 +676,11 @@ private int getRatioValue(int id) { } } - public MAssertion getProveM() { - int id = bt.getSelectedIndex(); - if (id < 0) return null; - MAssertion ass = new MAssertion(id); - for (int i = 0; i < vlist.size(); i++) { - JComboBox b = (JComboBox) vlist.get(i); - if (b.isEnabled() && b.getSelectedIndex() < 0) { - ass.addItem(b.getSelectedItem()); - } - } - for (int i = 0; i < vlist1.size(); i++) { - JComboBox b = (JComboBox) vlist1.get(i); - if (b.isEnabled() && b.getSelectedIndex() < 0) { - ass.addItem(b.getSelectedItem()); - } - } - return ass; - } - + /** + * Returns the conclusion based on the selected points and type. + * + * @return the conclusion object + */ public Cons getProve() { JComboBox box1 = (JComboBox) vlist.get(0); if (box1.getItemCount() == 0) return null; @@ -690,14 +736,6 @@ public Cons getProve() { return c; } - public String getSpecialAngle() { - Object o = bx1.getSelectedItem(); - if (o != null) - return o.toString(); - else - return null; - } - class condPane extends JPanel implements ActionListener { JComboBox[] bx = new JComboBox[3]; @@ -709,6 +747,10 @@ class condPane extends JPanel implements ActionListener { JPopupMenu mint; + /** + * Constructs a condPane object. + * Initializes the layout, buttons, combo boxes, and other components. + */ public condPane() { this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); field.setFont(font); @@ -757,6 +799,9 @@ public condPane() { field.setFocusable(true); } + /** + * Clears the text field and resets the combo boxes. + */ public void clear() { field.setText(""); bx[0].setSelectedIndex(-1); @@ -767,6 +812,12 @@ public void clear() { ltext1.setText(""); } + /** + * Sets the status of the condPane. + * Updates the visibility and enabled state of the combo boxes based on the status. + * + * @param s the status to set (0 for segment, 1 for angle) + */ public void setStatus(int s) { if (s == 0) { bx[2].setVisible(false); @@ -783,13 +834,16 @@ public void setStatus(int s) { bx[2].setSelectedIndex(-1); } + /** + * Handles action events for the buttons and menu items. + * + * @param e the ActionEvent triggered by the user + */ public void actionPerformed(ActionEvent e) { Object o = e.getSource(); if (o == b3) { - { - addPtsText1(); - addText(" * "); - } + addPtsText1(); + addText(" * "); } else if (o == b1) { addPtsText1(); addText(" + "); @@ -799,9 +853,9 @@ public void actionPerformed(ActionEvent e) { } else if (o == b4) { addPtsText1(); addText(" = "); - } else if (o == b5) + } else if (o == b5) { mint.show(b5, 0, b5.getHeight()); - else if (o == badd) { + } else if (o == badd) { addText(getPts()); } else { String s = e.getActionCommand(); @@ -809,17 +863,30 @@ else if (o == badd) { } } + /** + * Adds the selected points text to the field if the add button is enabled. + */ public void addPtsText1() { if (!badd.isEnabled()) return; addText(getPts()); } + /** + * Appends the specified text to the field and unselects the combo boxes. + * + * @param s the text to add + */ public void addText(String s) { field.setText(field.getText() + s); unselect(); } + /** + * Sets the points in the combo boxes. + * + * @param v the vector of points to set + */ public void setPoints(Vector v) { for (int i = 0; i < 3; i++) { bx[i].removeAllItems(); @@ -831,6 +898,11 @@ public void setPoints(Vector v) { } } + /** + * Selects a point in the combo boxes. + * + * @param o the point to select + */ public void selectAPoint(Object o) { boolean set = false; for (int i = 0; i < 3; i++) { @@ -839,13 +911,17 @@ public void selectAPoint(Object o) { if (set == false) { bx[i].setSelectedItem(o); set = true; - } else + } else { return; + } } } badd.setEnabled(true); } + /** + * Unselects all combo boxes and disables the add button. + */ public void unselect() { for (int i = 0; i < 3; i++) { bx[i].setSelectedIndex(-1); @@ -853,18 +929,11 @@ public void unselect() { badd.setEnabled(false); } - public void getSelected(Vector v) { - for (int i = 0; i < 3 && bx[i].isEnabled(); i++) { - Object obj = bx[i].getSelectedItem(); - if (obj != null) - v.add(obj); - else { - v.clear(); - return; - } - } - } - + /** + * Returns the selected points as a string. + * + * @return the selected points + */ public String getPts() { String s = ""; for (int i = 0; i < 3 && bx[i].isEnabled(); i++) { @@ -874,6 +943,11 @@ public String getPts() { return s; } + /** + * Returns the value of the text field. + * + * @return the value of the text field + */ public String getValue() { return field.getText(); } diff --git a/src/main/java/wprover/ConcPanel.java b/src/main/java/wprover/ConcPanel.java index 5da06604..a82587a0 100644 --- a/src/main/java/wprover/ConcPanel.java +++ b/src/main/java/wprover/ConcPanel.java @@ -8,11 +8,8 @@ import java.awt.event.*; /** - * Created by IntelliJ IDEA. - * User: yezheng - * Date: 2006-7-5 - * Time: 13:25:43 - * To change this template use File | Settings | File Templates. + * ConcPanel is a JPanel that provides a user interface for selecting geometric assertions. + * It allows users to select points and check the validity of assertions based on the selected points. */ public class ConcPanel extends JPanel implements ActionListener, ItemListener { @@ -34,20 +31,35 @@ public class ConcPanel extends JPanel implements ActionListener, ItemListener { private MProveInputPanel ipanel = null; + /** + * Constructs a ConcPanel with the specified GExpert instance. + * Initializes the panel and sets the selected index of the combo box to -1. + * + * @param gx the GExpert instance + */ public ConcPanel(GExpert gx) { gxInstance = gx; init(); bt.setSelectedIndex(-1); } + /** + * Constructs a ConcPanel with the specified GExpert instance and MProveInputPanel. + * Calls the other constructor and sets the input panel. + * + * @param gx the GExpert instance + * @param ipanel the MProveInputPanel instance + */ public ConcPanel(GExpert gx, MProveInputPanel ipanel) { this(gx); this.ipanel = ipanel; } - + /** + * Initializes the ConcPanel. + * Sets up the layout, combo boxes, panels, and other components. + */ private void init() { - this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); contentPane = new JPanel(); contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS)); @@ -127,11 +139,22 @@ public Dimension getMaximumSize() { ass_show = new MAssertion(0); } + /** + * Sets the selected index of the combo box and revalidates the state. + * + * @param k the index to set + */ public void setTypeSelection(int k) { bt.setSelectedIndex(k); this.revalidateValidState(); } + /** + * Sets the user object for the panel. + * Resets all items and updates the combo box and points based on the provided assertion. + * + * @param as the MAssertion object to set + */ public void setUserObject(MAssertion as) { this.resetAllItem(); ass = as; @@ -143,10 +166,14 @@ public void setUserObject(MAssertion as) { } else { bt.setSelectedIndex(-1); } - - } + /** + * Returns the user object for the panel. + * Creates or updates the assertion object based on the selected points. + * + * @return the MObject representing the assertion + */ public MObject getUserObject() { if (ass == null) ass = new MAssertion(bt.getSelectedIndex()); @@ -170,10 +197,18 @@ public MObject getUserObject() { return ass; } + /** + * Updates the points in the panel based on the current point list from the GExpert instance. + */ public void update() { this.setPoints(gxInstance.dp.getPointList()); } + /** + * Sets the value of the ltext1 label based on the given boolean. + * + * @param t the boolean value to set + */ private void setLtext1Value(boolean t) { if (t) { ltext1.setText(""); @@ -184,11 +219,11 @@ private void setLtext1Value(boolean t) { } } - public int getPointsCount() { - JComboBox b = (JComboBox) vlist.get(0); - return b.getItemCount(); - } - + /** + * Sets the points in the combo boxes based on the provided vector of points. + * + * @param v the vector of points to set + */ public void setPoints(Vector v) { for (int i = 0; i < vlist.size(); i++) { JComboBox b = (JComboBox) vlist.get(i); @@ -208,6 +243,11 @@ public void setPoints(Vector v) { } } + /** + * Returns the number of points left to be selected. + * + * @return the number of points left to be selected + */ private int ptLeftTobeSelect() { int n = this.getStatePointsCount(); @@ -226,6 +266,10 @@ private int ptLeftTobeSelect() { return n; } + /** + * Revalidates the state of the panel based on the current input. + * Checks if the input is finished and updates the validity state and combo box accordingly. + */ public void revalidateValidState() { if (inputFinished()) { boolean v = checkValid(); @@ -239,6 +283,12 @@ public void revalidateValidState() { ltext1.setIcon(icon_Question); } + /** + * Handles item state changes for the combo boxes. + * Resets all items, updates the combo box and points, and revalidates the state. + * + * @param e the ItemEvent triggered by the user + */ public void itemStateChanged(ItemEvent e) { if (!this.isVisible()) return; @@ -265,9 +315,13 @@ public void itemStateChanged(ItemEvent e) { ltext1.setIcon(icon_Question); updateBState(); - } + /** + * Updates the state of the button in the input panel based on the current selection. + * If the input panel is not null and the input is finished or the selected index is CONVEX, + * it sets the button state to true, otherwise sets it to false. + */ public void updateBState() { if (ipanel != null) { if (inputFinished() || bt.getSelectedIndex() == MAssertion.CONVEX) @@ -277,6 +331,12 @@ public void updateBState() { } } + /** + * Creates an assertion based on the selected points. + * Initializes or updates the assertion object and adds selected points to it. + * + * @return true if the assertion is valid, false otherwise + */ private boolean createAssertion() { if (ass_show == null) ass_show = new MAssertion(bt.getSelectedIndex()); @@ -296,8 +356,12 @@ private boolean createAssertion() { return ass_show.checkValid(); } + /** + * Checks if the input is finished by verifying that all enabled combo boxes have a selected item. + * + * @return true if the input is finished, false otherwise + */ private boolean inputFinished() { -// return 0 == ptLeftTobeSelect(); for (int i = 0; i < vlist.size(); i++) { JComboBox b = (JComboBox) vlist.get(i); if (b.isEnabled() && b.getSelectedIndex() < 0) { @@ -313,6 +377,10 @@ private boolean inputFinished() { return true; } + /** + * Displays a tip text indicating the number of points left to be selected. + * Updates the assertion panel with the appropriate message. + */ private void showTipText() { int n = ptLeftTobeSelect(); @@ -326,8 +394,13 @@ private void showTipText() { } } + /** + * Selects a point in the combo boxes. + * Sets the selected item in the first available enabled combo box. + * + * @param p the point to select + */ public void selectAPoint(CPoint p) { - for (int i = 0; i < vlist.size(); i++) { JComboBox b = (JComboBox) vlist.get(i); if (b.isEnabled() && b.getSelectedIndex() < 0) { @@ -343,9 +416,11 @@ public void selectAPoint(CPoint p) { } } asspane.repaint(); -// this.repaint(); } + /** + * Resets all combo boxes by setting their selected index to -1. + */ private void resetAllItem() { for (int i = 0; i < vlist.size(); i++) { JComboBox b = (JComboBox) vlist.get(i); @@ -355,9 +430,13 @@ private void resetAllItem() { JComboBox b = (JComboBox) vlist1.get(i); b.setSelectedIndex(-1); } - } + /** + * Returns the number of points required for the selected assertion type. + * + * @return the number of points required + */ private int getStatePointsCount() { switch (bt.getSelectedIndex()) { case MAssertion.COLL: @@ -386,6 +465,11 @@ private int getStatePointsCount() { return -1; } + /** + * Sets the visibility and enabled state of the combo boxes based on the selected assertion type. + * + * @param id the selected assertion type + */ private void setItemChanged(int id) { switch (id) { case MAssertion.COLL: @@ -423,7 +507,6 @@ private void setItemChanged(int id) { case MAssertion.ANGLE_INSIDE: case MAssertion.ANGLE_OUTSIDE: case MAssertion.TRIANGLE_INSIDE: - this.setVisibleBox2(3); break; case MAssertion.BETWEEN: @@ -438,10 +521,15 @@ private void setItemChanged(int id) { default: CMisc.print("massertion " + id + " not found"); break; - } } + /** + * Handles action events for the buttons. + * Resets all items and updates the assertion based on the temporary assertion. + * + * @param e the ActionEvent triggered by the user + */ public void actionPerformed(ActionEvent e) { String command = e.getActionCommand(); Object obj = e.getSource(); @@ -458,9 +546,13 @@ public void actionPerformed(ActionEvent e) { } else { } bpanel.setVisible(false); - } + /** + * Sets the visibility and enabled state of the combo boxes based on the specified number. + * + * @param num the number of combo boxes to be visible and enabled + */ private void setVisibleBox2(int num) { int k = 1; for (int i = 0; i < vlist.size(); i++) { @@ -486,9 +578,13 @@ private void setVisibleBox2(int num) { obj.setVisible(false); } } - } +/** + * Sets the visibility and enabled state of the first set of combo boxes based on the specified number. + * + * @param num the number of combo boxes to be visible and enabled + */ private void setVisibleBox1(int num) { int k = num / 2; for (int i = 0; i < vlist.size(); i++) { @@ -513,6 +609,11 @@ private void setVisibleBox1(int num) { } } + /** + * Sets the visibility and enabled state of the combo boxes based on the specified number. + * + * @param num the number of combo boxes to be visible and enabled + */ private void setVisibleBox(int num) { for (int i = 0; i < vlist.size(); i++) { JComboBox obj = (JComboBox) vlist.get(i); @@ -531,6 +632,13 @@ private void setVisibleBox(int num) { } } + /** + * Returns the selected item from the specified combo box as a string. + * + * @param id1 the index of the combo box list (0 for vlist, 1 for vlist1) + * @param id2 the index of the combo box within the list + * @return the selected item as a string, or an empty string if the index is out of bounds + */ private String vs(int id1, int id2) { if (id1 == 0) { JComboBox box = ((JComboBox) vlist.get(id2)); @@ -556,9 +664,15 @@ private String vs(int id1, int id2) { return obj.toString(); } } - } + /** + * Returns the selected item from the specified combo box as a CPoint. + * + * @param id1 the index of the combo box list (0 for vlist, 1 for vlist1) + * @param id2 the index of the combo box within the list + * @return the selected item as a CPoint, or null if the index is out of bounds + */ private CPoint vspt(int id1, int id2) { if (id1 == 0) { JComboBox box = ((JComboBox) vlist.get(id2)); @@ -585,6 +699,11 @@ private CPoint vspt(int id1, int id2) { } } + /** + * Checks the validity of the selected geometric assertion based on the selected points. + * + * @return true if the assertion is valid, false otherwise + */ private boolean checkValid() { int id = bt.getSelectedIndex(); if (!inputFinished()) return false; @@ -605,16 +724,14 @@ private boolean checkValid() { return DrawBase.check_eqangle(vspt(0, 0), vspt(0, 1), vspt(0, 2), vspt(1, 0), vspt(1, 1), vspt(1, 2)); case 7: return DrawBase.check_congtri(vspt(0, 0), vspt(0, 1), vspt(0, 2), vspt(1, 0), vspt(1, 1), vspt(1, 2)); - case 8: return DrawBase.check_simtri(vspt(0, 0), vspt(0, 1), vspt(0, 2), vspt(1, 0), vspt(1, 1), vspt(1, 2)); - case 9: return DrawBase.check_distance_less(vspt(0, 0), vspt(0, 1), vspt(1, 0), vspt(1, 1)); case 10: return DrawBase.check_angle_less(vspt(0, 0), vspt(0, 1), vspt(0, 2), vspt(1, 0), vspt(1, 1), vspt(1, 2)); case 11: -// return drawbase.check_concurrent(); + // return drawbase.check_concurrent(); case 12: return DrawBase.check_perp(vspt(0, 0), vspt(1, 1), vspt(1, 0), vspt(0, 1)); case 13: @@ -644,7 +761,6 @@ private boolean checkValid() { case MAssertion.ANGLE_INSIDE: return DrawBase.check_angle_less(vspt(0, 0), vspt(1, 1), vspt(1, 2), vspt(1, 0), vspt(1, 1), vspt(1, 2)) && DrawBase.check_angle_less(vspt(0, 0), vspt(1, 1), vspt(1, 0), vspt(1, 0), vspt(1, 1), vspt(1, 2)); - case MAssertion.ANGLE_OUTSIDE: return !(DrawBase.check_angle_less(vspt(0, 0), vspt(1, 1), vspt(1, 2), vspt(1, 0), vspt(1, 1), vspt(1, 2)) && DrawBase.check_angle_less(vspt(0, 0), vspt(1, 1), vspt(1, 0), vspt(1, 0), vspt(1, 1), vspt(1, 2))); @@ -653,38 +769,21 @@ private boolean checkValid() { case MAssertion.PARA_INSIDE: return DrawBase.check_triangle_inside(vspt(0, 0), vspt(1, 0), vspt(1, 1), vspt(1, 2)) || DrawBase.check_triangle_inside(vspt(0, 0), vspt(1, 0), vspt(1, 2), vspt(1, 3)); - case MAssertion.OPPOSITE_SIDE: return !DrawBase.check_same_side(vspt(0, 0), vspt(0, 1), vspt(1, 0), vspt(1, 1)); case MAssertion.SAME_SIDE: return DrawBase.check_same_side(vspt(0, 0), vspt(0, 1), vspt(1, 0), vspt(1, 1)); case MAssertion.CONVEX: return true; - } return true; } - - public MAssertion getProveM() { - int id = bt.getSelectedIndex(); - if (id < 0) return null; - MAssertion ass = new MAssertion(id); - for (int i = 0; i < vlist.size(); i++) { - JComboBox b = (JComboBox) vlist.get(i); - if (b.isEnabled() && b.getSelectedIndex() < 0) { - ass.addItem(b.getSelectedItem()); - } - } - for (int i = 0; i < vlist1.size(); i++) { - JComboBox b = (JComboBox) vlist1.get(i); - if (b.isEnabled() && b.getSelectedIndex() < 0) { - ass.addItem(b.getSelectedItem()); - } - } - return ass; - } - + /** + * Returns the proof statement for the selected geometric assertion. + * + * @return the proof statement as a string, or "Not Yet Supported Conclusion" if the assertion type is not supported + */ public String getProve() { JComboBox box1 = (JComboBox) vlist.get(0); if (box1.getItemCount() == 0) return ""; @@ -715,37 +814,9 @@ public String getProve() { return "Not Yet Supported Conclusion"; } - public String getProveDescription() { - JComboBox box1 = (JComboBox) vlist.get(0); - if (box1.getItemCount() == 0) return ""; - if (!this.inputFinished()) return ""; - - int id = bt.getSelectedIndex(); - - switch (id) { - case MAssertion.COLL: - return vs(0, 0) + " " + vs(0, 1) + " " + vs(0, 2) + " are collinear;"; - case MAssertion.PARA: - return vs(0, 0) + " " + vs(0, 1) + " is Parallel to " + vs(1, 0) + " " + vs(1, 1) + ";"; - case MAssertion.PERP: - return vs(0, 0) + " " + vs(0, 1) + " is Perpendicular to " + vs(1, 0) + " " + vs(1, 1) + ";"; - case MAssertion.MID: - return vs(0, 0) + " is the midpoint of " + vs(0, 1) + " " + vs(0, 2) + ";"; - case MAssertion.CYCLIC: - return vs(0, 0) + " " + vs(0, 1) + " " + vs(0, 2) + " " + vs(0, 3) + " are cyclic;"; - case MAssertion.EQDIS: - return vs(0, 0) + " " + vs(0, 1) + " equals to " + vs(1, 0) + " " + vs(1, 1) + ";"; - case MAssertion.EQANGLE: - return Cm.ANGLE_SIGN + vs(0, 0) + vs(0, 1) + vs(0, 2) + " = " + Cm.ANGLE_SIGN + vs(1, 0) + vs(1, 1) + vs(1, 2); - - case MAssertion.SIM: - return "tri " + vs(0, 0) + vs(0, 1) + vs(0, 2) + " is similiar to " + "tri " + vs(1, 0) + vs(1, 1) + vs(1, 2); - case MAssertion.CONG: - return "tri " + vs(0, 0) + vs(0, 1) + vs(0, 2) + " is equal to " + "tri " + vs(1, 0) + vs(1, 1) + vs(1, 2); - } - return "Not Yet Supported Conclusion"; - } - + /** + * Shows the correct order of points for the selected geometric assertion. + */ private void showCorrentOrder() { JComboBox box1 = (JComboBox) vlist.get(0); if (box1.getItemCount() == 0) return; @@ -789,10 +860,11 @@ else if (id == MAssertion.CONG) bpanel.setVisible(true); } } - - } + /** + * Cancels the current assertion and resets all combo boxes. + */ public void cancel() { ass = null; this.resetAllItem(); diff --git a/src/main/java/wprover/Constraint.java b/src/main/java/wprover/Constraint.java index 3b3fe328..7c1880f4 100644 --- a/src/main/java/wprover/Constraint.java +++ b/src/main/java/wprover/Constraint.java @@ -12,7 +12,11 @@ import maths.Param; import maths.TMono; - +/** + * The Constraint class represents a geometric constraint in a geometric construction. + * It contains methods to generate and manipulate constraints, as well as to calculate + * polynomial representations of the constraints. + */ public class Constraint { final public static int NULLTYPE = 0; final public static int PONLINE = 11; // collinear @@ -114,6 +118,11 @@ public class Constraint { Cons csd = null; Cons csd1 = null; + /** + * Retrieves the polynomial list and sets it to null. + * + * @return the current polynomial list + */ public static TPoly getPolyListAndSetNull() { TPoly pl = polylist; polylist = null; @@ -125,10 +134,21 @@ public static TPoly getPolyListAndSetNull() { return pl; } + /** + * Gets the type of the constraint. + * + * @return the type of the constraint + */ public int GetConstraintType() { return this.ConstraintType; } + /** + * Retrieves an element from the element list at the specified index. + * + * @param i the index of the element to retrieve + * @return the element at the specified index, or null if the index is out of bounds + */ public Object getelement(int i) { if (i >= 0 && i < elementlist.size()) return elementlist.get(i); @@ -136,35 +156,45 @@ public Object getelement(int i) { return null; } - public CPoint getLPoints2(CPoint p1, CPoint p2) { - for (int i = 0; i < elementlist.size(); i++) { - CPoint p = (CPoint) elementlist.get(i); - if (p != p1 && p != p2) - return p; - } - return null; - } - - public boolean cotainPoints(CPoint p1, CPoint p2) { - return elementlist.contains(p1) && elementlist.contains(p2); - } - + /** + * Retrieves all elements in the element list. + * + * @return a vector containing all elements in the element list + */ public Vector getAllElements() { Vector v = new Vector(); v.addAll(elementlist); return v; } + /** + * Constructs a Constraint with the specified ID. + * + * @param id the ID of the constraint + */ public Constraint(int id) { this.id = id; } + /** + * Calculates the polynomial representation using the given parameters. + * + * @param para an array of parameters to use for the calculation + */ public void calculate(Param[] para) { if (polylist == null) return; poly.calculv(polylist.getPoly(), para); is_poly_genereate = false; } +/** + * Constructs a Constraint with two elements and optionally generates the polynomial. + * + * @param type the type of the constraint + * @param obj1 the first element + * @param obj2 the second element + * @param gpoly true if the polynomial should be generated, false otherwise + */ public Constraint(int type, Object obj1, Object obj2, boolean gpoly) { this.ConstraintType = type; elementlist.add(obj1); @@ -175,19 +205,37 @@ public Constraint(int type, Object obj1, Object obj2, boolean gpoly) { } } + /** + * Constructs a Constraint with a list of elements and generates the polynomial. + * + * @param type the type of the constraint + * @param olist a vector containing the elements + */ public Constraint(int type, Vector olist) { this.ConstraintType = type; elementlist.addAll(olist); PolyGenerate(); } + /** + * Constructs a Constraint with a single element. + * + * @param type the type of the constraint + * @param obj the element + */ public Constraint(int type, Object obj) { this.ConstraintType = type; elementlist.add(obj); } - public Constraint(int type, Object obj1, Object obj2)// - { + /** + * Constructs a Constraint with two elements and generates the polynomial if required. + * + * @param type the type of the constraint + * @param obj1 the first element + * @param obj2 the second element + */ + public Constraint(int type, Object obj1, Object obj2) { this.ConstraintType = type; elementlist.add(obj1); elementlist.add(obj2); @@ -203,6 +251,15 @@ else if (type == PERPENDICULAR) { } } + /** + * Constructs a Constraint with three elements and a proportion, and generates the polynomial if required. + * + * @param type the type of the constraint + * @param obj1 the first element + * @param obj2 the second element + * @param obj3 the third element + * @param prop the proportion + */ public Constraint(int type, Object obj1, Object obj2, Object obj3, int prop) { this.ConstraintType = type; elementlist.add(obj1); @@ -211,18 +268,33 @@ public Constraint(int type, Object obj1, Object obj2, Object obj3, int prop) { this.proportion = prop; if (is_poly_genereate) PolyGenerate(); - } + /** + * Constructs a Constraint with a single element and a proportion, and generates the polynomial if required. + * + * @param type the type of the constraint + * @param obj1 the element + * @param prop the proportion + */ public Constraint(int type, Object obj1, int prop) { this.ConstraintType = type; elementlist.add(obj1); this.proportion = prop; if (is_poly_genereate) PolyGenerate(); - } + /** + * Constructs a Constraint with four elements and a proportion, and generates the polynomial if required. + * + * @param type the type of the constraint + * @param obj1 the first element + * @param obj2 the second element + * @param obj3 the third element + * @param obj4 the fourth element + * @param prop the proportion + */ public Constraint(int type, Object obj1, Object obj2, Object obj3, Object obj4, int prop) { this.ConstraintType = type; elementlist.add(obj1); @@ -234,6 +306,16 @@ public Constraint(int type, Object obj1, Object obj2, Object obj3, Object obj4, PolyGenerate(); } + /** + * Constructs a Constraint with five elements and generates the polynomial if required. + * + * @param type the type of the constraint + * @param obj1 the first element + * @param obj2 the second element + * @param obj3 the third element + * @param obj4 the fourth element + * @param obj5 the fifth element + */ public Constraint(int type, Object obj1, Object obj2, Object obj3, Object obj4, Object obj5) { this.ConstraintType = type; addelement(obj1); @@ -245,8 +327,15 @@ public Constraint(int type, Object obj1, Object obj2, Object obj3, Object obj4, PolyGenerate(); } - public Constraint(int type, Object obj1, Object obj2, Object obj3)// - { + /** + * Constructs a Constraint with three elements and generates the polynomial if required. + * + * @param type the type of the constraint + * @param obj1 the first element + * @param obj2 the second element + * @param obj3 the third element + */ + public Constraint(int type, Object obj1, Object obj2, Object obj3) { this.ConstraintType = type; addelement(obj1); addelement(obj2); @@ -255,13 +344,26 @@ public Constraint(int type, Object obj1, Object obj2, Object obj3)// PolyGenerate(); } + /** + * Adds an element to the element list if it is not null. + * + * @param obj the element to be added + */ public void addelement(Object obj) { if (obj != null) elementlist.add(obj); } - public Constraint(int type, Object obj1, Object obj2, Object obj3, Object obj4)// - { + /** + * Constructs a Constraint with four elements and generates the polynomial if required. + * + * @param type the type of the constraint + * @param obj1 the first element + * @param obj2 the second element + * @param obj3 the third element + * @param obj4 the fourth element + */ + public Constraint(int type, Object obj1, Object obj2, Object obj3, Object obj4) { this.ConstraintType = type; addelement(obj1); addelement(obj2); @@ -271,8 +373,18 @@ public Constraint(int type, Object obj1, Object obj2, Object obj3, Object obj4)/ PolyGenerate(); } - public Constraint(int type, Object obj1, Object obj2, Object obj3, Object obj4, Object obj5, Object obj6)// - { + /** + * Constructs a Constraint with six elements and generates the polynomial if required. + * + * @param type the type of the constraint + * @param obj1 the first element + * @param obj2 the second element + * @param obj3 the third element + * @param obj4 the fourth element + * @param obj5 the fifth element + * @param obj6 the sixth element + */ + public Constraint(int type, Object obj1, Object obj2, Object obj3, Object obj4, Object obj5, Object obj6) { this.ConstraintType = type; addelement(obj1); addelement(obj2); @@ -284,19 +396,38 @@ public Constraint(int type, Object obj1, Object obj2, Object obj3, Object obj4, PolyGenerate(); } - + /** + * Sets whether the polynomial should be generated. + * + * @param r true if the polynomial should be generated, false otherwise + */ public void setPolyGenerate(boolean r) { is_poly_genereate = r; } + /** + * Adds an element to the element list. + * + * @param obj the element to be added + */ public void addElement(Object obj) { elementlist.add(obj); } + /** + * Returns the message representation of the constraint. + * + * @return the message representation of the constraint + */ String getMessage() { return toString(); } + /** + * Returns the string representation of the constraint. + * + * @return the string representation of the constraint + */ public String toString() { if (csd != null) return csd.toDString(); @@ -352,7 +483,6 @@ else if (i == 3) case PERPBISECT: return e1.TypeString() + " is on the perpendicular bisector of " + e2.m_name + " " + e3.TypeString(); case MIRROR: - case PRATIO: return "o(" + e1.m_name + e2.m_name + ") / " + "o(" + e3.m_name + e4.m_name + ") = 1 : " + this.proportion; case LRATIO: @@ -368,24 +498,31 @@ else if (i == 3) return "set " + e1.TypeString() + e2.TypeString() + " a horizonal line"; case VERTICAL: return "set " + e1.TypeString() + e2.TypeString() + " a vertical line"; - } return new String(); } + /** + * Clears all constraints by setting the constraint descriptors to null. + */ public void clear_all_cons() { csd = null; csd1 = null; } + /** + * Generates the polynomial representation based on the constraint type. + * + * @return a TPoly object representing the generated polynomial list + */ TPoly PolyGenerate() { TMono tm = null; TPoly tp = null; switch (this.ConstraintType) { case LINE: -// this.add_des(gib.C_LINE, elementlist); + // this.add_des(gib.C_LINE, elementlist); break; case CIRCLE: this.add_des(Gib.C_CIRCLE, elementlist); @@ -423,7 +560,7 @@ TPoly PolyGenerate() { case PONLINE: // p_o_L tm = this.PolyOnLine(); break; - case PONCIRCLE: // p_o_C + case PONCIRCLE: // p_o_C tm = this.PolyOnCircle(); break; case INTER_LL: @@ -435,43 +572,42 @@ TPoly PolyGenerate() { case INTER_CC: tp = PolyIntersection_CC(); break; - case PARALLEL: // P_O_P + case PARALLEL: // P_O_P tm = this.PolyParel(); break; - case PERPENDICULAR: // p_o_T + case PERPENDICULAR: // p_o_T tm = this.PolyPerp(); break; - case PFOOT: // LT + case PFOOT: // LT tp = this.PolyPfoot(); break; - case MIDPOINT: // MID + case MIDPOINT: // MID tp = this.PolyMidPoint(); break; - case EQDISTANCE: // + case EQDISTANCE: tm = this.PolyEqidstance(); break; - case EQANGLE: // P_O_A + case EQANGLE: // P_O_A tm = this.PolyEqAngle(); break; - case COLLINEAR: // P_O_L + case COLLINEAR: // P_O_L tm = this.collinear(); break; case CCTANGENT: tm = this.PolyCCTangent(); break; - case CCLine: { - } - break; + case CCLine: + break; case TRATIO: tp = this.PolyTRatio(); break; - case PERPBISECT: // p_O_B + case PERPBISECT: // p_O_B tm = this.PolyPerpBisect(); break; case ISO_TRIANGLE: tm = PolyISOTriangle(); break; - case MIRROR: // P_REF + case MIRROR: // P_REF tp = this.PolyMirror(); break; case PRATIO: @@ -480,7 +616,7 @@ TPoly PolyGenerate() { case LRATIO: tp = this.PolyPropPoint(); break; - case CIRCUMCENTER: // P_CIR + case CIRCUMCENTER: // P_CIR tp = this.PolyCircumCenter(); break; case BARYCENTER: @@ -581,7 +717,6 @@ TPoly PolyGenerate() { case CONSTANT: tm = PolyConstant(); break; - } if (tm != null) { @@ -594,6 +729,11 @@ TPoly PolyGenerate() { return polylist; } + /** + * Adds a polynomial to the polynomial list. + * + * @param tp the polynomial to be added + */ public void addPoly(TPoly tp) { TPoly t = tp; while (t.getNext() != null) @@ -602,20 +742,11 @@ public void addPoly(TPoly tp) { polylist = tp; } - public boolean optimizePolygon(TPoly p) { - boolean a = false; - while (p != null) { - TMono m = p.getPoly(); - if (m != null && poly.plength(m) == 1) { - boolean d = poly.addZeroN(m.x); - if (d) - a = true; - } - p = p.getNext(); - } - return a; - } - + /** + * Computes the polynomial representation of a constant. + * + * @return a TMono object representing the constant + */ TMono PolyConstant() { String t1 = elementlist.get(0).toString(); String t2 = elementlist.get(1).toString(); @@ -624,6 +755,11 @@ TMono PolyConstant() { return parseTMonoString(t1, t2, p1.xindex); } + /** + * Computes the polynomial representation of points on a line. + * + * @return a TMono object representing the points on a line + */ TMono PolyONALine() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -646,6 +782,11 @@ TMono PolyONALine() { } } + /** + * Computes the polynomial representation of points on a circle. + * + * @return a TMono object representing the points on a circle + */ TMono PolyONRCircle() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -656,6 +797,11 @@ TMono PolyONRCircle() { p4.x1.xindex, p4.y1.xindex, p3.x1.xindex, p3.y1.xindex); } + /** + * Computes the polynomial representation of points on a perpendicular circle. + * + * @return a TMono object representing the points on a perpendicular circle + */ TMono PolyONDCircle() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -665,6 +811,11 @@ TMono PolyONDCircle() { p1.x1.xindex, p1.y1.xindex, p3.x1.xindex, p3.y1.xindex); } + /** + * Computes the polynomial representation of points on an AB line. + * + * @return a TMono object representing the points on an AB line + */ TMono PolyONABLine() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -676,6 +827,11 @@ TMono PolyONABLine() { p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex); } + /** + * Computes the polynomial representation of points on a cyclic circle. + * + * @return a TMono object representing the points on a cyclic circle + */ TMono PolyONSCircle() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -686,6 +842,11 @@ TMono PolyONSCircle() { p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex); } + /** + * Computes the polynomial representation of a tangent line to two circles. + * + * @return a TPoly object representing the tangent line to two circles + */ TPoly PolyCCTangentLine() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -704,9 +865,13 @@ TPoly PolyCCTangentLine() { TPoly poly2 = this.NewTPoly(m3, m4); poly1.getNext().setNext(poly2); return poly1; - } + /** + * Computes the polynomial representation of a ratio. + * + * @return a TMono object representing the ratio + */ TMono PolyRatio() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -723,6 +888,11 @@ TMono PolyRatio() { p7.x1.xindex, p7.y1.xindex, p8.x1.xindex, p8.y1.xindex); } + /** + * Computes the polynomial representation of a bisected line. + * + * @return a TMono object representing the bisected line + */ TMono PolyBLine() { CPoint p1 = (CPoint) elementlist.get(1); CPoint p2 = (CPoint) elementlist.get(2); @@ -734,9 +904,13 @@ TMono PolyBLine() { add_des(Gib.C_O_B, p, p1, p2); return poly.bisect1(p.x1.xindex, p.y1.xindex, p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex); } - } + /** + * Computes the polynomial representation of a tangent line to a circle. + * + * @return a TMono object representing the tangent line to a circle + */ TMono PolyTCLine() { Circle c = (Circle) elementlist.get(0); CLine ln = (CLine) elementlist.get(1); @@ -755,9 +929,13 @@ TMono PolyTCLine() { return poly.perpendicular(p.x1.xindex, p.y1.xindex, p1.x1.xindex, p1.y1.xindex, p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex); } - } + /** + * Computes the polynomial representation of a circle passing through three points. + * + * @return a TPoly object representing the circle passing through three points + */ TPoly PolyCircle3P() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -769,6 +947,11 @@ TPoly PolyCircle3P() { p4.x1.xindex, p4.y1.xindex); } + /** + * Computes the polynomial representation of an angle bisector. + * + * @return a TMono object representing the angle bisector + */ TMono PolyAngleBisector() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -784,8 +967,12 @@ TMono PolyAngleBisector() { return null; } - TPoly PolyPsym() // p1 is the mirror of p2 through p3 - { + /** + * Computes the polynomial representation of a symmetric point. + * + * @return a TPoly object representing the symmetric point + */ + TPoly PolyPsym() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); CPoint p3 = (CPoint) elementlist.get(2); @@ -795,23 +982,11 @@ TPoly PolyPsym() // p1 is the mirror of p2 through p3 return this.NewTPoly(m1, m2); } - TPoly PolySquare() { - CPoint p1 = (CPoint) elementlist.get(0); - CPoint p2 = (CPoint) elementlist.get(1); - CPoint p3 = (CPoint) elementlist.get(2); - CPoint p4 = (CPoint) elementlist.get(3); - add_des(Gib.C_SQUARE, p1, p2, p3, p4); - TPoly t1 = poly.squarept1(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, - p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex, this.proportion); - TPoly t2 = poly.squarept2(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, - p1.x1.xindex, p1.y1.xindex, p4.x1.xindex, p4.y1.xindex, this.proportion); - TPoly t = t2; - while (t2.getNext() != null) - t2 = t2.getNext(); - t2.setNext(t1); - return t1; - } - + /** + * Computes the polynomial representation of an equilateral triangle. + * + * @return a TPoly object representing the equilateral triangle + */ TPoly PolyPeTriangle() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -820,6 +995,11 @@ TPoly PolyPeTriangle() { return poly.pn_eq_triangle(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex, true); } + /** + * Computes the polynomial representation of points on a line. + * + * @return a TMono object representing the points on a line + */ TMono polyPonALine() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -832,6 +1012,11 @@ TMono polyPonALine() { p4.x1.xindex, p4.y1.xindex, p5.x1.xindex, p5.y1.xindex, p6.x1.xindex, p6.y1.xindex); } + /** + * Computes the polynomial representation of an incenter. + * + * @return a TPoly object representing the incenter + */ TPoly PolyInCenter() { CPoint p = (CPoint) elementlist.get(0); CPoint p1 = (CPoint) elementlist.get(1); @@ -849,6 +1034,11 @@ TPoly PolyInCenter() { return this.NewTPoly(m1, m2); } + /** + * Computes the polynomial representation of an orthocenter. + * + * @return a TPoly object representing the orthocenter + */ TPoly PolyOrthoCenter() { CPoint p = (CPoint) elementlist.get(0); CPoint p1 = (CPoint) elementlist.get(1); @@ -862,9 +1052,13 @@ TPoly PolyOrthoCenter() { add_des(Gib.C_ORTH, p, p1, p2, p3); return this.NewTPoly(m1, m2); - } + /** + * Computes the polynomial representation of a symmetric point. + * + * @return a TPoly object representing the symmetric point + */ TPoly PolySymPoint() { CPoint p1 = (CPoint) elementlist.get(0); CPoint po = (CPoint) elementlist.get(1); @@ -876,6 +1070,11 @@ TPoly PolySymPoint() { return this.NewTPoly(m1, m2); } + /** + * Computes the polynomial representation of a multiple side ratio. + * + * @return a TMono object representing the multiple side ratio + */ TMono polyMulside() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -885,23 +1084,35 @@ TMono polyMulside() { Integer i2 = (Integer) elementlist.get(5); add_des(Gib.C_NRATIO, p1, p2, p3, p4, i1, i2); return poly.p_p_mulside(p1, p2, p3, p4, i1.intValue(), i2.intValue()); - - } + /** + * Computes the polynomial representation of a horizontal line. + * + * @return a TMono object representing the horizontal line + */ TMono PolyHorizonal() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); return poly.p_p_horizonal(p1, p2); } + /** + * Computes the polynomial representation of a vertical line. + * + * @return a TMono object representing the vertical line + */ TMono PolyVertical() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); return poly.p_p_vertical(p1, p2); } - + /** + * Computes the polynomial representation of a line-circle tangent. + * + * @return a TPoly object representing the line-circle tangent + */ TPoly PolyLCTangent() { CLine line1; Circle c; @@ -926,6 +1137,11 @@ TPoly PolyLCTangent() { return tp; } + /** + * Computes the polynomial representation of a circumcenter. + * + * @return a TPoly object representing the circumcenter + */ TPoly PolyCircumCenter() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -938,6 +1154,11 @@ TPoly PolyCircumCenter() { p4.x1.xindex, p4.y1.xindex); } + /** + * Computes the polynomial representation of a barycenter. + * + * @return a TPoly object representing the barycenter + */ TPoly PolyBaryCenter() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -948,7 +1169,11 @@ TPoly PolyBaryCenter() { p4.x1.xindex, p4.y1.xindex); } - + /** + * Computes the polynomial representation of a proportional point. + * + * @return a TPoly object representing the proportional point + */ TPoly PolyPropPoint() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -961,7 +1186,12 @@ TPoly PolyPropPoint() { return poly.prop_point(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex, i1.intValue(), i2.intValue()); } - TPoly PolyPratio() { // p1 is p2 + /p3p4/ + /** + * Computes the polynomial representation of a point ratio. + * + * @return a TPoly object representing the point ratio + */ + TPoly PolyPratio() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); CPoint p3 = (CPoint) elementlist.get(2); @@ -981,6 +1211,11 @@ TPoly PolyPratio() { // p1 is p2 + /p3p4/ p4.x1.xindex, p4.y1.xindex, r1, r2); } + /** + * Computes the polynomial representation of the intersection of two circles. + * + * @return a TPoly object representing the intersection of the circles + */ TPoly PolyInterCC() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -988,16 +1223,18 @@ TPoly PolyInterCC() { Circle c2 = (Circle) elementlist.get(3); CPoint p3 = c1.o; CPoint p4 = c2.o; -// add_des(gib.C_O_C, p1, p3, p2); -// add_des(gib.C_O_C, p1, p4, p2); add_des(Gib.C_I_CC, p1, p3, p2, p4, p2); return poly.mirrorPL(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex); } - TPoly PolyMirror() // p1 to p2 through obj - { + /** + * Computes the polynomial representation of a mirror point. + * + * @return a TPoly object representing the mirror point + */ + TPoly PolyMirror() { Object obj = elementlist.get(2); CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -1020,9 +1257,13 @@ TPoly PolyMirror() // p1 to p2 through obj return poly.mirrorPL(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex); } - } + /** + * Computes the polynomial representation of an isosceles triangle. + * + * @return a TMono object representing the isosceles triangle + */ TMono PolyISOTriangle() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -1033,16 +1274,25 @@ TMono PolyISOTriangle() { return poly.bisect(p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex, p1.x1.xindex, p1.y1.xindex); } + /** + * Computes the polynomial representation of a perpendicular bisector. + * + * @return a TMono object representing the perpendicular bisector + */ TMono PolyPerpBisect() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); CPoint p3 = (CPoint) elementlist.get(2); add_des(Gib.C_O_B, p1, p2, p3); - return poly.bisect(p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex, p1.x1.xindex, p1.y1.xindex); } + /** + * Computes the polynomial representation of a trapezoid. + * + * @return a TPoly object representing the trapezoid + */ TPoly PolyTRatio() { int n = elementlist.size(); CPoint p1 = (CPoint) elementlist.get(0); @@ -1062,19 +1312,13 @@ TPoly PolyTRatio() { int t2 = I1.intValue(); return poly.Tratio(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex, t1, t2); - - } - - TPoly PolyNTSegment() { - CPoint p1 = (CPoint) elementlist.get(0); - CPoint p2 = (CPoint) elementlist.get(1); - CPoint p3 = (CPoint) elementlist.get(2); - CPoint p4 = (CPoint) elementlist.get(3); - //des = new Act(Act.QSQUAR, p1, p2, p3, p4); - return poly.squarept2(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex, this.proportion); - } + /** + * Computes the polynomial representation of an angle. + * + * @return a TMono object representing the angle + */ TMono PolyNTAngle() { CLine ln1 = (CLine) elementlist.get(0); CLine ln2 = (CLine) elementlist.get(1); @@ -1093,6 +1337,11 @@ TMono PolyNTAngle() { c.x1.xindex, c.y1.xindex, pt.x1.xindex, pt.y1.xindex); } + /** + * Computes the polynomial representation of a square. + * + * @return a TPoly object representing the square + */ TPoly PolyPsquare() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -1100,32 +1349,26 @@ TPoly PolyPsquare() { CPoint p4 = (CPoint) elementlist.get(2); return poly.squarept1(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex, this.proportion); - } + /** + * Computes the polynomial representation of a square. + * + * @return a TPoly object representing the square + */ TPoly PolyQsquare() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); CPoint p3 = p2; CPoint p4 = (CPoint) elementlist.get(2); return poly.squarept2(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex, this.proportion); - - } - - TMono PolyCCLine() { - CPoint p = (CPoint) this.getelement(0); - Circle c1 = (Circle) this.getelement(1); - Circle c2 = (Circle) this.getelement(2); - CPoint po1 = c1.o; - CPoint po2 = c2.o; - CPoint pc1 = c1.getSidePoint(); - CPoint pc2 = c2.getSidePoint(); - - return poly.ccline(p.x1.xindex, p.y1.xindex, po1.x1.xindex, po1.y1.xindex, pc1.x1.xindex, pc1.y1.xindex, - po2.x1.xindex, po2.y1.xindex, pc2.x1.xindex, pc2.y1.xindex); - } + /** + * Computes the polynomial representation of a specific angle. + * + * @return a TMono object representing the specific angle + */ TMono PolySAngle() { CLine ln1 = (CLine) elementlist.get(0); CLine ln2 = (CLine) elementlist.get(1); @@ -1141,6 +1384,11 @@ TMono PolySAngle() { return null; } + /** + * Computes the polynomial representation of an angle. + * + * @return a TMono object representing the angle + */ TMono PolyALine() { CLine ln1 = (CLine) elementlist.get(0); CLine ln2 = (CLine) elementlist.get(1); @@ -1182,6 +1430,11 @@ TMono PolyALine() { return null; } + /** + * Computes the polynomial representation of equal angles. + * + * @return a TMono object representing the equal angles + */ TMono PolyEqAngle() { if (elementlist.size() == 2) { CAngle ag1 = (CAngle) elementlist.get(0); @@ -1235,10 +1488,14 @@ TMono PolyEqAngle() { lp2[0].x1.xindex, lp2[0].y1.xindex, lp2[1].x1.xindex, lp2[1].y1.xindex, lp3[0].x1.xindex, lp3[0].y1.xindex, lp3[1].x1.xindex, lp3[1].y1.xindex, lp4[0].x1.xindex, lp4[0].y1.xindex, lp4[1].x1.xindex, lp4[1].y1.xindex); - } } + /** + * Computes the polynomial representation of equal angles with three points. + * + * @return a TMono object representing the equal angles with three points + */ TMono PolyEqAngle3P() { CAngle ag1 = (CAngle) elementlist.get(0); CAngle ag2 = (CAngle) elementlist.get(1); @@ -1261,14 +1518,23 @@ TMono PolyEqAngle3P() { p4.x1.xindex, p4.y1.xindex, p5.x1.xindex, p5.y1.xindex, p6.x1.xindex, p6.y1.xindex, p7.x1.xindex, p7.y1.xindex, p8.x1.xindex, p8.y1.xindex, p9.x1.xindex, p9.y1.xindex, pm.xindex); - } + /** + * Computes the polynomial representation of a specific angle. + * + * @return a TMono object representing the specific angle + */ TMono PolySpecifiAngle() { Param pm = (Param) elementlist.get(0); return poly.specificangle(pm.xindex, this.proportion); } + /** + * Computes the polynomial representation of equal distances. + * + * @return a TMono object representing the equal distances + */ TMono PolyEqidstance() { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -1278,9 +1544,13 @@ TMono PolyEqidstance() { add_des(Gib.C_EQDISTANCE, p1, p2, p3, p4); return poly.eqdistance(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex); - } + /** + * Computes the polynomial representation of a midpoint. + * + * @return a TPoly object representing the midpoint + */ TPoly PolyMidPoint() { CPoint po = (CPoint) elementlist.get(0); CPoint p1 = (CPoint) elementlist.get(1); @@ -1297,282 +1567,334 @@ TPoly PolyMidPoint() { poly2.setPoly(m2); poly2.setNext(poly); return poly2; - - } - - - TPoly PolyRectangle() { - CPoint p1 = (CPoint) elementlist.get(0); - CPoint p2 = (CPoint) elementlist.get(1); - CPoint p3 = (CPoint) elementlist.get(2); - CPoint p4 = (CPoint) elementlist.get(3); - add_des(Gib.C_RECTANGLE, p1, p2, p3, p4); - - TMono m1 = poly.parallel(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, - p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex); - TMono m2 = poly.perpendicular(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, - p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex); - TMono m3 = poly.perpendicular(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, - p1.x1.xindex, p1.y1.xindex, p4.x1.xindex, p4.y1.xindex); - TPoly p = NewTPoly(m1, m2); - TPoly pp = new TPoly(); - pp.setPoly(m3); - pp.setNext(p); - return pp; } - TMono PolyTrapezoid() { - CPoint p1 = (CPoint) elementlist.get(0); - CPoint p2 = (CPoint) elementlist.get(1); - CPoint p3 = (CPoint) elementlist.get(2); - CPoint p4 = (CPoint) elementlist.get(3); - add_des(Gib.C_TRAPEZOID, p1, p2, p3, p4); - TMono m1 = poly.parallel(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, - p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex); - return m1; - } - - TPoly PolyParallelogram() { - CPoint p1 = (CPoint) elementlist.get(0); - CPoint p2 = (CPoint) elementlist.get(1); - CPoint p3 = (CPoint) elementlist.get(2); - CPoint p4 = (CPoint) elementlist.get(3); - int n = p4.x1.xindex; - if (n > p1.x1.xindex && n > p2.x1.xindex) { - CPoint pt = p4; - p4 = p1; - p1 = pt; - pt = p3; - p3 = p2; - p2 = pt; + /** + * Computes the polynomial representation of a rectangle. + * + * @return a TPoly object representing the rectangle + */ + TPoly PolyRectangle() { + CPoint p1 = (CPoint) elementlist.get(0); + CPoint p2 = (CPoint) elementlist.get(1); + CPoint p3 = (CPoint) elementlist.get(2); + CPoint p4 = (CPoint) elementlist.get(3); + add_des(Gib.C_RECTANGLE, p1, p2, p3, p4); + + TMono m1 = poly.parallel(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, + p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex); + TMono m2 = poly.perpendicular(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, + p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex); + TMono m3 = poly.perpendicular(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, + p1.x1.xindex, p1.y1.xindex, p4.x1.xindex, p4.y1.xindex); + TPoly p = NewTPoly(m1, m2); + TPoly pp = new TPoly(); + pp.setPoly(m3); + pp.setNext(p); + return pp; } - add_des(Gib.C_PARALLELOGRAM, p1, p2, p3, p4); - TMono m1 = poly.parallel(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, - p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex); - TMono m2 = poly.parallel(p1.x1.xindex, p1.y1.xindex, p4.x1.xindex, p4.y1.xindex, - p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex); - return this.NewTPoly(m1, m2); - - } - - TPoly PolyRTrapezoid() { - CPoint p1 = (CPoint) elementlist.get(0); - CPoint p2 = (CPoint) elementlist.get(1); - CPoint p3 = (CPoint) elementlist.get(2); - CPoint p4 = (CPoint) elementlist.get(3); - add_des(Gib.C_R_TRAPEZOID, p1, p2, p3, p4); - TMono m1 = poly.parallel(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, - p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex); - TMono m2 = poly.perpendicular(p1.x1.xindex, p1.y1.xindex, p4.x1.xindex, p4.y1.xindex, - p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex); - return this.NewTPoly(m1, m2); - - } - - TMono PolyRightTriangle() { - CPoint po = (CPoint) elementlist.get(0); - CPoint p1 = (CPoint) elementlist.get(1); - CPoint p2 = (CPoint) elementlist.get(2); - add_des(Gib.C_R_TRI, po, p1, p2); - return poly.perpendicular(po.x1.xindex, po.y1.xindex, p1.x1.xindex, p1.y1.xindex, - po.x1.xindex, po.y1.xindex, p2.x1.xindex, p2.y1.xindex); - } - - TMono PolyOnLine() { - CPoint p = (CPoint) this.getelement(0); - CLine line = (CLine) this.getelement(1); - int x, y; - x = p.x1.xindex; - y = p.y1.xindex; - if (line.type == CLine.CCLine) { - Constraint cs = line.getcons(0); - - Circle c1 = (Circle) cs.getelement(1); - Circle c2 = (Circle) cs.getelement(2); - CPoint po1 = c1.o; - CPoint po2 = c2.o; - CPoint pc1 = c1.getSidePoint(); - CPoint pc2 = c2.getSidePoint(); - //????? - return poly.ccline(p.x1.xindex, p.y1.xindex, po1.x1.xindex, po1.y1.xindex, pc1.x1.xindex, pc1.y1.xindex, - po2.x1.xindex, po2.y1.xindex, pc2.x1.xindex, pc2.y1.xindex); - - - } else { - CPoint[] plist = line.getTowSideOfLine(); - if (plist == null) return null; - CPoint p1, p2; - p1 = plist[0]; - p2 = plist[1]; - add_des(Gib.C_O_L, p, p1, p2); - return poly.collinear(x, y, p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex); + /** + * Computes the polynomial representation of a trapezoid. + * + * @return a TMono object representing the trapezoid + */ + TMono PolyTrapezoid() { + CPoint p1 = (CPoint) elementlist.get(0); + CPoint p2 = (CPoint) elementlist.get(1); + CPoint p3 = (CPoint) elementlist.get(2); + CPoint p4 = (CPoint) elementlist.get(3); + add_des(Gib.C_TRAPEZOID, p1, p2, p3, p4); + TMono m1 = poly.parallel(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, + p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex); + return m1; } - } - - TPoly PolyIntersection_CC() { - CPoint p1 = (CPoint) elementlist.get(0); - Circle c1 = (Circle) elementlist.get(1); - Circle c2 = (Circle) elementlist.get(2); - Vector v = Circle.CommonPoints(c1, c2); - TPoly tp = null; - int n = v.size(); - CPoint p2 = null; - - if (n == 2) { - CPoint t1 = (CPoint) v.get(0); - CPoint t2 = (CPoint) v.get(1); - if (p1 == t1) - p2 = t2; - else - p2 = t1; - } else if (n == 1 && v.get(0) != p1) - p2 = (CPoint) v.get(0); + /** + * Computes the polynomial representation of a parallelogram. + * + * @return a TPoly object representing the parallelogram + */ + TPoly PolyParallelogram() { + CPoint p1 = (CPoint) elementlist.get(0); + CPoint p2 = (CPoint) elementlist.get(1); + CPoint p3 = (CPoint) elementlist.get(2); + CPoint p4 = (CPoint) elementlist.get(3); - if (p2 != null && p2.x1.xindex < p1.x1.xindex) { - CPoint p3 = c1.o; - CPoint p4 = c2.o; - this.add_des(Gib.C_I_CC, p1, p3, p2, p4, p2); - return poly.mirrorPL(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex, - p4.x1.xindex, p4.y1.xindex); + int n = p4.x1.xindex; + if (n > p1.x1.xindex && n > p2.x1.xindex) { + CPoint pt = p4; + p4 = p1; + p1 = pt; + pt = p3; + p3 = p2; + p2 = pt; + } + add_des(Gib.C_PARALLELOGRAM, p1, p2, p3, p4); + TMono m1 = poly.parallel(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, + p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex); + TMono m2 = poly.parallel(p1.x1.xindex, p1.y1.xindex, p4.x1.xindex, p4.y1.xindex, + p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex); + return this.NewTPoly(m1, m2); } - p2 = c1.getSidePoint(); - CPoint p3 = c2.getSidePoint(); - if (p2 != null && p3 != null) { - this.add_des(Gib.C_I_CC, p1, c1.o, p2, c2.o, p3); - TMono m1 = poly.eqdistance(p1.x1.xindex, p1.y1.xindex, c1.o.x1.xindex, c1.o.y1.xindex, - p2.x1.xindex, p2.y1.xindex, c1.o.x1.xindex, c1.o.y1.xindex); - TMono m2 = poly.eqdistance(p1.x1.xindex, p1.y1.xindex, c2.o.x1.xindex, c2.o.y1.xindex, - p3.x1.xindex, p3.y1.xindex, c2.o.x1.xindex, c2.o.y1.xindex); - return this.NewTPoly(m1, m2); - } else { - CPoint[] l1 = c1.getRadiusPoint(); - CPoint[] l2 = c2.getRadiusPoint(); - this.add_des(Gib.C_I_RR, p1, c1.o, l1[0], l1[1], c2.o, l2[0], l2[1]); - - TMono m1 = poly.eqdistance(p1.x1.xindex, p1.y1.xindex, c1.o.x1.xindex, c1.o.y1.xindex, - l1[0].x1.xindex, l1[0].y1.xindex, l1[1].x1.xindex, l1[1].y1.xindex); - TMono m2 = poly.eqdistance(p1.x1.xindex, p1.y1.xindex, c2.o.x1.xindex, c2.o.y1.xindex, - l2[0].x1.xindex, l2[0].y1.xindex, l2[1].x1.xindex, l2[1].y1.xindex); + /** + * Computes the polynomial representation of a right trapezoid. + * + * @return a TPoly object representing the right trapezoid + */ + TPoly PolyRTrapezoid() { + CPoint p1 = (CPoint) elementlist.get(0); + CPoint p2 = (CPoint) elementlist.get(1); + CPoint p3 = (CPoint) elementlist.get(2); + CPoint p4 = (CPoint) elementlist.get(3); + add_des(Gib.C_R_TRAPEZOID, p1, p2, p3, p4); + TMono m1 = poly.parallel(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, + p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex); + TMono m2 = poly.perpendicular(p1.x1.xindex, p1.y1.xindex, p4.x1.xindex, p4.y1.xindex, + p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex); return this.NewTPoly(m1, m2); } - } - TPoly PolyIntersection_ll() { - CPoint p1 = (CPoint) elementlist.get(0); - CLine ln1 = (CLine) elementlist.get(1); - CLine ln2 = (CLine) elementlist.get(2); - if (compareLN(ln1, ln2)) { - CLine ln = ln1; - ln1 = ln2; - ln2 = ln; + /** + * Computes the polynomial representation of a right triangle. + * + * @return a TMono object representing the right triangle + */ + TMono PolyRightTriangle() { + CPoint po = (CPoint) elementlist.get(0); + CPoint p1 = (CPoint) elementlist.get(1); + CPoint p2 = (CPoint) elementlist.get(2); + add_des(Gib.C_R_TRI, po, p1, p2); + return poly.perpendicular(po.x1.xindex, po.y1.xindex, p1.x1.xindex, p1.y1.xindex, + po.x1.xindex, po.y1.xindex, p2.x1.xindex, p2.y1.xindex); } - CPoint[] ps1 = ln1.getTowSideOfLine(); - if (ps1 == null) return null; - CPoint[] ps2 = ln2.getTowSideOfLine(); - if (ps2 == null) return null; - add_des(Gib.C_I_LL, p1, ps1[0], ps1[1], ps2[0], ps2[1]); - TMono m1 = poly.collinear(p1.x1.xindex, p1.y1.xindex, ps1[0].x1.xindex, ps1[0].y1.xindex, ps1[1].x1.xindex, ps1[1].y1.xindex); - addZeron(m1); - TMono m2 = poly.collinear(p1.x1.xindex, p1.y1.xindex, ps2[0].x1.xindex, ps2[0].y1.xindex, ps2[1].x1.xindex, ps2[1].y1.xindex); - return this.NewTPoly(m1, m2); - } - - TPoly PolyIntersection_lc() { - CPoint p1 = (CPoint) elementlist.get(0); - CLine ln = (CLine) elementlist.get(1); - Circle c = (Circle) elementlist.get(2); - CPoint[] ls = CLine.commonPoint(ln, c); - CPoint[] np = ln.getTowSideOfLine(); - CPoint o = c.o; - - CPoint p2; + /** + * Computes the polynomial representation of a point on a line. + * + * @return a TMono object representing the point on the line + */ + TMono PolyOnLine() { + CPoint p = (CPoint) this.getelement(0); + CLine line = (CLine) this.getelement(1); + int x, y; + x = p.x1.xindex; + y = p.y1.xindex; + + if (line.type == CLine.CCLine) { + Constraint cs = line.getcons(0); + + Circle c1 = (Circle) cs.getelement(1); + Circle c2 = (Circle) cs.getelement(2); + CPoint po1 = c1.o; + CPoint po2 = c2.o; + CPoint pc1 = c1.getSidePoint(); + CPoint pc2 = c2.getSidePoint(); + //????? + return poly.ccline(p.x1.xindex, p.y1.xindex, po1.x1.xindex, po1.y1.xindex, pc1.x1.xindex, pc1.y1.xindex, + po2.x1.xindex, po2.y1.xindex, pc2.x1.xindex, pc2.y1.xindex); + } else { + CPoint[] plist = line.getTowSideOfLine(); + if (plist == null) return null; + CPoint p1, p2; + p1 = plist[0]; + p2 = plist[1]; + add_des(Gib.C_O_L, p, p1, p2); + return poly.collinear(x, y, p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex); + } + } - if (ls.length == 2) { - if (p1 == ls[0]) - p2 = ls[1]; - else - p2 = ls[0]; - } else if (ls.length == 1 && ls[0] != p1) - p2 = ls[0]; - else - p2 = null; + /** + * Computes the polynomial representation of the intersection of two circles. + * + * @return a TPoly object representing the intersection of the circles + */ + TPoly PolyIntersection_CC() { + CPoint p1 = (CPoint) elementlist.get(0); + Circle c1 = (Circle) elementlist.get(1); + Circle c2 = (Circle) elementlist.get(2); + Vector v = Circle.CommonPoints(c1, c2); + TPoly tp = null; + int n = v.size(); + CPoint p2 = null; + + if (n == 2) { + CPoint t1 = (CPoint) v.get(0); + CPoint t2 = (CPoint) v.get(1); + if (p1 == t1) + p2 = t2; + else + p2 = t1; + } else if (n == 1 && v.get(0) != p1) + p2 = (CPoint) v.get(0); + + if (p2 != null && p2.x1.xindex < p1.x1.xindex) { + CPoint p3 = c1.o; + CPoint p4 = c2.o; + this.add_des(Gib.C_I_CC, p1, p3, p2, p4, p2); + return poly.mirrorPL(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex, + p4.x1.xindex, p4.y1.xindex); + } - if (p2 != null && p1.x1.xindex > p2.x1.xindex) { - add_des(Gib.C_I_LC, p1, np[0], np[1], c.o, c.getSidePoint()); - CPoint pl = ln.getSecondPoint(p2); - return poly.LCMeet(o.x1.xindex, o.y1.xindex, p2.x1.xindex, - p2.y1.xindex, pl.x1.xindex, pl.y1.xindex, p1.x1.xindex, p1.y1.xindex); + p2 = c1.getSidePoint(); + CPoint p3 = c2.getSidePoint(); + if (p2 != null && p3 != null) { + this.add_des(Gib.C_I_CC, p1, c1.o, p2, c2.o, p3); + TMono m1 = poly.eqdistance(p1.x1.xindex, p1.y1.xindex, c1.o.x1.xindex, c1.o.y1.xindex, + p2.x1.xindex, p2.y1.xindex, c1.o.x1.xindex, c1.o.y1.xindex); + TMono m2 = poly.eqdistance(p1.x1.xindex, p1.y1.xindex, c2.o.x1.xindex, c2.o.y1.xindex, + p3.x1.xindex, p3.y1.xindex, c2.o.x1.xindex, c2.o.y1.xindex); + return this.NewTPoly(m1, m2); + } else { + CPoint[] l1 = c1.getRadiusPoint(); + CPoint[] l2 = c2.getRadiusPoint(); + this.add_des(Gib.C_I_RR, p1, c1.o, l1[0], l1[1], c2.o, l2[0], l2[1]); + + TMono m1 = poly.eqdistance(p1.x1.xindex, p1.y1.xindex, c1.o.x1.xindex, c1.o.y1.xindex, + l1[0].x1.xindex, l1[0].y1.xindex, l1[1].x1.xindex, l1[1].y1.xindex); + TMono m2 = poly.eqdistance(p1.x1.xindex, p1.y1.xindex, c2.o.x1.xindex, c2.o.y1.xindex, + l2[0].x1.xindex, l2[0].y1.xindex, l2[1].x1.xindex, l2[1].y1.xindex); + return this.NewTPoly(m1, m2); + } } - CPoint pl = c.getSidePoint(); - if (pl != null) { - add_des(Gib.C_I_LC, p1, np[0], np[1], c.o, c.getSidePoint()); - TMono m1 = poly.collinear(p1.x1.xindex, p1.y1.xindex, np[0].x1.xindex, np[0].y1.xindex, np[1].x1.xindex, np[1].y1.xindex); - addZeron(m1); - TMono m2 = poly.eqdistance(o.x1.xindex, o.y1.xindex, p1.x1.xindex, p1.y1.xindex, o.x1.xindex, o.y1.xindex, pl.x1.xindex, pl.y1.xindex); - return this.NewTPoly(m1, m2); - } else { - CPoint[] ll = c.getRadiusPoint(); - add_des(Gib.C_I_LR, p1, np[0], np[1], c.o, ll[0], ll[1]); - TMono m1 = poly.collinear(p1.x1.xindex, p1.y1.xindex, np[0].x1.xindex, np[0].y1.xindex, np[1].x1.xindex, np[1].y1.xindex); + /** + * Computes the polynomial representation of the intersection of two lines. + * + * @return a TPoly object representing the intersection of the lines + */ + TPoly PolyIntersection_ll() { + CPoint p1 = (CPoint) elementlist.get(0); + CLine ln1 = (CLine) elementlist.get(1); + CLine ln2 = (CLine) elementlist.get(2); + if (compareLN(ln1, ln2)) { + CLine ln = ln1; + ln1 = ln2; + ln2 = ln; + } + + CPoint[] ps1 = ln1.getTowSideOfLine(); + if (ps1 == null) return null; + CPoint[] ps2 = ln2.getTowSideOfLine(); + if (ps2 == null) return null; + add_des(Gib.C_I_LL, p1, ps1[0], ps1[1], ps2[0], ps2[1]); + TMono m1 = poly.collinear(p1.x1.xindex, p1.y1.xindex, ps1[0].x1.xindex, ps1[0].y1.xindex, ps1[1].x1.xindex, ps1[1].y1.xindex); addZeron(m1); - TMono m2 = poly.eqdistance(o.x1.xindex, o.y1.xindex, p1.x1.xindex, p1.y1.xindex, ll[0].x1.xindex, ll[0].y1.xindex, ll[1].x1.xindex, ll[1].x1.xindex); + TMono m2 = poly.collinear(p1.x1.xindex, p1.y1.xindex, ps2[0].x1.xindex, ps2[0].y1.xindex, ps2[1].x1.xindex, ps2[1].y1.xindex); return this.NewTPoly(m1, m2); } - } - - TMono collinear() { - CPoint p1, p2, p3; - p1 = p2 = p3 = null; + /** + * Computes the polynomial representation of the intersection of a line and a circle. + * + * @return a TPoly object representing the intersection of the line and the circle + */ + TPoly PolyIntersection_lc() { + CPoint p1 = (CPoint) elementlist.get(0); + CLine ln = (CLine) elementlist.get(1); + Circle c = (Circle) elementlist.get(2); + CPoint[] ls = CLine.commonPoint(ln, c); + CPoint[] np = ln.getTowSideOfLine(); + CPoint o = c.o; - for (int i = 0; i < this.elementlist.size(); i++) { - CPoint p = (CPoint) this.getelement(i); - if (p == null) continue; + CPoint p2; - if (p1 == null) - p1 = p; - else if (p1.x1.xindex < p.x1.xindex) { - if (p2 == null) - p2 = p1; + if (ls.length == 2) { + if (p1 == ls[0]) + p2 = ls[1]; else - p3 = p1; - p1 = p; - - } else if (p2 == null) - p2 = p; + p2 = ls[0]; + } else if (ls.length == 1 && ls[0] != p1) + p2 = ls[0]; else - p3 = p; - } + p2 = null; - add_des(Gib.C_O_L, p1, p2, p3); - return poly.collinear(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex); - } + if (p2 != null && p1.x1.xindex > p2.x1.xindex) { + add_des(Gib.C_I_LC, p1, np[0], np[1], c.o, c.getSidePoint()); + CPoint pl = ln.getSecondPoint(p2); + return poly.LCMeet(o.x1.xindex, o.y1.xindex, p2.x1.xindex, + p2.y1.xindex, pl.x1.xindex, pl.y1.xindex, p1.x1.xindex, p1.y1.xindex); + } - TPoly PolyLCMeet() { + CPoint pl = c.getSidePoint(); + if (pl != null) { + add_des(Gib.C_I_LC, p1, np[0], np[1], c.o, c.getSidePoint()); + TMono m1 = poly.collinear(p1.x1.xindex, p1.y1.xindex, np[0].x1.xindex, np[0].y1.xindex, np[1].x1.xindex, np[1].y1.xindex); + addZeron(m1); + TMono m2 = poly.eqdistance(o.x1.xindex, o.y1.xindex, p1.x1.xindex, p1.y1.xindex, o.x1.xindex, o.y1.xindex, pl.x1.xindex, pl.y1.xindex); + return this.NewTPoly(m1, m2); + } else { + CPoint[] ll = c.getRadiusPoint(); + add_des(Gib.C_I_LR, p1, np[0], np[1], c.o, ll[0], ll[1]); + TMono m1 = poly.collinear(p1.x1.xindex, p1.y1.xindex, np[0].x1.xindex, np[0].y1.xindex, np[1].x1.xindex, np[1].y1.xindex); + addZeron(m1); + TMono m2 = poly.eqdistance(o.x1.xindex, o.y1.xindex, p1.x1.xindex, p1.y1.xindex, ll[0].x1.xindex, ll[0].y1.xindex, ll[1].x1.xindex, ll[1].x1.xindex); + return this.NewTPoly(m1, m2); + } + } - CPoint pl = null; - CPoint p = (CPoint) this.getelement(0); - CPoint pc = (CPoint) this.getelement(1); - CLine ln = (CLine) this.getelement(2); - Circle c = (Circle) this.getelement(3); - CPoint o = c.o; - Vector pts = ln.points; - for (int i = 0; i < pts.size(); i++) - if (pts.get(i) != pc) { - pl = (CPoint) pts.get(i); - break; + /** + * Computes the polynomial representation of collinear points. + * + * @return a TMono object representing the collinear points + */ + TMono collinear() { + CPoint p1, p2, p3; + p1 = p2 = p3 = null; + + for (int i = 0; i < this.elementlist.size(); i++) { + CPoint p = (CPoint) this.getelement(i); + if (p == null) continue; + + if (p1 == null) + p1 = p; + else if (p1.x1.xindex < p.x1.xindex) { + if (p2 == null) + p2 = p1; + else + p3 = p1; + p1 = p; + + } else if (p2 == null) + p2 = p; + else + p3 = p; } - if (pl == null) return null; - add_des(Gib.C_I_LC, p, pc, pl, o, pc); - return poly.LCMeet(o.x1.xindex, o.y1.xindex, pc.x1.xindex, pc.y1.xindex, pl.x1.xindex, pl.y1.xindex, p.x1.xindex, p.y1.xindex); - } + add_des(Gib.C_O_L, p1, p2, p3); + return poly.collinear(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex); + } + + /** + * Computes the polynomial representation of the intersection of a line and a circle. + * + * @return a TPoly object representing the intersection of the line and the circle + */ + TPoly PolyLCMeet() { + CPoint pl = null; + CPoint p = (CPoint) this.getelement(0); + CPoint pc = (CPoint) this.getelement(1); + CLine ln = (CLine) this.getelement(2); + Circle c = (Circle) this.getelement(3); + CPoint o = c.o; + Vector pts = ln.points; + for (int i = 0; i < pts.size(); i++) + if (pts.get(i) != pc) { + pl = (CPoint) pts.get(i); + break; + } + if (pl == null) return null; + add_des(Gib.C_I_LC, p, pc, pl, o, pc); + return poly.LCMeet(o.x1.xindex, o.y1.xindex, pc.x1.xindex, pc.y1.xindex, pl.x1.xindex, pl.y1.xindex, p.x1.xindex, p.y1.xindex); + } + + /** + * Checks if a point lies on a circle. + * + * @return a TMono object representing the constraint + */ TMono PolyOnCircle() { CPoint p = (CPoint) this.getelement(0); Circle c = (Circle) this.getelement(1); @@ -1594,8 +1916,7 @@ TMono PolyOnCircle() { add_des(Gib.C_O_R, p, o, p1, p2); return poly.eqdistance(o.x1.xindex, o.y1.xindex, p.x1.xindex, p.y1.xindex, p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex); - } else if (c.points.size() != 0)//|| c.type == Circle.PCircle || c.type == Circle.SCircle) - { + } else if (c.points.size() != 0) { CPoint pt = c.getSidePoint(); if (pt == null) return null; @@ -1610,6 +1931,11 @@ TMono PolyOnCircle() { return null; } + /** + * Checks if two lines or four points are perpendicular. + * + * @return a TMono object representing the perpendicularity constraint + */ TMono PolyPerp() { if (elementlist.size() == 2) { CLine line1 = (CLine) this.getelement(0); @@ -1645,9 +1971,13 @@ TMono PolyPerp() { return poly.perpendicular(x1, y1, x2, y2, x3, y3, x4, y4); } return null; - } + /** + * Computes the foot of a perpendicular from a point to a line. + * + * @return a TPoly object representing the foot of the perpendicular + */ TPoly PolyPfoot() { CPoint p1 = (CPoint) this.getelement(0); CPoint p2 = (CPoint) this.getelement(1); @@ -1659,10 +1989,13 @@ TPoly PolyPfoot() { TMono m2 = poly.perpendicular(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex); return mpoly(m1, m2); - - } + /** + * Checks if two lines are parallel. + * + * @return a TMono object representing the parallelism constraint + */ TMono PolyParel() { CLine line1 = (CLine) this.getelement(0); CLine line2 = (CLine) this.getelement(1); @@ -1681,6 +2014,11 @@ TMono PolyParel() { pl2[0].x1.xindex, pl2[0].y1.xindex, pl2[1].x1.xindex, pl2[1].y1.xindex); } + /** + * Computes the tangent between two circles. + * + * @return a TMono object representing the tangent constraint + */ TMono PolyCCTangent() { Circle c1 = (Circle) this.getelement(0); Circle c2 = (Circle) this.getelement(1); @@ -1692,60 +2030,13 @@ TMono PolyCCTangent() { return poly.c_c_tangent(pl1[0], pl1[1], c1.o, pl2[0], pl2[1], c2.o); } - public static boolean PolyConstraint(int type, CPoint p1, CPoint p2, CPoint p3, CPoint p4) { - int x1, y1, x2, y2, x3, y3, x4, y4; - x1 = p1.x1.xindex; - y1 = p1.y1.xindex; - x2 = p2.x1.xindex; - y2 = p2.y1.xindex; - x3 = p3.x1.xindex; - y3 = p3.y1.xindex; - TMono mpoly = null; - TMono mpoly1 = null; - switch (type) { - case Constraint.COLLINEAR: // 3 obj - mpoly = poly.collinear(x1, y1, x2, y2, x3, y3); - break; - case Constraint.PARALLEL: // 4 obj - x4 = p4.x1.xindex; - y4 = p4.y1.xindex; - mpoly = poly.parallel(x1, y1, x2, y2, x3, y3, x4, y4); - break; - case Constraint.PERPENDICULAR: //4 - x4 = p4.x1.xindex; - y4 = p4.y1.xindex; - mpoly = poly.perpendicular(x1, y1, x2, y2, x3, y3, x4, y4); - break; - case Constraint.EQDISTANCE: //4 - x4 = p4.x1.xindex; - y4 = p4.y1.xindex; - mpoly = poly.eqdistance(x1, y1, x2, y2, x3, y3, x4, y4); - break; - case Constraint.BISECT: - mpoly = poly.bisect(x1, y1, x2, y2, x3, y3); - break; - case Constraint.MIDPOINT: - mpoly = poly.midpoint(x1, x2, x3); - mpoly1 = poly.midpoint(y1, y2, y3); - default: - break; - } - - if (mpoly == null) - return false; - TPoly tp = new TPoly(); - tp.setPoly(mpoly); - tp.setNext(polylist); - polylist = tp; - if (type == Constraint.MIDPOINT) { - tp = new TPoly(); - tp.setPoly(mpoly1); - tp.setNext(polylist); - polylist = tp; - } - return true; - } - + /** + * Creates a new TPoly object from two TMono objects. + * + * @param m1 the first TMono object + * @param m2 the second TMono object + * @return the created TPoly object + */ public TPoly NewTPoly(TMono m1, TMono m2) { TPoly poly = new TPoly(); poly.setPoly(m1); @@ -1755,6 +2046,12 @@ public TPoly NewTPoly(TMono m1, TMono m2) { return poly2; } + /** + * Saves the constraint data to a DataOutputStream. + * + * @param out the DataOutputStream to write to + * @throws IOException if an I/O error occurs + */ public void Save(DataOutputStream out) throws IOException { out.writeInt(id); @@ -1806,10 +2103,13 @@ public void Save(DataOutputStream out) throws IOException { } out.writeInt(proportion); out.writeBoolean(this.is_poly_genereate); - - } + /** + * Adds a constraint description to the list of constraints. + * + * @param s the Cons object representing the constraint description + */ private void add_des(Cons s) { if (this.csd == null) this.csd = s; @@ -1817,7 +2117,15 @@ private void add_des(Cons s) { this.csd1 = s; } - + /** + * Adds a constraint description with three points and an additional object to the list of constraints. + * + * @param t the type of the constraint + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @param obj the additional object + */ public void add_des(int t, CPoint p1, CPoint p2, CPoint p3, Object obj) { Cons csd = new Cons(t); @@ -1829,6 +2137,14 @@ public void add_des(int t, CPoint p1, CPoint p2, CPoint p3, Object obj) { add_des(csd); } + /** + * Adds a constraint description with three points to the list of constraints. + * + * @param t the type of the constraint + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + */ public void add_des(int t, CPoint p1, CPoint p2, CPoint p3) { Cons csd = new Cons(t); @@ -1839,6 +2155,12 @@ public void add_des(int t, CPoint p1, CPoint p2, CPoint p3) { add_des(csd); } + /** + * Adds a constraint description with a vector of points to the list of constraints. + * + * @param t the type of the constraint + * @param v the vector of points + */ public void add_des(int t, Vector v) { Cons csd = new Cons(t); csd.setId(id); @@ -1847,11 +2169,27 @@ public void add_des(int t, Vector v) { add_des(csd); } + /** + * Compares two points based on their x-index. + * + * @param a the first point + * @param b the second point + * @return true if the x-index of the first point is less than the x-index of the second point, false otherwise + */ public boolean less(CPoint a, CPoint b) { return a.x1.xindex < b.x1.xindex; } - public void add_desx1(int t, CPoint p1, CPoint p2, CPoint p3, CPoint p4) { //parallel ,perpendicular + /** + * Adds a constraint description with four points to the list of constraints, ensuring the points are ordered by their x-index. + * + * @param t the type of the constraint + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @param p4 the fourth point + */ + public void add_desx1(int t, CPoint p1, CPoint p2, CPoint p3, CPoint p4) { if (less(p1, p2)) { CPoint a = p1; p1 = p2; @@ -1873,8 +2211,16 @@ public void add_desx1(int t, CPoint p1, CPoint p2, CPoint p3, CPoint p4) { //p add_des(t, p1, p2, p3, p4); } + /** + * Adds a constraint description with four points to the list of constraints. + * + * @param t the type of the constraint + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @param p4 the fourth point + */ public void add_des(int t, CPoint p1, CPoint p2, CPoint p3, CPoint p4) { - Cons csd = new Cons(t); csd.setId(id); csd.add_pt(p1); @@ -1884,6 +2230,16 @@ public void add_des(int t, CPoint p1, CPoint p2, CPoint p3, CPoint p4) { add_des(csd); } + /** + * Adds a constraint description with five objects to the list of constraints. + * + * @param t the type of the constraint + * @param p1 the first object + * @param p2 the second object + * @param p3 the third object + * @param p4 the fourth object + * @param p5 the fifth object + */ public void add_des(int t, Object p1, Object p2, Object p3, Object p4, Object p5) { Cons csd = new Cons(t); csd.setId(id); @@ -1895,6 +2251,17 @@ public void add_des(int t, Object p1, Object p2, Object p3, Object p4, Object p5 add_des(csd); } + /** + * Adds a constraint description with six objects to the list of constraints. + * + * @param t the type of the constraint + * @param p1 the first object + * @param p2 the second object + * @param p3 the third object + * @param p4 the fourth object + * @param p5 the fifth object + * @param p6 the sixth object + */ public void add_des(int t, Object p1, Object p2, Object p3, Object p4, Object p5, Object p6) { Cons csd = new Cons(t); csd.setId(id); @@ -1907,8 +2274,20 @@ public void add_des(int t, Object p1, Object p2, Object p3, Object p4, Object p5 add_des(csd); } - public void add_des(int t, Object p1, Object p2, Object p3, - Object p4, Object p5, Object p6, Object p7, Object p8) { + /** + * Adds a constraint description with eight objects to the list of constraints. + * + * @param t the type of the constraint + * @param p1 the first object + * @param p2 the second object + * @param p3 the third object + * @param p4 the fourth object + * @param p5 the fifth object + * @param p6 the sixth object + * @param p7 the seventh object + * @param p8 the eighth object + */ + public void add_des(int t, Object p1, Object p2, Object p3, Object p4, Object p5, Object p6, Object p7, Object p8) { Cons csd = new Cons(t); csd.setId(id); csd.add_pt(p1); @@ -1922,8 +2301,22 @@ public void add_des(int t, Object p1, Object p2, Object p3, add_des(csd); } - public void add_des(int t, Object p1, Object p2, Object p3, - Object p4, Object p5, Object p6, Object p7, Object p8, Object p9, Object p10) { + /** + * Adds a constraint description with ten objects to the list of constraints. + * + * @param t the type of the constraint + * @param p1 the first object + * @param p2 the second object + * @param p3 the third object + * @param p4 the fourth object + * @param p5 the fifth object + * @param p6 the sixth object + * @param p7 the seventh object + * @param p8 the eighth object + * @param p9 the ninth object + * @param p10 the tenth object + */ + public void add_des(int t, Object p1, Object p2, Object p3, Object p4, Object p5, Object p6, Object p7, Object p8, Object p9, Object p10) { Cons csd = new Cons(t); csd.setId(id); csd.add_pt(p1); @@ -1939,8 +2332,19 @@ public void add_des(int t, Object p1, Object p2, Object p3, add_des(csd); } - public void add_des(int t, Object p1, Object p2, Object p3, - Object p4, Object p5, Object p6, Object p7) { + /** + * Adds a constraint description with seven objects to the list of constraints. + * + * @param t the type of the constraint + * @param p1 the first object + * @param p2 the second object + * @param p3 the third object + * @param p4 the fourth object + * @param p5 the fifth object + * @param p6 the sixth object + * @param p7 the seventh object + */ + public void add_des(int t, Object p1, Object p2, Object p3, Object p4, Object p5, Object p6, Object p7) { Cons csd = new Cons(t); csd.setId(id); csd.add_pt(p1); @@ -1953,7 +2357,13 @@ public void add_des(int t, Object p1, Object p2, Object p3, add_des(csd); } - + /** + * Loads the constraint data from a DataInputStream. + * + * @param in the DataInputStream to read from + * @param dp the DrawProcess instance to use for retrieving elements + * @throws IOException if an I/O error occurs + */ public void Load(DataInputStream in, DrawProcess dp) throws IOException { id = in.readInt(); ConstraintType = in.readInt(); @@ -2001,18 +2411,16 @@ public void Load(DataInputStream in, DrawProcess dp) throws IOException { this.ConstraintType = NSQUARE; elementlist.remove(1); } - } } - int pidx(CPoint p) { - return p.x1.xindex; - } - - int pidy(CPoint p) { - return p.y1.xindex; - } - + /** + * Creates a new TPoly object from two TMono objects. + * + * @param m1 the first TMono object + * @param m2 the second TMono object + * @return the created TPoly object + */ TPoly mpoly(TMono m1, TMono m2) { TPoly p1 = new TPoly(); p1.setPoly(m1); @@ -2022,6 +2430,12 @@ TPoly mpoly(TMono m1, TMono m2) { return p2; } + /** + * Returns the special angle value for the given angle in degrees. + * + * @param v the angle in degrees + * @return the special angle value + */ public static double get_sp_ag_value(int v) { double val = 0; if (v == 90) @@ -2032,10 +2446,13 @@ public static double get_sp_ag_value(int v) { return val; } - public double get_sangle_v() { - return get_sp_ag_value(proportion); - } - + /** + * Checks if the constraint is satisfied for the given coordinates. + * + * @param x the x-coordinate + * @param y the y-coordinate + * @return true if the constraint is satisfied, false otherwise + */ public boolean check_constraint(double x, double y) { switch (ConstraintType) { case ANGLE_BISECTOR: @@ -2047,6 +2464,13 @@ public boolean check_constraint(double x, double y) { } } + /** + * Checks if the incenter constraint is satisfied for the given coordinates. + * + * @param x the x-coordinate + * @param y the y-coordinate + * @return true if the incenter constraint is satisfied, false otherwise + */ public boolean check_incenter(double x, double y) { CPoint p1 = (CPoint) elementlist.get(1); CPoint p2 = (CPoint) elementlist.get(2); @@ -2066,6 +2490,13 @@ public boolean check_incenter(double x, double y) { return r1 * r2 > 0 && r3 * r4 > 0; } + /** + * Checks if the angle bisector constraint is satisfied for the given coordinates. + * + * @param x the x-coordinate + * @param y the y-coordinate + * @return true if the angle bisector constraint is satisfied, false otherwise + */ public boolean check_agbisector(double x, double y) { CPoint p1 = (CPoint) elementlist.get(0); CPoint p2 = (CPoint) elementlist.get(1); @@ -2083,26 +2514,65 @@ public boolean check_agbisector(double x, double y) { return r1 * r2 > 0; } + /** + * Calculates the determinant of the given points. + * + * @param x1 the x-coordinate of the first point + * @param y1 the y-coordinate of the first point + * @param x2 the x-coordinate of the second point + * @param y2 the y-coordinate of the second point + * @param x the x-coordinate of the third point + * @param y the y-coordinate of the third point + * @return the determinant value + */ public double dr_pr(double x1, double y1, double x2, double y2, double x, double y) { return (y2 - y1) * (x - x2) - (y - y2) * (x2 - x1); - } + /** + * Creates a TMono object representing the equality of distances between two pairs of points. + * + * @param p1 the first point of the first pair + * @param p2 the second point of the first pair + * @param p3 the first point of the second pair + * @param p4 the second point of the second pair + * @return the created TMono object + */ public TMono eqdistance(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { return poly.eqdistance(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex); } + /** + * Compares two lines based on the ID of their first points. + * + * @param ln1 the first line + * @param ln2 the second line + * @return true if the first point of the first line has a greater ID than the first point of the second line, false otherwise + */ public boolean compareLN(CLine ln1, CLine ln2) { - return - (ln1.getfirstPoint().m_id > ln2.getfirstPoint().m_id); + return (ln1.getfirstPoint().m_id > ln2.getfirstPoint().m_id); } + /** + * Parses a TMono object from a string representation. + * + * @param name the name of the TMono object + * @param func the function string + * @param x the x-coordinate + * @return the parsed TMono object + */ public TMono parseTMonoString(String name, String func, int x) { Parser p = new Parser(name, func, x); TMono m = p.parse(); return m; } + /** + * Adds a zero coefficient to the TMono object if its length is 1. + * + * @param m1 the TMono object + * @return true if a zero coefficient was added, false otherwise + */ public boolean addZeron(TMono m1) { if (m1 != null && poly.plength(m1) == 1) return poly.addZeroN(m1.x); diff --git a/src/main/java/wprover/DPanel.java b/src/main/java/wprover/DPanel.java index ff3914a1..2746d918 100644 --- a/src/main/java/wprover/DPanel.java +++ b/src/main/java/wprover/DPanel.java @@ -3,36 +3,51 @@ import javax.swing.*; import java.awt.*; import java.awt.event.*; - +/** + * A custom JPanel that handles various mouse and component events. + * Implements MouseListener, MouseMotionListener, MouseWheelListener, and ComponentListener. + */ class DPanel extends JPanel implements MouseListener, MouseMotionListener, MouseWheelListener, ComponentListener { + /** Constant for draw mode. */ final public static int DRAW = 0; + /** Constant for construction mode. */ final public static int CONS = 1; // construction. DrawTextProcess dp = new DrawTextProcess(); + /** The input type, either DRAW or CONS. */ private int Input_type = DRAW; // draw ,1 : prove GExpert gxInstance; - public void SetInputType(int type) { - this.Input_type = type; - } - + /** + * Clears all components from the panel. + */ public void clearAll() { this.removeAll(); } - public void SetDrawType(int type) { - this.Input_type = DRAW; - dp.SetCurrentAction(type); - } - + /** + * Sets the animation step. + * + * @param step the step value to set + */ public void setStep(double step) { dp.animate.Setstep(step); } + /** + * Checks if an action needs to proceed based on the prover's state. + * + * @return true if the action needs to proceed, false otherwise + */ public boolean actionNeedProceed() { return gxInstance == null || !gxInstance.getpprove().isProverRunning(); } + /** + * Constructor for DPanel. + * + * @param gx the GExpert instance + */ public DPanel(GExpert gx) { gxInstance = gx; @@ -42,18 +57,22 @@ public DPanel(GExpert gx) { this.setDoubleBuffered(true); this.setLayout(null); this.addComponentListener(this); -// this.setBorder(BorderFactory.createLineBorder(Color.lightGray)); -// this.setBorder(new GBevelBorder(GBevelBorder.RAISED)); this.setBackground(CMisc.getBackGroundColor()); } - + /** + * Recalculates and repaints the panel. + */ public void repaintAndCalculate() { dp.reCalculate(); this.repaint(); } - + /** + * Handles animation based on the type. + * + * @param type the type of animation (0: on time, 1: start, 2: stop) + */ public void onAnimate(int type) { if (type == 1) //start dp.animationStart(); @@ -63,18 +82,22 @@ else if (type == 0) dp.animationOntime(); repaint(); - } + /** + * Returns the preferred size of the panel. + * + * @return the preferred size + */ public Dimension getPreferredSize() { -// Rectangle rc = dp.getBounds(); -// -// int x = (int) (Math.abs(rc.getX() + rc.getWidth())) + 20; -// int y = (int) (Math.abs(rc.getY() + rc.getHeight())) + 20; -// return new Dimension(x, y); return super.getPreferredSize(); } + /** + * Handles mouse pressed events. + * + * @param e the MouseEvent + */ public void mousePressed(MouseEvent e) { if (!this.actionNeedProceed()) return; @@ -93,23 +116,30 @@ public void mousePressed(MouseEvent e) { } } + /** + * Handles mouse dragged events. + * + * @param e the MouseEvent + */ public void mouseDragged(MouseEvent e) { if (!this.actionNeedProceed()) return; int button = e.getButton(); if (button == MouseEvent.BUTTON3) { - return; } if (Input_type == 0) { dp.DWMouseDrag(e.getX(), e.getY()); repaint(); - } else { } } - + /** + * Handles mouse released events. + * + * @param e the MouseEvent + */ public void mouseReleased(MouseEvent e) { if (!this.actionNeedProceed()) return; @@ -124,9 +154,12 @@ public void mouseReleased(MouseEvent e) { } } + /** + * Handles mouse moved events. + * + * @param e the MouseEvent + */ public void mouseMoved(MouseEvent e) { - - int button = e.getButton(); if (button == MouseEvent.BUTTON3) @@ -137,6 +170,11 @@ public void mouseMoved(MouseEvent e) { } } + /** + * Handles mouse clicked events. + * + * @param e the MouseEvent + */ public void mouseClicked(MouseEvent e) { if (!this.actionNeedProceed()) return; @@ -145,69 +183,82 @@ public void mouseClicked(MouseEvent e) { dp.DWMouseRightClick(e.getX(), e.getY()); else if (e.getClickCount() > 1) dp.DWMouseDbClick(e.getX(), e.getY()); - } + /** + * Handles mouse exited events. + * + * @param e the MouseEvent + */ public void mouseExited(MouseEvent e) { -// if (!this.actionNeedProceed()) -// return; - dp.setMouseInside(false); this.repaint(); } + /** + * Handles mouse entered events. + * + * @param e the MouseEvent + */ public void mouseEntered(MouseEvent e) { -// if (!this.actionNeedProceed()) -// return; - dp.setMouseInside(true); this.repaint(); } + /** + * Handles mouse wheel moved events. + * + * @param e the MouseWheelEvent + */ public void mouseWheelMoved(MouseWheelEvent e) { -// if (!this.actionNeedProceed()) -// return; - int n = e.getScrollAmount(); dp.DWMouseWheel(e.getX(), e.getY(), n, e.getWheelRotation()); this.repaint(); } - + /** + * Handles component resized events. + * + * @param e the ComponentEvent + */ public void componentResized(ComponentEvent e) { } + /** + * Handles component moved events. + * + * @param e the ComponentEvent + */ public void componentMoved(ComponentEvent e) { } + /** + * Handles component shown events. + * + * @param e the ComponentEvent + */ public void componentShown(ComponentEvent e) { } + /** + * Handles component hidden events. + * + * @param e the ComponentEvent + */ public void componentHidden(ComponentEvent e) { } - + /** + * Paints the component. + * + * @param g the Graphics object + */ public void paintComponent(Graphics g) { super.paintComponent(g); Dimension dm = this.getSize(); dp.SetDimension(dm.getWidth(), dm.getHeight()); dp.paintPoint(g); -// paintBD(g); - } - - - final private static BasicStroke bstroke = new BasicStroke(1.0f); - - public void paintBD(Graphics g) { - Graphics2D g2 = (Graphics2D) g; - g2.setStroke(bstroke); - g2.setColor(Color.LIGHT_GRAY); - int w = this.getWidth() - 1; - int h = this.getHeight() - 1; - - g2.drawLine(0, h, w, h); - g2.drawLine(w, 0, w, h); } -} +} \ No newline at end of file diff --git a/src/main/java/wprover/DiagramUpdater.java b/src/main/java/wprover/DiagramUpdater.java index 1eecd8ea..9c0a67e5 100644 --- a/src/main/java/wprover/DiagramUpdater.java +++ b/src/main/java/wprover/DiagramUpdater.java @@ -1,13 +1,13 @@ package wprover; /** - * Created by IntelliJ IDEA. - * User: ye - * Date: Mar 14, 2007 - * Time: 9:03:10 AM - * To change this template use File | Settings | File Templates. + * DiagramUpdater is an interface that defines a method for updating a diagram. + * Implementing classes should provide the specific implementation of the UpdateDiagram method. */ public interface DiagramUpdater { - + /** + * Updates the diagram. + * This method should be implemented to provide the specific logic for updating the diagram. + */ public void UpdateDiagram(); } diff --git a/src/main/java/wprover/DialogProperty.java b/src/main/java/wprover/DialogProperty.java index 68eb1c27..98f053dd 100644 --- a/src/main/java/wprover/DialogProperty.java +++ b/src/main/java/wprover/DialogProperty.java @@ -4,14 +4,16 @@ import java.awt.*; /** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2005-7-16 - * Time: 15:47:43 - * To change this template use File | Settings | File Templates. + * DialogProperty is a class that represents a dialog for displaying properties. + * It extends the JBaseDialog class and provides a constructor to initialize the dialog with a specified owner and panel. */ public class DialogProperty extends JBaseDialog { + /** + * Constructs a DialogProperty with specified owner and panel. + * @param owner the owner of the dialog + * @param panel the panel to be displayed in the dialog + */ public DialogProperty(GExpert owner,JPanel panel) { super(owner.getFrame(),false); diff --git a/src/main/java/wprover/DialogPsProperty.java b/src/main/java/wprover/DialogPsProperty.java index 6a345ab0..97edc0b6 100644 --- a/src/main/java/wprover/DialogPsProperty.java +++ b/src/main/java/wprover/DialogPsProperty.java @@ -3,12 +3,21 @@ import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; - +/** + * Dialog for setting PostScript (PS) properties. + * Extends JBaseDialog and implements ActionListener. + */ public class DialogPsProperty extends JBaseDialog implements ActionListener { private int type = -1; private JCheckBox pfill; private GExpert gxInstance; + /** + * Retrieves the localized language string for the given key. + * + * @param s the key for the language string + * @return the localized language string, or the key if no localization is found + */ public String getLanguage(String s) { String s1 = ""; if (gxInstance != null) @@ -18,13 +27,18 @@ public String getLanguage(String s) { return s; } + /** + * Constructor for the DialogPsProperty class. + * Initializes the dialog with the specified GExpert owner. + * + * @param owner the GExpert instance that owns this dialog + */ public DialogPsProperty(GExpert owner) { super(owner.getFrame(), true); gxInstance = owner; this.setTitle(getLanguage("Save as PS")); -// this.setSize(350, 120); JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); JToggleButton button1 = new JToggleButton(gxInstance.getLanguage("Color")); @@ -54,14 +68,16 @@ public DialogPsProperty(GExpert owner) { JPanel ppanel = new JPanel(); ppanel.setLayout(new BoxLayout(ppanel, BoxLayout.Y_AXIS)); pfill = new JCheckBox(gxInstance.getLanguage("Point filled with background color")); -// ptext = new JCheckBox(gxInstance.getLanguage(1014, "Proof text")); -// ptext.setSelected(true); ppanel.add(pfill); -// ppanel.add(ptext); this.getContentPane().add(ppanel, "South"); this.pack(); } + /** + * Handles action events for the dialog's buttons. + * + * @param e the ActionEvent triggered by a button click + */ public void actionPerformed(ActionEvent e) { String command = e.getActionCommand(); if (command.compareTo("Color") == 0) @@ -75,15 +91,21 @@ else if (command.compareTo("Cancel") == 0) this.setVisible(false); } + /** + * Retrieves the selected save type for PostScript. + * + * @return the save type (0: Color, 1: Gray, 2: Black and White, 3: Cancel) + */ int getSavePsType() { return type; } + /** + * Checks if the point fill option is selected. + * + * @return true if the point fill option is selected, false otherwise + */ boolean getPointfilled() { return pfill.isSelected(); } - -// boolean getisProveTextSaved() { -// return ptext.isSelected(); -// } } diff --git a/src/main/java/wprover/DrawBase.java b/src/main/java/wprover/DrawBase.java index 1b46d880..96435130 100644 --- a/src/main/java/wprover/DrawBase.java +++ b/src/main/java/wprover/DrawBase.java @@ -13,11 +13,9 @@ import java.util.Vector; /** - * Created by IntelliJ IDEA. - * User: yezheng - * Date: 2006-5-2 - * Time: 21:27:59 - * To change this template use File | Settings | File Templates. + * DrawBase is a class that provides methods for drawing geometric objects and handling user interactions. + * It includes methods for drawing points, lines, circles, polygons, and other geometric shapes. + * It also provides methods for handling mouse events and managing the drawing environment. */ public class DrawBase { final public static int D_POINT = 1; @@ -122,7 +120,15 @@ public class DrawBase { protected GExpert gxInstance; protected Language lan; + protected boolean footMarkShown = CMisc.isFootMarkShown(); + protected double footMarkLength = CMisc.FOOT_MARK_LENGTH; + /** + * The POOL array contains the types of geometric objects and their parameters. + * Each entry in the array represents a different type of geometric object, + * with the first element being the type identifier and the subsequent elements + * representing the number of parameters required for that object. + */ final public static int[][] POOL = //1: pt //2. line 3. Circle. 4. LC (line or circle). { @@ -153,7 +159,6 @@ public class DrawBase { {D_CCLINE, 3, 3}, {D_IOSTRI, 1, 1}, {MIRROR, 4, 2}, -// {D_PFOOT, 1, 1}, {87, 1, 1, 4}, {43, 1}, {D_PTDISTANCE, 1, 1}, @@ -169,14 +174,17 @@ public class DrawBase { {75, 1, 1}, {82, 1, 1, 1, 1, 1, 1, 1, 1}, {81, 2, 1} - -// {29, 1, 1, 1, 4} -// {D_PFOOT, 1, 1} - - }; - + /** + * Returns the number of parameters for the specified geometric object type. + * For a polygon (\_D\_POLYGON), returns the current status if less than 10, otherwise 0. + * For other types, iterates through the POOL array and returns the parameter count. + * Returns -1 if the type is not found. + * + * @param a the geometric object type identifier + * @return the number of parameters for the object type, or -1 if not found + */ final public int getPooln(int a) { if (a == D_POLYGON) { if (STATUS < 10) @@ -192,6 +200,15 @@ final public int getPooln(int a) { return -1; } + /** + * Returns the parameter at a specific index for the given geometric object type. + * Iterates through the POOL array and returns the value at the specified index. + * If the index is out of bounds, returns 1. + * + * @param a the geometric object type identifier + * @param index the index of the parameter to retrieve + * @return the parameter value at the given index, or 1 if not found + */ public int getPoolA(int a, int index) { for (int i = 0; i < POOL.length; i++) { if (POOL[i][0] == a) { @@ -202,25 +219,57 @@ public int getPoolA(int a, int index) { return 1; } + /** + * Sets the language for the drawing environment. + * + * @param lan the Language instance to be set + */ public void setLanguage(Language lan) { this.lan = lan; } + /** + * Handles a button down event at the specified coordinates. + * The implementation depends on the current action. + * + * @param x the x-coordinate of the button down event + * @param y the y-coordinate of the button down event + */ public void DWButtonDown(double x, double y) { switch (CurrentAction) { } } + /** + * Sets the state indicating whether the mouse is inside the drawing area. + * + * @param t true if the mouse is inside, false otherwise + */ public void setMouseInside(boolean t) { mouseInside = t; } + /** + * Creates a temporary point with the specified coordinates. + * + * @param x the x-coordinate of the temporary point + * @param y the y-coordinate of the temporary point + * @return a new temporary CPoint instance + */ final public CPoint CreateATempPoint(double x, double y) { Param p1 = new Param(-1, x); Param p2 = new Param(-1, y); return new CPoint(CPoint.TEMP_POINT, p1, p2); } + /** + * Finds and returns an existing line that connects the two specified points. + * Returns null if no such line exists or if either point is null. + * + * @param p1 the first point + * @param p2 the second point + * @return the CLine connecting the two points, or null if not found + */ public CLine fd_line(CPoint p1, CPoint p2) { if (p1 == null || p2 == null) { return null; @@ -234,6 +283,11 @@ public CLine fd_line(CPoint p1, CPoint p2) { return null; } + /** + * Sets the antialiasing rendering hint on the provided Graphics2D object based on the application setting. + * + * @param g2 the Graphics2D object on which to set the anti-aliasing + */ final public void setAntiAlias(Graphics2D g2) { if (CMisc.AntiAlias) { RenderingHints qualityHints = new RenderingHints(RenderingHints. @@ -249,21 +303,16 @@ final public void setAntiAlias(Graphics2D g2) { } } - void paint(Graphics2D g2) { - drawList(polygonlist, g2); - drawSelect(SelectList, g2); - drawPerpFoot(g2, null, 0); - drawList(tracelist, g2); - drawList(distancelist, g2); - drawList(anglelist, g2); - drawList(circlelist, g2); - drawList(linelist, g2); - drawList(pointlist, g2); - drawList(textlist, g2); - drawList(otherlist, g2); - drawCatch(g2); - } - + /** + * Draws the perpendicular footmarks for constraints. + * Iterates through the constraint list and draws the foot for each applicable constraint. + * Supports constraint types such as PERPENDICULAR, PFOOT, RIGHT\_ANGLED\_TRIANGLE, + * and RIGHT\_ANGLE\_TRAPEZOID. + * + * @param g2 the Graphics2D object used for drawing + * @param vlist a Vector used for additional drawing information + * @param type the mode type (0 for drawing and 1 for PostScript) + */ final public void drawPerpFoot(Graphics2D g2, Vector vlist, int type) { // 0: draw ,1: ps for (int i = 0; i < constraintlist.size(); i++) { Constraint cs = (Constraint) constraintlist.get(i); @@ -328,11 +377,6 @@ final public void drawPerpFoot(Graphics2D g2, Vector vlist, int type) { // 0: dr CPoint p3 = (CPoint) cs.getelement(2); CPoint p4 = (CPoint) cs.getelement(3); -// drawTTFoot(type, vlist, g2, p1.getx(), p1.gety(), p1, p2, p4); -// drawTTFoot(type, vlist, g2, p2.getx(), p2.gety(), p2, p1, p3); -// drawTTFoot(type, vlist, g2, p3.getx(), p3.gety(), p3, p2, p4); -// drawTTFoot(type, vlist, g2, p4.getx(), p4.gety(), p4, p1, p3); - } break; case Constraint.RIGHT_ANGLED_TRIANGLE: { @@ -359,22 +403,44 @@ final public void drawPerpFoot(Graphics2D g2, Vector vlist, int type) { // 0: dr } + /** + * Removes the last n elements from the provided Vector. + * + * @param v the Vector from which elements will be removed + * @param n the number of elements to remove from the end + */ final public void removeFromeListLastNElements(Vector v, int n) { if (v.size() < n) return; while (n-- > 0) v.remove(v.size() - 1); } + /** + * Returns the number of points in the drawing. + * + * @return the size of the point list + */ final public int getPointSize() { return pointlist.size(); } + /** + * Returns a copy of the point list. + * + * @return a new Vector containing all points. + */ final public Vector getPointList() { Vector v = new Vector(); v.addAll(pointlist); return v; } + /** + * Draws all objects in the given list using the provided Graphics2D context. + * + * @param list the Vector containing drawable objects. + * @param g2 the Graphics2D object used for drawing. + */ final public void drawList(Vector list, Graphics2D g2) { if (list == null || list.size() == 0) { return; @@ -386,18 +452,33 @@ final public void drawList(Vector list, Graphics2D g2) { } } + /** + * Draws the name and coordinate location of a point. + * + * @param p the point whose location is displayed. + * @param g2 the Graphics2D context used for drawing. + */ final public void drawPointNameLocation(CPoint p, Graphics2D g2) { g2.drawString("(x: " + ((int) p.getx()) + ", y: " + (int) p.gety() + ")", (int) p.getx() + 23, (int) p.gety() - 5); // FIXME: 23 and 5 seem hardcoded } + /** + * Sets the current drawing environment parameters such as color and stroke. + * + * @param g2 the Graphics2D object where the environment settings are applied. + */ final public void setCurrentDrawEnvironment(Graphics2D g2) { g2.setColor(DrawData.getCurrentColor()); g2.setStroke(CMisc.NormalLineStroke); } - + /** + * Draws the grid on the drawing area if grid drawing or snapping is enabled. + * + * @param g2 the Graphics2D context used for drawing the grid. + */ final public void drawGrid(Graphics2D g2) { if (!this.DRAWGRID && !SNAP) { return; @@ -424,6 +505,14 @@ final public void drawGrid(Graphics2D g2) { } + /** + * Draws a tip triangle marker based on the provided points. + * + * @param p1 the first point defining the triangle. + * @param p2 the second point defining the triangle. + * @param p the reference point for triangle alignment. + * @param g2 the Graphics2D context used for drawing. + */ final public void drawTipTirangle(CPoint p1, CPoint p2, CPoint p, Graphics2D g2) { @@ -484,6 +573,14 @@ final public void drawTipTirangle(CPoint p1, CPoint p2, CPoint p, catchY = y2; } + /** + * Draws a cross centered at the given coordinates with the specified half-width. + * + * @param x the x-coordinate of the center. + * @param y the y-coordinate of the center. + * @param w the half-width of the cross. + * @param g2 the Graphics2D context used for drawing. + */ final public void drawCross(int x, int y, int w, Graphics2D g2) { g2.setColor(Color.red); g2.setStroke(new BasicStroke(1.0f)); @@ -491,6 +588,11 @@ final public void drawCross(int x, int y, int w, Graphics2D g2) { g2.drawLine(x + w, y - w, x - w, y + w); } + /** + * Draws a catch rectangle around the catch point if certain conditions are met. + * + * @param g2 the Graphics2D context used for drawing. + */ public void drawCatchRect(Graphics2D g2) { if (!isPointOnObject || !mouseInside) return; int x = (int) CatchPoint.getx(); @@ -506,6 +608,11 @@ public void drawCatchRect(Graphics2D g2) { } } + /** + * Draws a cross marker to indicate an intersection catch point. + * + * @param g2 the Graphics2D context used for drawing. + */ public void drawCatchInterCross(Graphics2D g2) { if (!isPointOnIntersection) return; int x = (int) CatchPoint.getx(); @@ -516,18 +623,23 @@ public void drawCatchInterCross(Graphics2D g2) { g2.drawString(GExpert.getLanguage("Intersection"), x + 10, y); } + /** + * Draws a tip rectangle around the specified coordinates. + * + * @param x the x-coordinate for the tip rectangle. + * @param y the y-coordinate for the tip rectangle. + * @param g2 the Graphics2D context used for drawing. + */ public void drawTipRect(int x, int y, Graphics2D g2) { g2.setColor(Color.red); this.drawRect(x - 5, y - 5, x + 5, y + 5, g2); } - public void drawCatchCross(Graphics2D g2) { - if (!isPointOnObject || !mouseInside) return; - int x = (int) CatchPoint.getx(); - int y = (int) CatchPoint.gety(); - drawCross(x, y, 5, g2); - } - + /** + * Draws either a point or a cross based on the object's state. + * + * @param g2 the Graphics2D context used for drawing. + */ public void drawPointOrCross(Graphics2D g2) { if (this.isPointOnObject) { if (!isPointOnIntersection) @@ -539,6 +651,11 @@ public void drawPointOrCross(Graphics2D g2) { } } + /** + * Draws the name of the caught object if exactly one object is caught. + * + * @param g2 the Graphics2D context used for drawing. + */ public void drawCatchObjName(Graphics2D g2) { if (CatchList.size() != 1) return; @@ -552,6 +669,14 @@ public void drawCatchObjName(Graphics2D g2) { g2.drawString(s, MouseX + 16, MouseY + 20); } + /** + * Draws a tip square marker using the provided points. + * + * @param p1 the first point defining the square. + * @param p2 the second point defining the square. + * @param p the reference point used for adjusting the square. + * @param g2 the Graphics2D context used for drawing. + */ final public void drawTipSquare(CPoint p1, CPoint p2, CPoint p, Graphics2D g2) { double x0 = p1.getx(); @@ -613,9 +738,18 @@ final public void drawTipSquare(CPoint p1, CPoint p2, CPoint p, } } - protected boolean footMarkShown = CMisc.isFootMarkShown(); - protected double footMarkLength = CMisc.FOOT_MARK_LENGTH; - + /** + * Draws two footmarks for a constraint between two lines. + * + * @param type the drawing mode (0 for direct drawing, non-zero for vector accumulation) + * @param vlist the vector list to add drawing points if not drawing directly + * @param g2 the Graphics2D context to draw on + * @param x the starting x coordinate for the footmark + * @param y the starting y coordinate for the footmark + * @param pc the common point for both lines (may be null) + * @param p1 the first point defining the first line + * @param p2 the second point defining the second line + */ public void drawTTFoot(int type, Vector vlist, Graphics2D g2, double x, double y, CPoint pc, CPoint p1, CPoint p2) { if (p1 == null || p2 == null) return; @@ -666,6 +800,14 @@ public void drawTTFoot(int type, Vector vlist, Graphics2D g2, double x, double y } } + /** + * Draws the catch indicator based on the current catch list and catch point. + * If no catch objects exist, draws smart horizontal/vertical catch lines. + * If one object exists, draws it with its predefined style. + * If multiple objects exist, displays a prompt for selection. + * + * @param g2 the Graphics2D context to draw on + */ public void drawCatch(Graphics2D g2) { int size = CatchList.size(); @@ -709,11 +851,25 @@ public void drawCatch(Graphics2D g2) { } + /** + * Checks if a line connecting the two given points is drawn. + * + * @param p1 the first point + * @param p2 the second point + * @return true if the line exists and is drawn; false otherwise + */ public boolean isLineDrawn(CPoint p1, CPoint p2) { CLine ln = this.fd_line(p1, p2); return ln != null && ln.isdraw(); } + /** + * Draws the selection highlight for a list of geometric objects. + * Iterates over the list and draws each object with selection indication. + * + * @param list the list of objects to be highlighted + * @param g2 the Graphics2D context to use for drawing + */ public void drawSelect(Vector list, Graphics2D g2) { for (int i = 0; i < list.size(); i++) { CClass cc = (CClass) list.get(i); @@ -722,7 +878,16 @@ public void drawSelect(Vector list, Graphics2D g2) { } } - + /** + * Draws a rectangle defined by two opposite corner coordinates. + * Four lines are drawn between the specified corners. + * + * @param x the x coordinate of the first corner + * @param y the y coordinate of the first corner + * @param x1 the x coordinate of the opposite corner + * @param y1 the y coordinate of the opposite corner + * @param g2 the Graphics2D context for drawing + */ public void drawRect(int x, int y, int x1, int y1, Graphics2D g2) { g2.drawLine(x, y, x1, y); g2.drawLine(x, y, x, y1); @@ -730,30 +895,61 @@ public void drawRect(int x, int y, int x1, int y1, Graphics2D g2) { g2.drawLine(x1, y, x1, y1); } - + /** + * Draws a circle defined by two points. + * The first point represents the center and the distance to the + * second point determines the radius. + * + * @param x1 the x coordinate of the center + * @param y1 the y coordinate of the center + * @param x2 the x coordinate of a point on the circle + * @param y2 the y coordinate of a point on the circle + * @param g2 the Graphics2D context for drawing + */ public void drawcircle2p(double x1, double y1, double x2, double y2, Graphics2D g2) { int r = (int) Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); g2.drawOval((int) (x1 - r), (int) (y1 - r), 2 * r, 2 * r); } - + /** + * Draws the specified point using its own drawing method. + * + * @param p the point to be drawn + * @param g2 the Graphics2D context for drawing + */ public void drawpoint(CPoint p, Graphics2D g2) { p.draw(g2); } + /** + * Adds the specified line to the list of lines if it is not already present. + * + * @param ln the line to be added + */ public void addLine(CLine ln) { if (!linelist.contains(ln)) { linelist.add(ln); } } + /** + * Adds the specified circle to the list of circles if it is not already present. + * + * @param c the circle to add + */ public void addCircle(Circle c) { if (!circlelist.contains(c)) { circlelist.add(c); } } + /** + * Searches for a point with the given name in the point list. + * + * @param name the name of the point to search for + * @return the point with the specified name, or null if not found + */ public CPoint findPoint(String name) { for (int i = 0; i < pointlist.size(); i++) { CPoint p = (CPoint) pointlist.get(i); @@ -764,6 +960,16 @@ public CPoint findPoint(String name) { return null; } + /** + * Finds a circle defined by a center point and a point on its circumference. + * + * Searches the circle list for a circle where the first point is the center and + * the second point lies on the circle. + * + * @param p1 the potential center point of the circle + * @param p2 the potential point on the circumference + * @return the matching circle if found; otherwise, null + */ public Circle fd_circle(CPoint p1, CPoint p2) { if (p1 == null || p2 == null) { return null; @@ -779,7 +985,11 @@ public Circle fd_circle(CPoint p1, CPoint p2) { } - + /** + * Returns the count of Cedmark objects present in otherlist. + * + * @return the number of Cedmark marks in otherlist. + */ int getEMarkNum() { int k = 0; for (int i = 0; i < otherlist.size(); i++) { @@ -790,6 +1000,11 @@ int getEMarkNum() { return k; } + /** + * Calculates and returns the bounding rectangle that encompasses all points, circles, and text elements. + * + * @return the bounding Rectangle of the drawing. + */ public Rectangle getBounds() { Rectangle rc = new Rectangle(0, 0, 0, 0); @@ -867,6 +1082,14 @@ public Rectangle getBounds() { return rc; } + /** + * Checks if three points are collinear. + * + * @param p1 the first point. + * @param p2 the second point. + * @param p3 the third point. + * @return true if the points are collinear, false otherwise. + */ static boolean check_Collinear(CPoint p1, CPoint p2, CPoint p3) { if (p1 == null || p2 == null || p3 == null) { return false; @@ -875,16 +1098,46 @@ static boolean check_Collinear(CPoint p1, CPoint p2, CPoint p3) { (p2.gety() - p1.gety()) * (p3.getx() - p2.getx())); } + /** + * Checks if the three points defined by their coordinates are collinear. + * + * @param x1 the x-coordinate of the first point. + * @param y1 the y-coordinate of the first point. + * @param x2 the x-coordinate of the second point. + * @param y2 the y-coordinate of the second point. + * @param x3 the x-coordinate of the third point. + * @param y3 the y-coordinate of the third point. + * @return true if the points are collinear, false otherwise. + */ static boolean check_Collinear(double x1, double y1, double x2, double y2, double x3, double y3) { return isZero((x2 - x1) * (y3 - y2) - (y2 - y1) * (x3 - x2)); } + /** + * Computes the signed area determined by three points. + * + * @param x1 the x-coordinate of the first point. + * @param y1 the y-coordinate of the first point. + * @param x2 the x-coordinate of the second point. + * @param y2 the y-coordinate of the second point. + * @param x3 the x-coordinate of the third point. + * @param y3 the y-coordinate of the third point. + * @return the signed area value. + */ public static double signArea(double x1, double y1, double x2, double y2, double x3, double y3) { return (x2 - x1) * (y3 - y2) - (y2 - y1) * (x3 - x2); } + /** + * Determines if a point lies between two other collinear points. + * + * @param p1 the first endpoint. + * @param p2 the second endpoint. + * @param p3 the point to check. + * @return true if p3 lies between p1 and p2, false otherwise. + */ static boolean check_between(CPoint p1, CPoint p2, CPoint p3) { if (p1 == null || p2 == null || p3 == null) { return false; @@ -898,12 +1151,28 @@ static boolean check_between(CPoint p1, CPoint p2, CPoint p3) { } + /** + * Checks if two lines are parallel. + * + * @param ln1 the first line. + * @param ln2 the second line. + * @return true if the lines are parallel, false otherwise. + */ static boolean check_para(CLine ln1, CLine ln2) { double k1 = ln1.getK(); double k2 = ln2.getK(); return isZero(k1 - k2); } + /** + * Checks if two pairs of points define parallel lines. + * + * @param p1 the first point of the first line. + * @param p2 the second point of the first line. + * @param p3 the first point of the second line. + * @param p4 the second point of the second line. + * @return true if the defined lines are parallel, false otherwise. + */ static boolean check_para(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { if (p1 == null || p2 == null || p3 == null || p4 == null) { return false; @@ -912,6 +1181,15 @@ static boolean check_para(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { (p2.gety() - p1.gety()) * (p4.getx() - p3.getx())); } + /** + * Checks if two lines, defined by two pairs of points, are perpendicular. + * + * @param p1 the first point of the first line. + * @param p2 the second point of the first line. + * @param p3 the first point of the second line. + * @param p4 the second point of the second line. + * @return true if the lines are perpendicular, false otherwise. + */ static boolean check_perp(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { if (p1 == null || p2 == null || p3 == null || p4 == null) { return false; @@ -920,6 +1198,14 @@ static boolean check_perp(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { (p2.gety() - p1.gety()) * (p4.gety() - p3.gety()))); } + /** + * Checks if a point is the midpoint of two other points. + * + * @param p the point to check. + * @param p1 the first endpoint. + * @param p2 the second endpoint. + * @return true if p is the midpoint of p1 and p2, false otherwise. + */ static boolean check_mid(CPoint p, CPoint p1, CPoint p2) { if (p == null || p1 == null || p2 == null) { return false; @@ -927,6 +1213,15 @@ static boolean check_mid(CPoint p, CPoint p1, CPoint p2) { return check_Collinear(p1, p2, p) && check_eqdistance(p, p1, p, p2); } + /** + * Determines if four points are concyclic, i.e., lie on the same circle. + * + * @param p1 the first point. + * @param p2 the second point. + * @param p3 the third point. + * @param p4 the fourth point. + * @return true if the four points are concyclic, false otherwise. + */ static boolean check_cyclic(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { if (p1 == null || p2 == null || p3 == null || p4 == null) { return false; @@ -949,6 +1244,15 @@ static boolean check_cyclic(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { return isZero(t1 - t2) && isZero(t2 - t3) && isZero(t3 - t4); } + /** + * Checks if the distances between the first pair of points and the second pair of points are equal. + * + * @param p1 the first point of the first pair. + * @param p2 the second point of the first pair. + * @param p3 the first point of the second pair. + * @param p4 the second point of the second pair. + * @return true if the distances are equal, false otherwise. + */ static boolean check_eqdistance(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { if (p1 == null || p2 == null || p3 == null || p4 == null) { return false; @@ -956,11 +1260,35 @@ static boolean check_eqdistance(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { return isZero(sdistance(p1, p2) - sdistance(p3, p4)); } + /** + * Checks if the distance between two points defined by coordinates is equal to the distance between another two points. + * + * @param x1 the x-coordinate of the first point. + * @param y1 the y-coordinate of the first point. + * @param x2 the x-coordinate of the second point. + * @param y2 the y-coordinate of the second point. + * @param x3 the x-coordinate of the third point. + * @param y3 the y-coordinate of the third point. + * @param x4 the x-coordinate of the fourth point. + * @param y4 the y-coordinate of the fourth point. + * @return true if the computed distances are equal, false otherwise. + */ static boolean check_eqdistance(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) { return isZero(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2) - Math.pow(x3 - x4, 2) - Math.pow(y3 - y4, 2)); } + /** + * Checks if the distance between two pairs of points, scaled by given factors, are equal. + * + * @param p1 the first point of the first pair. + * @param p2 the second point of the first pair. + * @param p3 the first point of the second pair. + * @param p4 the second point of the second pair. + * @param t1 the scaling factor for the first pair. + * @param t2 the scaling factor for the second pair. + * @return true if the scaled distances are equal, false otherwise. + */ static boolean check_eqdistance(CPoint p1, CPoint p2, CPoint p3, CPoint p4, int t1, int t2) { if (p1 == null || p2 == null || p3 == null || p4 == null) { return false; @@ -968,6 +1296,17 @@ static boolean check_eqdistance(CPoint p1, CPoint p2, CPoint p3, CPoint p4, int return isZero(sdistance(p1, p2) * t2 - sdistance(p3, p4) * t1); } + /** + * Checks if the angles formed by three points in two sets are equal. + * + * @param p1 the first point of the first angle. + * @param p2 the vertex of the first angle. + * @param p3 the third point of the first angle. + * @param p4 the first point of the second angle. + * @param p5 the vertex of the second angle. + * @param p6 the third point of the second angle. + * @return true if the angles are equal, false otherwise. + */ static boolean check_eqangle(CPoint p1, CPoint p2, CPoint p3, CPoint p4, CPoint p5, CPoint p6) { if (p1 == null || p2 == null || p3 == null || p4 == null) { return false; @@ -977,6 +1316,19 @@ static boolean check_eqangle(CPoint p1, CPoint p2, CPoint p3, CPoint p4, CPoint return isZero(t1 - t2); } + /** + * Checks if the angles defined by four points in two sets are equal. + * + * @param p1 the first point of the first angle. + * @param p2 the second point of the first angle. + * @param p3 the third point of the first angle. + * @param p4 the fourth point used with the first angle calculation. + * @param p5 the first point of the second angle. + * @param p6 the second point of the second angle. + * @param p7 the third point of the second angle. + * @param p8 the fourth point used with the second angle calculation. + * @return true if the angles are equal, false otherwise. + */ static boolean check_eqangle(CPoint p1, CPoint p2, CPoint p3, CPoint p4, CPoint p5, CPoint p6, CPoint p7, CPoint p8) { if (p1 == null || p2 == null || p3 == null || p4 == null || p5 == null || p6 == null || p7 == null || p8 == null) { return false; @@ -986,7 +1338,15 @@ static boolean check_eqangle(CPoint p1, CPoint p2, CPoint p3, CPoint p4, CPoint return isZero(t1 - t2); } - + /** + * Checks if points p3 and p4 lie on the same side of the line defined by p1 and p2. + * + * @param p1 first point defining the line + * @param p2 second point defining the line + * @param p3 first point to test + * @param p4 second point to test + * @return true if p3 and p4 are on the same side of the line; false otherwise + */ public static boolean check_same_side(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { if (p4 == null || p1 == null || p2 == null || p3 == null) { return false; @@ -994,12 +1354,29 @@ public static boolean check_same_side(CPoint p1, CPoint p2, CPoint p3, CPoint p4 return collv(p1, p2, p3) * collv(p1, p2, p4) > 0; } + /** + * Computes the cross product of vectors AB and AC. + * + * @param A the starting point + * @param B the end point of the first vector + * @param C the end point of the second vector + * @return the cross product value + */ public static double collv(CPoint A, CPoint B, CPoint C) { double d1 = (B.getx() - A.getx()) * (C.gety() - A.gety()) - (B.gety() - A.gety()) * (C.getx() - A.getx()); return d1; } + /** + * Determines if point p lies inside the triangle defined by p1, p2, and p3. + * + * @param p the point to test + * @param p1 first vertex of the triangle + * @param p2 second vertex of the triangle + * @param p3 third vertex of the triangle + * @return true if p is inside the triangle; false otherwise + */ public static boolean check_triangle_inside(CPoint p, CPoint p1, CPoint p2, CPoint p3) { if (p == null || p1 == null || p2 == null || p3 == null) { return false; @@ -1013,16 +1390,17 @@ public static boolean check_triangle_inside(CPoint p, CPoint p1, CPoint p2, CPoi } - public static double areaTriangle(CPoint p1, CPoint p2, CPoint p3) { - double a = DrawBase.sdistance(p1, p2); - double b = DrawBase.sdistance(p1, p3); - double c = DrawBase.sdistance(p3, p2); - - return Math.sqrt(a * a * c * c - Math.pow(a * a + c * c - b * b, 2) / 4); - - - } - + /** + * Compares two angles defined by sets of three points. + * + * @param p1 first angle's first point + * @param p2 vertex of the first angle + * @param p3 first angle's third point + * @param p4 second angle's first point + * @param p5 vertex of the second angle + * @param p6 second angle's third point + * @return true if the absolute value of the first angle is greater than that of the second; false otherwise + */ static boolean check_angle_less(CPoint p1, CPoint p2, CPoint p3, CPoint p4, CPoint p5, CPoint p6) { if (p1 == null || p2 == null || p3 == null || p4 == null) { return false; @@ -1032,6 +1410,15 @@ static boolean check_angle_less(CPoint p1, CPoint p2, CPoint p3, CPoint p4, CPoi return Math.abs(t1) > Math.abs(t2); } + /** + * Compares the distances between two pairs of points. + * + * @param p1 first point of the first pair + * @param p2 second point of the first pair + * @param p3 first point of the second pair + * @param p4 second point of the second pair + * @return true if the distance between p1 and p2 is less than the distance between p3 and p4; false otherwise + */ static boolean check_distance_less(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { if (p1 == null || p2 == null || p3 == null || p4 == null) { return false; @@ -1039,6 +1426,14 @@ static boolean check_distance_less(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { return (sdistance(p1, p2) < sdistance(p3, p4)); } + /** + * Checks if point p1 is equidistant from points p2 and p3. + * + * @param p1 the point to test + * @param p2 first end of the segment + * @param p3 second end of the segment + * @return true if p1 is equidistant to p2 and p3; false otherwise + */ static boolean check_bisect(CPoint p1, CPoint p2, CPoint p3) { if (p1 == null || p2 == null || p3 == null) { return false; @@ -1046,6 +1441,17 @@ static boolean check_bisect(CPoint p1, CPoint p2, CPoint p3) { return isZero(sdistance(p1, p2) - sdistance(p1, p3)); } + /** + * Determines if two triangles are similar by comparing the ratios of their corresponding sides. + * + * @param p1 first vertex of the first triangle + * @param p2 second vertex of the first triangle + * @param p3 third vertex of the first triangle + * @param p4 first vertex of the second triangle + * @param p5 second vertex of the second triangle + * @param p6 third vertex of the second triangle + * @return true if the triangles are similar; false otherwise + */ static boolean check_simtri(CPoint p1, CPoint p2, CPoint p3, CPoint p4, CPoint p5, CPoint p6) { if (p1 == null || p2 == null || p3 == null || p4 == null || p5 == null || @@ -1064,6 +1470,17 @@ static boolean check_simtri(CPoint p1, CPoint p2, CPoint p3, CPoint p4, return isZero(t1 - t2) && isZero(t1 - t3) && isZero(t2 - t3); } + /** + * Determines if two triangles are congruent by comparing the lengths of their corresponding sides. + * + * @param p1 first vertex of the first triangle + * @param p2 second vertex of the first triangle + * @param p3 third vertex of the first triangle + * @param p4 first vertex of the second triangle + * @param p5 second vertex of the second triangle + * @param p6 third vertex of the second triangle + * @return true if the triangles are congruent; false otherwise + */ static boolean check_congtri(CPoint p1, CPoint p2, CPoint p3, CPoint p4, CPoint p5, CPoint p6) { if (p1 == null || p2 == null || p3 == null || p4 == null || p5 == null || @@ -1080,23 +1497,28 @@ static boolean check_congtri(CPoint p1, CPoint p2, CPoint p3, CPoint p4, return isZero(r1 - r4) && isZero(r2 - r5) && isZero(r3 - r6); } - static boolean check_lc_tangent(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { - return false; - } - - static boolean check_cc_tangent(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { - return isZero(sdistance(p1, p2) - sdistance(p3, p4)); - } - + /** + * Calculates the Euclidean distance between two points. + * + * @param p1 the first point + * @param p2 the second point + * @return the distance between p1 and p2 + */ static double sdistance(CPoint p1, CPoint p2) { return Math.sqrt(Math.pow(p1.getx() - p2.getx(), 2) + Math.pow(p1.gety() - p2.gety(), 2)); } - static boolean nearPt(double x, double y, CPoint pt) { - return Math.abs(x - pt.getx()) < CMisc.PIXEPS && Math.abs(y - pt.gety()) < CMisc.PIXEPS; - } - - + /** + * Computes an adjusted midpoint on the line defined by (x1, y1) and (x2, y2) based on the direction from the line's midpoint to (x, y). + * + * @param x1 the x-coordinate of the first point on the line + * @param y1 the y-coordinate of the first point on the line + * @param x2 the x-coordinate of the second point on the line + * @param y2 the y-coordinate of the second point on the line + * @param x the x-coordinate of the external reference point + * @param y the y-coordinate of the external reference point + * @return a two-element array containing the computed x and y coordinates + */ double[] get_pt_dmcr(double x1, double y1, double x2, double y2, double x, double y) { double dis = Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2)); @@ -1129,6 +1551,13 @@ static boolean nearPt(double x, double y, CPoint pt) { return r; } + /** + * Computes the intersection points between a line and a circle. + * + * @param ln the line + * @param cr the circle + * @return an array containing intersection coordinates; an empty array if there is no intersection + */ double[] intersect_lc(CLine ln, Circle cr) { double r2 = cr.getRadius(); r2 *= r2; @@ -1178,6 +1607,13 @@ static boolean nearPt(double x, double y, CPoint pt) { } } + /** + * Computes the intersection point of two lines. + * + * @param ln1 the first line + * @param ln2 the second line + * @return a two-element array with the x and y coordinates of the intersection, or null if undefined + */ public double[] intersect_ll(CLine ln1, CLine ln2) { CPoint p1 = ln1.getfirstPoint(); double k1 = ln1.getK(); @@ -1205,6 +1641,13 @@ public double[] intersect_ll(CLine ln1, CLine ln2) { return r; } + /** + * Computes the intersection points of two circles. + * + * @param c1 the first circle + * @param c2 the second circle + * @return an array containing the intersection coordinates; null if there is no intersection + */ public double[] intersect_cc(Circle c1, Circle c2) { double r1 = c1.getRadius(); CPoint o1 = c1.o; @@ -1249,7 +1692,13 @@ public double[] intersect_cc(Circle c1, Circle c2) { } - + /** + * Checks if two circles intersect based on their radii and center distance. + * + * @param c1 the first circle + * @param c2 the second circle + * @return true if the circles intersect within the defined tolerance + */ protected boolean check_cc_inter(Circle c1, Circle c2) { double r1 = c1.getRadius(); double r2 = c2.getRadius(); @@ -1263,24 +1712,48 @@ protected boolean check_cc_inter(Circle c1, Circle c2) { } + /** + * Checks if a line and a circle intersect. + * + * @param ln the line + * @param c2 the circle + * @return true if the line intersects the circle + */ protected boolean check_lc_inter(CLine ln, Circle c2) { double r1 = ln.distance(c2.getCenterOX(), c2.getCenterOY()); double r2 = c2.getRadius(); return (r2 - r1) > 0; } + /** + * Determines if a given value is effectively zero within a tolerance. + * + * @param r the value to check + * @return true if the value is considered zero + */ protected static boolean isZero(double r) { return Math.abs(r) < CMisc.ZERO; } + /** + * Checks whether two coordinates are nearly equal based on a tolerance. + * + * @param x the first x-coordinate + * @param y the first y-coordinate + * @param x1 the second x-coordinate + * @param y1 the second y-coordinate + * @return true if the points are near each other + */ protected static boolean near(double x, double y, double x1, double y1) { return Math.abs(Math.pow(x - x1, 2) + Math.pow(y - y1, 2)) < CMisc.PIXEPS * CMisc.PIXEPS; } - public static void set_eps(double r) { - } - - + /** + * Retrieves an array of points extracted from the given construct. + * + * @param c the construct containing point identifiers + * @return an array of points, or null if a point cannot be found + */ protected CPoint[] getPoints(Cons c) { CPoint[] pp = new CPoint[8]; @@ -1300,20 +1773,12 @@ protected CPoint[] getPoints(Cons c) { return pp; } -// public int dxindex(int n) -// { -// gt -// } -// -// public TMono getTMono(cndg d) -// { -// if(d == null) -// return null; -// -// - - // } - + /** + * Builds a TMono object that represents a geometric relation based on the construct. + * + * @param c the construct defining the relation + * @return the constructed TMono object, or null if it cannot be built + */ protected TMono getTMono(Cons c) { if (c == null) return null; @@ -1366,6 +1831,13 @@ protected TMono getTMono(Cons c) { return m; } + /** + * Determines whether two points are identical by comparing their Wu representations. + * + * @param p1 the first point + * @param p2 the second point + * @return true if both points are considered identical + */ public boolean decide_wu_identical(CPoint p1, CPoint p2) { TMono m1 = poly.ppdd(p1.x1.xindex, p2.x1.xindex); //poly.pdif(poly.pcopy(p1.x1.m), poly.pcopy(p2.x1.m)); @@ -1374,6 +1846,12 @@ public boolean decide_wu_identical(CPoint p1, CPoint p2) { } + /** + * Checks if the given TMono reduces to zero relative to the polynomial set. + * + * @param m1 the TMono expression to check + * @return true if the expression is effectively zero within the polynomial context + */ public boolean div_set(TMono m1) { if (m1 == null) return true; @@ -1413,6 +1891,11 @@ public boolean div_set(TMono m1) { return false; } + /** + * Prints the polynomial represented by the TPoly chain. + * + * @param p the TPoly instance containing the polynomial + */ public void printPoly(TPoly p) { while (p != null) { poly.printpoly(p.getPoly()); @@ -1420,18 +1903,15 @@ public void printPoly(TPoly p) { } } - - public boolean verify_ndg(TMono m) { - if (m == null) - return true; - TPoly p1 = polylist; - if (poly.pzerop(m)) - return false; - - - return true; - } - + /** + * Searches for a CTMark based on two pairs of points. + * + * @param p1 the first point of the first pair + * @param p2 the second point of the first pair + * @param p3 the first point of the second pair + * @param p4 the second point of the second pair + * @return the CTMark if found, otherwise null + */ public CTMark findCTMark(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { for (int i = 0; i < otherlist.size(); i++) { CClass c = (CClass) otherlist.get(i); @@ -1447,6 +1927,15 @@ public CTMark findCTMark(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { return null; } + /** + * Determines if a tmark exists that contains the specified four points. + * + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @param p4 the fourth point + * @return true if a matching tmark is found + */ public boolean find_tmark(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { for (int i = 0; i < flashlist.size(); i++) { JFlash f = (JFlash) flashlist.get(i); @@ -1459,6 +1948,11 @@ public boolean find_tmark(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { return false; } + /** + * Checks if there is at least one freezed point in the diagram. + * + * @return true if any point is freezed, otherwise false + */ public boolean containFreezedPoint() { for (int i = 0; i < pointlist.size(); i++) { CPoint p = (CPoint) pointlist.get(i); @@ -1469,6 +1963,9 @@ public boolean containFreezedPoint() { return false; } + /** + * Unfreezes all points in the diagram. + */ public void unfreezeAllPoints() { for (int i = 0; i < pointlist.size(); i++) { CPoint p = (CPoint) pointlist.get(i); @@ -1478,6 +1975,11 @@ public void unfreezeAllPoints() { } } + /** + * Determines if the diagram is in a frozen state. + * + * @return true if any point is freezed, indicating the diagram is frozen + */ public boolean isFrozen() { for (int i = 0; i < pointlist.size(); i++) { CPoint p = (CPoint) pointlist.get(i); @@ -1489,6 +1991,13 @@ public boolean isFrozen() { return false; } + /** + * Zooms out the diagram from a specified center by adjusting the points. + * + * @param x the x-coordinate of the zoom center + * @param y the y-coordinate of the zoom center + * @param zz the zoom factor denominator + */ public void zoom_out(double x, double y, int zz) { if (isFrozen()) @@ -1503,6 +2012,13 @@ public void zoom_out(double x, double y, int zz) { } } + /** + * Zooms in the diagram from a specified center by adjusting the points. + * + * @param x the x-coordinate of the zoom center + * @param y the y-coordinate of the zoom center + * @param zz the zoom factor denominator + */ public void zoom_in(double x, double y, int zz) { if (isFrozen()) return; @@ -1515,6 +2031,9 @@ public void zoom_in(double x, double y, int zz) { } } + /** + * Adjusts the catch point type by examining proximity to other points. + */ public void hvCatchPoint() { for (int i = 0; i < pointlist.size(); i++) { CPoint pt = (CPoint) pointlist.get(i); @@ -1536,6 +2055,12 @@ public void hvCatchPoint() { } } + /** + * Retrieves a horizontal or vertical catch point based on the catch type. + * + * @param CatchType the catch type indicator (2 for vertical, 3 for horizontal) + * @return the catch point if found, otherwise null + */ public CPoint getCatchHVPoint(int CatchType) { for (int i = 0; i < pointlist.size(); i++) { CPoint pt = (CPoint) pointlist.get(i); @@ -1550,6 +2075,11 @@ public CPoint getCatchHVPoint(int CatchType) { return null; } + /** + * Adjusts the provided point to align with a nearby point based on the catch type. + * + * @param pv the point to be adjusted + */ public void setCatchHVPoint(CPoint pv) { if (CatchType != 2 && CatchType != 3 && CatchType != 4) return; @@ -1568,6 +2098,4 @@ public void setCatchHVPoint(CPoint pv) { } } } - - } diff --git a/src/main/java/wprover/DrawData.java b/src/main/java/wprover/DrawData.java index 057571cc..16de568a 100644 --- a/src/main/java/wprover/DrawData.java +++ b/src/main/java/wprover/DrawData.java @@ -8,11 +8,8 @@ import java.io.FileOutputStream; /** - * Created by IntelliJ IDEA. - * User: Administrator - * Date: 2005-3-2 - * Time: 20:40:39 - * To change this template use File | Settings | File Templates. + * DrawData is a utility class that manages color, dash, and width configurations for drawing operations. + * It provides methods to add colors, retrieve color and dash values, and save/load configurations. */ public class DrawData { public static int RED = 3; @@ -20,6 +17,20 @@ public class DrawData { public static int WIDTH2 = 2; public static int LIGHTCOLOR = 18; + public static int cindex = 0; + public static int dindex = 0; + public static int windex = 2; + + final public static int pointcolor = 3; + final public static int pointcolor_half_decided = 5; + final public static int pointcolor_decided = 14; + + public static int polygoncolor = 17; + public static int anglecolor = 3; + public static int anglewidth = 2; + public static int angledash = 0; + public static int tractcolor = 3; + private static DrawData dd = new DrawData(); private static int cnum; @@ -29,7 +40,9 @@ public class DrawData { int default_color_num; - + /** + * Constructs a new DrawData instance and initializes default color, dash, and width lists. + */ private DrawData() { Color[] color = { Color.blue, @@ -85,14 +98,21 @@ private DrawData() { } } - public static int getDefaultColorCount() { - return dd.default_color_num; - } - + /** + * Returns the number of available widths. + * + * @return the total width count + */ public static int getWidthCounter() { return dd.widthlist.size(); } + /** + * Returns the width value at the specified index. + * + * @param index the index of the width value to retrieve + * @return the width value as a double + */ public static double getWidth(int index) { double d; try { @@ -103,10 +123,21 @@ public static double getWidth(int index) { return d; } + /** + * Returns the number of available dash configurations. + * + * @return the total dash count + */ public static int getDashCounter() { return dd.dashlist.size(); } + /** + * Returns the dash value at the specified index. + * + * @param index the index of the dash value to retrieve + * @return the dash value as a double + */ public static double getDash(int index) { double d; try { @@ -117,30 +148,43 @@ public static double getDash(int index) { return d; } - + /** + * Returns the number of available colors. + * + * @return the total color count + */ public static int getColorCounter() { return dd.colorlist.size(); } - public static int getNextColor(int n) { - return n % getColorCounter(); - } - + /** + * Returns a color offset from the default angle color. + * + * @param n the offset from the angle color index + * @return the calculated Color object + */ public static Color getColorSinceRed(int n) { return getColor(anglecolor + n); } + /** + * Returns the color corresponding to the given index. The index wraps around the color list. + * + * @param index the index of the color to retrieve + * @return the Color object, or null if index is negative + */ public static Color getColor(int index) { int n = dd.colorlist.size(); if (index < 0 ) return null; return (Color) (dd.colorlist.get(index % n)); } - public static Color getCtColor(int index) { - Color c = (Color) (dd.colorlist.get(index)); - return new Color(255 - c.getRed(), 255 - c.getGreen(), 255 - c.getBlue()); - } - + /** + * Adds a new color to the color list if it is not already present. + * + * @param co the Color to add + * @return the new total count of colors, or the existing index plus one if already present + */ public static int addColor(Color co) { for (int i = 0; i < dd.colorlist.size(); i++) { Color c = (Color) dd.colorlist.get(i); @@ -152,30 +196,18 @@ public static int addColor(Color co) { return dd.colorlist.size(); } - //////////////////////////////////////////////////////////////////////// - - - - public static int cindex = 0; - public static int dindex = 0; - public static int windex = 2; - - final public static int pointcolor = 3; - final public static int pointcolor_half_decided = 5; - final public static int pointcolor_decided = 14; - - public static int polygoncolor = 17; - public static int anglecolor = 3; - public static int anglewidth = 2; - public static int angledash = 0; - public static int tractcolor = 3; - + /** + * Resets the color, dash, and width indices to the default status. + */ public static void setDefaultStatus() { cindex = 0; dindex = 0; windex = 2; } + /** + * Sets the color, dash, and width indices to the prove status. + */ public static void setProveStatus() { cindex = 3; dindex = 9; @@ -183,17 +215,21 @@ public static void setProveStatus() { } + /** + * Sets the color, dash, and width indices to the auxiliary status. + */ public static void setAuxStatus() { cindex = RED; dindex = DASH8; windex = 2; } - public static void setDefaultColor(int id) { - if (id < 0) return; - cindex = id; - } - + /** + * Returns the index of the specified color in the color list. + * + * @param color the Color to search for + * @return the index of the color, or -1 if not found + */ public static int getColorIndex(Color color) { for (int i = 0; i < dd.colorlist.size(); i++) { Color c = (Color) dd.colorlist.get(i); @@ -203,23 +239,32 @@ public static int getColorIndex(Color color) { return -1; } + /** + * Returns the current color based on the current color index. + * + * @return the current Color object + */ public static Color getCurrentColor() { return getColor(cindex); } - public static void setDefaultPolygonColor(int index) { - polygoncolor = index; - } - + /** + * Resets the DrawData instance by reinitializing it to default values. + */ public static void reset() { dd = new DrawData(); } - - - ///////////////////////////////////////////////////////////////////// - - + /** + * Saves the color, dash, and width configuration to the specified PostScript file. + * + * @param vc the vector containing color indices + * @param vd the vector containing dash indices + * @param vw the vector containing width indices + * @param fp the file output stream to write to + * @param stype the style type (0 for color, 1 for gray, 2 for black & white) + * @throws IOException if an I/O error occurs while writing + */ public static void SavePS(Vector vc, Vector vd, Vector vw, FileOutputStream fp, int stype) throws IOException { fp.write("%-----define color, dash and width\n".getBytes()); @@ -277,7 +322,12 @@ public static void SavePS(Vector vc, Vector vd, Vector vw, FileOutputStream fp, } } - + /** + * Saves additional color configurations to the specified data output stream. + * + * @param out the data output stream to write to + * @throws IOException if an I/O error occurs while writing + */ public static void Save(DataOutputStream out) throws IOException { int size = dd.colorlist.size(); out.writeInt(size); @@ -290,6 +340,13 @@ public static void Save(DataOutputStream out) throws IOException { } } + /** + * Loads color configurations from the specified data input stream. + * + * @param in the data input stream to read from + * @param dp the DrawProcess instance used for object mapping + * @throws IOException if an I/O error occurs while reading + */ public static void Load(DataInputStream in, DrawProcess dp) throws IOException { if (CMisc.version_load_now < 0.01) { int size = in.readInt(); @@ -329,7 +386,6 @@ public static void Load(DataInputStream in, DrawProcess dp) throws IOException { } } } - } diff --git a/src/main/java/wprover/DrawProcess.java b/src/main/java/wprover/DrawProcess.java index 21e9c9eb..27d49b94 100644 --- a/src/main/java/wprover/DrawProcess.java +++ b/src/main/java/wprover/DrawProcess.java @@ -24,9 +24,11 @@ import maths.CharSet; import org.w3c.dom.*; - -public class -DrawProcess extends DrawBase implements Printable, ActionListener { +/** + * DrawProcess is a class that handles the drawing and processing of geometric objects. + * It extends the DrawBase class and implements the Printable and ActionListener interfaces. + */ +public class DrawProcess extends DrawBase implements Printable, ActionListener { final public static int SELECT = 0; @@ -109,62 +111,99 @@ private int save_id = CMisc.id_count; private int CAL_MODE = 0; // 0: MOVEMODE. 1. CAL - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - protected GTerm gt; protected int nd = 1; - //////////////// protected UndoStruct U_Obj = null; protected boolean status = true; - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - + /** + * Toggles the status state. + */ public void stateChange() { status = !status; } + /** + * Sets the calculation mode to 1. + */ public void setCalMode1() { CAL_MODE = 1; } + /** + * Sets the calculation mode to 0. + */ public void setCalMode0() { CAL_MODE = 0; } + /** + * Retrieves the GTerm object. + * + * @return the GTerm object + */ public GTerm gterm() { if (gt == null) gt = gxInstance.getpprove().getConstructionTerm(); return gt; } + /** + * Clears the construction and resets the nd value. + */ public void clearConstruction() { gt = null; nd = 1; } + /** + * Resets the current undo structure's ID to the current ID count. + */ public void resetUndo() { this.currentUndo.id = CMisc.id_count; } + /** + * Retrieves the name of the current object. + * + * @return the name of the current object + */ public String getName() { return this.name; } + /** + * Sets the recalculation flag. + * + * @param r the recalculation flag to set + */ public void setRecal(boolean r) { isRecal = r; } + /** + * Sets the name of the current object. + * + * @param s the name to set + */ public void setName(String s) { this.name = s; } + /** + * Stops tracking the current point. + */ public void stopTrack() { CTrackPt = null; } + /** + * Starts tracking a given point. + * + * @param pt the point to start tracking + */ public void startTrackPt(CPoint pt) { - CTrackPt = pt; boolean r = false; @@ -173,7 +212,6 @@ public void startTrackPt(CPoint pt) { if (tr.isTracePt(CTrackPt)) { r = true; break; - } } if (!r) { @@ -181,10 +219,15 @@ public void startTrackPt(CPoint pt) { this.addObjectToList(t, tracelist); this.UndoAdded(t.toString()); } - } + /** + * Retrieves a parameter by its index. + * + * @param index the index of the parameter to retrieve + * @return the parameter with the specified index, or null if not found + */ public Param getParameterByindex(int index) { for (int i = 0; i < paraCounter - 1; i++) { if (parameter[i].xindex == index) { @@ -194,21 +237,42 @@ public Param getParameterByindex(int index) { return null; } + /** + * Retrieves the last constructed point. + * + * @return the last constructed point, or null if no points exist + */ public CPoint getLastConstructedPoint() { if (pointlist.size() <= 0) return null; return (CPoint) pointlist.get(pointlist.size() - 1); } + /** + * Retrieves a point by its ID. + * + * @param id the ID of the point to retrieve + * @return the point with the specified ID, or null if not found + */ public CPoint getPointById(int id) { return (CPoint) this.getObjectInListById(id, pointlist); } - + /** + * Retrieves all constraints. + * + * @return a vector containing all constraints + */ public Vector getAllConstraint() { return constraintlist; } + /** + * Retrieves a constraint by its ID. + * + * @param id the ID of the constraint to retrieve + * @return the constraint with the specified ID, or null if not found + */ public Constraint getConstraintByid(int id) { for (int i = 0; i < constraintlist.size(); i++) { Constraint cs = (Constraint) constraintlist.get(i); @@ -219,24 +283,51 @@ public Constraint getConstraintByid(int id) { return null; } + /** + * Retrieves a line by its ID. + * + * @param id the ID of the line to retrieve + * @return the line with the specified ID, or null if not found + */ public CLine getLineByid(int id) { return (CLine) this.getObjectInListById(id, linelist); } + /** + * Retrieves a circle by its ID. + * + * @param id the ID of the circle to retrieve + * @return the circle with the specified ID, or null if not found + */ public Circle getCircleByid(int id) { return (Circle) this.getObjectInListById(id, circlelist); } - + /** + * Retrieves a trace by its ID. + * + * @param id the ID of the trace to retrieve + * @return the trace with the specified ID, or null if not found + */ public CTrace getTraceById(int id) { return (CTrace) this.getObjectInListById(id, tracelist); } - + /** + * Retrieves an angle by its ID. + * + * @param id the ID of the angle to retrieve + * @return the angle with the specified ID, or null if not found + */ public CAngle getAngleByid(int id) { return (CAngle) this.getObjectInListById(id, anglelist); } + /** + * Retrieves all solid objects. + * + * @return a vector containing all solid objects + */ public Vector getAllSolidObj() { Vector v = new Vector(); int n = CMisc.id_count + 1; @@ -253,6 +344,12 @@ public Vector getAllSolidObj() { return v; } + /** + * Retrieves an object by its ID. + * + * @param id the ID of the object to retrieve + * @return the object with the specified ID, or null if not found + */ public CClass getOjbectById(int id) { CClass cc = this.getObjectInListById(id, pointlist); if (cc != null) { @@ -290,6 +387,13 @@ public CClass getOjbectById(int id) { return cc; } + /** + * Retrieves an object from a list by its ID. + * + * @param id the ID of the object to retrieve + * @param v the list to search + * @return the object with the specified ID, or null if not found + */ public CClass getObjectInListById(int id, Vector v) { for (int i = 0; i < v.size(); i++) { CClass cc = (CClass) v.get(i); @@ -298,9 +402,14 @@ public CClass getObjectInListById(int id, Vector v) { } } return null; - } + /** + * Retrieves an UndoStruct object by its ID. + * + * @param id the ID of the UndoStruct to retrieve + * @return the UndoStruct object with the specified ID, or null if not found + */ public UndoStruct getUndoById(int id) { for (int i = 0; i < undolist.size(); i++) { UndoStruct cc = (UndoStruct) undolist.get(i); @@ -314,27 +423,28 @@ public UndoStruct getUndoById(int id) { return null; } - public void SetProportionLineAction(int prop) { - - this.SetCurrentAction(DrawProcess.LRATIO); - this.proportion = prop; - - } - + /** + * Adds a DiagramUpdater listener to the list of updater listeners. + * + * @param d the DiagramUpdater listener to add + */ public void addDiagramUpdaterListener(DiagramUpdater d) { if (!updaterListeners.contains(d)) updaterListeners.add(d); } + /** + * Removes a DiagramUpdater listener from the list of updater listeners. + * + * @param d the DiagramUpdater listener to remove + */ public void RemoveDiagramUpdaterListener(DiagramUpdater d) { updaterListeners.remove(d); } - public void SetActionWithPropotion(int action, int prop) { - this.SetCurrentAction(action); - this.proportion = prop; - } - + /** + * Clears all geometric objects and resets the drawing state. + */ public void clearAll() { CurrentAction = SELECT; SelectList.clear(); @@ -362,7 +472,6 @@ public void clearAll() { pSolution = null; solutionlist.clear(); -// trackPoint = null; undolist.clear(); redolist.clear(); CMisc.id_count = 1; @@ -400,66 +509,120 @@ public void clearAll() { name = ""; CAL_MODE = 0; status = true; - } + /** + * Sets the saved tag to indicate that the current state is saved. + */ public void setSavedTag() { needSave = false; save_id = CMisc.id_count; } + /** + * Checks if the current state is saved. + * + * @return true if the current state is saved, false otherwise + */ public boolean isitSaved() { return needSave || save_id >= CMisc.id_count; } + /** + * Retrieves the AnimateC object. + * + * @return the AnimateC object + */ public AnimateC getAnimateC() { return animate; } + /** + * Retrieves the current file. + * + * @return the current file + */ public File getFile() { return file; } + /** + * Sets the current file. + * + * @param f the file to set + */ public void setFile(File f) { file = f; } - + /** + * Retrieves the list of selected objects. + * + * @return the list of selected objects + */ public Vector getSelectList() { return SelectList; } + /** + * Sets the snap mode. + * + * @param snap true to enable snap mode, false to disable + */ public void SetSnap(boolean snap) { this.SNAP = snap; - } + /** + * Retrieves the current status. + * + * @return the current status + */ public int getStatus() { return STATUS; } + /** + * Sets the current status. + * + * @param t the status to set + */ public void setStatus(int t) { STATUS = t; } + /** + * Checks if snap mode is enabled. + * + * @return true if snap mode is enabled, false otherwise + */ public boolean isSnap() { return this.SNAP; } + /** + * Sets the grid mode. + * + * @param grid true to enable grid mode, false to disable + */ public void SetGrid(boolean grid) { this.DRAWGRID = grid; - } + /** + * Checks if grid mode is enabled. + * + * @return true if grid mode is enabled, false otherwise + */ public boolean isDrawGrid() { return this.DRAWGRID; } - public void setGridXY(int n) { - if (n > 0) - GridX = GridY = n; - } - + /** + * Adjusts the mesh step size. + * + * @param add true to increase the mesh step size, false to decrease + */ public void setMeshStep(boolean add) { if (add) { this.GridX += 10; @@ -470,60 +633,32 @@ public void setMeshStep(boolean add) { } this.GridX -= 10; this.GridY -= 10; - - } - - } - - public TPoly getCopyPolylist() { - TPoly pl = polylist; - TPoly plist = null; - - while (pl != null) { - TPoly p = new TPoly(); - p.setPoly(poly.pcopy(pl.getPoly())); - p.setNext(plist); - plist = p; - - pl = pl.getNext(); - } - return plist; - } - - public TPoly getCopyPolyBacklist() { - TPoly pl = pblist; - TPoly plist = null; - - while (pl != null) { - TPoly p = new TPoly(); - p.setPoly(poly.pcopy(pl.getPoly())); - p.setNext(plist); - plist = p; - - pl = pl.getNext(); } - return plist; } + /** + * Retrieves the polynomial list. + * + * @return the polynomial list + */ public TPoly getPolyList() { return polylist; } - public Vector getPolyVector() { - Vector v = new Vector(); - TPoly p = polylist; - while (p != null) { - v.add(p.getPoly()); - p = p.next; - } - - return v; - } - + /** + * Retrieves the PB list. + * + * @return the PB list + */ public TPoly getPBList() { return pblist; } + /** + * Returns a vector containing copies of the TMono objects from the pblist. + * + * @return a vector of TMono objects. + */ public Vector getPBMono() { TPoly poly = pblist; GeoPoly basic = GeoPoly.getPoly(); //.getInstance(); @@ -548,6 +683,11 @@ public Vector getPBMono() { // Get the nondegenerate conditions from the polynomials. // This is the simplest nondegenerate conditions. + + /** + * Prints the nondegenerate conditions derived from the TPoly list. + * Simplifies each TMono condition, prints each condition and the final combined condition. + */ public void printNDGS() { GeoPoly basic = GeoPoly.getPoly(); CharSet set = CharSet.getinstance(); @@ -589,6 +729,13 @@ public void printNDGS() { } + /** + * Computes and returns the nondegenerate conditions for the current TPoly. + * Extracts TMono elements from the pblist, pairs them based on degree, + * computes and reduces the differences, and collects the resulting conditions. + * + * @return a vector of computed nondegenerate conditions. + */ public Vector getNDGS() { TPoly poly = pblist; GeoPoly basic = GeoPoly.getPoly(); //.getInstance(); @@ -636,39 +783,12 @@ public Vector getNDGS() { return vx; } - public String getPolyString(int id) { - int index = 0; - String s = new String(); - TPoly pl = null; - - if (id == 1) { - pl = polylist; - } else if (id == 0) { - pl = pblist; - } - - while (pl != null) { - TMono m = pl.getPoly(); - String s1 = poly.printSPoly(m); - if (id == 1) { - s += "f_" + index + ": "; - } else if (id == 0) { - s += "h_" + index + ": "; - } - - if (s1.length() > 70) { - s += (s1.substring(0, 60) + " + ......\n"); - } else { - s += s1 + "\n"; - } - pl = pl.getNext(); - index++; - } - - return s; - } - - + /** + * Recalculates the diagram by transforming all points and updating parameters. + * Restores previous values if the recalculation fails, triggers diagram updates, and recalculates traces and texts. + * + * @return true if recalculation is successful, false otherwise. + */ public boolean reCalculate() { boolean success = true; @@ -760,6 +880,10 @@ public boolean reCalculate() { return success; } + /** + * Calculates the text values for all CText objects in the text list. + * If the text type is VALUE_TEXT, it calculates the value and updates the text value. + */ public void calculate_text() { for (int i = 0; i < textlist.size(); i++) { CText t = (CText) textlist.get(i); @@ -778,29 +902,14 @@ public void calculate_text() { } } - public void backup_parameter(boolean success, double x, double y, double sin, double cos) { - if (success == false) { - for (int i = 0; i < paraCounter; i++) { - if (parameter[i] != null) - parameter[i].value = paraBackup[i]; - } - x = pptrans[0]; - y = pptrans[1]; - sin = pptrans[2]; - cos = pptrans[3]; - } else { - for (int i = 0; i < paraCounter; i++) { - if (parameter[i] != null) - paraBackup[i] = parameter[i].value; - } - pptrans[0] = x; - pptrans[1] = y; - pptrans[2] = sin; - pptrans[3] = cos; - } - - } - + /** + * Translates all points back to their original positions after transformation. + * + * @param x1 the x-coordinate translation + * @param y1 the y-coordinate translation + * @param sin the sine of the rotation angle + * @param cos the cosine of the rotation angle + */ public void translate_back(double x1, double y1, double sin, double cos) { if (CMisc.POINT_TRANS) { double t1, t2; @@ -818,9 +927,11 @@ public void translate_back(double x1, double y1, double sin, double cos) { p.y1.value += y1; } } - } + /** + * Recalculates all flash animations in the flash list. + */ public void recal_allFlash() { for (int i = 0; i < flashlist.size(); i++) { JFlash f = (JFlash) flashlist.get(i); @@ -828,15 +939,16 @@ public void recal_allFlash() { } } + /** + * Calculates the trace points for all CTrace objects in the trace list. + */ public void calculate_trace() { - int nt = tracelist.size(); if (nt == 0) return; CAL_MODE = 1; - for (int i = 0; i < nt; i++) { CTrace t = (CTrace) tracelist.get(i); CPoint p = t.getPoint(); @@ -851,15 +963,11 @@ public void calculate_trace() { if (c instanceof CLine) { CLine ln = (CLine) c; -// double w = this.Width; -// double h = this.Height; -// double k = ln.getK(); CPoint[] lpt = ln.getMaxMinPoint(false); double x0 = lpt[0].getx(); double y0 = lpt[0].gety(); double x, y, dx, dy; -// double k1 = Math.abs(w / h); x = x0; y = y0; dx = (lpt[1].getx() - lpt[0].getx()) / n; @@ -896,7 +1004,11 @@ public void calculate_trace() { CAL_MODE = 0; } - + /** + * Retrieves the current parameter values. + * + * @return an array of parameter values + */ public double[] getParameter() { double[] r = new double[parameter.length]; for (int i = 0; i < paraCounter; i++) { @@ -906,6 +1018,11 @@ public double[] getParameter() { return r; } + /** + * Sets the parameter values. + * + * @param r an array of parameter values to set + */ public void setParameter(double[] r) { for (int i = 0; i < paraCounter; i++) { if (parameter[i] != null) @@ -913,6 +1030,12 @@ public void setParameter(double[] r) { } } + /** + * Backs up or restores the parameter values. + * + * @param rr an array to store or restore parameter values + * @param b a boolean indicating whether to back up (true) or restore (false) the values + */ public void BackupParameter(double[] rr, boolean b) { if (b) for (int i = 0; i < paraCounter; i++) { @@ -924,10 +1047,13 @@ public void BackupParameter(double[] rr, boolean b) { if (parameter[i] != null) parameter[i].value = rr[i]; } - } - + /** + * Sets the parameter values and translates points back if necessary. + * + * @param dd an array of parameter values to set + */ public void setParameterValue(double[] dd) { for (int i = 0; i < dd.length; i++) { if (parameter[i] != null) @@ -943,7 +1069,11 @@ public void setParameterValue(double[] dd) { } } - + /** + * Calculates all results from the polygons. + * + * @return a Vector containing result arrays for each parameter configuration. + */ public Vector calculate_allResults() { // calculate all results from the polygons. double x1, y1, sin, cos; x1 = y1 = 0; @@ -1061,6 +1191,12 @@ public Vector calculate_allResults() { // calculate all results from the pol return vlist; } + /** + * Calculates all points based on current parameter values. + * + * @param d a flag indicating whether to perform dynamic recalculations + * @return true if all points are calculated successfully; false otherwise. + */ public boolean calculate_allpt(boolean d) { double x1, y1, sin, cos; x1 = y1 = 0; @@ -1105,12 +1241,18 @@ public boolean calculate_allpt(boolean d) { return s; } + /** + * Opens the dialog for selecting the leading variable. + */ public void popLeadingVariableDialog() { LeadVariableDialog dlg = new LeadVariableDialog(gxInstance); dlg.loadVariable(this.getPointList(), false); dlg.setVisible(true); } + /** + * Calculates and updates parameter values based on specific angle constraints. + */ public void calv_parameter() { int n = 0; for (int i = 0; i < constraintlist.size(); i++) { @@ -1136,6 +1278,12 @@ public void calv_parameter() { } + /** + * Finds and returns the circle on which the specified point lies. + * + * @param pt the point to check + * @return the Circle if the point is on a circle; null otherwise. + */ public Circle fd_pt_on_which_circle(CPoint pt) { for (int i = 0; i < circlelist.size(); i++) { Circle cr = (Circle) circlelist.get(i); @@ -1150,7 +1298,12 @@ public Circle fd_pt_on_which_circle(CPoint pt) { return null; } - + /** + * Finds and returns the line on which the specified point lies. + * + * @param pt the point to check + * @return the CLine if the point is on a line; null otherwise. + */ public CLine fd_pt_on_which_line(CPoint pt) { for (int i = 0; i < linelist.size(); i++) { CLine ln = (CLine) linelist.get(i); @@ -1165,18 +1318,12 @@ public CLine fd_pt_on_which_line(CPoint pt) { return null; } - public void setOnLine(CPoint pt, double[] r) { - CLine ln = this.fd_pt_on_which_line(pt); - if (ln != null) { - CPoint p1 = ln.getfirstPoint(); - CPoint p2 = ln.getSecondPoint(p1); - double x1 = paraBackup[pt.x1.xindex - 1]; - double y1 = paraBackup[pt.y1.xindex - 1]; - if (ln.pointOnLineN(pt)) { - } - } - } - + /** + * Calculates the corresponding point on a circle. + * + * @param pt the point used for the calculation + * @return an array containing x and y coordinates of the calculated point, or null if not applicable. + */ public double[] calculate_ocir(CPoint pt) { if (this.CurrentAction == MOVE && this.SelectList.contains(pt) || CAL_MODE == 1) return null; @@ -1211,7 +1358,12 @@ public double[] calculate_ocir(CPoint pt) { return null; } - + /** + * Calculates the intersection point on a line based on the given point. + * + * @param pt the point used for the calculation + * @return an array containing x and y coordinates of the calculated intersection point, or null if not applicable. + */ public double[] calculate_oline(CPoint pt) { if (this.CurrentAction == MOVE && this.SelectList.contains(pt) || CAL_MODE == 1) return null; @@ -1247,6 +1399,13 @@ public double[] calculate_oline(CPoint pt) { return null; } + /** + * Calculates and adjusts the given point based on a line-circle or circle-circle constraint. + * + * @param cp the point to adjust + * @param r an array containing candidate coordinates + * @return true if the point is set successfully according to constraints; false otherwise. + */ public boolean calculate_lccc(CPoint cp, double[] r) { Param pm1 = cp.x1; Param pm2 = cp.y1; @@ -1383,7 +1542,13 @@ else if (area < 0) return false; } - + /** + * Calculates the coordinates for a given point using its defining parameters and constraints. + * + * @param p the point to calculate + * @param d a flag that, if true, forces dynamic recalculation using constraint equations + * @return true if the point is calculated successfully; false otherwise. + */ public boolean calculate_a_point(CPoint p, boolean d) { if (p == null || p.isAFreePoint()) return true; @@ -1569,6 +1734,15 @@ public boolean calculate_a_point(CPoint p, boolean d) { return success; } + /** + * Calculates the values of a polynomial. + *

+ * This method calculates the values of a given polynomial using the provided parameters. + * If the result is null, it attempts to find the polynomial in the polynomial list and calculate its values. + * + * @param m the polynomial to calculate + * @return an array of calculated values, or null if the calculation fails + */ public double[] calcu_m1(TMono m) { double[] result = poly.calculv(m, parameter); @@ -1590,7 +1764,6 @@ public double[] calcu_m1(TMono m) { TMono m2 = null; int d = poly.deg(m, lva); - while (plist != null) { if (poly.lv(plist.getPoly()) == lva) { if (m1 == null) { @@ -1603,7 +1776,7 @@ public double[] calcu_m1(TMono m) { } if (m1 == null && m2 == null) { - + return null; } if (m1 != null && m2 != null) { result = poly.calculv2poly(m1, m2, parameter); @@ -1622,6 +1795,11 @@ public double[] calcu_m1(TMono m) { return result; } + /** + * Backs up the current parameter values. + *

+ * This method saves the current values of the parameters into the backup array. + */ public void pushbackup() { for (int i = 0; i < paraCounter; i++) { if (parameter[i] != null) { @@ -1630,6 +1808,15 @@ public void pushbackup() { } } + /** + * Calculates the values of two polynomials. + *

+ * This method calculates the values of two polynomials with the same leading variable. + * + * @param lv the leading variable + * @param p the array of parameters + * @return an array of calculated values, or null if the calculation fails + */ public double[] calform(int lv, Param p[]) { TPoly plist = pblist; TMono m1, m2; @@ -1646,17 +1833,23 @@ public double[] calform(int lv, Param p[]) { n++; } plist = plist.getNext(); - } if (m1 == null || m2 == null) { return null; } - double[] result; //= new double[1]; + double[] result; result = poly.calculv2poly(m1, m2, p); return result; } + /** + * Adds polynomials to the list and optimizes them. + *

+ * This method adds polynomials to the list, optimizes them, and recalculates the values if necessary. + * + * @param calcu a boolean indicating whether to recalculate the values + */ public void charsetAndAddPoly(boolean calcu) { TPoly plist = Constraint.getPolyListAndSetNull(); TPoly plist2 = plist; @@ -1701,12 +1894,7 @@ public void charsetAndAddPoly(boolean calcu) { } try { -// CMisc.print("----------------------"); -// this.printPoly(polylist); -// polylist = optmizePolygonOnLine(polylist); polylist = charset.charset(polylist); -// CMisc.print("======================"); -// this.printPoly(polylist); } catch (OutOfMemoryError ee) { JOptionPane.showMessageDialog(gxInstance, ee.getMessage(), ee.toString(), JOptionPane.ERROR_MESSAGE); } @@ -1720,6 +1908,11 @@ public void charsetAndAddPoly(boolean calcu) { } } + /** + * Optimizes the polynomial list. + *

+ * This method optimizes the polynomial list by adding zero constraints for certain points. + */ public void optmizePolynomial() { if (!CMisc.POINT_TRANS) return; @@ -1756,6 +1949,14 @@ public void optmizePolynomial() { } } + /** + * Adds a zero constraint for a given variable. + *

+ * This method adds a zero constraint for a given variable to the zero constraints array. + * + * @param x the variable index + * @param zeron the array of zero constraints + */ public void addZeron(int x, int[] zeron) { for (int i = 0; true; i++) { if (zeron[i] == x) @@ -1767,6 +1968,15 @@ public void addZeron(int x, int[] zeron) { } } + /** + * Selects multiple solutions for a given point. + *

+ * This method selects multiple solutions for a given point by calculating the possible values + * and adding them to the solution list. + * + * @param p the point for which to select multiple solutions + * @return true if the selection is successful, false otherwise + */ public boolean mulSolutionSelect(CPoint p) { pSolution = p; TMono m1 = p.x1.m; @@ -1777,7 +1987,6 @@ public boolean mulSolutionSelect(CPoint p) { if (m1.deg == 1 && m2.deg == 1) return true; - double x1, y1, sin, cos; x1 = y1 = 0; sin = 0; @@ -1827,7 +2036,6 @@ public boolean mulSolutionSelect(CPoint p) { if (r == null) r = this.calform(lva, parameter); - for (int j = 0; j < r.length; j++) { CPoint pt = this.CreateATempPoint(result[i], r[j]); solutionlist.add(pt); @@ -1872,6 +2080,14 @@ public boolean mulSolutionSelect(CPoint p) { return true; } + /** + * Erases a decided point from the polynomial list. + *

+ * This method removes a point from the polynomial list and adjusts the list accordingly. + * It also updates the parameter counter. + * + * @param p the point to be erased + */ public void ErasedADecidedPoint(CPoint p) { //there are some problems in this function. int x1 = p.x1.xindex; int y1 = p.y1.xindex; @@ -1918,25 +2134,42 @@ public void ErasedADecidedPoint(CPoint p) { //there are some problems in this fu return; } - + /** + * Sets the dimensions of the drawing area. + * + * @param x the width of the drawing area + * @param y the height of the drawing area + */ public void SetDimension(double x, double y) { this.Width = x; this.Height = y; } + /** + * Retrieves the current action type. + * + * @return the current action type + */ public int GetCurrentAction() { return this.CurrentAction; } + /** + * Sets the parameters for the drawing process. + * + * @param v1 the first parameter + * @param v2 the second parameter + */ public void setParameter(int v1, int v2) { this.v1 = v1; this.v2 = v2; } - public void setCurrentDrawStartOver() { - SetCurrentAction(CurrentAction); - } - + /** + * Sets the current action type and updates the UI accordingly. + * + * @param type the action type to set + */ public void SetCurrentAction(int type) { if (type != MOVE && CurrentAction == CONSTRUCT_FROM_TEXT) { this.clearFlash(); @@ -1965,9 +2198,15 @@ else if (gxInstance != null) if (dlg != null && dlg.isVisible()) dlg.setAction(this.getActionType(type)); } - } + /** + * Finds an edmark object between two points. + * + * @param p1 the first point + * @param p2 the second point + * @return the found edmark object, or null if not found + */ public Cedmark fd_edmark(CPoint p1, CPoint p2) { for (int i = 0; i < otherlist.size(); i++) { Object obj = otherlist.get(i); @@ -1981,90 +2220,40 @@ public Cedmark fd_edmark(CPoint p1, CPoint p2) { return null; } - + /** + * Sets the current status. + * + * @param status the status to set + */ public void setcurrentStatus(int status) { STATUS = status; } - - public boolean saveProveText(String path) throws IOException { - if (cpfield == null) { - return false; - } - - FileOutputStream fp; - File f = new File(path); - - if (f.exists()) { - f.delete(); - fp = new FileOutputStream(f, true); - - } else { - f.createNewFile(); - fp = new FileOutputStream(f, false); - } - if (fp == null) { - return false; - } - DataOutputStream out = new DataOutputStream(fp); - return cpfield.saveText(out, 0); - - } - - public void createProveHead() { - } - - public boolean undoProveToHead() { - if (cpfield == null) { - return false; - } - return cpfield.undo_to_head(this); - } - - public boolean prove_run_to_prove() { - if (cpfield != null) { - cpfield.run_to_end(this); - return cpfield.undo_default(this); - } else { - gxInstance.getpprove().m_runtobegin(); - } - return true; - } - - public boolean nextProveStep() { - if (cpfield != null) { - clearSelection(); - UndoStruct u = this.redo_step(); + /** + * Proceeds to the next step in the proof process. + * + * @return true if the next step is successfully executed, false otherwise + */ + public boolean nextProveStep() { + if (cpfield != null) { + clearSelection(); + UndoStruct u = this.redo_step(); if (u == null) this.Undo(); else cpfield.setSelectedUndo(u, this); return true; - -// boolean r = cpfield.next_prove_step(this); - -// if (!) { -// cpfield.undo_to_head(this); //.undo_default(this); -// } } else { -// if (gxInstance != null && gxInstance.getpprove() != null) -// gxInstance.getpprove().mstep(); - } - return false; - } - - - public CLine fd_line(Vector v) { - for (int i = 0; i < linelist.size(); i++) { - CLine ln = (CLine) linelist.get(i); - if (ln.points.containsAll(v)) { - return ln; - } + return false; } - return null; } + /** + * Starts the proof play with a specified timer interval. + * + * @param num the timer interval in milliseconds + */ public void provePlay(int num) { if (timer_type == 0) { timer = new Timer(num, this); @@ -2077,6 +2266,9 @@ public void provePlay(int num) { } } + /** + * Stops the proof play. + */ public void proveStop() { if (timer_type != 2) { return; @@ -2086,6 +2278,13 @@ public void proveStop() { cpfield.run_to_end(this); } + /** + * Runs the proof process to a specific step. + * + * @param u the current undo structure + * @param u1 the target undo structure + * @return true if the process is successfully executed, false otherwise + */ public boolean run_to_prove(UndoStruct u, UndoStruct u1) { this.doFlash(); @@ -2105,6 +2304,9 @@ public boolean run_to_prove(UndoStruct u, UndoStruct u1) { return true; } + /** + * Runs the proof process to the current undo structure. + */ public void runto() { UndoStruct u = U_Obj; if (u == null) return; @@ -2121,6 +2323,11 @@ public void runto() { U_Obj = null; } + /** + * Runs the proof process to a specific undo structure. + * + * @param u the target undo structure + */ public void runto1(UndoStruct u) { if (u == null) return; UndoStruct ux; @@ -2139,6 +2346,11 @@ public void runto1(UndoStruct u) { } } + /** + * Checks if all flash animations are finished. + * + * @return true if all flash animations are finished, false otherwise + */ public boolean all_flash_finished() { for (int i = 0; i < flashlist.size(); i++) { JFlash f = (JFlash) flashlist.get(i); @@ -2148,10 +2360,18 @@ public boolean all_flash_finished() { return true; } + /** + * Checks if the construction proof field exists. + * + * @return true if the construction proof field exists, false otherwise + */ public boolean checkCPfieldExists() { return cpfield != null; } + /** + * Runs the proof process to the end. + */ public void prove_run_to_end() { if (cpfield != null) { cpfield.run_to_end(this); @@ -2159,37 +2379,15 @@ public void prove_run_to_end() { if (gxInstance != null && gxInstance.getpprove() != null) gxInstance.getpprove().m_runtoend(); } - - } - - public void prove_run_to_begin() { - if (cpfield != null) { - cpfield.run_to_end(this); - cpfield.run_to_begin(this); - } else { - gxInstance.getpprove().m_runtobegin(); - } - } - - public void Regenerate_Prove_Text() { - if (cpfield != null) { - cpfield.reGenerateAll(); - } - } - - public boolean removeLastProveNode() { - if (cpfield != null) { - boolean r = cpfield.removeLast(); - if (r == false) { - cpfield = null; - } - return r; - - } else { - return false; - } } + /** + * Retrieves the snap coordinates based on the grid settings. + * + * @param x the x-coordinate + * @param y the y-coordinate + * @return an array containing the snapped x and y coordinates + */ public double[] getSnap(double x, double y) { double[] r = new double[2]; if (!this.SNAP) { @@ -2204,6 +2402,14 @@ public double[] getSnap(double x, double y) { return r; } + /** + * Handles the mouse wheel event for zooming in and out. + * + * @param x the x-coordinate + * @param y the y-coordinate + * @param n the number of notches the mouse wheel was rotated + * @param rt the rotation direction (positive for zoom in, negative for zoom out) + */ public void DWMouseWheel(double x, double y, int n, int rt) { switch (this.CurrentAction) { case MOVE: @@ -2218,15 +2424,19 @@ public void DWMouseWheel(double x, double y, int n, int rt) { if (k > 0) this.reCalculate(); break; - } } + /** + * Handles the double-click event on the drawing window. + * + * @param x the x-coordinate + * @param y the y-coordinate + */ public void DWMouseDbClick(double x, double y) { CatchPoint.setXY(x, y); switch (this.CurrentAction) { - // case SELECT: case MOVE: { if (!viewElementFromXY(x, y)) { } @@ -2234,6 +2444,9 @@ public void DWMouseDbClick(double x, double y) { } } + /** + * Defines a specific angle constraint. + */ public void defineSpecificAngle() { if (paraCounter != 1) { Vector v = this.getSpecificAngleList(); @@ -2266,9 +2479,6 @@ public void defineSpecificAngle() { this.charsetAndAddPoly(false); } if (paraCounter % 2 != 0) { -// paraCounter += 2; -// parameter[paraCounter-1] = new param(0,0); -// parameter[paraCounter-2] = new param(0,0); parameter[paraCounter - 1] = new Param(0, 0); paraCounter += 1; parameter[paraCounter - 1] = new Param(0, 0); @@ -2277,9 +2487,14 @@ public void defineSpecificAngle() { parameter[paraCounter - 1] = new Param(0, 0); paraCounter += 1; } - } + /** + * Retrieves the parameter associated with a specific angle constraint. + * + * @param ang the specific angle value + * @return the parameter associated with the specific angle constraint, or null if not found + */ public Param getParaForSpecificAngle(int ang) { for (int i = 0; i < constraintlist.size(); i++) { Constraint cs = (Constraint) constraintlist.get(i); @@ -2293,6 +2508,11 @@ public Param getParaForSpecificAngle(int ang) { return null; } + /** + * Retrieves a list of specific angle constraints. + * + * @return a vector containing the specific angle constraints + */ public Vector getSpecificAngleList() { Vector v = new Vector(); @@ -2303,9 +2523,15 @@ public Vector getSpecificAngleList() { } } return v; - } + /** + * Views an element from the specified coordinates. + * + * @param x the x-coordinate + * @param y the y-coordinate + * @return true if an element is viewed, false otherwise + */ public boolean viewElementFromXY(double x, double y) { Vector v = new Vector(); this.SelectAllFromXY(v, x, y, 0); @@ -2327,10 +2553,17 @@ public boolean viewElementFromXY(double x, double y) { v.add(c); this.setObjectListForFlash(v); this.onDBClick(c); -// this.viewElement(c); return true; } + /** + * Displays a selection dialog if multiple objects are selected. + * + * @param v the vector of selected objects + * @param x the x-coordinate + * @param y the y-coordinate + * @return the selected object, or null if no object is selected + */ public Object popSelect(Vector v, int x, int y) { if (v.size() == 1) { this.viewElement((CClass) v.get(0)); @@ -2350,21 +2583,31 @@ public Object popSelect(Vector v, int x, int y) { return null; } + /** + * Handles the right mouse button down event. + * + * @param x the x-coordinate + * @param y the y-coordinate + */ public void DWMouseRightDown(double x, double y) { if (CurrentAction != DEFINEPOLY && CurrentAction != TRANSFORM && CurrentAction != FREE_TRANSFORM) { CatchPoint.setXY(x, y); clearSelection(); STATUS = 0; this.RightMenuPopup(x, y); - } } + /** + * Handles the right mouse button click event. + * + * @param x the x-coordinate + * @param y the y-coordinate + */ public void DWMouseRightClick(double x, double y) { CatchPoint.setXY(x, y); switch (CurrentAction) { case DEFINEPOLY: { - if (SelectList.size() == 1 && STATUS != 0) { CPolygon cp = (CPolygon) SelectList.get(0); if (cp.pointlist.size() >= 3) { @@ -2381,7 +2624,6 @@ public void DWMouseRightClick(double x, double y) { STATUS = 0; this.RightMenuPopup(x, y); } - } break; case TRANSFORM: { @@ -2416,12 +2658,16 @@ public void actionPerformed(ActionEvent e) { } } break; - } - } + /** + * Displays a right-click context menu at the specified coordinates. + * + * @param x the x-coordinate where the menu should be displayed + * @param y the y-coordinate where the menu should be displayed + */ public void RightMenuPopup(double x, double y) { if (gxInstance == null) return; @@ -2450,7 +2696,15 @@ public void RightMenuPopup(double x, double y) { } - public void SelectFromAList(Vector v1, Vector v2, double x, double y) { // from v1 to v2 + /** + * Selects objects from one list and adds them to another based on coordinates. + * + * @param v1 the list to which selected objects are added + * @param v2 the list from which objects are selected + * @param x the x-coordinate for selection + * @param y the y-coordinate for selection + */ + public void SelectFromAList(Vector v1, Vector v2, double x, double y) { for (int i = 0; i < v2.size(); i++) { CClass cc = (CClass) v2.get(i); if (cc.select(x, y)) { @@ -2459,6 +2713,14 @@ public void SelectFromAList(Vector v1, Vector v2, double x, double y) { // from } } + /** + * Selects all objects from various lists based on coordinates and type. + * + * @param v the list to which selected objects are added + * @param x the x-coordinate for selection + * @param y the y-coordinate for selection + * @param type the type of objects to select (0: point preferential, 1: geometry object only, 2: all, etc.) + */ public void SelectAllFromXY(Vector v, double x, double y, int type) { // 2: all; 1: geometry object only 0: point preferential //3: only point, 4:only line, 5: only circle @@ -2523,6 +2785,13 @@ public void SelectAllFromXY(Vector v, double x, double y, int type) { } + /** + * Selects text objects based on coordinates. + * + * @param v the list to which selected text objects are added + * @param x the x-coordinate for selection + * @param y the y-coordinate for selection + */ public void SelectNameText(Vector v, double x, double y) { for (int i = 0; i < textlist.size(); i++) { CText text = (CText) textlist.get(i); @@ -2537,6 +2806,14 @@ public void SelectNameText(Vector v, double x, double y) { } } + /** + * Selects a single object from various lists based on coordinates and type. + * + * @param x the x-coordinate for selection + * @param y the y-coordinate for selection + * @param type the type of objects to select (0: point preferential, 1: geometry object only, 2: all, etc.) + * @return the selected object, or null if no object is selected + */ public CClass SelectOneFromXY(double x, double y, int type) { Vector v = new Vector(); this.SelectAllFromXY(v, x, y, type); @@ -2550,40 +2827,12 @@ public CClass SelectOneFromXY(double x, double y, int type) { } - public Vector OnSelect(double x, double y) { - - Vector v = new Vector(); - SelectAllFromXY(v, x, y, 0); - - if (v.size() == 0) { - clearSelection(); - } else { - if (v.size() == 1) { - if (SelectList.containsAll(v)) { - removeAllSelection(v); - return SelectList; - } else { - CClass cc = (CClass) v.get(0); - SelectList.addAll(v); - v.clear(); - if (cc.m_type == CClass.ANGLE) { - CAngle ag = (CAngle) cc; - v.add(ag.lstart); - v.add(ag.lend); - this.flashStep(v); - } - } - } else { - Object obj = this.popSelect(v, (int) x, (int) y); - if (obj != null) { - this.addObjectToList(obj, SelectList); - } - } - - } - return v; - } - + /** + * Adjusts the coordinates of the second point to align with the first point if they are close enough. + * + * @param p1 the first point + * @param p2 the second point + */ public void getSmartPV(CPoint p1, CPoint p2) { int x, y; x = y = 0; @@ -2611,19 +2860,20 @@ public void getSmartPV(CPoint p1, CPoint p2) { } } - public CProveText SelectProveText(double x, double y) { - if (cpfield == null) { - return null; - } - return cpfield.select(x, y, false); - } - + /** + * Clears the selection list. + */ public void clearSelection() { SelectList.clear(); if (gxInstance != null) gxInstance.updateActionPool(this.CurrentAction); } + /** + * Adds an object to the selection list. + * + * @param c the object to add + */ public void addToSelectList(Object c) { if (c != null) { SelectList.add(c); @@ -2633,19 +2883,26 @@ public void addToSelectList(Object c) { } - public void removeAllSelection(Vector v) { - SelectList.removeAll(v); - if (gxInstance != null) - gxInstance.updateActionPool(this.CurrentAction); - } - - + /** + * Selects objects based on coordinates and adds them to the catch list. + * + * @param x the x-coordinate for selection + * @param y the y-coordinate for selection + * @return the list of selected objects + */ public Vector OnCatch(double x, double y) { CatchList.clear(); SelectAllFromXY(CatchList, x, y, 0); return CatchList; } + /** + * Checks if a point can be animated along a line. + * + * @param p the point to check + * @param ln the line to check + * @return true if the point can be animated along the line, false otherwise + */ public boolean check_animation(CPoint p, CLine ln) { if (p == null || ln == null) return false; @@ -2657,728 +2914,874 @@ public boolean check_animation(CPoint p, CLine ln) { return true; } - public void DWButtonDown(double x, double y) { - CPoint p = null; - CatchList.clear(); - IsButtonDown = true; - if (SNAP && CurrentAction != SELECT) { - double[] r = getSnap(x, y); - x = r[0]; - y = r[1]; - } - CatchPoint.setXY(x, y); + /** + * Handles selection logic based on the provided x and y coordinates. + * Determines whether to select a smart point, display the rule panel, or update the catch list. + * + * @param x the x-coordinate for selection + * @param y the y-coordinate for selection + */ + private void handleSelectCase(double x, double y) { + CPoint t = SelectAPoint(x, y); + boolean r = false; - switch (this.CurrentAction) { - case SELECT: { - CPoint t = SelectAPoint(x, y); - boolean r = false; + if (gxInstance.isDialogProveVisible()) { + clearSelection(); + if (t != null) + addToSelectList(t); + r = true; + gxInstance.getDialogProve().setSelect(SelectList); + } - if (gxInstance.isDialogProveVisible()) { - clearSelection(); - if (t != null) - addToSelectList(t); + if (t == null) { + if (cpfield != null) { + CProveText ct1 = cpfield.mouseMove(x, y); + if (ct1 == null) { r = true; - gxInstance.getDialogProve().setSelect(SelectList); - } - - if (t == null) { - if (cpfield != null) { - CProveText ct1 = cpfield.mouseMove(x, y); - if (ct1 == null) { - r = true; - CProveText ct = cpfield.select(x, y, false); - if (ct != null) { - UndoStruct un = ct.getUndoStruct(); - if (un != null) { - this.setObjectListForFlash(un.getAllObjects(this)); - } - } - } else { - Point pt = ct1.getPopExLocation(); - gxInstance.showRulePanel("R1", (int) pt.getX(), (int) pt.getY()); + CProveText ct = cpfield.select(x, y, false); + if (ct != null) { + UndoStruct un = ct.getUndoStruct(); + if (un != null) { + this.setObjectListForFlash(un.getAllObjects(this)); } } - } else { - if (gxInstance.hasMannualInputBar()) { - PanelProve pp = gxInstance.getpprove(); - r = pp.selectAPoint((CPoint) t); - if (r) - this.setObjectListForFlash(t); - } - gxInstance.selectAPoint((CPoint) t); + Point pt = ct1.getPopExLocation(); + gxInstance.showRulePanel("R1", (int) pt.getX(), (int) pt.getY()); } + } + } else { + if (gxInstance.hasMannualInputBar()) { + PanelProve pp = gxInstance.getpprove(); + r = pp.selectAPoint(t); + if (r) + this.setObjectListForFlash(t); + } + gxInstance.selectAPoint(t); + } - if (r == false) { - CatchList.clear(); - this.SelectAllFromXY(CatchList, x, y, 0); - if (CatchList.size() == 0) - this.clearSelection(); - else { - this.addToSelectList(CatchList.get(0)); - } - } else - this.clearSelection(); - vx1 = x; - vy1 = y; + if (r == false) { + CatchList.clear(); + this.SelectAllFromXY(CatchList, x, y, 0); + if (CatchList.size() == 0) + this.clearSelection(); + else { + this.addToSelectList(CatchList.get(0)); } - break; - case MOVE: { - FirstPnt = this.CreateATempPoint(x, y); - Vector v = new Vector(); + } else { + this.clearSelection(); + } + vx1 = x; + vy1 = y; + } - this.SelectAllFromXY(v, x, y, 0); - if (v.size() == 0) { - clearSelection(); - if (cpfield != null) { - CProveText ct1 = cpfield.mouseMove(x, y); - if (ct1 == null) { - CProveText ct = cpfield.select(x, y, false); - if (ct != null) { - UndoStruct un = ct.getUndoStruct(); - if (un != null) { - this.setObjectListForFlash(un.getAllObjects(this)); - } + /** + * Handles the move case by selecting objects from the given coordinates. + * Clears the selection and updates the view of elements based on user interaction. + * + * @param x the x-coordinate for moving + * @param y the y-coordinate for moving + */ + private void handleMoveCase(double x, double y) { + FirstPnt = this.CreateATempPoint(x, y); + Vector v = new Vector(); - } - } else { - Point pt = ct1.getPopExLocation(); - gxInstance.showRulePanel(ct1.getRulePath(), - (int) pt.getX(), (int) pt.getY()); - } - } - } else if (v.size() == 1) { - clearSelection(); - SelectList.addAll(v); - CClass cc = (CClass) v.get(0); - v.clear(); - if (cc instanceof CPoint) { - if (gxInstance != null) { - if (gxInstance.isconcVisible()) { - gxInstance.getConcDialog().selectAPoint((CPoint) cc); - } - if (gxInstance.hasMannualInputBar()) { - gxInstance.getMannalInputToolBar().selectAPoint((CPoint) cc); - } + this.SelectAllFromXY(v, x, y, 0); + if (v.size() == 0) { + clearSelection(); + if (cpfield != null) { + CProveText ct1 = cpfield.mouseMove(x, y); + if (ct1 == null) { + CProveText ct = cpfield.select(x, y, false); + if (ct != null) { + UndoStruct un = ct.getUndoStruct(); + if (un != null) { + this.setObjectListForFlash(un.getAllObjects(this)); } + } } else { - clearSelection(); - addToSelectList(v.get(0)); + Point pt = ct1.getPopExLocation(); + gxInstance.showRulePanel(ct1.getRulePath(), + (int) pt.getX(), (int) pt.getY()); } - - if (SelectList.size() == 1) { - if (gxInstance != null) { - gxInstance.viewElementsAuto((CClass) SelectList.get(0)); + } + } else if (v.size() == 1) { + clearSelection(); + SelectList.addAll(v); + CClass cc = (CClass) v.get(0); + v.clear(); + if (cc instanceof CPoint) { + if (gxInstance != null) { + if (gxInstance.isconcVisible()) { + gxInstance.getConcDialog().selectAPoint((CPoint) cc); + } + if (gxInstance.hasMannualInputBar()) { + gxInstance.getMannalInputToolBar().selectAPoint((CPoint) cc); } } } - break; - case D_POINT: { - clearSelection(); - p = this.SmartgetApointFromXY(x, y); - if (p != null) { - addToSelectList(p); - this.UndoAdded(p.TypeString()); - } + } else { + clearSelection(); + addToSelectList(v.get(0)); + } + + if (SelectList.size() == 1) { + if (gxInstance != null) { + gxInstance.viewElementsAuto((CClass) SelectList.get(0)); } - break; - case TRIANGLE: { + } + } - if (STATUS == 0) { - CPoint pp = (CPoint) this.CatchList(pointlist, x, y); - if (pp == null) { - pp = SmartgetApointFromXY(x, y); - } + /** + * Handles the point definition case. + * Clears the current selection, retrieves a smart point from the given coordinates, and adds it to the selection. + * + * @param x the x-coordinate for defining a point + * @param y the y-coordinate for defining a point + * @param p an initial point which may be replaced by a smart-detected point + */ + private void handleDpointCase(double x, double y, CPoint p) { + clearSelection(); + p = this.SmartgetApointFromXY(x, y); + if (p != null) { + addToSelectList(p); + this.UndoAdded(p.TypeString()); + } + } - this.addToSelectList(pp); - FirstPnt = pp; - STATUS = 1; + /** + * Handles the triangle creation process by selecting three distinct points. + * Manages state transitions for triangle construction and adds corresponding lines and constraints. + * + * @param x the x-coordinate used in triangle construction + * @param y the y-coordinate used in triangle construction + */ + private void handleTriangleCase(double x, double y) { + if (STATUS == 0) { + CPoint pp = (CPoint) this.CatchList(pointlist, x, y); + if (pp == null) { + pp = SmartgetApointFromXY(x, y); + } - } else if (STATUS == 1) { - CPoint pp = (CPoint) this.CatchList(pointlist, x, y); - if (pp == null) { - pp = SmartgetApointFromXY(x, y); - } + this.addToSelectList(pp); + FirstPnt = pp; + STATUS = 1; - if (!SelectList.contains(pp)) { - addToSelectList(pp); - SecondPnt = pp; - STATUS = 2; - } + } else if (STATUS == 1) { + CPoint pp = (CPoint) this.CatchList(pointlist, x, y); + if (pp == null) { + pp = SmartgetApointFromXY(x, y); + } - } else { - CPoint pp = (CPoint) this.CatchList(pointlist, x, y); - if (pp == null) { - pp = SmartgetApointFromXY(x, y); - } + if (!SelectList.contains(pp)) { + addToSelectList(pp); + SecondPnt = pp; + STATUS = 2; + } - if (!SelectList.contains(pp)) { - addToSelectList(pp); - } else { - break; - } + } else { + CPoint pp = (CPoint) this.CatchList(pointlist, x, y); + if (pp == null) { + pp = SmartgetApointFromXY(x, y); + } - CPoint p1 = (CPoint) SelectList.get(0); - CPoint p2 = (CPoint) SelectList.get(1); - CPoint p3 = (CPoint) SelectList.get(2); - CLine line1 = new CLine(p1, p2); - CLine line2 = new CLine(p1, p3); - CLine line3 = new CLine(p2, p3); - this.addPointToList(p1); - this.addPointToList(p2); - this.addPointToList(p3); - this.addLineToList(line1); - this.addLineToList(line2); - this.addLineToList(line3); - Constraint cs = new Constraint(Constraint.TRIANGLE, p1, p2, p3); - this.addConstraintToList(cs); - this.UndoAdded("Triangle " + p1.m_name + p2.m_name + p3.m_name); - FirstPnt = SmartgetApointFromXY(x, y); - SecondPnt = this.CreateATempPoint(x, y); - clearSelection(); - STATUS = 0; - } + if (!SelectList.contains(pp)) { + addToSelectList(pp); + } else { + return; } - break; - case H_LINE: - case V_LINE: - if (STATUS == 0) { - FirstPnt = SmartgetApointFromXY(x, y); - SecondPnt = this.CreateATempPoint(x, y); - STATUS = 1; - } - break; - case D_LINE: { - if (STATUS == 0) { - if ((FirstPnt = SmartgetApointFromXY(x, y)) != null) { - STATUS = 1; - addPointToList(FirstPnt); - this.addToSelectList(FirstPnt); - } - } else if (STATUS == 1) { - CPoint tp = FirstPnt; - if (this.isPointOnObject) { - x = mouseCatchX; - y = mouseCatchY; - } - CPoint pp = SmartgetApointFromXY(x, y); + + CPoint p1 = (CPoint) SelectList.get(0); + CPoint p2 = (CPoint) SelectList.get(1); + CPoint p3 = (CPoint) SelectList.get(2); + CLine line1 = new CLine(p1, p2); + CLine line2 = new CLine(p1, p3); + CLine line3 = new CLine(p2, p3); + this.addPointToList(p1); + this.addPointToList(p2); + this.addPointToList(p3); + this.addLineToList(line1); + this.addLineToList(line2); + this.addLineToList(line3); + Constraint cs = new Constraint(Constraint.TRIANGLE, p1, p2, p3); + this.addConstraintToList(cs); + this.UndoAdded("Triangle " + p1.m_name + p2.m_name + p3.m_name); + FirstPnt = SmartgetApointFromXY(x, y); + SecondPnt = this.CreateATempPoint(x, y); + clearSelection(); + STATUS = 0; + } + } + + /** + * Handles the vertical line case. + * Sets the first point and creates a temporary second point for further vertical line processing. + * + * @param x the x-coordinate for vertical line creation + * @param y the y-coordinate for vertical line creation + */ + private void handleVLineCase(double x, double y) { + if (STATUS == 0) { + FirstPnt = SmartgetApointFromXY(x, y); + SecondPnt = this.CreateATempPoint(x, y); + STATUS = 1; + } + } + + /** + * Handles the definition of a line by selecting two points. + * In the first stage, selects the starting point; in the second stage, completes the line, applies smart adjustments, + * adds the line to the list, and creates the associated constraint. + * + * @param x the x-coordinate for line definition + * @param y the y-coordinate for line definition + */ + private void handleDLineCase(double x, double y) { + if (STATUS == 0) { + if ((FirstPnt = SmartgetApointFromXY(x, y)) != null) { + STATUS = 1; + addPointToList(FirstPnt); + this.addToSelectList(FirstPnt); + } + } else if (STATUS == 1) { + CPoint tp = FirstPnt; + if (this.isPointOnObject) { + x = mouseCatchX; + y = mouseCatchY; + } + CPoint pp = SmartgetApointFromXY(x, y); // pp.setXY(x, y); - getSmartPV(FirstPnt, pp); + getSmartPV(FirstPnt, pp); - if (tp != pp && tp != null && pp != null) { - setSmartPVLine(tp, pp); - addPointToList(pp); - CLine ln = new CLine(pp, tp, CLine.LLine); - this.addLineToList(ln); - Constraint cs = new Constraint(Constraint.LINE, tp, pp); - addConstraintToList(cs); - this.reCalculate(); - this.UndoAdded(ln.getDescription()); - } - clearSelection(); - STATUS = 0; - FirstPnt = null; - } + if (tp != pp && tp != null && pp != null) { + setSmartPVLine(tp, pp); + addPointToList(pp); + CLine ln = new CLine(pp, tp, CLine.LLine); + this.addLineToList(ln); + Constraint cs = new Constraint(Constraint.LINE, tp, pp); + addConstraintToList(cs); + this.reCalculate(); + this.UndoAdded(ln.getDescription()); } - break; - case D_POLYGON: { - CPoint pt = SmartgetApointFromXY(x, y); - setSmartPVLine(FirstPnt, pt); - boolean finish = false; + clearSelection(); + STATUS = 0; + FirstPnt = null; + } + } - if (SelectList.size() == 0) { - this.addPointToList(pt); - addToSelectList(pt); - FirstPnt = pt; - SecondPnt = this.CreateATempPoint(x, y); - } else if (pt == SelectList.get(0)) { - finish = true; - } else if (SelectList.contains(pt)) { - break; - } else { - this.addPointToList(pt); - addToSelectList(pt); - if (SelectList.size() == STATUS) { - finish = true; - } - FirstPnt = pt; + /** + * Handles the polygon definition process by selecting multiple points. + * Adds points until the first point is re-selected, then constructs the polygon, creates connecting lines, + * and adds polygon constraints. + * + * @param x the x-coordinate for polygon definition + * @param y the y-coordinate for polygon definition + */ + private void handleDPolygonCase(double x, double y) { + CPoint pt = SmartgetApointFromXY(x, y); + setSmartPVLine(FirstPnt, pt); + boolean finish = false; + + if (SelectList.isEmpty()) { + this.addPointToList(pt); + addToSelectList(pt); + FirstPnt = pt; + SecondPnt = this.CreateATempPoint(x, y); + } else if (pt == SelectList.get(0)) { + finish = true; + } else if (SelectList.contains(pt)) { + return; + } else { + this.addPointToList(pt); + addToSelectList(pt); + if (SelectList.size() == STATUS) { + finish = true; + } + FirstPnt = pt; + } + if (finish) { + if (SelectList.size() <= 1) { + clearSelection(); + return; + } + CPoint t1 = (CPoint) SelectList.get(0); + CPoint tp = t1; + for (int i = 1; i < SelectList.size(); i++) { + CPoint tt = (CPoint) SelectList.get(i); + if (this.fd_line(tt, tp) == null) { + CLine ln = new CLine(tt, tp, CLine.LLine); + this.addLineToList(ln); } - if (finish) { - if (SelectList.size() <= 1) { - clearSelection(); - return; - } - CPoint t1 = (CPoint) SelectList.get(0); - CPoint tp = t1; - for (int i = 1; i < SelectList.size(); i++) { - CPoint tt = (CPoint) SelectList.get(i); - if (this.fd_line(tt, tp) == null) { - CLine ln = new CLine(tt, tp, CLine.LLine); - this.addLineToList(ln); - } - tp = tt; - } - if (this.fd_line(t1, tp) == null) { - CLine ln = new CLine(t1, tp); - this.addLineToList(ln); - } + tp = tt; + } + if (this.fd_line(t1, tp) == null) { + CLine ln = new CLine(t1, tp); + this.addLineToList(ln); + } - String s = ""; - int size = SelectList.size(); - for (int i = 0; i < size; i++) { - CClass cc = (CClass) SelectList.get(i); - s += cc.m_name; + StringBuilder s = new StringBuilder(); + int size = SelectList.size(); + for (Object o : SelectList) { + CClass cc = (CClass) o; + s.append(cc.m_name); - } - if (size == 3) { - Constraint cs = new Constraint(Constraint.TRIANGLE, SelectList); - this.addConstraintToList(cs); + } + if (size == 3) { + Constraint cs = new Constraint(Constraint.TRIANGLE, SelectList); + this.addConstraintToList(cs); - this.UndoAdded("triangle " + s); - } else if (size == 4) { - Constraint cs = new Constraint(Constraint.QUADRANGLE, SelectList); - this.addConstraintToList(cs); - this.UndoAdded("quadrangle " + s); - } else if (size == 5) { - Constraint cs = new Constraint(Constraint.PENTAGON, SelectList); - this.addConstraintToList(cs); - this.UndoAdded(GExpert.getTranslationViaGettext("Pentagon {0}", s)); - } else { - Constraint cs = new Constraint(Constraint.POLYGON, SelectList); - this.addConstraintToList(cs); - this.UndoAdded(GExpert.getTranslationViaGettext("Polygon {0}", s)); - } - clearSelection(); - } + this.UndoAdded("triangle " + s); + } else if (size == 4) { + Constraint cs = new Constraint(Constraint.QUADRANGLE, SelectList); + this.addConstraintToList(cs); + this.UndoAdded("quadrangle " + s); + } else if (size == 5) { + Constraint cs = new Constraint(Constraint.PENTAGON, SelectList); + this.addConstraintToList(cs); + this.UndoAdded(GExpert.getTranslationViaGettext("Pentagon {0}", s.toString())); + } else { + Constraint cs = new Constraint(Constraint.POLYGON, SelectList); + this.addConstraintToList(cs); + this.UndoAdded(GExpert.getTranslationViaGettext("Polygon {0}", s.toString())); } - break; - case D_PARELINE: { - if (STATUS == 0) { - clearSelection(); - CLine line = this.SmartPLine(CatchPoint); + clearSelection(); + } + } - if (line == null) { - break; - } - addToSelectList(line); - STATUS = 1; - } else if (STATUS == 1) { - if (SelectList.size() == 0) { - break; - } - CPoint pt = this.SmartgetApointFromXY(x, y); - CLine line = (CLine) SelectList.get(0); + /** + * Handles the parallel line definition case. + * Selects an existing line and a point to create a new line that is parallel to the selected one, + * then adds the parallel constraint. + * + * @param x the x-coordinate for parallel line definition + * @param y the y-coordinate for parallel line definition + */ + private void handleDPareLineCase(double x, double y) { + if (STATUS == 0) { + clearSelection(); + CLine line = this.SmartPLine(CatchPoint); - CLine line1 = new CLine(pt, CLine.PLine); - Constraint cs = new Constraint(Constraint.PARALLEL, line1, line); - this.addConstraintToList(cs); - line1.addconstraint(cs); - clearSelection(); - this.addLineToList(line1); - // UndoStruct u = this.UndoAdded(line1.TypeString() + " parallel " + - // line.getDiscription() + " passing " + - // pt.getname()); - UndoStruct u = this.UndoAdded(line1.TypeString() + " " + GExpert.getTranslationViaGettext("parallel to {0} passing {1}", - line.getDiscription(), pt.getname())); - u.addObject(line1); - u.addObject(line); - u.addObject(pt); - clearSelection(); - STATUS = 0; + if (line == null) { + return; + } + addToSelectList(line); + STATUS = 1; + } else if (STATUS == 1) { + if (SelectList.isEmpty()) { + return; + } + CPoint pt = this.SmartgetApointFromXY(x, y); + CLine line = (CLine) SelectList.get(0); - } + CLine line1 = new CLine(pt, CLine.PLine); + Constraint cs = new Constraint(Constraint.PARALLEL, line1, line); + this.addConstraintToList(cs); + line1.addconstraint(cs); + clearSelection(); + this.addLineToList(line1); + // UndoStruct u = this.UndoAdded(line1.TypeString() + " parallel " + + // line.getDiscription() + " passing " + + // pt.getname()); + UndoStruct u = this.UndoAdded(line1.TypeString() + " " + GExpert.getTranslationViaGettext("parallel to {0} passing {1}", + line.getDiscription(), pt.getname())); + u.addObject(line1); + u.addObject(line); + u.addObject(pt); + clearSelection(); + STATUS = 0; + + } + + } + + /** + * Handles the perpendicular line definition case. + * Selects an existing line and a point to create a new line perpendicular to the selected one, + * then adds the perpendicular constraint. + * + * @param x the x-coordinate for perpendicular line definition + * @param y the y-coordinate for perpendicular line definition + */ + private void handleDPerpLineCase(double x, double y) { + if (STATUS == 0) { + clearSelection(); + CLine line = this.SmartPLine(CatchPoint); + if (line == null) + return; + addToSelectList(line); + STATUS = 1; + } else if (STATUS == 1) { + if (SelectList.size() == 0) { + return; } - break; + CLine line = (CLine) SelectList.get(0); + CPoint pt = this.SmartgetApointFromXY(x, y); + + CLine line1 = new CLine(pt, CLine.TLine); + Constraint c = new Constraint(Constraint.PERPENDICULAR, line1, line); + this.addConstraintToList(c); + line1.addconstraint(c); + addLineToList(line1); + addCTMark(line, line1); + UndoStruct u = this.UndoAdded(line1.TypeString() + " perp " + + // line.getDiscription() + " passing " + + // pt.getname()); + line.getDescription() + " " + + GExpert.getTranslationViaGettext("passing {0}", pt.getname())); + u.addObject(line1); + u.addObject(line); + u.addObject(pt); + STATUS = 0; + clearSelection(); + } + } - case D_PERPLINE: { - if (STATUS == 0) { - clearSelection(); - CLine line = this.SmartPLine(CatchPoint); - if (line == null) - break; + /** + * Handles the A-line construction case based on existing selected lines. + * If fewer than three lines are selected, accumulates the selection; otherwise, creates a new A-line constrained + * by the intersection properties of the selected lines. + * + * @param x the x-coordinate used for A-line construction + * @param y the y-coordinate used for A-line construction + */ + private void handleDAlineCase(double x, double y) { + int n = SelectList.size(); + if (n < 3) { + CLine line = this.SmartPLine(CatchPoint); + if (line == null) { + return; + } + if (n == 1) { + CLine ln1 = (CLine) SelectList.get(0); + if (CLine.commonPoint(ln1, line) == null) { + JOptionPane.showMessageDialog(gxInstance, GExpert.getLanguage("The selected two lines don't have intersected point"), + GExpert.getLanguage("Warning"), JOptionPane.WARNING_MESSAGE); + return; + } + } + addToSelectList(line); + } else { + CLine ln1 = (CLine) SelectList.get(0); + CLine ln2 = (CLine) SelectList.get(1); + CLine ln3 = (CLine) SelectList.get(2); + CPoint tt = null; + if (this.SmartPLine(CatchPoint) == ln3 || ((tt = this.SmartPoint(CatchPoint)) != null && ln3.containPT(tt))) { + CPoint p1 = this.SmartgetApointFromXY(x, y); + CLine ln = new CLine(CLine.ALine); + ln.addApoint(p1); + Constraint cs = new Constraint(Constraint.ALINE, ln1, ln2, ln3, ln); + cs.setPolyGenerate(false); + + ln.addconstraint(cs); + this.addLineToList(ln); + this.addConstraintToList(cs); + clearSelection(); + this.UndoAdded("ALine " + ln.getname()); + } + } + } - addToSelectList(line); - STATUS = 1; - } else if (STATUS == 1) { - if (SelectList.size() == 0) { - break; - } - CLine line = (CLine) SelectList.get(0); - CPoint pt = this.SmartgetApointFromXY(x, y); - - CLine line1 = new CLine(pt, CLine.TLine); - Constraint c = new Constraint(Constraint.PERPENDICULAR, line1, line); - this.addConstraintToList(c); - line1.addconstraint(c); - addLineToList(line1); - addCTMark(line, line1); - // this.otherlist.add(m); - UndoStruct u = this.UndoAdded(line1.TypeString() + " perp " + - // line.getDiscription() + " passing " + - // pt.getname()); - line.getDescription() + " " + - GExpert.getTranslationViaGettext("passing {0}", pt.getname())); - u.addObject(line1); - u.addObject(line); - u.addObject(pt); - STATUS = 0; - clearSelection(); + /** + * Handles the DAB line case. + * + *

+ * Depending on the current selection status, it selects points or lines and creates a line representing the angle bisector. + * In one case, it creates a new auxiliary point and line constraint; in the other, it directly creates the bisector. + *

+ * + * @param x the x coordinate of the click + * @param y the y coordinate of the click + * @param p a context-dependent point parameter + */ + private void handleDABlineCase(double x, double y, CPoint p) { + int n = SelectList.size(); + if (STATUS == 0) { + p = this.SelectAPoint(x, y); + if (p != null) { + addToSelectList(p); + STATUS = 1; + } else { + CLine ln = SelectALine(x, y); + if (ln != null) { + addToSelectList(ln); + CatchPoint.setXY(x, y); + ln.pointonline(CatchPoint); + catchX = CatchPoint.getx(); + catchY = CatchPoint.gety(); } + STATUS = 2; } - break; - case D_ALINE: { - int n = SelectList.size(); - if (n < 3) { - CLine line = this.SmartPLine(CatchPoint); - if (line == null) { - break; - } - if (n == 1) { - CLine ln1 = (CLine) SelectList.get(0); - if (CLine.commonPoint(ln1, line) == null) { - JOptionPane.showMessageDialog(gxInstance, GExpert.getLanguage("The selected two lines don't have intersected point"), - GExpert.getLanguage("Warning"), JOptionPane.WARNING_MESSAGE); - break; - } - } - addToSelectList(line); - } else { + } else if (STATUS == 5) { + CLine ln = (CLine) SelectList.get(0); + } else { + + if (n < 3 && STATUS == 1) { + addSelectPoint(x, y); + } else if (n < 2 && STATUS == 2) { + CLine ln = SelectALine(x, y); + if (ln != null) { + if (SelectList.isEmpty()) + return; + CLine ln0 = (CLine) SelectList.get(0); + if (CLine.commonPoint(ln0, ln) != null) + addToSelectList(ln); + else + JOptionPane.showMessageDialog(gxInstance, gxInstance.getLanguage("The selected two lines don't have intersected point") + , gxInstance.getLanguage("No intersected point"), JOptionPane.WARNING_MESSAGE); + } + } + n = SelectList.size(); + { + CPoint p1, p2, p3; + boolean dd = true; + if (STATUS == 1 && n == 3) { + p1 = (CPoint) SelectList.get(0); + p2 = (CPoint) SelectList.get(1); + p3 = (CPoint) SelectList.get(2); + } else if (STATUS == 2 && n == 2) { CLine ln1 = (CLine) SelectList.get(0); CLine ln2 = (CLine) SelectList.get(1); - CLine ln3 = (CLine) SelectList.get(2); - CPoint tt = null; - if (this.SmartPLine(CatchPoint) == ln3 || ((tt = this.SmartPoint(CatchPoint)) != null && ln3.containPT(tt))) { - CPoint p1 = this.SmartgetApointFromXY(x, y); - CLine ln = new CLine(CLine.ALine); - ln.addApoint(p1); - Constraint cs = new Constraint(Constraint.ALINE, ln1, ln2, ln3, ln); - cs.setPolyGenerate(false); + p2 = CLine.commonPoint(ln1, ln2); + p1 = ln1.get_Lptv(p2, catchX, catchY); + p3 = ln2.get_Lptv(p2, x, y); + dd = false; + } else + return; + if (p3 != null && p3 != p1 && p3 != p2) { + CLine ln = new CLine(CLine.ABLine); + ln.addApoint(p2); + if (dd) { + CPoint pt = this.CreateANewPoint(0, 0); + ln.addApoint(pt); + CLine ln1 = this.addALine(CLine.LLine, p1, p3); + Constraint cs = new Constraint(Constraint.ANGLE_BISECTOR, p1, p2, p3, ln); + Constraint cs1 = new Constraint(Constraint.PONLINE, pt, ln1); + ln.addconstraint(cs); + this.addPointToList(pt); + this.addLineToList(ln); + this.addConstraintToList(cs); + this.charsetAndAddPoly(false); + clearSelection(); + STATUS = 0; + this.UndoAdded(ln.getSimpleName() + " is the bisector of angle " + p1 + p2 + p3, true, ln.getPtsSize() > 1); + } else { + Constraint cs = new Constraint(Constraint.ANGLE_BISECTOR, p1, p2, p3, ln); ln.addconstraint(cs); this.addLineToList(ln); this.addConstraintToList(cs); clearSelection(); - this.UndoAdded("ALine " + ln.getname()); + STATUS = 0; + this.UndoAdded("Angle Bisector " + ln.getname(), true, ln.getPtsSize() > 1); } } } - break; - case D_ABLINE: { - int n = SelectList.size(); - if (STATUS == 0) { - p = this.SelectAPoint(x, y); - if (p != null) { - addToSelectList(p); - STATUS = 1; - } else { - CLine ln = SelectALine(x, y); - if (ln != null) { - addToSelectList(ln); - CatchPoint.setXY(x, y); - ln.pointonline(CatchPoint); - catchX = CatchPoint.getx(); - catchY = CatchPoint.gety(); - } - STATUS = 2; - } - } else if (STATUS == 5) { - CLine ln = (CLine) SelectList.get(0); - } else { - - if (n < 3 && STATUS == 1) { - addSelectPoint(x, y); - } else if (n < 2 && STATUS == 2) { - CLine ln = SelectALine(x, y); - if (ln != null) { - if (SelectList.size() < 1) - break; - CLine ln0 = (CLine) SelectList.get(0); - if (CLine.commonPoint(ln0, ln) != null) - addToSelectList(ln); - else - JOptionPane.showMessageDialog(gxInstance, gxInstance.getLanguage("The selected two lines don't have intersected point") - , gxInstance.getLanguage("No intersected point"), JOptionPane.WARNING_MESSAGE); - } - } - n = SelectList.size(); - { - CPoint p1, p2, p3; - boolean dd = true; - if (STATUS == 1 && n == 3) { - p1 = (CPoint) SelectList.get(0); - p2 = (CPoint) SelectList.get(1); - p3 = (CPoint) SelectList.get(2); - } else if (STATUS == 2 && n == 2) { - CLine ln1 = (CLine) SelectList.get(0); - CLine ln2 = (CLine) SelectList.get(1); - p2 = CLine.commonPoint(ln1, ln2); - p1 = ln1.get_Lptv(p2, catchX, catchY); - p3 = ln2.get_Lptv(p2, x, y); - dd = false; - } else - break; + } + } - if (p3 != null && p3 != p1 && p3 != p2) { - CLine ln = new CLine(CLine.ABLine); - ln.addApoint(p2); - if (dd) { - CPoint pt = this.CreateANewPoint(0, 0); - ln.addApoint(pt); - CLine ln1 = this.addALine(CLine.LLine, p1, p3); - Constraint cs = new Constraint(Constraint.ANGLE_BISECTOR, p1, p2, p3, ln); - Constraint cs1 = new Constraint(Constraint.PONLINE, pt, ln1); - ln.addconstraint(cs); - this.addPointToList(pt); - this.addLineToList(ln); - this.addConstraintToList(cs); - this.charsetAndAddPoly(false); - clearSelection(); - STATUS = 0; - this.UndoAdded(ln.getSimpleName() + " is the bisector of angle " + p1 + p2 + p3, true, ln.getPtsSize() > 1); - } else { - Constraint cs = new Constraint(Constraint.ANGLE_BISECTOR, p1, p2, p3, ln); - ln.addconstraint(cs); - this.addLineToList(ln); - this.addConstraintToList(cs); - clearSelection(); - STATUS = 0; - this.UndoAdded("Angle Bisector " + ln.getname(), true, ln.getPtsSize() > 1); - } - } - } + /** + * Handles the DP foot case. + * + *

+ * Processes the creation of a perpendicular foot. Initially selects a point, then computes the foot point relative + * to an existing selected point, adds necessary constraints, and may create corresponding lines. + *

+ * + * @param x the x coordinate of the click + * @param y the y coordinate of the click + * @param p a context-dependent point parameter + */ + private void handleDPfootCase(double x, double y, CPoint p) { + if (STATUS == 0) { + CPoint pt = this.SmartgetApointFromXY(x, y); + if (SelectList.size() == 1) { + CPoint pa = (CPoint) SelectList.get(0); + this.setSmartPVLine(pa, pt); + if (fd_line(pa, pt) == null) { + CLine ln = new CLine(pa, pt); + this.addLineToList(ln); } } - break; - case D_PFOOT: { - if (STATUS == 0) { - CPoint pt = this.SmartgetApointFromXY(x, y); - if (SelectList.size() == 1) { - CPoint pa = (CPoint) SelectList.get(0); - this.setSmartPVLine(pa, pt); - if (fd_line(pa, pt) == null) { - CLine ln = new CLine(pa, pt); - this.addLineToList(ln); - } - } - if (!SelectList.contains(pt)) { - addToSelectList(pt); - } - if (SelectList.size() == 2) { - STATUS = 2; - } - } else if (STATUS == 2) { - CPoint p1 = (CPoint) SelectList.get(0); - CPoint p2 = (CPoint) SelectList.get(1); - - double[] r = get_pt_dmcr(p1.getx(), p1.gety(), p2.getx(), p2.gety(), x, y); - double xr = r[0]; - double yr = r[1]; - p = this.SmartgetApointFromXY(xr, yr); - if (p == p1 || p == p2) { - break; - } - CLine ln1, ln2; - ln1 = ln2 = null; - if ((ln1 = fd_line(p, p1)) == null) { - ln1 = new CLine(p1, p, CLine.LLine); - this.addLineToList(ln1); - } - if ((ln2 = fd_line(p, p2)) == null) { - ln2 = new CLine(p2, p, CLine.LLine); - this.addLineToList(ln2); - } - Constraint cs = new Constraint(Constraint.RIGHT_ANGLED_TRIANGLE, p, p1, p2); - this.addConstraintToList(cs); - this.charsetAndAddPoly(false); - if (!this.isLineExists(p1, p2)) { - CLine lp = new CLine(p1, p2, CLine.LLine); - this.addLineToList(lp); - } - clearSelection(); - STATUS = 0; - addCTMark(ln1, ln2); - //this.otherlist.add(m); - // FIXME: use better keys - this.UndoAdded(GExpert.getLanguage("Right") + " triangle " + p1.getname() + p2.getname() + p.getname()); - } + if (!SelectList.contains(pt)) { + addToSelectList(pt); } - break; + if (SelectList.size() == 2) { + STATUS = 2; + } + } else if (STATUS == 2) { + CPoint p1 = (CPoint) SelectList.get(0); + CPoint p2 = (CPoint) SelectList.get(1); - case PERPWITHFOOT: { - if (STATUS == 0) { - CPoint tp = SmartgetApointFromXY(x, y); - FirstPnt = tp; - STATUS = 1; - } else if (STATUS == 1) { - CPoint pt = this.SmartPoint(CatchPoint); - if (pt == FirstPnt) { - break; - } - CLine line = this.SmartPLine(CatchPoint); - if (line == null) { - break; - } - CPoint pp = this.CreateANewPoint(0, 0); - this.add_PFOOT(line, FirstPnt, pp); - STATUS = 0; - } + double[] r = get_pt_dmcr(p1.getx(), p1.gety(), p2.getx(), p2.gety(), x, y); + double xr = r[0]; + double yr = r[1]; + p = this.SmartgetApointFromXY(xr, yr); + if (p == p1 || p == p2) { + return; } - break; - case D_CIRCLE: { - if (STATUS == 0) { - p = this.SmartgetApointFromXY(x, y); - if (p != null) { - FirstPnt = p; - addToSelectList(p); - addPointToList(p); - STATUS = 1; - } - } else if (STATUS == 1) { - p = SmartgetApointFromXY(x, y); - if (p == FirstPnt) - break; + CLine ln1, ln2; + ln1 = ln2 = null; + if ((ln1 = fd_line(p, p1)) == null) { + ln1 = new CLine(p1, p, CLine.LLine); + this.addLineToList(ln1); + } + if ((ln2 = fd_line(p, p2)) == null) { + ln2 = new CLine(p2, p, CLine.LLine); + this.addLineToList(ln2); + } + Constraint cs = new Constraint(Constraint.RIGHT_ANGLED_TRIANGLE, p, p1, p2); + this.addConstraintToList(cs); + this.charsetAndAddPoly(false); + if (!this.isLineExists(p1, p2)) { + CLine lp = new CLine(p1, p2, CLine.LLine); + this.addLineToList(lp); + } + clearSelection(); + STATUS = 0; + addCTMark(ln1, ln2); + //this.otherlist.add(m); + // FIXME: use better keys + this.UndoAdded(GExpert.getLanguage("Right") + " triangle " + p1.getname() + p2.getname() + p.getname()); + } + } - Circle c = new Circle(FirstPnt, p); - addCircleToList(c); - Constraint cs = new Constraint(Constraint.CIRCLE, FirstPnt, p); - this.addConstraintToList(cs); - this.charsetAndAddPoly(false); - this.UndoAdded(c.getDescription()); - STATUS = 0; - clearSelection(); - } + /** + * Handles the perpendicular with foot case. + * + *

+ * Selects a point and then computes the perpendicular foot of a point on a line, + * creating a new point and linking it with a constraint. + *

+ * + * @param x the x coordinate of the click + * @param y the y coordinate of the click + */ + private void handlePerpWithFoot(double x, double y) { + if (STATUS == 0) { + FirstPnt = SmartgetApointFromXY(x, y); + STATUS = 1; + } else if (STATUS == 1) { + CPoint pt = this.SmartPoint(CatchPoint); + if (pt == FirstPnt) { + return; } - break; - case D_CIR_BY_DIM: { + CLine line = this.SmartPLine(CatchPoint); + if (line == null) { + return; + } + CPoint pp = this.CreateANewPoint(0, 0); + this.add_PFOOT(line, FirstPnt, pp); + STATUS = 0; + } + } + /** + * Handles the DCircle case. + * + *

+ * In the first step, selects a point to be used as the circle's center. On the subsequent call, + * selects a second point that defines the radius, creates the circle, and sets the corresponding constraint. + *

+ * + * @param x the x coordinate of the click + * @param y the y coordinate of the click + * @param p a context-dependent point parameter + */ + private void handleDCircleCase(double x, double y, CPoint p) { + if (STATUS == 0) { + p = this.SmartgetApointFromXY(x, y); + if (p != null) { + FirstPnt = p; + addToSelectList(p); + addPointToList(p); + STATUS = 1; } - break; - case D_CIRCLEBYRADIUS: { - if (SelectList.size() < 2) { - p = (CPoint) this.CatchList(pointlist, x, y); - if (p != null) { - this.addObjectToList(p, SelectList); - } - } else { - p = this.SmartgetApointFromXY(x, y); - CPoint p1 = (CPoint) SelectList.get(0); - CPoint p2 = (CPoint) SelectList.get(1); + } else if (STATUS == 1) { + p = SmartgetApointFromXY(x, y); + if (p == FirstPnt) + return; - Circle cr = new Circle(Circle.RCircle, p); - Constraint cs = new Constraint(Constraint.RCIRCLE, p1, p2, cr); - cr.addConstraint(cs); - this.addConstraintToList(cs); - this.addCircleToList(cr); + Circle c = new Circle(FirstPnt, p); + addCircleToList(c); + Constraint cs = new Constraint(Constraint.CIRCLE, FirstPnt, p); + this.addConstraintToList(cs); + this.charsetAndAddPoly(false); + this.UndoAdded(c.getDescription()); + STATUS = 0; + clearSelection(); + } + } - STATUS = 0; - clearSelection(); - FirstPnt = SecondPnt = null; - this.UndoAdded(cr.getDescription()); - } + /** + * Handles the DCircle By Radius case. + * + *

+ * Waits until two points are selected and then uses a third point's coordinate (via the x and y parameters) + * in conjunction with the selected points to create a circle defined by a radius constraint. + *

+ * + * @param x the x coordinate of the click + * @param y the y coordinate of the click + * @param p a context-dependent point parameter + */ + private void handleDCircleByRadiusCase(double x, double y, CPoint p) { + if (SelectList.size() < 2) { + p = (CPoint) this.CatchList(pointlist, x, y); + if (p != null) { + this.addObjectToList(p, SelectList); } - break; - case D_PRATIO: { - if (SelectList.size() < 2) { - p = this.SelectAPoint(x, y); - if (p != null) { - addObjectToList(p, SelectList); - } else - clearSelection(); - } else { - CPoint px = this.SmartgetApointFromXY(x, y); - if (px != null) { - CPoint p1 = (CPoint) SelectList.get(0); - CPoint p2 = (CPoint) SelectList.get(1); + } else { + p = this.SmartgetApointFromXY(x, y); + CPoint p1 = (CPoint) SelectList.get(0); + CPoint p2 = (CPoint) SelectList.get(1); - p = this.CreateANewPoint(x, y); - Constraint cs = new Constraint(Constraint.PRATIO, p, px, p1, p2, v1, v2); - CPoint pu = this.addADecidedPointWithUnite(p); - if (pu == null) { - this.addConstraintToList(cs); - this.addPointToList(p); - if (true) { - CLine ln = fd_line(p1, p2); - if (status && (ln == null || !ln.containPT(px))) { - CLine ln1 = new CLine(px, p, CLine.LLine); - this.addLineToList(ln1); - } else { - Constraint cs1 = new Constraint(Constraint.PONLINE); - cs1.setPolyGenerate(false); - cs1.addElement(p); - cs1.addElement(ln); - this.addConstraintToList(cs1); - if (status && ln != null) - ln.addApoint(p); - } - } - this.UndoAdded(cs.getMessage()); - } else { - p = pu; - } - clearSelection(); - } else - clearSelection(); - } - } - break; - case D_TRATIO: { - if (SelectList.size() < 2) { - p = this.SelectAPoint(x, y); - if (p != null) { - this.addObjectToList(p, SelectList); - } - } else { - p = this.SmartgetApointFromXY(x, y); - if (SelectList.size() != 2) break; + Circle cr = new Circle(Circle.RCircle, p); + Constraint cs = new Constraint(Constraint.RCIRCLE, p1, p2, cr); + cr.addConstraint(cs); + this.addConstraintToList(cs); + this.addCircleToList(cr); - CPoint p1 = (CPoint) SelectList.get(0); - CPoint p2 = (CPoint) SelectList.get(1); - CPoint px = p; - p = this.CreateANewPoint(x, y); - double dx = p2.getx() - p1.getx(); - double dy = p2.gety() - p1.gety(); + STATUS = 0; + clearSelection(); + FirstPnt = SecondPnt = null; + this.UndoAdded(cr.getDescription()); + } + } - Constraint cs = new Constraint(Constraint.TRATIO, p, px, p1, p2, v1, v2); - CPoint pu = this.addADecidedPointWithUnite(p); - if (pu == null) { - addConstraintToList(cs); - addPointToList(p); - if (true) { - CLine ln = fd_line(p, px); - if (status && ln == null) { - CLine ln1 = new CLine(px, p, CLine.LLine); - this.addLineToList(ln1); - } else { - Constraint cs1 = new Constraint(Constraint.PONLINE); - cs1.setPolyGenerate(false); - cs1.addElement(p); - cs1.addElement(ln); - this.addConstraintToList(cs1); - if (status && ln != null) - ln.addApoint(p); - } - } + /** + * Handles the DPRatio case. + * + *

+ * When two points are already selected, creates a new point based on the ratio parameters and applies a ratio constraint + * between the selected points, optionally adding an auxiliary line if needed. + *

+ * + * @param x the x coordinate of the click + * @param y the y coordinate of the click + * @param p a context-dependent point parameter + */ + private void handleDPRatioCase(double x,double y,CPoint p){ + if (SelectList.size() < 2) { + p = this.SelectAPoint(x, y); + if (p != null) { + addObjectToList(p, SelectList); + } else + clearSelection(); + } else { + CPoint px = this.SmartgetApointFromXY(x, y); + if (px != null) { + CPoint p1 = (CPoint) SelectList.get(0); + CPoint p2 = (CPoint) SelectList.get(1); + + p = this.CreateANewPoint(x, y); + Constraint cs = new Constraint(Constraint.PRATIO, p, px, p1, p2, v1, v2); + CPoint pu = this.addADecidedPointWithUnite(p); + if (pu == null) { + this.addConstraintToList(cs); + this.addPointToList(p); + CLine ln = fd_line(p1, p2); + if (status && (ln == null || !ln.containPT(px))) { + CLine ln1 = new CLine(px, p, CLine.LLine); + this.addLineToList(ln1); } else { - p = pu; + Constraint cs1 = new Constraint(Constraint.PONLINE); + cs1.setPolyGenerate(false); + cs1.addElement(p); + cs1.addElement(ln); + this.addConstraintToList(cs1); + if (status && ln != null) + ln.addApoint(p); } - clearSelection(); - STATUS = 0; this.UndoAdded(cs.getMessage()); + } else { + p = pu; } + clearSelection(); + } else + clearSelection(); + } + } + + /** + * Handles the DTRatio case. + * + *

+ * Applies a triangle ratio constraint between two selected points. A new point is created, + * and additional lines or constraints are generated to enforce the specified ratio. + *

+ * + * @param x the x coordinate of the click + * @param y the y coordinate of the click + * @param p a context-dependent point parameter + */ + private void handleDTRatioCase(double x, double y, CPoint p) { + if (SelectList.size() < 2) { + p = this.SelectAPoint(x, y); + if (p != null) { + this.addObjectToList(p, SelectList); } - break; - case D_PTDISTANCE: { - if (SelectList.size() < 3) { - CPoint pt = this.CreateATempPoint(x, y); - p = this.SmartPoint(pt); + } else { + p = this.SmartgetApointFromXY(x, y); + if (SelectList.size() != 2) return; + + CPoint p1 = (CPoint) SelectList.get(0); + CPoint p2 = (CPoint) SelectList.get(1); + CPoint px = p; + p = this.CreateANewPoint(x, y); + double dx = p2.getx() - p1.getx(); + double dy = p2.gety() - p1.gety(); + + Constraint cs = new Constraint(Constraint.TRATIO, p, px, p1, p2, v1, v2); + CPoint pu = this.addADecidedPointWithUnite(p); + if (pu == null) { + addConstraintToList(cs); + addPointToList(p); + CLine ln = fd_line(p, px); + if (status && ln == null) { + CLine ln1 = new CLine(px, p, CLine.LLine); + this.addLineToList(ln1); + } else { + Constraint cs1 = new Constraint(Constraint.PONLINE); + cs1.setPolyGenerate(false); + cs1.addElement(p); + cs1.addElement(ln); + this.addConstraintToList(cs1); + if (status && ln != null) + ln.addApoint(p); + } + } else { + p = pu; + } + clearSelection(); + STATUS = 0; + this.UndoAdded(cs.getMessage()); + } + } + + /** + * Handles the DPTDistance case. + * + *

+ * When three points are selected, this method enforces an equal distance relationship. + * Depending on whether a line or circle is selected next, it sets up the appropriate constraint and creates a new point. + *

+ * + * @param x the x coordinate of the click + * @param y the y coordinate of the click + * @param p a context-dependent point parameter + */ + private void handleDPTDistanceCase(double x, double y, CPoint p) { + if (SelectList.size() < 3) { + CPoint pt = this.CreateATempPoint(x, y); + p = this.SmartPoint(pt); // String s = null; - if (p != null) { - addToSelectList(p); + if (p != null) { + addToSelectList(p); // s = (p.m_name + " selected"); - this.setObjectListForFlash(p); - } + this.setObjectListForFlash(p); + } // switch (SelectList.size()) { // case 0: // gxInstance.setTipText(s + ',' + " Please Select a Point"); @@ -3395,1876 +3798,2433 @@ public void DWButtonDown(double x, double y) { // gxInstance.setTipText("third point " + s + ',' + // " select a line or a circle"); // } - } else { - CPoint p1 = (CPoint) SelectList.get(0); - CPoint p2 = (CPoint) SelectList.get(1); - CPoint p3 = (CPoint) SelectList.get(2); - Circle c = null; - CLine ln = SelectALine(x, y); - if (ln != null) { - double r = ln.distance(p3.getx(), p3.gety()); - double r1 = sdistance(p1, p2); - if (r < r1) { - CPoint pt = this.CreateANewPoint(x, y); - this.AddPointToLine(pt, ln, false); - Constraint cs = new Constraint(Constraint.EQDISTANCE, p1, p2, p3, pt); - this.charsetAndAddPoly(true); - if (true || this.mulSolutionSelect(pt)) { - this.addConstraintToList(cs); - this.addPointToList(pt); - /* - this.UndoAdded("Take a point " - + pt.m_name + " on " + ln.getDescription() + - " st " + p1.m_name + p2.m_name + " = " + - p3.m_name + pt.m_name); - */ - this.UndoAdded(GExpert.getTranslationViaGettext( - "Take a point {0} on line {1} such that {2}",pt.m_name, - ln.getSimpleName(), p1.m_name + p2.m_name + " = " + - p3.m_name + pt.m_name)); + } else { + CPoint p1 = (CPoint) SelectList.get(0); + CPoint p2 = (CPoint) SelectList.get(1); + CPoint p3 = (CPoint) SelectList.get(2); + Circle c = null; + CLine ln = SelectALine(x, y); + if (ln != null) { + double r = ln.distance(p3.getx(), p3.gety()); + double r1 = sdistance(p1, p2); + if (r < r1) { + CPoint pt = this.CreateANewPoint(x, y); + this.AddPointToLine(pt, ln, false); + Constraint cs = new Constraint(Constraint.EQDISTANCE, p1, p2, p3, pt); + this.charsetAndAddPoly(true); + this.addConstraintToList(cs); + this.addPointToList(pt); + this.UndoAdded(GExpert.getTranslationViaGettext( + "Take a point {0} on line {1} such that {2}", pt.m_name, + ln.getSimpleName(), p1.m_name + p2.m_name + " = " + + p3.m_name + pt.m_name)); - } else { - this.ErasedADecidedPoint(pt); - ln.points.remove(pt); - } - } else - JOptionPane.showMessageDialog(gxInstance, "Can not add a point", "No Solution", JOptionPane.ERROR_MESSAGE); - - } else if ((c = this.SelectACircle(x, y)) != null) { - CPoint po = c.o; - double d = sdistance(po, p3); - double r = c.getRadius(); - double s = sdistance(p1, p2); - double d1 = d + r; - double d2 = Math.abs(d - r); - if (s > d1 || s < d2) { - JOptionPane.showMessageDialog(gxInstance, "Can not add a point", "No Solution", JOptionPane.ERROR_MESSAGE); - } else { - CPoint pt = this.CreateANewPoint(0, 0); - Constraint cs = new Constraint(Constraint.EQDISTANCE, p1, p2, p3, pt); - Constraint cs1 = new Constraint(Constraint.PONCIRCLE, pt, c); - this.charsetAndAddPoly(true); - if (this.mulSolutionSelect(pt)) { - this.addConstraintToList(cs); - this.addConstraintToList(cs1); - this.addPointToList(pt); - c.addPoint(pt); + } else + JOptionPane.showMessageDialog(gxInstance, "Can not add a point", "No Solution", JOptionPane.ERROR_MESSAGE); + + } else if ((c = this.SelectACircle(x, y)) != null) { + CPoint po = c.o; + double d = sdistance(po, p3); + double r = c.getRadius(); + double s = sdistance(p1, p2); + double d1 = d + r; + double d2 = Math.abs(d - r); + if (s > d1 || s < d2) { + JOptionPane.showMessageDialog(gxInstance, "Can not add a point", "No Solution", JOptionPane.ERROR_MESSAGE); + } else { + CPoint pt = this.CreateANewPoint(0, 0); + Constraint cs = new Constraint(Constraint.EQDISTANCE, p1, p2, p3, pt); + Constraint cs1 = new Constraint(Constraint.PONCIRCLE, pt, c); + this.charsetAndAddPoly(true); + if (this.mulSolutionSelect(pt)) { + this.addConstraintToList(cs); + this.addConstraintToList(cs1); + this.addPointToList(pt); + c.addPoint(pt); /* this.UndoAdded("Take a point " + pt.m_name + "on " + c.getDescription() + " st " + p1.m_name + p2.m_name + " = " + p3.m_name + pt.m_name); */ - this.UndoAdded(GExpert.getTranslationViaGettext( - "Take a point {0} on circle {1} such that {2}", - pt.m_name, c.getname(), p1.m_name + p2.m_name + " = " + + this.UndoAdded(GExpert.getTranslationViaGettext( + "Take a point {0} on circle {1} such that {2}", + pt.m_name, c.getname(), p1.m_name + p2.m_name + " = " + p3.m_name + pt.m_name)); - } else { - this.ErasedADecidedPoint(pt); - gxInstance.setTipText("Failed: can not find a point(P) on Circle " + - " that satisfy |" + p1.m_name + p2.m_name + - "| = |" + p3.m_name + "P|"); - } - } - } else { + this.ErasedADecidedPoint(pt); + gxInstance.setTipText("Failed: can not find a point(P) on Circle " + + " that satisfy |" + p1.m_name + p2.m_name + + "| = |" + p3.m_name + "P|"); } - clearSelection(); - } - } - break; - case LRATIO: { - CPoint pt = this.CreateATempPoint(x, y); - p = this.SmartPoint(pt); - if (p == null) { - break; } - if (SelectList.size() == 0) { - this.addObjectToList(p, SelectList); - } else { - if (p == SelectList.get(0)) { - break; - } - CPoint p1 = (CPoint) SelectList.get(0); - CPoint pp = this.CreateANewPoint(x, y); - Integer t1 = v1; - Integer t2 = v2; - Constraint cs = new Constraint(Constraint.LRATIO, pp, p1, p, t1, t2); - CPoint pu = this.addADecidedPointWithUnite(pp); - if (pu == null) { - this.addConstraintToList(cs); - this.addPointToList(pp); - } else { - pp = pu; - clearSelection(); - this.resetUndo(); - break; - } - CLine ln = null; - for (int i = 0; i < linelist.size(); i++) { - CLine t = (CLine) linelist.get(i); - if (t.sameLine(p1, p)) { - ln = t; - break; - } - } - if (ln != null) { - ln.addApoint(pp); - } - this.charsetAndAddPoly(false); - clearSelection(); - this.UndoAdded(pp.TypeString() + ": " + p1.m_name + - pp.m_name + " / " + pp.m_name + p.m_name + " = " + t1 + "/" + - t2); - } } - break; - case MEET: { - CClass cc = this.SelectALine(x, y); - if (cc == null) - cc = this.SelectACircle(x, y); + clearSelection(); + } + } - if (cc == null) { - clearSelection(); - break; - } - addObjectToList(cc, SelectList); + /** + * Handles the LRatio case. + * + *

+ * Establishes a line ratio constraint. It creates a new point such that the ratio between the distances from the selected point + * is maintained according to provided values. + *

+ * + * @param x the x coordinate of the click + * @param y the y coordinate of the click + * @param p a context-dependent point parameter + */ + private void handleLRatioCase(double x, double y, CPoint p) { + CPoint pt = this.CreateATempPoint(x, y); + p = this.SmartPoint(pt); + if (p == null) { + return; + } + if (SelectList.isEmpty()) { + this.addObjectToList(p, SelectList); + } else { + if (p == SelectList.get(0)) { + return; + } + CPoint p1 = (CPoint) SelectList.get(0); + CPoint pp = this.CreateANewPoint(x, y); + Integer t1 = v1; + Integer t2 = v2; + Constraint cs = new Constraint(Constraint.LRATIO, pp, p1, p, t1, t2); + CPoint pu = this.addADecidedPointWithUnite(pp); + if (pu == null) { + this.addConstraintToList(cs); + this.addPointToList(pp); + } else { + pp = pu; + clearSelection(); + this.resetUndo(); + return; + } - if (SelectList.size() == 1) { + CLine ln = null; + for (Object o : linelist) { + CLine t = (CLine) o; + if (t.sameLine(p1, p)) { + ln = t; break; - } else if (SelectList.size() == 2) { - Object obj1 = SelectList.get(0); - Object obj2 = SelectList.get(1); - meetTwoObject(obj1, obj2, false, x, y); - clearSelection(); } } - break; - case MIRROR: { - CatchPoint.setXY(x, y); - CLine ln = null; - p = this.SmartPoint(CatchPoint); - if (p == null) { - ln = this.SmartPLine(CatchPoint); - if (ln != null) { - this.addObjectToList(ln, SelectList); - } else { - Circle c = this.SmartPCircle(CatchPoint); - if (c != null) { - this.addObjectToList(c, SelectList); - } - } - } else { - this.addObjectToList(p, SelectList); - } - - if (SelectList.size() == 2) { - Object obj1, obj2; - obj1 = SelectList.get(0); - obj2 = SelectList.get(1); - if (obj1 instanceof CPoint && obj2 instanceof CPoint) { - CPoint p1 = (CPoint) obj1; - CPoint p2 = (CPoint) obj2; - CPoint pp = this.CreateANewPoint(0, 0); - Constraint cs = new Constraint(Constraint.PSYM, pp, p1, p2); - CPoint pu = this.addADecidedPointWithUnite(pp); - if (pu == null) { - this.addPointToList(pp); - this.addConstraintToList(cs); - // this.UndoAdded(pp.TypeString() + " is reflection of " + - // p1.TypeString() + " wrt " + - // p2.TypeString()); - this.UndoAdded(GExpert.getTranslationViaGettext("{0} is the reflection of {1} wrt {2}", pp.TypeString(), - p1.TypeString(),p2.TypeString())); - - } else { - pp = pu; - } + if (ln != null) { + ln.addApoint(pp); + } + this.charsetAndAddPoly(false); + clearSelection(); + this.UndoAdded(pp.TypeString() + ": " + p1.m_name + + pp.m_name + " / " + pp.m_name + p.m_name + " = " + t1 + "/" + + t2); + } + } - } else if (obj1 instanceof CPoint && obj2 instanceof CLine) { - CPoint p1 = (CPoint) obj1; - CLine line = (CLine) obj2; + /** + * Handles the meet case. + * + *

+ * Selects geometric objects (lines or circles) and computes their intersection point. + * When two objects are selected, it finds and processes their meeting point. + *

+ * + * @param x the x coordinate of the click + * @param y the y coordinate of the click + */ + private void handleMeetCase(double x, double y) { + CClass cc = this.SelectALine(x, y); + if (cc == null) + cc = this.SelectACircle(x, y); - CPoint pp = this.CreateANewPoint(0, 0); - Constraint cs = new Constraint(Constraint.MIRROR, pp, p1, line); - CPoint pu = this.addADecidedPointWithUnite(pp); - if (pu == null) { - this.addPointToList(pp); - this.addConstraintToList(cs); - // this.UndoAdded(pp.TypeString() + " is reflection of " + - // p1.TypeString() + " wrt " + - // line.getDiscription()); - this.UndoAdded(GExpert.getTranslationViaGettext("{0} is the reflection of {1} wrt {2}", pp.TypeString(), - p1.TypeString(), line.getDiscription())); + if (cc == null) { + clearSelection(); + return; + } + addObjectToList(cc, SelectList); - } else { - pp = pu; - } + if (SelectList.size() == 1) { + return; + } else if (SelectList.size() == 2) { + Object obj1 = SelectList.get(0); + Object obj2 = SelectList.get(1); + meetTwoObject(obj1, obj2, false, x, y); + clearSelection(); + } + } - } else if (obj1 instanceof CLine && obj2 instanceof CPoint) { - CLine line = (CLine) obj1; - CPoint p1 = (CPoint) obj2; + /** + * Handles the mirror case. + * + *

+ * Creates mirrored objects based on the selected geometric entities. Depending on the types of the objects (points, lines, or circles), + * it generates mirror images and sets up the corresponding constraints. + *

+ * + * @param x the x coordinate of the click + * @param y the y coordinate of the click + * @param p a context-dependent point parameter + */ + private void handleMirrorCase(double x, double y, CPoint p) { + CatchPoint.setXY(x, y); + CLine ln = null; + p = this.SmartPoint(CatchPoint); + if (p == null) { + ln = this.SmartPLine(CatchPoint); + if (ln != null) { + this.addObjectToList(ln, SelectList); + } else { + Circle c = this.SmartPCircle(CatchPoint); + if (c != null) { + this.addObjectToList(c, SelectList); + } + } + } else { + this.addObjectToList(p, SelectList); + } + + if (SelectList.size() == 2) { + Object obj1, obj2; + obj1 = SelectList.get(0); + obj2 = SelectList.get(1); + if (obj1 instanceof CPoint && obj2 instanceof CPoint) { + CPoint p1 = (CPoint) obj1; + CPoint p2 = (CPoint) obj2; + CPoint pp = this.CreateANewPoint(0, 0); + Constraint cs = new Constraint(Constraint.PSYM, pp, p1, p2); + CPoint pu = this.addADecidedPointWithUnite(pp); + if (pu == null) { + this.addPointToList(pp); + this.addConstraintToList(cs); + // this.UndoAdded(pp.TypeString() + " is reflection of " + + // p1.TypeString() + " wrt " + + // p2.TypeString()); + this.UndoAdded(GExpert.getTranslationViaGettext("{0} is the reflection of {1} wrt {2}", pp.TypeString(), + p1.TypeString(), p2.TypeString())); - int exist_point_number = 0; - Vector vp = new Vector(); + } else { + pp = pu; + } - for (int i = 0; i < line.points.size(); i++) { - CPoint pu = null; - CPoint pp = null; - Constraint cs = null; + } else if (obj1 instanceof CPoint && obj2 instanceof CLine) { + CPoint p1 = (CPoint) obj1; + CLine line = (CLine) obj2; - CPoint pt = (CPoint) line.points.get(i); - if (pt == p1) { - pu = pt; - } else { - pp = this.CreateANewPoint(0, 0); - cs = new Constraint(Constraint.PSYM, pp, pt, p1); - pu = this.addADecidedPointWithUnite(pp); - } - if (pu == null) { - this.addPointToList(pp); - this.addConstraintToList(cs); - } else { - pp = pu; - exist_point_number++; - } - vp.add(pp); - } + CPoint pp = this.CreateANewPoint(0, 0); + Constraint cs = new Constraint(Constraint.MIRROR, pp, p1, line); + CPoint pu = this.addADecidedPointWithUnite(pp); + if (pu == null) { + this.addPointToList(pp); + this.addConstraintToList(cs); + // this.UndoAdded(pp.TypeString() + " is reflection of " + + // p1.TypeString() + " wrt " + + // line.getDiscription()); + this.UndoAdded(GExpert.getTranslationViaGettext("{0} is the reflection of {1} wrt {2}", pp.TypeString(), + p1.TypeString(), line.getDiscription())); - if (exist_point_number < line.points.size()) { - if (line.points.contains(p1)) { - for (int i = 0; i < vp.size(); i++) { - CPoint tt = (CPoint) vp.get(i); - line.addApoint(tt); - } - this.UndoAdded("reflection"); + } else { + pp = pu; + } - } else { - CLine line2 = new CLine(line.type); - line2.m_color = line.m_color; - line2.m_dash = line.m_dash; - line2.m_width = line.m_width; - - for (int i = 0; i < vp.size(); i++) { - CPoint tt = (CPoint) vp.get(i); - line2.addApoint(tt); - } - Constraint cs = new Constraint(Constraint.LINE, vp); - this.addConstraintToList(cs); - this.addLineToList(line2); - // this.UndoAdded(line2.TypeString() + - // " is reflection of " + - // line.getDiscription() + " wrt " + - // p1.TypeString()); - this.UndoAdded(GExpert.getTranslationViaGettext("{0} is the reflection of {1} wrt {2}", line2.TypeString(), - line.getDiscription(),p1.TypeString())); + } else if (obj1 instanceof CLine && obj2 instanceof CPoint) { + CLine line = (CLine) obj1; + CPoint p1 = (CPoint) obj2; + int exist_point_number = 0; + Vector vp = new Vector<>(); - } + for (int i = 0; i < line.points.size(); i++) { + CPoint pu = null; + CPoint pp = null; + Constraint cs = null; - } else { - boolean exists = false; - for (int i = 0; i < linelist.size(); i++) { - CLine ll = (CLine) linelist.get(i); - if (ll.points.containsAll(vp)) { - exists = true; - break; - } - } - if (exists == false) { - CLine line2 = new CLine(line.type); - for (int i = 0; i < vp.size(); i++) { - CPoint tt = (CPoint) vp.get(i); - line2.addApoint(tt); - } - line2.m_color = ln.m_color; - line2.m_dash = ln.m_dash; - line2.m_width = ln.m_width; - Constraint cs = new Constraint(Constraint.LINE, vp); - this.addConstraintToList(cs); - this.addLineToList(line2); - // this.UndoAdded(line2.getDiscription() + - // " is reflection of " + - // line.getDiscription() + " wrt " + - // p1.TypeString()); - this.UndoAdded(GExpert.getTranslationViaGettext("{0} is the reflection of {1} wrt {2}", line2.getDiscription(), - line.getDescription(),p1.TypeString())); - - - } else - this.UndoAdded("reflection"); - } - } else if (obj1 instanceof CLine && obj2 instanceof CLine) { - CLine line = (CLine) obj1; - CLine line2 = (CLine) obj2; - CPoint cp = CLine.commonPoint(line, line2); - - CLine line3 = new CLine(line.type); - line3.m_color = line.m_color; - line3.m_dash = line.m_dash; - line3.m_width = line.m_width; - - int exist_point_number = 0; - for (int i = 0; i < line.points.size(); i++) { - CPoint pt = (CPoint) line.points.get(i); - - CPoint pp; - if (pt == cp) { - pp = cp; - exist_point_number++; - } else { - pp = this.CreateANewPoint(0, 0); - Constraint cs = new Constraint(Constraint.MIRROR, pp, pt, line2); - CPoint pu = this.addADecidedPointWithUnite(pp); - if (pu == null) { - this.addPointToList(pp); - this.addConstraintToList(cs); - } else { - pp = pu; - exist_point_number++; - } + CPoint pt = (CPoint) line.points.get(i); + if (pt == p1) { + pu = pt; + } else { + pp = this.CreateANewPoint(0, 0); + cs = new Constraint(Constraint.PSYM, pp, pt, p1); + pu = this.addADecidedPointWithUnite(pp); + } + if (pu == null) { + this.addPointToList(pp); + this.addConstraintToList(cs); + } else { + pp = pu; + exist_point_number++; + } + vp.add(pp); + } - } - line3.addApoint(pp); + if (exist_point_number < line.points.size()) { + if (line.points.contains(p1)) { + for (CPoint cPoint : vp) { + CPoint tt = (CPoint) cPoint; + line.addApoint(tt); } - Constraint cs = new Constraint(Constraint.LINE, line3.points); - addConstraintToList(cs); + this.UndoAdded("reflection"); - if (exist_point_number < line.points.size()) { - this.addLineToList(line3); + } else { + CLine line2 = new CLine(line.type); + line2.m_color = line.m_color; + line2.m_dash = line.m_dash; + line2.m_width = line.m_width; - // this.UndoAdded(line3.getDiscription() + - // " is reflection of " + - // line.getDiscription() + " wrt " + - // line2.getDiscription()); - this.UndoAdded(GExpert.getTranslationViaGettext("{0} is the reflection of {1} wrt {2}", line3.getDiscription(), - line.getDiscription(), line2.getDiscription())); + for (CPoint cPoint : vp) { + line2.addApoint((CPoint) cPoint); + } + Constraint cs = new Constraint(Constraint.LINE, vp); + this.addConstraintToList(cs); + this.addLineToList(line2); + // this.UndoAdded(line2.TypeString() + + // " is reflection of " + + // line.getDiscription() + " wrt " + + // p1.TypeString()); + this.UndoAdded(GExpert.getTranslationViaGettext("{0} is the reflection of {1} wrt {2}", line2.TypeString(), + line.getDiscription(), p1.TypeString())); - } else { - boolean exists = false; - for (int i = 0; i < linelist.size(); i++) { - CLine ll = (CLine) linelist.get(i); - if (ll.sameLine(line3)) { - exists = true; - break; - } - } - if (exists == false) { - this.addLineToList(line3); - // this.UndoAdded(line3.getDiscription() + - // " is reflection of " + - // line.getDiscription() + " wrt " + - // line2.getDiscription()); - this.UndoAdded(GExpert.getTranslationViaGettext("{0} is the reflection of {1} wrt {2}", line3.getDiscription(), - line.getDiscription(),line2.getDiscription())); + } - } + } else { + boolean exists = false; + for (Object o : linelist) { + CLine ll = (CLine) o; + if (ll.points.containsAll(vp)) { + exists = true; + break; + } + } + if (!exists) { + CLine line2 = new CLine(line.type); + for (CPoint cPoint : vp) { + line2.addApoint(cPoint); } + line2.m_color = ln.m_color; + line2.m_dash = ln.m_dash; + line2.m_width = ln.m_width; + Constraint cs = new Constraint(Constraint.LINE, vp); + this.addConstraintToList(cs); + this.addLineToList(line2); + this.UndoAdded(GExpert.getTranslationViaGettext("{0} is the reflection of {1} wrt {2}", line2.getDiscription(), + line.getDescription(), p1.TypeString())); - } else if (obj1 instanceof Circle && obj2 instanceof CPoint) { - int exist_point_number = 0; - Circle c1 = (Circle) obj1; - CPoint p1 = (CPoint) obj2; - CPoint pp = this.CreateANewPoint(0, 0); - Constraint cs = new Constraint(Constraint.PSYM, pp, c1.o, p1); + } else + this.UndoAdded("reflection"); + } + } else if (obj1 instanceof CLine && obj2 instanceof CLine) { + CLine line = (CLine) obj1; + CLine line2 = (CLine) obj2; + CPoint cp = CLine.commonPoint(line, line2); + + CLine line3 = new CLine(line.type); + line3.m_color = line.m_color; + line3.m_dash = line.m_dash; + line3.m_width = line.m_width; + + int exist_point_number = 0; + for (int i = 0; i < line.points.size(); i++) { + CPoint pt = (CPoint) line.points.get(i); + + CPoint pp; + if (pt == cp) { + pp = cp; + exist_point_number++; + } else { + pp = this.CreateANewPoint(0, 0); + Constraint cs = new Constraint(Constraint.MIRROR, pp, pt, line2); CPoint pu = this.addADecidedPointWithUnite(pp); if (pu == null) { this.addPointToList(pp); this.addConstraintToList(cs); } else { - exist_point_number++; pp = pu; + exist_point_number++; } - Circle c = null; - for (int i = 0; i < c1.points.size(); i++) { - CPoint pt = (CPoint) c1.points.get(i); - p = this.CreateANewPoint(0, 0); - cs = new Constraint(Constraint.PSYM, p, pt, p1); - CPoint pu1 = this.addADecidedPointWithUnite(p); - if (pu1 == null) { - this.addPointToList(p); - this.addConstraintToList(cs); - } else { - p = pu1; - exist_point_number++; - } + } + line3.addApoint(pp); + } + Constraint cs = new Constraint(Constraint.LINE, line3.points); + addConstraintToList(cs); - if (i == 0) { - c = new Circle(pp, p); - c.m_color = c1.m_color; - c.m_dash = c1.m_dash; - c.m_width = c1.m_width; - } else { - c.addPoint(p); - } - } - cs = new Constraint(Constraint.CIRCLE, c.o); - cs.addElement(c.points); - cs.PolyGenerate(); + if (exist_point_number < line.points.size()) { + this.addLineToList(line3); - addConstraintToList(cs); + // this.UndoAdded(line3.getDiscription() + + // " is reflection of " + + // line.getDiscription() + " wrt " + + // line2.getDiscription()); + this.UndoAdded(GExpert.getTranslationViaGettext("{0} is the reflection of {1} wrt {2}", line3.getDiscription(), + line.getDiscription(), line2.getDiscription())); - if (exist_point_number < c1.points.size() + 1) { - this.addCircleToList(c); - // this.UndoAdded(c.getDescription() + - // " is reflection of " + c1.getDescription() + - // " wrt " + p1.TypeString()); - this.UndoAdded(GExpert.getTranslationViaGettext("{0} is the reflection of {1} wrt {2}", c.getDescription(), - c1.getDescription(),p1.TypeString())); + } else { + boolean exists = false; + for (Object o : linelist) { + CLine ll = (CLine) o; + if (ll.sameLine(line3)) { + exists = true; + break; } + } + if (!exists) { + this.addLineToList(line3); + // this.UndoAdded(line3.getDiscription() + + // " is reflection of " + + // line.getDiscription() + " wrt " + + // line2.getDiscription()); + this.UndoAdded(GExpert.getTranslationViaGettext("{0} is the reflection of {1} wrt {2}", line3.getDiscription(), + line.getDiscription(), line2.getDiscription())); - } else if (obj1 instanceof Circle && obj2 instanceof CLine) { - int exist_point_number = 0; + } + } - Circle c1 = (Circle) obj1; - CLine line = (CLine) obj2; - CPoint pp = this.CreateANewPoint(0, 0); - Constraint cs = new Constraint(Constraint.MIRROR, pp, c1.o, - line); - CPoint pu1 = this.addADecidedPointWithUnite(pp); - if (pu1 == null) { - this.addPointToList(pp); - this.addConstraintToList(cs); - } else { - pp = pu1; - exist_point_number++; - } + } else if (obj1 instanceof Circle && obj2 instanceof CPoint) { + int exist_point_number = 0; - Circle c = null; - for (int i = 0; i < c1.points.size(); i++) { - CPoint pt = (CPoint) c1.points.get(i); - p = this.CreateANewPoint(0, 0); - cs = new Constraint(Constraint.MIRROR, p, pt, line); - CPoint pu2 = this.addADecidedPointWithUnite(p); - if (pu2 == null) { - this.addPointToList(p); - this.addConstraintToList(cs); - } else { - p = pu1; - exist_point_number++; - } - if (i == 0) { - c = new Circle(pp, p); - c.m_color = c1.m_color; - c.m_dash = c1.m_dash; - c.m_width = c1.m_width; - } else { - c.addPoint(p); - } + Circle c1 = (Circle) obj1; + CPoint p1 = (CPoint) obj2; + CPoint pp = this.CreateANewPoint(0, 0); + Constraint cs = new Constraint(Constraint.PSYM, pp, c1.o, p1); + CPoint pu = this.addADecidedPointWithUnite(pp); + if (pu == null) { + this.addPointToList(pp); + this.addConstraintToList(cs); + } else { + exist_point_number++; + pp = pu; + } - } - cs = new Constraint(Constraint.CIRCLE, c.o); - cs.addElement(c.points); - cs.PolyGenerate(); - addConstraintToList(cs); - if (exist_point_number < c1.points.size() + 1) { - this.addCircleToList(c); - // this.UndoAdded(c.getDescription() + - // " is reflection of " + c1.getDescription() + - // " wrt " + line.getDescription()); - this.UndoAdded(GExpert.getTranslationViaGettext("{0} is the reflection of {1} wrt {2}", c.getDescription(), - c1.getDescription(), line.getDescription())); + Circle c = null; + for (int i = 0; i < c1.points.size(); i++) { + CPoint pt = (CPoint) c1.points.get(i); + p = this.CreateANewPoint(0, 0); + cs = new Constraint(Constraint.PSYM, p, pt, p1); + CPoint pu1 = this.addADecidedPointWithUnite(p); + if (pu1 == null) { + this.addPointToList(p); + this.addConstraintToList(cs); + } else { + p = pu1; + exist_point_number++; + } - } + if (i == 0) { + c = new Circle(pp, p); + c.m_color = c1.m_color; + c.m_dash = c1.m_dash; + c.m_width = c1.m_width; } else { - CMisc.print("can not mirror by a circle"); + c.addPoint(p); } - clearSelection(); } - } - break; - case D_MIDPOINT: { + cs = new Constraint(Constraint.CIRCLE, c.o); + cs.addElement(c.points); + cs.PolyGenerate(); - CPoint tp = this.SelectAPoint(x, y); - if (tp != null) { - if (SelectList.size() == 1 && tp != SelectList.get(0)) { - CPoint tp1 = (CPoint) SelectList.get(0); + addConstraintToList(cs); - CPoint po = this.CreateANewPoint(0, 0); - Constraint cs = new Constraint(Constraint.MIDPOINT, po, tp, tp1); - CPoint pu = this.addADecidedPointWithUnite(po); - if (pu == null) { - this.addConstraintToList(cs); - this.addPointToList(po); - CLine ln = fd_line(tp, tp1); - if (ln != null) { - ln.addApoint(po); - Constraint cs2 = new Constraint(Constraint.PONLINE, po, ln, false); - this.addConstraintToList(cs2); + if (exist_point_number < c1.points.size() + 1) { + this.addCircleToList(c); + // this.UndoAdded(c.getDescription() + + // " is reflection of " + c1.getDescription() + + // " wrt " + p1.TypeString()); + this.UndoAdded(GExpert.getTranslationViaGettext("{0} is the reflection of {1} wrt {2}", c.getDescription(), + c1.getDescription(), p1.TypeString())); - } - // this.UndoAdded(po.getname() + ": the midpoint YYY of " + tp1.m_name + tp.m_name); - this.UndoAdded(po.getname() + ": " + GExpert.getTranslationViaGettext("midpoint of {0}", tp1.m_name + tp.m_name)); + } - } else { - po = pu; - } - clearSelection(); + } else if (obj1 instanceof Circle && obj2 instanceof CLine) { + int exist_point_number = 0; + + Circle c1 = (Circle) obj1; + CLine line = (CLine) obj2; + CPoint pp = this.CreateANewPoint(0, 0); + Constraint cs = new Constraint(Constraint.MIRROR, pp, c1.o, + line); + CPoint pu1 = this.addADecidedPointWithUnite(pp); + if (pu1 == null) { + this.addPointToList(pp); + this.addConstraintToList(cs); + } else { + pp = pu1; + exist_point_number++; + } + + Circle c = null; + for (int i = 0; i < c1.points.size(); i++) { + CPoint pt = (CPoint) c1.points.get(i); + p = this.CreateANewPoint(0, 0); + cs = new Constraint(Constraint.MIRROR, p, pt, line); + CPoint pu2 = this.addADecidedPointWithUnite(p); + if (pu2 == null) { + this.addPointToList(p); + this.addConstraintToList(cs); } else { - this.addObjectToList(tp, SelectList); + p = pu1; + exist_point_number++; + } + if (i == 0) { + c = new Circle(pp, p); + c.m_color = c1.m_color; + c.m_dash = c1.m_dash; + c.m_width = c1.m_width; + } else { + c.addPoint(p); } + + } + assert c != null; + cs = new Constraint(Constraint.CIRCLE, c.o); + cs.addElement(c.points); + cs.PolyGenerate(); + addConstraintToList(cs); + if (exist_point_number < c1.points.size() + 1) { + this.addCircleToList(c); + // this.UndoAdded(c.getDescription() + + // " is reflection of " + c1.getDescription() + + // " wrt " + line.getDescription()); + this.UndoAdded(GExpert.getTranslationViaGettext("{0} is the reflection of {1} wrt {2}", c.getDescription(), + c1.getDescription(), line.getDescription())); + } + } else { + CMisc.print("can not mirror by a circle"); } - break; - case D_3PCIRCLE: { - if (STATUS == 0) { // first click - clearSelection(); - p = SmartgetApointFromXY(x, y); - this.addObjectToList(p, SelectList); - STATUS = 1; + clearSelection(); + } + } - } else if (STATUS == 1) { - p = SmartgetApointFromXY(x, y); - this.addObjectToList(p, SelectList); - if (SelectList.size() == 2) { - STATUS = 2; - } + /** + * Handles the midpoint creation case. + * Selects a point by its coordinates to compute the midpoint between the selected point and a previously stored point. + * + * @param x the x-coordinate of the selected point. + * @param y the y-coordinate of the selected point. + */ + private void handleDMidpointCase(double x, double y) { - } else { //third click - CPoint p1, p2, p3; - p1 = (CPoint) SelectList.get(0); - p2 = (CPoint) SelectList.get(1); + CPoint tp = this.SelectAPoint(x, y); + if (tp != null) { + if (SelectList.size() == 1 && tp != SelectList.get(0)) { + CPoint tp1 = (CPoint) SelectList.get(0); - p3 = this.SelectAPoint(x, y); - if (p3 != null) { - if (DrawBase.check_Collinear(p1, p2, p3)) - break; - } + CPoint po = this.CreateANewPoint(0, 0); + Constraint cs = new Constraint(Constraint.MIDPOINT, po, tp, tp1); + CPoint pu = this.addADecidedPointWithUnite(po); + if (pu == null) { + this.addConstraintToList(cs); + this.addPointToList(po); + CLine ln = fd_line(tp, tp1); + if (ln != null) { + ln.addApoint(po); + Constraint cs2 = new Constraint(Constraint.PONLINE, po, ln, false); + this.addConstraintToList(cs2); - if (p3 == null) - p3 = SmartgetApointFromXY(x, y); - if (p3 == null) { - break; } + // this.UndoAdded(po.getname() + ": the midpoint YYY of " + tp1.m_name + tp.m_name); + this.UndoAdded(po.getname() + ": " + GExpert.getTranslationViaGettext("midpoint of {0}", tp1.m_name + tp.m_name)); + } else { + po = pu; + } + clearSelection(); + } else { + this.addObjectToList(tp, SelectList); + } + } + } - if (SelectList.contains(p3)) { - break; - } + /** + * Handles the 3-point circle creation case. + * Collects three points from user selections and creates a circle passing through them. + * + * @param x the x-coordinate for point selection. + * @param y the y-coordinate for point selection. + * @param p a temporary point used during the circle creation process. + */ + private void handleD3PCircleCase(double x, double y, CPoint p) { + if (STATUS == 0) { // first click + clearSelection(); + p = SmartgetApointFromXY(x, y); + this.addObjectToList(p, SelectList); + STATUS = 1; - p = this.CreateANewPoint(0, 0); - Constraint cs = new Constraint(Constraint.CIRCLE3P, p, p1, p2, p3); - CPoint pu = this.addADecidedPointWithUnite(p); - if (pu == null) { - Circle c = new Circle(p, p1, p2, p3); - p.m_name = this.get_cir_center_name(); - this.addPointToList(p); - this.addConstraintToList(cs); - addCircleToList(c); - this.UndoAdded(c.getDescription()); + } else if (STATUS == 1) { + p = SmartgetApointFromXY(x, y); + this.addObjectToList(p, SelectList); + if (SelectList.size() == 2) { + STATUS = 2; + } - } else { - p = pu; - if (!this.isCircleExists(p1, p2, p3)) { - Circle c = new Circle(p, p1, p2, p3); - this.addCircleToList(c); - this.UndoAdded(c.getDescription()); - } - } + } else { //third click + CPoint p1, p2, p3; + p1 = (CPoint) SelectList.get(0); + p2 = (CPoint) SelectList.get(1); - clearSelection(); - STATUS = 0; - } + p3 = this.SelectAPoint(x, y); + if (p3 != null) { + if (DrawBase.check_Collinear(p1, p2, p3)) + return; } - break; - case TRANSLATE: { - FirstPnt = this.CreateATempPoint(x, y); + if (p3 == null) + p3 = SmartgetApointFromXY(x, y); + if (p3 == null) { + return; } - break; - case ZOOM_IN: - zoom_in(x, y, 1); - reCalculate(); - break; - case ZOOM_OUT: - zoom_out(x, y, 1); - reCalculate(); - break; - case ANIMATION: { - CatchPoint.setXY(x, y); - p = this.SmartPoint(CatchPoint); - if (SelectList.size() == 0) { - if (p != null) { - addToSelectList(p); - } - break; - } - if (p != null) - break; - p = (CPoint) SelectList.get(0); - CLine line = SmartPLine(CatchPoint); - if (line != null && !check_animation(p, line)) - break; + if (SelectList.contains(p3)) { + return; + } - AnimatePanel af = gxInstance.getAnimateDialog(); - if (line != null) { - clearSelection(); - animate = new AnimateC(p, line, this.Width, this.Height); - af.setAttribute(animate); - gxInstance.showAnimatePane(); - this.SetCurrentAction(MOVE); - } else { - Circle c = this.SmartPCircle(CatchPoint); - if (c != null) { - clearSelection(); - animate = new AnimateC(p, c, this.Width, this.Height); - af.setAttribute(animate); - gxInstance.showAnimatePane(); - this.SetCurrentAction(MOVE); - } else { - CTrace ct = (CTrace) this.SelectFromAList(tracelist, x, y); - if (ct != null) { - clearSelection(); - animate = new AnimateC(p, ct, this.Width, this.Height); - af.setAttribute(animate); - gxInstance.showAnimatePane(); - this.SetCurrentAction(MOVE); - } - } - } + p = this.CreateANewPoint(0, 0); + Constraint cs = new Constraint(Constraint.CIRCLE3P, p, p1, p2, p3); + CPoint pu = this.addADecidedPointWithUnite(p); + if (pu == null) { + Circle c = new Circle(p, p1, p2, p3); + p.m_name = this.get_cir_center_name(); + this.addPointToList(p); + this.addConstraintToList(cs); + addCircleToList(c); + this.UndoAdded(c.getDescription()); + } else { + p = pu; + if (!this.isCircleExists(p1, p2, p3)) { + Circle c = new Circle(p, p1, p2, p3); + this.addCircleToList(c); + this.UndoAdded(c.getDescription()); + } } - break; - case D_ANGLE: { - if (STATUS == 0 && SelectList.size() == 0) { - FirstPnt = this.CreateATempPoint(x, y); + clearSelection(); + STATUS = 0; + } + } - CLine line = SmartPLine(FirstPnt); - if (line != null) { - addToSelectList(line); - } - } else if (STATUS == 0 && SelectList.size() == 1) { - SecondPnt = this.CreateATempPoint(x, y); - CLine line = SmartPLine(SecondPnt); - if (line != null) { - CLine l2 = (CLine) SelectList.get(0); - if (line == l2) { - break; - } + /** + * Handles the translate action case. + * Captures the starting point for a translation action based on the provided coordinates. + * + * @param x the x-coordinate of the translation start point. + * @param y the y-coordinate of the translation start point. + */ + private void handleTranslateCase(double x, double y) { + FirstPnt = this.CreateATempPoint(x, y); + } - CAngle ag = new CAngle(l2, line, FirstPnt, SecondPnt); - addAngleToList(ag); - ag.move(x, y); - clearSelection(); - addToSelectList(ag); - STATUS = 1; - this.UndoAdded(ag.getDescription(), false, false); - } - } else if (STATUS == 1) { - STATUS = 0; - clearSelection(); - } + /** + * Handles the zoom in action. + * Zooms in at the specified coordinates and recalculates the drawing. + * + * @param x the x-coordinate for zooming in. + * @param y the y-coordinate for zooming in. + */ + private void handleZoomInCase(double x, double y) { + zoom_in(x, y, 1); + reCalculate(); + } + + /** + * Handles the zoom out action. + * Zooms out from the specified coordinates and recalculates the drawing. + * + * @param x the x-coordinate for zooming out. + * @param y the y-coordinate for zooming out. + */ + private void handleZoomOutCase(double x, double y) { + zoom_out(x, y, 1); + reCalculate(); + } + + /** + * Handles the animation case. + * Depending on the current selection and point detection, triggers an animation on a point, line, circle, or trace. + * + * @param x the x-coordinate used for triggering animation. + * @param y the y-coordinate used for triggering animation. + * @param p a temporary point used during the animation process. + */ + private void handleAnimationCase(double x, double y, CPoint p) { + CatchPoint.setXY(x, y); + p = this.SmartPoint(CatchPoint); + + if (SelectList.isEmpty()) { + if (p != null) { + addToSelectList(p); } - break; - case SETEQSIDE: { - CPoint pt = (CPoint) this.CatchList(pointlist, x, y); - if (pt == null) { - clearSelection(); - break; - } - if (SelectList.size() == 3) { - CPoint pt1 = (CPoint) SelectList.get(0); - CPoint pt2 = (CPoint) SelectList.get(1); - CPoint pt3 = (CPoint) SelectList.get(2); - if (STATUS == 1) { - Constraint cs = new Constraint(Constraint.EQDISTANCE, pt1, pt2, pt3, pt); - this.addConstraintToList(cs); - this.charsetAndAddPoly(false); - clearSelection(); - this.UndoAdded(pt1.m_name + pt2.m_name + " = " + pt3.m_name + - pt.m_name); - } else { - Constraint cs = new Constraint(Constraint.NRATIO, pt1, pt2, pt3, pt, v1, v2); - this.addConstraintToList(cs); - this.charsetAndAddPoly(false); - clearSelection(); - this.UndoAdded(pt1.m_name + pt2.m_name + " = " + STATUS + - " " + pt3.m_name + pt.m_name); + return; + } + if (p != null) + return; - } - } else { - addToSelectList(pt); + p = (CPoint) SelectList.get(0); + CLine line = SmartPLine(CatchPoint); + if (line != null && !check_animation(p, line)) + return; + + AnimatePanel af = gxInstance.getAnimateDialog(); + if (line != null) { + clearSelection(); + animate = new AnimateC(p, line, this.Width, this.Height); + af.setAttribute(animate); + gxInstance.showAnimatePane(); + this.SetCurrentAction(MOVE); + } else { + Circle c = this.SmartPCircle(CatchPoint); + if (c != null) { + clearSelection(); + animate = new AnimateC(p, c, this.Width, this.Height); + af.setAttribute(animate); + gxInstance.showAnimatePane(); + this.SetCurrentAction(MOVE); + } else { + CTrace ct = (CTrace) this.SelectFromAList(tracelist, x, y); + if (ct != null) { + clearSelection(); + animate = new AnimateC(p, ct, this.Width, this.Height); + af.setAttribute(animate); + gxInstance.showAnimatePane(); + this.SetCurrentAction(MOVE); } } - break; + } - case SETEQANGLE: { - if (SelectList.size() == 0) { - CAngle ag = CatchAngle(x, y); - if (ag != null) { - addToSelectList(ag); - } - } else if (SelectList.size() == 1) { - CAngle ag = CatchAngle(x, y); - CAngle ag1 = (CAngle) SelectList.get(0); + } - if (ag == ag1) { - clearSelection(); - break; - } + /** + * Handles the direct angle creation case. + * Based on the selection status, sets up an angle using a temporary point and/or a previously selected line. + * + * @param x the x-coordinate for angle creation. + * @param y the y-coordinate for angle creation. + */ + private void handleDAngleCase(double x, double y) { - if (ag != null && ag != ag1) { - CPoint pd = CAngle.canEqual(ag, ag1); - if (pd == null) { - CMisc.print("the angle is decided,can not be set equal"); - clearSelection(); - } else { - clearSelection(); - Constraint cs = new Constraint(Constraint.EQANGLE, ag1, ag); - this.addConstraintToList(cs); - this.charsetAndAddPoly(false); -// this.mulSolutionSelect(pd); -// this.reCalculate(); - this.UndoAdded(ag.getDescription() + " = " + - ag1.getDescription()); - } - } + if (STATUS == 0 && SelectList.isEmpty()) { + FirstPnt = this.CreateATempPoint(x, y); + + CLine line = SmartPLine(FirstPnt); + if (line != null) { + addToSelectList(line); + } + } else if (STATUS == 0 && SelectList.size() == 1) { + SecondPnt = this.CreateATempPoint(x, y); + CLine line = SmartPLine(SecondPnt); + if (line != null) { + CLine l2 = (CLine) SelectList.get(0); + if (line == l2) { + return; } + CAngle ag = new CAngle(l2, line, FirstPnt, SecondPnt); + addAngleToList(ag); + ag.move(x, y); + clearSelection(); + addToSelectList(ag); + STATUS = 1; + this.UndoAdded(ag.getDescription(), false, false); } - break; + } else if (STATUS == 1) { + STATUS = 0; + clearSelection(); + } + } - case SETEQANGLE3P: { - CAngle ag = (CAngle) this.SelectFromAList(anglelist, x, y); - if (ag == null) { - break; - } - if (SelectList.size() == 2) { - CAngle ag1 = (CAngle) SelectList.get(0); - CAngle ag2 = (CAngle) SelectList.get(1); + /** + * Handles the equal side setting case. + * Adds a constraint to set equal distances between points or sides based on the selection. + * + * @param x the x-coordinate used for setting equal sides. + * @param y the y-coordinate used for setting equal sides. + * @param p a temporary point involved in the constraint process. + */ + private void handleSetEqSideCase(double x, double y, CPoint p) { + CPoint pt = (CPoint) this.CatchList(pointlist, x, y); + if (pt == null) { + clearSelection(); + return; + } + if (SelectList.size() == 3) { + CPoint pt1 = (CPoint) SelectList.get(0); + CPoint pt2 = (CPoint) SelectList.get(1); + CPoint pt3 = (CPoint) SelectList.get(2); + if (STATUS == 1) { + Constraint cs = new Constraint(Constraint.EQDISTANCE, pt1, pt2, pt3, pt); + this.addConstraintToList(cs); + this.charsetAndAddPoly(false); + clearSelection(); + this.UndoAdded(pt1.m_name + pt2.m_name + " = " + pt3.m_name + + pt.m_name); + } else { + Constraint cs = new Constraint(Constraint.NRATIO, pt1, pt2, pt3, pt, v1, v2); + this.addConstraintToList(cs); + this.charsetAndAddPoly(false); + clearSelection(); + this.UndoAdded(pt1.m_name + pt2.m_name + " = " + STATUS + + " " + pt3.m_name + pt.m_name); - Vector alist = this.getSpecificAngleList(); - SpecificAngleDialog dlg = new SpecificAngleDialog(gxInstance, 2, alist); - dlg.setLocation(400, 400); - dlg.setTitle("Please select an specific angle"); - dlg.setVisible(true); + } + } else { + addToSelectList(pt); + } + } - Vector v = dlg.getSpecificAngle(); - if (v.size() == 1) { - Integer in = (Integer) v.get(0); - int va = in.intValue(); - Param pm = this.getParaForSpecificAngle(va); + /** + * Handles the equal angle setting case. + * Compares a selected angle with another angle determined from the coordinates and sets them equal if possible. + * + * @param x the x-coordinate used for setting equal angle. + * @param y the y-coordinate used for setting equal angle. + * @param p a temporary point or indicator used during the process. + */ + private void handleSetEqAngleCase(double x, double y, CPoint p) { + if (SelectList.isEmpty()) { + CAngle ag = CatchAngle(x, y); + if (ag != null) { + addToSelectList(ag); + } + } else if (SelectList.size() == 1) { + CAngle ag = CatchAngle(x, y); + CAngle ag1 = (CAngle) SelectList.get(0); - Constraint cs = new Constraint(Constraint.EQANGLE3P, ag1, ag2, ag, pm, va); - this.addConstraintToList(cs); - this.charsetAndAddPoly(false); - clearSelection(); - this.UndoAdded(ag1.getDescription() + " + " + - ag2.getDescription() + " + " + - ag.getDescription() + " = " + - ag.getDescription()); - } else { - clearSelection(); - break; - } - } else { - addToSelectList(ag); - } + if (ag == ag1) { + clearSelection(); + return; } - break; - case SETCCTANGENT: { - Circle c = (Circle) this.SelectFromAList(circlelist, x, y); - if (c == null) { - break; - } - if (SelectList.size() == 1) { - Circle c0 = (Circle) SelectList.get(0); - Constraint cs = new Constraint(Constraint.CCTANGENT, c0, c); - this.charsetAndAddPoly(false); - this.addConstraintToList(cs); - this.UndoAdded(c0.getDescription() + " tangent to " + - c.getDescription()); + + if (ag != null) { + CPoint pd = CAngle.canEqual(ag, ag1); + if (pd == null) { + CMisc.print("the angle is decided,can not be set equal"); + clearSelection(); } else { - addToSelectList(c); + clearSelection(); + Constraint cs = new Constraint(Constraint.EQANGLE, ag1, ag); + this.addConstraintToList(cs); + this.charsetAndAddPoly(false); +// this.mulSolutionSelect(pd); +// this.reCalculate(); + this.UndoAdded(ag.getDescription() + " = " + + ag1.getDescription()); } } - break; - case D_SQUARE: { - if (STATUS == 0) { - CPoint pt = this.SmartPoint(CatchPoint); - if (pt == null) { - if (SelectList.size() == 0) { - CLine line = this.SmartPLine(CatchPoint); - if (line != null) { - addToSelectList(line); - STATUS = 1; - break; - } - } - pt = this.SmartgetApointFromXY(x, y); - } + } - if (SelectList.size() == 1) { - CPoint pa = (CPoint) SelectList.get(0); - this.setSmartPVLine(pa, pt); - } - if (!SelectList.contains(pt)) { - addToSelectList(pt); - } - if (SelectList.size() == 2) { - STATUS = 2; - } - } else if (STATUS == 2) { - CPoint p1 = (CPoint) SelectList.get(0); - CPoint p2 = (CPoint) SelectList.get(1); - addsquare(p1, p2, CatchPoint); - clearSelection(); - STATUS = 0; + } - } + /** + * Handles the equal angle constraint for three points. + * After selecting two angles, prompts for a specific angle parameter and applies a constraint to equalize them. + * + * @param x the x-coordinate for angle selection. + * @param y the y-coordinate for angle selection. + * @param p a temporary point used during the constraint process. + */ + private void handleSetEqAngle3PCase(double x, double y, CPoint p) { + CAngle ag = (CAngle) this.SelectFromAList(anglelist, x, y); + if (ag == null) { + return; + } + if (SelectList.size() == 2) { + CAngle ag1 = (CAngle) SelectList.get(0); + CAngle ag2 = (CAngle) SelectList.get(1); + + Vector alist = this.getSpecificAngleList(); + SpecificAngleDialog dlg = new SpecificAngleDialog(gxInstance, 2, alist); + dlg.setLocation(400, 400); + dlg.setTitle("Please select an specific angle"); + dlg.setVisible(true); + + Vector v = dlg.getSpecificAngle(); + if (v.size() == 1) { + Integer in = (Integer) v.get(0); + int va = in.intValue(); + Param pm = this.getParaForSpecificAngle(va); + + Constraint cs = new Constraint(Constraint.EQANGLE3P, ag1, ag2, ag, pm, va); + this.addConstraintToList(cs); + this.charsetAndAddPoly(false); + clearSelection(); + this.UndoAdded(ag1.getDescription() + " + " + + ag2.getDescription() + " + " + + ag.getDescription() + " = " + + ag.getDescription()); + } else { + clearSelection(); } - break; - case D_CCLINE: { - if (SelectList.size() == 0) { - Circle c = this.SmartPCircle(CatchPoint); - if (c != null) { - this.addObjectToList(c, SelectList); - } - } else if (SelectList.size() == 1) { - Circle c = this.SmartPCircle(CatchPoint); - if (c != null) { - Circle c0 = (Circle) SelectList.get(0); - if (c0.o == c.o) { - clearSelection(); - break; - } + } else { + addToSelectList(ag); + } + } - CLine line = new CLine(CLine.CCLine); - this.addLineToList(line); + /** + * Handles the circle-to-circle tangent constraint case. + * When one circle is already selected, selects another circle to set a tangent constraint between them. + * + * @param x the x-coordinate used for tangent detection. + * @param y the y-coordinate used for tangent detection. + * @param p a temporary point used during the process. + */ + private void handleSetCCTangentCase(double x, double y, CPoint p) { + Circle c = (Circle) this.SelectFromAList(circlelist, x, y); + if (c == null) { + return; + } + if (SelectList.size() == 1) { + Circle c0 = (Circle) SelectList.get(0); + Constraint cs = new Constraint(Constraint.CCTANGENT, c0, c); + this.charsetAndAddPoly(false); + this.addConstraintToList(cs); + this.UndoAdded(c0.getDescription() + " tangent to " + + c.getDescription()); + } else { + addToSelectList(c); + } + } - Constraint cs = new Constraint(Constraint.CCLine, line, c0, - c); - this.addConstraintToList(cs); - line.addconstraint(cs); - clearSelection(); - this.UndoAdded(line.TypeString() + ": " + GExpert.getTranslationViaGettext( - "Radical of {0} and {1}",c0.getDescription(), c.getDescription())); + /** + * Handles the square construction case. + * Determines two points for the construction of a square and invokes square creation logic. + * + * @param x the x-coordinate used for square construction. + * @param y the y-coordinate used for square construction. + */ + private void handleDSquareCase(double x, double y) { + if (STATUS == 0) { + CPoint pt = this.SmartPoint(CatchPoint); + if (pt == null) { + if (SelectList.isEmpty()) { + CLine line = this.SmartPLine(CatchPoint); + if (line != null) { + addToSelectList(line); + STATUS = 1; + return; } } + pt = this.SmartgetApointFromXY(x, y); + } + if (SelectList.size() == 1) { + CPoint pa = (CPoint) SelectList.get(0); + this.setSmartPVLine(pa, pt); } - break; - case D_IOSTRI: { - if (SelectList.size() < 2) { - CPoint pt = SmartgetApointFromXY(x, y); - if (SelectList.size() == 1) { - CPoint pa = (CPoint) SelectList.get(0); - setSmartPVLine(pa, pt); - } - if (SelectList.size() == 0) { - addToSelectList(pt); - } else if (pt == SelectList.get(0)) { - clearSelection(); - } else { - addToSelectList(pt); - } - } else { - CPoint p1 = (CPoint) SelectList.get(0); - CPoint p2 = (CPoint) SelectList.get(1); - addisoAngle(p1, p2, CatchPoint, 0); - clearSelection(); - STATUS = 0; - } + if (!SelectList.contains(pt)) { + addToSelectList(pt); } - break; - case DRAWTRIALL: { - if (STATUS == 0) { - CPoint pt = this.SmartgetApointFromXY(x, y); - addToSelectList(pt); - STATUS = 1; - } else if (STATUS == 1) { - CPoint pt = this.SmartgetApointFromXY(x, y); - if (pt == SelectList.get(0)) { - STATUS = 0; - clearSelection(); - break; - } - if (SelectList.size() == 1) { - CPoint pa = (CPoint) SelectList.get(0); - this.setSmartPVLine(pa, pt); - } - CPoint p1 = (CPoint) SelectList.get(0); - addToSelectList(pt); - if (fd_line(p1, pt) == null) { - CLine line = new CLine(p1, pt, CLine.LLine); - this.addLineToList(line); - } - STATUS = 2; - } else { - CPoint p1 = (CPoint) SelectList.get(0); - CPoint p2 = (CPoint) SelectList.get(1); - CPoint pt = CreateANewPoint(x, y); + if (SelectList.size() == 2) { + STATUS = 2; + } + } else if (STATUS == 2) { + CPoint p1 = (CPoint) SelectList.get(0); + CPoint p2 = (CPoint) SelectList.get(1); + addsquare(p1, p2, CatchPoint); + clearSelection(); + STATUS = 0; - Constraint cs = new Constraint(Constraint.PETRIANGLE, pt, p1, p2); - CPoint pu = this.addADecidedPointWithUnite(pt); - if (pu == null) { - addConstraintToList(cs); - addPointToList(pt); - } else { - pt = pu; - } - addALine(CLine.LLine, pt, p1); - addALine(CLine.LLine, pt, p2); + } + } + + /** + * Handles the circle-circle line (radical axis) construction case. + * Selects two circles based on the provided coordinates and creates a line representing their radical axis. + * + * @param x the x-coordinate used for circle selection. + * @param y the y-coordinate used for circle selection. + */ + private void handleDCCLineCase(double x, double y) { + if (SelectList.isEmpty()) { + Circle c = this.SmartPCircle(CatchPoint); + if (c != null) { + this.addObjectToList(c, SelectList); + } + } else if (SelectList.size() == 1) { + Circle c = this.SmartPCircle(CatchPoint); + if (c != null) { + Circle c0 = (Circle) SelectList.get(0); + if (c0.o == c.o) { clearSelection(); - STATUS = 0; - // FIXME: use a translation key for triangle and substitute the image later for all translations - UndoAdded(GExpert.getLanguage("Equilateral") + " triangle " + pt.m_name + p1.m_name + p2.m_name); + return; } + + CLine line = new CLine(CLine.CCLine); + this.addLineToList(line); + + Constraint cs = new Constraint(Constraint.CCLine, line, c0, + c); + this.addConstraintToList(cs); + line.addconstraint(cs); + clearSelection(); + this.UndoAdded(line.TypeString() + ": " + GExpert.getTranslationViaGettext( + "Radical of {0} and {1}", c0.getDescription(), c.getDescription())); } - break; - case RA_TRAPEZOID: { - if (STATUS == 0) { - CPoint pt = this.SmartgetApointFromXY(x, y); + } - if (SelectList.size() > 0) { - CPoint pa = (CPoint) SelectList.get(SelectList.size() - 1); - this.setSmartPVLine(pa, pt); - } + } - if (!SelectList.contains(pt)) { - addToSelectList(pt); - } - if (SelectList.size() == 2) { - STATUS = 1; - } - } else { - CPoint p1 = (CPoint) SelectList.get(0); - CPoint p2 = (CPoint) SelectList.get(1); - CPoint p3 = this.SmartgetApointFromXY(x, y); - CPoint p4 = this.CreateANewPoint(x, y); - Constraint cs = new Constraint(Constraint.RIGHT_ANGLE_TRAPEZOID, p1, p2, p3, p4); - CPoint pu = this.addADecidedPointWithUnite(p4); - if (pu == null) { - this.addALine(CLine.LLine, p1, p2); - this.addALine(CLine.LLine, p2, p3); - this.addALine(CLine.LLine, p3, p4); - this.addALine(CLine.LLine, p1, p4); - this.addPointToList(p4); - this.addConstraintToList(cs); - this.charsetAndAddPoly(false); - } else - p4 = pu; - // FIXME: use better keys - this.UndoAdded(GExpert.getLanguage("Right") + " trapezoid " + p1.m_name + p2.m_name + p3.m_name + p4.m_name); - STATUS = 0; - clearSelection(); - } + /** + * Handles drawing of an isosceles triangle based on the current selection. + * + * @param x the x-coordinate of the user input + * @param y the y-coordinate of the user input + */ + private void handleDIOSTriCase(double x, double y) { + if (SelectList.size() < 2) { + CPoint pt = SmartgetApointFromXY(x, y); + if (SelectList.size() == 1) { + CPoint pa = (CPoint) SelectList.get(0); + setSmartPVLine(pa, pt); + } + if (SelectList.isEmpty()) { + addToSelectList(pt); + } else if (pt == SelectList.get(0)) { + clearSelection(); + } else { + addToSelectList(pt); } - break; - case TRAPEZOID: { - if (STATUS == 0) { - CPoint pt = this.SmartgetApointFromXY(x, y); - if (SelectList.size() > 0) { - CPoint pa = (CPoint) SelectList.get(SelectList.size() - 1); - this.setSmartPVLine(pa, pt); - } - if (!SelectList.contains(pt)) { - addToSelectList(pt); - } else { - break; - } - if (SelectList.size() == 3) { - STATUS = 1; - } - } else { - CPoint p1 = (CPoint) SelectList.get(0); - CPoint p2 = (CPoint) SelectList.get(1); - CPoint p3 = (CPoint) SelectList.get(2); - x = CatchPoint.getx(); - y = (p1.gety() - p2.gety()) * (x - p3.getx()) / - (p1.getx() - p3.getx()) + p3.gety(); - // y = (p1.gety() - p2.gety()) * (x - p3.getx()) / (p1.getx() - p2.getx()) + p3.gety(); - CPoint p4 = this.SmartgetApointFromXY(x, y); - Constraint cs1 = new Constraint(Constraint.TRAPEZOID, p1, p2, p3, p4); - CPoint pu = this.addADecidedPointWithUnite(p4); - p4.setXY(x, y); - if (pu == null) { - this.addALine(CLine.LLine, p1, p2); - this.addALine(CLine.LLine, p2, p3); - this.addALine(CLine.LLine, p3, p4); - this.addALine(CLine.LLine, p1, p4); - this.addPointToList(p4); - this.addConstraintToList(cs1); - this.charsetAndAddPoly(false); - } else - p4 = pu; - this.reCalculate(); - this.UndoAdded("trapezoid " + p1.m_name + p2.m_name + p3.m_name + p4.m_name); - STATUS = 0; - clearSelection(); + } else { + CPoint p1 = (CPoint) SelectList.get(0); + CPoint p2 = (CPoint) SelectList.get(1); + addisoAngle(p1, p2, CatchPoint, 0); + clearSelection(); + STATUS = 0; + } + } - } + /** + * Handles drawing of an equilateral triangle in three user interaction steps. + * + * @param x the x-coordinate of the user input + * @param y the y-coordinate of the user input + */ + private void handleDrawTriAllCase(double x, double y) { + if (STATUS == 0) { + CPoint pt = this.SmartgetApointFromXY(x, y); + addToSelectList(pt); + STATUS = 1; + } else if (STATUS == 1) { + CPoint pt = this.SmartgetApointFromXY(x, y); + if (pt == SelectList.get(0)) { + STATUS = 0; + clearSelection(); + return; + } + if (SelectList.size() == 1) { + CPoint pa = (CPoint) SelectList.get(0); + this.setSmartPVLine(pa, pt); + } + CPoint p1 = (CPoint) SelectList.get(0); + addToSelectList(pt); + if (fd_line(p1, pt) == null) { + CLine line = new CLine(p1, pt, CLine.LLine); + this.addLineToList(line); + } + STATUS = 2; + } else { + CPoint p1 = (CPoint) SelectList.get(0); + CPoint p2 = (CPoint) SelectList.get(1); + CPoint pt = CreateANewPoint(x, y); + Constraint cs = new Constraint(Constraint.PETRIANGLE, pt, p1, p2); + CPoint pu = this.addADecidedPointWithUnite(pt); + if (pu == null) { + addConstraintToList(cs); + addPointToList(pt); + } else { + pt = pu; } - break; - case PARALLELOGRAM: { - if (STATUS == 0) { - CPoint pt = this.SmartgetApointFromXY(x, y); - addToSelectList(pt); - STATUS = 1; - } else if (STATUS == 1) { - CPoint pt = this.SmartgetApointFromXY(x, y); - if (pt == SelectList.get(0)) { - STATUS = 0; - clearSelection(); - break; - } - if (SelectList.size() == 1) { - CPoint pa = (CPoint) SelectList.get(0); - this.setSmartPVLine(pa, pt); - } - addToSelectList(pt); - STATUS = 2; - } else { - CPoint p1 = (CPoint) SelectList.get(0); - CPoint p2 = (CPoint) SelectList.get(1); - CPoint p3 = this.SmartgetApointFromXY(x, y); - CPoint p4 = this.CreateANewPoint(x, y); - Constraint cs = new Constraint(Constraint.PARALLELOGRAM, p1, p2, p3, p4); - CPoint pu = this.addADecidedPointWithUnite(p4); - if (pu == null) { - this.addPointToList(p4); - addALine(CLine.LLine, p1, p2); - addALine(CLine.LLine, p1, p4); - addALine(CLine.LLine, p2, p3); - addALine(CLine.LLine, p3, p4); - this.addConstraintToList(cs); - this.charsetAndAddPoly(false); - } else - p4 = pu; - this.UndoAdded("parallelogram " + p1.m_name + p2.m_name + p3.m_name + p4.m_name); - STATUS = 0; - clearSelection(); - } + addALine(CLine.LLine, pt, p1); + addALine(CLine.LLine, pt, p2); + clearSelection(); + STATUS = 0; + // FIXME: use a translation key for triangle and substitute the image later for all translations + UndoAdded(GExpert.getLanguage("Equilateral") + " triangle " + pt.m_name + p1.m_name + p2.m_name); + } + } + /** + * Handles drawing of a right-angled trapezoid by capturing two points and a new transient point. + * + * @param x the x-coordinate of the user input + * @param y the y-coordinate of the user input + */ + private void handleRATrapezoidCase(double x, double y) { + if (STATUS == 0) { + CPoint pt = this.SmartgetApointFromXY(x, y); + + if (!SelectList.isEmpty()) { + CPoint pa = (CPoint) SelectList.get(SelectList.size() - 1); + this.setSmartPVLine(pa, pt); } - break; - case RECTANGLE: { - if (STATUS == 0) { - CPoint pt = this.SmartgetApointFromXY(x, y); - addToSelectList(pt); - STATUS = 1; - } else if (STATUS == 1) { - CPoint pt = this.SmartgetApointFromXY(x, y); - if (pt == SelectList.get(0)) { - STATUS = 0; - clearSelection(); - break; - } - if (SelectList.size() == 1) { - CPoint pa = (CPoint) SelectList.get(0); - this.setSmartPVLine(pa, pt); - } - addToSelectList(pt); - STATUS = 2; - } else { - CPoint p1 = (CPoint) SelectList.get(0); - CPoint p2 = (CPoint) SelectList.get(1); + if (!SelectList.contains(pt)) { + addToSelectList(pt); + } + if (SelectList.size() == 2) { + STATUS = 1; + } + } else { + CPoint p1 = (CPoint) SelectList.get(0); + CPoint p2 = (CPoint) SelectList.get(1); + CPoint p3 = this.SmartgetApointFromXY(x, y); + CPoint p4 = this.CreateANewPoint(x, y); + Constraint cs = new Constraint(Constraint.RIGHT_ANGLE_TRAPEZOID, p1, p2, p3, p4); + CPoint pu = this.addADecidedPointWithUnite(p4); + if (pu == null) { + this.addALine(CLine.LLine, p1, p2); + this.addALine(CLine.LLine, p2, p3); + this.addALine(CLine.LLine, p3, p4); + this.addALine(CLine.LLine, p1, p4); + this.addPointToList(p4); + this.addConstraintToList(cs); + this.charsetAndAddPoly(false); + } else + p4 = pu; + // FIXME: use better keys + this.UndoAdded(GExpert.getLanguage("Right") + " trapezoid " + p1.m_name + p2.m_name + p3.m_name + p4.m_name); + STATUS = 0; + clearSelection(); + } + } - double x1 = p1.getx(); - double y1 = p1.gety(); - double x2 = p2.getx(); - double y2 = p2.gety(); + /** + * Handles drawing of a trapezoid by computing a fourth point via coordinate calculations. + * + * @param x the x-coordinate from the current catch point + * @param y the y-coordinate computed based on the selected points + */ + private void handleTrapezoide(double x, double y) { + if (STATUS == 0) { + CPoint pt = this.SmartgetApointFromXY(x, y); + if (!SelectList.isEmpty()) { + CPoint pa = (CPoint) SelectList.get(SelectList.size() - 1); + this.setSmartPVLine(pa, pt); + } + if (!SelectList.contains(pt)) { + addToSelectList(pt); + } else { + return; + } + if (SelectList.size() == 3) { + STATUS = 1; + } + } else { + CPoint p1 = (CPoint) SelectList.get(0); + CPoint p2 = (CPoint) SelectList.get(1); + CPoint p3 = (CPoint) SelectList.get(2); + x = CatchPoint.getx(); + y = (p1.gety() - p2.gety()) * (x - p3.getx()) / + (p1.getx() - p3.getx()) + p3.gety(); + // y = (p1.gety() - p2.gety()) * (x - p3.getx()) / (p1.getx() - p2.getx()) + p3.gety(); + CPoint p4 = this.SmartgetApointFromXY(x, y); + Constraint cs1 = new Constraint(Constraint.TRAPEZOID, p1, p2, p3, p4); + CPoint pu = this.addADecidedPointWithUnite(p4); + p4.setXY(x, y); + if (pu == null) { + this.addALine(CLine.LLine, p1, p2); + this.addALine(CLine.LLine, p2, p3); + this.addALine(CLine.LLine, p3, p4); + this.addALine(CLine.LLine, p1, p4); + this.addPointToList(p4); + this.addConstraintToList(cs1); + this.charsetAndAddPoly(false); + } else + p4 = pu; + this.reCalculate(); + this.UndoAdded("trapezoid " + p1.m_name + p2.m_name + p3.m_name + p4.m_name); + STATUS = 0; + clearSelection(); - double xc = CatchPoint.getx(); - double yc = CatchPoint.gety(); + } + } - double dlx = x2 - x1; - double dly = y2 - y1; - double dl = dlx * dlx + dly * dly; + /** + * Handles drawing of a parallelogram by collecting points and creating the missing vertex. + * + * @param x the x-coordinate of the user input + * @param y the y-coordinate of the user input + */ + private void handleParallelogram(double x, double y) { + if (STATUS == 0) { + CPoint pt = this.SmartgetApointFromXY(x, y); + addToSelectList(pt); + STATUS = 1; + } else if (STATUS == 1) { + CPoint pt = this.SmartgetApointFromXY(x, y); + if (pt == SelectList.get(0)) { + STATUS = 0; + clearSelection(); + return; + } + if (SelectList.size() == 1) { + CPoint pa = (CPoint) SelectList.get(0); + this.setSmartPVLine(pa, pt); + } + addToSelectList(pt); + STATUS = 2; + } else { + CPoint p1 = (CPoint) SelectList.get(0); + CPoint p2 = (CPoint) SelectList.get(1); + CPoint p3 = this.SmartgetApointFromXY(x, y); + CPoint p4 = this.CreateANewPoint(x, y); + Constraint cs = new Constraint(Constraint.PARALLELOGRAM, p1, p2, p3, p4); + CPoint pu = this.addADecidedPointWithUnite(p4); + if (pu == null) { + this.addPointToList(p4); + addALine(CLine.LLine, p1, p2); + addALine(CLine.LLine, p1, p4); + addALine(CLine.LLine, p2, p3); + addALine(CLine.LLine, p3, p4); + this.addConstraintToList(cs); + this.charsetAndAddPoly(false); + } else + p4 = pu; + this.UndoAdded("parallelogram " + p1.m_name + p2.m_name + p3.m_name + p4.m_name); + STATUS = 0; + clearSelection(); + } - double xx = ((y2 - yc) * dlx * dly + dly * dly * xc + - dlx * dlx * x2) / dl; - double yy = ((x2 - xc) * dlx * dly + dlx * dlx * yc + - dly * dly * y2) / dl; + } - CPoint p3 = this.SmartgetApointFromXY(xx, yy); - double xt = x + p1.getx() - p2.getx(); - double yt = y + p1.gety() - p2.gety(); - CPoint p4 = this.CreateANewPoint(xt, yt); - Constraint cs1 = new Constraint(Constraint.RECTANGLE, p1, p2, p3, p4); - CPoint pu = this.addADecidedPointWithUnite(p4); - if (pu == null) { - this.addPointToList(p4); - CLine tl1 = addALine(CLine.LLine, p1, p2); - CLine tl2 = addALine(CLine.LLine, p1, p4); - addALine(CLine.LLine, p2, p3); - addALine(CLine.LLine, p3, p4); - addCTMark(tl1, tl2); - this.addConstraintToList(cs1); - this.charsetAndAddPoly(false); - } else - p4 = pu; - this.UndoAdded("rectangle " + p1.m_name + p2.m_name + p3.m_name + p4.m_name); - STATUS = 0; + /** + * Handles drawing of a rectangle by using two selected points to compute the remaining vertices. + * + * @param x the x-coordinate of the user input + * @param y the y-coordinate of the user input + */ + private void handleRectangle(double x, double y) { + if (STATUS == 0) { + CPoint pt = this.SmartgetApointFromXY(x, y); + + addToSelectList(pt); + STATUS = 1; + } else if (STATUS == 1) { + CPoint pt = this.SmartgetApointFromXY(x, y); + if (pt == SelectList.get(0)) { + STATUS = 0; + clearSelection(); + return; + } + if (SelectList.size() == 1) { + CPoint pa = (CPoint) SelectList.get(0); + this.setSmartPVLine(pa, pt); + } + addToSelectList(pt); + STATUS = 2; + } else { + CPoint p1 = (CPoint) SelectList.get(0); + CPoint p2 = (CPoint) SelectList.get(1); + + double x1 = p1.getx(); + double y1 = p1.gety(); + double x2 = p2.getx(); + double y2 = p2.gety(); + + double xc = CatchPoint.getx(); + double yc = CatchPoint.gety(); + + double dlx = x2 - x1; + double dly = y2 - y1; + double dl = dlx * dlx + dly * dly; + + double xx = ((y2 - yc) * dlx * dly + dly * dly * xc + + dlx * dlx * x2) / dl; + double yy = ((x2 - xc) * dlx * dly + dlx * dlx * yc + + dly * dly * y2) / dl; + + CPoint p3 = this.SmartgetApointFromXY(xx, yy); + double xt = x + p1.getx() - p2.getx(); + double yt = y + p1.gety() - p2.gety(); + CPoint p4 = this.CreateANewPoint(xt, yt); + Constraint cs1 = new Constraint(Constraint.RECTANGLE, p1, p2, p3, p4); + CPoint pu = this.addADecidedPointWithUnite(p4); + if (pu == null) { + this.addPointToList(p4); + CLine tl1 = addALine(CLine.LLine, p1, p2); + CLine tl2 = addALine(CLine.LLine, p1, p4); + addALine(CLine.LLine, p2, p3); + addALine(CLine.LLine, p3, p4); + addCTMark(tl1, tl2); + this.addConstraintToList(cs1); + this.charsetAndAddPoly(false); + } else + p4 = pu; + this.UndoAdded("rectangle " + p1.m_name + p2.m_name + p3.m_name + p4.m_name); + STATUS = 0; + clearSelection(); + + } + } + + /** + * Handles drawing of an isosceles right triangle by capturing base points and computing the apex. + * + * @param x the x-coordinate of the user input + * @param y the y-coordinate of the user input + */ + private void handleDrawTriSqIsoCase(double x, double y) { + if (STATUS == 0) { + CPoint pt = this.SmartgetApointFromXY(x, y); + addToSelectList(pt); + STATUS = 1; + } else if (STATUS == 1) { + CPoint pt = this.SmartgetApointFromXY(x, y); + if (pt == SelectList.get(0)) { + STATUS = 0; + clearSelection(); + return; + } + CPoint p1 = (CPoint) SelectList.get(0); + addALine(CLine.LLine, p1, pt); + addToSelectList(pt); + STATUS = 2; + } else { + CPoint p1 = (CPoint) SelectList.get(0); + CPoint p2 = (CPoint) SelectList.get(1); + CPoint pt = this.CreateANewPoint(x, y); + CLine ln1 = new CLine(pt, p1, CLine.LLine); + CLine ln2 = new CLine(pt, p2, CLine.LLine); + Constraint cs = new Constraint(Constraint.PERPBISECT, pt, p1, p2); + Constraint cs1 = new Constraint(Constraint.PERPENDICULAR, ln1, ln2); + CPoint pu = this.addADecidedPointWithUnite(pt); + if (pu == null) { + this.addPointToList(pt); + this.charsetAndAddPoly(false); + this.addConstraintToList(cs1); + this.addConstraintToList(cs); + this.addLineToList(ln1); + this.addLineToList(ln2); + } + + clearSelection(); + STATUS = 0; + this.UndoAdded("isoceles-right triangle " + pt.m_name + p1.m_name + p2.m_name); + } + } + + /** + * Handles definition of a polygon by either selecting a circle or accumulating points from user input. + * + * @param x the x-coordinate of the user input + * @param y the y-coordinate of the user input + * @param p a reference point used in the polygon definition process + */ + private void handleDefinePolyCase(double x, double y, CPoint p) { + if (this.SelectAPoint(x, y) == null && SelectList.isEmpty()) { + Circle c = SelectACircle(x, y); + if (c != null) { + for (Object o : polygonlist) { + CPolygon px = (CPolygon) o; + if (px.isEqual(c)) break; + } + if (this.fd_polygon(c) == null) { + CPolygon px = new CPolygon(c); + this.addPolygonToList(px); clearSelection(); - + this.UndoAdded(px.getDescription()); } } - break; - case DRAWTRISQISO: { + } else { + FirstPnt = this.CreateATempPoint(x, y); + p = this.SmartPoint(FirstPnt); + if (p != null) { if (STATUS == 0) { - CPoint pt = this.SmartgetApointFromXY(x, y); - addToSelectList(pt); + CPolygon cp = new CPolygon(); + cp.addAPoint(p); + addToSelectList(cp); STATUS = 1; - } else if (STATUS == 1) { - CPoint pt = this.SmartgetApointFromXY(x, y); - if (pt == SelectList.get(0)) { + } else { + CPolygon cp = (CPolygon) SelectList.get(0); + if (cp.addAPoint(p)) { STATUS = 0; + addPolygonToList(cp); clearSelection(); - break; - } - CPoint p1 = (CPoint) SelectList.get(0); - addALine(CLine.LLine, p1, pt); - addToSelectList(pt); - STATUS = 2; - } else { - CPoint p1 = (CPoint) SelectList.get(0); - CPoint p2 = (CPoint) SelectList.get(1); - CPoint pt = this.CreateANewPoint(x, y); - CLine ln1 = new CLine(pt, p1, CLine.LLine); - CLine ln2 = new CLine(pt, p2, CLine.LLine); - Constraint cs = new Constraint(Constraint.PERPBISECT, pt, p1, p2); - Constraint cs1 = new Constraint(Constraint.PERPENDICULAR, ln1, ln2); - CPoint pu = this.addADecidedPointWithUnite(pt); - if (pu == null) { - this.addPointToList(pt); - this.charsetAndAddPoly(false); - this.addConstraintToList(cs1); - this.addConstraintToList(cs); - this.addLineToList(ln1); - this.addLineToList(ln2); + this.UndoAdded(cp.getDescription()); } - - clearSelection(); - STATUS = 0; - this.UndoAdded("isoceles-right triangle " + pt.m_name + p1.m_name + p2.m_name); } } - break; + } + } - case DEFINEPOLY: { + /** + * Handles text editing by showing a dialog for a selected text object. + * + * @param x the x-coordinate of the user input + * @param y the y-coordinate of the user input + */ + private void handleDTextCase(double x, double y) { + CText tc = (CText) this.SelectFromAList(textlist, x, y); + dialog_addText(tc, (int) x, (int) y); + } - if (this.SelectAPoint(x, y) == null && SelectList.size() == 0) { - Circle c = SelectACircle(x, y); - if (c != null) { - for (int i = 0; i < polygonlist.size(); i++) { - CPolygon px = (CPolygon) polygonlist.get(i); - if (px.isEqual(c)) break; - } - if (this.fd_polygon(c) == null) { - CPolygon px = new CPolygon(c); - this.addPolygonToList(px); - clearSelection(); - this.UndoAdded(px.getDescription()); - } - break; - } - } else { - FirstPnt = this.CreateATempPoint(x, y); - p = this.SmartPoint(FirstPnt); - if (p != null) { - if (STATUS == 0) { - CPolygon cp = new CPolygon(); - cp.addAPoint(p); - addToSelectList(cp); - STATUS = 1; - } else { - CPolygon cp = (CPolygon) SelectList.get(0); - if (cp.addAPoint(p)) { - STATUS = 0; - addPolygonToList(cp); - clearSelection(); - this.UndoAdded(cp.getDescription()); - } - } - } - } - } - break; - case D_TEXT: { - CText tc = (CText) this.SelectFromAList(textlist, x, y); - dialog_addText(tc, (int) x, (int) y); - } - break; - case MULSELECTSOLUTION: { - for (int i = 0; i < solutionlist.size(); i++) { - p = (CPoint) solutionlist.get(i); - if (Math.pow(p.getx() - x, 2) + Math.pow(p.gety() - y, 2) < 18 * 18) { - pSolution.setXY(p.getx(), p.gety()); - solutionlist.clear(); - pSolution = null; - SetCurrentAction(PreviousAction); - } - } + /** + * Handles multiple solution selection by checking proximity of solution points to the user input. + * + * @param x the x-coordinate of the user input + * @param y the y-coordinate of the user input + * @param p a reference point used for comparison + */ + private void handleMulSelectSolutionCase(double x, double y, CPoint p) { + for (int i = 0; i < solutionlist.size(); i++) { + p = (CPoint) solutionlist.get(i); + if (Math.pow(p.getx() - x, 2) + Math.pow(p.gety() - y, 2) < 18 * 18) { + pSolution.setXY(p.getx(), p.gety()); + solutionlist.clear(); + pSolution = null; + SetCurrentAction(PreviousAction); } - break; + } + } - case SETTRACK: { - CTrackPt = this.SelectAPoint(x, y); - boolean r = false; + /** + * Handles setting a track point and adds a trace if the point is not already traced. + * + * @param x the x-coordinate of the user input + * @param y the y-coordinate of the user input + */ + private void handleSetTrackCase(double x, double y) { + CTrackPt = this.SelectAPoint(x, y); + boolean r = false; - for (int i = 0; i < tracelist.size(); i++) { - CTrace tr = (CTrace) tracelist.get(i); - if (tr.isTracePt(CTrackPt)) { - r = true; - break; + for (Object o : tracelist) { + CTrace tr = (CTrace) o; + if (tr.isTracePt(CTrackPt)) { + r = true; + break; - } - } - if (!r) { - CTrace t = new CTrace(CTrackPt); + } + } + if (!r) { + CTrace t = new CTrace(CTrackPt); + this.addObjectToList(t, tracelist); + this.UndoAdded(t.toString()); + if (gxInstance != null) + gxInstance.setActionMove(); + } + } + + /** + * Handles locus creation by selecting one or two points and then a line or circle to define the locus. + * + * @param x the x-coordinate of the user input + * @param y the y-coordinate of the user input + */ + private void handleLocusCase(double x, double y) { + int n = SelectList.size(); + if (n <= 1) { + CPoint pt = this.SelectAPoint(x, y); + if (pt != null) { + if (n == 0 && !pt.isAFixedPoint()) { + JOptionPane.showMessageDialog(gxInstance, GExpert.getLanguage("The point should be a fix point."), + GExpert.getLanguage("Warning"), + JOptionPane.WARNING_MESSAGE); + } else + this.addObjectToList(pt, SelectList); + int k = SelectList.size(); + if (k == 1) + gxInstance.setTipText(GExpert.getLanguage("Please select the second point.")); + else if (k == 2) + gxInstance.setTipText(GExpert.getLanguage("Please select a line or a circle.")); + } + } else { + CPoint pt = (CPoint) SelectList.get(0); + CPoint pt1 = (CPoint) SelectList.get(1); + CLine ln = this.SelectALine(x, y); + + if (ln != null) { + CTrace t = new CTrace(pt, pt1, ln); + this.addObjectToList(t, tracelist); + this.UndoAdded(t.toString()); + } else { + Circle c = this.SelectACircle(x, y); + if (c != null) { + CTrace t = new CTrace(pt, pt1, c); this.addObjectToList(t, tracelist); this.UndoAdded(t.toString()); - if (gxInstance != null) - gxInstance.setActionMove(); } - break; } + clearSelection(); + this.reCalculate(); + } + } - case LOCUS: { - int n = SelectList.size(); - if (n <= 1) { - CPoint pt = this.SelectAPoint(x, y); - if (pt != null) { - if (n == 0 && !pt.isAFixedPoint()) { - JOptionPane.showMessageDialog(gxInstance, GExpert.getLanguage("The point should be a fix point."), - GExpert.getLanguage("Warning"), - JOptionPane.WARNING_MESSAGE); - } else - this.addObjectToList(pt, SelectList); - int k = SelectList.size(); - if (k == 1) - gxInstance.setTipText(GExpert.getLanguage("Please select the second point.")); - else if (k == 2) - gxInstance.setTipText(GExpert.getLanguage("Please select a line or a circle.")); - } - } else { - CPoint pt = (CPoint) SelectList.get(0); - CPoint pt1 = (CPoint) SelectList.get(1); - CLine ln = this.SelectALine(x, y); - - if (ln != null) { - CTrace t = new CTrace(pt, pt1, ln); - this.addObjectToList(t, tracelist); - this.UndoAdded(t.toString()); - } else { - Circle c = this.SelectACircle(x, y); - if (c != null) { - CTrace t = new CTrace(pt, pt1, c); - this.addObjectToList(t, tracelist); - this.UndoAdded(t.toString()); - } else { - } - } - clearSelection(); - this.reCalculate(); - } + /** + * Handles the computation and addition of a circumcenter, barycenter, orthocenter, + * or incenter based on the current action. It creates a new point and adds the corresponding + * constraint if three points have been selected. + * + * @param x the x-coordinate of the temporary point + * @param y the y-coordinate of the temporary point + * @param p a CPoint object used in the calculation (may be updated) + */ + private void handleCircumCenter(double x, double y, CPoint p) { + CPoint pt = this.CreateATempPoint(x, y); + CPoint tp = this.SmartPoint(pt); + if (tp != null) { + this.addObjectToList(tp, SelectList); + } + if (SelectList.size() == 3) { + CPoint p1 = (CPoint) SelectList.get(0); + CPoint p2 = (CPoint) SelectList.get(1); + CPoint p3 = (CPoint) SelectList.get(2); + CPoint pp = this.CreateANewPoint(x, y); + Constraint cs = null; + String s = null; + if (CurrentAction == BARYCENTER) { + cs = new Constraint(Constraint.BARYCENTER, pp, p1, p2, p3); + s = "barycenter"; + } else if (CurrentAction == CIRCUMCENTER) { + cs = new Constraint(Constraint.CIRCUMCENTER, pp, p1, p2, p3); + s = "circumcenter"; + } else if (CurrentAction == ORTHOCENTER) { + cs = new Constraint(Constraint.ORTHOCENTER, pp, p1, p2, p3); + s = "orthocenter"; + } else if (CurrentAction == INCENTER) { + cs = new Constraint(Constraint.INCENTER, pp, p1, p2, p3); + s = "incenter"; + pp.addcstoPoint(cs); + } else { + return; } - break; - case INCENTER: - case BARYCENTER: - case ORTHOCENTER: - case CIRCUMCENTER: { - CPoint pt = this.CreateATempPoint(x, y); - CPoint tp = this.SmartPoint(pt); - if (tp != null) { - this.addObjectToList(tp, SelectList); - } - if (SelectList.size() == 3) { - CPoint p1 = (CPoint) SelectList.get(0); - CPoint p2 = (CPoint) SelectList.get(1); - CPoint p3 = (CPoint) SelectList.get(2); - CPoint pp = this.CreateANewPoint(x, y); - Constraint cs = null; - String s = null; - if (CurrentAction == BARYCENTER) { - cs = new Constraint(Constraint.BARYCENTER, pp, p1, p2, p3); - s = "barycenter"; - } else if (CurrentAction == CIRCUMCENTER) { - cs = new Constraint(Constraint.CIRCUMCENTER, pp, p1, p2, p3); - s = "circumcenter"; - } else if (CurrentAction == ORTHOCENTER) { - cs = new Constraint(Constraint.ORTHOCENTER, pp, p1, p2, p3); - s = "orthocenter"; - } else if (CurrentAction == INCENTER) { - cs = new Constraint(Constraint.INCENTER, pp, p1, p2, p3); - s = "incenter"; - pp.addcstoPoint(cs); - } else { - return; - } - CPoint pu = this.addADecidedPointWithUnite(pp); - if (pu == null) { - this.addPointToList(pp); - this.addConstraintToList(cs); - // Here we construct the translation key from s: - this.UndoAdded(pp.TypeString() + ": " + GExpert.getTranslationViaGettext( - s + " of {0}", p1.m_name + p2.m_name + p3.m_name)); + CPoint pu = this.addADecidedPointWithUnite(pp); + if (pu == null) { + this.addPointToList(pp); + this.addConstraintToList(cs); + // Here we construct the translation key from s: + this.UndoAdded(pp.TypeString() + ": " + GExpert.getTranslationViaGettext( + s + " of {0}", p1.m_name + p2.m_name + p3.m_name)); - } else { - p = pu; - } - clearSelection(); - } + } else { + p = pu; } - break; + clearSelection(); + } + } - case NTANGLE: { - if (STATUS == 0) { - CLine ln = (CLine) this.SelectFromAList(linelist, x, y); - if (ln != null) { - addToSelectList(ln); - } - if (SelectList.size() == 3) { - STATUS = 1; - Vector v = new Vector(); - v.add(ln); - this.flashStep(v); - } - } else if (STATUS == 1) { - CPoint pt = this.SelectAPoint(x, y); - if (pt != null) { - CLine ln = new CLine(CLine.NTALine); - ln.addApoint(pt); - addToSelectList(ln); - Constraint cs = new Constraint(Constraint.NTANGLE, - SelectList); - clearSelection(); - Constraint cs1 = new Constraint(Constraint.PONLINE, pt, ln, false); - ln.addconstraint(cs); - this.addLineToList(ln); - this.addConstraintToList(cs1); - this.addConstraintToList(cs); - this.UndoAdded("eqanle added"); - } - } + /** + * Handles the NT Angle case. + *

+ * If STATUS is 0, selects a line from the linelist and flashes the step. + * If STATUS is 1, creates a new NT Angle line using a selected point and adds its constraints. + *

+ * + * @param x the x-coordinate of the event + * @param y the y-coordinate of the event + */ + private void handleNTangleCase(double x, double y) { + if (STATUS == 0) { + CLine ln = (CLine) this.SelectFromAList(linelist, x, y); + if (ln != null) { + addToSelectList(ln); + } + if (SelectList.size() == 3) { + STATUS = 1; + Vector v = new Vector(); + v.add(ln); + this.flashStep(v); + } + } else if (STATUS == 1) { + CPoint pt = this.SelectAPoint(x, y); + if (pt != null) { + CLine ln = new CLine(CLine.NTALine); + ln.addApoint(pt); + addToSelectList(ln); + Constraint cs = new Constraint(Constraint.NTANGLE, + SelectList); + clearSelection(); + Constraint cs1 = new Constraint(Constraint.PONLINE, pt, ln, false); + ln.addconstraint(cs); + this.addLineToList(ln); + this.addConstraintToList(cs1); + this.addConstraintToList(cs); + this.UndoAdded("eqanle added"); + } + } + + } + + /** + * Handles viewing an element based on the given coordinates. + * + * @param x the x-coordinate of the view event + * @param y the y-coordinate of the view event + */ + private void handleViewElementCase(double x, double y) { + viewElementFromXY(x, y); + } + /** + * Handles the arrow creation case. + *

+ * If no object is currently selected, adds a point to the selection. + * Otherwise, creates an arrow between the first selected point and the newly selected point. + *

+ * + * @param x the x-coordinate of the event + * @param y the y-coordinate of the event + */ + private void handleArrowCase(double x, double y) { + CPoint pt = (CPoint) this.SmartgetApointFromXY(x, y); + if (pt == null) { + return; + } + if (SelectList.isEmpty()) { + this.addObjectToList(pt, SelectList); + } else { + CPoint tp = (CPoint) SelectList.get(0); + if (tp == pt) { + return; } - break; + CArrow ar = new CArrow(pt, tp); + otherlist.add(ar); + clearSelection(); + this.UndoAdded("Arrow " + ar.getDescription()); + } + } + + /** + * Handles the distance measurement case. + *

+ * Selects a point from the pointlist; if one is already selected, measures the distance between the two points. + *

+ * + * @param x the x-coordinate for distance measurement + * @param y the y-coordinate for distance measurement + */ + private void handleDistanceCase(double x, double y){ - case VIEWELEMENT: { - viewElementFromXY(x, y); + CPoint pt = (CPoint) this.SelectFromAList(pointlist, x, y); + if (pt == null) { + return; + } + if (SelectList.size() == 0) { + if (pt != null) { + this.addObjectToList(pt, SelectList); } - break; - case ARROW: { - CPoint pt = (CPoint) this.SmartgetApointFromXY(x, y); - if (pt == null) { - break; - } - if (SelectList.size() == 0) { - if (pt != null) { - this.addObjectToList(pt, SelectList); - } - } else { - CPoint tp = (CPoint) SelectList.get(0); - if (tp == pt) { - break; - } - CArrow ar = new CArrow(pt, tp); - otherlist.add(ar); - clearSelection(); - this.UndoAdded("Arrow " + ar.getDescription()); - } + } else { + CPoint tp = (CPoint) SelectList.get(0); + if (tp == pt) { + return; } - case DISTANCE: { + CDistance dis = new CDistance(pt, tp); + distancelist.add(dis); + clearSelection(); + this.UndoAdded("measure " + dis.getDescription()); + } - CPoint pt = (CPoint) this.SelectFromAList(pointlist, x, y); - if (pt == null) { - break; - } - if (SelectList.size() == 0) { - if (pt != null) { - this.addObjectToList(pt, SelectList); - } - } else { - CPoint tp = (CPoint) SelectList.get(0); - if (tp == pt) { - break; - } - CDistance dis = new CDistance(pt, tp); - distancelist.add(dis); - clearSelection(); - this.UndoAdded("measure " + dis.getDescription()); - } + } + /** + * Handles the equality mark case. + *

+ * Selects a point; if another point is already selected, creates an equality mark between them. + *

+ * + * @param x the x-coordinate of the event + * @param y the y-coordinate of the event + */ + private void handleEqMark(double x, double y) { + CPoint pt = (CPoint) this.SelectFromAList(pointlist, x, y); + if (pt == null) { + return; + } + if (SelectList.size() == 0) { + if (pt != null) { + this.addObjectToList(pt, SelectList); } - break; - case EQMARK: { - CPoint pt = (CPoint) this.SelectFromAList(pointlist, x, y); - if (pt == null) { - break; - } - if (SelectList.size() == 0) { - if (pt != null) { - this.addObjectToList(pt, SelectList); - } - } else { - CPoint tp = (CPoint) SelectList.get(0); - if (tp == pt) - break; + } else { + CPoint tp = (CPoint) SelectList.get(0); + if (tp == pt) + return; - Cedmark ce = new Cedmark(pt, tp, STATUS); - otherlist.add(ce); - clearSelection(); - this.UndoAdded("mark of " + pt.m_name + tp.m_name); - } + Cedmark ce = new Cedmark(pt, tp, STATUS); + otherlist.add(ce); + clearSelection(); + this.UndoAdded("mark of " + pt.m_name + tp.m_name); + } + } + + /** + * Handles the right angle mark case. + *

+ * Selects a line; if another line is already selected, adds a right angle mark between them. + *

+ * + * @param x the x-coordinate of the event + * @param y the y-coordinate of the event + */ + private void handleRaMark(double x, double y) { + CLine ln = (CLine) this.SelectFromAList(linelist, x, y); + if (ln == null) + return; + if (SelectList.size() == 0) + this.addObjectToList(ln, SelectList); + else { + CLine ln1 = (CLine) SelectList.get(0); + if (ln == ln1) + return; + addCTMark(ln, ln1); + clearSelection(); + this.UndoAdded("Right Angle Mark of " + ln.getDescription() + " and " + ln1.getDescription()); + } + } + + /** + * Handles hiding an object. + *

+ * Selects an object at the given coordinates, adds an invisible constraint, and sets it as not visible. + *

+ * + * @param x the x-coordinate of the hide event + * @param y the y-coordinate of the hide event + */ + private void handleHideObject(double x, double y) { + CClass cc = this.SelectOneFromXY(x, y, 0); + if (cc != null) { + Constraint cs = new Constraint(Constraint.INVISIBLE, cc); + this.addConstraintToList(cs); + cc.setVisible(false); + UndoStruct un = this.UndoAdded("Hide " + cc.getDescription()); + if (un != null) { + un.addRelatedObject(cc); + } + } + } + + /** + * Handles showing an object. + *

+ * Iterates through constraints to find an invisible object, restores its visibility, and flashes it. + *

+ * + * @param x the x-coordinate of the show event + * @param y the y-coordinate of the show event + */ + private void handleShowObject(double x, double y) { + CClass cc = null; + for (int i = 0; i < constraintlist.size(); i++) { + Constraint cs = (Constraint) constraintlist.get(i); + if (cs.GetConstraintType() != Constraint.INVISIBLE) { + continue; } - break; - case RAMARK: { - CLine ln = (CLine) this.SelectFromAList(linelist, x, y); - if (ln == null) + CClass c1 = (CClass) cs.getelement(0); + if (c1.visible == false) { + c1.setVisible(true); + if (c1.select(x, y)) { + cc = c1; + Constraint cs1 = new Constraint(Constraint.VISIBLE, cc); + this.addConstraintToList(cs1); + UndoStruct un = this.UndoAdded("Show " + + cc.getDescription()); + Vector v = new Vector(); + v.add(cc); + this.setObjectListForFlash(v); break; - if (SelectList.size() == 0) - this.addObjectToList(ln, SelectList); - else { - CLine ln1 = (CLine) SelectList.get(0); - if (ln == ln1) - break; - addCTMark(ln, ln1); - // this.addObjectToList(m, otherlist); - clearSelection(); - this.UndoAdded("Right Angle Mark of " + ln.getDescription() + " and " + ln1.getDescription()); - } - } - break; - case HIDEOBJECT: { - CClass cc = this.SelectOneFromXY(x, y, 0); - if (cc != null) { - Constraint cs = new Constraint(Constraint.INVISIBLE, cc); - this.addConstraintToList(cs); - cc.setVisible(false); - UndoStruct un = this.UndoAdded("Hide " + cc.getDescription()); - if (un != null) { - un.addRelatedObject(cc); - } + } else { + c1.setVisible(false); } } - break; - case SHOWOBJECT: { - CClass cc = null; - for (int i = 0; i < constraintlist.size(); i++) { - Constraint cs = (Constraint) constraintlist.get(i); - if (cs.GetConstraintType() != Constraint.INVISIBLE) { - continue; - } - CClass c1 = (CClass) cs.getelement(0); - if (c1.visible == false) { - c1.setVisible(true); - if (c1.select(x, y)) { - cc = c1; - Constraint cs1 = new Constraint(Constraint.VISIBLE, cc); - this.addConstraintToList(cs1); - UndoStruct un = this.UndoAdded("Show " + - cc.getDescription()); - Vector v = new Vector(); - v.add(cc); - this.setObjectListForFlash(v); - break; - } else { - c1.setVisible(false); - } - } - } + } + + } + /** + * Handles the SAngle action using the coordinate (x, y) and a point. + *

+ * If no element is selected, attempts to select a line from the catch point. + * If one element is selected, selects a point if it lies on the selected line. + * With two elements selected, calculates two slope candidates and chooses one based on proximity, + * then adds a new angle constraint and performs related updates. + * + * @param x the x-coordinate of the mouse event + * @param y the y-coordinate of the mouse event + * @param p the point parameter used in processing + */ + private void handleSAngle(double x, double y, CPoint p) { + int n = SelectList.size(); + if (n == 0) { + CLine line = this.SmartPLine(CatchPoint); + if (line != null && line.points.size() >= 2) { + addToSelectList(line); } - break; + } else if (n == 1) { + p = SelectAPoint(x, y); + CLine ln1 = (CLine) SelectList.get(0); + if (p != null && ln1.pointOnLine(p)) + addToSelectList(p); - case SANGLE: { - int n = SelectList.size(); - if (n == 0) { - CLine line = this.SmartPLine(CatchPoint); - if (line != null && line.points.size() >= 2) { - addToSelectList(line); - } - } else if (n == 1) { - p = SelectAPoint(x, y); - CLine ln1 = (CLine) SelectList.get(0); - if (p != null && ln1.pointOnLine(p)) - addToSelectList(p); + } else if (n == 2) { + CLine ln1 = (CLine) SelectList.get(0); + p = (CPoint) SelectList.get(1); - } else if (n == 2) { - CLine ln1 = (CLine) SelectList.get(0); - p = (CPoint) SelectList.get(1); + double k = ln1.getK(); + double k1 = Constraint.get_sp_ag_value(STATUS); + double kx1 = (k + k1) / (1 - k * k1); + double kx2 = (k - k1) / (1 + k * k1); - double k = ln1.getK(); - double k1 = Constraint.get_sp_ag_value(STATUS); - double kx1 = (k + k1) / (1 - k * k1); - double kx2 = (k - k1) / (1 + k * k1); + double r1 = CLine.distanceToPoint(p.getx(), p.gety(), kx1, x, y); + double r2 = CLine.distanceToPoint(p.getx(), p.gety(), kx2, x, y); - double r1 = CLine.distanceToPoint(p.getx(), p.gety(), kx1, x, y); - double r2 = CLine.distanceToPoint(p.getx(), p.gety(), kx2, x, y); + Integer I = null; + int id = 0; - Integer I = null; - int id = 0; + if (r1 <= r2) { + I = -STATUS; + id = add_sp_angle_value(-STATUS); + } else { + I = STATUS; + id = add_sp_angle_value(STATUS); + } + CLine ln = new CLine(CLine.SALine); + ln.addApoint(p); + Constraint cs = new Constraint(Constraint.SANGLE, ln1, ln, I); + cs.proportion = id; - if (r1 <= r2) { - I = -STATUS; - id = add_sp_angle_value(-STATUS); - } else { - I = STATUS; - id = add_sp_angle_value(STATUS); - } - CLine ln = new CLine(CLine.SALine); - ln.addApoint(p); - Constraint cs = new Constraint(Constraint.SANGLE, ln1, ln, I); - cs.proportion = id; + ln.addconstraint(cs); + addConstraintToList(cs); + this.addLineToList(ln); + this.UndoAdded(ln.getDescription()); + clearSelection(); + } + } - ln.addconstraint(cs); - addConstraintToList(cs); - this.addLineToList(ln); - this.UndoAdded(ln.getDescription()); - clearSelection(); - } + /** + * Handles the double boundary line action using the coordinate (x, y). + *

+ * Adds a point based on the mouse event and, if two distinct points are collected, + * creates a boundary line between them along with its associated constraint. + * + * @param x the x-coordinate of the mouse event + * @param y the y-coordinate of the mouse event + */ + private void handleDBLine(double x, double y){ + addSelectPoint(x, y); + if (SelectList.size() == 2) { + CPoint p1 = (CPoint) SelectList.get(0); + CPoint p2 = (CPoint) SelectList.get(1); + if (p1 != p2) { + CLine ln = new CLine(CLine.BLine); + Constraint cs = new Constraint(Constraint.BLINE, ln, p1, p2); + ln.addconstraint(cs); + this.addLineToList(ln); + this.addConstraintToList(cs); + clearSelection(); + this.UndoAdded("BLine " + ln.getDescription()); } - break; - case D_BLINE: { - addSelectPoint(x, y); - if (SelectList.size() == 2) { - CPoint p1 = (CPoint) SelectList.get(0); - CPoint p2 = (CPoint) SelectList.get(1); - if (p1 != p2) { - CLine ln = new CLine(CLine.BLine); - Constraint cs = new Constraint(Constraint.BLINE, ln, p1, p2); - ln.addconstraint(cs); - this.addLineToList(ln); - this.addConstraintToList(cs); - clearSelection(); - this.UndoAdded("BLine " + ln.getDescription()); - } - } + } + } + + /** + * Handles drawing a tangent line to a circle using the coordinate (x, y). + *

+ * If no object is selected, identifies a circle based on the catch point. + * Otherwise, if the coordinates lie on the selected circle, + * calculates a point on the circle and creates a tangent line with an associated constraint. + * + * @param x the x-coordinate of the mouse event + * @param y the y-coordinate of the mouse event + */ + private void handleDTCLine(double x, double y) { + CatchPoint.setXY(x, y); + + if (SelectList.size() == 0) { + Circle c = SmartPCircle(CatchPoint); + if (c != null) + addToSelectList(c); + } else { + Circle c = (Circle) SelectList.get(0); + if (c.on_circle(x, y)) { + CPoint p1 = SmartgetApointFromXY(x, y); + CLine ln = new CLine(p1, CLine.TCLine); + Constraint cs = new Constraint(Constraint.TCLINE, c, ln, p1); + this.addConstraintToList(cs); + ln.addconstraint(cs); + this.addLineToList(ln); } - break; - case D_TCLINE: { - CatchPoint.setXY(x, y); + } + } - if (SelectList.size() == 0) { - Circle c = SmartPCircle(CatchPoint); - if (c != null) - addToSelectList(c); - } else { - Circle c = (Circle) SelectList.get(0); - if (c.on_circle(x, y)) { - CPoint p1 = SmartgetApointFromXY(x, y); - CLine ln = new CLine(p1, CLine.TCLine); - Constraint cs = new Constraint(Constraint.TCLINE, c, ln, p1); - this.addConstraintToList(cs); - ln.addconstraint(cs); - this.addLineToList(ln); + /** + * Handles the creation of a common tangent line between two circles using the coordinate (x, y). + *

+ * If one circle is already selected and the new circle is distinct and non-overlapping, + * creates new points and adds a tangent constraint between the circles. + * + * @param x the x-coordinate of the mouse event + * @param y the y-coordinate of the mouse event + */ + private void handleCCTANGent(double x, double y) { + Circle c = this.SelectACircle(x, y); + if (c != null) { + int n = SelectList.size(); + if (n == 1) { + Circle c1 = (Circle) SelectList.get(0); + if (c != c1 && c.o != c1.o) { + CPoint p1 = this.CreateANewPoint(0, 0); + CPoint p2 = this.CreateANewPoint(x, y); + c1.addPoint(p1); + c.addPoint(p2); + Constraint cs = new Constraint(Constraint.CCTANGENT_LINE, p1, p2, c1, c); + this.addPointToList(p1); + this.addPointToList(p2); + this.addConstraintToList(cs); + this.charsetAndAddPoly(false); + this.UndoAdded("TANGENT LINE"); + } + } else + this.addObjectToList(c, SelectList); + } + } + + /** + * Handles the ratio constraint action using the coordinate (x, y) and a point. + *

+ * Selects a point based on the provided coordinates and avoids duplicate successive selections. + * When eight points are collected, creates a ratio constraint and updates relevant lists. + * + * @param x the x-coordinate of the mouse event + * @param y the y-coordinate of the mouse event + * @param p the point parameter used in processing + */ + private void handleRatio(double x, double y, CPoint p) { + int n = SelectList.size(); + p = SelectAPoint(x, y); + if (p != null) { + if (n % 2 != 0 && p == SelectList.get(n - 1)) + return; + addToSelectList(p); + setObjectListForFlash(p); + } + if (SelectList.size() == 8) { + Constraint cs = new Constraint(Constraint.RATIO, SelectList); + this.addConstraintToList(cs); + this.charsetAndAddPoly(false); + this.UndoAdded("RATIO"); + clearSelection(); + } + } + + /** + * Handles the equivalence (area-preserving transformation) action using the coordinate (x, y) and a point. + *

+ * Depending on the current status, selects a polygon and then a point or line segment. + * Creates a new polygon with an appropriate equivalence constraint to record the transformation. + * + * @param x the x-coordinate of the mouse event + * @param y the y-coordinate of the mouse event + * @param p the point parameter used in processing + */ + private void handleEquivalence(double x, double y, CPoint p) { + if (STATUS == 0) { + CPolygon g = (CPolygon) this.SelectFromAList(polygonlist, x, y); + if (g != null) { + addObjectToList(g, SelectList); + STATUS = 1; + } + } else if (STATUS == 1) { + CPoint pt = this.SelectAPoint(x, y); + if (pt != null) { + addToSelectList(pt); + STATUS = 2; + } else { + CPolygon g = (CPolygon) SelectList.get(0); + int n = g.getPtn(); + + for (int i = 0; i < n - 1; i++) { + CPoint p1 = g.getPoint(i); + CPoint p2 = g.getPoint(i + 1); + if (CLine.mouse_on_line(x, y, p1.getx(), p1.gety(), p2.getx(), p2.gety())) { + addToSelectList(p1); + addToSelectList(p2); + vx1 = x; + vy1 = y; + STATUS = 3; + break; } } } - break; - case CCTANGENT: { - Circle c = this.SelectACircle(x, y); - if (c != null) { - int n = SelectList.size(); - if (n == 1) { - Circle c1 = (Circle) SelectList.get(0); - if (c != c1 && c.o != c1.o) { - CPoint p1 = this.CreateANewPoint(0, 0); - CPoint p2 = this.CreateANewPoint(x, y); - c1.addPoint(p1); - c.addPoint(p2); - Constraint cs = new Constraint(Constraint.CCTANGENT_LINE, p1, p2, c1, c); - this.addPointToList(p1); - this.addPointToList(p2); - this.addConstraintToList(cs); - this.charsetAndAddPoly(false); - this.UndoAdded("TANGENT LINE"); - } - } else - this.addObjectToList(c, SelectList); - } + if (STATUS == 1) { + STATUS = 0; + clearSelection(); } - break; - case RATIO: { - int n = SelectList.size(); - p = SelectAPoint(x, y); - if (p != null) { - if (n % 2 != 0 && p == SelectList.get(n - 1)) - break; - addToSelectList(p); - setObjectListForFlash(p); + + } else if (STATUS == 2) { + CPolygon g = (CPolygon) SelectList.get(0); + CPoint p1 = (CPoint) SelectList.get(1); + CPoint t1 = g.getPreviousePoint(p1); + CPoint t2 = g.getNextPoint(p1); + double[] r = getPTInterSection(x, y, p1.getx(), p1.gety() + , t1.getx(), t1.gety(), t2.getx(), t2.gety()); + CPoint pt = this.SelectAPoint(r[0], r[1]); + + if (pt != null && pt != t1) { + CPolygon poly = new CPolygon(); + poly.copy(g); + int t = g.getPtn(); + + for (int i = 0; i < t; i++) { + CPoint m = g.getPoint(i); + if (m == p1) + m = pt; + poly.addAPoint(m); + } + if (this.findPolygon(poly.pointlist) != g) { + g.setVisible(false); + Constraint cs = new Constraint(Constraint.EQUIVALENCE1, g, poly); + this.addConstraintToList(cs); + this.addObjectToList(poly, polygonlist); + this.UndoAdded("Area-Preserving");//+ g.getDescription() + " transformed to " + poly.getDescription()); } - if (SelectList.size() == 8) { - Constraint cs = new Constraint(Constraint.RATIO, SelectList); + } + STATUS = 0; + clearSelection(); + g.setDraggedPoints(null, null, 0, 0); + + } else if (STATUS == 3) { + CPolygon g = (CPolygon) SelectList.get(0); + CPoint t1 = (CPoint) SelectList.get(1); + CPoint t2 = (CPoint) SelectList.get(2); + double dx = x - vx1; + double dy = y - vy1; + + CPoint pt1 = this.SelectAPoint(t1.getx() + dx, t1.gety() + dy); + CPoint pt2 = this.SelectAPoint(t2.getx() + dx, t2.gety() + dy); + if (pt1 != null && pt2 != null && (pt1 != t1 || pt2 != t2)) { + CPolygon poly = new CPolygon(); + poly.copy(g); + int t = g.getPtn(); + + for (int i = 0; i < t; i++) { + CPoint m = g.getPoint(i); + if (m == t1) + m = pt1; + else if (m == t2) + m = pt2; + + poly.addAPoint(m); + } + if (this.findPolygon(poly.pointlist) != g) { + g.setVisible(false); + Constraint cs = new Constraint(Constraint.EQUIVALENCE2, g, poly); this.addConstraintToList(cs); - this.charsetAndAddPoly(false); - this.UndoAdded("RATIO"); - clearSelection(); + this.addObjectToList(poly, polygonlist); + this.UndoAdded("Area-Preserving");//g.getDescription() + " transformed to " + poly.getDescription()); } } - break; - case EQUIVALENCE: { - if (STATUS == 0) { - CPolygon g = (CPolygon) this.SelectFromAList(polygonlist, x, y); - if (g != null) { - addObjectToList(g, SelectList); - STATUS = 1; - } - } else if (STATUS == 1) { - CPoint pt = this.SelectAPoint(x, y); - if (pt != null) { - addToSelectList(pt); - STATUS = 2; - } else { - CPolygon g = (CPolygon) SelectList.get(0); - int n = g.getPtn(); - - for (int i = 0; i < n - 1; i++) { - CPoint p1 = g.getPoint(i); - CPoint p2 = g.getPoint(i + 1); - if (CLine.mouse_on_line(x, y, p1.getx(), p1.gety(), p2.getx(), p2.gety())) { - addToSelectList(p1); - addToSelectList(p2); - vx1 = x; - vy1 = y; - STATUS = 3; - break; - } - } - } - if (STATUS == 1) { - STATUS = 0; - clearSelection(); - } - } else if (STATUS == 2) { - CPolygon g = (CPolygon) SelectList.get(0); - CPoint p1 = (CPoint) SelectList.get(1); - CPoint t1 = g.getPreviousePoint(p1); - CPoint t2 = g.getNextPoint(p1); - double[] r = getPTInterSection(x, y, p1.getx(), p1.gety() - , t1.getx(), t1.gety(), t2.getx(), t2.gety()); - CPoint pt = this.SelectAPoint(r[0], r[1]); - - if (pt != null && pt != t1) { - CPolygon poly = new CPolygon(); - poly.copy(g); - int t = g.getPtn(); - - for (int i = 0; i < t; i++) { - CPoint m = g.getPoint(i); - if (m == p1) - m = pt; - poly.addAPoint(m); - } - if (this.findPolygon(poly.pointlist) != g) { - g.setVisible(false); - Constraint cs = new Constraint(Constraint.EQUIVALENCE1, g, poly); - this.addConstraintToList(cs); - this.addObjectToList(poly, polygonlist); - this.UndoAdded("Area-Preserving");//+ g.getDescription() + " transformed to " + poly.getDescription()); + STATUS = 0; + clearSelection(); + g.setDraggedPoints(null, null, 0, 0); + } + } + + /** + * Handles the free transformation of a polygon using the coordinate (x, y). + *

+ * If no polygon is selected, attempts to select one based on the coordinates. + * Otherwise, adds the selected point to the transformation sequence of the polygon, + * and once all required points are gathered, applies and finalizes the free transform. + * + * @param x the x-coordinate of the mouse event + * @param y the y-coordinate of the mouse event + */ + private void handleFreeTransform(double x, double y) { + if (STATUS == 0) { + CPolygon g = (CPolygon) this.SelectAPolygon(x, y);//SelectFromAList(polygonlist, x, y); + if (g != null) { + this.addObjectToList(g, SelectList); + STATUS = 1; + } + } else { + CPoint pt = this.SelectAPoint(x, y); + CPolygon poly = (CPolygon) SelectList.get(0); + + if (pt == null) { + STATUS = 0; + clearSelection(); + poly.setDraggedPointsNull(); + } else { + if (SelectList.size() == 1) { + Vector v = poly.getDraggedPoints(); + boolean already = false; + for (int i = 0; i < v.size() / 2; i++) { + if (v.get(i * 2) == pt) { + already = true; + break; } } - STATUS = 0; - clearSelection(); - g.setDraggedPoints(null, null, 0, 0); - - } else if (STATUS == 3) { - CPolygon g = (CPolygon) SelectList.get(0); + if (!already) + addToSelectList(pt); + } else { CPoint t1 = (CPoint) SelectList.get(1); - CPoint t2 = (CPoint) SelectList.get(2); - double dx = x - vx1; - double dy = y - vy1; - - CPoint pt1 = this.SelectAPoint(t1.getx() + dx, t1.gety() + dy); - CPoint pt2 = this.SelectAPoint(t2.getx() + dx, t2.gety() + dy); - if (pt1 != null && pt2 != null && (pt1 != t1 || pt2 != t2)) { - CPolygon poly = new CPolygon(); - poly.copy(g); - int t = g.getPtn(); - - for (int i = 0; i < t; i++) { - CPoint m = g.getPoint(i); - if (m == t1) - m = pt1; - else if (m == t2) - m = pt2; - - poly.addAPoint(m); - } - if (this.findPolygon(poly.pointlist) != g) { - g.setVisible(false); - Constraint cs = new Constraint(Constraint.EQUIVALENCE2, g, poly); - this.addConstraintToList(cs); - this.addObjectToList(poly, polygonlist); - this.UndoAdded("Area-Preserving");//g.getDescription() + " transformed to " + poly.getDescription()); - } + poly.addDraggedPoints(t1, pt); + SelectList.remove(t1); + if (poly.allDragged()) { + add_free_transform(); } - - STATUS = 0; - clearSelection(); - g.setDraggedPoints(null, null, 0, 0); } } - break; - case FREE_TRANSFORM: { - if (STATUS == 0) { - CPolygon g = (CPolygon) this.SelectAPolygon(x, y);//SelectFromAList(polygonlist, x, y); - if (g != null) { - this.addObjectToList(g, SelectList); - STATUS = 1; - } - } else { - CPoint pt = this.SelectAPoint(x, y); - CPolygon poly = (CPolygon) SelectList.get(0); - if (pt == null) { - STATUS = 0; - clearSelection(); - poly.setDraggedPointsNull(); - } else { - if (SelectList.size() == 1) { - Vector v = poly.getDraggedPoints(); - boolean already = false; - for (int i = 0; i < v.size() / 2; i++) { - if (v.get(i * 2) == pt) { - already = true; - break; - } - } - if (!already) - addToSelectList(pt); - } else { - CPoint t1 = (CPoint) SelectList.get(1); - poly.addDraggedPoints(t1, pt); - SelectList.remove(t1); - if (poly.allDragged()) { - add_free_transform(); - } - } - } + } + } + + /** + * Handles the transformation (rotation and/or translation) of a polygon using the coordinate (x, y). + *

+ * On initial selection, stores the starting point and enables transformation mode. + * In subsequent steps, captures additional points, computes new positions for the polygon, + * applies the transformation, and creates a constraint to record the change. + * + * @param x the x-coordinate of the mouse event + * @param y the y-coordinate of the mouse event + */ + private void handleTransform(double x, double y) { + if (STATUS == 0) { + CPolygon g = (CPolygon) this.SelectAPolygon(x, y); // SelectFromAList(polygonlist, x, y); + if (g != null) { + this.addObjectToList(g, SelectList); + catchX = x; + catchY = y; + STATUS = 1; + FirstPnt = SecondPnt = ThirdPnt = null; + } + } else if (STATUS == 1 || STATUS == 2) { + if (STATUS == 2 && (FirstPnt == null || ThirdPnt == null)) { + CPoint pt = this.SelectAPoint(x - vx1, y - vy1); + if (pt != null) { + x = pt.getx() + vx1; + y = pt.gety() + vy1; + } + if (FirstPnt == null) { + FirstPnt = this.CreateATempPoint(x, y); + SecondPnt = pt; + catchX = x - vx1; + catchY = y - vy1; + } else { + ThirdPnt = this.CreateATempPoint(x - vx1, y - vy1); } + } else { + CPolygon poly = (CPolygon) SelectList.get(0); + clearSelection(); + STATUS = 0; - } - break; - case TRANSFORM: { - if (STATUS == 0) { - CPolygon g = (CPolygon) this.SelectAPolygon(x, y); // SelectFromAList(polygonlist, x, y); - if (g != null) { - this.addObjectToList(g, SelectList); - catchX = x; - catchY = y; - STATUS = 1; - FirstPnt = SecondPnt = ThirdPnt = null; - } - } else if (STATUS == 1 || STATUS == 2) { - if (STATUS == 2 && (FirstPnt == null || ThirdPnt == null)) { - CPoint pt = this.SelectAPoint(x - vx1, y - vy1); - if (pt != null) { - x = pt.getx() + vx1; - y = pt.gety() + vy1; - } - if (FirstPnt == null) { - FirstPnt = this.CreateATempPoint(x, y); - SecondPnt = pt; - catchX = x - vx1; - catchY = y - vy1; - } else { - ThirdPnt = this.CreateATempPoint(x - vx1, y - vy1); - } - } else { - CPolygon poly = (CPolygon) SelectList.get(0); + int n = poly.getPtn(); + double cx = catchX + vx1; + double cy = catchY + vy1; + double sin = Math.sin(vangle); + double cos = Math.cos(vangle); + + if (Math.abs(vangle) < CMisc.ZERO) { + PolygonTransPointsCreated(poly); + } + + for (int i = 0; i < n; i++) { + CPoint t = poly.getPoint(i); + double tx = (t.getx() + vx1); + double ty = (t.gety() + vy1); + + tx -= cx; + ty -= cy; + double mx = (tx) * cos - (ty) * sin; + double my = (tx) * sin + (ty) * cos; + tx = mx + cx; + ty = my + cy; + CPoint t1 = this.SelectAPoint(tx, ty); + if (t1 == null) { clearSelection(); - STATUS = 0; + break; + } + addToSelectList(t1); + } + if (!SelectList.isEmpty()) { + CPolygon poly1 = new CPolygon(); + poly1.setPoints(SelectList); + if (this.findPolygon(SelectList) != poly) { + Constraint cs = new Constraint(Constraint.TRANSFORM, poly, poly1, SecondPnt); - int n = poly.getPtn(); - double cx = catchX + vx1; - double cy = catchY + vy1; - double sin = Math.sin(vangle); - double cos = Math.cos(vangle); + int r = -1; - if (Math.abs(vangle) < CMisc.ZERO) { - PolygonTransPointsCreated(poly); - } + if (CMisc.TransComfirmed) { + String s1 = poly.getDescription() + " is transformed to " + poly1.getDescription(); + String s2 = "Do you want to keep the original polygon visible?"; + TransformConfirmDialog dlg = new TransformConfirmDialog(gxInstance.getFrame(), s1, s2); + gxInstance.centerDialog(dlg); + dlg.setVisible(true); + r = dlg.getResult(); + } else + r = 1; - for (int i = 0; i < n; i++) { - CPoint t = poly.getPoint(i); - double tx = (t.getx() + vx1); - double ty = (t.gety() + vy1); - - tx -= cx; - ty -= cy; - double mx = (tx) * cos - (ty) * sin; - double my = (tx) * sin + (ty) * cos; - tx = mx + cx; - ty = my + cy; - CPoint t1 = this.SelectAPoint(tx, ty); - if (t1 == null) { - clearSelection(); - break; - } - addToSelectList(t1); + if (r == 0) {//JOptionPane.YES_OPTION) { + cs.proportion = 0; + } else if (r == 1) { + poly.setVisible(false); + cs.proportion = 1; } - if (SelectList.size() != 0) { - CPolygon poly1 = new CPolygon(); - poly1.setPoints(SelectList); - if (this.findPolygon(SelectList) != poly) { - Constraint cs = new Constraint(Constraint.TRANSFORM, poly, poly1, SecondPnt); - - int r = -1; - - if (CMisc.TransComfirmed) { - String s1 = poly.getDescription() + " is transformed to " + poly1.getDescription(); - String s2 = "Do you want to keep the original polygon visible?"; - TransformConfirmDialog dlg = new TransformConfirmDialog(gxInstance.getFrame(), s1, s2); - gxInstance.centerDialog(dlg); - dlg.setVisible(true); - r = dlg.getResult(); - } else - r = 1; - - if (r == 0) {//JOptionPane.YES_OPTION) { - cs.proportion = 0; - } else if (r == 1) { - poly.setVisible(false); - cs.proportion = 1; - } else { - } - if (r != 2) { - this.addObjectToList(poly1, polygonlist); - poly1.copy(poly); - this.addConstraintToList(cs); + if (r != 2) { + this.addObjectToList(poly1, polygonlist); + poly1.copy(poly); + this.addConstraintToList(cs); // String s = "Isometry Transforming"; // if (Math.abs(vangle) < CMisc.ZERO) // s = "Transforming"; // else if (SecondPnt != null) // s = "Rotating"; - String s = poly.getDescription() + " = " + poly1.getDescription(); - this.UndoAdded(s);//); - } - } - + String s = poly.getDescription() + " = " + poly1.getDescription(); + this.UndoAdded(s);//); } - STATUS = 0; - clearSelection(); - vtrx = vtry = vx1 = vy1 = vangle = 0.0; - FirstPnt = SecondPnt = ThirdPnt = null; } + } + STATUS = 0; + clearSelection(); + vtrx = vtry = vx1 = vy1 = vangle = 0.0; + FirstPnt = SecondPnt = ThirdPnt = null; } - break; + } + } + /** + * Handles the "mouse down" (button press) event within the drawing canvas. + * + *

This method interprets user input based on the current action mode + * (such as SELECT, MOVE, D_POINT, etc.) and performs corresponding + * geometry-related operations. These may include selecting or modifying + * points, creating lines, circles, constraints, or initiating transformations.

+ * + *

Behavior depends on {@code CurrentAction}, which is evaluated in a large + * switch-case structure that includes many interactive drawing modes.

+ * + * @param x The x-coordinate of the mouse click, in screen or canvas coordinates + * @param y The y-coordinate of the mouse click, in screen or canvas coordinates + * @see #CurrentAction + * @see #SelectList + * @see #CatchPoint + * @see #STATUS + */ + public void DWButtonDown(double x, double y) { + CPoint p = null; + CatchList.clear(); + IsButtonDown = true; + if (SNAP && CurrentAction != SELECT) { + double[] r = getSnap(x, y); + x = r[0]; + y = r[1]; } + CatchPoint.setXY(x, y); + switch (this.CurrentAction) { + case SELECT: + handleSelectCase(x, y); + break; + case MOVE: + handleMoveCase(x, y); + break; + case D_POINT: + handleDpointCase(x, y, p); + break; + case TRIANGLE: + handleTriangleCase(x, y); + break; + case V_LINE: + handleVLineCase(x, y); + break; + case D_LINE: + handleDLineCase(x, y); + break; + case D_POLYGON: + handleDPolygonCase(x,y); + break; + case D_PARELINE: + handleDPareLineCase(x,y); + break; + case D_PERPLINE: + handleDPerpLineCase(x,y); + break; + case D_ALINE: + handleDAlineCase(x,y); + break; + case D_ABLINE: + handleDABlineCase(x,y,p); + break; + case D_PFOOT: + handleDPfootCase(x,y,p); + break; + case PERPWITHFOOT: + handlePerpWithFoot(x,y); + break; + case D_CIRCLE: + handleDCircleCase(x,y,p); + break; + case D_CIRCLEBYRADIUS: + handleDCircleByRadiusCase(x,y,p); + break; + case D_PRATIO: + handleDPRatioCase(x,y,p); + break; + case D_TRATIO: + handleDTRatioCase(x,y,p); + break; + case D_PTDISTANCE: + handleDPTDistanceCase(x,y,p); + break; + case LRATIO: + handleLRatioCase(x,y,p); + break; + case MEET: + handleMeetCase(x,y); + break; + case MIRROR: + handleMirrorCase(x,y,p); + break; + case D_MIDPOINT: + handleDMidpointCase(x,y); + break; + case D_3PCIRCLE: + handleD3PCircleCase(x,y,p); + break; + case TRANSLATE: + handleTranslateCase(x,y); + break; + case ZOOM_IN: + handleZoomInCase(x,y); + break; + case ZOOM_OUT: + handleZoomOutCase(x,y); + break; + case ANIMATION: + handleAnimationCase(x,y,p); + break; + case D_ANGLE: + handleDAngleCase(x,y); + break; + case SETEQSIDE: + handleSetEqSideCase(x,y,p); + break; + case SETEQANGLE: + handleSetEqAngleCase(x,y,p); + break; + case SETEQANGLE3P: + handleSetEqAngle3PCase(x,y,p); + break; + case SETCCTANGENT: + handleSetCCTangentCase(x,y,p); + break; + case D_SQUARE: + handleDSquareCase(x,y); + break; + case D_CCLINE: + handleDCCLineCase(x,y); + break; + case D_IOSTRI: + handleDIOSTriCase(x,y); + break; + case DRAWTRIALL: + handleDrawTriAllCase(x,y); + break; + case RA_TRAPEZOID: + handleRATrapezoidCase(x,y); + break; + case TRAPEZOID: + handleTrapezoide(x,y); + break; + case PARALLELOGRAM: + handleParallelogram(x,y); + break; + case RECTANGLE: + handleRectangle(x,y); + break; + case DRAWTRISQISO: + handleDrawTriSqIsoCase(x,y); + break; + case DEFINEPOLY: + handleDefinePolyCase(x,y,p); + break; + case D_TEXT: + handleDTextCase(x,y); + break; + case MULSELECTSOLUTION: + handleMulSelectSolutionCase(x,y,p); + break; + case SETTRACK: + handleSetTrackCase(x,y); + break; + case LOCUS: + handleLocusCase(x,y); + break; + case CIRCUMCENTER: + handleCircumCenter(x,y,p); + break; + case NTANGLE: + handleNTangleCase(x,y); + break; + case VIEWELEMENT: + handleViewElementCase(x,y); + break; + case ARROW: + handleArrowCase(x,y); + break; + case DISTANCE: + handleDistanceCase(x,y); + break; + case EQMARK: + handleEqMark(x,y); + break; + case RAMARK: + handleRaMark(x,y); + break; + case HIDEOBJECT: + handleHideObject(x,y); + break; + case SHOWOBJECT: + handleShowObject(x,y); + break; + case SANGLE: + handleSAngle(x,y,p); + break; + case D_BLINE: + handleDBLine(x,y); + break; + case D_TCLINE: + handleDTCLine(x,y); + break; + case CCTANGENT: + handleCCTANGent(x,y); + break; + case RATIO: + handleRatio(x,y,p); + break; + case EQUIVALENCE: + handleEquivalence(x,y,p); + break; + case FREE_TRANSFORM: + handleFreeTransform(x,y); + break; + case TRANSFORM: + handleTransform(x,y); + break; + default: + break; + } } + /** + * Adds a free transform to the selected polygon. + *

+ * This method creates a transformed copy of the selected polygon, adds a constraint + * for the transformation, and updates the polygon list. It also clears the selection + * and resets the status. + */ public void add_free_transform() { CPolygon p = (CPolygon) SelectList.get(0); Vector v = p.getTransformedPoints(); @@ -5281,6 +6241,16 @@ public void add_free_transform() { this.UndoAdded(p.getDescription() + " transformed to " + p1.getDescription()); } + /** + * Finds the intersection point of two geometric objects. + * + * @param obj1 the first geometric object (CLine or Circle) + * @param obj2 the second geometric object (CLine or Circle) + * @param d a boolean flag indicating some condition (not specified) + * @param x the x-coordinate for the intersection calculation + * @param y the y-coordinate for the intersection calculation + * @return the intersection point, or null if no intersection is found + */ public CPoint meetTwoObject(Object obj1, Object obj2, boolean d, double x, double y) { if (obj1 instanceof CLine && obj2 instanceof CLine) { return MeetDefineAPoint((CLine) obj1, (CLine) obj2); @@ -5296,11 +6266,12 @@ public CPoint meetTwoObject(Object obj1, Object obj2, boolean d, double x, doubl return null; } -// public void addToSelectList(Object p) { -// if (p != null && !SelectList.contains(p)) -// addToSelectList(p); -// } - + /** + * Adds a point to the selection list based on the given coordinates. + * + * @param x the x-coordinate + * @param y the y-coordinate + */ public void addSelectPoint(double x, double y) { CPoint p = this.SelectAPoint(x, y); if (p != null && !SelectList.contains(p)) { @@ -5308,6 +6279,14 @@ public void addSelectPoint(double x, double y) { } } + /** + * Adds a line between two points to the line list. + * + * @param t the type of the line + * @param p1 the first point + * @param p2 the second point + * @return the added line, or the existing line if it already exists + */ public CLine addALine(int t, CPoint p1, CPoint p2) { CLine ln1 = this.fd_line(p1, p2); if (ln1 != null) { @@ -5318,21 +6297,12 @@ public CLine addALine(int t, CPoint p1, CPoint p2) { return ln; } - public Vector printStep(String cc) { - CMisc.print("***************************"); - - Vector v = this.getConstructionFromDraw(); - v.add(cc); - - for (int i = 0; i < v.size(); i++) { - String st = (String) v.get(i); - CMisc.print(st); - } - return v; - } - + /** + * Retrieves the construction steps from the drawing. + * + * @return a vector containing the construction steps + */ public Vector getConstructionFromDraw() { - Vector alist = new Vector(); for (int i = 0; i < constraintlist.size(); i++) { Constraint cs = (Constraint) constraintlist.get(i); @@ -5348,6 +6318,12 @@ public Vector getConstructionFromDraw() { return alist; } + /** + * Finds a polygon in the polygon list that matches the given vector of points. + * + * @param v the vector of points + * @return the matching polygon, or null if no match is found + */ public CPolygon findPolygon(Vector v) { for (int i = 0; i < polygonlist.size(); i++) { CPolygon p = (CPolygon) polygonlist.get(i); @@ -5357,6 +6333,13 @@ public CPolygon findPolygon(Vector v) { return null; } + /** + * Finds a polygon in the polygon list that matches the given vector of points, + * considering rotational and directional equivalence. + * + * @param v the vector of points + * @return the matching polygon, or null if no match is found + */ public CPolygon findPolygon1(Vector v) { for (int i = 0; i < polygonlist.size(); i++) { CPolygon p = (CPolygon) polygonlist.get(i); @@ -5366,6 +6349,11 @@ public CPolygon findPolygon1(Vector v) { return null; } + /** + * Checks if auto animation is possible. + * + * @return true if auto animation is possible, false otherwise + */ public boolean canAutoAnimate() { if (animate != null) { return true; @@ -5373,6 +6361,11 @@ public boolean canAutoAnimate() { return false; } + /** + * Toggles auto animation on or off. + * + * @return true if auto animation is started, false if it is stopped + */ public boolean autoAnimate() { if (canAutoAnimate()) { AnimatePanel af = gxInstance.getAnimateDialog(); @@ -5393,10 +6386,16 @@ public boolean autoAnimate() { return false; } + /** + * Automatically shows the next step in the construction. + */ public void autoShowstep() { this.autoUndoRedo(); } + /** + * Toggles automatic undo and redo actions. + */ public void autoUndoRedo() { if (timer_type == 1) { timer.stop(); @@ -5419,6 +6418,11 @@ public void autoUndoRedo() { } + /** + * Handles action events triggered by the timer or other sources. + * + * @param e the action event + */ public void actionPerformed(ActionEvent e) { Object obj = e.getSource(); @@ -5452,6 +6456,9 @@ public void actionPerformed(ActionEvent e) { panel.repaint(); } + /** + * Updates the delay for all flash objects in the flash list. + */ public void updateFlashDelay() { for (int i = 0; i < flashlist.size(); i++) { JFlash f = (JFlash) flashlist.get(i); @@ -5459,6 +6466,11 @@ public void updateFlashDelay() { } } + /** + * Sets the delay for the timer. + * + * @param delay the delay in milliseconds + */ public void setTimerDelay(int delay) { if (timer == null) { return; @@ -5466,6 +6478,11 @@ public void setTimerDelay(int delay) { timer.setDelay(delay); } + /** + * Displays the properties of the specified object in the dialog. + * + * @param obj the object to view + */ public void viewElement(CClass obj) { if (obj == null) { return; @@ -5478,11 +6495,16 @@ public void viewElement(CClass obj) { } } - + /** + * Starts the animation. + */ public void animationStart() { animate.startAnimate(); } + /** + * Stops the animation and recalculates the drawing. + */ public void animationStop() { if (animate != null) { animate.stopAnimate(); @@ -5490,12 +6512,22 @@ public void animationStop() { this.reCalculate(); } + /** + * Updates the animation on each timer tick and recalculates the drawing. + */ public void animationOntime() { animate.onTimer(); this.reCalculate(); - } + /** + * Selects an object from the list based on the given coordinates. + * + * @param v the list of objects + * @param x the x-coordinate + * @param y the y-coordinate + * @return the selected object, or null if no object is selected + */ public CClass CatchList(Vector v, double x, double y) { for (int i = 0; i < v.size(); i++) { CClass cc = (CClass) v.get(i); @@ -5504,9 +6536,15 @@ public CClass CatchList(Vector v, double x, double y) { } } return null; - } + /** + * Selects an angle from the list based on the given coordinates. + * + * @param x the x-coordinate + * @param y the y-coordinate + * @return the selected angle, or null if no angle is selected + */ public CAngle CatchAngle(double x, double y) { for (int i = 0; i < anglelist.size(); i++) { CAngle ag = (CAngle) anglelist.get(i); @@ -5517,6 +6555,13 @@ public CAngle CatchAngle(double x, double y) { return null; } + /** + * Displays a dialog to add or edit text at the specified coordinates. + * + * @param tc the text object + * @param x the x-coordinate + * @param y the y-coordinate + */ public void dialog_addText(CText tc, int x, int y) { TextFrame tf = new TextFrame(gxInstance, x, y); tf.setText(tc); @@ -5524,16 +6569,36 @@ public void dialog_addText(CText tc, int x, int y) { tf.setVisible(true); } + /** + * Adds a point at the specified coordinates. + * + * @param x the x-coordinate + * @param y the y-coordinate + * @return the added point + */ public CPoint SmartgetApointFromXY(double x, double y) { CPoint pt = SmartAddPoint(x, y); return pt; } + /** + * Adds a point with the specified name at the given coordinates. + * + * @param x the x-coordinate + * @param y the y-coordinate + * @param name the name of the point + * @return the added point + */ public CPoint SmartgetApointFromXY(double x, double y, String name) { CPoint pt = SmartAddPoint(x, y, name); return pt; } + /** + * Adds a point to the point list and assigns a name if not already set. + * + * @param p the point to add + */ public void addPointToList(CPoint p) { if (p == null) return; @@ -5559,6 +6624,12 @@ public void addPointToList(CPoint p) { this.reCalculate(); } + /** + * Generates a point name based on the given count. + * + * @param n the count used to generate the point name + * @return the generated point name + */ public String getPointNameByCount(int n) { int in = (n) / 26; int number = n - in * 26; @@ -5576,6 +6647,11 @@ public String getPointNameByCount(int n) { return s; } + /** + * Adds an angle to the angle list if it is not already present. + * + * @param ag the angle to add + */ public void addAngleToList(CAngle ag) { if (anglelist.contains(ag)) { return; @@ -5584,32 +6660,27 @@ public void addAngleToList(CAngle ag) { textlist.add(ag.getText()); } + /** + * Adds a line to the line list if it is not already present. + * + * @param line the line to add + */ public void addLineToList(CLine line) { if (linelist.contains(line)) { return; } - -// int in = (this.plineCounter) / 26; -// int number = this.plineCounter - in * 26; -// if (in == 0) { -// char[] c = new char[1]; -// c[0] = (char) (number + 'a'); -// line.m_name = new String(c); -// } else { -// char[] c = new char[2]; -// c[0] = (char) (number + 'a'); -// c[1] = (char) ('0' + in); -// line.m_name = new String(c); -// } String str = new String("l"); str += this.plineCounter; -// plineCounter++; line.m_name = str; this.plineCounter++; linelist.add(line); } - + /** + * Adds a polygon to the polygon list if it is not already present. + * + * @param p the polygon to add + */ public void addPolygonToList(CPolygon p) { if (p == null || polygonlist.contains(p)) return; @@ -5637,6 +6708,12 @@ public void addPolygonToList(CPolygon p) { this.polygonlist.add(p); } + /** + * Draws a line between two points and adds it to the line list if it does not already exist. + * + * @param p1 the first point + * @param p2 the second point + */ public void drawLineAndAdd(CPoint p1, CPoint p2) { if (p1 == null || p2 == null || p1 == p2) return; @@ -5646,6 +6723,11 @@ public void drawLineAndAdd(CPoint p1, CPoint p2) { } } + /** + * Adds a circle to the circle list if it is not already present. + * + * @param c the circle to add + */ public void addCircleToList(Circle c) { if (circlelist.contains(c)) { return; @@ -5657,6 +6739,13 @@ public void addCircleToList(Circle c) { circlelist.add(c); } + /** + * Adds an object to the specified list if it is not already present. + * + * @param obj the object to add + * @param list the list to which the object is added + * @return true if the object was added, false otherwise + */ public boolean addObjectToList(Object obj, Vector list) { if (obj == null) { return false; @@ -5671,20 +6760,40 @@ public boolean addObjectToList(Object obj, Vector list) { return true; } + /** + * Adds a constraint to the constraint list if it is not already present. + * + * @param cs the constraint to add + */ public void addConstraintToList(Constraint cs) { if (cs != null && !constraintlist.contains(cs)) { constraintlist.add(cs); } } + /** + * Removes a constraint from the constraint list. + * + * @param cs the constraint to remove + */ public void removeConstraintFromList(Constraint cs) { constraintlist.remove(cs); } + /** + * Clears all constraints from the constraint list. + */ public void clearAllConstraint() { constraintlist.clear(); } + /** + * Checks if a line exists between two points. + * + * @param p1 the first point + * @param p2 the second point + * @return true if the line exists, false otherwise + */ private boolean isLineExists(CPoint p1, CPoint p2) { for (int i = 0; i < linelist.size(); i++) { CLine ln = (CLine) linelist.get(i); @@ -5695,6 +6804,14 @@ private boolean isLineExists(CPoint p1, CPoint p2) { return false; } + /** + * Checks if a circle exists that passes through three points. + * + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @return true if the circle exists, false otherwise + */ private boolean isCircleExists(CPoint p1, CPoint p2, CPoint p3) { for (int i = 0; i < circlelist.size(); i++) { Circle ln = (Circle) circlelist.get(i); @@ -5706,6 +6823,15 @@ private boolean isCircleExists(CPoint p1, CPoint p2, CPoint p3) { return false; } + /** + * Selects and adds objects (points, lines, circles, and texts) that lie within the rectangular region + * defined by the two diagonal points (x1, y1) and (x2, y2). + * + * @param x1 the x-coordinate of the first corner of the rectangle + * @param y1 the y-coordinate of the first corner of the rectangle + * @param x2 the x-coordinate of the opposite corner of the rectangle + * @param y2 the y-coordinate of the opposite corner of the rectangle + */ public void SelectByRect(double x1, double y1, double x2, double y2) { for (int i = 0; i < pointlist.size(); i++) { CPoint p = (CPoint) pointlist.get(i); @@ -5734,6 +6860,13 @@ public void SelectByRect(double x1, double y1, double x2, double y2) { } + /** + * Handles the mouse button release (up) event by applying snap adjustments and executing actions + * based on the current drawing mode (e.g., line creation, point selection, or transformation). + * + * @param x the x-coordinate where the mouse button was released + * @param y the y-coordinate where the mouse button was released + */ public void DWButtonUp(double x, double y) { this.IsButtonDown = false; @@ -5873,6 +7006,11 @@ public void DWButtonUp(double x, double y) { IsButtonDown = false; } + /** + * Adjusts the position of a free-moving point along its connecting line segments to ensure proper alignment. + * The method checks nearby points on the connected line and snaps the point to the corresponding x or y value + * if within a defined pixel threshold. + */ public void smartPVDragLine() { if (SelectList.size() != 1) return; @@ -5916,6 +7054,13 @@ public void smartPVDragLine() { } + /** + * Processes mouse drag events and updates the position of objects accordingly based on the current drawing action. + * Applies snapping if enabled, and updates positions of points and transformations for the active drawing mode. + * + * @param x the current x-coordinate during the drag + * @param y the current y-coordinate during the drag + */ public void DWMouseDrag(double x, double y) { if (SNAP && CurrentAction != SELECT) { @@ -5996,55 +7141,22 @@ public void DWMouseDrag(double x, double y) { case D_PRATIO: case D_TRATIO: case D_3PCIRCLE: - case D_SQUARE: - case D_IOSTRI: - break; - - } - } - - private int SmartLineType(double x1, double y1, CPoint p2) { - double x2 = p2.getx(); - double y2 = p2.gety(); - - if (Math.abs(x2 - x1) < CMisc.PIXEPS && - Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2) > - 4 * CMisc.PIXEPS * CMisc.PIXEPS) { - return 1; //vertical - } else if (Math.abs(y2 - y1) < CMisc.PIXEPS && - Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2) > - 4 * CMisc.PIXEPS * CMisc.PIXEPS) { - return 2; //horizonal - } else { - return 0; - } - - } - - private int setSmartPVPointLocation(double x1, double y1, CPoint p2) { - double x2 = p2.getx(); - double y2 = p2.gety(); + case D_SQUARE: + case D_IOSTRI: + break; - if (Math.abs(x2 - x1) < CMisc.PIXEPS && - Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2) > - 4 * CMisc.PIXEPS * CMisc.PIXEPS) { - p2.setXY(x1, y2); - return 1; //vertical - } else if (Math.abs(y2 - y1) < CMisc.PIXEPS && - Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2) > - 4 * CMisc.PIXEPS * CMisc.PIXEPS) { - p2.setXY(x2, y1); - return 2; //horizonal - } else { - return 0; } - } + /** + * Adds a perpendicular foot from a point to a line. + * + * @param line the line to which the perpendicular foot is added + * @param p1 the point from which the perpendicular foot is drawn + * @param p the perpendicular foot point + */ public void add_PFOOT(CLine line, CPoint p1, CPoint p) { CLine line1 = new CLine(p1, p); -// constraint c1 = new constraint(constraint.PONLINE, p, line, false); -// constraint c2 = new constraint(constraint.PONLINE, p, line1, false); CPoint[] pl = line.getTowSideOfLine(); Constraint cs = null; if (pl != null) { @@ -6053,17 +7165,12 @@ public void add_PFOOT(CLine line, CPoint p1, CPoint p) { if (pu == null) { this.addPointToList(p); addLineToList(line1); -// this.addConstraintToList(c1); -// this.addConstraintToList(c2); this.addConstraintToList(cs); this.AddPointToLineX(p, line); -// line.addApoint(p); addCTMark(line, line1); - // this.addObjectToList(m, otherlist); line1.addconstraint(cs); this.UndoAdded(line1.getSimpleName() + " perp " + line.getSimpleName() + - // " with foot " + p.m_name); " " + GExpert.getTranslationViaGettext("with foot {0}", p.m_name)); } else { @@ -6076,10 +7183,7 @@ public void add_PFOOT(CLine line, CPoint p1, CPoint p) { if (pu == null) { this.addPointToList(p); addLineToList(line1); -// this.addConstraintToList(c1); -// this.addConstraintToList(c2); addCTMark(line, line1); - // this.addObjectToList(m, otherlist); this.AddPointToLineX(p, line); this.addConstraintToList(cs); line1.addconstraint(cs); @@ -6087,11 +7191,15 @@ public void add_PFOOT(CLine line, CPoint p1, CPoint p) { line.getSimpleName() + " with footy " + p.m_name); } } - } + /** + * Translates all points and text objects by the given delta values. + * + * @param dx the delta x value + * @param dy the delta y value + */ private void translate(double dx, double dy) { - if (isFrozen()) return; @@ -6102,16 +7210,18 @@ private void translate(double dx, double dy) { for (int i = 0; i < textlist.size(); i++) { CText t = (CText) textlist.get(i); t.move(dx, dy); - } this.reCalculate(); - - } - - private void smartFreePointMoved(CPoint pt) { - } + /** + * Updates the location of objects in the list based on the new coordinates. + * + * @param list the list of objects to update + * @param old the old point + * @param x the new x-coordinate + * @param y the new y-coordinate + */ private void ObjectLocationChanged(Vector list, CPoint old, double x, double y) { double x0 = FirstPnt.getx(); double y0 = FirstPnt.gety(); @@ -6181,13 +7291,19 @@ private void ObjectLocationChanged(Vector list, CPoint old, double x, double y) if (isFrozen()) return; - for (int i = 0; i < pointlist.size(); i++) { CPoint p = (CPoint) pointlist.get(i); p.setXY(p.getx() + dx, p.gety() + dy); } } + /** + * Updates the location of a circle and its points based on the given delta values. + * + * @param c the circle to update + * @param dx the delta x value + * @param dy the delta y value + */ private void circleLocationChanged(Circle c, double dx, double dy) { Circle c1 = (Circle) c; CPoint p1 = c1.o; @@ -6197,6 +7313,13 @@ private void circleLocationChanged(Circle c, double dx, double dy) { return; } + /** + * Moves all objects in the list by the given delta values. + * + * @param list the list of objects to move + * @param dx the delta x value + * @param dy the delta y value + */ public void objectsListMoved(Vector list, double dx, double dy) { for (int i = 0; i < list.size(); i++) { CClass c = (CClass) list.get(i); @@ -6209,10 +7332,15 @@ public void objectsListMoved(Vector list, double dx, double dy) { break; } } - - } + /** + * This method is used to move the catch point to the nearest point on the + * object. + * + * @param x the x-coordinate + * @param y the y-coordinate + */ public void DWMouseMove(double x, double y) { if (SNAP && CurrentAction != SELECT) { double[] r = getSnap(x, y); @@ -6398,6 +7526,12 @@ public void DWMouseMove(double x, double y) { } + /** + * Moves the catch point to the specified coordinates if a point is found at those coordinates. + * + * @param x the x-coordinate + * @param y the y-coordinate + */ public void SmartmoveCatchPt(double x, double y) { CPoint pt = this.SelectAPoint(x, y); CatchList.clear(); @@ -6408,6 +7542,12 @@ public void SmartmoveCatchPt(double x, double y) { } } + /** + * Moves the catch point to the specified coordinates if a line is found at those coordinates. + * + * @param x the x-coordinate + * @param y the y-coordinate + */ public void SmartmoveCatchLine(double x, double y) { CLine pt = this.SelectALine(x, y); CatchList.clear(); @@ -6418,12 +7558,24 @@ public void SmartmoveCatchLine(double x, double y) { } } + /** + * Moves the catch point to the specified coordinates, considering all types of objects. + * + * @param x the x-coordinate + * @param y the y-coordinate + */ public void SmartmoveCatch(double x, double y) { SmartmoveCatch(x, y, 0); } - public void SmartmoveCatch(double x, double y, int type) { // 0. All. 1. Point Only. - // 2. Line Only . 3. Circle Only. 4. P and L 5. P and C . 6. L and C. + /** + * Moves the catch point to the specified coordinates, considering specific types of objects. + * + * @param x the x-coordinate + * @param y the y-coordinate + * @param type the type of objects to consider (0: All, 1: Point Only, 2: Line Only, 3: Circle Only, 4: Point and Line, 5: Point and Circle, 6: Line and Circle) + */ + public void SmartmoveCatch(double x, double y, int type) { CatchList.clear(); CatchType = 0; SelectAllFromXY(CatchList, x, y, 1); @@ -6462,7 +7614,12 @@ public void SmartmoveCatch(double x, double y, int type) { // 0. All. 1. Point mouseCatchY = (int) CatchPoint.gety(); } - + /** + * Moves the catch point to the specified coordinates, considering points, lines, and circles. + * + * @param x the x-coordinate + * @param y the y-coordinate + */ public void moveCatch(double x, double y) { int n = CatchList.size(); CatchList.clear(); @@ -6480,6 +7637,12 @@ public void moveCatch(double x, double y) { panel.repaint(); } + /** + * Finds the intersection point of two objects (lines or circles) in the catch list. + * + * @param x the x-coordinate + * @param y the y-coordinate + */ public void get_Catch_Intersection(double x, double y) { int k = 0; CLine ln = null; @@ -6534,7 +7697,15 @@ else if (o2 == null) } } - public boolean Smart(CPoint p, double x, double y) { // set p to a point on obj and near x,y + /** + * Sets the given point to the specified coordinates and checks if it is on any geometric object. + * + * @param p the point to set + * @param x the x-coordinate + * @param y the y-coordinate + * @return true if the point is on an object, false otherwise + */ + public boolean Smart(CPoint p, double x, double y) { p.setXY(x, y); CPoint pt = SmartPoint(p); if (pt != null) { @@ -6551,12 +7722,18 @@ public boolean Smart(CPoint p, double x, double y) { // set p to a point on obj return false; } - public CPoint SmartAddPoint(double x, double y) { // add a new point to drawing with x,y + /** + * Adds a new point to the drawing at the specified coordinates. + * + * @param x the x-coordinate + * @param y the y-coordinate + * @return the created point, or an existing point if one is found at the coordinates + */ + public CPoint SmartAddPoint(double x, double y) { CPoint pt = SelectAPoint(x, y); if (pt != null) return pt; - Vector v = new Vector(); SelectFromAList(v, linelist, x, y); SelectFromAList(v, circlelist, x, y); @@ -6584,12 +7761,19 @@ public CPoint SmartAddPoint(double x, double y) { // add a new point to drawing return p; } - public CPoint SmartAddPoint(double x, double y, String name) { // add a new point to drawing with x,y + /** + * Adds a new point to the drawing at the specified coordinates with a given name. + * + * @param x the x-coordinate + * @param y the y-coordinate + * @param name the name of the new point + * @return the created point, or an existing point if one is found at the coordinates + */ + public CPoint SmartAddPoint(double x, double y, String name) { CPoint pt = SelectAPoint(x, y); if (pt != null) return pt; - Vector v = new Vector(); SelectFromAList(v, linelist, x, y); SelectFromAList(v, circlelist, x, y); @@ -6617,27 +7801,24 @@ public CPoint SmartAddPoint(double x, double y, String name) { // add a new poin return p; } - public Object SmartPointOnWhich(CPoint p) { - CPoint pt = SmartPoint(p); - if (pt != null) { - return pt; - } - CLine line = SmartPLine(p); - if (line != null) { - return line; - } - Circle c = SmartPCircle(p); - if (c != null) { - return c; - } - return null; - } - - + /** + * Selects a line from the drawing that is near the specified coordinates. + * + * @param x the x-coordinate + * @param y the y-coordinate + * @return the selected line, or null if no line is found + */ public CLine SelectALine(double x, double y) { return SmartPointOnLine(x, y); } + /** + * Selects a circle from the drawing that is near the specified coordinates. + * + * @param x the x-coordinate + * @param y the y-coordinate + * @return the selected circle, or null if no circle is found + */ public Circle SelectACircle(double x, double y) { for (int i = 0; i < circlelist.size(); i++) { Circle c = (Circle) circlelist.get(i); @@ -6648,6 +7829,13 @@ public Circle SelectACircle(double x, double y) { return null; } + /** + * Selects a point from the drawing that is near the specified coordinates. + * + * @param x the x-coordinate + * @param y the y-coordinate + * @return the selected point, or null if no point is found + */ public CPoint SelectAPoint(double x, double y) { CPoint pt = null; for (int i = 0; i < pointlist.size(); i++) { @@ -6660,24 +7848,9 @@ public CPoint SelectAPoint(double x, double y) { return pt; } - - public void clearFlashAndAdd(Vector v) { - clearFlash(); - flashlist.addAll(v); - } - - public void clear_but_angle() { - for (int i = 0; i < flashlist.size(); i++) { - JFlash ff = (JFlash) flashlist.get(i); - if (ff instanceof JAngleFlash) { - continue; - } - ff.stop(); - flashlist.remove(i); - i--; - } - } - + /** + * Starts and stops the flashing process for flash items in the flash list. + */ public void doFlash() { for (int i = 0; i < flashlist.size(); i++) { JFlash ff = (JFlash) flashlist.get(i); @@ -6692,6 +7865,9 @@ public void doFlash() { } } + /** + * Clears all flash items from the flash list. + */ public void clearFlash() { for (int i = 0; i < flashlist.size(); i++) { JFlash ff = (JFlash) flashlist.get(i); @@ -6700,6 +7876,11 @@ public void clearFlash() { flashlist.clear(); } + /** + * Adds a flash item to the flash list and starts it. + * + * @param f the flash item to add + */ public void addFlash(JFlash f) { if (f == null) return; @@ -6709,6 +7890,15 @@ public void addFlash(JFlash f) { f.start(); } + /** + * Finds the common point between two lines or a line and a point. + * + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @param p4 the fourth point + * @return the common point if found, otherwise null + */ public CPoint getCommonPoint(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { CLine ln1 = this.fd_line(p1, p2); CLine ln2 = this.fd_line(p3, p4); @@ -6749,9 +7939,15 @@ public CPoint getCommonPoint(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { } } return null; - } + /** + * Adds two JCgFlash items and a JFlash item to the flash list. + * + * @param f1 the first JCgFlash item + * @param f2 the second JCgFlash item + * @param f the JFlash item + */ public void addCgFlash(JCgFlash f1, JCgFlash f2, JFlash f) { int size = flashlist.size(); int n = 0; @@ -6789,10 +7985,9 @@ public void addCgFlash(JCgFlash f1, JCgFlash f2, JFlash f) { addFlashx(f2); } - public boolean isInAction() { - return STATUS != 0 || SelectList.size() != 0; - } - + /** + * Starts the flashing process for flash items in the flash list. + */ public void startFlash() { for (int j = 0; j < flashlist.size(); j++) { JFlash fx = (JFlash) flashlist.get(j); @@ -6805,6 +8000,11 @@ public void startFlash() { } } + /** + * Adds the specified flash object before any existing JRedoStepFlash in the flash list. + * + * @param f the flash object to add + */ public void addFlash2(JFlash f) { for (int i = 0; i < flashlist.size(); i++) { if (flashlist.get(i) instanceof JRedoStepFlash) { @@ -6815,6 +8015,11 @@ public void addFlash2(JFlash f) { addFlash1(f); } + /** + * Adds the specified flash object and starts it immediately if it is the only flash item. + * + * @param f the flash object to add + */ public void addFlash1(JFlash f) { addFlashx(f); @@ -6822,6 +8027,12 @@ public void addFlash1(JFlash f) { f.start(); } + /** + * Adds the specified flash object to the flash list if not already present. + * For JAngleFlash instances, adjusts the flash radius based on the number of similar flash objects. + * + * @param f the flash object to add + */ public void addFlashx(JFlash f) { if (f == null) return; @@ -6850,6 +8061,11 @@ public void addFlashx(JFlash f) { flashlist.add(f); } + /** + * Checks whether the flash process is finished. + * + * @return {@code true} if there are no flash items or the sole flash item has finished; {@code false} otherwise + */ public boolean isFlashFinished() { int n = flashlist.size(); if (n == 0) return true; @@ -6859,6 +8075,12 @@ public boolean isFlashFinished() { } + /** + * Draws all flash items to the provided Graphics2D object, starts flash processes if necessary, + * and triggers a proof run when all flashes are finished. + * + * @param g2 the graphics context used for drawing + */ public void drawFlash(Graphics2D g2) { if (flashlist.size() == 0) return; @@ -6891,6 +8113,12 @@ public void drawFlash(Graphics2D g2) { } } + /** + * Paints the current drawing scene including grid, undo objects, various shape lists, flashes, + * points, texts, and catch objects. Also draws additional components such as the track point. + * + * @param g the graphics context used for painting + */ public void paintPoint(Graphics g) { Graphics2D g2 = (Graphics2D) g; @@ -6927,6 +8155,11 @@ public void paintPoint(Graphics g) { drawTrackpt(g2); } + /** + * Draws the tracking point on the given Graphics2D context and adds it to the corresponding trace list. + * + * @param g2 the graphics context used for drawing + */ public void drawTrackpt(Graphics2D g2) { if (CTrackPt == null) return; @@ -6941,6 +8174,12 @@ public void drawTrackpt(Graphics2D g2) { } } + /** + * Returns the trace object that contains the current tracking point. + * + * @param pt the point used to identify the corresponding trace + * @return the matching CTrace if found; otherwise, {@code null} + */ public CTrace getTraceByPt(CPoint pt) { for (int i = 0; i < tracelist.size(); i++) { CTrace tr = (CTrace) tracelist.get(i); @@ -6950,6 +8189,12 @@ public CTrace getTraceByPt(CPoint pt) { return null; } + /** + * Adjusts the position of point p2 relative to point p1 to enforce a smart horizontal or vertical alignment. + * + * @param p1 the reference point + * @param p2 the point to be adjusted + */ public void setSmartPVLine(CPoint p1, CPoint p2) { if (p1 == null || p2 == null) { return; @@ -6972,6 +8217,14 @@ public void setSmartPVLine(CPoint p1, CPoint p2) { } + /** + * Draws a smart PV (parallel or vertical/horizontal) line between p1 and p2. + * If the line is nearly horizontal or vertical and sufficiently long, the line is extended accordingly. + * + * @param p1 the starting point of the line + * @param p2 the target point for alignment and extension + * @param g2 the graphics context used for drawing + */ public void drawSmartPVLine(CPoint p1, CPoint p2, Graphics2D g2) { int x, y; x = y = 0; @@ -7017,6 +8270,12 @@ public void drawSmartPVLine(CPoint p1, CPoint p2, Graphics2D g2) { g2.drawLine((int) p1.getx(), (int) p1.gety(), x, y); } + /** + * Draws the current action environment including auxiliary lines, selection outlines, + * and other drawing components based on the current action state. + * + * @param g2 the graphics context used for drawing + */ public void drawCurrentAct(Graphics2D g2) { // if (trackPoint != null) { @@ -7717,7 +8976,12 @@ public void drawCurrentAct(Graphics2D g2) { drawCatchObjName(g2); } - + /** + * Sets the first point for transformation and updates the translation offsets. + * + * @param x the new x-coordinate + * @param y the new y-coordinate + */ public void setFirstPnt(double x, double y) { if (FirstPnt != null) { vtrx = x - FirstPnt.getx(); @@ -7725,6 +8989,15 @@ public void setFirstPnt(double x, double y) { } } + /** + * Sets the transformation status and updates related points and selections. + * + *

When t is 0, the selection is cleared. + * When t is 2, the first point's coordinates are updated based on current catch values + * and a repaint is requested.

+ * + * @param t the new transformation status + */ public void setTransformStatus(int t) { if (t == 0) { @@ -7743,23 +9016,26 @@ public void setTransformStatus(int t) { STATUS = t; } + /** + * Requests a repaint of the panel. + */ public void repaint() { panel.repaint(); } - double[] getFootPosition(double xc, double yc, double x1, double y1, double x2, double y2) { - double dlx = x2 - x1; - double dly = y2 - y1; - double dl = dlx * dlx + dly * dly; - - double x = ((y2 - yc) * dlx * dly + dly * dly * xc + dlx * dlx * x2) / dl; - double y = ((x2 - xc) * dlx * dly + dlx * dlx * yc + dly * dly * y2) / dl; - double[] n = new double[2]; - n[0] = x; - n[1] = y; - return n; - } - + /** + * Calculates the intersection point of a perpendicular line from a point to a line segment. + * + * @param x the x coordinate of the point + * @param y the y coordinate of the point + * @param xa the x coordinate of the first endpoint of the line segment + * @param ya the y coordinate of the first endpoint of the line segment + * @param x1 the x coordinate of the second endpoint of the line segment + * @param y1 the y coordinate of the second endpoint of the line segment + * @param x2 the x coordinate of the third endpoint of the line segment + * @param y2 the y coordinate of the third endpoint of the line segment + * @return an array containing the x and y coordinates of the intersection point + */ double[] getPTInterSection(double x, double y, double xa, double ya, double x1, double y1, double x2, double y2) { double k = (y2 - y1) / (x2 - x1); double xt = (y - ya + k * xa + x / k) / (k + 1 / k); @@ -7775,6 +9051,16 @@ public void repaint() { } + /** + * Adds a flash polygon effect between two polygons. + * + * @param p1 the first polygon + * @param p2 the second polygon + * @param t the flash type identifier + * @param ct a flag for custom behavior + * @param xc the x coordinate for the flash center + * @param yc the y coordinate for the flash center + */ public void addFlashPolygon(CPolygon p1, CPolygon p2, int t, boolean ct, double xc, double yc) { int n = p1.getPtn(); if (n != p2.getPtn()) return; @@ -7782,6 +9068,14 @@ public void addFlashPolygon(CPolygon p1, CPolygon p2, int t, boolean ct, double this.addFlash2(f); } + /** + * Draws an auxiliary line with a dashed stroke based on a given slope. + * + * @param x the x coordinate of the starting point + * @param y the y coordinate of the starting point + * @param k the slope of the line + * @param g2 the Graphics2D context used for drawing + */ public void drawAuxLine(int x, int y, double k, Graphics2D g2) { g2.setColor(Color.red); g2.setStroke(CMisc.DashedStroke); @@ -7797,12 +9091,15 @@ public void drawAuxLine(int x, int y, double k, Graphics2D g2) { } } - public CClass getFirstCatchObject() { - if (CatchList.size() == 0) return null; - return (CClass) CatchList.get(0); - } - - //./public double get + /** + * Adds an isosceles angle constraint by adjusting the third point. + * + * @param p1 the first point defining the base of the triangle + * @param p2 the second point defining the base of the triangle + * @param p the point to be adjusted to form an isosceles triangle + * @param type the angle type indicator (0 for standard isosceles) + * @return true if the constraint is successfully added, false otherwise + */ public boolean addisoAngle(CPoint p1, CPoint p2, CPoint p, int type) { @@ -7869,7 +9166,14 @@ public boolean addisoAngle(CPoint p1, CPoint p2, CPoint p, int type) { return true; } - + /** + * Constructs a square by using two initial points and adjusting a third point. + * + * @param p1 the first point on the square + * @param p2 the second point on the square + * @param p a point used to determine the orientation and size of the square + * @return true if the square is successfully constructed, false otherwise + */ public boolean addsquare(CPoint p1, CPoint p2, CPoint p) { CPoint t1, t2; t1 = p1; @@ -7989,6 +9293,13 @@ public boolean addsquare(CPoint p1, CPoint p2, CPoint p) { return true; } + /** + * Adds a line defined by two points to the drawing. + * If the line already exists, the points are added to it. + * + * @param p1 the first endpoint of the line + * @param p2 the second endpoint of the line + */ public void add_line(CPoint p1, CPoint p2) { CLine ln = null; if ((ln = this.fd_line(p1, p2)) != null) { @@ -8001,28 +9312,12 @@ public void add_line(CPoint p1, CPoint p2) { this.addLineToList(ln); } - public void drawTrackPoint(CPoint p, Graphics2D g2) { - int x = (int) p.getx(); - int y = (int) p.gety(); - g2.setStroke(CMisc.NormalLineStroke); - g2.setColor(Color.white); - g2.fillOval(x - 5, y - 5, 10, 10); - g2.setColor(Color.black); - g2.drawOval(x - 5, y - 5, 10, 10); - p.setDraw(g2); - - g2.fillOval(x - 3, y - 3, 6, 6); - - } - - public void drawselectPoint(CPoint p, Graphics2D g2) { - int x = (int) p.getx(); - int y = (int) p.gety(); - - g2.setColor(CMisc.SelectObjectColor); - g2.fillOval(x - 7, y - 7, 14, 14); - } - + /** + * Finds a point in the drawing that matches the given point's coordinates. + * + * @param p the point to match + * @return the matching point if found, otherwise null + */ public CPoint SmartPoint(CPoint p) { CPoint pt = SelectAPoint((int) p.getx(), (int) p.gety()); if (pt != null) { @@ -8032,6 +9327,12 @@ public CPoint SmartPoint(CPoint p) { return null; } + /** + * Finds a line in the drawing that contains the given point. + * + * @param p the point to match + * @return the matching line if found, otherwise null + */ public CLine SmartPLine(CPoint p) { CLine line = SmartPointOnLine(p.getx(), p.gety()); if (line != null) { @@ -8041,6 +9342,12 @@ public CLine SmartPLine(CPoint p) { return null; } + /** + * Finds a circle in the drawing that contains the given point. + * + * @param p the point to match + * @return the matching circle if found, otherwise null + */ public Circle SmartPCircle(CPoint p) { for (int i = 0; i < circlelist.size(); i++) { Circle c = (Circle) circlelist.get(i); @@ -8052,6 +9359,13 @@ public Circle SmartPCircle(CPoint p) { return null; } + /** + * Finds a line in the drawing that is near the given coordinates. + * + * @param x the x-coordinate to match + * @param y the y-coordinate to match + * @return the matching line if found, otherwise null + */ public CLine SmartPointOnLine(double x, double y) { double dis = Double.MAX_VALUE; CLine ln = null; @@ -8065,7 +9379,6 @@ public CLine SmartPointOnLine(double x, double y) { ln = line; } } - } if (dis < CMisc.PIXEPS) { return ln; @@ -8074,48 +9387,72 @@ public CLine SmartPointOnLine(double x, double y) { } } - + /** + * Creates a new point with the given coordinates. + * + * @param x the x-coordinate of the new point + * @param y the y-coordinate of the new point + * @return the created point, or null if the parameter limit is exceeded + */ public CPoint CreateANewPoint(double x, double y) { if (paraCounter > 1023) { CMisc.print("point overflow."); return null; } - Param p1 = parameter[paraCounter - - 1] = new Param(paraCounter++, x); - Param p2 = parameter[paraCounter - - 1] = new Param(paraCounter++, y); + Param p1 = parameter[paraCounter - 1] = new Param(paraCounter++, x); + Param p2 = parameter[paraCounter - 1] = new Param(paraCounter++, y); CPoint p = new CPoint(p1, p2); - // this.setTextPositionAutomatically(p.ptext); + // this.setTextPositionAutomatically(p.ptext); return p; } + /** + * Creates a new point with the given coordinates and name. + * + * @param x the x-coordinate of the new point + * @param y the y-coordinate of the new point + * @param name the name of the new point + * @return the created point, or null if the parameter limit is exceeded + */ public CPoint CreateANewPoint(double x, double y, String name) { if (paraCounter > 1023) { CMisc.print("point overflow."); return null; } - Param p1 = parameter[paraCounter - - 1] = new Param(paraCounter++, x); - Param p2 = parameter[paraCounter - - 1] = new Param(paraCounter++, y); + Param p1 = parameter[paraCounter - 1] = new Param(paraCounter++, x); + Param p2 = parameter[paraCounter - 1] = new Param(paraCounter++, y); CPoint p = new CPoint(name, p1, p2); - // this.setTextPositionAutomatically(p.ptext); + // this.setTextPositionAutomatically(p.ptext); return p; } + /** + * Finds or creates a point at the intersection of two lines. + * + * @param line1 the first line + * @param line2 the second line + * @return the intersection point, or null if the lines are parallel or already intersect + */ public CPoint MeetDefineAPoint(CLine line1, CLine line2) { return MeetDefineAPoint(line1, line2, true); } + /** + * Finds or creates a point at the intersection of two lines, optionally ensuring uniqueness. + * + * @param line1 the first line + * @param line2 the second line + * @param unique whether to ensure the intersection point is unique + * @return the intersection point, or null if the lines are parallel or already intersect + */ public CPoint MeetDefineAPoint(CLine line1, CLine line2, boolean unique) { if (CLine.commonPoint(line1, line2) != null) return null; if (check_para(line1, line2)) { JOptionPane.showMessageDialog(gxInstance, gxInstance.getLanguage("The two lines you selected are parallel" + - ", don't have any intersection!") - , gxInstance.getLanguage("No intersection"), JOptionPane.ERROR_MESSAGE); + ", don't have any intersection!"), gxInstance.getLanguage("No intersection"), JOptionPane.ERROR_MESSAGE); return null; } @@ -8149,8 +9486,6 @@ public CPoint MeetDefineAPoint(CLine line1, CLine line2, boolean unique) { CPoint p = this.CreateANewPoint(0, 0); Constraint cs1 = new Constraint(Constraint.INTER_LL, p, line1, line2); CPoint tp = this.addADecidedPointWithUnite(p); -// poly.printpoly(p.x1.m); -// poly.printpoly(p.y1.m); if (tp != null && unique) { line2.addApoint(tp); line1.addApoint(tp); @@ -8160,7 +9495,6 @@ public CPoint MeetDefineAPoint(CLine line1, CLine line2, boolean unique) { addConstraintToList(cs1); line1.addApoint(p); line2.addApoint(p); -// this.charsetAndAddPoly(false); } this.UndoAdded(p.m_name + ": intersection of " + line1.getDiscription() + " and " + @@ -8170,6 +9504,16 @@ public CPoint MeetDefineAPoint(CLine line1, CLine line2, boolean unique) { return null; } + /** + * Finds or creates a point at the intersection of a line and a circle. + * + * @param line the line + * @param c the circle + * @param m whether to move the point to the given coordinates + * @param x the x-coordinate to move the point to + * @param y the y-coordinate to move the point to + * @return the intersection point, or null if the line and circle do not intersect + */ public CPoint MeetLCToDefineAPoint(CLine line, Circle c, boolean m, double x, double y) { CPoint p = null; CPoint p1 = null; @@ -8218,7 +9562,6 @@ public CPoint MeetLCToDefineAPoint(CLine line, Circle c, boolean m, double x, do return pt; } - CPoint pout = this.CreateANewPoint(0, 0); this.addPointToList(pout); Constraint css = new Constraint(Constraint.INTER_LC, pout, line, c); @@ -8226,14 +9569,10 @@ public CPoint MeetLCToDefineAPoint(CLine line, Circle c, boolean m, double x, do if (m) pout.setXY(x, y); -// constraint cs1 = new constraint(constraint.PONLINE, pout, line, false); -// constraint cs2 = new constraint(constraint.PONCIRCLE, pout, c, false); line.addApoint(pout); c.addPoint(pout); this.addPointToList(pout); this.addConstraintToList(css); -// this.addConstraintToList(cs1); -// this.addConstraintToList(cs2); this.UndoAdded(pout.m_name + ": intersection of " + line.getDiscription() + " and " + c.getDescription()); @@ -8241,15 +9580,23 @@ public CPoint MeetLCToDefineAPoint(CLine line, Circle c, boolean m, double x, do return pout; } + /** + * Finds or creates a point at the intersection of two circles. + * + * @param c1 the first circle + * @param c2 the second circle + * @param m whether to move the point to the given coordinates + * @param x the x-coordinate to move the point to + * @param y the y-coordinate to move the point to + * @return the intersection point, or null if the circles do not intersect + */ public CPoint MeetCCToDefineAPoint(Circle c1, Circle c2, boolean m, double x, double y) { CPoint p = null; CPoint p1 = null; - if (!check_cc_inter(c1, c2)) { JOptionPane.showMessageDialog(gxInstance, gxInstance.getLanguage("The circles you selected don't have any intersection"), - gxInstance.getLanguage("No intersection"), - JOptionPane.ERROR_MESSAGE); + gxInstance.getLanguage("No intersection"), JOptionPane.ERROR_MESSAGE); return null; } for (int i = 0; i < c1.points.size(); i++) { @@ -8270,15 +9617,12 @@ public CPoint MeetCCToDefineAPoint(Circle c1, Circle c2, boolean m, double x, do if (p == null) { CPoint pt = this.CreateANewPoint(0, 0); -// constraint cs = new constraint(constraint.PONCIRCLE, pt, c1); -// constraint cs1 = new constraint(constraint.PONCIRCLE, pt, c2); Constraint cs = new Constraint(Constraint.INTER_CC, pt, c1, c2); if (m) pt.setXY(x, y); this.charsetAndAddPoly(true); if (m || mulSolutionSelect(pt)) { this.addConstraintToList(cs); -// this.addConstraintToList(cs1); c1.addPoint(pt); c2.addPoint(pt); this.addPointToList(pt); @@ -8290,21 +9634,14 @@ public CPoint MeetCCToDefineAPoint(Circle c1, Circle c2, boolean m, double x, do gxInstance.setTipText("Circle " + c1.m_name + " and Circle " + c2.m_name + " can not intersect"); } - return pt; } CPoint pt = this.CreateANewPoint(0, 0); -// constraint cs = new constraint(constraint.INTER_CC1, pt, p, c1, c2); - -// constraint cs2 = new constraint(constraint.PONCIRCLE, pt, c1, false); -// constraint cs3 = new constraint(constraint.PONCIRCLE, pt, c2, false); Constraint cs = new Constraint(Constraint.INTER_CC, pt, c1, c2); CPoint pu = this.addADecidedPointWithUnite(pt); if (pu == null) { this.addConstraintToList(cs); -// this.addConstraintToList(cs2); -// this.addConstraintToList(cs3); this.addPointToList(pt); c1.addPoint(pt); c2.addPoint(pt); @@ -8318,6 +9655,12 @@ public CPoint MeetCCToDefineAPoint(Circle c1, Circle c2, boolean m, double x, do return pt; } + /** + * Adds a point to a line if it is not already on the line. + * + * @param p the point to add + * @param ln the line to add the point to + */ public void AddPointToLineX(CPoint p, CLine ln) { if (ln.containPT(p)) return; @@ -8327,6 +9670,13 @@ public void AddPointToLineX(CPoint p, CLine ln) { this.addConstraintToList(cs); } + /** + * Adds a point to a circle and optionally adds an undo action. + * + * @param p the point to add + * @param c the circle to add the point to + * @param un whether to add an undo action + */ public void AddPointToCircle(CPoint p, Circle c, boolean un) { c.addPoint(p); Constraint cs = new Constraint(Constraint.PONCIRCLE, p, c); @@ -8335,16 +9685,24 @@ public void AddPointToCircle(CPoint p, Circle c, boolean un) { if (un) this.UndoAdded(p.TypeString() + " on " + c.getDescription()); } - public void AddPointToCircle(CPoint p, Circle c) { - AddPointToCircle(p, c, true); - } - + /** + * Adds a point to a line and adds an undo action. + * + * @param p the point to add + * @param line the line to add the point to + */ public void AddPointToLine(CPoint p, CLine line) { AddPointToLine(p, line, true); } + /** + * Adds a point to a line and optionally adds an undo action. + * + * @param p the point to add + * @param line the line to add the point to + * @param un whether to add an undo action + */ public void AddPointToLine(CPoint p, CLine line, boolean un) { - if (line.containPT(p)) return; line.addApoint(p); @@ -8356,12 +9714,10 @@ public void AddPointToLine(CPoint p, CLine line, boolean un) { if (un) { this.UndoAdded(p.getDescription()); } - } else { switch (line.type) { case CLine.PLine: { - Constraint cs = null; - cs = new Constraint(Constraint.PONLINE, p, line, false); + Constraint cs = new Constraint(Constraint.PONLINE, p, line, false); this.addConstraintToList(cs); Constraint cs1 = line.getconsByType(Constraint.PARALLEL); @@ -8387,8 +9743,7 @@ public void AddPointToLine(CPoint p, CLine line, boolean un) { } break; case CLine.BLine: { - Constraint cs = null; - cs = new Constraint(Constraint.PONLINE, p, line, false); + Constraint cs = new Constraint(Constraint.PONLINE, p, line, false); this.addConstraintToList(cs); Constraint cs1 = line.getconsByType(Constraint.BLINE); @@ -8475,23 +9830,14 @@ public void AddPointToLine(CPoint p, CLine line, boolean un) { break; } } - - } - - public void GeneratePoly(Constraint cs) { - if (cs == null) { - return; - } - cs.PolyGenerate(); - TPoly pl = Constraint.getPolyListAndSetNull(); - TPoly tp = pl; - while (tp.getNext() != null) { - tp = tp.getNext(); - } - tp.setNext(polylist); - polylist = pl; } + /** + * Adds a decided point to the list and checks for common points. + * + * @param p the point to add + * @return the common point if found, otherwise null + */ public CPoint addADecidedPointWithUnite(CPoint p) { boolean r = pointlist.add(p); this.charsetAndAddPoly(false); @@ -8507,9 +9853,13 @@ public CPoint addADecidedPointWithUnite(CPoint p) { eraseAPoly(p.y1.m); CMisc.showMessage("Point " + tp.m_name + " already exists"); return tp; - } + /** + * Erases a polynomial from the list. + * + * @param m the polynomial to erase + */ public void eraseAPoly(TMono m) { TPoly t1 = null; TPoly t = polylist; @@ -8523,11 +9873,15 @@ public void eraseAPoly(TMono m) { t1 = t; t = t.getNext(); } - } - public CPoint CheckCommonPoint(CPoint p) { //gometry coincident. - + /** + * Checks for a common point in the list. + * + * @param p the point to check + * @return the common point if found, otherwise null + */ + public CPoint CheckCommonPoint(CPoint p) { TPoly plist = polylist; while (plist != null) { TMono mm = plist.getPoly(); @@ -8556,7 +9910,13 @@ public CPoint CheckCommonPoint(CPoint p) { //gometry coincident. return null; } - public CPoint isPointAlreadyExists(CPoint p) { // phisical coincident + /** + * Checks if a point already exists in the list. + * + * @param p the point to check + * @return the existing point if found, otherwise null + */ + public CPoint isPointAlreadyExists(CPoint p) { for (int i = 0; i < pointlist.size(); i++) { CPoint t = (CPoint) pointlist.get(i); if (t == p) { @@ -8569,6 +9929,9 @@ public CPoint isPointAlreadyExists(CPoint p) { // phisical coincident return null; } + /** + * Sets variables for the points in the list. + */ public void SetVarable() { TPoly plist = polylist; while (plist != null) { @@ -8589,7 +9952,13 @@ public void SetVarable() { } } - + /** + * Selects a polygon that contains the specified point. + * + * @param x the x coordinate of the selection point. + * @param y the y coordinate of the selection point. + * @return the selected polygon, or null if no polygon is selected. + */ public CPolygon SelectAPolygon(double x, double y) { Vector v = new Vector(); SelectFromAList(v, polygonlist, x, y); @@ -8601,6 +9970,14 @@ public CPolygon SelectAPolygon(double x, double y) { } + /** + * Selects the first object from the given list that is hit by the specified coordinates. + * + * @param list the list of objects to search. + * @param x the x coordinate of the selection point. + * @param y the y coordinate of the selection point. + * @return the selected object, or null if none are hit. + */ public CClass SelectFromAList(Vector list, double x, double y) { if (list == null) { return null; @@ -8615,22 +9992,10 @@ public CClass SelectFromAList(Vector list, double x, double y) { return null; } - public void NameFontSizeChange(int n) { - for (int i = 0; i < textlist.size(); i++) { - CText t = (CText) textlist.get(i); - if (t.getType() == CText.NAME_TEXT && t.getFontSize() <= 5) - return; - } - - - for (int i = 0; i < textlist.size(); i++) { - CText t = (CText) textlist.get(i); - if (t.getType() == CText.NAME_TEXT) - t.fontsizeChange(n); - } - panel.repaint(); - } - + /** + * Regenerates all polynomial representations, clears current constraints, + * and optimizes polynomials based on the existing constraints. + */ public void re_generate_all_poly() { polylist = pblist = null; Vector v = new Vector(); @@ -8649,6 +10014,13 @@ public void re_generate_all_poly() { } } + /** + * Opens an output file at the specified path. + * + * @param path the file path where the output file is to be created. + * @return a DataOutputStream for writing to the file. + * @throws IOException if an error occurs while opening or creating the file. + */ public DataOutputStream openOutputFile(String path) throws IOException { FileOutputStream fp; File f = new File(path); @@ -8668,13 +10040,13 @@ public DataOutputStream openOutputFile(String path) throws IOException { return out; } - boolean Save(String name) throws IOException { - boolean r = Save(openOutputFile(name)); - file = new File(name); - needSave = false; - return r; - } - + /** + * Saves the current state to the provided DataOutputStream. + * + * @param out the output stream to which the state is written. + * @return true if the state is saved successfully. + * @throws IOException if an I/O error occurs during saving. + */ boolean Save(DataOutputStream out) throws IOException { if (cpfield != null) { cpfield.run_to_end(this); @@ -8825,6 +10197,13 @@ boolean Save(DataOutputStream out) throws IOException { return true; } + /** + * Opens an input file from the specified path. + * + * @param path the path of the file to be opened. + * @return a DataInputStream for reading from the file, or null if the file does not exist. + * @throws IOException if an error occurs while opening the file. + */ DataInputStream openInputFile(String path) throws IOException { File f = new File(path); FileInputStream fp; @@ -8841,11 +10220,25 @@ DataInputStream openInputFile(String path) throws IOException { return in; } + /** + * Loads the current state from a file specified by its name. + * + * @param name the name of the file to load. + * @return true if the file is loaded successfully; false otherwise. + * @throws IOException if an error occurs during file loading. + */ boolean Load(String name) throws IOException { File f = new File(name); return Load(f); } + /** + * Loads the current state from the given file. + * + * @param f the file to load. + * @return true if the state is loaded successfully; false otherwise. + * @throws IOException if an error occurs during file loading. + */ boolean Load(File f) throws IOException { FileInputStream fp; if (f.exists()) { @@ -8864,6 +10257,13 @@ boolean Load(File f) throws IOException { return n; } + /** + * Loads the current state from the provided DataInputStream. + * + * @param in the DataInputStream from which the state is read. + * @return true if the state is loaded successfully; false otherwise. + * @throws IOException if an error occurs during the reading process. + */ boolean Load(DataInputStream in) throws IOException { byte[] tl = new byte[2]; in.read(tl, 0, tl.length); @@ -9103,6 +10503,12 @@ boolean Load(DataInputStream in) throws IOException { } + /** + * Saves the global state to the specified output stream. + * + * @param out the output stream to save the global state to + * @throws IOException if an I/O error occurs + */ public void Save_global(DataOutputStream out) throws IOException { DrawData.Save(out); int index = UndoStruct.INDEX; @@ -9110,6 +10516,12 @@ public void Save_global(DataOutputStream out) throws IOException { CMisc.Save(out); } + /** + * Loads the global state from the specified input stream. + * + * @param in the input stream to load the global state from + * @throws IOException if an I/O error occurs + */ public void Load_global(DataInputStream in) throws IOException { if (CMisc.version_load_now < 0.010) { int size = in.readInt(); @@ -9131,9 +10543,17 @@ public void Load_global(DataInputStream in) throws IOException { footMarkLength = CMisc.FOOT_MARK_LENGTH; } - boolean write_ps(String name, int stype, boolean ptf, boolean pts) throws - IOException { // 0: color 1: gray ; 2: black and white - + /** + * Writes the drawing to a PostScript file. + * + * @param name the name of the PostScript file + * @param stype the style type (0: color, 1: gray, 2: black and white) + * @param ptf whether to include points in the file + * @param pts whether to include the cpfield in the file + * @return true if the file was written successfully, false otherwise + * @throws IOException if an I/O error occurs + */ + boolean write_ps(String name, int stype, boolean ptf, boolean pts) throws IOException { FileOutputStream fp; File f = new File(name); if (f.exists()) { @@ -9147,11 +10567,9 @@ boolean write_ps(String name, int stype, boolean ptf, boolean pts) throws return false; } -// int y, m, d; Calendar c = Calendar.getInstance(); String stime = "%Create Time: " + c.getTime().toString() + "\n"; - String sversion = "%Created By: " + Version.getNameAndVersion() + - "\n"; + String sversion = "%Created By: " + Version.getNameAndVersion() + "\n"; String s = "%!PS-Adobe-2.0\n" + stime + sversion + "\n" + "%%BoundingBox: 0 500 400 650\n" + @@ -9206,6 +10624,13 @@ boolean write_ps(String name, int stype, boolean ptf, boolean pts) throws return true; } + /** + * Writes the perpendicular foot to the PostScript file. + * + * @param fp the file output stream + * @param stype the style type + * @throws IOException if an I/O error occurs + */ void write_perp_foot(FileOutputStream fp, int stype) throws IOException { Vector vlist = new Vector(); this.drawPerpFoot(null, vlist, 1); @@ -9234,8 +10659,16 @@ void write_perp_foot(FileOutputStream fp, int stype) throws IOException { fp.write("stroke \n".getBytes()); } - void write_list_ps(FileOutputStream fp, Vector vlist, String discription, - int stype) throws IOException { + /** + * Writes a list of objects to the PostScript file. + * + * @param fp the file output stream + * @param vlist the list of objects to write + * @param discription the description of the list + * @param stype the style type + * @throws IOException if an I/O error occurs + */ + void write_list_ps(FileOutputStream fp, Vector vlist, String discription, int stype) throws IOException { if (vlist.size() != 0) { fp.write((discription).getBytes()); } @@ -9245,8 +10678,14 @@ void write_list_ps(FileOutputStream fp, Vector vlist, String discription, } } - private void SaveDrawAttr(FileOutputStream fp, int stype) throws - IOException { + /** + * Saves the drawing attributes to the PostScript file. + * + * @param fp the file output stream + * @param stype the style type + * @throws IOException if an I/O error occurs + */ + private void SaveDrawAttr(FileOutputStream fp, int stype) throws IOException { Vector vc = new Vector(); Vector vd = new Vector(); Vector vw = new Vector(); @@ -9268,6 +10707,14 @@ private void SaveDrawAttr(FileOutputStream fp, int stype) throws DrawData.SavePS(vc, vd, vw, fp, stype); } + /** + * Gets the unique drawing attributes from the list and adds them to the specified vectors. + * + * @param vc the vector for colors + * @param vd the vector for dash patterns + * @param vw the vector for widths + * @param vlist the list of objects to process + */ private void getUDAFromList(Vector vc, Vector vd, Vector vw, Vector vlist) { for (int i = 0; i < vlist.size(); i++) { CClass cc = (CClass) vlist.get(i); @@ -9277,6 +10724,12 @@ private void getUDAFromList(Vector vc, Vector vd, Vector vw, Vector vlist) { } } + /** + * Adds an attribute to the specified vector if it is not already present. + * + * @param atrr the attribute to add + * @param v the vector to add the attribute to + */ private void addAttrToList(int atrr, Vector v) { int i = 0; @@ -9290,11 +10743,18 @@ private void addAttrToList(int atrr, Vector v) { } } v.add(i, atrr); - } - public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws - PrinterException { + /** + * Prints the drawing on the specified page. + * + * @param graphics the graphics context + * @param pageFormat the page format + * @param pageIndex the index of the page to print + * @return PAGE_EXISTS if the page is rendered successfully, NO_SUCH_PAGE otherwise + * @throws PrinterException if a printer error occurs + */ + public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException { if (pageIndex >= 1) { return Printable.NO_SUCH_PAGE; } @@ -9315,6 +10775,11 @@ public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws return 0; } + /** + * Prints the content of the current drawing. + * Sets up the printer job and page format, and initiates the print dialog. + * If the user confirms the print dialog, it attempts to print the content. + */ public void PrintContent() { PrinterJob job = PrinterJob.getPrinterJob(); PageFormat landscape = job.defaultPage(); @@ -9330,7 +10795,6 @@ public void PrintContent() { pf.setPaper(paper); job.setPrintable(this, pf); - if (job.printDialog()) { try { job.print(); @@ -9340,7 +10804,13 @@ public void PrintContent() { } } - + /** + * Adds a text object to the drawing. + * If the text object is not null and successfully added to the text list, + * it adds an undo action for the addition. + * + * @param tx the text object to add + */ public void addText(CText tx) { if (tx != null) { if (this.addObjectToList(tx, textlist)) { @@ -9349,56 +10819,50 @@ public void addText(CText tx) { } } - public UndoStruct addProveToList() { - UndoStruct undo = new UndoStruct(UndoStruct.T_PROVE_NODE, 0); - this.undolist.add(undo); - return undo; - } - - public UndoStruct addToProveToList() { - UndoStruct undo = new UndoStruct(UndoStruct.T_TO_PROVE_NODE, 0); - undo.msg = ""; - this.undolist.add(undo); - return undo; - } - + /** + * Adds an undo structure to the undo list. + * + * @param un the undo structure to add + */ public void addNodeToUndoList(UndoStruct un) { this.undolist.add(un); - -// if (undolist.size() == 0) { -// if (gxInstance.getUndoEditDialog().isVisible()) { -// } else { -// } -// } else { -// if (gxInstance != null && !gxInstance.getUndoEditDialog().isVisible()) { -// UndoStruct u = (UndoStruct) undolist.get(undolist.size() - 1); -// if (u.m_type == UndoStruct.T_UNDO_NODE) { -// undolist.add(un); -// } else { -// u.childundolist.add(un); -// } -// } else { -// } -// } } - + /** + * Adds an undo action with a specified tip message. + * + * @param tip the tip message for the undo action + * @return the added undo structure + */ public UndoStruct UndoAdded(Object tip) { return UndoAdded(tip, true); - } + /** + * Adds an undo action with a specified tip message and a flag to generate proof. + * + * @param tip the tip message for the undo action + * @param gr whether to generate proof + * @return the added undo structure + */ public UndoStruct UndoAdded(Object tip, boolean gr) { return UndoAdded(tip, gr, true); } + /** + * Adds an undo action with a specified tip message, a flag to generate proof, + * and a flag to update the manual input bar. + * + * @param tip the tip message for the undo action + * @param gr whether to generate proof + * @param m whether to update the manual input bar + * @return the added undo structure + */ public UndoStruct UndoAdded(Object tip, boolean gr, boolean m) { - if (CMisc.id_count == this.currentUndo.id) { return null; } - String message = tip.toString(); if (message.length() != 0) { char c = message.charAt(0); @@ -9406,19 +10870,17 @@ public UndoStruct UndoAdded(Object tip, boolean gr, boolean m) { c += 'A' - 'a'; message = c + message.substring(1); } - } // upper case first char of the mesage. + } // upper case first char of the message. this.redolist.clear(); UndoStruct Undo = this.currentUndo; Undo.action = this.CurrentAction; if (message != null && message.length() >= 1) { - char c = message.charAt(0); if (c >= 'a' && c <= 'z') { c = (char) (c + 'A' - 'a'); message = c + message.substring(1); } - Undo.msg = message; } Undo.id_b = CMisc.id_count; @@ -9445,21 +10907,22 @@ public UndoStruct UndoAdded(Object tip, boolean gr, boolean m) { gxInstance.setBKState(); } - return Undo; - } - + /** + * Adds a default undo action with a generic message. + */ public void UndoAdded() { UndoAdded("Not yet added "); } - public void UndoAdded(CClass cc) { - UndoAdded(cc.TypeString() + ": " + cc.getDescription()); - } - + /** + * Performs a pure undo operation. + * Calls `doFlash` and repeatedly calls `Undo_stepPure` until it returns false. + * Regenerates all polygons and calls `doFlash` again. + */ public void UndoPure() { this.doFlash(); while (true) { @@ -9471,6 +10934,10 @@ public void UndoPure() { } } + /** + * Performs an undo operation. + * Repeatedly calls `Undo_step` until it returns false. + */ public void Undo() { while (true) { if (!Undo_step()) { @@ -9479,6 +10946,10 @@ public void Undo() { } } + /** + * Performs a redo operation. + * Repeatedly calls `redo_step` until it returns null. + */ public void redo() { while (true) { if (null == redo_step()) { @@ -9487,14 +10958,25 @@ public void redo() { } } + /** + * Performs a single undo step. + * + * @param Undo the undo structure + * @return true if the undo step was successful, false otherwise + */ public boolean undo_step(UndoStruct Undo) { return undo_step(Undo, true); } + /** + * Performs a single undo step with an option to regenerate and recalculate. + * + * @param Undo the undo structure + * @param rg whether to regenerate and recalculate + * @return true if the undo step was successful, false otherwise + */ public boolean undo_step(UndoStruct Undo, boolean rg) { - - if (Undo.m_type == UndoStruct.T_COMBINED_NODE || - Undo.m_type == UndoStruct.T_PROVE_NODE) { + if (Undo.m_type == UndoStruct.T_COMBINED_NODE || Undo.m_type == UndoStruct.T_PROVE_NODE) { for (int i = 0; i < Undo.childundolist.size(); i++) { UndoStruct u = (UndoStruct) Undo.childundolist.get(i); this.undo_step(u); @@ -9507,44 +10989,6 @@ public boolean undo_step(UndoStruct Undo, boolean rg) { int para = Undo.paraCounter; int parab = Undo.paraCounter_b; Undo.clear(); -// TPoly pl, tp; -// pl = this.polylist; -// tp = null; -// while (pl != null) { -// TMono m = pl.getPoly(); -// int tid = poly.lv(m); -// -// if (tid >= para && tid < parab) { -// if (tp == null) { -// this.polylist = null; -// } else { -// tp.setNext(null); -// } -// Undo.polylist = pl; -// break; -// } -// tp = pl; -// pl = pl.getNext(); -// } -// pl = pblist; -// tp = null; -// -// while (pl != null) { -// TMono m = pl.getPoly(); -// int tid = poly.lv(m); -// -// if (tid >= para && tid < parab) { -// if (tp == null) { -// this.pblist = null; -// } else { -// tp.setNext(null); -// } -// Undo.pblist = pl; -// break; -// } -// tp = pl; -// pl = pl.getNext(); -// } moveUndoObjectFromList(Undo.pointlist, pointlist, pc, pcb); moveUndoObjectFromList(Undo.linelist, linelist, pc, pcb); @@ -9618,10 +11062,8 @@ public boolean undo_step(UndoStruct Undo, boolean rg) { CPolygon p1 = (CPolygon) cs.getelement(0); CPolygon p2 = (CPolygon) cs.getelement(1); p1.setVisible(true); - } break; - } } } @@ -9644,11 +11086,21 @@ public boolean undo_step(UndoStruct Undo, boolean rg) { return true; } + /** + * Checks if the redo list is empty. + * + * @return true if the redo list is empty, false otherwise + */ public boolean isRedoAtEnd() { return redolist.size() == 0; } - + /** + * Performs a pure undo step. + * Clears the selection and catch list, and moves the undo structure from the undo list to the redo list. + * + * @return true if the undo step was successful, false otherwise + */ public boolean Undo_stepPure() { this.undo = null; if (CMisc.id_count != this.currentUndo.id) { @@ -9665,17 +11117,16 @@ public boolean Undo_stepPure() { this.undo_step(Undo, false); this.redolist.add(Undo); return true; - } + /** + * Performs an undo step. + * Clears the selection and catch list, and moves the undo structure from the undo list to the redo list. + * + * @return true if the undo step was successful, false otherwise + */ public boolean Undo_step() { - -// clearSelection(); -// STATUS = 0; -// FirstPnt = SecondPnt = null; this.cancelCurrentAction(); - - this.undo = null; if (CMisc.id_count != this.currentUndo.id) { UndoAdded(); @@ -9701,25 +11152,34 @@ public boolean Undo_step() { if (gxInstance != null) gxInstance.getpprove().generate(); return true; - } + /** + * Gets the size of the undo list. + * + * @return the size of the undo list + */ public int getUndolistSize() { return undolist.size(); } + /** + * Gets the size of the redo list. + * + * @return the size of the redo list + */ public int getRedolistSize() { return redolist.size(); } - public UndoStruct getNextRedoStruct() { - if (redolist.size() == 0) { - return null; - } - return (UndoStruct) redolist.get(redolist.size() - 1); - } - - + /** + * Moves undo objects from one list to another based on their IDs. + * + * @param v1 the destination list + * @param v2 the source list + * @param pc1 the starting ID + * @param pc2 the ending ID + */ public void moveUndoObjectFromList(Vector v1, Vector v2, int pc1, int pc2) { for (int i = 0; i < v2.size(); i++) { CClass cc = (CClass) v2.get(i); @@ -9731,6 +11191,14 @@ public void moveUndoObjectFromList(Vector v1, Vector v2, int pc1, int pc2) { } } + /** + * Selects undo objects from one list to another based on their IDs. + * + * @param v1 the destination list + * @param v2 the source list + * @param pc1 the starting ID + * @param pc2 the ending ID + */ public void selectUndoObjectFromList(Vector v1, Vector v2, int pc1, int pc2) { for (int i = 0; i < v2.size(); i++) { CClass cc = (CClass) v2.get(i); @@ -9740,7 +11208,14 @@ public void selectUndoObjectFromList(Vector v1, Vector v2, int pc1, int pc2) { } } - + /** + * Sets the undo structure for display. + * If the provided undo structure is not null and flashing is enabled, + * the method retrieves all associated flash objects and initiates a flash display. + * + * @param u the undo structure to display + * @param compulsory_flash if true, forces the flash display regardless of the internal flag + */ public void setUndoStructForDisPlay(UndoStruct u, boolean compulsory_flash) { if (u == null) return; @@ -9754,6 +11229,12 @@ public void setUndoStructForDisPlay(UndoStruct u, boolean compulsory_flash) { } } + /** + * Searches through the undo list for an undo structure whose id range contains the given id, + * then sets it for display with compulsory flashing. + * + * @param id the identifier used to locate the corresponding undo structure + */ public void flash_node_by_id(int id) { for (int i = 0; i < undolist.size(); i++) { UndoStruct u = (UndoStruct) undolist.get(i); @@ -9764,18 +11245,36 @@ public void flash_node_by_id(int id) { } } + /** + * Creates and returns a flash object for the given graphical component. + * + * @param cc the graphical object to be flashed + * @return the flash object containing the given component + */ public JObjectFlash getObjectFlash(CClass cc) { JObjectFlash f = new JObjectFlash(panel); f.addFlashObject(cc); return f; } + /** + * Creates a flash effect for a single graphical object by wrapping it in a vector + * and invoking the flash display mechanism. + * + * @param cc the graphical object to set for flash display + */ public void setObjectListForFlash(CClass cc) { Vector v = new Vector(); v.add(cc); setObjectListForFlash(v); } + /** + * Sets a list of objects for flash display on the specified panel. + * + * @param list the list of objects to be flashed + * @param p the panel on which the flash effect should be displayed + */ public void setObjectListForFlash(Vector list, JPanel p) { JObjectFlash f = new JObjectFlash(panel); @@ -9783,10 +11282,21 @@ public void setObjectListForFlash(Vector list, JPanel p) { this.addFlash(f); } + /** + * Sets a list of objects for flash display using the default panel. + * + * @param list the list of objects to be flashed + */ public void setObjectListForFlash(Vector list) { setObjectListForFlash(list, panel); } + /** + * Extracts all flashable objects from each undo structure in the provided list + * and sets them for flash display. + * + * @param list the list of undo structures whose associated objects will be flashed + */ public void setUndoListForFlash(Vector list) { Vector v = new Vector(); for (int i = 0; i < list.size(); i++) { @@ -9796,6 +11306,12 @@ public void setUndoListForFlash(Vector list) { setObjectListForFlash(v); } + /** + * Extracts all flashable objects from each undo structure in the provided list + * and sets them for flash display using an alternative flash mechanism. + * + * @param list the list of undo structures whose associated objects will be flashed + */ public void setUndoListForFlash1(Vector list) { Vector v = new Vector(); for (int i = 0; i < list.size(); i++) { @@ -9807,29 +11323,22 @@ public void setUndoListForFlash1(Vector list) { this.addFlash1(f); } + /** + * Stops any active undo flash display by clearing the flash queue. + */ public void stopUndoFlash() { this.clearFlash(); } - public boolean redo_till_specified_idcount(int id) { - UndoStruct Undo; - if (redolist.size() == 0) { - return false; - } - while (true) { - Undo = (UndoStruct) redolist.get(redolist.size() - 1); - if (Undo.id_b <= id) { - this.redo_step(); - } else { - break; - } - if (redolist.size() == 0) { - break; - } - } - return true; - } - + /** + * Performs a redo step for the provided undo structure. + * If the undo structure represents a combined or prove node, + * it recursively redoes each sub-node. + * Otherwise, it restores various elements and recalculates the state. + * + * @param Undo the undo structure to be redone + * @return true if the redo step is successful + */ public boolean redo_step(UndoStruct Undo) { if (Undo.m_type == UndoStruct.T_COMBINED_NODE || @@ -9990,10 +11499,24 @@ public boolean redo_step(UndoStruct Undo) { return true; } + /** + * Determines whether a given undo structure is not present in the redo list. + * + * @param u the undo structure to check + * @return true if the structure is not already in the redo list, false otherwise + */ public boolean already_redo(UndoStruct u) { return !redolist.contains(u); } + /** + * Performs a redo step with the option to clear the flash display. + * It retrieves the most recent redo step, updates the internal lists, + * and returns the corresponding undo structure. + * + * @param cf if true, clears any active flash display prior to redoing the step + * @return the undo structure that was redone, or null if no redo step is available + */ public UndoStruct redo_step(boolean cf) { if (redolist.size() == 0) return null; @@ -10012,11 +11535,22 @@ public UndoStruct redo_step(boolean cf) { return Undo; } + /** + * Performs a redo step with flash clearing enabled by default. + * + * @return the undo structure that was redone, or null if no redo step is available + */ public UndoStruct redo_step() { return redo_step(true); } + /** + * Finds a point by its index. + * + * @param index the index of the point + * @return the point if found, null otherwise + */ public CPoint fd_point(int index) { if (index <= 0) { return null; @@ -10036,6 +11570,15 @@ public CPoint fd_point(int index) { return null; } + /** + * Finds an angle defined by four points. + * + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @param p4 the fourth point + * @return the angle if found, null otherwise + */ public CAngle fd_angle_4p(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { for (int i = 0; i < anglelist.size(); i++) { CAngle ag = (CAngle) anglelist.get(i); @@ -10046,6 +11589,15 @@ public CAngle fd_angle_4p(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { return null; } + /** + * Finds an angle defined by four points (alternative method). + * + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @param p4 the fourth point + * @return the angle if found, null otherwise + */ public CAngle fd_angle_m(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { for (int i = 0; i < anglelist.size(); i++) { CAngle ag = (CAngle) anglelist.get(i); @@ -10056,6 +11608,12 @@ public CAngle fd_angle_m(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { return null; } + /** + * Finds an angle that matches the given angle. + * + * @param ag the angle to match + * @return the matching angle if found, null otherwise + */ public CAngle fd_angle(CAngle ag) { for (int i = 0; i < anglelist.size(); i++) { CAngle g = (CAngle) anglelist.get(i); @@ -10066,8 +11624,15 @@ public CAngle fd_angle(CAngle ag) { return null; } + /** + * Adds a circle defined by three points. + * + * @param o the first point + * @param a the second point + * @param b the third point + * @return the added circle + */ public Circle add_rcircle(int o, int a, int b) { - if (o == 0 || a == 0 || b == 0) { return null; } @@ -10081,6 +11646,13 @@ public Circle add_rcircle(int o, int a, int b) { return this.addCr(o, op); } + /** + * Adds a circle defined by two points. + * + * @param o the first point + * @param a the second point + * @return the added circle + */ public Circle addCr(int o, int a) { CPoint p1 = this.fd_point(o); Circle c = null; @@ -10093,6 +11665,14 @@ public Circle addCr(int o, int a) { return c; } + /** + * Finds a circle defined by three points. + * + * @param o the first point + * @param a the second point + * @param b the third point + * @return the circle if found, null otherwise + */ public Circle fd_rcircle(int o, int a, int b) { if (o == 0 || a == 0 || b == 0) { return null; @@ -10116,6 +11696,13 @@ public Circle fd_rcircle(int o, int a, int b) { return null; } + /** + * Finds a circle defined by two points. + * + * @param o the first point + * @param a the second point + * @return the circle if found, null otherwise + */ public Circle fd_circle(int o, int a) { if (o == 0 || a == 0) { return null; @@ -10135,6 +11722,14 @@ public Circle fd_circle(int o, int a) { return null; } + /** + * Finds a circle defined by an origin and two radius points. + * + * @param o the origin point + * @param p1 the first radius point + * @param p2 the second radius point + * @return the circle if found, null otherwise + */ public Circle fd_circleOR(CPoint o, CPoint p1, CPoint p2) { for (int i = 0; i < circlelist.size(); i++) { Circle cc = (Circle) circlelist.get(i); @@ -10148,6 +11743,14 @@ public Circle fd_circleOR(CPoint o, CPoint p1, CPoint p2) { return null; } + /** + * Finds a circle defined by three points. + * + * @param a the first point + * @param b the second point + * @param c the third point + * @return the circle if found, null otherwise + */ public Circle fd_circle(int a, int b, int c) { CPoint p1 = this.fd_point(a); CPoint p2 = this.fd_point(b); @@ -10160,10 +11763,15 @@ public Circle fd_circle(int a, int b, int c) { } } return null; - } - + /** + * Adds a mark between two points. + * + * @param a the first point + * @param b the second point + * @return the added mark + */ public Cedmark addedMark(int a, int b) { CPoint p1 = this.fd_point(a); CPoint p2 = this.fd_point(b); @@ -10175,6 +11783,13 @@ public Cedmark addedMark(int a, int b) { return null; } + /** + * Adds a mark between two points. + * + * @param p1 the first point + * @param p2 the second point + * @return the added mark + */ public Cedmark addedMark(CPoint p1, CPoint p2) { if (p1 != null && p2 != null && this.fd_edmark(p1, p2) == null) { Cedmark ed = new Cedmark(p1, p2); @@ -10184,24 +11799,13 @@ public Cedmark addedMark(CPoint p1, CPoint p2) { return null; } - public void addedMarks(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { - - Cedmark e1 = addedMark(p1, p2); - Cedmark e2 = addedMark(p3, p4); - int n = this.getEMarkNum(); - n = n / 2; - if (e1 != null) { - e1.setdnum(n); - } - if (e2 != null) { - e2.setdnum(n); - } - } - int aux_angle = 0; int aux_polygon = 0; int aux_mark = 0; + /** + * Resets auxiliary counters and performs an undo step. + */ public void resetAux() { this.UndoAdded(); this.Undo_step(); @@ -10210,10 +11814,20 @@ public void resetAux() { aux_mark = 0; } + /** + * Initiates a flash using the provided vector of objects. + * + * @param v the vector containing objects to flash + */ public void flashStep(Vector v) { this.setUndoListForFlash(v); } + /** + * Computes and returns a simple name for an angle based on the current angle count. + * + * @return a string representing the angle name + */ public String getAngleSimpleName() { int n = anglelist.size() + 1; String sn; @@ -10227,22 +11841,42 @@ public String getAngleSimpleName() { return sn; } + /** + * Sets the current drawing panel. + * + * @param panel the JPanel to set as the current drawing panel + */ public void setCurrentDrawPanel(JPanel panel) { this.panel = panel; } + /** + * Sets the current geometry expert instance and updates the drawing panel accordingly. + * + * @param gx the GExpert instance to set as the current instance + */ public void setCurrentInstance(GExpert gx) { gxInstance = gx; this.panel = gx.d; } + /** + * Creates and returns a new parameter, updating the parameter counter. + * + * @return a new instance of Param + */ public Param getANewParam() { int n = paraCounter; Param p1 = parameter[paraCounter - 1] = new Param(paraCounter++, 0); return p1; } - + /** + * Adds a special angle value. + * + * @param v the input value to compute the special angle value + * @return the x-index of the parameter corresponding to the added angle + */ public int add_sp_angle_value(int v) { int n = paraCounter; Param p1 = parameter[paraCounter - 1] = new Param(paraCounter++, 0); @@ -10251,7 +11885,14 @@ public int add_sp_angle_value(int v) { return p1.xindex; } - + /** + * Retrieves a unique name for a circle center. + *

+ * This method generates a name starting with "O", and appends a number + * if necessary to ensure uniqueness among the existing points. + * + * @return the generated circle center name + */ String get_cir_center_name() { int k = 0; while (true) { @@ -10277,27 +11918,14 @@ String get_cir_center_name() { else return "O" + k; } - - public void add_to_undolist(UndoStruct u) { - if (!undolist.contains(u)) - undolist.add(u); - - } - - public void remove_from_undolist(UndoStruct u) { - undolist.remove(u); - } - - public void add_to_redolist(UndoStruct u) { - if (!redolist.contains(u)) - redolist.add(u); - - } - - public void remove_from_redolist(UndoStruct u) { - redolist.remove(u); - } - + /** + * Checks if the current state needs to be saved. + *

+ * The state is considered modified if there are points, text objects, + * other elements, or more than one parameter. + * + * @return true if there are unsaved changes, false otherwise + */ public boolean need_save() { return pointlist.size() > 0 || textlist.size() > 0 @@ -10305,8 +11933,15 @@ public boolean need_save() { || paraCounter > 1; } -////////////////////////////////////////////////////////////////////////////////// - + /** + * Finds a polygon associated with the given circle. + *

+ * The method searches through the polygon list for a polygon of a specific type + * that matches the circle's properties. + * + * @param c the circle to search for the corresponding polygon + * @return the found polygon or null if none match + */ public CPolygon fd_polygon(Circle c) { for (int i = 0; i < polygonlist.size(); i++) { CPolygon cp = (CPolygon) polygonlist.get(i); @@ -10324,13 +11959,28 @@ public CPolygon fd_polygon(Circle c) { return null; } -///////////////////////////////////////////////////////////////////// - + /** + * Reduces a given TMono object using the current parameters. + *

+ * This method creates a copy of the input TMono and applies reduction + * based on the available parameters. + * + * @param m the TMono object to reduce + * @return the reduced TMono object + */ public TMono reduce(TMono m) { PolyBasic basic = GeoPoly.getInstance(); return basic.reduce(basic.p_copy(m), parameter); } + /** + * Handles double-click events on a CClass object. + *

+ * Depending on the type of the object, this method either opens an editor + * or performs a view action. + * + * @param c the CClass object that was double-clicked + */ public void onDBClick(CClass c) { if (c == null) return; @@ -10356,6 +12006,13 @@ public void onDBClick(CClass c) { } + /** + * Rounds a double value to a specified number of decimal places. + * + * @param r the value to round + * @param n the number of decimal places + * @return the rounded value + */ public double roundn(double r, int n) { if (n <= 0) return r; @@ -10369,6 +12026,15 @@ public double roundn(double r, int n) { return (int) (r * k) / k; } + /** + * Calculates the numerical value of a given CTextValue expression. + *

+ * This method evaluates the expression represented by the CTextValue object + * using basic arithmetic operations and mathematical functions. + * + * @param ct the CTextValue object representing the expression + * @return the calculated numerical value + */ public double calculate(CTextValue ct) { if (ct == null) return 0.0; @@ -10411,6 +12077,14 @@ public double calculate(CTextValue ct) { } + /** + * Retrieves a CTextValue parameter by its name. + *

+ * Searches the text list for a text element with a value type that matches the given name. + * + * @param s the name of the parameter to find + * @return the corresponding CTextValue if found; otherwise, null + */ CTextValue fd_para(String s) { for (int i = 0; i < textlist.size(); i++) { CText t = (CText) textlist.get(i); @@ -10420,7 +12094,14 @@ CTextValue fd_para(String s) { return null; } - + /** + * Adds a calculation for the X-coordinate of a point. + *

+ * This method creates a text representation of the X-coordinate + * calculation for the provided point. + * + * @param p the point for which the X-coordinate calculation is added + */ final public void addCalculationPX(CPoint p) { if (p == null) return; @@ -10437,6 +12118,14 @@ final public void addCalculationPX(CPoint p) { } + /** + * Adds a calculation for the Y-coordinate of a point. + *

+ * This method creates a text representation of the Y-coordinate + * calculation for the provided point. + * + * @param p the point for which the Y-coordinate calculation is added + */ final public void addCalculationPY(CPoint p) { if (p == null) return; @@ -10452,6 +12141,13 @@ final public void addCalculationPY(CPoint p) { addText(tx); } + /** + * Adds a polygon calculation displaying its area. + *

+ * Constructs a text object representing the area calculation for the provided polygon. + * + * @param poly the polygon for which the area calculation is added + */ final public void addCalculationPolygon(CPolygon poly) { if (poly == null) return; @@ -10473,6 +12169,14 @@ final public void addCalculationPolygon(CPolygon poly) { addText(tx); } + /** + * Adds a calculation for the slope of a line. + *

+ * This method creates a text representation of the slope calculation + * for the given line based on its two supporting points. + * + * @param ln the line for which the slope calculation is added + */ final public void addLineSlope(CLine ln) { if (ln == null) return; @@ -10496,6 +12200,15 @@ final public void addLineSlope(CLine ln) { addText(tx); } + /** + * Adds a calculation for a circle based on the specified type. + *

+ * Depending on the type parameter, the method adds a text representation for + * the area, girth, or radius calculation of the circle. + * + * @param c the circle for which the calculation is added + * @param t the type of calculation (0 for area, 1 for girth, other for radius) + */ final public void addCalculationCircle(Circle c, int t) { if (c == null) return; @@ -10531,6 +12244,12 @@ final public void addCalculationCircle(Circle c, int t) { addText(tx); } + /** + * Determines the location for a text object. + * Calculates an appropriate position for the text object based on existing text objects. + * + * @param t1 the text object for which the location is determined + */ public void getTextLocation(CText t1) { int n = 0; int n1 = 5; @@ -10544,9 +12263,11 @@ public void getTextLocation(CText t1) { t1.setXY(n1, n); } - public void flashAllNonVisibleObjects() { - } - + /** + * Cancels the current action and resets relevant states. + * This method clears selections, resets action-related variables, + * repaints the panel, and performs undo operations if necessary. + */ public void cancelCurrentAction() { int type = CurrentAction; @@ -10574,21 +12295,12 @@ public void cancelCurrentAction() { this.Undo_stepPure(); } - - public void hightlightAllInvisibleObject() { - Vector v = this.getAllSolidObj(); - for (int i = 0; i < v.size(); i++) { - CClass c = (CClass) v.get(i); - if (c == null || c.visible()) { - v.remove(i); - i--; - } - } - SelectList.clear(); - SelectList.addAll(v); - } - - + /** + * Returns the action type based on the given action code. + * + * @param ac the action code + * @return an integer representing the action type, or -1 if not recognized + */ public int getActionType(int ac) //-1. ByPass Action; 0. defalut; // 1. Draw Action + point; 2: draw action line + circle // 3: fill action 4: angle 5: move/select/intersect @@ -10701,6 +12413,12 @@ public void hightlightAllInvisibleObject() { return -1; } + /** + * Adds a perpendicularity mark between two given lines if they are perpendicular. + * + * @param ln1 the first line + * @param ln2 the second line + */ public void addCTMark(CLine ln1, CLine ln2) { if (ln1 == null || ln2 == null) return; @@ -10713,11 +12431,23 @@ public void addCTMark(CLine ln1, CLine ln2) { this.otherlist.add(m); } + /** + * Adds a perpendicularity mark by deriving lines from two pairs of points. + * + * @param p1 the first point of the first line + * @param p2 the second point of the first line + * @param p3 the first point of the second line + * @param p4 the second point of the second line + */ public void addCTMark(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { addCTMark(fd_line(p1, p2), fd_line(p3, p4)); } - + /** + * Translates the polygon's points and creates corresponding oriented segments. + * + * @param poly the polygon whose points are to be transformed + */ public void PolygonTransPointsCreated(CPolygon poly) { CPoint pt0, pt1; pt0 = pt1 = null; @@ -10767,6 +12497,15 @@ public void PolygonTransPointsCreated(CPolygon poly) { } } + /** + * Creates a new oriented segment for a given point and its transformed coordinates. + * + * @param p1 the first reference point + * @param p2 the second reference point + * @param px the original point for segment generation + * @param x the transformed x-coordinate + * @param y the transformed y-coordinate + */ public void addOrientedSegment(CPoint p1, CPoint p2, CPoint px, double x, double y) { CPoint p = this.CreateANewPoint(x, y); @@ -10778,522 +12517,16 @@ public void addOrientedSegment(CPoint p1, CPoint p2, CPoint px, double x, double } } - public void setTextPositionAutomatically(CText tex) { - if (tex.getType() != CText.NAME_TEXT) - return; - - Point o = tex.getLocation(); - double w = tex.w; - double h = tex.height; - double r = 15; - - CClass c = tex.father; - if (c != null && c.get_type() == CClass.POINT) { - CPoint px = (CPoint) c; - double x = tex.getX(); - double y = tex.getY(); - double dx = x;//- px.getx(); - double dy = y;//- px.gety(); - double dpi = Math.PI / 16; - boolean bfound = false; - double sx, sy; - sx = sy = 0; - for (int i = 0; i < 16; i++) { - if (bfound) - break; - double sta = i * dpi; - for (int j = 0; j < 2; j++) { - sx = dx * Math.cos(sta) - dy * Math.sin(sta); - sy = dx * Math.sin(sta) + dy * Math.cos(sta); - if (!intsWithCircle(sx + px.getx(), sy + px.gety(), r)) { - bfound = true; - break; - } - if (bfound) - break; - sta *= -1; - } - } - if (bfound) { - tex.setXY((int) (sx), (int) (sy)); - } - } - - } - - public boolean intsWithCircle(double ptx, double pty, double r) { - - boolean bat = false; - int size = pointlist.size(); - for (int i = 0; i < size - 1; i++) { - CPoint p = (CPoint) pointlist.get(i); - double ds = Math.pow(p.getx() - ptx, 2) + Math.pow(p.gety() - pty, 2); - ds = Math.sqrt(ds); - if (ds < r) { - return true; - } - } - - size = linelist.size(); - for (int i = 0; i < size; i++) { - CLine ln = (CLine) linelist.get(i); - double d = ln.distance(ptx, pty); - if (d < r) { - if (ln.isOnMiddle(ptx, pty)) - return true; - } - } - size = circlelist.size(); - for (int i = 0; i < size; i++) { - Circle c = (Circle) circlelist.get(i); - double d = Math.sqrt(Math.pow(c.o.getx() - ptx, 2) + Math.pow(c.o.gety() - pty, 2)); - if (Math.abs(d - c.getRadius()) < r) - return true; - } - return false; - } - - public boolean LoadGGB(DataInputStream in, String path) throws IOException { - // Reset everything in the current construction - clearAll(); - double version = 0.053; // Current gex file version for JGEX 0.8 is 0.053 - CMisc.version_load_now = version; - - // Need to make type ArrayList because JGEX uses java.awt.List as well - ArrayList points = new ArrayList<>(); - ArrayList lines = new ArrayList<>(); - ArrayList angles = new ArrayList<>(); - - ZipFile ggbFile = new ZipFile(path); - - Enumeration entries = ggbFile.entries(); - - while (entries.hasMoreElements()) { - ZipEntry entry = entries.nextElement(); - String filename = entry.getName(); - if (filename.equals("geogebra.xml")) { - InputStream stream = ggbFile.getInputStream(entry); - try { - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - //an instance of builder to parse the specified xml file - DocumentBuilder db = dbf.newDocumentBuilder(); - Document doc = db.parse(stream); - doc.getDocumentElement().normalize(); - - // System.out.println("Root element: " + doc.getDocumentElement().getNodeName()); - - NodeList nodeSize = doc.getElementsByTagName("size"); - if (nodeSize.getLength() > 1) { - System.out.println("More than one size element in ggb file! Use only graphics view 1."); - } - NamedNodeMap sizeGGB = nodeSize.item(0).getAttributes(); - int widthGGB = Integer.parseInt(sizeGGB.getNamedItem("width").getTextContent()); - int heightGGB = Integer.parseInt(sizeGGB.getNamedItem("height").getTextContent()); - - NodeList nodeScales = doc.getElementsByTagName("coordSystem"); - if (nodeScales.getLength() > 1) { - System.out.println("More than one coord system in ggb file! Use only graphics views 1."); - } - NamedNodeMap coordsGGB = nodeScales.item(0).getAttributes(); - double xScaleGGB = Double.parseDouble(coordsGGB.getNamedItem("scale").getTextContent()); - double yScaleGGB = Double.parseDouble(coordsGGB.getNamedItem("yscale").getTextContent()); - double xZeroGGB = Double.parseDouble(coordsGGB.getNamedItem("xZero").getTextContent()); - double yZeroGGB = Double.parseDouble(coordsGGB.getNamedItem("yZero").getTextContent()); - - double widthFraction = (double) Width / widthGGB; - double heightFraction = (double) Height / heightGGB; - - - // Find commands. - HashSet midpointsGgb = new HashSet<>(); // Set of Midpoints - ArrayList segmentsGgb = new ArrayList<>(); // Set of Segments - ArrayList linesGgb = new ArrayList<>(); - NodeList nodeList = doc.getElementsByTagName("command"); - for (int itr = 0; itr < nodeList.getLength(); itr++) { - Node node = nodeList.item(itr); - if (node.getNodeType() == Node.ELEMENT_NODE) { - Element eElement = (Element) node; - if (eElement.getAttribute("name").equals("Midpoint")) { // Handle Midpoint Command - NamedNodeMap outputName = eElement.getElementsByTagName("output").item(0).getAttributes(); - NamedNodeMap inputName = eElement.getElementsByTagName("input").item(0).getAttributes(); - String nameMidpoint = outputName.getNamedItem("a0").getTextContent(); - if (inputName.getLength() == 2) { // Midpoint of two points - String nameP1 = inputName.getNamedItem("a0").getTextContent(); - String nameP2 = inputName.getNamedItem("a1").getTextContent(); - midpointsGgb.add(new GgbMidpoint(nameMidpoint, nameP1, nameP2)); - } else if (inputName.getLength() == 1) { // Midpoint of a segment - String nameSegment = inputName.getNamedItem("a0").getTextContent(); - GgbSegment segment = getGgbSegment(segmentsGgb, nameSegment); - midpointsGgb.add(new GgbMidpoint(nameMidpoint, segment.getNameP1(), segment.getNameP2())); - } - } else if (eElement.getAttribute("name").equals("Segment")) { // Handle segment command. Segment between two points - NamedNodeMap outputName = eElement.getElementsByTagName("output").item(0).getAttributes(); - NamedNodeMap inputName = eElement.getElementsByTagName("input").item(0).getAttributes(); - if (inputName.getLength() == 2) { // Segment between two points - String nameSegment = outputName.getNamedItem("a0").getTextContent(); - String nameP1 = inputName.getNamedItem("a0").getTextContent(); - String nameP2 = inputName.getNamedItem("a1").getTextContent(); - segmentsGgb.add(new GgbSegment(nameSegment, nameP1, nameP2)); - } - } else if (eElement.getAttribute("name").equals("Line")) { // Handle line command - NamedNodeMap outputName = eElement.getElementsByTagName("output").item(0).getAttributes(); - NamedNodeMap inputName = eElement.getElementsByTagName("input").item(0).getAttributes(); - if (inputName.getLength() == 2) { // Line between two points - String nameLine = outputName.getNamedItem("a0").getTextContent(); - String nameP1 = inputName.getNamedItem("a0").getTextContent(); - String nameP2 = inputName.getNamedItem("a1").getTextContent(); - linesGgb.add(new GgbLine(nameLine, nameP1, nameP2)); - } - } - } - } - - - // Get a list of all elements in the construction - nodeList = doc.getElementsByTagName("element"); - // nodeList is not iterable, so we are using for loop - for (int itr = 0; itr < nodeList.getLength(); itr++) { - Node node = nodeList.item(itr); - if (node.getNodeType() == Node.ELEMENT_NODE) { - Element eElement = (Element) node; - - // Handle GeoGebra Point - if (eElement.getAttribute("type").equals("point")) { - // The name of the point is the same as in GeoGebra - String label = eElement.getAttribute("label"); - - // Do not add midpoints - if (midpointsGgb.contains(new GgbMidpoint(label))) { - continue; - } - - NamedNodeMap coords = eElement.getElementsByTagName("coords").item(0).getAttributes(); - double xGGB = Double.parseDouble(coords.getNamedItem("x").getTextContent()); - double yGGB = Double.parseDouble(coords.getNamedItem("y").getTextContent()); - double xJGEX = widthFraction * (xZeroGGB + xScaleGGB * xGGB); - double yJGEX = heightFraction * (yZeroGGB - yScaleGGB * yGGB); - // clearSelection(); - - - CPoint p = this.SmartgetApointFromXY(xJGEX, yJGEX, label); - - points.add(p); - - - if (p != null) { - addToSelectList(p); - this.UndoAdded(p.TypeString()); - } - // System.out.println(xJGEX+", "+yJGEX); // DEBUG - } // TODO: Add handlers for other geometric objects as well - /* - System.out.println("Student id: " + eElement.getElementsByTagName("id").item(0).getTextContent()); - System.out.println("First Name: " + eElement.getElementsByTagName("firstname").item(0).getTextContent()); - System.out.println("Last Name: " + eElement.getElementsByTagName("lastname").item(0).getTextContent()); - System.out.println("Subject: " + eElement.getElementsByTagName("subject").item(0).getTextContent()); - System.out.println("Marks: " + eElement.getElementsByTagName("marks").item(0).getTextContent()); - - */ - } - } - - // Make all Midpoints between two Points or Segments - for (GgbMidpoint mp : midpointsGgb) { - CPoint[] pts = new CPoint[2]; - pts[0] = getCPoint(points, mp.getNameP1()); - pts[1] = getCPoint(points, mp.getNameP2()); - CPoint po = this.CreateANewPoint(0, 0); - Constraint cs = new Constraint(Constraint.MIDPOINT, po, pts[0], pts[1]); - CPoint pu = this.addADecidedPointWithUnite(po); - if (pu == null) { - this.addConstraintToList(cs); - this.addPointToList(po); - CLine ln = fd_line(pts[0], pts[1]); - if (ln != null) { - ln.addApoint(po); - Constraint cs2 = new Constraint(Constraint.PONLINE, po, ln, false); - this.addConstraintToList(cs2); - } - this.UndoAdded(po.getname() + ": the midpoint of " + pts[0].m_name + pts[1].m_name); - } else { - po = pu; - } - clearSelection(); - } - - // Make a line for every segment - for (GgbSegment seg : segmentsGgb) { - CPoint[] pts = new CPoint[2]; - pts[0] = getCPoint(points, seg.getNameP1()); - pts[1] = getCPoint(points, seg.getNameP2()); - - CPoint tp = pts[0]; - CPoint pp = pts[1]; - - getSmartPV(pts[0], pts[1]); - - if (tp != pp && tp != null && pp != null) { - setSmartPVLine(tp, pp); - addPointToList(pp); - CLine ln = new CLine(pp, tp, CLine.LLine); - this.addLineToList(ln); - Constraint cs = new Constraint(Constraint.LINE, tp, pp); - addConstraintToList(cs); - this.reCalculate(); - this.UndoAdded(ln.getDescription()); - } - } - - // Make a line for every line - for (GgbLine l : linesGgb) { - CPoint[] pts = new CPoint[2]; - pts[0] = getCPoint(points, l.getNameP1()); - pts[1] = getCPoint(points, l.getNameP2()); - CPoint tp = pts[0]; - CPoint pp = pts[1]; - - getSmartPV(pts[0], pts[1]); - - if (tp != pp && tp != null && pp != null) { - setSmartPVLine(tp, pp); - addPointToList(pp); - CLine ln = new CLine(pp, tp, CLine.LLine); - this.addLineToList(ln); - Constraint cs = new Constraint(Constraint.LINE, tp, pp); - addConstraintToList(cs); - this.reCalculate(); - this.UndoAdded(ln.getDescription()); - } - } - - - } catch (Exception e) { - e.printStackTrace(); - } - } - } - - ggbFile.close(); -// -// //int idcount = CMisc.id_count = getNumIds(); // TODO -// poly.clearZeroN(); -// -// -// pnameCounter = in.readInt(); -// plineCounter = in.readInt(); -// pcircleCounter = in.readInt(); -// paraCounter = in.readInt(); -// -// for (int i = 0; i < this.paraCounter - 1; i++) { -// param pm = new param(); -// pm.Load(in); -// this.parameter[i] = pm; -// } -// -// for (int i = 0; i < this.paraCounter - 1; i++) { -// paraBackup[i] = in.readDouble(); -// } -// -// int size; -// -// if (CMisc.version_load_now < 0.01) { -// size = in.readInt(); -// int trackCounter = size; -// if (CMisc.version_load_now >= 0.008) { -// for (int i = 0; i < 2 * trackCounter; i++) { -// in.readInt(); -// } -// } else { -// for (int i = 0; i < trackCounter; i++) { -// in.readInt(); -// } -// } -// } else if (CMisc.version_load_now < 0.012) { -// size = in.readInt(); -// for (int i = 0; i < size; i++) { -// CTrace ct = new CTrace(null); -// ct.Load(in, this); -// tracelist.add(ct); -// } -// } -// -// size = in.readInt(); -// for (int i = 0; i < size; i++) { -// int d = in.readInt(); -// addConstraintToList(new constraint(d)); -// } -// -// size = in.readInt(); -// for (int i = 0; i < size; i++) { -// CPoint p = new CPoint(); -// p.Load(in, this); -// pointlist.add(p); -// } -// size = in.readInt(); -// for (int i = 0; i < size; i++) { -// CLine ln = new CLine(0); -// ln.Load(in, this); -// linelist.add(ln); -// } -// size = in.readInt(); -// for (int i = 0; i < size; i++) { -// Circle c = new Circle(); -// c.Load(in, this); -// circlelist.add(c); -// } -// size = in.readInt(); -// for (int i = 0; i < size; i++) { -// CAngle ag = new CAngle(); -// ag.Load(in, this); -// anglelist.add(ag); -// } -// size = in.readInt(); -// for (int i = 0; i < size; i++) { -// CDistance dis = new CDistance(); -// dis.Load(in, this); -// distancelist.add(dis); -// } -// size = in.readInt(); -// for (int i = 0; i < size; i++) { -// -// CPolygon poly = new CPolygon(); -// poly.Load(in, this); -// addPolygonToList(poly); -// } -// size = in.readInt(); -// for (int i = 0; i < size; i++) { -// CText ct = new CText(); -// ct.Load(in, this); -// textlist.add(ct); -// } -// -// if (CMisc.version_load_now >= 0.012) { -// size = in.readInt(); -// for (int i = 0; i < size; i++) { -// CTrace ct = new CTrace(null); -// ct.Load(in, this); -// tracelist.add(ct); -// } -// } -// -// if (CMisc.version_load_now >= 0.017) { -// size = in.readInt(); -// if (CMisc.version_load_now <= 0.040) -// for (int i = 0; i < size; i++) { -// Cedmark ce = new Cedmark(); -// ce.Load(in, this); -// otherlist.add(ce); -// } -// else { -// for (int i = 0; i < size; i++) { -// int t = in.readInt(); -// switch (t) { -// -// case CClass.TMARK: { -// CTMark mt = new CTMark(); -// mt.Load(in, this); -// otherlist.add(mt); -// } -// break; -// case CClass.ARROW: { -// CArrow ar = new CArrow(null, null); -// ar.Load(in, this); -// otherlist.add(ar); -// break; -// } -// case CClass.EQMARK: -// case 0: { -// Cedmark ce = new Cedmark(); -// ce.Load(in, this); -// otherlist.add(ce); -// } -// break; -// default: -// CMisc.eprint(panel, "Mark unidentified!"); -// break; -// } -// } -// } -// -// } -// -// -// this.optmizePolynomial(); -// -// size = in.readInt(); -// for (int i = 0; i < size; i++) { -// constraint cs = (constraint) constraintlist.get(i); -// cs.Load(in, this); -// if (cs.is_poly_genereate) { -// cs.PolyGenerate(); -// this.charsetAndAddPoly(true); -// } -// -// } -// -//// for (int i = 0; i < size; i++) { -//// constraint cs = (constraint) constraintlist.get(i); -//// -//// } -// -// size = in.readInt(); -// for (int i = 0; i < size; i++) { -// UndoStruct ud = new UndoStruct(0); -// ud.Load(in, this); -// undolist.add(ud); -// if (ud.m_type == UndoStruct.T_TO_PROVE_NODE) { -// drawData.setProveStatus(); -// } -// } -// -// currentUndo = new UndoStruct(0); -// currentUndo.Load(in, this); -// -// if (version >= 0.006) { -// int ti = in.readInt(); -// } -// -// if (CMisc.version_load_now >= 0.009) { //version 0.009 special for web saver. -// boolean isrun = in.readBoolean(); -// if (isrun) { -// this.animate = new AnimateC(); -// this.animate.Load(in, this); -// if (gxInstance != null) { -// { -// gxInstance.anButton.setEnabled(true); -// gxInstance.getAnimateDialog().setAttribute(animate); -// gxInstance.showAnimatePane(); -// } -// } -// } else { -// if (gxInstance != null) { -// { -// gxInstance.anButton.setEnabled(false); -// } -// } -// } -// } -// -// if (CMisc.version_load_now >= 0.017) { -// boolean havep = in.readBoolean(); -// if (havep) { -// cpfield = new CProveField(); -// cpfield.Load(in, this); -//// if (gxInstance != null) { -//// gxInstance.showProveBar(true); -//// } -// } -// } - //CMisc.id_count = idcount; - CurrentAction = MOVE; - //currentUndo.id = idcount; - - setSavedTag(); - return true; - } - - // New version that iterates over the ggb construction element + /** + * Loads a GeoGebra file and processes its construction steps. + * Disclaimer: New version that iterates over the ggb construction element + * + * @param in the data input stream of the file + * @param path the file path + * @return true if loaded successfully, false otherwise + * @throws IOException if an I/O error occurs + */ public boolean LoadGGB2(DataInputStream in, String path) throws IOException { //BUG: Axis Ratio needs to be 1:1 // Reset everything in the current construction @@ -11405,7 +12638,7 @@ public boolean LoadGGB2(DataInputStream in, String path) throws IOException { String name = output.getNamedItem("a0").getTextContent(); boolean processed = false; int n; - for (n=0; !processed; n++) { + for (n = 0; !processed; n++) { Node node = input.getNamedItem("a" + n); if (node == null) { processed = true; @@ -11414,7 +12647,7 @@ public boolean LoadGGB2(DataInputStream in, String path) throws IOException { n--; CPolygon polygon = new CPolygon(); // n contains the number of vertices of the polygon - for (int vertex=0; vertex < n; vertex++) { + for (int vertex = 0; vertex < n; vertex++) { String nameP1 = input.getNamedItem("a" + vertex).getTextContent(); String nameP2 = input.getNamedItem("a" + (vertex + 1) % n).getTextContent(); String nameSegment = output.getNamedItem("a" + (vertex + 1)).getTextContent(); @@ -11571,7 +12804,7 @@ else if (step.getAttribute("name").equals("Midpoint")) { u.addObject(linePar); u.addObject(origLine); u.addObject(pts[0]); - linePar.m_name=nameLine; + linePar.m_name = nameLine; } } } else if (step.getAttribute("name").equals("OrthogonalLine")) { // Handle PerpendicularLine (OrthogonalLine) command @@ -11601,7 +12834,7 @@ else if (step.getAttribute("name").equals("Midpoint")) { u.addObject(linePerp); u.addObject(origLine); u.addObject(footPoint); - linePerp.m_name=nameLinePerp; + linePerp.m_name = nameLinePerp; } } else if (step.getAttribute("name").equals("LineBisector")) { NamedNodeMap outputName = step.getElementsByTagName("output").item(0).getAttributes(); @@ -11890,8 +13123,7 @@ else if (step.getAttribute("name").equals("Midpoint")) { c.set_conc(true); GExpert.conclusion = c; // working around that some data may be missing here exprs.put(name, c); - } - else { + } else { System.out.println("Unsupported command: " + step.getAttribute("name")); } break; @@ -11923,6 +13155,7 @@ else if (step.getAttribute("name").equals("Midpoint")) { /** * Get conclusion (and eventually set it globally if a workaround is required). + * * @param parameter input string, e.g. AreCollinear(A, B, C) * @param points * @param lines @@ -11986,12 +13219,12 @@ Cons getConclusion(String parameter, ArrayList points, GExpert.conclusion = c; // working around that some data may be missing here: } } else if (parameter.contains("∥")) { - int condtype = CST.getClu_D("Parallel"); - String parameter1 = parameter.substring(0, parameter.indexOf("∥")).trim(); - String parameter2 = parameter.substring(parameter.indexOf("∥") + 1).trim(); - c = new Cons(condtype); - setConclusionParameters2Lines(points, lines, c, parameter1, parameter2); - c.set_conc(true); + int condtype = CST.getClu_D("Parallel"); + String parameter1 = parameter.substring(0, parameter.indexOf("∥")).trim(); + String parameter2 = parameter.substring(parameter.indexOf("∥") + 1).trim(); + c = new Cons(condtype); + setConclusionParameters2Lines(points, lines, c, parameter1, parameter2); + c.set_conc(true); } else if (parameter.contains("≟")) { int condtype = -1; // dummy init String parameter1 = parameter.substring(0, parameter.indexOf("≟")).trim(); @@ -12200,6 +13433,16 @@ Cons getConclusion(String parameter, ArrayList points, return c; } + /** + * Handles the GGB prove process by setting the conclusion based on the input element and existing expressions. + * + * @param step the XML element representing the prove step + * @param points the list of points + * @param segmentsGgb the list of GGB segments + * @param lines the list of lines + * @param circles the list of circles + * @param exprs the map of constraint expressions + */ void handleGGBProve(Element step, ArrayList points, ArrayList segmentsGgb, ArrayList lines, ArrayList circles, HashMap exprs) { @@ -12218,6 +13461,12 @@ void handleGGBProve(Element step, ArrayList points, } } + /** + * Extracts the parameter list from a string representation. + * + * @param parameter the string containing parameter list enclosed in brackets + * @return an array of trimmed parameter strings + */ String[] getParameterList(String parameter) { // We assume that the list begins and ends with "[" and "]". String parameterItems = parameter.substring(parameter.indexOf("[")); @@ -12231,6 +13480,13 @@ String[] getParameterList(String parameter) { return parameterList; } + /** + * Retrieves a point from the list by its name. + * + * @param points the list of points + * @param parameterItem the name of the point to retrieve + * @return the corresponding CPoint, or null if not found + */ CPoint getCPoint(ArrayList points, String parameterItem) { for (CPoint p : points) { if (p.getname().equals(parameterItem)) { @@ -12240,6 +13496,13 @@ CPoint getCPoint(ArrayList points, String parameterItem) { return null; } + /** + * Retrieves a GGB segment from the list by its name. + * + * @param segmentsGgb the list of GGB segments + * @param parameterItem the name of the segment to retrieve + * @return the corresponding GgbSegment, or null if not found + */ GgbSegment getGgbSegment(ArrayList segmentsGgb, String parameterItem) { for (GgbSegment segment : segmentsGgb) { // Find segment if (segment.getName().equals(parameterItem)) { @@ -12249,6 +13512,14 @@ GgbSegment getGgbSegment(ArrayList segmentsGgb, String parameterItem return null; } + /** + * Detects a segment based on the provided parameter string. + * Supports both the "Distance[A, B]" format and concatenated point names. + * + * @param points the list of points + * @param parameterItem the string representing the segment + * @return an array containing the two CPoint objects that form the segment, or null if not found + */ CPoint[] detectSegment(ArrayList points, String parameterItem) { // Format Distance[A, B] if (parameterItem.startsWith("Distance")) { @@ -12273,6 +13544,15 @@ CPoint[] detectSegment(ArrayList points, String parameterItem) { return null; // not found } + /** + * Retrieves a line from the list by its name. + * Supports both a direct name lookup and a lookup based on concatenated point names. + * + * @param points the list of points + * @param lines the list of lines + * @param parameterItem the name or concatenated point names representing the line + * @return the corresponding CLine, or null if not identified + */ CLine getCLine(ArrayList points, ArrayList lines, String parameterItem) { // Format l for (CLine l : lines) { @@ -12295,6 +13575,13 @@ CLine getCLine(ArrayList points, ArrayList lines, String paramete return null; // unidentified } + /** + * Retrieves a circle from the list by its name. + * + * @param circles the list of circles + * @param parameterItem the name of the circle to retrieve + * @return the corresponding Circle, or null if not found + */ Circle getCircle(ArrayList circles, String parameterItem) { for (Circle c : circles) { if (c.getname().equals(parameterItem)) { @@ -12304,6 +13591,15 @@ Circle getCircle(ArrayList circles, String parameterItem) { return null; } + /** + * Sets the conclusion parameters for a relation between two lines. + * + * @param points the list of points + * @param lines the list of lines + * @param c the constraint to which the points will be added + * @param nameLine1 the name of the first line + * @param nameLine2 the name of the second line + */ void setConclusionParameters2Lines(ArrayList points, ArrayList lines, Cons c, String nameLine1, String nameLine2) { CLine l1 = getCLine(points, lines, nameLine1); @@ -12324,8 +13620,17 @@ void setConclusionParameters2Lines(ArrayList points, ArrayList li c.add_pt(p4, 3); } + /** + * Sets the conclusion parameters for a relation between two segments. + * + * @param points the list of points + * @param ggbSegments the list of GGB segments + * @param c the constraint to which the points will be added + * @param nameLine1 the name of the first segment (or its points) + * @param nameLine2 the name of the second segment (or its points) + */ void setConclusionParameters2Segments(ArrayList points, ArrayList ggbSegments, Cons c, String nameLine1, - String nameLine2) { + String nameLine2) { CPoint p1; CPoint p2; CPoint p3; @@ -12357,9 +13662,17 @@ void setConclusionParameters2Segments(ArrayList points, ArrayList points, Cons c, String namePoint1, - String namePoint2, String namePoint3) { + String namePoint2, String namePoint3) { CPoint p1 = getCPoint(points, namePoint1); CPoint p2 = getCPoint(points, namePoint2); @@ -12369,6 +13682,16 @@ void setConclusionParameters3Points(ArrayList points, Cons c, String nam c.add_pt(p3, 2); } + /** + * Sets the conclusion parameters for a relation defined by four points. + * + * @param points the list of points + * @param c the constraint to which the points will be added + * @param namePoint1 the name of the first point + * @param namePoint2 the name of the second point + * @param namePoint3 the name of the third point + * @param namePoint4 the name of the fourth point + */ void setConclusionParameters4Points(ArrayList points, Cons c, String namePoint1, String namePoint2, String namePoint3, String namePoint4) { @@ -12383,8 +13706,7 @@ void setConclusionParameters4Points(ArrayList points, Cons c, String nam } // taken from https://stackoverflow.com/a/1657688/1044586 - public static int[] GetFraction(double input) - { + public static int[] GetFraction(double input) { int p0 = 1; int q0 = 0; int p1 = (int) Math.floor(input); @@ -12394,15 +13716,14 @@ public static int[] GetFraction(double input) double r = input - p1; double next_cf; - while(true) - { + while (true) { r = 1.0 / r; next_cf = Math.floor(r); p2 = (int) (next_cf * p1 + p0); q2 = (int) (next_cf * q1 + q0); // Limit the numerator and denominator to be 256 or less - if(p2 > 256 || q2 > 256) + if (p2 > 256 || q2 > 256) break; // remember the last two fractions @@ -12416,17 +13737,13 @@ public static int[] GetFraction(double input) input = (double) p1 / q1; // hard upper and lower bounds for ratio - if(input > 256.0) - { + if (input > 256.0) { p1 = 256; q1 = 1; - } - else if(input < 1.0 / 256.0) - { + } else if (input < 1.0 / 256.0) { p1 = 1; q1 = 256; } - return new int[] {p1, q1}; + return new int[]{p1, q1}; } - } diff --git a/src/main/java/wprover/DrawTextProcess.java b/src/main/java/wprover/DrawTextProcess.java index 2ecd3d02..62f8ca7e 100644 --- a/src/main/java/wprover/DrawTextProcess.java +++ b/src/main/java/wprover/DrawTextProcess.java @@ -11,11 +11,21 @@ import java.io.IOException; import java.util.Vector; +/** + * DrawTextProcess is a class that handles the construction and animation of geometric diagrams + * based on textual input. It extends the DrawProcess class and provides methods for managing + * construction steps, point attributes, and geometric constraints. + */ public class DrawTextProcess extends DrawProcess { private Timer cons_timer; double PX, PY; + /** + * Checks if the construction process is currently active. + * + * @return true if the construction process is active, false otherwise + */ public boolean inConstruction() { if (gt == null) return false; @@ -24,6 +34,11 @@ public boolean inConstruction() { return nd > 1 && nd < n && n > 0; } + /** + * Checks if the construction process is finished. + * + * @return true if the construction process is finished, false otherwise + */ public boolean isConsFinished() { if (gt == null) return true; @@ -32,6 +47,11 @@ public boolean isConsFinished() { return nd > n; } + /** + * Sets the construction lines for the given geometric term. + * + * @param g the geometric term + */ public void setConstructLines(GTerm g) { cleardText(); this.clearAll(); @@ -39,11 +59,20 @@ public void setConstructLines(GTerm g) { nd = 1; } + /** + * Clears the construction text. + */ public void cleardText() { gt = null; nd = 1; } + /** + * Animates a diagram from the given string. + * + * @param s the string representing the animation + * @return true if the animation was successfully loaded, false otherwise + */ public boolean animateDiagramFromString(String s) { AnimateC an = new AnimateC(); if (false == an.loadAnimationString(s, this)) { @@ -60,6 +89,11 @@ public boolean animateDiagramFromString(String s) { return true; } + /** + * Automatically constructs the diagram from the given geometric term. + * + * @param g the geometric term + */ public void autoConstruct(GTerm g) { cleardText(); @@ -115,6 +149,12 @@ public void actionPerformed(ActionEvent e) { } } + /** + * Writes the positions of points to the given output stream. + * + * @param out the output stream to write to + * @throws IOException if an I/O error occurs + */ public void writePointPosition(FileOutputStream out) throws IOException { int n = pointlist.size(); for (int i = 0; i < n; i++) { @@ -152,6 +192,11 @@ public void writePointPosition(FileOutputStream out) throws IOException { } } + /** + * Adds an auxiliary point to the construction. + * + * @param ax the auxiliary point to add + */ public void addAuxPoint(AuxPt ax) { if (this.isConsFinished()) { int act = gxInstance.dp.CurrentAction; @@ -186,11 +231,22 @@ public void addAuxPoint(AuxPt ax) { } + /** + * Sets the attributes of a point as constructed. + * + * @param pt the point to set attributes for + */ public void setPointAttrAsConstructed(CPoint pt) { pt.setRadius(6); pt.setColor(8); } + /** + * Adds a free point to the construction. + * + * @param c the construction object + * @return true if a free point was added, false otherwise + */ public boolean addFreePt(Cons c) { int[] pp = c.ps; for (int i = 0; i < pp.length && pp[i] != 0; i++) { @@ -201,6 +257,12 @@ public boolean addFreePt(Cons c) { return false; } + /** + * Adds a geometric term point to the construction. + * + * @param c the construction object + * @return true if a geometric term point was added, false otherwise + */ public boolean addGTPt(Cons c) { int[] pp = c.ps; int i = 0; @@ -217,6 +279,12 @@ public boolean addGTPt(Cons c) { return false; } + /** + * Adds a point to the construction by its index. + * + * @param n the index of the point + * @return the added point + */ public CPoint addPt2(int n) { int x = gt.getPointsNum(); for (int i = 1; i <= x && i < n; i++) { @@ -227,6 +295,13 @@ public CPoint addPt2(int n) { return addPt(n); } + /** + * Adds a point to a line in the construction. + * + * @param p1 the index of the point to add + * @param p2 the index of the first point of the line + * @param p3 the index of the second point of the line + */ public void addPt2Line(int p1, int p2, int p3) { CLine ln = fd_line(p2, p3); if (ln == null) @@ -239,10 +314,23 @@ public void addPt2Line(int p1, int p2, int p3) { this.addConstraintToList(cs); } + /** + * Handles mouse down events at the specified coordinates. + * + * @param x the x-coordinate + * @param y the y-coordinate + */ public void mouseDown(double x, double y) { mouseDown(x, y, false); } + /** + * Handles mouse down events at the specified coordinates with an option to clear constraints. + * + * @param x the x-coordinate + * @param y the y-coordinate + * @param cc a flag indicating whether to clear constraints + */ public void mouseDown(double x, double y, boolean cc) { if (CurrentAction == CONSTRUCT_FROM_TEXT) { @@ -276,13 +364,29 @@ public void mouseDown(double x, double y, boolean cc) { } else finishConstruction(); } else if (addPt2(gt.getPointsNum()) == null) finishConstruction(); - } else - - { + } else { super.DWButtonDown(x, y); } } + /** + * Processes the provided construction point and applies the appropriate geometric constraints + * and operations based on its type. + * + *

This method examines the type of the provided construction object and executes the corresponding + * logic to update the constraint and geometric element lists. Depending on the provided parameters, + * it adds points, lines, circles, angles, or other entities and registers constraints related to them.

+ * + * @param pt the construction object encapsulating geometric data and type information + * @param type the specific type of construction operation to execute + * @param pp an array of integers representing indices for points and other parameters + * @param cc a boolean flag indicating whether to perform specific additional operations + * @param index an identifier used for certain point creation methods + * @param x the x-coordinate value used for point creation if applicable + * @param y the y-coordinate value used for point creation if applicable + * @param cp a CPoint object that will be updated or used during the construction + * @param pss an array of additional parameters used for constructing constants or constraints + */ public void pointAdded(Cons pt, int type, int[] pp, boolean cc, int index, double x, double y, CPoint cp, Object[] pss) { switch (pt.type) { case GDDBase.C_POINT: { @@ -1212,6 +1316,12 @@ public void pointAdded(Cons pt, int type, int[] pp, boolean cc, int index, doubl } } + /** + * Finds a constant parameter by its name. + * + * @param name the name of the constant parameter + * @return the constant parameter, or null if not found + */ public Param findConstantParam(String name) { for (int i = 0; i < constraintlist.size(); i++) { Constraint cs = (Constraint) constraintlist.get(i); @@ -1225,6 +1335,13 @@ public Param findConstantParam(String name) { return null; } + /** + * Adds visual flashing effects for up to three objects. + * + * @param c1 the first object to flash + * @param c2 the second object to flash + * @param c3 the third object to flash + */ public void addObjectFlash(CClass c1, CClass c2, CClass c3) { clearFlash(); int n = CMisc.getFlashInterval(); @@ -1236,13 +1353,12 @@ public void addObjectFlash(CClass c1, CClass c2, CClass c3) { } if (c2 != null) { - JFlash f = this.getObjectFlash(c2); f.setDealy(n / 2); addFlash1(f); } - if (c2 != null) { + if (c3 != null) { JFlash f = this.getObjectFlash(c3); f.setDealy(n / 2); addFlash1(f); @@ -1250,12 +1366,16 @@ public void addObjectFlash(CClass c1, CClass c2, CClass c3) { panel.repaint(); } + /** + * Renders visual flashing effects for a given construction. + * + * @param c the construction + */ public void flashcons(Cons c) { if (c == null) return; switch (c.type) { case Gib.C_POINT: -// this.setObjectListForFlash(this.fd_line()); break; case Gib.C_O_L: addObjectFlash(fd_point(c.ps[0]), fd_line(c.ps[1], c.ps[2]), null); @@ -1306,11 +1426,12 @@ public void flashcons(Cons c) { default: addObjectFlash(fd_point(c.ps[0]), null, null); break; - - } } + /** + * Finishes the construction process. + */ public void finishConstruction() { gxInstance.setActionMove(); this.SetCurrentAction(MOVE); @@ -1319,6 +1440,11 @@ public void finishConstruction() { this.flashCond(gterm().getConc(), true); } + /** + * Adds lines or circles based on the given condition. + * + * @param cc the condition + */ public void addConcLineOrCircle(Cond cc) { if (cc == null) return; @@ -1335,6 +1461,11 @@ public void addConcLineOrCircle(Cond cc) { } } + /** + * Adds all lines based on the given points. + * + * @param pp the points + */ public void addAllLn(int[] pp) { SelectList.clear(); int p1, p2; @@ -1355,6 +1486,12 @@ else if (p2 == 0) this.addToSelectList(addLn(p2, pp[0])); } + /** + * Retrieves a point by its index. + * + * @param i the index of the point + * @return the point, or null if not found + */ CPoint getPt(int i) { String s = gterm().getPtName(i); @@ -1366,12 +1503,23 @@ CPoint getPt(int i) { return null; } + /** + * Checks if a point is free. + * + * @param n the index of the point + * @return true if the point is free, false otherwise + */ public boolean isFreePoint(int n) { GTerm gt = gterm(); return gt.isFreePoint(n); } - + /** + * Adds a point by its index. + * + * @param index the index of the point + * @return the added point + */ CPoint addPt(int index) { ProPoint pt = gterm().getProPoint(index); CPoint cp = null; @@ -1388,16 +1536,39 @@ CPoint addPt(int index) { return cp; } + /** + * Adds a point by its index and sets its coordinates. + * + * @param index the index of the point + * @param x the x-coordinate of the point + * @param y the y-coordinate of the point + * @return the added point + */ CPoint addPt(int index, double x, double y) { CPoint p = this.addPt(index); p.setXY(x, y); return p; } + /** + * Finds a line between two points. + * + * @param a the index of the first point + * @param b the index of the second point + * @return the line, or null if not found + */ CLine fd_line(int a, int b) { return fd_line(getPt(a), getPt(b)); } + /** + * Finds a parallel line through a point. + * + * @param a the index of the point + * @param b the index of the first point of the line + * @param c the index of the second point of the line + * @return the parallel line, or null if not found + */ CLine fd_p_line(int a, int b, int c) { CPoint A = getPt(a); CLine ln = fd_line(b, c); @@ -1418,6 +1589,14 @@ CLine fd_p_line(int a, int b, int c) { return null; } + /** + * Finds a perpendicular line through a point. + * + * @param a the index of the point + * @param b the index of the first point of the line + * @param c the index of the second point of the line + * @return the perpendicular line, or null if not found + */ CLine fd_t_line(int a, int b, int c) { CPoint A = getPt(a); CLine ln = fd_line(b, c); @@ -1438,26 +1617,13 @@ CLine fd_t_line(int a, int b, int c) { return null; } - CLine fd_b_line(int a, int b, int c) { - CPoint A = getPt(a); - CPoint B = getPt(b); - CPoint C = getPt(c); - for (int i = 0; i < constraintlist.size(); i++) { - Constraint cs = (Constraint) constraintlist.get(i); - int t = cs.GetConstraintType(); - if (t == Constraint.PERPBISECT) { - CPoint p1 = (CPoint) cs.getelement(0); - CPoint p2 = (CPoint) cs.getelement(1); - CPoint p3 = (CPoint) cs.getelement(1); - - if (A == p1 && ((B == p2 && C == p3) || (B == p3 && C == p2))) { - return this.fd_line(b, c); - } - } - } - return null; - } - + /** + * Adds a circle through two points. + * + * @param o the index of the center point + * @param a the index of the point on the circle + * @return the added circle + */ Circle ad_circle(int o, int a) { Circle c = fd_circle(o, a); if (c != null) { @@ -1468,21 +1634,14 @@ Circle ad_circle(int o, int a) { return c; } - - Circle fd_circle3(int a, int b, int c) { - CPoint A = getPt(a); - CPoint B = getPt(b); - CPoint C = getPt(c); - for (int i = 0; i < circlelist.size(); i++) { - Circle cc = (Circle) circlelist.get(i); - if (cc.points.contains(A) && cc.points.contains(B) && - cc.points.contains(C)) { - return cc; - } - } - return null; - } - + /** + * Adds a perpendicular line through a point. + * + * @param a the index of the point + * @param b the index of the first point of the line + * @param c the index of the second point of the line + * @return the added perpendicular line + */ CLine addTLn(int a, int b, int c) { CPoint p1 = getPt(a); CLine lp = this.fd_line(b, c); @@ -1497,6 +1656,14 @@ CLine addTLn(int a, int b, int c) { return ln; } + /** + * Adds a parallel line through a point. + * + * @param a the index of the point + * @param b the index of the first point of the line + * @param c the index of the second point of the line + * @return the added parallel line + */ CLine addPLn(int a, int b, int c) { CPoint p1 = getPt(a); CLine lp = this.fd_line(b, c); @@ -1511,6 +1678,13 @@ CLine addPLn(int a, int b, int c) { return ln; } + /** + * Adds a line between two points. + * + * @param a the index of the first point + * @param b the index of the second point + * @return the added line, or null if the points are invalid + */ CLine addLn(int a, int b) { if (a == 0 || b == 0 || a == b) return null; @@ -1522,23 +1696,19 @@ CLine addLn(int a, int b) { CLine line = new CLine(p1, p2, CLine.LLine); this.addLineToList(line); return line; - } else { return ln; } } - public CPoint llmeet(CLine ln, CLine ln1) { - for (int i = 0; i < ln.points.size(); i++) { - CPoint t = (CPoint) ln.points.get(i); - if (ln1.points.contains(t)) { - return t; - } - } - return null; - } - + /** + * Finds the intersection point between a circle and a line. + * + * @param c the circle + * @param ln the line + * @return the intersection point, or null if no intersection + */ public CPoint lcmeet(Circle c, CLine ln) { for (int i = 0; i < c.points.size(); i++) { CPoint t = (CPoint) c.points.get(i); @@ -1550,6 +1720,14 @@ public CPoint lcmeet(Circle c, CLine ln) { return null; } + /** + * Finds the intersection point between a circle and a line, excluding a specific point. + * + * @param c the circle + * @param ln the line + * @param p1 the point to exclude from the search + * @return the intersection point, or null if no intersection + */ public CPoint lcmeet(Circle c, CLine ln, CPoint p1) { for (int i = 0; i < c.points.size(); i++) { CPoint t = (CPoint) c.points.get(i); @@ -1560,6 +1738,12 @@ public CPoint lcmeet(Circle c, CLine ln, CPoint p1) { return null; } + /** + * Renders visual flashing effects for a given condition. + * + * @param co the condition + * @param fb a flag indicating whether to clear existing flash effects + */ public void flashCond(Cond co, boolean fb) { if (this.pointlist.size() == 0) { return; @@ -1582,7 +1766,13 @@ public void flashCond(Cond co, boolean fb) { } } - + /** + * Retrieves a flash effect for a given condition. + * + * @param co the condition + * @param fb a flag indicating whether to clear existing flash effects + * @return the flash effect + */ public JFlash getCond(Cond co, boolean fb) { if (this.pointlist.size() == 0) { return null; @@ -1591,6 +1781,12 @@ public JFlash getCond(Cond co, boolean fb) { return getFlashCond(panel, co, fb); } + /** + * Adds a congruence flash effect for a given condition. + * + * @param co the condition + * @param cl a flag indicating whether to clear existing flash effects + */ public void addCongFlash(Cond co, boolean cl) { if (co == null) { return; @@ -1602,6 +1798,12 @@ public void addCongFlash(Cond co, boolean cl) { } } + /** + * Adds an angle congruence flash effect for a given condition. + * + * @param co the condition + * @param cl a flag indicating whether to clear existing flash effects + */ public void addAcongFlash(Cond co, boolean cl) { if (co.pred == Gib.CO_ACONG) { if (cl) { @@ -1618,22 +1820,13 @@ public void addAcongFlash(Cond co, boolean cl) { } } - public Vector getAcongFlash(JPanel panel, Cond co) { - Vector v = new Vector(); - if (co.pred == Gib.CO_ACONG) { - int[] vp = co.p; - if (vp[0] == 0) { - return null; - } - JFlash f = getAngleFlash(panel, vp[0], vp[1], vp[2], vp[3]); - - v.add(f); - f = getAngleFlash(panel, vp[4], vp[5], vp[6], vp[7]); - v.add(f); - } - return v; - } - + /** + * Adds a line between two points. + * + * @param a the first point + * @param b the second point + * @return the line, or null if the points are invalid + */ public CLine add_Line(CPoint a, CPoint b) { if (a == null || b == null) return null; CLine ln = fd_line(a, b); @@ -1643,6 +1836,15 @@ public CLine add_Line(CPoint a, CPoint b) { return ln; } + /** + * Adds a line with specific color and dash style between two points. + * + * @param a the first point + * @param b the second point + * @param color the color of the line + * @param d the dash style of the line + * @return the line + */ public CLine addLnWC(CPoint a, CPoint b, int color, int d) { CLine ln = null; if ((ln = this.fd_line(a, b)) == null) { @@ -1655,15 +1857,28 @@ public CLine addLnWC(CPoint a, CPoint b, int color, int d) { return ln; } + /** + * Retrieves a point from a condition by its index. + * + * @param c the condition + * @param n the index of the point + * @return the point, or null if not found + */ public CPoint getPtN(Cons c, int n) { if (c == null) return null; Object o = c.getPTN(n); if (o == null) return null; String s = o.toString(); return this.findPoint(s); - } + /** + * Adds auxiliary conditions for a given condition. + * + * @param co the condition + * @param aux a flag indicating whether to add auxiliary conditions + * @return a vector of added lines + */ public Vector addCondAux(Cons co, boolean aux) { Vector vl = new Vector(); if (co == null) { @@ -1683,9 +1898,7 @@ public Vector addCondAux(Cons co, boolean aux) { break; case Gib.CO_PARA: case Gib.CO_PERP: - case Gib.CO_CONG: - - { + case Gib.CO_CONG: { CLine ln1 = this.addLnWC(getPtN(co, 0), getPtN(co, 1), DrawData.RED, d); CLine ln2 = this.addLnWC(getPtN(co, 2), getPtN(co, 3), DrawData.RED, d); vl.add(ln1); @@ -1716,11 +1929,26 @@ public Vector addCondAux(Cons co, boolean aux) { return vl; } + /** + * Retrieves a flash effect for a given condition. + * + * @param panel the panel to display the flash effect + * @param co the condition + * @param fb a flag indicating whether to clear existing flash effects + * @return the flash effect + */ public JFlash getFlashCond(JPanel panel, Cond co, boolean fb) { JFlash f = this.getFlashCond(panel, co); return f; } + /** + * Retrieves a flash effect for a given condition. + * + * @param panel the panel to display the flash effect + * @param co the condition + * @return the flash effect + */ public JFlash getFlashCond(JPanel panel, Cond co) { if (this.pointlist.size() == 0) { @@ -1816,10 +2044,31 @@ public JFlash getFlashCond(JPanel panel, Cond co) { } + /** + * Retrieves an angle flash effect for two lines intersecting at a point. + * + * @param panel the panel to display the flash effect + * @param p1 the first point of the first line + * @param p2 the second point of the first line + * @param p3 the first point of the second line + * @param p4 the second point of the second line + * @return the angle flash effect + */ public JFlash getAngleFlash(JPanel panel, int p1, int p2, int p3, int p4) { return getMAngleFlash(panel, fd_point(p1), fd_point(p2), fd_point(p3), fd_point(p4), 1); // full angle. } + /** + * Retrieves a modified angle flash effect for two lines intersecting at a point. + * + * @param panel the panel to display the flash effect + * @param p1 the first point of the first line + * @param p2 the second point of the first line + * @param p3 the first point of the second line + * @param p4 the second point of the second line + * @param t the type of angle flash effect + * @return the modified angle flash effect + */ public JFlash getMAngleFlash(JPanel panel, CPoint p1, CPoint p2, CPoint p3, CPoint p4, int t) { CAngle ag = fd_angle_m(p1, p2, p3, p4); if (ag != null) { @@ -1843,14 +2092,11 @@ public JFlash getMAngleFlash(JPanel panel, CPoint p1, CPoint p2, CPoint p3, CPoi return f; } - public void flashMpnode(MObject obj) { - if (obj instanceof MAssertion) { - - } else if (obj instanceof MDrObj) { - - } - } - + /** + * Retrieves the number of area flash effects. + * + * @return the number of area flash effects + */ public int getAreaFlashNumber() { int n = 0; for (int i = 0; i < flashlist.size(); i++) { @@ -1862,6 +2108,12 @@ public int getAreaFlashNumber() { return n; } + /** + * Retrieves an area flash effect for a given drawing object. + * + * @param d the drawing object + * @return the area flash effect + */ public JFlash getAreaFlash(MDrObj d) { int n = this.getAreaFlashNumber(); Vector v = new Vector(); @@ -1880,6 +2132,12 @@ public JFlash getAreaFlash(MDrObj d) { return f; } + /** + * Retrieves a flash effect for a given drawing object. + * + * @param d the drawing object + * @return the flash effect + */ public JFlash getDrobjFlash(MDrObj d) { int t1 = d.getType1(); if (t1 == MDrObj.LINE) { @@ -1907,6 +2165,11 @@ public JFlash getDrobjFlash(MDrObj d) { return null; } + /** + * Renders visual flashing effects for a given node. + * + * @param n the node + */ public void flashmnode(MNode n) { for (int i = 0; i < n.objSize(); i++) { @@ -1915,10 +2178,21 @@ public void flashmnode(MNode n) { } } + /** + * Renders visual flashing effects for a given object. + * + * @param obj the object + */ public void flashmobj(MObject obj) { flashmobj(obj, true); } + /** + * Renders visual flashing effects for a given object. + * + * @param obj the object + * @param clear whether to clear existing flash effects + */ public void flashmobj(MObject obj, boolean clear) { if (obj == null) { return; @@ -1967,6 +2241,12 @@ public void flashmobj(MObject obj, boolean clear) { } } + /** + * Adds a flash effect for a line. + * + * @param p1 the first point of the line + * @param p2 the second point of the line + */ public void addlineFlash(CPoint p1, CPoint p2) { JLineFlash f = new JLineFlash(panel); int id = f.addALine(); @@ -1975,6 +2255,12 @@ public void addlineFlash(CPoint p1, CPoint p2) { addFlash1(f); } + /** + * Adds a flash effect for an infinite line. + * + * @param p1 the first point of the line + * @param p2 the second point of the line + */ public void addInfinitelineFlash(CPoint p1, CPoint p2) { JLineFlash f = new JLineFlash(panel); int id = f.addALine(); @@ -1984,6 +2270,19 @@ public void addInfinitelineFlash(CPoint p1, CPoint p2) { addFlash1(f); } + /** + * Renders visual flashing effects for a given assertion. + * + *

+ * This method examines the type of the provided MAssertion and + * displays the corresponding flash pattern based on the assertion type. + * It supports various assertion types such as collinearity, parallelism, + * equality of distances, perpendicularity, cyclic configurations, angle equality, + * midpoint conditions, congruency, triangle properties, and several others. + *

+ * + * @param ass the geometric assertion to be processed and flashed; may be null + */ public void flashassert(MAssertion ass) { if (ass == null) return; @@ -2221,11 +2520,24 @@ public void flashassert(MAssertion ass) { } + /** + * Adds a flash effect to enlarge a point. + * + * @param pt the point to enlarge + */ public void addPtEnlargeFlash(CPoint pt) { JPointEnlargeFlash f = new JPointEnlargeFlash(panel, pt); this.addFlash1(f); } + /** + * Adds a flash effect for congruent segments. + * + * @param p1 the first point of the first segment + * @param p2 the second point of the first segment + * @param p3 the first point of the second segment + * @param p4 the second point of the second segment + */ public void addCGFlash(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { JCgFlash f1 = new JCgFlash(panel); f1.addACg(p1, p2); @@ -2240,6 +2552,11 @@ public void addCGFlash(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { this.startFlash(); } + /** + * Adds a flash effect for an area based on an assertion. + * + * @param ass the assertion containing the area information + */ public void addAreaFlash1(MAssertion ass) { int n = this.getAreaFlashNumber(); JAreaFlash f = new JAreaFlash(panel, n); @@ -2249,6 +2566,11 @@ public void addAreaFlash1(MAssertion ass) { this.addFlash1(f); } + /** + * Adds a flash effect for an area based on an assertion. + * + * @param ass the assertion containing the area information + */ public void addAreaFlash(MAssertion ass) { int n = this.getAreaFlashNumber(); JAreaFlash f = new JAreaFlash(panel, n); @@ -2258,6 +2580,15 @@ public void addAreaFlash(MAssertion ass) { this.addFlash1(f); } + /** + * Retrieves an angle flash effect for two lines intersecting at a point. + * + * @param panel the panel to display the flash effect + * @param p the intersection point + * @param l1 the first line + * @param l2 the second line + * @return the angle flash effect + */ public JFlash getAngleFlashLL(JPanel panel, int p, LLine l1, LLine l2) { int a, b; @@ -2273,6 +2604,12 @@ public JFlash getAngleFlashLL(JPanel panel, int p, LLine l1, LLine l2) { return f; } + /** + * Adds a flash effect for a geometric class. + * + * @param cc the geometric class + * @param panel the panel to display the flash effect + */ public void flashattr(gprover.CClass cc, JPanel panel) { if (cc == null) return; @@ -2457,12 +2794,15 @@ public void flashattr(gprover.CClass cc, JPanel panel) { } - public void falshPropoint(ProPoint pt) { - switch (pt.type) { - case Gib.C_CIRCUM: - } - } - + /** + * Finds and returns a JAngleFlash from the flash list that matches the given four points. + * + * @param a the first point + * @param b the second point + * @param c the third point + * @param d the fourth point + * @return the matching JAngleFlash if found; otherwise, null + */ public JAngleFlash find_angFlash(CPoint a, CPoint b, CPoint c, CPoint d) { for (int i = 0; i < flashlist.size(); i++) { JFlash flash = (JFlash) flashlist.get(i); @@ -2476,6 +2816,13 @@ public JAngleFlash find_angFlash(CPoint a, CPoint b, CPoint c, CPoint d) { return null; } + /** + * Creates or retrieves a flash angle based on an XTerm object. + * The flash is added to the flash list and its color is adjusted based on the PV value. + * + * @param x the XTerm object containing variable and point indices information + * @return the created or restarted flash; null if the XTerm, its variable, or any required point is not found + */ public JFlash addFlashXtermAngle(XTerm x) { if (x == null) { return null; @@ -2518,7 +2865,16 @@ public JFlash addFlashXtermAngle(XTerm x) { return f; } - + /** + * Creates or retrieves a flash angle based on the given point indices. + * The flash is added to the flash list and the panel is repainted. + * + * @param a the index of the first point + * @param b the index of the second point + * @param c the index of the third point + * @param d the index of the fourth point + * @return the created or restarted flash; null if any of the points is not found + */ public JFlash addFlashAngle(int a, int b, int c, int d) { CPoint p1 = fd_point(a); CPoint p2 = fd_point(b); @@ -2539,17 +2895,11 @@ public JFlash addFlashAngle(int a, int b, int c, int d) { return f; } - public void addauxPoint(int m1, int m2) { - CLine ln = this.fd_line(m1, m2); - if (ln != null) { - return; - } - ln = this.addLn(m1, m2); - ln.m_dash = 3; - ln.m_color = DrawData.getColorIndex(Color.red); - ln.m_width = 1; - } - + /** + * Processes auxiliary proof text to add the corresponding flashes, marks, or polygons. + * + * @param cpt the CProveText object containing condition and proof information + */ public void addaux(CProveText cpt) { Cond co = cpt.getcond(); if (co == null) { @@ -2712,6 +3062,13 @@ public void addaux(CProveText cpt) { this.UndoAdded("step"); } + /** + * Determines and returns an array of four point indices for defining an angle from the given array. + * Adjustments are made using line intersections if the direct configuration is ambiguous. + * + * @param pt an array of point indices relevant to the angle + * @return an array of four point indices that define the angle + */ int[] get4PtsForAngle(int[] pt) { int[] p = new int[4]; boolean rt1, rt2; @@ -2806,6 +3163,14 @@ int[] get4PtsForAngle(int[] pt) { return p; } + /** + * Calculates the cosine of the angle formed by three points identified by their indices. + * + * @param a the index of the first point + * @param b the index of the second point (vertex of the angle) + * @param c the index of the third point + * @return the cosine of the angle formed at point b + */ double cos3Pt(int a, int b, int c) { CPoint p1 = this.fd_point(a); CPoint p2 = this.fd_point(b); @@ -2820,6 +3185,12 @@ int[] get4PtsForAngle(int[] pt) { return cs; } + /** + * Adds a CAngle to the angle list. + * If an angle with similar intersection is already present, the radius is adjusted before adding. + * + * @param ag the CAngle object to be added + */ public void addAngleToList2(CAngle ag) { int num = 0; double[] p = CLine.Intersect(ag.lstart, ag.lend); @@ -2841,20 +3212,4 @@ public void addAngleToList2(CAngle ag) { } this.addAngleToList(ag); } - - - Constraint find_constraint(int t, Object obj1, Object obj2) { - for (int i = 0; i < constraintlist.size(); i++) { - Constraint c = (Constraint) constraintlist.get(i); - if (c.GetConstraintType() != t) { - continue; - } - Vector v = c.getAllElements(); - if (v.contains(obj1) && v.contains(obj2)) { - return c; - } - } - return null; - } - } diff --git a/src/main/java/wprover/DrawType.java b/src/main/java/wprover/DrawType.java index 74af8ba0..5a5da5d2 100644 --- a/src/main/java/wprover/DrawType.java +++ b/src/main/java/wprover/DrawType.java @@ -7,11 +7,8 @@ import java.io.DataInputStream; /** - * Created by IntelliJ IDEA. - * User: Administrator - * Date: 2005-3-3 - * Time: 13:54:48 - * To change this template use File | Settings | File Templates. + * The DrawType class represents a drawing type with properties such as color index, dash style, and width. + * It provides methods to save and load its state, set properties, and retrieve color information. */ public class DrawType { int color_index; @@ -19,21 +16,32 @@ public class DrawType { int width; +/** + * Default constructor for the DrawType class. + */ public DrawType() { } - public DrawType(int ci, int dash, int width) - { - color_index = ci; - this.dash = dash; - this.width = width; - } + + /** + * Saves the current state of the DrawType object to a DataOutputStream. + * + * @param out the DataOutputStream to write to + * @throws IOException if an I/O error occurs + */ public void Save(DataOutputStream out) throws IOException { out.writeInt(color_index); out.writeInt(dash); out.writeInt(width); } + + /** + * Loads the state of the DrawType object from a DataInputStream. + * + * @param in the DataInputStream to read from + * @throws IOException if an I/O error occurs + */ public void Load(DataInputStream in) throws IOException { color_index = in.readInt(); @@ -41,54 +49,43 @@ public void Load(DataInputStream in) throws IOException width = in.readInt(); } - public void setdrawType(Graphics2D g2) - { - if(color_index >= 0) - g2.setColor(DrawData.getColor(color_index)); - - float d =0; - if(dash >=0 ) - d = (float) DrawData.getDash(dash); - float w = (float) DrawData.getWidth(width); - - if(dash >0) - { - float dash[] = {d}; - g2.setStroke(new BasicStroke(w, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 5.0f, dash, 0.0f)); - }else g2.setStroke(new BasicStroke(w)); - - } - - - public void setColorIndex(int id) - { - color_index = id; - } + /** + * Sets the dash style for the DrawType object. + * + * @param dash the dash style to set + */ public void setDash(int dash) { this.dash = dash; } + + /** + * Sets the width for the DrawType object. + * + * @param width the width to set + */ public void setWidth(int width) { this.width = width; } + + /** + * Retrieves the color index of the DrawType object. + * + * @return the color index + */ public int getColorIndex() { return color_index; } + + /** + * Retrieves the color corresponding to the color index of the DrawType object. + * + * @return the color + */ public Color getColor() { return DrawData.getColor(color_index); } - public int getDashIndex() - { - return dash; - } - public int getWidthIndex() - { - return width; - } -////////////// /////////// - - } diff --git a/src/main/java/wprover/FactFinderDialog.java b/src/main/java/wprover/FactFinderDialog.java index fa3c7cca..1a37b753 100644 --- a/src/main/java/wprover/FactFinderDialog.java +++ b/src/main/java/wprover/FactFinderDialog.java @@ -8,7 +8,10 @@ import java.awt.event.*; import java.util.Vector; - +/** + * FactFinderDialog is a dialog that allows users to search for geometric facts based on selected points and types. + * It extends JBaseDialog and implements ActionListener and ItemListener interfaces. + */ public class FactFinderDialog extends JBaseDialog implements ActionListener, ItemListener { final private static String[] S = @@ -24,6 +27,13 @@ public class FactFinderDialog extends JBaseDialog implements ActionListener, Ite private JList list; + /** + * Constructs a FactFinderDialog with the specified owner, type, and title. + * + * @param owner the GExpert instance that owns this dialog + * @param type the type of fact to find + * @param title the title of the dialog + */ public FactFinderDialog(GExpert owner, int type, String title) { super(owner.getFrame(), title); gxInstance = owner; @@ -98,6 +108,11 @@ public void mouseExited(MouseEvent e) { this.setSize(300, 400); } + /** + * Sets the points in the combo boxes. + * + * @param v the vector of points to set + */ public void setPoints(Vector v) { b1.removeAllItems(); b2.removeAllItems(); @@ -110,12 +125,18 @@ public void setPoints(Vector v) { } } + /** + * Shows the dialog. + */ public void showDialog() { reselect(); bs.setSelectedIndex(-1); this.setVisible(true); } + /** + * Reselects the combo boxes based on the find type. + */ private void reselect() { if (find_type == 0 || find_type == 3 || find_type == 4 || find_type == 6) b3.setEnabled(false); @@ -129,6 +150,11 @@ private void reselect() { b3.setSelectedIndex(-1); } + /** + * Handles action events for the buttons. + * + * @param e the action event + */ public void actionPerformed(ActionEvent e) { Object src = e.getSource(); if (src == bcancel) { @@ -166,6 +192,11 @@ public void actionPerformed(ActionEvent e) { } } + /** + * Selects a point in the combo boxes. + * + * @param b the point to select + */ public void selectAPoint(Object b) { if (b1.getSelectedIndex() == -1) b1.setSelectedItem(b); @@ -175,6 +206,11 @@ else if (b3.getSelectedIndex() == -1) b3.setSelectedItem(b); } + /** + * Handles item state changes for the combo boxes. + * + * @param e the item event + */ public void itemStateChanged(ItemEvent e) { JComboBox bx = (JComboBox) e.getSource(); if (bx == bs) { diff --git a/src/main/java/wprover/FloatableToolBar.java b/src/main/java/wprover/FloatableToolBar.java index 7e168bc9..156931ac 100644 --- a/src/main/java/wprover/FloatableToolBar.java +++ b/src/main/java/wprover/FloatableToolBar.java @@ -7,42 +7,68 @@ import java.awt.event.*; /** - * Created by IntelliJ IDEA. - * User: yezheng - * Date: 2006-6-17 - * Time: 13:11:37 - * To change this template use File | Settings | File Templates. + * FloatableToolBar is a custom popup menu that can be dragged around the screen. + * It contains a close button and allows the user to move it by dragging. + * It is used in the GExpert application to provide a floating toolbar for various tools. + * The toolbar can be shown at the bottom of the screen and can be closed by clicking the close button. */ public class FloatableToolBar extends JPopupMenu { int x, y; JPanel mpanel; JToggleButton bquit; + /** + * Returns the maximum size of the toolbar. + * + * @return the maximum size of the toolbar + */ public Dimension getMaximumSize() { Dimension dm = super.getMaximumSize(); dm.setSize(Integer.MAX_VALUE, super.getPreferredSize().getHeight()); return dm; } + /** + * Shows the toolbar at the bottom of the specified component. + * + * @param invoker the component to show the toolbar on + */ public void show(Component invoker) { int h = invoker.getHeight(); int w = invoker.getWidth(); super.show(invoker, 0, h - (int) this.getPreferredSize().getHeight() - 2); } + /** + * Handles changes in menu selection. + * + * @param isIncluded whether the menu is included in the selection + */ public void menuSelectionChanged(boolean isIncluded) { } + /** + * Constructs a FloatableToolBar. + */ public FloatableToolBar() { this.setBorder(null); this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); - JToggleButton button = new JToggleButton(GExpert.createImageIcon("images/quit.gif")) { + /** + * Returns the preferred size of the button. + * + * @return the preferred size of the button + */ public Dimension getPreferredSize() { return super.getMinimumSize(); } + /** + * Returns the maximum size of the button. + * + * @return the maximum size of the button + */ public Dimension getMaximumSize() { return super.getMinimumSize(); } @@ -53,6 +79,11 @@ public Dimension getMaximumSize() { button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); button.setToolTipText(GExpert.getLanguage("Close")); button.addActionListener(new ActionListener() { + /** + * Hides the toolbar when the button is clicked. + * + * @param e the action event + */ public void actionPerformed(ActionEvent e) { FloatableToolBar.this.setVisible(false); JToggleButton b = (JToggleButton) e.getSource(); @@ -70,21 +101,30 @@ public void actionPerformed(ActionEvent e) { this.add(mpanel); mpanel.addMouseMotionListener(new MouseMotionListener() { + /** + * Moves the toolbar when the mouse is dragged. + * + * @param e the mouse event + */ public void mouseDragged(MouseEvent e) { int dx = e.getX() - x; int dy = e.getY() - y; movetoDxy(dx, dy); - } public void mouseMoved(MouseEvent e) { } - }); + mpanel.addMouseListener(new MouseListener() { public void mouseClicked(MouseEvent e) { } + /** + * Records the initial mouse position when the mouse is pressed. + * + * @param e the mouse event + */ public void mousePressed(MouseEvent e) { x = e.getX(); y = e.getY(); @@ -99,11 +139,15 @@ public void mouseEntered(MouseEvent e) { public void mouseExited(MouseEvent e) { } }); - } + /** + * Moves the toolbar by the specified delta values. + * + * @param xx the delta x value + * @param yy the delta y value + */ public void movetoDxy(int xx, int yy) { - int dx = xx; int dy = yy; Point pt = FloatableToolBar.this.getLocationOnScreen(); @@ -133,6 +177,5 @@ else if (ty + ht > pt1.getY() + h) else y = ty; FloatableToolBar.this.setLocation(x, y); - } } diff --git a/src/main/java/wprover/GExpert.java b/src/main/java/wprover/GExpert.java index 1e1ebbe6..ee0c9d04 100644 --- a/src/main/java/wprover/GExpert.java +++ b/src/main/java/wprover/GExpert.java @@ -36,6 +36,11 @@ import org.apache.commons.cli.*; +/** + * GExpert is the main class for the GEXPERT application. + * It initializes the application, sets up the GUI, and handles user interactions. + * It also manages the language settings and file operations. + */ public class GExpert extends JFrame implements ActionListener, KeyListener, DropTargetListener, WindowListener { // APPLET ONLY. private JLabel label; @@ -92,24 +97,29 @@ public class GExpert extends JFrame implements ActionListener, KeyListener, Drop public static gprover.Cons conclusion = null; // Temporary fix for storing conclusion with == in GGB import + /** + * Constructs a new GExpert instance and initializes the application if it is running as an application. + */ public GExpert() { super(); //GAPPLET. if (CMisc.isApplication()) init(); } + /** + * Initializes the GExpert application, setting up the GUI components, loading preferences, language settings, and rules. + * It also initializes various attributes and sets up the main content pane. + */ public void init() { - this.setIconImage(GExpert.createImageIcon("images/gexicon.gif").getImage()); //GAPPLET -// setLocal(); -// showWelcome(); + // setLocal(); + // showWelcome(); CMisc.initFont(); loadPreference(); //swapped loadPreference() and loadRules() because loadPreference needs to happen first. loadLanguage(); // this was after loadrules and loadpreference. real order: loadRules, LoadPreference, loadLanguage loadRules(); - initAttribute(); setLookAndFeel(); initKeyMap(); @@ -146,19 +156,28 @@ public void init() { addWindowListener(this); this.getContentPane().add(contentPane, BorderLayout.CENTER); - } - + /** + * Loads the rules for the GExpert application. + */ public void loadRules() { RuleList.loadRules(); Gib.initRules(); } + /** + * Returns the main content pane of the application. + * + * @return the main content pane + */ public JComponent getContent() { return contentPane; } + /** + * Adds a component listener to the drawing panel to handle resizing and visibility changes. + */ public void addSplitListener() { d.addComponentListener(new ComponentListener() { public void componentResized(ComponentEvent e) { @@ -177,25 +196,28 @@ public void componentHidden(ComponentEvent e) { }); } + /** + * Loads the user preferences from the configuration file. + */ public void loadPreference() { - String u = getUserHome(); try { - InputStreamReader read = new InputStreamReader(new FileInputStream(u + "/jgex.cfg"), "UTF-8");// + InputStreamReader read = new InputStreamReader(new FileInputStream(u + "/jgex.cfg"), "UTF-8"); BufferedReader reader = new BufferedReader(read); CMisc.LoadProperty(reader); } catch (IOException ee) { -// CMisc.print(ee.getMessage()); + // CMisc.print(ee.getMessage()); } - } + /** + * Loads the language settings for the application and sets up internationalization. + */ public void loadLanguage() { - language = new Language(); String user_directory = getUserDir(); Language.setLanguage(language); - System.out.println("Language loaded: "+CMisc.lan); + System.out.println("Language loaded: " + CMisc.lan); lan = CMisc.lan; //setting lan to current language so RuleList can read it. // Set gettext based internationalization: @@ -253,10 +275,8 @@ public void loadLanguage() { UIManager.put("FileChooser.fileSizeHeaderText", getLanguage("Size")); UIManager.put("FileChooser.fileDateHeaderText", getLanguage("Date Modified")); - /* There are still some keys that require translation. TODO. - * This piece of code may help finding the missing keys. - */ - + // There are still some keys that require translation. TODO. + // This piece of code may help finding the missing keys. /* UIDefaults defaults = UIManager.getDefaults(); java.util.Enumeration keysEnumeration = defaults.keys(); @@ -269,27 +289,35 @@ public void loadLanguage() { } + /** + * Initializes the attributes of the application, setting the font if the language is not English. + */ public void initAttribute() { - if (language != null && !language.isEnglish()) { Font f = language.getFont(); - if (f != null) { - { - setUIFont(new FontUIResource(f)); - CMisc.setFont(f.getName()); - } + setUIFont(new FontUIResource(f)); + CMisc.setFont(f.getName()); } } } + /** + * Returns the default font of the application. + * + * @return the default Font object, or null if the language is not set + */ public Font getDefaultFont() { if (language == null) return null; return language.getFont(); } - + /** + * Returns the Frame object of the application. + * + * @return the Frame object, or null if no Frame is found + */ public Frame getFrame() { Container c = this; while (c != null) { @@ -300,35 +328,39 @@ public Frame getFrame() { return (Frame) null; } + /** + * Loads the cursor for the application. + */ public void loadCursor() { } - public void createCursor(Toolkit kit, String file, String name) { - } - - public Cursor getDefinedCursor(String name) { - return null; - } - - + /** + * Checks if the panel is visible. + * + * @return true if the panel is visible, false otherwise + */ public boolean isPPanelVisible() { return ppanel.isVisible(); } + /** + * Shows or hides the panel. + * + * @param t if true, hides the panel; if false, shows the panel + */ public void showppanel(boolean t) { show_button.setSelected(t); ppanel.setVisible(!t); contentPane.resetToPreferredSizes(); -// if (t == false) { -// Dimension dm = contentPane.getMinimumSize(); -// contentPane.setSize(dm); -// } - } - - public JSplitPane getSplitContentPane() { - return contentPane; } + /** + * Shows the rule panel at the specified location. + * + * @param s the rule to be shown + * @param x the x-coordinate of the location + * @param y the y-coordinate of the location + */ public void showRulePanel(String s, int x, int y) { if (rview == null) { rview = new JPopExView(this); @@ -340,14 +372,29 @@ public void showRulePanel(String s, int x, int y) { } } + /** + * Returns the PanelProve object. + * + * @return the PanelProve object + */ public PanelProve getpprove() { return pprove; } + /** + * Checks if the animate frame is present. + * + * @return true if the animate frame is present, false otherwise + */ public boolean hasAFrame() { return aframe != null; } + /** + * Returns the AnimatePanel object, initializing it if necessary. + * + * @return the AnimatePanel object + */ public AnimatePanel getAnimateDialog() { if (aframe == null) { aframe = new AnimatePanel(this, d, dp); @@ -355,16 +402,13 @@ public AnimatePanel getAnimateDialog() { return aframe; } - public boolean isAframeShown() { - return afpane.isVisible() && aframe != null && aframe.isVisible(); - } - + /** + * Shows the animate pane. + */ public void showAnimatePane() { - if (aframe == null) this.getAnimateDialog(); - Rectangle rc = scroll.getVisibleRect(); if (afpane == null) afpane = new FloatableToolBar(); @@ -379,6 +423,12 @@ public void showAnimatePane() { aframe.repaint(); } + /** + * Returns the RuleDialog object for the specified rule, initializing it if necessary. + * + * @param n the rule number + * @return the RuleDialog object + */ public RuleDialog getRuleDialog(int n) { if (rdialog == null) { rdialog = new RuleDialog(this); @@ -393,6 +443,11 @@ public RuleDialog getRuleDialog(int n) { } + /** + * Automatically sets the panel type for the given class. + * + * @param c the class for which the panel type is to be set + */ public void viewElementsAuto(CClass c) { if (c == null) return; @@ -401,6 +456,11 @@ public void viewElementsAuto(CClass c) { cp.SetPanelType(c); } + /** + * Returns the dialog property, initializing it if necessary. + * + * @return the dialog property + */ public DialogProperty getDialogProperty() { if (propt == null) { cp = new CProperty(d, language); @@ -413,12 +473,22 @@ public DialogProperty getDialogProperty() { return propt; } + /** + * Centers the given dialog relative to the main frame. + * + * @param dlg the dialog to be centered + */ public void centerDialog(JDialog dlg) { dlg.setLocation(this.getX() + this.getWidth() / 2 - dlg.getWidth() / 2, this.getY() + this.getHeight() / 2 - dlg.getHeight() / 2); } + /** + * Returns the select dialog, initializing it if necessary. + * + * @return the select dialog + */ public SelectDialog getSelectDialog() { if (sdialog == null) { sdialog = new SelectDialog(this, new Vector()); @@ -426,6 +496,11 @@ public SelectDialog getSelectDialog() { return sdialog; } + /** + * Checks if the conclusion dialog is visible. + * + * @return true if the conclusion dialog is visible, false otherwise + */ public boolean isconcVisible() { if (cdialog != null && cdialog.isVisible()) { return true; @@ -433,6 +508,11 @@ public boolean isconcVisible() { return false; } + /** + * Returns the conclusion dialog, initializing it if necessary. + * + * @return the conclusion dialog + */ public ConcDialog getConcDialog() { if (cdialog == null) { cdialog = new ConcDialog(this, ""); @@ -441,6 +521,9 @@ public ConcDialog getConcDialog() { return cdialog; } + /** + * Shows the number check dialog if there are points to check. + */ public void showNumDialog() { if (ndialog != null && ndialog.isVisible()) return; @@ -451,11 +534,21 @@ public void showNumDialog() { ndialog.setVisible(true); } + /** + * Selects a point in the number check dialog if it is visible. + * + * @param p the point to be selected + */ public void selectAPoint(CPoint p) { if (ndialog != null && ndialog.isVisible()) ndialog.addSelectPoint(p); } + /** + * Returns the undo edit dialog, initializing it if necessary. + * + * @return the undo edit dialog + */ public UndoEditDialog getUndoEditDialog() { if (udialog == null) { udialog = new UndoEditDialog(this); @@ -464,10 +557,20 @@ public UndoEditDialog getUndoEditDialog() { return udialog; } + /** + * Checks if the prove dialog is visible. + * + * @return true if the prove dialog is visible, false otherwise + */ public boolean isDialogProveVisible() { return pdialog != null && pdialog.isVisible(); } + /** + * Returns the prove dialog, initializing it if necessary. + * + * @return the prove dialog + */ public CDialogProve getDialogProve() { if (pdialog == null) { pdialog = new CDialogProve(this); @@ -475,6 +578,12 @@ public CDialogProve getDialogProve() { return pdialog; } + /** + * Returns a file chooser, initializing it if necessary. + * + * @param importGgb if true, sets the file filter to GeoGebra files; otherwise, sets it to GEX files + * @return the file chooser + */ public JFileChooser getFileChooser(boolean importGgb) { if (filechooser == null) { filechooser = new JFileChooser(); @@ -491,42 +600,83 @@ public JFileChooser getFileChooser(boolean importGgb) { return filechooser; } + /** + * Returns the user directory. + * + * @return the user directory + */ public static String getUserDir() { return System.getProperty("user.dir"); } + /** + * Returns the user home directory. + * + * @return the user home directory + */ public static String getUserHome() { return System.getProperty("user.home"); } + /** + * Returns the file separator. + * + * @return the file separator + */ public static String getFileSeparator() { return File.separator; } + /** + * Checks if the manual input bar is present. + * + * @return true if the manual input bar is present, false otherwise + */ public boolean hasMannualInputBar() { return inputm != null; } + /** + * Returns the prove status. + * + * @return the prove status + */ public int getProveStatus() { return pprove.getSelectedIndex(); } + /** + * Returns the style dialog. + * + * @return the style dialog + */ public CStyleDialog getStyleDialog() { return styleDialog; } + /** + * Returns the manual input toolbar. + * + * @return the manual input toolbar + */ public MProveInputPanel getMannalInputToolBar() { return inputm; } + /** + * Adds a button to the draw group. + * + * @param b the button to be added + */ public void addButtonToDrawGroup(JToggleButton b) { group.add(b); } - public CProveBarPanel getPProveBar() { - return provePanelbar; - } - + /** + * Switches the visibility of the prove bar. + * + * @param r if false, hides the prove bar; if true, shows the prove bar + */ public void switchProveBarVisibility(boolean r) { if (r == false) { if (provePanelbar == null) @@ -536,6 +686,11 @@ public void switchProveBarVisibility(boolean r) { showProveBar(true); } + /** + * Shows or hides the prove bar. + * + * @param show if true, shows the prove bar; if false, hides the prove bar + */ public void showProveBar(boolean show) { if (provePanelbar == null) { provePanelbar = new CProveBarPanel(this); @@ -554,6 +709,9 @@ public void showProveBar(boolean show) { } } + /** + * Shows the style dialog. + */ public void showStyleDialog() { if (styleDialog == null) { styleDialog = new CStyleDialog(this, d); @@ -570,6 +728,9 @@ public void showStyleDialog() { } } + /** + * Creates and initializes the tip label. + */ public void createTipLabel() { label = new JLabel() { @@ -596,8 +757,8 @@ public Dimension getMaximumSize() { GBevelBorder border = new GBevelBorder(GBevelBorder.RAISED, 1); - label.setBorder(border); //BorderFactory.createBevelBorder(BevelBorder.RAISED)); - label2.setBorder(border); //BorderFactory.createBevelBorder(BevelBorder.RAISED)); + label.setBorder(border); + label2.setBorder(border); JPanel panel = new JPanel(); panel.setBorder(null); @@ -605,7 +766,6 @@ public Dimension getMaximumSize() { panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); tipanel = panel; - show_button = new TStateButton(GExpert.createImageIcon("images/ticon/show.gif"), GExpert.createImageIcon("images/ticon/hide.gif")); @@ -627,31 +787,21 @@ public void actionPerformed(ActionEvent e) { } + /** + * Sets the location of the frame. + * + * @param x the x-coordinate of the frame + * @param y the y-coordinate of the frame + */ public void setLocation(int x, int y) { super.setLocation(x, y); } - void addDirectoryIcons(File f) { - if (f.isDirectory()) { - File contents[] = f.listFiles(); - for (int i = 0; i < contents.length; i++) { - if (contents[i].isDirectory()) { - continue; - } - iconPool.add(GExpert.createImageIcon(contents[i].getPath())); - } - - for (int i = 0; i < contents.length; i++) { - String s = contents[i].getName(); - String t = s; - if (contents[i].isDirectory()) { - this.addDirectoryIcons(contents[i]); - } - } - - } - } - + /** + * Adds all example files from the examples directory to the specified menu. + * + * @param menu the menu to which the example files will be added + */ void addAllExamples(JMenu menu) { String user_directory = getUserDir(); String sp = GExpert.getFileSeparator(); @@ -660,6 +810,13 @@ void addAllExamples(JMenu menu) { this.addDirectory(dir, menu, dr); } + /** + * Adds the contents of the specified directory to the specified menu. + * + * @param f the directory whose contents will be added + * @param menu the menu to which the contents will be added + * @param path the path of the directory + */ void addDirectory(File f, JMenu menu, String path) { String sp = GExpert.getFileSeparator(); @@ -701,44 +858,12 @@ void addDirectory(File f, JMenu menu, String path) { } - void addDirectory(BufferedReader bf, JMenu menu, String path) throws IOException { - - String s1 = bf.readLine(); - s1.trim(); - - while (s1.length() != 0) { - if (s1.length() == 1 && s1.charAt(0) == '(') { - s1 = bf.readLine(); - s1.trim(); - JMenu m = new JMenu(s1); - addMenu(menu, m); - if (path.length() == 0) - addDirectory(bf, m, s1); - else - addDirectory(bf, m, path + "/" + s1); - } else if (s1.length() == 1 && s1.charAt(0) == ')') { - return; - } else { - if (s1.endsWith(".gex")) { - s1 = s1.substring(0, s1.length() - 4); - JMenuItem mt = new JMenuItem(s1); - mt.setName(path); - mt.setToolTipText(s1); - mt.setActionCommand("example"); - mt.addActionListener(this); - addMenu(menu, mt); - } - - } - s1 = bf.readLine(); - - if (s1 != null) - s1.trim(); - else - return; - } - } - + /** + * Adds a menu item to the specified menu in alphabetical order. + * + * @param menu the menu to which the item will be added + * @param item the menu item to be added + */ void addMenu(JMenu menu, JMenuItem item) { String name = item.getText(); for (int i = 0; i < menu.getItemCount(); i++) { @@ -754,7 +879,15 @@ void addMenu(JMenu menu, JMenuItem item) { menu.add(item); } - + /** + * Initializes and adds the menu and tool bar(s) to the application frame. + *

+ * This method creates and configures the top toolbar, the right-side toolbar, + * and the menu bar with all necessary menus and menu items for file operations, + * examples, construction, constraints, actions, and help. + * Toolbar buttons and menu items are set up with icons and action listeners. + *

+ */ public void addMenueToolBar() { JToolBar toolBar = new JToolBar("Toolbar"); toolBar.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT); @@ -930,9 +1063,9 @@ public void addMenueToolBar() { JMenu sub2 = new JMenu(getLanguage(getLanguage("Ratio Distance"))); // addRadioButtonMenuItem(sub2, "1 : 1", "Set two segments to have ratio: 1 : 1", this, "ra_side"); - addRadioButtonMenuItem(sub2, "1 : 1", GExpert.getTranslationViaGettext("Set two segments to have ratio: {0}", "1 : 1"), this, "ra_side"); - addRadioButtonMenuItem(sub2, "1 : 2", GExpert.getTranslationViaGettext("Set two segments to have ratio: {0}", "1 : 2"), this, "ra_side"); - addRadioButtonMenuItem(sub2, "1 : 3", GExpert.getTranslationViaGettext("Set two segments to have ratio: {0}", "1 : 3"), this, "ra_side"); + addRadioButtonMenuItem(sub2, "1 : 1", GExpert.getTranslationViaGettext("Set two segments to have ratio: {0}", "1 : 1"), this, "ra_side"); + addRadioButtonMenuItem(sub2, "1 : 2", GExpert.getTranslationViaGettext("Set two segments to have ratio: {0}", "1 : 2"), this, "ra_side"); + addRadioButtonMenuItem(sub2, "1 : 3", GExpert.getTranslationViaGettext("Set two segments to have ratio: {0}", "1 : 3"), this, "ra_side"); addRadioButtonMenuItem(sub2, "Other...", "Set two segments to have specified ratio", this, "ra_side"); menu.add(sub2); addRadioButtonMenuItem(menu, "CCtangent", "Set two circles to be tangent", this); @@ -1018,6 +1151,16 @@ public void addMenueToolBar() { getContentPane().add(toolBarRight, BorderLayout.EAST); } + /** + * Creates a JRadioButtonMenuItem with the specified name, tooltip, action listener, and command. + * + * @param bar the menu to add the item to + * @param name the display name and action command of the menu item + * @param tooltip the tooltip text to display + * @param listener the action listener to register on the menu item + * @param command the specific action command to set + * @return the created JRadioButtonMenuItem + */ public JRadioButtonMenuItem addRadioButtonMenuItem(JMenu bar, String name, String tooltip, ActionListener listener, String command) { JRadioButtonMenuItem item = addRadioButtonMenuItem(bar, name, tooltip, listener); @@ -1025,6 +1168,17 @@ public JRadioButtonMenuItem addRadioButtonMenuItem(JMenu bar, String name, return item; } + /** + * Creates a JRadioButtonMenuItem with the specified name, custom text, tooltip, and action listener. + * The menu item's text is set to its localized value. + * + * @param bar the menu to add the item to + * @param name the internal name of the menu item used as its action command + * @param text the text to display on the menu item (to be localized) + * @param tooltip the tooltip text to display + * @param listener the action listener to register on the menu item + * @return the created JRadioButtonMenuItem with localized text + */ public JRadioButtonMenuItem addRadioButtonMenuItem(JMenu bar, String name, String text, String tooltip, ActionListener listener) { JRadioButtonMenuItem item = addRadioButtonMenuItem(bar, name, tooltip, listener); @@ -1032,6 +1186,17 @@ public JRadioButtonMenuItem addRadioButtonMenuItem(JMenu bar, String name, Strin return item; } + /** + * Creates a JRadioButtonMenuItem with the specified name, tooltip, and action listener. + * The menu item's text and action command are set based on the provided name. + * If the tooltip is null, a localized language tip may be used instead. + * + * @param bar the menu to add the item to + * @param name the name used as the action command and display text of the menu item + * @param tooltip the tooltip text to display (or a localized tip if null) + * @param listener the action listener to register on the menu item + * @return the created JRadioButtonMenuItem + */ public JRadioButtonMenuItem addRadioButtonMenuItem(JMenu bar, String name, String tooltip, ActionListener listener) { JRadioButtonMenuItem miten; @@ -1053,21 +1218,16 @@ else if (s1 != null && s1.length() > 0) return miten; } - /* - public JMenuItem addAMenu(JMenu bar, String name, String tooltip, - ActionListener listener, String command) { - JMenuItem item = addAMenu(bar, name, tooltip, listener); - item.setActionCommand(command); - return item; - } - - public JMenuItem addAMenu(JMenu bar, String command, String text, String tip, ActionListener listener) { - JMenuItem item = addAMenu(bar, text, tip, listener); - item.setActionCommand(command); - return item; - } + /** + * Adds a menu item to the specified menu bar with the given name, tooltip, mnemonic, and action listener. + * + * @param bar the menu bar to which the menu item will be added + * @param name the name of the menu item + * @param tooltip the tooltip text for the menu item + * @param ne the mnemonic for the menu item + * @param listener the action listener for the menu item + * @return the created JMenuItem */ - public JMenuItem addAMenu(JMenu bar, String name, String tooltip, int ne, ActionListener listener) { JMenuItem item = addAMenu(bar, name, tooltip, listener); item.setMnemonic(ne); @@ -1076,16 +1236,32 @@ public JMenuItem addAMenu(JMenu bar, String name, String tooltip, int ne, Action return item; } + /** + * Adds a blank image icon to the specified menu item. + * + * @param item the menu item to which the image icon will be added + */ public void addImageToItem(JMenuItem item) { ImageIcon m = GExpert.createImageIcon("images/small/" + "blank.gif"); item.setIcon(m); } + /** + * Adds a blank image icon to the specified menu. + * + * @param item the menu to which the image icon will be added + */ public void addImageToItem(JMenu item) { ImageIcon m = GExpert.createImageIcon("images/small/" + "blank.gif"); item.setIcon(m); } + /** + * Adds an image icon to the specified menu item with the given name. + * + * @param item the menu item to which the image icon will be added + * @param name the name of the image icon + */ public void addImageToItem(JMenuItem item, String name) { ImageIcon m = GExpert.createImageIcon("images/small/" + name + ".gif"); if (m == null) @@ -1093,24 +1269,20 @@ public void addImageToItem(JMenuItem item, String name) { item.setIcon(m); } - /* - public JMenuItem addAMenu(JMenu bar, String name, String tooltip, int ne, ActionListener listener, String image) { - JMenuItem item = addAMenu(bar, name, tooltip, listener); - item.setMnemonic(ne); - KeyStroke ctrlP = KeyStroke.getKeyStroke(ne, InputEvent.CTRL_MASK); - item.setAccelerator(ctrlP); - ImageIcon m = GExpert.createImageIcon("images/small/" + image + ".gif"); - item.setIcon(m); - return item; - } - */ - + /** + * Adds a menu item to the specified menu bar with the given name, tooltip, and action listener. + * + * @param bar the menu bar to which the menu item will be added + * @param name the name of the menu item + * @param tooltip the tooltip text for the menu item + * @param listener the action listener for the menu item + * @return the created JMenuItem + */ public JMenuItem addAMenu(JMenu bar, String name, String tooltip, ActionListener listener) { JMenuItem miten; miten = new JMenuItem(name); if (tooltip != null) { miten.setToolTipText(this.getLanguage(tooltip)); - // System.out.println("Tooltip set for " + tooltip); } miten.setActionCommand(name); miten.setText(this.getLanguage(name)); @@ -1119,10 +1291,21 @@ public JMenuItem addAMenu(JMenu bar, String name, String tooltip, ActionListener return miten; } + /** + * Returns the current language settings. + * + * @return the current Language object + */ public Language getLan() { return language; } + /** + * Returns the translated string for the given key. + * + * @param s1 the key to be translated + * @return the translated string + */ public static String getLanguage(String s1) { s1 = getTranslationViaGettext(s1); if (s1 != null) { @@ -1135,6 +1318,12 @@ public static String getLanguage(String s1) { return s2; } + /** + * Returns the tooltip text for the given key. + * + * @param s1 the key to be translated + * @return the translated tooltip text + */ public static String getLanguageTip(String s1) { s1 = getTranslationViaGettext(s1); if (s1 != null) { @@ -1150,10 +1339,23 @@ public static String getLanguageTip(String s1) { return s2; } + /** + * Returns the translated string for the given key using gettext. + * + * @param s the key to be translated + * @return the translated string + */ public static String getTranslationViaGettext(String s) { return getTranslationViaGettext(s, (String) null); } + /** + * Returns the translated string for the given key using gettext with parameters. + * + * @param s the key to be translated + * @param p the parameters for the translation + * @return the translated string + */ public static String getTranslationViaGettext(String s, String... p) { String gettextTranslation = null; try { @@ -1173,29 +1375,50 @@ public static String getTranslationViaGettext(String s, String... p) { } if (gettextTranslation != null && !gettextTranslation.equals("")) return gettextTranslation; - } catch(Exception ex) { + } catch (Exception ex) { System.err.println("Caught exception " + ex); } System.err.println("Missing translation: " + s + ", " + p); return ""; } + /** + * Sets the action to "Move" and selects the move button. + */ public void setActionMove() { sendAction("Move", buttonMove); buttonMove.setSelected(true); } + /** + * Sets the action to "Select" and selects the select button. + */ public void setActionSelect() { sendAction("Select", buttonSelect); buttonSelect.setSelected(true); } + /** + * Handles action events by sending the action command and source to the sendAction method. + * + * @param e the action event + */ public void actionPerformed(ActionEvent e) { String command = e.getActionCommand(); Object src = e.getSource(); sendAction(command, src); } + /** + * Processes an action command based on the provided command string and source. + * + *

This method interprets the action command triggered by the user and executes + * the corresponding operation such as saving files, opening dialogs, performing undo/redo actions, + * updating the UI state, and other application-specific functions. + * + * @param command the action command to be processed + * @param src the source object that triggered the command (e.g., JMenuItem, JToggleButton, or File) + */ synchronized public void sendAction(String command, Object src) { @@ -1302,14 +1525,11 @@ public String getDescription() { dp.setFile((File) src); } this.saveAFile(false); - } - else this.saveAFile(true); + } else this.saveAFile(true); } else if (command.equalsIgnoreCase("Save GDD Proof as GraphViz File")) { this.saveGDDProofAsGraphViz(src); - } - - else if (command.equals("Save as Text")) { + } else if (command.equals("Save as Text")) { if (!need_save()) return; @@ -1350,7 +1570,7 @@ else if (command.equals("Save as Text")) { if (src instanceof File) { openAFile((File) src); - } else { + } else { JFileChooser chooser = getFileChooser(false); int result = chooser.showOpenDialog(this); @@ -1741,12 +1961,16 @@ else if (command.equalsIgnoreCase("Calculation")) { } } + /** + * Saves the GDD proof as a GraphViz file. + * + * @param src the source object, which can be a File or another object + */ private void saveGDDProofAsGraphViz(Object src) { File ff; if (src instanceof File) { ff = (File) src; } else { - JFileChooser chooser = new JFileChooser(); chooser.setFileFilter(new JFileFilter("gv")); @@ -1777,7 +2001,12 @@ private void saveGDDProofAsGraphViz(Object src) { } } - + /** + * Opens a GeoGebra file (.ggb) and loads its content. + * + * @param file the GeoGebra file to be opened + * @return true if the file was opened successfully, false otherwise + */ private boolean openGGBFile(File file) { String path = file.getPath(); File f = new File(path); @@ -1794,7 +2023,7 @@ private boolean openGGBFile(File file) { dp.setFile(f); DataInputStream in = dp.openInputFile(f.getPath()); //r = dp.LoadGGB(in,f.getPath()); - r = dp.LoadGGB2(in,f.getPath()); + r = dp.LoadGGB2(in, f.getPath()); // pprove.LoadProve(in); // TODO: in.close(); // dp.stopUndoFlash(); // TODO: @@ -1822,6 +2051,12 @@ private boolean openGGBFile(File file) { return false; } + /** + * Parses a string in the format "x:y" into an array of two integers. + * + * @param s the string to be parsed + * @return an array of two integers parsed from the string + */ int[] parse2Int(String s) { String[] sl = s.split(":"); int[] t = new int[2]; @@ -1835,6 +2070,9 @@ int[] parse2Int(String s) { return t; } + /** + * Sets the enabled state of the undo and redo buttons based on the sizes of the undo and redo lists. + */ public void setBKState() { int n1 = dp.getUndolistSize(); int n2 = dp.getRedolistSize(); @@ -1851,6 +2089,11 @@ public void setBKState() { } } + /** + * Prompts the user to save any unsaved changes before exiting the application. + * + * @return true if the user chose to save or discard changes, false if the user canceled the operation + */ public boolean saveBeforeExit() { if (dp.need_save() && CMisc.needSave()) { int n = JOptionPane.showConfirmDialog(this, getLanguage("The diagram has been changed, do you want to save it?"), @@ -1866,6 +2109,11 @@ public boolean saveBeforeExit() { return true; } + /** + * Checks if there are any unsaved changes. + * + * @return true if there are unsaved changes, false otherwise + */ public boolean need_save() { if (!dp.need_save()) { this.setTipText(getLanguage("Nothing to be saved.")); @@ -1874,12 +2122,19 @@ public boolean need_save() { return true; } + /** + * Saves the current file. If the file does not exist or the user chooses "Save as...", + * prompts the user to select a file location. + * + * @param n if true, prompts the user to select a file location + * @return true if the file was saved successfully, false otherwise + */ public boolean saveAFile(boolean n) { File file = dp.getFile(); int result = 0; if (need_save()) { - if (file == null || n) { //command.equals("Save as...") + if (file == null || n) { // command.equals("Save as...") JFileChooser chooser = this.getFileChooser(false); try { @@ -1920,6 +2175,12 @@ public boolean saveAFile(boolean n) { return false; } + /** + * Clears the current diagram and resets the application state. + * Prompts the user to save any unsaved changes before clearing. + * + * @return 0 if the diagram was cleared successfully, 2 if the user canceled the operation + */ public int Clear() { int n = 0; if (CMisc.isApplication() && !dp.isitSaved()) { @@ -1929,8 +2190,8 @@ public int Clear() { if (!saveAFile(false)) return 2; } else if (n == JOptionPane.NO_OPTION) { -// if (!saveAFile(true)) -// return 2; + // if (!saveAFile(true)) + // return 2; } else { return 2; } @@ -1952,6 +2213,9 @@ public int Clear() { return 0; } + /** + * Closes all open dialogs in the application. + */ public void closeAllDialogs() { if (propt != null) propt.setVisible(false); @@ -1969,22 +2233,32 @@ public void closeAllDialogs() { ndialog.setVisible(false); if (adialog != null) adialog.setVisible(false); -// removeAllDependentDialogs(); + // removeAllDependentDialogs(); } + /** + * Sets the cursor to the specified predefined cursor type. + * + * @param t the predefined cursor type + */ public void setDrawCursor(int t) { d.setCursor(Cursor.getPredefinedCursor(t)); } - public void setDrawCursor(String s) { - d.setCursor(this.getDefinedCursor(s)); - } - + /** + * Reloads the list of points if the list panel and undo dialog are visible. + */ public void reloadLP() { if (lp != null && udialog != null && udialog.isVisible()) lp.reload(); } + /** + * Prompts the user to confirm overwriting an existing file. + * + * @param name the name of the file to be overwritten + * @return true if the user chose to overwrite the file, false otherwise + */ public boolean get_User_Overwrite_Option(String name) { if (JOptionPane.OK_OPTION != JOptionPane.showConfirmDialog(this, getTranslationViaGettext("{0} already exists, do you want to overwrite it?", name), @@ -1994,6 +2268,12 @@ public boolean get_User_Overwrite_Option(String name) { return false; } + /** + * Saves the project to a file at the specified path. + * + * @param path the file path to save the project + * @throws IOException if an I/O error occurs during saving + */ public void saveAFile(String path) throws IOException { DataOutputStream out = dp.openOutputFile(path); dp.Save(out); @@ -2001,13 +2281,17 @@ public void saveAFile(String path) throws IOException { out.close(); } + /** + * Saves the proof as a GIF image. + * Opens dialogs to select the region and file destination, then encodes the proof into a GIF. + */ public void saveProofAsGIF() { if (provePanelbar == null) return; if (!need_save()) return; - RectChooser1 r1 = new RectChooser1(this); + RectangleSelectionDialog r1 = new RectangleSelectionDialog(this); this.centerDialog(r1); r1.setVisible(true); if (!r1.getResult()) @@ -2059,6 +2343,10 @@ public void saveProofAsGIF() { } + /** + * Saves the current animation as a GIF. + * Displays GIF options, captures the animation frames, and writes them to the selected file. + */ public void saveAsGIF() { if (!need_save()) @@ -2152,7 +2440,10 @@ public void saveAsGIF() { } - + /** + * Saves the current view as an image file. + * Opens a file chooser to select the output format and destination, then writes the captured image. + */ public void saveAsImage() { if (!need_save()) @@ -2248,7 +2539,12 @@ public void saveAsImage() { } - + /** + * Returns a buffered image of the drawing area bounded by the specified rectangle. + * + * @param rc the rectangle defining the area to capture + * @return the buffered image of the drawing area + */ public BufferedImage getBufferedImage(Rectangle rc) { BufferedImage image = new BufferedImage((int) rc.getWidth(), (int) rc.getHeight(), BufferedImage.TYPE_INT_RGB); Graphics g = image.getGraphics(); @@ -2258,6 +2554,12 @@ public BufferedImage getBufferedImage(Rectangle rc) { return image; } + /** + * Returns a buffered image of the content pane bounded by the specified rectangle. + * + * @param rc the rectangle defining the area to capture + * @return the buffered image of the content pane + */ public BufferedImage getBufferedImage2(Rectangle rc) { BufferedImage image = new BufferedImage((int) rc.getWidth(), (int) rc.getHeight(), BufferedImage.TYPE_INT_RGB); Graphics g = image.getGraphics(); @@ -2267,6 +2569,13 @@ public BufferedImage getBufferedImage2(Rectangle rc) { return image; } + /** + * Opens and loads a project file. + * Adjusts the file extension if necessary, then loads the project data accordingly. + * + * @param file the file to open + * @return true if the file was successfully loaded, false otherwise + */ public boolean openAFile(File file) { String path = file.getPath(); File f = new File(path); @@ -2330,6 +2639,11 @@ public boolean openAFile(File file) { return false; } + /** + * Adds right-side buttons to the provided tool bar. + * + * @param toolBar the tool bar to which the right-side buttons are added + */ protected void addRightButtons(JToolBar toolBar) { JToggleButton button = null; @@ -2378,6 +2692,11 @@ protected void addRightButtons(JToolBar toolBar) { button.setEnabled(false); } + /** + * Adds primary action buttons to the provided tool bar. + * + * @param toolBar the tool bar to which the primary action buttons are added + */ protected void addButtons(JToolBar toolBar) { JToggleButton button = null; //ButtonGroup group = new ButtonGroup(); @@ -2560,6 +2879,16 @@ public void actionPerformed(ActionEvent e) { } }; + /** + * Creates a toggle button with the specified image, action command, tooltip text, alternate text, and an optional action listener. + * + * @param imageName the name of the image file (without extension) to be used as the button icon + * @param actionCommand the action command to be set for the button + * @param toolTipText the tooltip text to be displayed when the mouse hovers over the button + * @param altText the alternate text to be used if the image cannot be found + * @param t a boolean indicating whether to add an action listener to the button + * @return the created JToggleButton + */ protected JToggleButton makeAButton(String imageName, String actionCommand, String toolTipText, @@ -2572,6 +2901,15 @@ protected JToggleButton makeAButton(String imageName, return button; } + /** + * Creates a toggle button with the specified image, action command, tooltip text, and alternate text. + * + * @param imageName the name of the image file (without extension) to be used as the button icon + * @param actionCommand the action command to be set for the button + * @param toolTipText the tooltip text to be displayed when the mouse hovers over the button + * @param altText the alternate text to be used if the image cannot be found + * @return the created JToggleButton + */ protected JToggleButton makeAButton(String imageName, String actionCommand, String toolTipText, @@ -2613,6 +2951,16 @@ protected JToggleButton makeAButton(String imageName, } + /** + * Creates a toggle button with two icons, one for the default state and one for the selected state. + * + * @param imageName the name of the image file (without extension) to be used as the button icon in the default state + * @param imageNameSelected the name of the image file (without extension) to be used as the button icon in the selected state + * @param actionCommand the action command to be set for the button + * @param toolTipText the tooltip text to be displayed when the mouse hovers over the button + * @param altText the alternate text to be used if the image cannot be found + * @return the created DActionButton with two status icons + */ protected JToggleButton makeAButtonWith2ICon(String imageName, String imageNameSelected, String actionCommand, @@ -2645,6 +2993,10 @@ protected JToggleButton makeAButtonWith2ICon(String imageName, } + /** + * This method is used to reset all button status. + * It is used to reset all button status when the user drags a file on the window. + */ public void resetAllButtonStatus() { if (lp != null) { @@ -2669,6 +3021,10 @@ public void resetAllButtonStatus() { BK4.setEnabled(true); } + /** + * This method is used to update the title of the window. + * It is used to update the title of the window when the user drags a file on the window. + */ public void updateTitle() { // APPLET ONLY. if (!CMisc.isApplication()) return; @@ -2688,6 +3044,10 @@ public void updateTitle() { // APPLET ONLY. } + /** + * This method is used to restore the scroll. + * It is used to restore the scroll when the user drags a file on the window. + */ public void restorScroll() { Rectangle rc = new Rectangle(0, 0, 0, 0); scroll.scrollRectToVisible(rc); @@ -2695,6 +3055,10 @@ public void restorScroll() { d.revalidate(); } + /** + * This method is used to set the text of the label. + * It is used to set the text of the label when the user drags a file on the window. + */ public void setActionTip(String name, String tip) { if (pprove.isProverRunning()) return; @@ -2710,15 +3074,27 @@ public void setActionTip(String name, String tip) { private int n = 4; private static Color fcolor = new Color(128, 0, 0); + /** + * This method is used to set the text of the label2. + * It is used to set the text of the label2 when the user drags a file on the window. + */ public void setTextLabel2(String s, int n) { setTextLabel2(s); this.n = n; } + /** + * This method is used to set the text of the label2. + * It is used to set the text of the label2 when the user drags a file on the window. + */ public void setLabelText2(String s) { label2.setText(" " + s); } + /** + * This method is used to stop the timer. + * It is used to stop the timer when the user drags a file on the window. + */ public void stopTimer() { if (timer != null) timer.stop(); @@ -2726,6 +3102,10 @@ public void stopTimer() { label2.setForeground(fcolor); } + /** + * This method is used to set the text of the label2. + * It is used to set the text of the label2 when the user drags a file on the window. + */ public void setTextLabel2(String s) { label2.setText(" " + s); if (timer == null && s != null && s.length() != 0) { @@ -2751,31 +3131,31 @@ public void actionPerformed(ActionEvent e) { } + /** + * This method is used to set the text of the tip. + * It is used to set the text of the tip when the user drags a file on the window. + */ public void setTipText(String text) { this.setTextLabel2(text); } - public void Animate(int type) { - d.onAnimate(type); - } - public void dragEnter(DropTargetDragEvent dtde) { - // System.out.println("Drag Enter"); } public void dragExit(DropTargetEvent dte) { - //System.out.println("Drag Exit"); } public void dragOver(DropTargetDragEvent dtde) { - // System.out.println("Drag Over"); } public void dropActionChanged(DropTargetDragEvent dtde) { - // System.out.println("Drop Action Changed"); } + /** + * This method is called when the user drops a file on the window. + * It accepts the drop and adds the file to the text area. + */ public void drop(DropTargetDropEvent dtde) { try { // Ok, get the dropped object and try to figure out what it is @@ -2830,6 +3210,10 @@ else if (flavors[i].isRepresentationClassInputStream()) { public void windowOpened(WindowEvent e) { } + /** + * This method is called when the user closes the window. + * It asks the user if he wants to save the file before quitting. + */ public void windowClosing(WindowEvent e) { if (saveBeforeExit()) System.exit(0); @@ -2852,10 +3236,10 @@ public void windowDeactivated(WindowEvent e) { } - ///////////////////////////////////////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////////////////////////////////////// - - + /** + * This class is used to create a popup menu with buttons. + * It is used to create the popup menu for the buttons in the toolbar. + */ class JPopButtonsPanel extends JPopupMenu implements ActionListener, MouseListener, ItemListener, PopupMenuListener { JToggleButton button, b2, bselect; Vector vlist = new Vector(); @@ -2966,7 +3350,11 @@ public void mouseExited(MouseEvent e) { } } - + /** + * Create an ImageIcon from the path. + * @param path the path to the image + * @return the ImageIcon + */ protected static ImageIcon createImageIcon(String path) { java.net.URL imgURL = GExpert.class.getResource(path); if (imgURL == null) { @@ -2975,6 +3363,11 @@ protected static ImageIcon createImageIcon(String path) { return new ImageIcon(imgURL); } + /** + * Get the resource URL from the path. + * @param path the path to the resource + * @return the URL of the resource + */ public static URL getResourceURL(String path) { return GExpert.class.getResource(path); } @@ -3013,7 +3406,7 @@ private static void createAndShowGUI() { * so we cannot wait for their finish her and cannot continue with the remaining requests. Instead, * we will continue performing the requests later, when the asynchronous command finishes. * - * @param exp a GExpert instance + * @param exp a GExpert instance * @param breakOnProve if the "Prove" command should be assumed as an asynchronous call */ public static void performCommandLineRequests(GExpert exp, boolean breakOnProve) { @@ -3049,6 +3442,7 @@ public static void setLookAndFeel() { public static ArrayList commandlineCommand = new ArrayList<>(); public static ArrayList commandlineSrc = new ArrayList<>(); public static int commandLineRequestsPerformed = 0; + private static void processCommandLineOptions(String[] args) { Options options = new Options(); @@ -3100,10 +3494,10 @@ private static void processCommandLineOptions(String[] args) { // Process first argument as a file: String filename = cmd.getArgList().get(0); if (filename.endsWith(".gex")) { - commandlineCommand.add("Open");} - else { + commandlineCommand.add("Open"); + } else { commandlineCommand.add("Import"); - } + } commandlineSrc.add(new File(filename)); if (cmd.hasOption("p")) { @@ -3134,8 +3528,15 @@ private static void processCommandLineOptions(String[] args) { } } + // TODO START CONVERTING HERE, this is the main method + /** + * Main entry point of the application. + * Processes command line options and initializes the GUI. + * + * @param args command line arguments. + */ public static void main(String[] args) { - System.out.println("Java " + Version.getNameAndVersion()); + System.out.println("Java " + Version.getNameAndVersion()); processCommandLineOptions(args); javax.swing.SwingUtilities.invokeLater(new Runnable() { @@ -3145,7 +3546,11 @@ public void run() { }); } - + /** + * Opens the specified URL in the system's default web browser. + * + * @param url the URL to open. + */ public static void openURL(String url) { String osName = System.getProperty("os.name"); try { @@ -3179,6 +3584,10 @@ public static void openURL(String url) { } } + /** + * Saves the current view as a PDF file. + * Prompts the user to choose a file and generates the PDF output. + */ public void saveAsPDF() { if (!need_save()) return; @@ -3214,7 +3623,7 @@ public String getDescription() { } if (file.exists()) { int n2 = JOptionPane.showConfirmDialog(this, - getTranslationViaGettext("{0} already exists, do you want to overwrite it?", file.getName()), + getTranslationViaGettext("{0} already exists, do you want to overwrite it?", file.getName()), "File Exists", JOptionPane.YES_NO_CANCEL_OPTION); if (n2 != JOptionPane.YES_OPTION) { return; @@ -3237,17 +3646,35 @@ public String getDescription() { } + /** + * Handles key typed events. + * + * @param e the key event. + */ public void keyTyped(KeyEvent e) { } + /** + * Handles key pressed events. + * + * @param e the key event. + */ public void keyPressed(KeyEvent e) { int k = 0; } + /** + * Handles key released events. + * + * @param e the key event. + */ public void keyReleased(KeyEvent e) { } - + /** + * This class is used to group buttons in a button group. + * It allows for easy retrieval of buttons by their action command. + */ class Group extends ButtonGroup { public Group() { super(); @@ -3268,19 +3695,11 @@ public AbstractButton getButton(String s) { } } -// public void addDependentDialog(JDialog dlg) { -// if (dlg != null && !depdlglist.contains(dlg)) -// depdlglist.add(dlg); -// } - -// private void removeAllDependentDialogs() { -// for (int i = 0; i < depdlglist.size(); i++) { -// JDialog dlg = (JDialog) depdlglist.get(i); -// dlg.setVisible(false); -// } -// depdlglist.clear(); -// } - + /** + * Sets the default UI font for all components. + * + * @param f the FontUIResource to be used. + */ public static void setUIFont(javax.swing.plaf.FontUIResource f) { java.util.Enumeration keys = UIManager.getDefaults().keys(); @@ -3292,16 +3711,23 @@ public static void setUIFont(javax.swing.plaf.FontUIResource f) { } } + /** + * Starts or initializes the component. + */ public void start() { } + /** + * Stops or cleans up the component. + */ public void stop() { } - public void destroy() { - } - - + /** + * Updates the action pool using the currently selected list of objects. + * + * @param n the pool identifier to update. + */ public void updateActionPool(int n) { Vector v = dp.getSelectList(); int nx = vpoolist.size(); @@ -3315,6 +3741,11 @@ public void updateActionPool(int n) { } + /** + * Configures the action pool based on the specified pool type. + * + * @param a the pool type identifier. + */ public void setActionPool(int a) { int n = dp.getPooln(a); int sz = vpoolist.size(); @@ -3346,6 +3777,10 @@ public void setActionPool(int a) { } } + /** + * This class represents a label in the action pool. + * It displays the type of object and allows for mouse interaction. + */ class OPoolabel extends JLabel implements MouseListener { private int otype = -1; private Object obj; @@ -3424,12 +3859,18 @@ public void mouseExited(MouseEvent e) { } + /** + * Cancels the current action triggered by key events. + */ public void onKeyCancel() { dp.cancelCurrentAction(); //this.setActionMove(); // closeAllDialogs(); } + /** + * Initializes the key mapping by registering a KeyEventPostProcessor. + */ public void initKeyMap() { KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); manager.addKeyEventPostProcessor(new KeyProcessor()); @@ -3437,6 +3878,9 @@ public void initKeyMap() { public static long HotKeyTimer = 0; + /** + * This class processes key events and performs actions based on the key pressed. + */ class KeyProcessor implements KeyEventPostProcessor { public boolean postProcessKeyEvent(KeyEvent event) { int key = event.getKeyCode(); @@ -3495,11 +3939,14 @@ else if (event.isControlDown()) } -//////////////////////////////////////////////// -////// End of GExpert.java. -/////////////////////////////////////////////// - +/// ///////////////////////////////////////////// +/// /// End of GExpert.java. +/// //////////////////////////////////////////// +/** + * This class is used to create a button with two icons, one for the selected state and one for the unselected state. + * It is used in the GExpert application to create buttons with different icons depending on their state. + */ class DActionButton extends ActionButton { private Icon ico1, ico2; @@ -3507,11 +3954,22 @@ public DActionButton(Icon co) { super(co); } + /** + * Sets the icons for the two status states of the button. + * + * @param ico1 the icon for the unselected state + * @param ico2 the icon for the selected state + */ public void set2StatusIcons(Icon ico1, Icon ico2) { this.ico1 = ico1; this.ico2 = ico2; } + /** + * Sets the selected state of the button and updates the icon accordingly. + * + * @param b true if the button is selected, false otherwise + */ public void setSelected(boolean b) { super.setSelected(b); if (b) { @@ -3519,9 +3977,13 @@ public void setSelected(boolean b) { } else { this.setIcon(ico1); } - } + /** + * Enables or disables the button and sets the icon to the unselected state. + * + * @param b true to enable the button, false to disable it + */ public void setEnabled(boolean b) { super.setEnabled(b); this.setIcon(ico1); @@ -3529,7 +3991,10 @@ public void setEnabled(boolean b) { } } - +/** + * This class is used to create a button with a custom UI. It is used in the GExpert application to create buttons + * with a specific look and feel. + */ class ActionButton extends JToggleButton { private static EntityButtonUI ui = new EntityButtonUI(); @@ -3543,10 +4008,6 @@ public ActionButton(Icon co) { dm = new Dimension(32, 28); } - public void setButtonSize(int x, int y) { - dm.setSize(x, y); - } - public Dimension getPreferredSize() { return dm; } @@ -3554,12 +4015,12 @@ public Dimension getPreferredSize() { public Dimension getMaximumSize() { return dm; } - - ////////////////////////////////////////////////////////////////////// - - } +/** + * This class is used to create a button with two states (selected and unselected) and two icons. It is used in the + * GExpert application to create buttons with different icons depending on their state. + */ class TStateButton extends JToggleButton { ImageIcon icon1, icon2; diff --git a/src/main/java/wprover/GIFOptionDialog.java b/src/main/java/wprover/GIFOptionDialog.java index 84de3616..cbac5d4e 100644 --- a/src/main/java/wprover/GIFOptionDialog.java +++ b/src/main/java/wprover/GIFOptionDialog.java @@ -8,20 +8,22 @@ import java.awt.event.ActionEvent; /** - * Created by IntelliJ IDEA. - * User: ye - * Date: 2008-4-10 - * Time: 22:42:17 - * To change this template use File | Settings | File Templates. - */ + * A dialog for setting GIF options in GeoGebra. + */ public class GIFOptionDialog extends JBaseDialog implements ActionListener, ChangeListener { - JSlider slider; - JTextField field1, field2; - JButton bok, bcancel; - boolean result = false; + private JSlider slider; + private JTextField field1, field2; + private JButton bok, bcancel; + private boolean result = false; private GExpert gxInstance; + /** + * Constructs a new GIFOptionDialog with the specified GExpert instance and title. + * + * @param fr the GExpert instance + * @param title the title of the dialog + */ public GIFOptionDialog(GExpert fr, String title) { super(fr.getFrame(), title, true); gxInstance = fr; @@ -40,7 +42,6 @@ public GIFOptionDialog(GExpert fr, String title) { panel.add(panel1); panel.add(Box.createVerticalStrut(5)); slider = new JSlider(1, 20, 1); -// slider = new JSlider(0, 20); slider.setValue(2); slider.setPaintTicks(true); slider.setMinorTickSpacing(1); @@ -63,20 +64,39 @@ public GIFOptionDialog(GExpert fr, String title) { this.setSize(300, 150); } + /** + * Sets the default value of the slider. + * + * @param n the default value + */ public void setDefaultValue(int n) { slider.setValue(n); this.updateValue(); } + /** + * Returns the result of the dialog. + * + * @return true if OK was pressed, false otherwise + */ public boolean getReturnResult() { return result; } + /** + * Returns the quality value based on the slider position. + * + * @return the quality value + */ public int getQuality() { return 21 - slider.getValue(); } - + /** + * Handles action events for the OK and Cancel buttons. + * + * @param e the action event + */ public void actionPerformed(ActionEvent e) { if (e.getSource() == bok) result = true; @@ -84,20 +104,30 @@ public void actionPerformed(ActionEvent e) { this.setVisible(false); } + /** + * Handles state change events for the slider. + * + * @param e the change event + */ public void stateChanged(ChangeEvent e) { updateValue(); } + /** + * Updates the text fields based on the slider value. + */ private void updateValue() { int v = slider.getValue(); field1.setText(Integer.toString(v)); field2.setText(getRate(v)); } - private int getValue() { - return 21 - slider.getValue(); - } - + /** + * Returns the quality rate as a string based on the slider value. + * + * @param n the slider value + * @return the quality rate + */ private String getRate(int n) { if (n > 18) return gxInstance.getLanguage("Best"); @@ -109,6 +139,4 @@ else if (n > 5) return gxInstance.getLanguage("Low"); else return gxInstance.getLanguage("Very Low"); } - - } \ No newline at end of file diff --git a/src/main/java/wprover/GIFProcessDialog.java b/src/main/java/wprover/GIFProcessDialog.java index 716a5043..1236c511 100644 --- a/src/main/java/wprover/GIFProcessDialog.java +++ b/src/main/java/wprover/GIFProcessDialog.java @@ -10,13 +10,8 @@ import java.io.IOException; /** - * Created by IntelliJ IDEA. - * User: ye - * Date: 2008-6-28 - * Time: 14:58:12 - * To change this template use File | Settings | File Templates. + * A dialog for processing GIF creation in GeoGebra. */ - public class GIFProcessDialog extends JBaseDialog implements ActionListener { JProgressBar progress; @@ -29,7 +24,11 @@ public class GIFProcessDialog extends JBaseDialog implements ActionListener { public Rectangle rect; public GifEncoder en; - + /** + * Constructs a new GIFProcessDialog with the specified frame. + * + * @param f the frame to associate with this dialog + */ public GIFProcessDialog(Frame f) { super(f, false); this.setTitle(GExpert.getLanguage("Building GIF File")); @@ -65,6 +64,9 @@ public GIFProcessDialog(Frame f) { boolean finished = false; + /** + * Starts the GIF creation process in a new thread. + */ public void setRun() { Saver sv = new Saver(); Thread t = new Thread(sv, "Progress"); @@ -72,15 +74,18 @@ public void setRun() { t.start(); } + /** + * A runnable class for saving the GIF frames. + */ class Saver implements Runnable { public void run() { - double []r = dp.getParameter(); - - am.minwd = rect.getX() +5; - am.minht = rect.getY() +5; - am.width = rect.getX() + rect.getWidth() -5; - am.height = rect.getY() + rect.getHeight() -5; + double[] r = dp.getParameter(); + + am.minwd = rect.getX() + 5; + am.minht = rect.getY() + 5; + am.width = rect.getX() + rect.getWidth() - 5; + am.height = rect.getY() + rect.getHeight() - 5; am.reClaclulate(); total = am.getRounds(); @@ -112,16 +117,30 @@ public void run() { } } + /** + * Sets the total number of frames to be processed. + * + * @param n the total number of frames + */ public void setTotal(int n) { this.total = n; } + /** + * Updates the progress bar and label with the current frame count. + * + * @param n the current frame count + */ public void setValue(int n) { progress.setValue(n * 100 / total); label.setText(n + " frame(s) added"); } - + /** + * Handles action events for the Cancel button. + * + * @param e the action event + */ public void actionPerformed(ActionEvent e) { finished = true; this.setVisible(false); diff --git a/src/main/java/wprover/GProver.java b/src/main/java/wprover/GProver.java index 185b978f..67088710 100644 --- a/src/main/java/wprover/GProver.java +++ b/src/main/java/wprover/GProver.java @@ -8,6 +8,10 @@ import static wprover.GExpert.commandlineCommand; +/** + * The GProver class implements the Runnable interface and is responsible for + * managing the proving process in GeoGebra. + */ public class GProver implements Runnable { GExpert gxInstance; @@ -20,26 +24,40 @@ public class GProver implements Runnable { int number = 0; long ftime = 0; + /** + * Constructs a new GProver with the specified PanelProve and GExpert instances. + * + * @param p the PanelProve instance + * @param fr the GExpert instance + */ public GProver(PanelProve p, GExpert fr) { pprove = p; gxInstance = fr; } + /** + * Sets the status to fix mode. + */ public void setFix() { Status = 0; } + /** + * Sets the status to prove mode. + */ public void setProve() { Status = 1; } + /** + * Starts the timer for the proving process. + */ public void startTimer() { number = 0; ftime = System.currentTimeMillis(); timer = new Timer(100, new ActionListener() { public void actionPerformed(ActionEvent e) { - // int n = Prover.getNumberofProperties(); if (!isRunning) timer.stop(); else { @@ -53,6 +71,9 @@ public void actionPerformed(ActionEvent e) { timer.start(); } + /** + * Runs the proving process in a separate thread. + */ public void run() { isRunning = true; try { @@ -93,10 +114,12 @@ public void run() { gxInstance.stopTimer(); isRunning = false; - // Do the remaining steps from the command line request... GExpert.performCommandLineRequests(gxInstance, false); - } + } + /** + * Starts the proving process in a new thread. + */ public void start() { if (isRunning) return; main = new Thread(this, "Prover"); @@ -104,6 +127,11 @@ public void start() { startTimer(); } + /** + * Checks if the proving process is currently running. + * + * @return true if the proving process is running, false otherwise + */ public boolean isRunning() { return isRunning; } diff --git a/src/main/java/wprover/GRule.java b/src/main/java/wprover/GRule.java index ec17022b..4b28c97b 100644 --- a/src/main/java/wprover/GRule.java +++ b/src/main/java/wprover/GRule.java @@ -1,20 +1,26 @@ package wprover; + /** - * Created by IntelliJ IDEA. - * User: ye - * Date: 2007-5-9 - * Time: 15:30:31 - * To change this template use File | Settings | File Templates. + * Represents a rule in GeoGebra with a type, name, head, description, and example string. */ public class GRule { public int type; - public int rx; // 0. GDD, 1. FULL + public int rx; // 0: GDD, 1: FULL public String name; public String head; public String description; public String exstring; + /** + * Constructs a new GRule with the specified type, head, description, example string, and rule type. + * + * @param t the type of the rule + * @param t1 the head of the rule + * @param t2 the description of the rule + * @param t3 the example string of the rule + * @param tx the rule type (0 for GDD, 1 for FULL) + */ public GRule(int t, String t1, String t2, String t3, int tx) { type = t; head = t1; @@ -27,10 +33,20 @@ public GRule(int t, String t1, String t2, String t3, int tx) { rx = tx; } + /** + * Checks if the rule is a GDD rule. + * + * @return true if the rule is a GDD rule, false otherwise + */ public boolean isGDDRule() { return rx == 0; } + /** + * Checks if the rule is a FULL rule. + * + * @return true if the rule is a FULL rule, false otherwise + */ public boolean isFullRule() { return rx == 1; } diff --git a/src/main/java/wprover/GeoPoly.java b/src/main/java/wprover/GeoPoly.java index 591dd5ac..03e5efcb 100644 --- a/src/main/java/wprover/GeoPoly.java +++ b/src/main/java/wprover/GeoPoly.java @@ -8,15 +8,29 @@ import java.util.Vector; - +/** + * GeoPoly is a singleton class that provides methods for constructing polynomial expressions + * related to geometric properties and relationships. + * It extends the PolyBasic class and provides various methods for creating polynomial terms, + * performing arithmetic operations on them, and checking conditions related to geometry. + */ public class GeoPoly extends PolyBasic { static GeoPoly poly = new GeoPoly(); static int[] zeron = new int[100]; + /** + * Private constructor to prevent instantiation. + */ private GeoPoly() { } + /** + * Adds a non-zero integer to the zeron array if it is not already present. + * + * @param n the integer to add + * @return true if the integer was added, false if it was already present or zero + */ public static boolean addZeroN(int n) { if (n == 0) return false; @@ -30,21 +44,39 @@ public static boolean addZeroN(int n) { } } + /** + * Clears the zeron array by setting all elements to zero. + */ public static void clearZeroN() { int i = 0; while (i < zeron.length) zeron[i++] = 0; } + /** + * Returns the zeron array. + * + * @return the zeron array + */ public static int[] getZeron() { return zeron; } + /** + * Returns the singleton instance of GeoPoly. + * + * @return the singleton instance of GeoPoly + */ public static GeoPoly getPoly() { return poly; } - + /** + * Checks if a given integer is present in the zeron array. + * + * @param n the integer to check + * @return true if the integer is present, false otherwise + */ public static boolean vzero(int n) { for (int i = 0; i < zeron.length && zeron[i] != 0; i++) { if (zeron[i] == n) @@ -53,14 +85,28 @@ public static boolean vzero(int n) { return false; } - TMono ppth(int x, int c, int d ) { + /** + * Constructs a TMono representing a polynomial term. + * + * @param x the variable index + * @param c the coefficient + * @param d the degree + * @return the constructed TMono, or null if the variable index is zero + */ + TMono ppth(int x, int c, int d) { if (vzero(x)) return null; else return pth(x, 1, 1); } - TMono ppdd(int x, int y)//new and add - { + /** + * Constructs a TMono representing the difference between two polynomial terms. + * + * @param x the variable index of the first term + * @param y the variable index of the second term + * @return the constructed TMono + */ + TMono ppdd(int x, int y) { if (CMisc.POINT_TRANS) { if (vzero(x)) { if (vzero(y)) @@ -88,34 +134,110 @@ TMono ppdd(int x, int y)//new and add } } - TMono sqdistance(int x1, int y1, int x2, int y2) //distance between two point - { + /** + * Constructs a TMono representing the squared distance between two points. + * + * @param x1 the x-coordinate of the first point + * @param y1 the y-coordinate of the first point + * @param x2 the x-coordinate of the second point + * @param y2 the y-coordinate of the second point + * @return the constructed TMono + */ + TMono sqdistance(int x1, int y1, int x2, int y2) { return (padd(pRtimes(ppdd(x1, x2), ppdd(x1, x2)), pRtimes(ppdd(y1, y2), ppdd(y1, y2)))); } - TMono eqdistance(int x1, int y1, int x2, int y2, //poly of equal distance - int x3, int y3, int x4, int y4) { + /** + * Constructs a TMono representing the equality of distances between two pairs of points. + * + * @param x1 the x-coordinate of the first point of the first pair + * @param y1 the y-coordinate of the first point of the first pair + * @param x2 the x-coordinate of the second point of the first pair + * @param y2 the y-coordinate of the second point of the first pair + * @param x3 the x-coordinate of the first point of the second pair + * @param y3 the y-coordinate of the first point of the second pair + * @param x4 the x-coordinate of the second point of the second pair + * @param y4 the y-coordinate of the second point of the second pair + * @return the constructed TMono + */ + TMono eqdistance(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) { return (pdif(sqdistance(x1, y1, x2, y2), sqdistance(x3, y3, x4, y4))); } - TMono perpendicular(int x1, int y1, int x2, int y2, - int x3, int y3, int x4, int y4) { + /** + * Constructs a TMono representing the perpendicularity condition between two lines. + * + * @param x1 the x-coordinate of the first point of the first line + * @param y1 the y-coordinate of the first point of the first line + * @param x2 the x-coordinate of the second point of the first line + * @param y2 the y-coordinate of the second point of the first line + * @param x3 the x-coordinate of the first point of the second line + * @param y3 the y-coordinate of the first point of the second line + * @param x4 the x-coordinate of the second point of the second line + * @param y4 the y-coordinate of the second point of the second line + * @return the constructed TMono + */ + TMono perpendicular(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) { return (padd(pRtimes(ppdd(x1, x2), ppdd(x3, x4)), pRtimes(ppdd(y1, y2), ppdd(y3, y4)))); } - TMono parallel(int x1, int y1, int x2, int y2, - int x3, int y3, int x4, int y4) { + /** + * Constructs a TMono representing the parallelism condition between two lines. + * + * @param x1 the x-coordinate of the first point of the first line + * @param y1 the y-coordinate of the first point of the first line + * @param x2 the x-coordinate of the second point of the first line + * @param y2 the y-coordinate of the second point of the first line + * @param x3 the x-coordinate of the first point of the second line + * @param y3 the y-coordinate of the first point of the second line + * @param x4 the x-coordinate of the second point of the second line + * @param y4 the y-coordinate of the second point of the second line + * @return the constructed TMono + */ + TMono parallel(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) { return (pdif(pRtimes(ppdd(x3, x4), ppdd(y1, y2)), pRtimes(ppdd(x1, x2), ppdd(y3, y4)))); } + /** + * Constructs a TMono representing the collinearity condition of three points. + * + * @param x1 the x-coordinate of the first point + * @param y1 the y-coordinate of the first point + * @param x2 the x-coordinate of the second point + * @param y2 the y-coordinate of the second point + * @param x3 the x-coordinate of the third point + * @param y3 the y-coordinate of the third point + * @return the constructed TMono + */ TMono collinear(int x1, int y1, int x2, int y2, int x3, int y3) { return (pdif(pRtimes(ppdd(x2, x3), ppdd(y1, y2)), pRtimes(ppdd(x1, x2), ppdd(y2, y3)))); } + /** + * Constructs a TMono representing the ratio condition between two sets of points. + * + * @param x1 the x-coordinate of the first point of the first set + * @param y1 the y-coordinate of the first point of the first set + * @param x2 the x-coordinate of the second point of the first set + * @param y2 the y-coordinate of the second point of the first set + * @param x3 the x-coordinate of the third point of the first set + * @param y3 the y-coordinate of the third point of the first set + * @param x4 the x-coordinate of the first point of the second set + * @param y4 the y-coordinate of the first point of the second set + * @param x5 the x-coordinate of the second point of the second set + * @param y5 the y-coordinate of the second point of the second set + * @param x6 the x-coordinate of the third point of the second set + * @param y6 the y-coordinate of the third point of the second set + * @param x7 the x-coordinate of the fourth point of the second set + * @param y7 the y-coordinate of the fourth point of the second set + * @param x8 the x-coordinate of the fifth point of the second set + * @param y8 the y-coordinate of the fifth point of the second set + * @return the constructed TMono + */ TMono ratio(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, int x5, int y5, int x6, int y6, int x7, int y7, int x8, int y8) { @@ -123,10 +245,33 @@ TMono ratio(int x1, int y1, int x2, int y2, int x3, int y3, ptimes(sqdistance(x3, y3, x4, y4), sqdistance(x5, y5, x6, y6))); } + /** + * Constructs a TMono representing the equality of three angles formed by nine points. + * + * @param x1 the x-coordinate of the first point of the first angle + * @param y1 the y-coordinate of the first point of the first angle + * @param x2 the x-coordinate of the second point of the first angle + * @param y2 the y-coordinate of the second point of the first angle + * @param x3 the x-coordinate of the third point of the first angle + * @param y3 the y-coordinate of the third point of the first angle + * @param x4 the x-coordinate of the first point of the second angle + * @param y4 the y-coordinate of the first point of the second angle + * @param x5 the x-coordinate of the second point of the second angle + * @param y5 the y-coordinate of the second point of the second angle + * @param x6 the x-coordinate of the third point of the second angle + * @param y6 the y-coordinate of the third point of the second angle + * @param x7 the x-coordinate of the first point of the third angle + * @param y7 the y-coordinate of the first point of the third angle + * @param x8 the x-coordinate of the second point of the third angle + * @param y8 the y-coordinate of the second point of the third angle + * @param x9 the x-coordinate of the third point of the third angle + * @param y9 the y-coordinate of the third point of the third angle + * @param xm the x-coordinate of the point used for the final calculation + * @return the TMono representing the equality of the three angles + */ TMono eqangle3p(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, int x5, int y5, int x6, int y6, int x7, int y7, int x8, int y8, int x9, int y9, int xm) { - TMono sx1 = pdif(pRtimes(ppdd(x3, x2), ppdd(y1, y2)), pRtimes(ppdd(x1, x2), ppdd(y3, y2))); TMono sy1 = padd(pRtimes(ppdd(x1, x2), ppdd(x3, x2)), pRtimes(ppdd(y1, y2), ppdd(y3, y2))); @@ -136,7 +281,6 @@ TMono eqangle3p(int x1, int y1, int x2, int y2, int x3, int y3, TMono sx3 = pdif(pRtimes(ppdd(x9, x8), ppdd(y7, y8)), pRtimes(ppdd(x7, x8), ppdd(y9, y8))); TMono sy3 = padd(pRtimes(ppdd(x7, x8), ppdd(x9, x8)), pRtimes(ppdd(y7, y8), ppdd(y9, y8))); - TMono mx1 = pRtimes(pcopy(sx1), pRtimes(pcopy(sy2), pcopy(sy3))); TMono mx2 = pRtimes(pcopy(sx2), pRtimes(pcopy(sy1), pcopy(sy3))); TMono mx3 = pRtimes(pcopy(sx3), pRtimes(pcopy(sy1), pcopy(sy2))); @@ -151,17 +295,16 @@ TMono eqangle3p(int x1, int y1, int x2, int y2, int x3, int y3, TMono t = pRtimes(pcopy(sy1), pRtimes(pcopy(sy2), pcopy(sy3))); TMono mm1 = pdif(t1, t2); TMono mm2 = pdif(t, padd(t3, padd(t4, t5))); - //return pdif(mm1, pRtimes(mm2, new TMono(xm, 1, 1))); - return pdif(mm1, pRtimes(mm2, ppth(xm, 1, 1)));//new TMono(xm, 1, 1))); - } - - TMono sangle(int x1, int y1, int x2, int y2, int x3, int y3, int d) { - TMono m = new TMono(d, -1, 1); - TMono m1 = pdif(ptimes(ppdd(y3, y2), ppdd(x1, x2)), ptimes(ppdd(y1, y2), ppdd(x3, x2))); - TMono m2 = padd(ptimes(ppdd(y3, y2), ppdd(y1, y2)), ptimes(ppdd(x1, x2), ppdd(x3, x2))); - return pdif(m1, ptimes(m2, m)); + return pdif(mm1, pRtimes(mm2, ppth(xm, 1, 1))); } + /** + * Constructs a TMono representing a specific angle. + * + * @param x1 the x-coordinate of the point + * @param degree the degree of the angle + * @return the TMono representing the specific angle + */ TMono specificangle(int x1, int degree) { if (degree == 0) { TMono m1 = new TMono(x1, 1, 1); @@ -171,17 +314,14 @@ TMono specificangle(int x1, int degree) { TMono m2 = new TMono(x1, -4, 1); TMono m3 = new TMono(0, 1, 0); return padd(pdif(m1, m2), m3); - } else if (degree == 30) { TMono m1 = new TMono(x1, 3, 2); TMono m2 = new TMono(0, 1, 0); return pdif(m1, m2); - } else if (degree == 45) { TMono m1 = new TMono(x1, 1, 1); TMono m2 = new TMono(0, 1, 0); return pdif(m1, m2); - } else if (degree == 60) { TMono m1 = new TMono(x1, 1, 2); TMono m2 = new TMono(0, 3, 0); @@ -190,23 +330,38 @@ TMono specificangle(int x1, int degree) { TMono m1 = new TMono(x1, 1, 2); TMono m2 = new TMono(0, 3, 0); return pdif(m1, m2); - } return null; } - - TMono eqangle(int x1, int y1, int x2, int y2, int x21, int y21, int x3, int y3, - int x4, int y4, int x5, int y5, int x51, int y51, int x6, int y6) { + /** + * Constructs a TMono representing the equality of two angles formed by six points. + * + * @param x1 the x-coordinate of the first point of the first angle + * @param y1 the y-coordinate of the first point of the first angle + * @param x2 the x-coordinate of the second point of the first angle + * @param y2 the y-coordinate of the second point of the first angle + * @param x3 the x-coordinate of the third point of the first angle + * @param y3 the y-coordinate of the third point of the first angle + * @param x4 the x-coordinate of the first point of the second angle + * @param y4 the y-coordinate of the first point of the second angle + * @param x5 the x-coordinate of the second point of the second angle + * @param y5 the y-coordinate of the second point of the second angle + * @param x6 the x-coordinate of the third point of the second angle + * @param y6 the y-coordinate of the third point of the second angle + * @return the TMono representing the equality of the two angles + */ + TMono eqangle(int x1, int y1, int x2, int y2, int x3, int y3, + int x4, int y4, int x5, int y5, int x6, int y6) { TMono sx1 = ppdd(x1, x2); - TMono sx2 = ppdd(x3, x21); + TMono sx2 = ppdd(x3, x2); TMono sx3 = ppdd(x4, x5); - TMono sx4 = ppdd(x6, x51); + TMono sx4 = ppdd(x6, x5); TMono sy1 = ppdd(y1, y2); - TMono sy2 = ppdd(y3, y21); + TMono sy2 = ppdd(y3, y2); TMono sy3 = ppdd(y4, y5); - TMono sy4 = ppdd(y6, y51); + TMono sy4 = ppdd(y6, y5); TMono s1 = this.pRtimes(poly.pcopy(sy2), poly.pcopy(sx1)); TMono s2 = this.pRtimes(poly.pcopy(sy1), poly.pcopy(sx2)); @@ -223,27 +378,43 @@ TMono eqangle(int x1, int y1, int x2, int y2, int x21, int y21, int x3, int y3, s4 = this.pRtimes((sy1), (sy2)); TMono t4 = padd(s3, s4); - TMono r1 = pRtimes(t1, t2); TMono r2 = pRtimes(t3, t4); return this.pdif(r1, r2); } - TMono cyclic(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) { - return eqangle(x1, y1, x3, y3, x2, y2, x1, y1, x4, y4, x2, y2); - } - - TMono eqangle(int x1, int y1, int x2, int y2, int x3, int y3, - int x4, int y4, int x5, int y5, int x6, int y6) { + /** + * Constructs a TMono representing the equality of two angles formed by six points. + * + * @param x1 the x-coordinate of the first point of the first angle + * @param y1 the y-coordinate of the first point of the first angle + * @param x2 the x-coordinate of the second point of the first angle + * @param y2 the y-coordinate of the second point of the first angle + * @param x21 the x-coordinate of the third point of the first angle + * @param y21 the y-coordinate of the third point of the first angle + * @param x3 the x-coordinate of the first point of the second angle + * @param y3 the y-coordinate of the first point of the second angle + * @param x4 the x-coordinate of the second point of the second angle + * @param y4 the y-coordinate of the second point of the second angle + * @param x5 the x-coordinate of the third point of the second angle + * @param y5 the y-coordinate of the third point of the second angle + * @param x51 the x-coordinate of the fourth point of the second angle + * @param y51 the y-coordinate of the fourth point of the second angle + * @param x6 the x-coordinate of the fifth point of the second angle + * @param y6 the y-coordinate of the fifth point of the second angle + * @return the TMono representing the equality of the two angles + */ + TMono eqangle(int x1, int y1, int x2, int y2, int x21, int y21, int x3, int y3, + int x4, int y4, int x5, int y5, int x51, int y51, int x6, int y6) { TMono sx1 = ppdd(x1, x2); - TMono sx2 = ppdd(x3, x2); + TMono sx2 = ppdd(x3, x21); TMono sx3 = ppdd(x4, x5); - TMono sx4 = ppdd(x6, x5); + TMono sx4 = ppdd(x6, x51); TMono sy1 = ppdd(y1, y2); - TMono sy2 = ppdd(y3, y2); + TMono sy2 = ppdd(y3, y21); TMono sy3 = ppdd(y4, y5); - TMono sy4 = ppdd(y6, y5); + TMono sy4 = ppdd(y6, y51); TMono s1 = this.pRtimes(poly.pcopy(sy2), poly.pcopy(sx1)); TMono s2 = this.pRtimes(poly.pcopy(sy1), poly.pcopy(sx2)); @@ -260,19 +431,70 @@ TMono eqangle(int x1, int y1, int x2, int y2, int x3, int y3, s4 = this.pRtimes((sy1), (sy2)); TMono t4 = padd(s3, s4); - TMono r1 = pRtimes(t1, t2); TMono r2 = pRtimes(t3, t4); - // int n1 = plength(r1); - // int n2 = plength(r2); return this.pdif(r1, r2); } + /** + * Constructs a TMono representing the cyclic condition of four points. + * + * @param x1 the x-coordinate of the first point + * @param y1 the y-coordinate of the first point + * @param x2 the x-coordinate of the second point + * @param y2 the y-coordinate of the second point + * @param x3 the x-coordinate of the third point + * @param y3 the y-coordinate of the third point + * @param x4 the x-coordinate of the fourth point + * @param y4 the y-coordinate of the fourth point + * @return the TMono representing the cyclic condition + */ + TMono cyclic(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) { + return eqangle(x1, y1, x3, y3, x2, y2, x1, y1, x4, y4, x2, y2); + } + + /** + * Constructs a TMono representing the angle between three points. + * + * @param x1 the x-coordinate of the first point + * @param y1 the y-coordinate of the first point + * @param x2 the x-coordinate of the second point + * @param y2 the y-coordinate of the second point + * @param x3 the x-coordinate of the third point + * @param y3 the y-coordinate of the third point + * @param d the degree of the angle + * @return the TMono representing the angle + */ + TMono sangle(int x1, int y1, int x2, int y2, int x3, int y3, int d) { + TMono m = new TMono(d, -1, 1); + TMono m1 = pdif(ptimes(ppdd(y3, y2), ppdd(x1, x2)), ptimes(ppdd(y1, y2), ppdd(x3, x2))); + TMono m2 = padd(ptimes(ppdd(y3, y2), ppdd(y1, y2)), ptimes(ppdd(x1, x2), ppdd(x3, x2))); + return pdif(m1, ptimes(m2, m)); + } + + /** + * Constructs a TMono representing the midpoint of three points. + * + * @param x1 the x-coordinate of the first point + * @param x2 the x-coordinate of the second point + * @param x3 the x-coordinate of the third point + * @return the TMono representing the midpoint + */ TMono midpoint(int x1, int x2, int x3) { return padd(ppdd(x2, x1), ppdd(x2, x3)); } + /** + * Constructs a TMono representing the bisector of an angle. + * + * @param x1 the x-coordinate of the first point + * @param y1 the y-coordinate of the first point + * @param x2 the x-coordinate of the second point + * @param y2 the y-coordinate of the second point + * @param x3 the x-coordinate of the third point + * @return the TMono representing the bisector + */ TMono bisect(int x1, int y1, int x2, int y2, int x3, int y3) { TMono m1 = padd(ppdd(y3, y2), ppdd(y3, y1)); TMono m2 = padd(ppdd(x3, x1), ppdd(x3, x2)); @@ -280,6 +502,16 @@ TMono bisect(int x1, int y1, int x2, int y2, int x3, int y3) { return padd(pRtimes(m1, ppdd(y2, y1)), pRtimes(m2, ppdd(x2, x1))); } + /** + * Constructs a TMono representing the bisector of an angle (alternative method). + * + * @param x1 the x-coordinate of the first point + * @param y1 the y-coordinate of the first point + * @param x2 the x-coordinate of the second point + * @param y2 the y-coordinate of the second point + * @param x3 the x-coordinate of the third point + * @return the TMono representing the bisector + */ TMono bisect1(int x1, int y1, int x2, int y2, int x3, int y3) { TMono m1 = padd(ppdd(y1, y2), ppdd(y1, y3)); TMono m2 = padd(ppdd(x1, x2), ppdd(x1, x3)); @@ -287,6 +519,21 @@ TMono bisect1(int x1, int y1, int x2, int y2, int x3, int y3) { return padd(pRtimes(m1, ppdd(y3, y2)), pRtimes(m2, ppdd(x3, x2))); } + /** + * Constructs a TMono representing the condition that a point lies on a conic section. + * + * @param x the x-coordinate of the point + * @param y the y-coordinate of the point + * @param x1 the x-coordinate of the first point on the conic + * @param y1 the y-coordinate of the first point on the conic + * @param x2 the x-coordinate of the second point on the conic + * @param y2 the y-coordinate of the second point on the conic + * @param x3 the x-coordinate of the third point on the conic + * @param y3 the y-coordinate of the third point on the conic + * @param x4 the x-coordinate of the fourth point on the conic + * @param y4 the y-coordinate of the fourth point on the conic + * @return the TMono representing the condition + */ TMono ccline(int x, int y, int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) { TMono s1 = ppdd(x, x1); TMono s2 = ppdd(y, y1); @@ -306,6 +553,20 @@ TMono ccline(int x, int y, int x1, int y1, int x2, int y2, int x3, int y3, int x return pdif(s, t); } + /** + * Constructs a TPoly representing a square point with a given ratio. + * + * @param x the x-coordinate of the point + * @param y the y-coordinate of the point + * @param x0 the x-coordinate of the first reference point + * @param y0 the y-coordinate of the first reference point + * @param x1 the x-coordinate of the second reference point + * @param y1 the y-coordinate of the second reference point + * @param x2 the x-coordinate of the third reference point + * @param y2 the y-coordinate of the third reference point + * @param ratio the ratio to be used + * @return the TPoly representing the square point + */ TPoly squarept1(int x, int y, int x0, int y0, int x1, int y1, int x2, int y2, int ratio) { TMono m1, m2; m1 = m2 = null; @@ -319,6 +580,20 @@ TPoly squarept1(int x, int y, int x0, int y0, int x1, int y1, int x2, int y2, in return newTPoly(m1, m2); } + /** + * Constructs a TPoly representing a square point with a given ratio (alternative method). + * + * @param x the x-coordinate of the point + * @param y the y-coordinate of the point + * @param x0 the x-coordinate of the first reference point + * @param y0 the y-coordinate of the first reference point + * @param x1 the x-coordinate of the second reference point + * @param y1 the y-coordinate of the second reference point + * @param x2 the x-coordinate of the third reference point + * @param y2 the y-coordinate of the third reference point + * @param ratio the ratio to be used + * @return the TPoly representing the square point + */ TPoly squarept2(int x, int y, int x0, int y0, int x1, int y1, int x2, int y2, int ratio) { TMono m1, m2; m1 = m2 = null; @@ -333,6 +608,19 @@ TPoly squarept2(int x, int y, int x0, int y0, int x1, int y1, int x2, int y2, in return newTPoly(m1, m2); } + /** + * Constructs a TPoly representing the mirror image of a point with respect to a line. + * + * @param x1 the x-coordinate of the first point on the line + * @param y1 the y-coordinate of the first point on the line + * @param x2 the x-coordinate of the second point on the line + * @param y2 the y-coordinate of the second point on the line + * @param x3 the x-coordinate of the point to be mirrored + * @param y3 the y-coordinate of the point to be mirrored + * @param x4 the x-coordinate of the mirrored point + * @param y4 the y-coordinate of the mirrored point + * @return the TPoly representing the mirror image + */ TPoly mirrorPL(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) { TMono m1 = this.perpendicular(x1, y1, x2, y2, x3, y3, x4, y4); TMono s1 = pRtimes(padd(ppdd(y2, y3), ppdd(y1, y3)), ppdd(x4, x3)); @@ -341,26 +629,80 @@ TPoly mirrorPL(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) { return newTPoly(m1, m2); } + /** + * Constructs a TPoly representing a point proportional to two other points. + * + * @param x1 the x-coordinate of the first point + * @param y1 the y-coordinate of the first point + * @param x2 the x-coordinate of the second point + * @param y2 the y-coordinate of the second point + * @param x3 the x-coordinate of the third point + * @param y3 the y-coordinate of the third point + * @param v1 the first proportional value + * @param v2 the second proportional value + * @return the TPoly representing the proportional point + */ TPoly prop_point(int x1, int y1, int x2, int y2, int x3, int y3, int v1, int v2) { TMono s1 = pdif(pctimes(ppdd(x2, x1), v2), pctimes(ppdd(x1, x3), v1)); TMono s2 = pdif(pctimes(ppdd(y2, y1), v2), pctimes(ppdd(y1, y3), v1)); -// printpoly(s1); -// printpoly(s2); return newTPoly(s1, s2); } + /** + * Constructs a TPoly representing the ratio of two points. + * + * @param x1 the x-coordinate of the first point + * @param y1 the y-coordinate of the first point + * @param x2 the x-coordinate of the second point + * @param y2 the y-coordinate of the second point + * @param x3 the x-coordinate of the third point + * @param y3 the y-coordinate of the third point + * @param x4 the x-coordinate of the fourth point + * @param y4 the y-coordinate of the fourth point + * @param r1 the first ratio value + * @param r2 the second ratio value + * @return the TPoly representing the ratio + */ TPoly Pratio(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, int r1, int r2) { TMono s1 = pdif(pctimes(ppdd(x1, x2), r2), pctimes(ppdd(x4, x3), r1)); TMono s2 = pdif(pctimes(ppdd(y1, y2), r2), pctimes(ppdd(y4, y3), r1)); return newTPoly(s1, s2); } + /** + * Constructs a TPoly representing the ratio of two points (alternative method). + * + * @param x1 the x-coordinate of the first point + * @param y1 the y-coordinate of the first point + * @param x2 the x-coordinate of the second point + * @param y2 the y-coordinate of the second point + * @param x3 the x-coordinate of the third point + * @param y3 the y-coordinate of the third point + * @param x4 the x-coordinate of the fourth point + * @param y4 the y-coordinate of the fourth point + * @param r1 the first ratio value + * @param r2 the second ratio value + * @return the TPoly representing the ratio + */ TPoly Tratio(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, int r1, int r2) { TMono s1 = pdif(pctimes(ppdd(x1, x2), r2), pctimes(ppdd(y4, y3), r1)); TMono s2 = padd(pctimes(ppdd(y1, y2), r2), pctimes(ppdd(x4, x3), r1)); return newTPoly(s1, s2); } + /** + * Constructs a TPoly representing the barycenter of four points. + * + * @param x1 the x-coordinate of the first point + * @param y1 the y-coordinate of the first point + * @param x2 the x-coordinate of the second point + * @param y2 the y-coordinate of the second point + * @param x3 the x-coordinate of the third point + * @param y3 the y-coordinate of the third point + * @param x4 the x-coordinate of the fourth point + * @param y4 the y-coordinate of the fourth point + * @return the TPoly representing the barycenter + */ TPoly barycenter(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) { TMono m1 = padd(padd(ppdd(x1, x2), ppdd(x1, x3)), ppdd(x1, x4)); TMono m2 = padd(padd(ppdd(y1, y2), ppdd(y1, y3)), ppdd(y1, y4)); @@ -368,16 +710,41 @@ TPoly barycenter(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) return newTPoly(m1, m2); } + /** + * Constructs a TPoly representing the circumcenter of a triangle. + * + * @param x1 the x-coordinate of the first point + * @param y1 the y-coordinate of the first point + * @param x2 the x-coordinate of the second point + * @param y2 the y-coordinate of the second point + * @param x3 the x-coordinate of the third point + * @param y3 the y-coordinate of the third point + * @param x4 the x-coordinate of the fourth point + * @param y4 the y-coordinate of the fourth point + * @return the TPoly representing the circumcenter + */ TPoly circumcenter(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) { TMono m1 = padd(pRtimes(padd(ppdd(x1, x2), ppdd(x1, x3)), ppdd(x2, x3)), pRtimes(padd(ppdd(y1, y2), ppdd(y1, y3)), ppdd(y2, y3))); TMono m2 = padd(pRtimes(padd(ppdd(x1, x3), ppdd(x1, x4)), ppdd(x3, x4)), pRtimes(padd(ppdd(y1, y3), ppdd(y1, y4)), ppdd(y3, y4))); return newTPoly(m1, m2); - } - TPoly LCMeet(int xo, int yo, int xc, int yc, int xl, int yl, int x, int y) { //o,pc,pl,p + /** + * Constructs a TPoly representing the intersection of a line and a circle. + * + * @param xo the x-coordinate of the circle's center + * @param yo the y-coordinate of the circle's center + * @param xc the x-coordinate of the circle's circumference + * @param yc the y-coordinate of the circle's circumference + * @param xl the x-coordinate of the line's first point + * @param yl the y-coordinate of the line's first point + * @param x the x-coordinate of the intersection point + * @param y the y-coordinate of the intersection point + * @return the TPoly representing the intersection + */ + TPoly LCMeet(int xo, int yo, int xc, int yc, int xl, int yl, int x, int y) { TMono m1 = padd(ptimes(padd(ppdd(y, yo), ppdd(yc, yo)), ppdd(yl, yc)), ptimes(padd(ppdd(x, xo), ppdd(xc, xo)), ppdd(xl, xc))); TMono m2 = pdif(ptimes(ppdd(y, yc), ppdd(xl, xc)), @@ -385,33 +752,35 @@ TPoly LCMeet(int xo, int yo, int xc, int yc, int xl, int yl, int x, int y) { //o return newTPoly(m1, m2); } + /** + * Constructs a TPoly representing an equilateral triangle. + * + * @param x the x-coordinate of the first point + * @param y the y-coordinate of the first point + * @param x1 the x-coordinate of the second point + * @param y1 the y-coordinate of the second point + * @param x2 the x-coordinate of the third point + * @param y2 the y-coordinate of the third point + * @param p a boolean flag + * @return the TPoly representing the equilateral triangle + */ TPoly pn_eq_triangle(int x, int y, int x1, int y1, int x2, int y2, boolean p) { TMono m1 = eqdistance(x, y, x1, y1, x1, y1, x2, y2); TMono m2 = eqdistance(x, y, x2, y2, x1, y1, x2, y2); return newTPoly(m1, m2); } - TMono ratio0(int x, int y, int z, int n1, int n2) { - return (pdif(pctimes(ppdd(x, y), n2), pctimes(ppdd(y, z), n1))); - } - - TMono sum3(int xa, int ya, int xb, int yb, int xc, int yc, int xd, int yd, int xe, int ye, int xf, int yf) { - TMono x, y, z, x1, y1, z1, s, r; - - x = sqdistance(xa, ya, xb, yb); - y = sqdistance(xc, yc, xd, yd); - z = sqdistance(xe, ye, xf, yf); - - x1 = pcopy(x); - y1 = pcopy(y); - z1 = pcopy(z); - TMono s1 = pdif(padd(pcopy(x1), pcopy(y1)), z1); - s1 = pRtimes(pcopy(s1), s1); - TMono s2 = pctimes(pRtimes(x1, y1), -4); - - return padd(s1, s2); - } - + /** + * Constructs a TMono representing the sum of three squared distances. + * + * @param a the first point + * @param b the second point + * @param c the third point + * @param d the fourth point + * @param e the fifth point + * @param f the sixth point + * @return the TMono representing the sum of three squared distances + */ TMono sum3(CPoint a, CPoint b, CPoint c, CPoint d, CPoint e, CPoint f) { TMono x, y, z, x1, y1, z1, s, r; @@ -435,20 +804,55 @@ TMono sum3(CPoint a, CPoint b, CPoint c, CPoint d, CPoint e, CPoint f) { return padd(s, r); } + /** + * Constructs a TMono representing the product of two squared distances. + * + * @param a the first point + * @param b the second point + * @param c the third point + * @param d the fourth point + * @param t1 the first multiplier + * @param t2 the second multiplier + * @return the TMono representing the product of two squared distances + */ TMono p_p_mulside(CPoint a, CPoint b, CPoint c, CPoint d, int t1, int t2) { TMono m1 = sqdistance(a.x1.xindex, a.y1.xindex, b.x1.xindex, b.y1.xindex); TMono m2 = sqdistance(c.x1.xindex, c.y1.xindex, d.x1.xindex, d.y1.xindex); return pdif(pctimes(m1, t2 * t2), pctimes(m2, t1 * t1)); } + /** + * Constructs a TMono representing the horizontal distance between two points. + * + * @param a the first point + * @param b the second point + * @return the TMono representing the horizontal distance + */ TMono p_p_horizonal(CPoint a, CPoint b) { return ppdd(a.y1.xindex, b.y1.xindex); } + /** + * Constructs a TMono representing the vertical distance between two points. + * + * @param a the first point + * @param b the second point + * @return the TMono representing the vertical distance + */ TMono p_p_vertical(CPoint a, CPoint b) { return ppdd(a.x1.xindex, b.x1.xindex); } + /** + * Constructs a TMono representing the tangent of a line and a circle. + * + * @param a the first point on the line + * @param b the second point on the line + * @param c the first point on the circle + * @param d the second point on the circle + * @param o the center of the circle + * @return the TMono representing the tangent + */ TMono l_c_tangent(CPoint a, CPoint b, CPoint c, CPoint d, CPoint o) { TMono p1, p2, p3; p1 = this.collinear(a.x1.xindex, a.y1.xindex, b.x1.xindex, b.y1.xindex, o.x1.xindex, o.y1.xindex); @@ -457,10 +861,28 @@ TMono l_c_tangent(CPoint a, CPoint b, CPoint c, CPoint d, CPoint o) { return pdif(pRtimes(p1, pcopy(p1)), pRtimes(p2, p3)); } + /** + * Constructs a TMono representing the tangent of two circles. + * + * @param a the first point on the first circle + * @param b the second point on the first circle + * @param o the center of the first circle + * @param c the first point on the second circle + * @param d the second point on the second circle + * @param o1 the center of the second circle + * @return the TMono representing the tangent + */ TMono c_c_tangent(CPoint a, CPoint b, CPoint o, CPoint c, CPoint d, CPoint o1) { return sum3(a, b, c, d, o, o1); } + /** + * Constructs a new TPoly from two TMonos. + * + * @param m1 the first TMono + * @param m2 the second TMono + * @return the new TPoly + */ TPoly newTPoly(TMono m1, TMono m2) { TPoly poly = new TPoly(); poly.setPoly(m1); @@ -471,49 +893,108 @@ TPoly newTPoly(TMono m1, TMono m2) { return poly1; } -// public boolean nde(TMono m, Vector v) -// { -// if(this.plength(m) != 2) return false; -// - - // } - ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - + /** + * Constructs a TMono representing a non-degenerate geometric condition. + * + * @param m the TMono to be checked + * @param z the index of the condition + * @return the TMono representing the non-degenerate condition + */ TMono n_ndg(TMono m, int z) { if (m == null) return null; return pdif(ptimes(pth(z, 1, 1), m), pth(0, 1, 0)); } + /** + * Constructs a TMono representing the parallel condition of two lines. + * + * @param p1 the first point on the first line + * @param p2 the second point on the first line + * @param p3 the first point on the second line + * @param p4 the second point on the second line + * @return the TMono representing the parallel condition + */ TMono parallel(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { return parallel(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex); } + /** + * Constructs a TMono representing the perpendicular condition of two lines. + * + * @param p1 the first point on the first line + * @param p2 the second point on the first line + * @param p3 the first point on the second line + * @param p4 the second point on the second line + * @return the TMono representing the perpendicular condition + */ TMono perpendicular(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { return perpendicular(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex); } + /** + * Constructs a TMono representing the equal distance condition between two pairs of points. + * + * @param p1 the first point of the first pair + * @param p2 the second point of the first pair + * @param p3 the first point of the second pair + * @param p4 the second point of the second pair + * @return the TMono representing the equal distance condition + */ TMono eqdistance(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { return eqdistance(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex); } + /** + * Constructs a TMono representing the collinear condition of three points. + * + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @return the TMono representing the collinear condition + */ TMono collinear(CPoint p1, CPoint p2, CPoint p3) { return collinear(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex); } + /** + * Constructs a TMono representing the cyclic condition of four points. + * + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @param p4 the fourth point + * @return the TMono representing the cyclic condition + */ TMono cyclic(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { return cyclic(p1.x1.xindex, p1.y1.xindex, p2.x1.xindex, p2.y1.xindex, p3.x1.xindex, p3.y1.xindex, p4.x1.xindex, p4.y1.xindex); } + /** + * Constructs a TMono representing the isotropic condition of two points. + * + * @param p1 the first point + * @param p2 the second point + * @return the TMono representing the isotropic condition + */ TMono isotropic(CPoint p1, CPoint p2) { TMono m1 = ptimes(ppdd(p1.x1.xindex, p2.x1.xindex), ppdd(p1.x1.xindex, p2.x1.xindex)); TMono m2 = ptimes(ppdd(p1.y1.xindex, p2.y1.xindex), ppdd(p1.y1.xindex, p2.y1.xindex)); return this.padd(m1, m2); } + /** + * Constructs a TMono representing the triple product invariant condition of four points. + * + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @param p4 the fourth point + * @return the TMono representing the triple product invariant condition + */ TMono triplePI(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { TMono m1 = ptimes(ppdd(p1.y1.xindex, p2.y1.xindex), ppdd(p3.y1.xindex, p4.y1.xindex)); TMono m2 = ptimes(ppdd(p1.x1.xindex, p2.x1.xindex), ppdd(p3.x1.xindex, p4.x1.xindex)); @@ -528,10 +1009,15 @@ TMono triplePI(CPoint p1, CPoint p2, CPoint p3, CPoint p4) { TMono x = ptimes(m1, m2); return ptimes(m, this.padd(n, x)); - } - //////////////////////////////////////////////////// + /** + * Constructs a TMono representing a non-degenerate geometric condition. + * + * @param c the CNdg object representing the condition + * @param dp the DrawProcess object + * @return the TMono representing the non-degenerate condition + */ public TMono mm_poly(CNdg c, DrawProcess dp) { if (c == null) return null; switch (c.type) { @@ -551,35 +1037,8 @@ public TMono mm_poly(CNdg c, DrawProcess dp) { return this.perpendicular(dp.fd_point(c.p[0]), dp.fd_point(c.p[1]), dp.fd_point(c.p[2]), dp.fd_point(c.p[3])); case Gib.NDG_TRIPLEPI: return this.triplePI(dp.fd_point(c.p[0]), dp.fd_point(c.p[1]), dp.fd_point(c.p[2]), dp.fd_point(c.p[3])); - - default: return null; } } - - public Vector ndg_gbasis(Vector v, Vector vp) { - Vector v1 = new Vector(); - if (v.size() == 0) - return v1; - - int n = v.size() + 2; - int d = -1; - for (int i = 0; i < v.size(); i++) { - TMono m = (TMono) v.get(i); - m = this.n_ndg(m, d); - v1.add(m); - d--; - } - - this.upValueTM(v1, n); - this.upValueTM(vp, n); - this.g_basis(v1); - - this.upValueTM(v1, -n); - this.upValueTM(vp, -n); - return v1; - } - - } diff --git a/src/main/java/wprover/GgbCircle.java b/src/main/java/wprover/GgbCircle.java index fe7a7c9c..f5d8c686 100644 --- a/src/main/java/wprover/GgbCircle.java +++ b/src/main/java/wprover/GgbCircle.java @@ -2,13 +2,26 @@ import java.util.Objects; +/** + * Represents a circle in GeoGebra with a name. + */ public class GgbCircle { private String name; + /** + * Constructs a new GgbCircle with the specified name. + * + * @param name the name of the circle + */ public GgbCircle(String name) { this.name = name; } + /** + * Returns the name of the circle. + * + * @return the name of the circle + */ public String getName() { return name; } diff --git a/src/main/java/wprover/GgbLine.java b/src/main/java/wprover/GgbLine.java index 6cbaccf4..a2abe1bd 100644 --- a/src/main/java/wprover/GgbLine.java +++ b/src/main/java/wprover/GgbLine.java @@ -1,30 +1,59 @@ package wprover; import java.util.Objects; - +/** + * Represents a line in GeoGebra with a name and two point names. + */ public class GgbLine { private String name; private String nameP1; private String nameP2; + /** + * Constructs a new GgbLine with the specified name and point names. + * + * @param name the name of the line + * @param nameP1 the name of the first point + * @param nameP2 the name of the second point + */ public GgbLine(String name, String nameP1, String nameP2) { this.name = name; this.nameP1 = nameP1; this.nameP2 = nameP2; } + /** + * Constructs a new GgbLine with the specified name. + * + * @param name the name of the line + */ public GgbLine(String name) { this.name=name; } + /** + * Returns the name of the line. + * + * @return the name of the line + */ public String getName() { return name; } + /** + * Returns the name of the first point. + * + * @return the name of the first point + */ public String getNameP1() { return nameP1; } + /** + * Returns the name of the second point. + * + * @return the name of the second point + */ public String getNameP2() { return nameP2; } diff --git a/src/main/java/wprover/GgbMidpoint.java b/src/main/java/wprover/GgbMidpoint.java index 0e77d011..037a0b7e 100644 --- a/src/main/java/wprover/GgbMidpoint.java +++ b/src/main/java/wprover/GgbMidpoint.java @@ -2,35 +2,71 @@ import java.util.Objects; +/** + * Represents a midpoint in GeoGebra with a label and optionally associated points or a segment. + */ public class GgbMidpoint { - private String labelMidpoint=""; + private String labelMidpoint = ""; private String labelP1; private String labelP2; private String labelSegment; - public GgbMidpoint(String labelMidpoint,String labelP1, String labelP2) { - this.labelMidpoint=labelMidpoint; - this.labelP1=labelP1; - this.labelP2=labelP2; + /** + * Constructs a new GgbMidpoint with the specified midpoint label and point labels. + * + * @param labelMidpoint the label of the midpoint + * @param labelP1 the label of the first point + * @param labelP2 the label of the second point + */ + public GgbMidpoint(String labelMidpoint, String labelP1, String labelP2) { + this.labelMidpoint = labelMidpoint; + this.labelP1 = labelP1; + this.labelP2 = labelP2; } - public GgbMidpoint(String labelMidpoint,String labelSegment) { - this.labelMidpoint=labelMidpoint; - this.labelSegment=labelSegment; + /** + * Constructs a new GgbMidpoint with the specified midpoint label and segment label. + * + * @param labelMidpoint the label of the midpoint + * @param labelSegment the label of the segment + */ + public GgbMidpoint(String labelMidpoint, String labelSegment) { + this.labelMidpoint = labelMidpoint; + this.labelSegment = labelSegment; } + /** + * Constructs a new GgbMidpoint with the specified name. + * + * @param name the name of the midpoint + */ public GgbMidpoint(String name) { - this.labelMidpoint=name; + this.labelMidpoint = name; } + /** + * Returns the name of the midpoint. + * + * @return the name of the midpoint + */ public String getName() { return labelMidpoint; } + /** + * Returns the name of the first point. + * + * @return the name of the first point + */ public String getNameP1() { return labelP1; } + /** + * Returns the name of the second point. + * + * @return the name of the second point + */ public String getNameP2() { return labelP2; } diff --git a/src/main/java/wprover/GgbPoint.java b/src/main/java/wprover/GgbPoint.java index 8f72b422..6df40d35 100644 --- a/src/main/java/wprover/GgbPoint.java +++ b/src/main/java/wprover/GgbPoint.java @@ -2,13 +2,26 @@ import java.util.Objects; +/** + * Represents a point in GeoGebra with a name. + */ public class GgbPoint { private String name; + /** + * Constructs a new GgbPoint with the specified name. + * + * @param name the name of the point + */ public GgbPoint(String name) { this.name = name; } + /** + * Returns the name of the point. + * + * @return the name of the point + */ public String getName() { return name; } diff --git a/src/main/java/wprover/GgbSegment.java b/src/main/java/wprover/GgbSegment.java index fa816a73..f0b1da10 100644 --- a/src/main/java/wprover/GgbSegment.java +++ b/src/main/java/wprover/GgbSegment.java @@ -2,25 +2,50 @@ import java.util.Objects; +/** + * Represents a segment in GeoGebra with a name and two point names. + */ public class GgbSegment { private String name; private String nameP1; private String nameP2; + /** + * Constructs a new GgbSegment with the specified name and point names. + * + * @param name the name of the segment + * @param nameP1 the name of the first point + * @param nameP2 the name of the second point + */ public GgbSegment(String name, String nameP1, String nameP2) { - this.name=name; + this.name = name; this.nameP1 = nameP1; this.nameP2 = nameP2; } + /** + * Returns the name of the segment. + * + * @return the name of the segment + */ public String getName() { return name; } + /** + * Returns the name of the first point. + * + * @return the name of the first point + */ public String getNameP1() { return nameP1; } + /** + * Returns the name of the second point. + * + * @return the name of the second point + */ public String getNameP2() { return nameP2; } diff --git a/src/main/java/wprover/HelpMode.java b/src/main/java/wprover/HelpMode.java index 8cec1b2d..ea631c00 100644 --- a/src/main/java/wprover/HelpMode.java +++ b/src/main/java/wprover/HelpMode.java @@ -3,17 +3,21 @@ import java.util.Vector; /** - * Created by IntelliJ IDEA. - * User: Administrator - * Date: 2009-1-22 - * Time: 16:59:07 - * To change this template use File | Settings | File Templates. + * The HelpMode class provides methods to manage and retrieve help items in GeoGebra. */ public class HelpMode { - + /** + * A vector to store help items. + */ public static Vector items = new Vector(); + /** + * Retrieves the help mode filename for the given command. + * + * @param comd the command to look up + * @return the filename associated with the command, or null if not found + */ public static String getHelpMode(String comd) { buildItems(); for (int i = 0; i < items.size(); i++) { @@ -24,6 +28,9 @@ public static String getHelpMode(String comd) { return null; } + /** + * Builds the list of help items if it is not already built. + */ public static void buildItems() { if (items.size() != 0) return; @@ -84,7 +91,7 @@ public static void buildItems() { addItem("Square", "polygon.html"); addItem("Pentagon", "polygon.html"); addItem("Polygon", "polygon.html"); - addItem("sangle", "special angle.html"); + addItem("sangle", "special_angle.html"); addItem("Eqangle", "constraint.html"); addItem("Eqangle3p", "constraint.html"); @@ -94,7 +101,6 @@ public static void buildItems() { addItem("Ratio Distance", "constraint.html"); addItem("CCtangent", "constraint.html"); - addItem("Trace", "trace.html"); addItem("Locus", "locus.html"); addItem("Animation", "animation.html"); @@ -121,7 +127,6 @@ public static void buildItems() { addItem("Show Step Bar", "index.html"); addItem("Style Dialog", "index.html"); - addItem("Help", "index.html"); addItem("Online Help", "index.html"); addItem("Help on Mode", "index.html"); @@ -129,24 +134,35 @@ public static void buildItems() { addItem("Contact Us", "index.html"); addItem("Check for Update", "index.html"); addItem("About JGEX", "index.html"); - - } + /** + * Adds a help item to the list. + * + * @param comd the command associated with the help item + * @param name the filename of the help item + */ public static void addItem(String comd, String name) { HelpItemAtom it = new HelpItemAtom(comd, name); items.add(it); } - - } +/** + * Represents a help item with a command and a filename. + */ class HelpItemAtom { String comd; String filename; + /** + * Constructs a new HelpItemAtom with the specified command and filename. + * + * @param s1 the command associated with the help item + * @param s2 the filename of the help item + */ public HelpItemAtom(String s1, String s2) { comd = s1; filename = s2; } -} +} \ No newline at end of file diff --git a/src/main/java/wprover/ImageTimer.java b/src/main/java/wprover/ImageTimer.java index 57aa9292..54d6a0e1 100644 --- a/src/main/java/wprover/ImageTimer.java +++ b/src/main/java/wprover/ImageTimer.java @@ -10,13 +10,8 @@ import java.awt.event.ActionListener; import java.awt.image.BufferedImage; import java.util.Vector; - /** - * Created by IntelliJ IDEA. - * User: ye - * Date: 2008-6-26 - * Time: 16:18:09 - * To change this template use File | Settings | File Templates. + * A dialog for saving a proof as a GIF file in GeoGebra. */ public class ImageTimer extends JBaseDialog implements ActionListener, ChangeListener { private GExpert gxInstance; @@ -39,10 +34,20 @@ public class ImageTimer extends JBaseDialog implements ActionListener, ChangeLis int n1 = 0; int n2 = 0; + /** + * Returns the result of the image timer process. + * + * @return true if the process was successful, false otherwise + */ public boolean getResult() { return result; } + /** + * Handles state changes for the sliders and updates the delay values. + * + * @param e the change event + */ public void stateChanged(ChangeEvent e) { int n = slider.getValue(); delay = n; @@ -51,7 +56,11 @@ public void stateChanged(ChangeEvent e) { updateValue(); } - + /** + * Constructs a new ImageTimer dialog with the specified GExpert instance. + * + * @param f the GExpert instance + */ public ImageTimer(GExpert f) { super(f.getFrame(), GExpert.getLanguage("Saving Proof as GIF File"), true); gxInstance = f; @@ -132,7 +141,11 @@ public ImageTimer(GExpert f) { } - + /** + * Sets the delay values for the sliders. + * + * @param n the delay value + */ public void setDelay(int n) { delay = n; slider.setValue(n); @@ -140,7 +153,9 @@ public void setDelay(int n) { slider2.setValue(n * 3); } - + /** + * Updates the text fields with the current slider values. + */ public void updateValue() { int n = slider.getValue() / 100; int n1 = slider1.getValue() / 100; @@ -150,18 +165,36 @@ public void updateValue() { field2.setText(Double.toString(n2 / 10.00)); } + /** + * Sets the GifEncoder instance for the image timer. + * + * @param e the GifEncoder instance + */ public void setEncorder(GifEncoder e) { this.encorder = e; } + /** + * Sets the CProveBarPanel instance for the image timer. + * + * @param bar the CProveBarPanel instance + */ public void setProveBar(CProveBarPanel bar) { this.bar = bar; } + /** + * Sets the rectangle area for capturing images. + * + * @param rc the rectangle area + */ public void setRectangle(Rectangle rc) { this.rc = rc; } + /** + * Starts the image timer and the save process. + */ public void start() { if (timer == null) timer = new Timer(delay, this); @@ -170,6 +203,9 @@ public void start() { startSave(); } + /** + * Starts the save process in a new thread. + */ public void startSave() { if (sprocess == null) { sprocess = new Thread(new SaveProcess()); @@ -182,6 +218,9 @@ public void startSave() { } } + /** + * Adds a new image to the buffer. + */ public void imageAdded() { BufferedImage i = gxInstance.getBufferedImage2(rc); if (i != null) { @@ -192,6 +231,11 @@ public void imageAdded() { } } + /** + * Handles action events for the timer and buttons. + * + * @param e the action event + */ public void actionPerformed(ActionEvent e) { Object o = e.getSource(); @@ -204,7 +248,6 @@ public void actionPerformed(ActionEvent e) { if (bar.isStepAtEnd()) { timer.stop(); finished = true; -// this.setVisible(false); result = true; } else bar.AStep(); @@ -223,7 +266,6 @@ public void actionPerformed(ActionEvent e) { timer.stop(); bar.stop(); interrupted = true; - } else { interrupted = true; this.setVisible(false); @@ -232,9 +274,11 @@ public void actionPerformed(ActionEvent e) { } } - boolean running = false; + /** + * A runnable class for saving the images in a separate thread. + */ class SaveProcess implements Runnable { public SaveProcess() { @@ -268,7 +312,5 @@ else if (finished && nimage[n1 + 1] == null) } running = false; } - - } -} +} \ No newline at end of file diff --git a/src/main/java/wprover/JAngleFlash.java b/src/main/java/wprover/JAngleFlash.java index b6e25824..9f0a792e 100644 --- a/src/main/java/wprover/JAngleFlash.java +++ b/src/main/java/wprover/JAngleFlash.java @@ -6,11 +6,8 @@ import javax.swing.*; /** - * Created by IntelliJ IDEA. - * User: yezheng - * Date: 2006-5-3 - * Time: 12:22:53 - * To change this template use File | Settings | File Templates. + * JAngleFlash is a class that extends JFlash and implements ActionListener. + * It is used to create a flashing angle effect between two lines in a JPanel. */ public class JAngleFlash extends JFlash implements ActionListener { private int radius = RAD; @@ -20,24 +17,49 @@ public class JAngleFlash extends JFlash implements ActionListener { private int value1 = 1; + /** + * Constructs a new JAngleFlash with the specified JPanel. + * + * @param p the JPanel to associate with this JAngleFlash + */ public JAngleFlash(JPanel p) { super(p); timer = new Timer(TIME_INTERVAL, this); inter = dl1 = dl2 = true; } + /** + * Sets whether the angle is formed by the intersection of two lines. + * + * @param r true if the angle is formed by intersecting lines, false otherwise + */ public void setAngleTwoLineIntersected(boolean r) { inter = r; } + /** + * Sets whether the first line should be drawn. + * + * @param r true if the first line should be drawn, false otherwise + */ public void setDrawLine1(boolean r) { dl1 = r; } + /** + * Sets whether the second line should be drawn. + * + * @param r true if the second line should be drawn, false otherwise + */ public void setDrawLine2(boolean r) { dl2 = r; } + /** + * Gets the common point between the two lines forming the angle. + * + * @return the common point if it exists, null otherwise + */ public CPoint getCommonPoint() { if (p1 == p3 || p1 == p4) { return p1; @@ -48,6 +70,15 @@ public CPoint getCommonPoint() { return null; } + /** + * Constructs a new JAngleFlash with the specified JPanel and points. + * + * @param p the JPanel to associate with this JAngleFlash + * @param p1 the first point of the first line + * @param p2 the second point of the first line + * @param p3 the first point of the second line + * @param p4 the second point of the second line + */ public JAngleFlash(JPanel p, CPoint p1, CPoint p2, CPoint p3, CPoint p4) { super(p); timer = new Timer(TIME_INTERVAL, this); @@ -58,19 +89,39 @@ public JAngleFlash(JPanel p, CPoint p1, CPoint p2, CPoint p3, CPoint p4) { dl1 = dl2 = true; } + /** + * Sets the type of the angle flash. + * + * @param t the type of the angle flash + */ public void setFtype(int t) { ftype = t; } - + /** + * Set the radius value. + * + * @param r the new radius value + */ public void setRadius(int r) { radius = r; } + /** + * Get the current radius. + * + * @return the current radius value + */ public int getRadius() { return radius; } + /** + * Handle action events. + * Decrements the counter, stops the animation if necessary, and repaints the panel. + * + * @param e the action event triggering this method + */ public void actionPerformed(ActionEvent e) { n--; if (n <= 0) { @@ -79,6 +130,13 @@ public void actionPerformed(ActionEvent e) { panel.repaint(); } + /** + * Draw the graphical elements. + * Draws either the provided lines or a modified angle based on the current state. + * + * @param g2 the graphics context used for drawing + * @return true if drawing succeeded + */ public boolean draw(Graphics2D g2) { if (n % 2 == 0) { g2.setColor(color); @@ -98,6 +156,21 @@ public boolean draw(Graphics2D g2) { return true; } + /** + * Draw a modified angle between two lines. + * Calculates the intersection point and draws arcs representing the angle. + * + * @param x1 the start x-coordinate of the first line + * @param y1 the start y-coordinate of the first line + * @param x2 the end x-coordinate of the first line + * @param y2 the end y-coordinate of the first line + * @param x3 the start x-coordinate of the second line + * @param y3 the start y-coordinate of the second line + * @param x4 the end x-coordinate of the second line + * @param y4 the end y-coordinate of the second line + * @param rad the radius used for the angle arc + * @param g2 the graphics context for drawing + */ public void drawMAngle(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, int rad, Graphics2D g2) { @@ -269,6 +342,13 @@ else if (dr1 * 10 - k < -0.5 && dr1 < 0) } + /** + * Draw all lines with proper styling. + * Draws dashed or solid lines based on the internal configuration and available points. + * + * @param g2 the graphics context used for drawing + * @return true if drawing succeeded; false if required points are missing + */ public boolean drawAllLine(Graphics2D g2) { if (p1 == null || p2 == null || p3 == null || p4 == null) { this.stop(); diff --git a/src/main/java/wprover/JAreaFlash.java b/src/main/java/wprover/JAreaFlash.java index 3d3cb25a..a888a313 100644 --- a/src/main/java/wprover/JAreaFlash.java +++ b/src/main/java/wprover/JAreaFlash.java @@ -7,58 +7,72 @@ import java.util.Vector; /** - * Created by IntelliJ IDEA. - * User: yezheng - * Date: 2006-7-24 - * Time: 16:32:16 - * To change this template use File | Settings | File Templates. + * JAreaFlash is a class that extends JFlash and implements ActionListener. + * It is used to create a flashing area effect on a JPanel. */ -public class JAreaFlash extends JFlash implements ActionListener{ +public class JAreaFlash extends JFlash implements ActionListener { private Vector vlist = new Vector(); private int color = DrawData.LIGHTCOLOR; - public JAreaFlash(JPanel p,int cindex) - { + /** + * Constructs a new JAreaFlash with the specified JPanel and color index. + * + * @param p the JPanel to associate with this JAreaFlash + * @param cindex the color index to use for the flashing area + */ + public JAreaFlash(JPanel p, int cindex) { super(p); color = DrawData.LIGHTCOLOR + cindex-1; timer = new Timer(TIME_INTERVAL, this); } - public boolean draw(Graphics2D g2) - { + + /** + * Draws the flashing area on the specified Graphics2D context. + * + * @param g2 the Graphics2D context to draw on + * @return true if the drawing was successful, false otherwise + */ + public boolean draw(Graphics2D g2) { if (n % 2 != 0) return true; int n = vlist.size(); Composite ac = g2.getComposite(); g2.setComposite(CMisc.getFillComposite()); - if(n == 0) return true; - - int []x = new int[n]; - int []y = new int[n]; - for(int i=0; i = 1) { CPoint p1 = (CPoint) vlist.get(0); double radius = Math.sqrt(Math.pow(o.getx() - p1.getx(), 2) + Math.pow(o.gety() - p1.gety(), 2)); @@ -39,7 +45,6 @@ public boolean draw(Graphics2D g2) { super.setDrawDashFb2(g2); g2.drawOval((int) (o.getx() - radius), (int) (o.gety() - radius), (int) (2 * radius), (int) (2 * radius)); } - } else if (vlist.size() >= 3) { CPoint p1 = (CPoint) vlist.get(0); CPoint p2 = (CPoint) vlist.get(1); @@ -84,7 +89,6 @@ public boolean draw(Graphics2D g2) { } } - if (n % 2 == 0) { if (o != null) o.draw(g2); @@ -96,23 +100,32 @@ public boolean draw(Graphics2D g2) { return true; } + /** + * Sets the center point of the circular flashing effect. + * + * @param t the center point to set + */ public void setCenter(CPoint t) { if (t == null) return; if (t != null) this.o = (CPoint) t; } -// public void addAPoint(CPoint pt) { -// -// if (pt != null && !vlist.contains(pt)) -// vlist.add(pt); -// } - + /** + * Adds a point to the list of points defining the circular flashing effect. + * + * @param pt the point to add + */ public void addAPoint(CPoint pt) { if (pt != null && !vlist.contains(pt)) vlist.add(pt); } + /** + * Handles action events for the timer. + * + * @param e the action event + */ public void actionPerformed(ActionEvent e) { n--; if (n <= 0) super.stop(); @@ -128,6 +141,9 @@ public void actionPerformed(ActionEvent e) { panel.repaint(); } + /** + * Stops the circular flashing effect. + */ public void stop() { super.stop(); for (int i = 0; i < vlist.size(); i++) { diff --git a/src/main/java/wprover/JExPanel.java b/src/main/java/wprover/JExPanel.java index 2429acbc..e4e0e59a 100644 --- a/src/main/java/wprover/JExPanel.java +++ b/src/main/java/wprover/JExPanel.java @@ -5,166 +5,223 @@ import java.awt.*; import java.net.URL; - -class JExPanel extends JPanel implements ActionListener, MouseListener, MouseMotionListener, ComponentListener -{ - DrawProcess dp; - static ImageIcon icoa; - static ImageIcon icos; - JToggleButton button; - Timer timer = null; - - public void paint(Graphics g) - { - super.paint(g); - if(dp != null) - dp.paintPoint(g); - } - public JExPanel() - { - super(); - this.setLayout(null); - this.addMouseListener(this); - this.addMouseMotionListener(this); - this.addComponentListener(this); - this.setBackground(new Color(228, 236, 252)); - URL imageURL = GExpert.class.getResource("images/animate_start.gif"); - ImageIcon image = new ImageIcon(imageURL); - URL imageURL1 = GExpert.class.getResource("images/animate_stop.gif"); - ImageIcon image1 = new ImageIcon(imageURL1); - - button = new JToggleButton(image) - { - public Dimension getPreferredSize() - { - return new Dimension(30, 28); - } - }; - this.add(button); - button.addActionListener(this); - Dimension dm = this.getSize(); - button.setBounds(new Rectangle(0, (int) dm.getHeight() - 28, 32, 28)); - //JExPanel.setAinimateIcon(image, image1); - button.setSelectedIcon(image1); - } - - public static void setAinimateIcon(ImageIcon ico1, ImageIcon ico2) - { - icoa = ico1; - icos = ico2; - } - - public Dimension getPreferredSize() - { - return new Dimension(600, 400); - } - - public void setdrawP(DrawProcess dp) - { - this.dp = dp; - if (timer != null) timer.stop(); - if (dp.animate != null) - { - AnimateC ant = dp.animate; - if (timer == null) - timer = new Timer(ant.getInitValue(), this); - else - timer.setDelay(ant.getInitValue()); - timer.start(); - button.setIcon(icos); - button.setVisible(true); - } else - button.setVisible(false); - - } - - public void actionPerformed(ActionEvent e) - { - if (e.getSource() == button) - { - if (!timer.isRunning()) - { - dp.animationStart(); - button.setIcon(icos); - timer.start(); - } else - { - dp.animationStop(); - button.setIcon(icoa); - timer.stop(); - } - } else if (e.getSource() == timer) - { - dp.animationOntime(); - this.repaint(); +/** + * JExPanel is a custom JPanel that provides a drawing area with animation capabilities. + * It allows for mouse interactions and supports animation through a timer. + */ +class JExPanel extends JPanel implements ActionListener, MouseListener, MouseMotionListener, ComponentListener { + DrawProcess dp; + static ImageIcon icoa; + static ImageIcon icos; + JToggleButton button; + Timer timer = null; + + /** + * Paints the component. This method is called whenever the component needs to be repainted. + * + * @param g the Graphics context in which to paint + */ + public void paint(Graphics g) { + super.paint(g); + if (dp != null) + dp.paintPoint(g); + } + + /** + * Constructs a new JExPanel. Initializes the panel with a null layout, adds mouse listeners, + * sets the background color, and initializes the toggle button for animation control. + */ + public JExPanel() { + super(); + this.setLayout(null); + this.addMouseListener(this); + this.addMouseMotionListener(this); + this.addComponentListener(this); + this.setBackground(new Color(228, 236, 252)); + URL imageURL = GExpert.class.getResource("images/animate_start.gif"); + ImageIcon image = new ImageIcon(imageURL); + URL imageURL1 = GExpert.class.getResource("images/animate_stop.gif"); + ImageIcon image1 = new ImageIcon(imageURL1); + + button = new JToggleButton(image) { + /** + * Returns the preferred size of the button. + * + * @return the preferred size of the button + */ + public Dimension getPreferredSize() { + return new Dimension(30, 28); } - } - - public void mouseClicked(MouseEvent e) - { - if (e.getClickCount() > 1) - dp.DWMouseDbClick(e.getX(), e.getY()); - if (e.getButton() == MouseEvent.BUTTON3) - dp.DWMouseRightClick(e.getX(), e.getY()); - } - - public void mousePressed(MouseEvent e) - { - dp.DWButtonDown(e.getX(), e.getY()); - repaint(); - } - - public void mouseReleased(MouseEvent e) - { - dp.DWButtonUp(e.getX(), e.getY()); - repaint(); - } - - public void mouseEntered(MouseEvent e) - { - } - - public void mouseExited(MouseEvent e) - { - } - - public void mouseDragged(MouseEvent e) - { - dp.DWMouseDrag(e.getX(), e.getY()); - this.repaint(); - } - - public void mouseMoved(MouseEvent e) - { - dp.DWMouseMove(e.getX(), e.getY()); + }; + this.add(button); + button.addActionListener(this); + Dimension dm = this.getSize(); + button.setBounds(new Rectangle(0, (int) dm.getHeight() - 28, 32, 28)); + button.setSelectedIcon(image1); + } + + /** + * Returns the preferred size of the panel. + * + * @return the preferred size of the panel + */ + public Dimension getPreferredSize() { + return new Dimension(600, 400); + } + + /** + * Sets the DrawProcess for this panel and starts the animation if available. + * + * @param dp the DrawProcess to set + */ + public void setdrawP(DrawProcess dp) { + this.dp = dp; + if (timer != null) timer.stop(); + if (dp.animate != null) { + AnimateC ant = dp.animate; + if (timer == null) + timer = new Timer(ant.getInitValue(), this); + else + timer.setDelay(ant.getInitValue()); + timer.start(); + button.setIcon(icos); + button.setVisible(true); + } else + button.setVisible(false); + } + + /** + * Handles action events for the button and timer. + * + * @param e the action event + */ + public void actionPerformed(ActionEvent e) { + if (e.getSource() == button) { + if (!timer.isRunning()) { + dp.animationStart(); + button.setIcon(icos); + timer.start(); + } else { + dp.animationStop(); + button.setIcon(icoa); + timer.stop(); + } + } else if (e.getSource() == timer) { + dp.animationOntime(); this.repaint(); - } - - public void paintComponent(Graphics g) - { - super.paintComponent(g); - dp.paintPoint(g); - - - } - - public void componentResized(ComponentEvent e) - { - Dimension dm = this.getSize(); - button.setBounds(new Rectangle(0, (int) dm.getHeight() - 28, 32, 28)); - } - - public void componentMoved(ComponentEvent e) - { - } - - public void componentShown(ComponentEvent e) - { - } - - public void componentHidden(ComponentEvent e) - { - timer.stop(); - } - + } + } + + /** + * Handles mouse click events. + * + * @param e the mouse event + */ + public void mouseClicked(MouseEvent e) { + if (e.getClickCount() > 1) + dp.DWMouseDbClick(e.getX(), e.getY()); + if (e.getButton() == MouseEvent.BUTTON3) + dp.DWMouseRightClick(e.getX(), e.getY()); + } + + /** + * Handles mouse press events. + * + * @param e the mouse event + */ + public void mousePressed(MouseEvent e) { + dp.DWButtonDown(e.getX(), e.getY()); + repaint(); + } + + /** + * Handles mouse release events. + * + * @param e the mouse event + */ + public void mouseReleased(MouseEvent e) { + dp.DWButtonUp(e.getX(), e.getY()); + repaint(); + } + + /** + * Handles mouse enter events. + * + * @param e the mouse event + */ + public void mouseEntered(MouseEvent e) { + } + + /** + * Handles mouse exit events. + * + * @param e the mouse event + */ + public void mouseExited(MouseEvent e) { + } + + /** + * Handles mouse drag events. + * + * @param e the mouse event + */ + public void mouseDragged(MouseEvent e) { + dp.DWMouseDrag(e.getX(), e.getY()); + this.repaint(); + } + + /** + * Handles mouse move events. + * + * @param e the mouse event + */ + public void mouseMoved(MouseEvent e) { + dp.DWMouseMove(e.getX(), e.getY()); + this.repaint(); + } + + /** + * Paints the component. This method is called whenever the component needs to be repainted. + * + * @param g the Graphics context in which to paint + */ + public void paintComponent(Graphics g) { + super.paintComponent(g); + dp.paintPoint(g); + } + + /** + * Handles component resize events. + * + * @param e the component event + */ + public void componentResized(ComponentEvent e) { + Dimension dm = this.getSize(); + button.setBounds(new Rectangle(0, (int) dm.getHeight() - 28, 32, 28)); + } + + /** + * Handles component move events. + * + * @param e the component event + */ + public void componentMoved(ComponentEvent e) { + } + + /** + * Handles component show events. + * + * @param e the component event + */ + public void componentShown(ComponentEvent e) { + } + + /** + * Handles component hide events. + * + * @param e the component event + */ + public void componentHidden(ComponentEvent e) { + timer.stop(); + } } diff --git a/src/main/java/wprover/JFileFilter.java b/src/main/java/wprover/JFileFilter.java index e7ce5907..828af288 100644 --- a/src/main/java/wprover/JFileFilter.java +++ b/src/main/java/wprover/JFileFilter.java @@ -1,37 +1,44 @@ package wprover; -//import java.io.FileFilter; - import javax.swing.filechooser.FileFilter; import java.io.File; /** - * Created by IntelliJ IDEA. - * User: ye - * Date: 2008-4-10 - * Time: 16:10:45 - * To change this template use File | Settings | File Templates. + * A file filter for use with JFileChooser that filters files based on a specified suffix. */ public class JFileFilter extends FileFilter { + /** + * The suffix to filter files by. + */ String endfix; - int dep = 0; -// public JFileFilter(String[] s) { -// if (s != null) { -// endfix = new String[s.length]; -// for (int i = 0; i < s.length; i++) -// endfix[i] = s[i]; -// } -// } + /** + * An additional integer field, not used in this implementation. + */ + int dep = 0; + /** + * The uppercase version of the suffix to filter files by. + */ private String endfix1; + /** + * Constructs a new JFileFilter with the specified suffix. + * + * @param s the suffix to filter files by + */ public JFileFilter(String s) { if (s == null || s.length() == 0) return; endfix = s; endfix1 = endfix.toUpperCase(); } + /** + * Determines whether the specified file should be accepted by this filter. + * + * @param f the file to test + * @return true if the file is a directory or ends with the specified suffix, false otherwise + */ public boolean accept(File f) { if (f.isDirectory()) return true; @@ -40,8 +47,12 @@ public boolean accept(File f) { return s.endsWith(endfix) || s.endsWith(endfix1); } + /** + * Returns the description of this filter. + * + * @return the suffix used by this filter + */ public String getDescription() { return endfix; } - -} +} \ No newline at end of file diff --git a/src/main/java/wprover/JFlash.java b/src/main/java/wprover/JFlash.java index 02eb7a54..e79710a4 100644 --- a/src/main/java/wprover/JFlash.java +++ b/src/main/java/wprover/JFlash.java @@ -6,13 +6,10 @@ import javax.swing.Timer; /** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2006-4-5 - * Time: 13:33:53 - * To change this template use File | Settings | File Templates. + * JFlash is an abstract class that provides methods for creating and managing + * graphical flash effects in a JPanel. It includes methods for drawing angles, + * setting colors, and managing timers. */ - public abstract class JFlash { protected Timer timer; @@ -43,52 +40,77 @@ public abstract class JFlash { protected int TIME_INTERVAL = CMisc.getFlashInterval(); + /** + * Updates the timer delay to the flash interval defined in CMisc. + */ public void updateTimer() { if (timer != null) timer.setDelay(CMisc.getFlashInterval()); } - public void setFlashFb(boolean f) { - fb = f; - } - + /** + * Sets the delay for the timer. + * + * @param n the delay in milliseconds + */ public void setDealy(int n) { if (timer != null) timer.setDelay(n); } - public boolean getFlashFb() { - return fb; - } - + /** + * Constructs a new JFlash with the specified JPanel. + * + * @param p the JPanel to associate with this JFlash + */ public JFlash(JPanel p) { panel = p; } - public void setvisibleType(boolean t) { - vType = t; - } - + /** + * Gets the visibility type of the flash. + * + * @return true if the flash is visible, false otherwise + */ public boolean getvisibleType() { return vType; } + /** + * Sets the color of the flash. + * + * @param c the color to set + */ public void setColor(Color c) { color = c; } + /** + * Gets the color of the flash. + * + * @return the color of the flash + */ public Color getColor() { return color; } + /** + * Draws the flash effect on the specified Graphics2D context. + * + * @param g2 the Graphics2D context to draw on + * @return true if the drawing was successful, false otherwise + */ public abstract boolean draw(Graphics2D g2); + /** + * Recalculates the flash effect. This method is intended to be overridden by subclasses. + */ public void recalculate() { } - public void createTimer(int n) { - } - + /** + * Starts the flash effect. + */ public void start() { if (timer != null) { finished = false; @@ -97,6 +119,9 @@ public void start() { } } + /** + * Stops the flash effect. + */ public void stop() { if (timer != null) { timer.stop(); @@ -104,28 +129,39 @@ public void stop() { } } + /** + * Checks if the flash effect is finished. + * + * @return true if the flash effect is finished, false otherwise + */ public boolean isfinished() { return this.finished; } + /** + * Checks if the timer is running. + * + * @return true if the timer is running, false otherwise + */ public boolean isrRunning() { return timer.isRunning(); } + /** + * Sets the drawing stroke to a dashed line with a red color. + * + * @param g2 the Graphics2D context to set the stroke on + */ final public void setDrawDash(Graphics2D g2) { g2.setColor(Color.red); g2.setStroke(DASH1); } - final public void setDrawDashFb(Graphics2D g2) { - if (fb) { - g2.setStroke(BStroke); - } else { - g2.setStroke(Dash); - } - g2.setColor(Color.red); - } - + /** + * Sets the drawing stroke to either a bold or dashed line with a red color based on the fb flag. + * + * @param g2 the Graphics2D context to set the stroke on + */ final public void setDrawDashFb2(Graphics2D g2) { if (fb) { g2.setStroke(BStroke2); @@ -135,10 +171,29 @@ final public void setDrawDashFb2(Graphics2D g2) { g2.setColor(Color.red); } + /** + * Checks if the given value is approximately zero. + * + * @param d the value to check + * @return true if the value is approximately zero, false otherwise + */ final public boolean isZero(double d) { return Math.abs(d) < ZERO; } + /** + * Calculates the intersection point of two lines defined by their endpoints. + * + * @param x1 the x-coordinate of the first point of the first line + * @param y1 the y-coordinate of the first point of the first line + * @param x2 the x-coordinate of the second point of the first line + * @param y2 the y-coordinate of the second point of the first line + * @param x3 the x-coordinate of the first point of the second line + * @param y3 the y-coordinate of the first point of the second line + * @param x4 the x-coordinate of the second point of the second line + * @param y4 the y-coordinate of the second point of the second line + * @return an array containing the x and y coordinates of the intersection point, or null if the lines are parallel + */ final static double[] interect_LL(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) { @@ -170,168 +225,29 @@ final static double[] interect_LL(double x1, double y1, double x2, return result; } - final public static void drawAngle(double x1, double y1, double x2, double y2, - double x3, double y3, double x4, double y4, - int rad, Graphics2D g2) { - double r[] = interect_LL(x1, y1, x2, y2, x3, y3, x4, y4); - if (r == null) { - return; - } - if (Math.abs(r[0]) > 10000 || Math.abs(r[1]) > 10000) { - return; - } - int radius = rad; - double psx, psy; - double pex, pey; - psx = psy = pex = pey = 0; - if (spt(x1, y1, r[0], r[1])) { - psx = x2; - psy = y2; - - } else { - psx = x1; - psy = y1; - } - - if (spt(x3, y3, r[0], r[1])) { - pex = x4; - pey = y4; - - } else { - pex = x3; - pey = y3; - } - - double dx1 = psx - r[0]; - double dy1 = psy - r[1]; - dy1 = (-1) * dy1; - - double k1 = dy1 / dx1; - double r1 = Math.atan(k1); - if (dx1 < 0) { - r1 += Math.PI; - } - - double t = Math.sqrt(dx1 * dx1 + dy1 * dy1); - dx1 = dx1 / t; - dy1 = dy1 / t; - - double dx2 = pex - r[0]; - double dy2 = pey - r[1]; - - dy2 = (-1) * dy2; - double k2 = dy2 / dx2; - double r2 = Math.atan(k2); - - if (dx2 < 0) { - r2 += Math.PI; - } - - t = Math.sqrt(dx2 * dx2 + dy2 * dy2); - dx2 = dx2 / t; - dy2 = dy2 / t; - - double jx = dx2 * radius + r[0]; - double jy = (-1) * dy2 * radius + r[1]; - - int ri1 = (int) (180 * r1 / Math.PI); - double dr = (180 * (r2 - r1) / Math.PI); - double tr = dr; - - - if (dr > 180) { - dr = dr - 360; - } else if (dr < -180) { - dr = dr + 360; - } - - - double rc = dr * Math.PI / (360); - double cx = (dx1 * Math.cos(rc) - dy1 * Math.sin(rc)) * (radius + 6) + r[0]; - double cy = -(dy1 * Math.cos(rc) + dx1 * Math.sin(rc)) * (radius + 6) + r[1]; - - - double dr1 = dr; - double k = dr1; - k = Math.abs(k); - - if (CMisc.ANGLE_TYPE == 1) { - - double lr = 12.0; - - double alpha = -Math.PI / 3; - if (dr > 0) { - alpha = -alpha; - dr = (dr - 180 * Math.cos(Math.PI / 2.0 - alpha) * lr * 1 / - (3 * Math.PI * radius)); - if (dr < 0) { - dr = 0; - } - } else { - dr = (dr + 180 * Math.cos(Math.PI / 2.0 + alpha) * lr * 1 / - (3 * Math.PI * radius)); - if (dr > 0) { - dr = 0; - } - } - dy2 = -dy2; - - double c1 = Math.cos(alpha); - double s1 = Math.sin(alpha); - double c2 = Math.cos(Math.PI - alpha); - double s2 = Math.sin(Math.PI - alpha); - - double jx1 = (dx2 * c1 - dy2 * s1) * lr + jx; - double jy1 = (dy2 * c1 + dx2 * s1) * lr + jy; - double jx2 = (dx2 * c2 - dy2 * s2) * lr + jx; - double jy2 = (dy2 * c2 + dx2 * s2) * lr + jy; - - if (dr >= 0) { - dr += 1.5; - } else { - dr -= 1.5; - } - - int[] xp = new int[4]; - int[] yp = new int[4]; - xp[0] = (int) jx; - xp[1] = (int) jx1; - xp[2] = (int) (jx1 / 3 + jx2 / 3 + jx / 3); - xp[3] = (int) jx2; - yp[0] = (int) jy; - yp[1] = (int) jy1; - yp[2] = (int) (jy1 / 3 + jy2 / 3 + jy / 3); - yp[3] = (int) jy2; - g2.fillPolygon(xp, yp, 4); - } - - g2.drawArc((int) r[0] - radius, (int) r[1] - radius, radius * 2, radius * 2, ri1, (int) dr); - g2.setColor(Color.black); - g2.setFont(CMisc.font); - if (CMisc.show_angle_text) { - if (k > 0) { - k = k * 100 + 50; - } else { - k = k * 100 - 50; - } - g2.drawString(((int) ((k) / 100)) + "", (int) cx, (int) cy); - } - - } - - public static void drawAngle(CPoint p1, CPoint p2, CPoint p3, CPoint p4, - int rad, Graphics2D g2) { - if (p1 != null && p2 != null && p3 != null && p4 != null) { - drawAngle(p1.getx(), p1.gety(), p2.getx(), p2.gety(), p3.getx(), - p3.gety(), p4.getx(), p4.gety(), rad, g2); - } - } - + /** + * Checks if the distance between two points is less than a small threshold. + * + * @param x0 the x-coordinate of the first point + * @param y0 the y-coordinate of the first point + * @param x the x-coordinate of the second point + * @param y the y-coordinate of the second point + * @return true if the distance between the points is less than the threshold, false otherwise + */ static boolean spt(double x0, double y0, double x, double y) { return Math.pow(x0 - x, 2) + Math.pow(y0 - y, 2) < CMisc.ZERO * CMisc.ZERO; } + /** + * Draws a line segment between a point and the closer of two other points. + * + * @param p1 the first point + * @param p2 the second point + * @param x the x-coordinate of the third point + * @param y the y-coordinate of the third point + * @param g2 the Graphics2D context to draw on + */ static public void drawALine3Short(CPoint p1, CPoint p2, double x, double y, Graphics2D g2) { @@ -349,6 +265,16 @@ static public void drawALine3Short(CPoint p1, CPoint p2, double x, double y, } + /** + * Draws a line segment between a point and the closer of two other points, with optional line drawing. + * + * @param p1 the first point + * @param p2 the second point + * @param x the x-coordinate of the third point + * @param y the y-coordinate of the third point + * @param ln whether to draw the line segment between p1 and p2 + * @param g2 the Graphics2D context to draw on + */ static public void drawALine3(CPoint p1, CPoint p2, double x, double y, boolean ln, Graphics2D g2) { if (Math.abs(x) > 10000 || Math.abs(y) > 10000) { @@ -397,15 +323,14 @@ static public void drawALine3(CPoint p1, CPoint p2, double x, double y, } } - static double getcircleDr(double x1, double y1) { - double k = y1 / x1; - double r = Math.atan(k); - if (x1 < 0) { - r += Math.PI; - } - return r; - } - + /** + * Gets a color that is a blend of two colors based on a ratio. + * + * @param c1 the first color index + * @param c2 the second color index + * @param ra the ratio for blending the colors + * @return the blended color + */ protected static Color getRatioColor(int c1, int c2, double ra) { Color o1 = DrawData.getColor(c1); Color o2 = DrawData.getColor(c2); diff --git a/src/main/java/wprover/JLine.java b/src/main/java/wprover/JLine.java index a9201e9a..d79a7462 100644 --- a/src/main/java/wprover/JLine.java +++ b/src/main/java/wprover/JLine.java @@ -4,34 +4,55 @@ import java.util.Vector; /** - * Created by IntelliJ IDEA. - * User: yezheng - * Date: 2006-5-3 - * Time: 12:35:47 - * To change this template use File | Settings | File Templates. + * JLine class represents a line in a graphical context. + * It allows adding points, drawing the line, and setting properties like infinite drawing. */ public class JLine { private boolean ext = false; Vector vlist = new Vector(); + /** + * Constructs a new JLine. + */ public JLine() { } + /** + * Sets whether the line should be drawn infinitely. + * + * @param inf true to draw the line infinitely, false otherwise + */ public void setDrawInfinite(boolean inf) { ext = inf; } + /** + * Adds a point to the list of points defining the line. + * + * @param p the point to add + */ public void addAPoint(CPoint p) { if (p != null && !vlist.contains(p)) { vlist.add(p); } } + /** + * Draws the line on the specified Graphics2D context. + * + * @param g2 the Graphics2D context to draw on + * @return true if the drawing was successful, false otherwise + */ public boolean draw(Graphics2D g2) { return true; } + /** + * Draws the line between the maximum and minimum points on the specified Graphics2D context. + * + * @param g2 the Graphics2D context to draw on + */ public void drawLine(Graphics2D g2) { CPoint[] pl = getMaxMinPoint(); if (pl != null) { @@ -39,13 +60,11 @@ public void drawLine(Graphics2D g2) { g2.drawLine((int) pl[0].getx(), (int) pl[0].gety(), (int) pl[1].getx(), (int) pl[1].gety()); } else { - if (Math.abs(pl[0].getx() - pl[1].getx()) < CMisc.ZERO) { double x = pl[0].getx(); double y1 = 0; double y2 = 2000; g2.drawLine((int) x, (int) y1, (int) x, (int) y2); - } else { double k = (pl[1].gety() - pl[0].gety()) / (pl[1].getx() - pl[0].getx()); @@ -55,14 +74,16 @@ public void drawLine(Graphics2D g2) { double y2 = k * (x2 - pl[0].getx()) + pl[0].gety(); g2.drawLine((int) x1, (int) y1, (int) x2, (int) y2); } - } } -// drawPt(g2); - + // drawPt(g2); } - + /** + * Draws the points defining the line on the specified Graphics2D context. + * + * @param g2 the Graphics2D context to draw on + */ public void drawPt(Graphics2D g2) { for (int i = 0; i < vlist.size(); i++) { CPoint pt = (CPoint) vlist.get(i); @@ -73,9 +94,13 @@ public void drawPt(Graphics2D g2) { } } + /** + * Fills the points defining the line with white color on the specified Graphics2D context. + * + * @param g2 the Graphics2D context to draw on + */ public void fillPt(Graphics2D g2) { g2.setColor(Color.white); - for (int i = 0; i < vlist.size(); i++) { CPoint pt = (CPoint) vlist.get(i); int x = (int) pt.getx(); @@ -83,9 +108,13 @@ public void fillPt(Graphics2D g2) { int r = pt.getRadius(); g2.fillOval(x - r - 1, y - r - 1, 2 * r + 1, 2 * r + 1); } - } + /** + * Sets the flashing mode for all points defining the line. + * + * @param t true to enable flashing mode, false to disable + */ public void setInFlashMode(boolean t) { for (int i = 0; i < vlist.size(); i++) { CPoint pt = (CPoint) vlist.get(i); @@ -93,10 +122,21 @@ public void setInFlashMode(boolean t) { } } + /** + * Checks if the specified point is contained in the list of points defining the line. + * + * @param pt the point to check + * @return true if the point is contained in the list, false otherwise + */ public boolean containPt(CPoint pt) { return vlist.contains(pt); } + /** + * Gets the maximum and minimum points defining the line. + * + * @return an array containing the maximum and minimum points, or null if there are less than two points + */ public CPoint[] getMaxMinPoint() { if (vlist.size() < 2) { return null; @@ -111,7 +151,6 @@ public CPoint[] getMaxMinPoint() { p2 = null; for (int i = 1; i < vlist.size(); i++) { CPoint p = (CPoint) vlist.get(i); - if (p.getx() < p1.getx()) { if (p2 == null) { p2 = p1; @@ -140,7 +179,6 @@ public CPoint[] getMaxMinPoint() { p2 = p; } } - } CPoint[] pl = new CPoint[2]; diff --git a/src/main/java/wprover/JLineFlash.java b/src/main/java/wprover/JLineFlash.java index 5ae2343f..9f3c4944 100644 --- a/src/main/java/wprover/JLineFlash.java +++ b/src/main/java/wprover/JLineFlash.java @@ -9,34 +9,62 @@ import javax.swing.Timer; +/** + * A class that represents a flashing line effect. + */ public class JLineFlash extends JFlash implements ActionListener { + /** + * A list of lines to be flashed. + */ private Vector vlist = new Vector(); + + /** + * A flag indicating whether to alternate the flashing effect. + */ private boolean alter = false; + + /** + * An index used for alternating the flashing effect. + */ private int an = 0; + /** + * Constructs a new JLineFlash with the specified JPanel. + * + * @param p the JPanel to associate with this JLineFlash + */ public JLineFlash(JPanel p) { super(p); timer = new Timer(TIME_INTERVAL, this); } - public JLineFlash(JPanel p, CPoint p1, CPoint p2) { - super(p); - vlist.add(p1); - vlist.add(p2); - timer = new Timer(TIME_INTERVAL, this); - } - + /** + * Adds a new line to the list of lines to be flashed. + * + * @return the index of the newly added line + */ public int addALine() { JLine ln = new JLine(); vlist.add(ln); return vlist.size() - 1; } + /** + * Sets a line to be drawn infinitely. + * + * @param n the index of the line to set as infinite + */ public void setInfinitLine(int n) { JLine ln = (JLine) vlist.get(n); ln.setDrawInfinite(true); } + /** + * Adds a point to a line at the specified index. + * + * @param index the index of the line to add the point to + * @param p the point to add + */ public void addAPoint(int index, CPoint p) { JLine ln = (JLine) vlist.get(index); @@ -45,6 +73,11 @@ public void addAPoint(int index, CPoint p) { } } + /** + * Sets the alternate flashing mode. + * + * @param a true to enable alternate flashing mode, false otherwise + */ public void setAlternate(boolean a) { if (a) { alter = true; @@ -52,14 +85,16 @@ public void setAlternate(boolean a) { } } + /** + * Draws the flashing lines on the specified Graphics2D context. + * + * @param g2 the Graphics2D context to draw on + * @return true if the drawing was successful, false otherwise + */ public boolean draw(Graphics2D g2) { - int cindex = DrawData.RED; - if (alter == false && n % 2 == 0) { - - g2.setColor(color); g2.setStroke(BStroke2); for (int i = 0; i < vlist.size(); i++) { @@ -73,7 +108,6 @@ public boolean draw(Graphics2D g2) { g2.setColor(color); ln.drawPt(g2); } - } else if (alter) { g2.setColor(color); g2.setStroke(BStroke2); @@ -86,6 +120,11 @@ public boolean draw(Graphics2D g2) { return true; } + /** + * Handles action events for the timer. + * + * @param e the action event + */ public void actionPerformed(ActionEvent e) { n--; @@ -122,6 +161,9 @@ public void actionPerformed(ActionEvent e) { panel.repaint(); } + /** + * Stops the flashing effect. + */ public void stop() { super.stop(); for (int i = 0; i < vlist.size(); i++) { @@ -129,5 +171,4 @@ public void stop() { ln.setInFlashMode(false); } } - } diff --git a/src/main/java/wprover/JObjectFlash.java b/src/main/java/wprover/JObjectFlash.java index 640a49dc..6a557f92 100644 --- a/src/main/java/wprover/JObjectFlash.java +++ b/src/main/java/wprover/JObjectFlash.java @@ -7,11 +7,7 @@ import java.util.Vector; /** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2005-8-11 - * Time: 13:28:05 - * To change this template use File | Settings | File Templates. + * A class that represents a flashing effect for graphical objects. */ public class JObjectFlash extends JFlash implements ActionListener { private static int TIMERS = 130; @@ -19,6 +15,11 @@ public class JObjectFlash extends JFlash implements ActionListener { private Vector vlist; private int count = 0; + /** + * Constructs a new JObjectFlash with the specified JPanel. + * + * @param p the JPanel to associate with this JObjectFlash + */ public JObjectFlash(JPanel p) { super(p); panel = p; @@ -27,10 +28,21 @@ public JObjectFlash(JPanel p) { vType = true; } + /** + * Draws the flashing objects on the specified Graphics2D context. + * + * @param g2 the Graphics2D context to draw on + * @return true if the drawing was successful, false otherwise + */ public boolean draw(Graphics2D g2) { return true; } + /** + * Handles action events for the timer. + * + * @param e the action event + */ public void actionPerformed(ActionEvent e) { if (count % 2 == 0) setListInFlashing(vlist, false); @@ -41,9 +53,14 @@ public void actionPerformed(ActionEvent e) { count++; if (count == MAXFLASHTIMES) this.stop(); - } + /** + * Sets the flashing mode for all objects in the list. + * + * @param v the list of objects + * @param inflash true to enable flashing mode, false to disable + */ private void setListInFlashing(Vector v, boolean inflash) { for (int i = 0; i < v.size(); i++) { CClass cc = (CClass) v.get(i); @@ -51,14 +68,24 @@ private void setListInFlashing(Vector v, boolean inflash) { } } + /** + * Stops the flashing effect for all objects in the list. + * + * @param v the list of objects + */ private void stopListFlash(Vector v) { for (int i = 0; i < v.size(); i++) { CClass cc = (CClass) v.get(i); cc.stopFlash(); } - } + /** + * Sets the panel and list of objects to be flashed. + * + * @param p the JPanel to associate with this JObjectFlash + * @param list the list of objects to be flashed + */ public void setAt(JPanel p, Vector list) { panel = p; stopListFlash(vlist); @@ -70,11 +97,19 @@ public void setAt(JPanel p, Vector list) { } } + /** + * Adds an object to the list of objects to be flashed. + * + * @param obj the object to add + */ public void addFlashObject(CClass obj) { if (obj != null && !vlist.contains(obj) && obj.visible()) vlist.add(obj); } + /** + * Starts the flashing effect. + */ public void start() { if (vlist.size() == 0) { stop(); @@ -86,8 +121,11 @@ public void start() { super.start(); } + /** + * Stops the flashing effect. + */ public void stop() { stopListFlash(vlist); super.stop(); } -} +} \ No newline at end of file diff --git a/src/main/java/wprover/JPointEnlargeFlash.java b/src/main/java/wprover/JPointEnlargeFlash.java index c3ba314e..e6bbf7c7 100644 --- a/src/main/java/wprover/JPointEnlargeFlash.java +++ b/src/main/java/wprover/JPointEnlargeFlash.java @@ -6,11 +6,8 @@ import java.awt.event.ActionEvent; /** - * Created by IntelliJ IDEA. - * User: ye - * Date: 2008-1-11 - * Time: 23:41:44 - * To change this template use File | Settings | File Templates. + * JPointEnlargeFlash is a class that extends JFlash and implements ActionListener. + * It is used to create a flashing effect on a point in a JPanel. */ public class JPointEnlargeFlash extends JFlash implements ActionListener { @@ -21,6 +18,12 @@ public class JPointEnlargeFlash extends JFlash implements ActionListener { // private int mradius = 0; + /** + * Constructs a new JPointEnlargeFlash with the specified JPanel and CPoint. + * + * @param p the JPanel to associate with this JPointEnlargeFlash + * @param pt the CPoint to apply the flashing effect on + */ public JPointEnlargeFlash(JPanel p, CPoint pt) { super(p); this.pt = pt; @@ -28,10 +31,21 @@ public JPointEnlargeFlash(JPanel p, CPoint pt) { nnn = pt.m_radius; } + /** + * Draws the flashing effect on the specified Graphics2D context. + * + * @param g2 the Graphics2D context to draw on + * @return true if the drawing was successful, false otherwise + */ public boolean draw(Graphics2D g2) { return true; } + /** + * Handles action events for the timer. + * + * @param e the action event + */ public void actionPerformed(ActionEvent e) { n--; if (n <= 0) stop(); @@ -42,9 +56,11 @@ public void actionPerformed(ActionEvent e) { } panel.repaint(); - } + /** + * Stops the flashing effect and resets the point's radius. + */ public void stop() { pt.m_radius = (nnn); super.stop(); diff --git a/src/main/java/wprover/JPolygonFlash.java b/src/main/java/wprover/JPolygonFlash.java index 39cf590d..4fa78b3d 100644 --- a/src/main/java/wprover/JPolygonFlash.java +++ b/src/main/java/wprover/JPolygonFlash.java @@ -7,11 +7,8 @@ import java.util.Vector; /** - * Created by IntelliJ IDEA. - * User: ye - * Date: Mar 19, 2007 - * Time: 12:40:56 AM - * To change this template use File | Settings | File Templates. + * JPolygonFlash is a class that extends JFlash and implements ActionListener. + * It is used to create a flashing polygon effect on a JPanel. */ public class JPolygonFlash extends JFlash implements ActionListener { private int c1, c2; @@ -25,7 +22,20 @@ public class JPolygonFlash extends JFlash implements ActionListener { private boolean R_Center = false; private double xc, yc; - public JPolygonFlash(JPanel p, CPolygon poly1, CPolygon poly2, boolean oc, double xc, double yc, int c1, int c2, int tt) { // A B C D ....A + /** + * Constructs a new JPolygonFlash with the specified parameters. + * + * @param p the JPanel to associate with this JPolygonFlash + * @param poly1 the first CPolygon to be used in the flashing effect + * @param poly2 the second CPolygon to be used in the flashing effect + * @param oc a boolean indicating whether to use the specified center coordinates + * @param xc the x-coordinate of the center + * @param yc the y-coordinate of the center + * @param c1 the first color index for the flashing effect + * @param c2 the second color index for the flashing effect + * @param tt the type of flashing effect + */ + public JPolygonFlash(JPanel p, CPolygon poly1, CPolygon poly2, boolean oc, double xc, double yc, int c1, int c2, int tt) { super(p); vlist = new Vector(); @@ -49,11 +59,13 @@ public JPolygonFlash(JPanel p, CPolygon poly1, CPolygon poly2, boolean oc, doubl this.poly1 = poly1; this.poly2 = poly2; - // poly1.setVisible(false); poly2.setVisible(false); } - + /** + * Initializes the flashing effect by calculating the number of steps required + * based on the distance between corresponding points in the two polygons. + */ private void init1() { int len = vlist.size(); if (len == 0) return; @@ -74,6 +86,10 @@ private void init1() { this.nd = 0; } + /** + * Initializes the flashing effect by calculating the centroid and the number of steps required + * based on the distance and angle between the centroids of the two polygons. + */ private void init() { int len = vlist.size(); if (len == 0) return; @@ -100,7 +116,6 @@ private void init() { dy2 = getCentroidY(vlist1); } - double x = dx2 - dx1; double y = dy2 - dy1; @@ -110,7 +125,6 @@ private void init() { p3 = (CPoint) vlist.get(1); p4 = (CPoint) vlist1.get(1); -// double r = CAngle.get4pAngle(p1.getx() + x, p1.gety() + y, dx2, dy2, p2.getx(), p2.gety()); double r = CAngle.get4pAngle(p1.getx(), p1.gety(), p3.getx(), p3.gety(), p2.getx(), p2.gety(), p4.getx(), p4.gety()); int s1 = (int) Math.abs(r / ASTEP); n = Math.max(s, s1); @@ -126,6 +140,12 @@ private void init() { this.nd = 0; } + /** + * Calculates the x-coordinate of the centroid of the given vector of points. + * + * @param v the vector of points + * @return the x-coordinate of the centroid + */ public double getCentroidX(Vector v) { double dx1 = 0; int n = v.size(); @@ -137,6 +157,12 @@ public double getCentroidX(Vector v) { return dx1; } + /** + * Calculates the y-coordinate of the centroid of the given vector of points. + * + * @param v the vector of points + * @return the y-coordinate of the centroid + */ public double getCentroidY(Vector v) { double dy1 = 0; int n = v.size(); @@ -148,6 +174,11 @@ public double getCentroidY(Vector v) { return dy1; } + /** + * Handles the action event for the timer, updating the animation state and repainting the panel. + * + * @param e the action event + */ public void actionPerformed(ActionEvent e) { if (nd <= n) nd++; @@ -158,23 +189,48 @@ public void actionPerformed(ActionEvent e) { panel.repaint(); } + /** + * Stops the flashing effect and makes the second polygon visible. + */ public void stop() { poly2.setVisible(true); super.stop(); } + /** + * Starts the flashing effect and makes the second polygon invisible. + */ public void start() { poly2.setVisible(false); super.start(); } - + /** + * Recalculates the flashing effect by reinitializing the animation state. + */ public void recalculate() { int t = nd; nd = t; this.init(); } + /** + * Draws the flashing polygon effect based on the current animation state. + * + *

+ * This method computes the polygon's vertex positions by either applying a rotation + * and translation transformation or by linearly interpolating between two sets of points, + * depending on the current flashing type. It then fills the polygon with an interpolated + * color and draws its outline. + *

+ * + *

+ * The method returns false if the animation is not running or has finished. + *

+ * + * @param g2 the Graphics2D context used for drawing + * @return true if the polygon is successfully drawn; false otherwise + */ public boolean draw(Graphics2D g2) { int ln = vlist.size(); @@ -234,12 +290,4 @@ public boolean draw(Graphics2D g2) { g2.drawPolygon(mx, my, ln); return true; } - - - public void drawColoredTriangle(int[] p1, int[] p2, Graphics2D g2) { - g2.setStroke(new BasicStroke(1.0f)); - g2.setColor(Color.black); - g2.drawPolygon(p1, p2, 3); - } - } \ No newline at end of file diff --git a/src/main/java/wprover/JPopExView.java b/src/main/java/wprover/JPopExView.java index 56bb8e45..5dd9c6e1 100644 --- a/src/main/java/wprover/JPopExView.java +++ b/src/main/java/wprover/JPopExView.java @@ -3,19 +3,19 @@ import java.io.IOException; /** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2005-11-6 - * Time: 20:57:00 - * To change this template use File | Settings | File Templates. + * JPopExView is a class that represents a pop-up view for displaying rules in the GExpert application. + * It extends the JBaseDialog class and provides functionality to load and display rules. */ -public class JPopExView extends JBaseDialog -{ +public class JPopExView extends JBaseDialog { GExpert gxInstance; JExPanel panel; - public JPopExView(GExpert exp) - { + /** + * Constructs a new JPopExView with the specified GExpert instance. + * + * @param exp the GExpert instance to associate with this JPopExView + */ + public JPopExView(GExpert exp) { super(exp.getFrame()); gxInstance = exp; this.setSize(600, 400); @@ -23,8 +23,13 @@ public JPopExView(GExpert exp) this.add(panel); } - public boolean loadRule(String s) - { + /** + * Loads a rule from the specified file name and displays it in the panel. + * + * @param s the name of the rule file to load + * @return true if the rule was loaded successfully, false otherwise + */ + public boolean loadRule(String s) { this.setTitle(s); String f = GExpert.getUserDir(); @@ -32,12 +37,10 @@ public boolean loadRule(String s) DrawProcess dp = new DrawProcess(); dp.clearAll(); - try - { - boolean ss = dp.Load(f + sp +"rules" + sp + s); + try { + boolean ss = dp.Load(f + sp + "rules" + sp + s); panel.setdrawP(dp); - } catch (IOException ee) - { + } catch (IOException ee) { CMisc.eprint(panel, "can not load rule: " + sp); return false; } diff --git a/src/main/java/wprover/JRedoStepFlash.java b/src/main/java/wprover/JRedoStepFlash.java index cea0aa81..21cc1c57 100644 --- a/src/main/java/wprover/JRedoStepFlash.java +++ b/src/main/java/wprover/JRedoStepFlash.java @@ -4,27 +4,39 @@ import java.awt.*; /** - * Created by IntelliJ IDEA. - * User: ye - * Date: Mar 25, 2007 - * Time: 3:52:07 AM - * To change this template use File | Settings | File Templates. + * JRedoStepFlash is a class that extends JFlash and is used to create a flashing + * effect on a JPanel when the redo step is performed in the drawing process. */ public class JRedoStepFlash extends JFlash { DrawProcess dp; + /** + * Constructs a new JRedoStepFlash with the specified JPanel and DrawProcess. + * + * @param p the JPanel to associate with this JRedoStepFlash + * @param dp the DrawProcess to be used for the redo step + */ public JRedoStepFlash(JPanel p, DrawProcess dp) { super(p); this.dp = dp; vType = true; } + /** + * Draws the flashing effect on the specified Graphics2D context. + * + * @param g2 the Graphics2D context to draw on + * @return true if the drawing was successful, false otherwise + */ public boolean draw(Graphics2D g2) { return true; } + /** + * Stops the flashing effect and performs the redo step in the drawing process. + */ public void stop() { if (finished) return; @@ -33,15 +45,27 @@ public void stop() { finished = true; } + /** + * Starts the flashing effect by stopping it first. + */ public void start() { stop(); } + /** + * Checks if the flashing effect is currently running. + * + * @return false as the flashing effect is not running + */ public boolean isrRunning() { return false; - } + /** + * Checks if the flashing effect has finished. + * + * @return true if the flashing effect has finished, false otherwise + */ public boolean isfinished() { return finished; } diff --git a/src/main/java/wprover/JSegmentMovingFlash.java b/src/main/java/wprover/JSegmentMovingFlash.java index faaf4aad..fedc8614 100644 --- a/src/main/java/wprover/JSegmentMovingFlash.java +++ b/src/main/java/wprover/JSegmentMovingFlash.java @@ -6,11 +6,8 @@ import java.awt.event.ActionEvent; /** - * Created by IntelliJ IDEA. - * User: ye - * Date: Mar 23, 2007 - * Time: 11:41:54 PM - * To change this template use File | Settings | File Templates. + * JSegmentMovingFlash is a class that extends JFlash and implements ActionListener. + * It is used to create a moving flash effect on a segment defined by four points. */ public class JSegmentMovingFlash extends JFlash implements ActionListener { @@ -21,6 +18,17 @@ public class JSegmentMovingFlash extends JFlash implements ActionListener { private double xc, yc, dxc, dyc; + /** + * Constructs a new JSegmentMovingFlash with the specified parameters. + * + * @param p the JPanel to associate with this JSegmentMovingFlash + * @param p1 the first CPoint of the segment + * @param p2 the second CPoint of the segment + * @param p3 the third CPoint of the segment + * @param p4 the fourth CPoint of the segment + * @param c1 the first color index for the flashing effect + * @param c2 the second color index for the flashing effect + */ public JSegmentMovingFlash(JPanel p, CPoint p1, CPoint p2, CPoint p3, CPoint p4, int c1, int c2) { super(p); @@ -35,9 +43,11 @@ public JSegmentMovingFlash(JPanel p, CPoint p1, CPoint p2, CPoint p3, CPoint p4, nstep = -3; timer = new Timer(TIME_INTERVAL, this); super.vType = true; - } + /** + * Initializes the parameters for the moving flash effect. + */ private void init() { double r = CMisc.getMoveStep(); double x1 = (p1.getx() + p2.getx()) / 2; @@ -97,6 +107,12 @@ else if (Math.abs(r2) < CMisc.ZERO && rt) da = r2 / n; } + /** + * Draws the moving flash effect on the specified Graphics2D context. + * + * @param g2 the Graphics2D context to draw on + * @return true if the drawing was successful, false otherwise + */ public boolean draw(Graphics2D g2) { double r = (double) (n - nd) / n; Color c = getRatioColor(c1, c2, r); @@ -104,7 +120,6 @@ public boolean draw(Graphics2D g2) { g2.setColor(c); if (nd >= 0 && nd != n) { - double dxt = (dxc) * nd / n; double dyt = (dyc) * nd / n; double tx1 = p1.getx() - xc; @@ -121,7 +136,6 @@ public boolean draw(Graphics2D g2) { double x2 = tx2 * cos - ty2 * sin + xc + dxt; double y2 = tx2 * sin + ty2 * cos + yc + dyt; g2.drawLine((int) x1, (int) y1, (int) x2, (int) y2); - } else if (nd < 0) { g2.drawLine((int) p1.getx(), (int) p1.gety(), (int) p2.getx(), (int) p2.gety()); } else if (nd == n && nstep <= 0) { @@ -130,6 +144,11 @@ public boolean draw(Graphics2D g2) { return true; } + /** + * Handles the action event for the timer, updating the animation state and repainting the panel. + * + * @param e the action event + */ public void actionPerformed(ActionEvent e) { nd++; if (nd >= n) { diff --git a/src/main/java/wprover/JTLineFlash.java b/src/main/java/wprover/JTLineFlash.java index 52c35849..143055f8 100644 --- a/src/main/java/wprover/JTLineFlash.java +++ b/src/main/java/wprover/JTLineFlash.java @@ -5,10 +5,18 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; - +/** + * JTLineFlash is a class that extends JFlash and implements ActionListener. + * It is used to create a flashing effect on two lines in a JPanel. + */ public class JTLineFlash extends JFlash implements ActionListener { JLine ln1, ln2; + /** + * Constructs a new JTLineFlash with the specified JPanel. + * + * @param p the JPanel to associate with this JTLineFlash + */ public JTLineFlash(JPanel p) { super(p); timer = new Timer(TIME_INTERVAL, this); @@ -16,6 +24,15 @@ public JTLineFlash(JPanel p) { ln2 = new JLine(); } + /** + * Constructs a new JTLineFlash with the specified JPanel and four CPoints. + * + * @param p the JPanel to associate with this JTLineFlash + * @param p1 the first CPoint of the first line + * @param p2 the second CPoint of the first line + * @param p3 the first CPoint of the second line + * @param p4 the second CPoint of the second line + */ public JTLineFlash(JPanel p, CPoint p1, CPoint p2, CPoint p3, CPoint p4) { super(p); timer = new Timer(TIME_INTERVAL, this); @@ -27,6 +44,12 @@ public JTLineFlash(JPanel p, CPoint p1, CPoint p2, CPoint p3, CPoint p4) { ln2.addAPoint(p4); } + /** + * Draws the flashing effect on the specified Graphics2D context. + * + * @param g2 the Graphics2D context to draw on + * @return true if the drawing was successful, false otherwise + */ public boolean draw(Graphics2D g2) { g2.setColor(color); diff --git a/src/main/java/wprover/JTriFlash.java b/src/main/java/wprover/JTriFlash.java index 628b9c29..2c3a2f73 100644 --- a/src/main/java/wprover/JTriFlash.java +++ b/src/main/java/wprover/JTriFlash.java @@ -9,11 +9,8 @@ import javax.swing.Timer; /** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2006-4-5 - * Time: 13:12:36 - * To change this template use File | Settings | File Templates. + * JTriFlash is a class that extends JFlash and implements ActionListener. + * It is used to create a triangular flashing effect on a JPanel. */ public class JTriFlash extends JFlash implements ActionListener { @@ -269,6 +266,11 @@ private void init(boolean dir) { } + /** + * Handles the action event by updating the animation state and repainting the panel. + * + * @param e the action event triggering the update + */ public void actionPerformed(ActionEvent e) { if (nd < n) nd++; @@ -281,14 +283,12 @@ public void actionPerformed(ActionEvent e) { panel.repaint(); } - - public void setColorIndex(int c) { - color = c; - } - int[] p1 = new int[3]; int[] p2 = new int[3]; + /** + * Recalculates the flash animation by reinitializing its state based on the current direction. + */ public void recalculate() { boolean dir = checkDirection(); init(dir); @@ -296,6 +296,12 @@ public void recalculate() { } + /** + * Draws the triangular flash effect onto the provided graphics context. + * + * @param g2 the graphics context to draw the flash effect on + * @return true if drawing was successful; false otherwise + */ public boolean draw(Graphics2D g2) { int index = nd; @@ -330,6 +336,11 @@ public boolean draw(Graphics2D g2) { return true; } + /** + * Draws the first triangle of the flash animation using the initial set of coordinates. + * + * @param g2 the graphics context to draw the triangle on + */ public void drawFirstTriangle(Graphics2D g2) { p1[0] = dax[0]; p1[1] = dbx[0]; @@ -342,7 +353,12 @@ public void drawFirstTriangle(Graphics2D g2) { drawColoredTriangle(p1, p2, g2); } - + /** + * Draws a colored line between specific vertices of the triangle based on the flash state. + * + * @param index determines which side of the triangle to draw + * @param g2 the graphics context used for drawing + */ private void drawColoredTriangleLine(int index, Graphics2D g2) { if (fn == 0) return; @@ -386,18 +402,36 @@ private void drawColoredTriangleLine(int index, Graphics2D g2) { } } + /** + * Draws an outline of the triangle using the specified vertex coordinates. + * + * @param p1 an array containing the x-coordinates of the triangle's vertices + * @param p2 an array containing the y-coordinates of the triangle's vertices + * @param g2 the graphics context for drawing the triangle outline + */ public void drawColoredTriangle(int[] p1, int[] p2, Graphics2D g2) { g2.setStroke(new BasicStroke(1.0f)); g2.setColor(Color.black); g2.drawPolygon(p1, p2, 3); } + /** + * Draws the final triangle of the flash effect using the last computed set of coordinates. + * + * @param g2 the graphics context on which to draw the triangle + */ public void drawLastTriangle(Graphics2D g2) { int index = n - 1; drawTiangle(g2, index); } + /** + * Draws a triangle at the specified index from the precomputed coordinate arrays. + * + * @param g2 the graphics context used for drawing the triangle + * @param index the index of the coordinate arrays to use for drawing + */ public void drawTiangle(Graphics2D g2, int index) { p1[0] = dax[index]; p1[1] = dbx[index]; diff --git a/src/main/java/wprover/Language.java b/src/main/java/wprover/Language.java index 4375af8e..b783f816 100644 --- a/src/main/java/wprover/Language.java +++ b/src/main/java/wprover/Language.java @@ -4,6 +4,11 @@ import java.awt.*; import java.util.Locale; +/** + * Language class for managing language-specific strings and font settings. + * This class provides methods to retrieve localized strings, write language + * files, and manage font settings. + */ public class Language { private static int MAX_LEN = 500; @@ -14,40 +19,57 @@ public class Language { private Font font; private lnode[] ndlist = new lnode[MAX_LEN]; + /** + * Sets the current language instance. + * + * @param lan the Language instance to set + */ public static void setLanguage(Language lan) { laninstance = lan; } + /** + * Checks if the current language is English. + * + * @return true if the current language is English, false otherwise + */ public boolean isEnglish() { return "English".equalsIgnoreCase(stype); } + /** + * Gets the font associated with the current language. + * + * @return the Font associated with the current language + */ public Font getFont() { return font; } + /** + * Gets the name of the current language. + * + * @return the name of the current language + */ public String getName() { return stype; } + /** + * Represents a language node containing index, English text, translated text, and tooltip. + */ class lnode { public int index; String en; String tx; String tip; - public lnode(int n, String e, String t1, String t2) { - index = n; - en = e; - tx = t1; - tip = t2; - } - - public lnode(String s) { - index = -1; - tip = s; - } - + /** + * Writes the language node to the specified OutputStreamWriter. + * + * @param out the OutputStreamWriter to write to + * @throws IOException if an I/O error occurs + */ public void write(OutputStreamWriter out) throws IOException { if (index >= 0) { String s = index + " \t#\t" + en + " \t#\t" + tx; @@ -58,15 +80,13 @@ public void write(OutputStreamWriter out) throws IOException { } else out.write(tip + "\n"); out.write("\n"); - - } - - public void writeen(OutputStreamWriter out) throws IOException { - out.write(index + " \t#\t"); - out.write(en); - out.write("\n"); } + /** + * Combines the current language node with another language node. + * + * @param ln the language node to combine with + */ public void combine(lnode ln) { if (index < 0) return; @@ -80,9 +100,14 @@ public void combine(lnode ln) { tx = ln.tx; tip = ln.tip; } - } + /** + * Gets the translated string for the specified English string. + * + * @param s the English string to translate + * @return the translated string, or the original string if not found + */ public String getString(String s) { for (int i = 0; i < MAX_LEN; i++) { lnode ln = ndlist[i]; @@ -94,7 +119,12 @@ public String getString(String s) { return s; } - + /** + * Gets the tooltip for the specified English string. + * + * @param s the English string to get the tooltip for + * @return the tooltip, or an empty string if not found + */ public String getString1(String s) { for (int i = 0; i < MAX_LEN; i++) { lnode ln = ndlist[i]; @@ -106,6 +136,12 @@ public String getString1(String s) { return ""; } + /** + * Gets the English string for the specified translated string. + * + * @param s the translated string to get the English string for + * @return the English string, or the original string if not found + */ public String getEnglish(String s) { if (stype == null) return GExpert.getLanguage(s); @@ -122,67 +158,25 @@ public String getEnglish(String s) { return s; } - + /** + * Gets the localized string for the specified string. + * + * @param s the string to localize + * @return the localized string, or the original string if not found + */ public static String getLs(String s) { if (laninstance == null) return s; return laninstance.getString(s); } - public static String getLs1(String s) { - if (laninstance == null) - return s; - return laninstance.getString1(s); - } - - - public OutputStreamWriter outputBlank(File f) throws IOException { - String path = f.getPath(); - String name = f.getName(); - - String n = path + "1"; - File f1 = new File(n); - f1.createNewFile(); - OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(f1), "UNICODE");//UNICODE,UTF-16 - return writer; - } - - public void writeFile(File f) { - try { - OutputStreamWriter writer = this.outputBlank(f); - writer.write("Font: " + font.getFontName() + " # " + font.getStyle() + " # " + font.getSize()); - for (int i = 0; i < ndlist.length; i++) { - if (ndlist[i] == null) - break; - lnode ln = ndlist[i]; - ln.write(writer); - - } - writer.close(); - - - } catch (IOException ee) { - } - - - } - - - public void writeOut(OutputStreamWriter writer, String[] ss) throws IOException { - if (ss.length == 0) - writer.write("\n"); - else { - for (int i = 0; i < ss.length; i++) { - writer.write(ss[i].trim()); - if (i != ss.length - 1) - writer.write(" #\t"); - } - writer.write("\n"); - } - } - + /** + * Gets the language node with the specified index. + * + * @param n the index of the language node to get + * @return the language node with the specified index, or null if not found + */ public lnode getlnode(int n) { - for (int i = 0; i < ndlist.length; i++) { if (ndlist[i] == null) break; @@ -193,6 +187,11 @@ public lnode getlnode(int n) { return null; } + /** + * Combines the current language with another language. + * + * @param lan the Language instance to combine with + */ public void combine(Language lan) { for (int i = 0; i < ndlist.length; i++) { if (ndlist[i] == null) diff --git a/src/main/java/wprover/LeadVariableDialog.java b/src/main/java/wprover/LeadVariableDialog.java index a6389bb8..d141ddef 100644 --- a/src/main/java/wprover/LeadVariableDialog.java +++ b/src/main/java/wprover/LeadVariableDialog.java @@ -15,6 +15,10 @@ import java.awt.event.ActionEvent; import java.awt.*; +/** + * LeadVariableDialog is a class that extends JBaseDialog and implements MouseListener and ActionListener. + * It is used to display and manipulate lead variables in a graphical user interface. + */ public class LeadVariableDialog extends JBaseDialog implements MouseListener, ActionListener { private JTabbedPane tpane; @@ -27,6 +31,11 @@ public class LeadVariableDialog extends JBaseDialog implements MouseListener, Ac protected static GeoPoly poly = GeoPoly.getPoly(); protected static CharSet charset = CharSet.getinstance(); + /** + * Constructs a new LeadVariableDialog with the specified GExpert instance. + * + * @param f the GExpert instance to associate with this LeadVariableDialog + */ public LeadVariableDialog(GExpert f) { super(f.getFrame()); @@ -52,7 +61,6 @@ public void valueChanged(ListSelectionEvent e) { bdtail.setEnabled(true); else bdtail.setEnabled(false); } - }); tpane = new JTabbedPane(JTabbedPane.BOTTOM); tpane.addTab(getLanguage("Variables"), pane); @@ -87,24 +95,27 @@ public Dimension getMaximumSize() { b.setEnabled(false); panel.add(p2); -// tpane.addTab(getLanguage(244, "NDGs"), new JScrollPane(new ndgPanel(), -// JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER)); - setSize(600, 420); this.setLocation(f.getX(), f.getY()); this.getContentPane().add(panel); } - + /** + * Gets the language string for the specified key. + * + * @param s the key for the language string + * @return the language string associated with the key + */ String getLanguage(String s) { return GExpert.getLanguage(s); - /* - if (gxInstance != null) - return gxInstance.getLanguage(s); - return s; - */ } + /** + * Loads variables from the specified vector and updates the table. + * + * @param s the vector containing the variables to load + * @param r a boolean indicating whether to reduce the variables + */ public void loadVariable(Vector s, boolean r) { try { loadAllPoints(s, r); @@ -112,12 +123,15 @@ public void loadVariable(Vector s, boolean r) { JOptionPane.showMessageDialog(gxInstance, ee.getMessage() + "\n" + "Out of Memory"); return; } - - } + /** + * Loads all points from the specified vector and updates the table. + * + * @param v the vector containing the points to load + * @param r a boolean indicating whether to reduce the points + */ public void loadAllPoints(Vector v, boolean r) { -// vdata.clear(); Vector vdata = new Vector(); for (int i = 0; i < v.size(); i++) { @@ -150,7 +164,6 @@ public void loadAllPoints(Vector v, boolean r) { if (p2.m != null) o2.add(poly.printSPoly(poly.reduce(poly.pcopy(p2.m), pm))); else o2.add(""); -// o2.add(poly.printSPoly(p2.m)); } vdata.add(o1); vdata.add(o2); @@ -161,7 +174,11 @@ public void loadAllPoints(Vector v, boolean r) { model.setDataList(vdata); } - + /** + * Handles action events for the dialog. + * + * @param e the action event + */ public void actionPerformed(ActionEvent e) { String s = e.getActionCommand(); if (s.equals("Reload")) { @@ -178,6 +195,11 @@ public void actionPerformed(ActionEvent e) { } } + /** + * Handles mouse click events for the table. + * + * @param e the mouse event + */ public void mouseClicked(MouseEvent e) { if (e.getSource() == table) { if (e.getClickCount() >= 2) @@ -197,7 +219,9 @@ public void mouseEntered(MouseEvent e) { public void mouseExited(MouseEvent e) { } - + /** + * Inspects the selected term in the table and displays its details. + */ public void inspectTerm() { if (tpane.getTabCount() > 1) { @@ -221,6 +245,12 @@ public void inspectTerm() { tpane.setSelectedIndex(1); } + /** + * Gets the points associated with the specified row index. + * + * @param n the row index + * @return the points associated with the row index + */ public Object getPoints(int n) { if (n % 2 != 0) n -= 1; @@ -228,6 +258,10 @@ public Object getPoints(int n) { return v1.get(0); } + /** + * LVTableModel is a custom table model for displaying lead variables in a JTable. + * It extends DefaultTableModel and provides methods to manage the data displayed in the table. + */ class LVTableModel extends DefaultTableModel { Vector vlist = new Vector(); Vector vdlist = new Vector(); @@ -278,6 +312,10 @@ public void setValueAt(Object value, int row, int col) { } } + /** + * InspectPanel is a custom JPanel that displays the details of a selected lead variable. + * It contains a JTable and a JEditorPane for displaying the variable's properties and polynomial. + */ class InspectPanel extends JPanel { private JTable table1; private JEditorPane pane; @@ -412,7 +450,10 @@ public void setStatus(boolean r) { } } - + /** + * inspectTableModel is a custom table model for displaying the details of a lead variable. + * It extends AbstractTableModel and provides methods to manage the data displayed in the table. + */ class inspectTableModel extends AbstractTableModel { private String[] names = {"", ""}; private Object[][] data = { @@ -455,77 +496,10 @@ public void setValueAt(Object value, int row, int col) { } } - - class ndgPanel extends JPanel { - private JTable tablen; - private ndgModel modeln; - private Vector vndgs = new Vector(); - - public ndgPanel() { - super(); - - this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); - tablen = new JTable((modeln = new ndgModel())); - TableColumn b = tablen.getColumnModel().getColumn(0); - b.setPreferredWidth(30); - b.setWidth(30); - b.setMaxWidth(30); - this.setBorder(BorderFactory.createEmptyBorder(2, 1, 2, 1)); - this.add(tablen); - - TPoly poly = gxInstance.dp.getPBList(); - PolyBasic basic = GeoPoly.getInstance(); - - TMono m1, m2; - m1 = m2 = null; - - if (poly == null) - return; - int nn = poly.getPoly().x; - - Vector v = new Vector(); - while (poly != null) { - m1 = poly.getPoly(); - if (m1 != null) - v.add(0, basic.p_copy(m1)); - poly = poly.next; - } - - Vector vlist = new Vector(); - - for (int n = 1; n < nn / 2 + 1; n++) { - m1 = m2 = null; - - for (int i = 0; i < v.size(); i++) { - TMono m = (TMono) v.get(i); - if (m.x == 2 * n || m.x == 2 * n - 1) { - if (m1 == null) - m1 = m; - else m2 = m; - } - } - - if (m1 != null && m2 != null) { - TMono t = basic.ll_delta(2 * n, m1, m2); - t = gxInstance.dp.reduce(t); - vlist.add(t); - } - if (m1 != null) - v.remove(m1); - if (m2 != null) - v.remove(m2); - } - basic.ndg_reduce(vlist); - for (int i = 0; i < vlist.size(); i++) { - TMono t = (TMono) vlist.get(i); - modeln.addData(" " + basic.getExpandedPrint(t)); - } - } - - - } - - + /** + * ndgModel is a custom table model for displaying NDG (Non-Deterministic Graph) data. + * It extends DefaultTableModel and provides methods to manage the data displayed in the table. + */ class ndgModel extends DefaultTableModel { private Vector vlist = new Vector(); diff --git a/src/main/java/wprover/ListTree.java b/src/main/java/wprover/ListTree.java index b7f3b14f..6ef8dd5b 100644 --- a/src/main/java/wprover/ListTree.java +++ b/src/main/java/wprover/ListTree.java @@ -1,20 +1,17 @@ package wprover; -/** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2005-8-12 - * Time: 11:06:53 - * To change this template use File | Settings | File Templates. - */ - import javax.swing.*; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; import java.util.Vector; - +/** + * ListTree provides a tabbed interface with two panels: + * - "Construct History": displays a list of undo structures. + * - "Objects": shows geometric objects and their properties. + * This class enables users to select items for detailed inspection. + */ public class ListTree extends JTabbedPane implements ActionListener, MouseListener, ListSelectionListener { @@ -25,6 +22,11 @@ public class ListTree extends JTabbedPane private CProperty prop; + /** + * Constructs a new ListTree with the specified GExpert instance. + * + * @param gx the GExpert instance to associate with this ListTree + */ public ListTree(GExpert gx) { super(JTabbedPane.BOTTOM); @@ -34,9 +36,8 @@ public ListTree(GExpert gx) { undolist = new Vector(); model = new DefaultListModel(); list = new JList(model); - list.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); + list.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); pane1.add(new JScrollPane(list)); -// list.setCellRenderer(); ListCellRenderer rener = new DefaultListCellRenderer() { public Component getListCellRendererComponent( @@ -50,7 +51,6 @@ public Component getListCellRendererComponent( d.setText((1 + index) + ". \t" + value.toString()); return d; } - }; list.setCellRenderer(rener); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); @@ -68,7 +68,7 @@ public Dimension getPreferredSize() { return dm; } }; - listx.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); + listx.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); ListCellRenderer rener1 = new DefaultListCellRenderer() { public Component getListCellRendererComponent( @@ -84,11 +84,10 @@ public Component getListCellRendererComponent( d.setText(c.getDescription()); return d; } - }; prop = new CProperty(gx.d, gx.getLan()); - prop.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); + prop.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); JSplitPane pane2 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); pane2.setLeftComponent(new JScrollPane(listx)); listx.setCellRenderer(rener1); @@ -97,13 +96,18 @@ public Component getListCellRendererComponent( this.addTab(GExpert.getLanguage("Objects"), pane2); } - + /** + * Handles action events for the ListTree. + * + * @param e the action event + */ public void actionPerformed(ActionEvent e) { } - /** - * Remove the currently selected node. + * Handles value change events for the list selections. + * + * @param e the list selection event */ public void valueChanged(ListSelectionEvent e) { if (e.getSource() == list) @@ -115,41 +119,60 @@ public void valueChanged(ListSelectionEvent e) { gxInstance.dp.setObjectListForFlash(c); } } - } - + /** + * Handles mouse click events for the ListTree. + * + * @param e the mouse event + */ public void mouseClicked(MouseEvent e) { if (e.getButton() == 3) { - - } else { - } } - + /** + * Handles mouse press events for the ListTree. + * + * @param e the mouse event + */ public void mousePressed(MouseEvent e) { - } + /** + * Handles mouse release events for the ListTree. + * + * @param e the mouse event + */ public void mouseReleased(MouseEvent e) { - } + /** + * Handles mouse enter events for the ListTree. + * + * @param e the mouse event + */ public void mouseEntered(MouseEvent e) { - } + /** + * Handles mouse exit events for the ListTree. + * + * @param e the mouse event + */ public void mouseExited(MouseEvent e) { - } + /** + * Clears all trees in the ListTree. + */ public void clearAllTrees() { - - } + /** + * Reloads the ListTree with the current undo list and solid objects. + */ public void reload() { undolist.clear(); model.removeAllElements(); @@ -164,12 +187,10 @@ public void reload() { Vector vx = dp.getAllSolidObj(); - for (int i = 0; i < vx.size(); i++) { - Object o = vx.get(i); + for (Object o : vx) { if (o != null) modelx.addElement(o); } - } } \ No newline at end of file diff --git a/src/main/java/wprover/MProveInputPanel.java b/src/main/java/wprover/MProveInputPanel.java index 2f774b3b..1b5d8434 100644 --- a/src/main/java/wprover/MProveInputPanel.java +++ b/src/main/java/wprover/MProveInputPanel.java @@ -12,11 +12,9 @@ import java.awt.event.*; /** - * Created by IntelliJ IDEA. - * User: yezheng - * Date: 2006-6-17 - * Time: 13:17:09 - * To change this template use File | Settings | File Templates. + * MProveInputPanel is a class that represents a panel for manual input in a + * graphical user interface. It provides various components for user interaction + * and input handling. */ public class MProveInputPanel extends JToolBar implements ActionListener { public static ImageIcon icon_Right = GExpert.createImageIcon("images/dtree/right.gif"); @@ -56,12 +54,17 @@ public class MProveInputPanel extends JToolBar implements ActionListener { private JPanel topPanel; + /** + * Sets the node value and updates the panel based on the provided MObject. + * + * @param node the DefaultMutableTreeNode to set + * @param obj the MObject to associate with the node + */ public void setNodeValue(DefaultMutableTreeNode node, MObject obj) { tnode = node; this.node = (MNode) node.getUserObject(); this.obj = obj; - if (obj != null && obj.getType() != 0) { int d = obj.getType() - 1; int d1 = -1; @@ -86,21 +89,34 @@ else if (obj instanceof MSymbol) { } } + /** + * Gets the language string for the specified key. + * + * @param s the key for the language string + * @return the language string associated with the key + */ String getLanguage(String s) { if (gxInstance != null) return GExpert.getLanguage(s); return s; } + /** + * Gets the maximum size of the component. + * + * @return the maximum size of the component + */ public Dimension getMaximumSize() { Dimension dm = super.getPreferredSize(); dm.setSize(Integer.MAX_VALUE, dm.getHeight()); return dm; } - private void setTypeSelection(int d, int d1) { - } - + /** + * Changes the state of the buttons based on the provided boolean value. + * + * @param r a boolean indicating whether to enable or disable the buttons + */ private void stateButtonChange(boolean r) { bok.setEnabled(r); badd.setEnabled(r); @@ -109,13 +125,23 @@ private void stateButtonChange(boolean r) { bcancel.setEnabled(r); } + /** + * Gets the preferred size of the component. + * + * @return the preferred size of the component + */ public Dimension getPreferredSize() { Dimension dm = super.getPreferredSize(); return dm; } + /** + * Handles menu selection and updates the panel based on the selected item. + * + * @param id the ID of the selected item + * @param id2 the secondary ID of the selected item + */ private void onMenuSelected(int id, int id2) { - int t = id; if (t == -1) return; type = t + 1; @@ -197,6 +223,14 @@ private void onMenuSelected(int id, int id2) { mdPanel.repaint(); } + /** + * Constructs a new MProveInputPanel with the specified GExpert instance, DPanel, DrawTextProcess, and JTree. + * + * @param gx the GExpert instance to associate with this MProveInputPanel + * @param pp the DPanel instance to associate with this MProveInputPanel + * @param dp the DrawTextProcess instance to associate with this MProveInputPanel + * @param tree the JTree instance to associate with this MProveInputPanel + */ public MProveInputPanel(GExpert gx, DPanel pp, DrawTextProcess dp, JTree tree) { super("Manual Input Toolbar"); super.setVisible(true); @@ -206,7 +240,6 @@ public MProveInputPanel(GExpert gx, DPanel pp, DrawTextProcess dp, JTree tree) { this.dpane = pp; this.dp = dp; - this.tree = (MProveTree) tree; this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); JPanel pane1 = new JPanel(); @@ -292,6 +325,11 @@ public MProveInputPanel(GExpert gx, DPanel pp, DrawTextProcess dp, JTree tree) { createPopMain(); } + /** + * Sets the state of the buttons in the panel. + * + * @param f a boolean indicating whether to enable or disable the buttons + */ public void setBState(boolean f) { if (f) { bok.setEnabled(true); @@ -307,19 +345,16 @@ public void setBState(boolean f) { } } + /** + * Creates the pop-up menu for selection. + */ private void createPopMain() { popSelect = new popSelectMenu1(); } - public Object getDefinedNode() { - if (type == 1) { - return new MText(textPane.getText()); - } else if (type == 2) { - - } - return null; - } - + /** + * Handles the OK button action. + */ public void buttonOK() { if (type == MObject.TEXT) { if (obj instanceof MText) @@ -364,6 +399,11 @@ public void buttonOK() { tree.reload(); } + /** + * Handles action events for the panel. + * + * @param e the action event + */ public void actionPerformed(ActionEvent e) { String s = e.getActionCommand(); JToggleButton b = (JToggleButton) e.getSource(); @@ -400,7 +440,7 @@ public void actionPerformed(ActionEvent e) { boolean r = b.isSelected(); tree.setEditable(r); topPanel.setVisible(r); - this.stateButtonChange(r); + this.stateButtonChange(r); } else if (s.equals("Step")) { b.setSelected(false); if (gxInstance != null) @@ -409,6 +449,12 @@ public void actionPerformed(ActionEvent e) { } + /** + * Selects a point in the panel. + * + * @param p the point to select + * @return true if the point was selected, false otherwise + */ public boolean selectAPoint(CPoint p) { if (type == MObject.DOBJECT) { objectPane.selectAPoint(p); @@ -421,6 +467,12 @@ public boolean selectAPoint(CPoint p) { return true; } + /** + * Adds an undo step to the panel. + * + * @param un the UndoStruct to add + * @param tip the tip associated with the undo step + */ public void addUndo(UndoStruct un, Object tip) { if (type == MObject.DRAW) { @@ -432,10 +484,18 @@ public void addUndo(UndoStruct un, Object tip) { tree.addUndoObject(un); } + /** + * Undoes the specified step in the panel. + * + * @param u the UndoStruct representing the step to undo + */ public void undoStep(UndoStruct u) { tree.undoStep(u); } + /** + * A class representing a text panel for user input. + */ class textPanel extends JPanel { JTextField tpane; @@ -474,6 +534,9 @@ public void cancel() { } } + /** + * A class representing a prefix panel for user input. + */ class prefixPanel extends JPanel { JComboBox box; MPrefix pfix = null; @@ -523,6 +586,9 @@ public void cancel() { } } + /** + * A class representing a symbol panel for user input. + */ class symbolPanel extends JPanel implements ItemListener { JComboBox box; MSymbol sym = null; @@ -570,6 +636,9 @@ public void cancel() { } } + /** + * A class representing a drawing panel for user input. + */ class drawPanel extends JPanel { private MDraw draw; private JTextPane field; @@ -645,7 +714,9 @@ public void cancel() { } - + /** + * A class representing a panel for user input of objects. + */ class dobjPanel extends JPanel implements ActionListener, ItemListener { private JComboBox box; @@ -847,6 +918,9 @@ public void cancel() { } } + /** + * A class representing a panel for user input of equations. + */ class rulePanel extends JPanel { private JComboBox box; private MRule rule; @@ -881,6 +955,9 @@ public void cancel() { } + /** + * A class representing a panel for user input of common equations. + */ class CommonEquationPanel extends JPanel implements ActionListener { private Vector vlist = new Vector(); @@ -1036,6 +1113,9 @@ public MEqTerm getUserObject() { private static Border border1 = BorderFactory.createRaisedBevelBorder(); private static Border border2 = BorderFactory.createEmptyBorder(2, 2, 2, 2); + /** + * This class is used to show the select menu + */ class selectLabel extends JLabel implements MouseListener, MouseMotionListener { public selectLabel() { @@ -1072,6 +1152,9 @@ public void mouseMoved(MouseEvent e) { } } + /** + * This class is used to show the select menu + */ class popSelectMenu1 extends JPopupMenu implements ActionListener { private int type; @@ -1217,6 +1300,9 @@ public void show(Component invoker, int x, int y, int type) { } + /** + * This class is used to show the select menu + */ class popSelectMenuItem extends JMenuItem { int m_id1, m_id2; @@ -1243,6 +1329,9 @@ public int getType2() { } + /** + * This method is used to set the node value + */ private void mselected(String s, int t1, int t2) { onMenuSelected(t1, t2); slabel.setText(s); diff --git a/src/main/java/wprover/MProveTree.java b/src/main/java/wprover/MProveTree.java index 86404aa6..030c6de3 100644 --- a/src/main/java/wprover/MProveTree.java +++ b/src/main/java/wprover/MProveTree.java @@ -10,7 +10,10 @@ import java.io.IOException; import java.io.DataOutputStream; - +/** + * MProveTree is a custom JTree implementation that represents a tree structure + * for mathematical objects and their associated undo structures. + */ public class MProveTree extends JTree implements ActionListener { private GExpert gxInstance; private DPanel dpane; @@ -824,7 +827,10 @@ public void actionPerformed(ActionEvent e) { } } - +/** + * MNode is a class that represents a node in a tree structure, specifically for + * managing mathematical objects and their associated undo structures. + */ class MNode extends Vector { private int index = -1; @@ -993,7 +999,11 @@ public void Save(DataOutputStream out) throws IOException { } - +/** + * MSymbol is a class that represents a mathematical symbol in a tree structure. + * It extends the MObject class and provides methods to load, save, and manage + * the symbol's type and associated image icon. + */ class MSymbol extends MObject { final static ImageIcon EQQ = GExpert.createImageIcon("images/symbol/eqq.gif"); final static ImageIcon EQ = GExpert.createImageIcon("images/symbol/eq.gif"); @@ -1060,7 +1070,11 @@ public void Save(DataOutputStream out) throws IOException { } } - +/** + * MPrefix is a class that represents a prefix in a mathematical proof tree. + * It extends the MObject class and provides methods to manage the prefix type + * and associated text. + */ class MPrefix extends MObject { public static int GIVEN = 0; @@ -1114,7 +1128,11 @@ public void Save(DataOutputStream out) throws IOException { } } - +/** + * MDraw is a class that represents a drawing object in a mathematical proof tree. + * It extends the MObject class and provides methods to manage the drawing's + * associated undo structures and text. + */ class MDraw extends MObject { private Vector vunlist = new Vector(); @@ -1198,7 +1216,10 @@ public void Save(DataOutputStream out) throws IOException { } } - +/** + * MText is a class that represents a text object in a mathematical proof tree. + * It extends the MObject class and provides methods to manage the text string. + */ class MText extends MObject { private String str = ""; @@ -1230,7 +1251,11 @@ public void Save(DataOutputStream out) throws IOException { } } - +/** + * MDrObj is a class that represents a mathematical object in a proof tree. + * It extends the MObject class and provides methods to manage the object's + * type, associated points, and validation checks. + */ class MDrObj extends MObject { final public static int LINE = 0; final public static int TRIANGLE = 1; @@ -1511,7 +1536,12 @@ public void Save(DataOutputStream out) throws IOException { } } - +/** + * MObject is a base class for representing various types of mathematical objects. + * It encapsulates basic properties such as the object type and provides methods for + * creating, loading, saving, and managing object data. Subclasses should extend this + * class to implement specialized behavior appropriate to their specific object type. + */ class MObject { static String[] pStrings = {"Text", "Keywords", "Symbol", "Assertion", "Object", "Draw", "Construction", "Equation", @@ -1665,6 +1695,11 @@ public void Save(DataOutputStream out) throws IOException { } // TODO. This seems to be unfinished. +/** + * MRule is a class that represents a rule in the GExpert system. + * It extends the MObject class and provides functionality to load and save + * rule data, as well as to manage the rule index and name. + */ class MRule extends MObject { int rindex; public static String[] cStrings = {"Rule1", "Rule2", "Rule3", "SAS", /* "AAS", */ "SSS", "ASA"}; // FIXME. AAS is missing among the files. @@ -1708,7 +1743,11 @@ public void Save(DataOutputStream out) throws IOException { } - +/** + * MEquation is a class that represents an equation in the GExpert system. + * It extends the MObject class and provides functionality to manage terms + * in the equation, as well as to load and save the equation data. + */ class MEquation extends MObject { private Vector vlist = new Vector(); @@ -1752,7 +1791,10 @@ public void Save(DataOutputStream out) throws IOException { } } - +/** + * MEqTerm is a class that represents a term in an equation in the GExpert system. + * It provides functionality to manage the type of the term and the associated object. + */ class MEqTerm { public static String[] cStrings = {" + ", " - ", " * ", " / ", " = ", " > ", " >= ", " < ", " <= ", " //= "}; @@ -1810,7 +1852,11 @@ public void Save(DataOutputStream out) throws IOException { } - +/** + * MAssertion is a class that represents an assertion in the GExpert system. + * It extends the MObject class and provides functionality to manage the + * assertion type and associated objects. + */ class MAssertion extends MObject { public static String[] cStrings = {"Collinear", "Parallel", "Perpendicular", "Midpoint", "Eqdistant", "Cyclic", diff --git a/src/main/java/wprover/MiscDialog.java b/src/main/java/wprover/MiscDialog.java index fa4a96b6..ce2948b0 100644 --- a/src/main/java/wprover/MiscDialog.java +++ b/src/main/java/wprover/MiscDialog.java @@ -9,6 +9,10 @@ import java.io.*; +/** + * MiscDialog is a class that extends JBaseDialog and implements FocusListener and ActionListener. + * It provides a dialog for setting various preferences in the GExpert application. + */ public class MiscDialog extends JBaseDialog implements FocusListener, ActionListener { private GExpert gxInstance; private String lan; @@ -22,24 +26,24 @@ public class MiscDialog extends JBaseDialog implements FocusListener, ActionList private boolean onSetting = false; + /** + * Constructs a new MiscDialog with the specified GExpert instance. + * + * @param gx the GExpert instance to associate with this MiscDialog + */ public MiscDialog(GExpert gx) { super(gx.getFrame(), ("Preferences"), false); gxInstance = gx; lan = CMisc.lan; - String s = GExpert.getLanguage("Preferences"); this.setTitle(s); gxInstance = gx; -// if (gxInstance != null) -// gxInstance.addDependentDialog(this); JTabbedPane pane = new JTabbedPane(JTabbedPane.TOP); pane.addTab(GExpert.getLanguage("Display"), pane1 = createPanelDisply()); - pane.addTab(GExpert.getLanguage("Mode"), pane2 = new modePanel()); - pane.addTab(GExpert.getLanguage("Color"), panelc = new colorPanel()); pane.addTab(GExpert.getLanguage("Font"), pane3 = new FontPanel()); pane.addTab(GExpert.getLanguage("Other"), pane4 = new AnglePanel()); @@ -47,7 +51,6 @@ public MiscDialog(GExpert gx) { JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); - panel.add(pane); JPanel p2 = new JPanel(new FlowLayout()); @@ -73,17 +76,23 @@ public MiscDialog(GExpert gx) { p2.add(b2); panel.add(p2); - this.addFocusListener(this); this.getContentPane().add(panel); - this.setSize(550, 600); //Changed the size of the window, so 'Save Preferences' was visible. TODO: Modify the height automatically to the chosen appearance. - + this.setSize(550, 600); // Changed the size of the window, so 'Save Preferences' was visible. TODO: Modify the height automatically to the chosen appearance. } + /** + * Sets the selected tab in the tabbed pane. + * + * @param n the index of the tab to select + */ public void setSelectedTabbedPane(int n) { tpane.setSelectedIndex(n); } + /** + * Initializes the panels in the dialog. + */ public void init() { pane1.init(); pane2.init(); @@ -91,57 +100,52 @@ public void init() { pane4.init(); } + /** + * Handles action events for the dialog. + * + * @param e the action event + */ public void actionPerformed(ActionEvent e) { String command = e.getActionCommand(); if (command.equals("OK")) { this.setVisible(false); - } else if (command.equals("Default")) { onSetting = true; CMisc.Reset(); init(); onSetting = false; } else if (command.equals("Save Preferences")) { - String s1 = GExpert.getUserHome(); String s2 = GExpert.getFileSeparator(); try { OutputStreamWriter writer = new OutputStreamWriter( new FileOutputStream(new File(s1 + s2 + "jgex.cfg")), "UTF-8"); - CMisc.SaveProperty(writer); } catch (IOException ee) { JOptionPane.showMessageDialog(gxInstance, GExpert.getLanguage("Can not save Preferences"), GExpert.getLanguage("Fail"), JOptionPane.WARNING_MESSAGE); } JOptionPane.showMessageDialog(gxInstance, GExpert.getLanguage("Preferences have been successfully saved.") + "\n" + - GExpert.getLanguage("Please restart the program."), + GExpert.getLanguage("Please restart the program."), GExpert.getLanguage("Saved"), JOptionPane.WARNING_MESSAGE); - - /* We don't try to restart the program, since it requires different strategies on different systems. - Instead, we leave the restart to the user. - - try { - ProcessBuilder pb = new ProcessBuilder("java", "-jar", - GExpert.getUserDir() + GExpert.getFileSeparator() + "jgex.jar"); - pb.directory(new File(GExpert.getUserDir())); - Map map = pb.environment(); - Process p = pb.start(); - System.exit(0); - } catch (IOException e0) { - } - */ } - } - + /** + * Creates and returns a new DisplayPanel. + * + * @return a new DisplayPanel + */ private DisplayPanel createPanelDisply() { return new DisplayPanel(); } + /** + * DisplayPanel is a JPanel that provides various display settings for the GExpert application. + * It includes sliders, checkboxes, and radio buttons for configuring the display options. + */ class DisplayPanel extends JPanel { private JLabel text; @@ -366,6 +370,10 @@ public void init() { } + /** + * AnglePanel is a JPanel that provides options for configuring angles in the GExpert application. + * It includes radio buttons for different angle types and a slider for adjusting the polygon moving interval. + */ class AnglePanel extends JPanel implements ItemListener { JRadioButton ba, bwa, bma, bfill; JSlider slider; @@ -453,13 +461,27 @@ public void init() { } + /** + * Invoked when the component gains the keyboard focus. + * + * @param e the focus event + */ public void focusGained(FocusEvent e) { } + /** + * Invoked when the component loses the keyboard focus. + * + * @param e the focus event + */ public void focusLost(FocusEvent e) { this.setVisible(false); } + /** + * This class represents a panel for selecting fonts in the GExpert application. + * It extends JPanel and provides buttons to choose different fonts for various elements. + */ class FontPanel extends JPanel { @@ -608,6 +630,10 @@ public void init() { } + /** + * colorPanel is a JPanel that allows the user to select colors for the background and grid. + * It includes radio buttons for different color modes and color selection panels. + */ class colorPanel extends JPanel implements ItemListener, MouseListener { private JRadioButton b1, b2, b3; @@ -741,6 +767,10 @@ public void mouseExited(MouseEvent e) { } + /** + * ColorPane is a JPanel that represents a color selection area. + * It is used in the colorPanel class to display the selected background and grid colors. + */ class ColorPane extends JPanel { int w, h; @@ -756,6 +786,10 @@ public Dimension getPreferredSize() { } } + /** + * modePanel is a JPanel that allows the user to select various modes and settings. + * It includes options for anti-aliasing, language selection, and look-and-feel selection. + */ class modePanel extends JPanel implements ItemListener { private JRadioButton r1, r2; private JComboBox blanguage, blook; diff --git a/src/main/java/wprover/NdgDialog.java b/src/main/java/wprover/NdgDialog.java index 6b0ff8a5..91b1a13d 100644 --- a/src/main/java/wprover/NdgDialog.java +++ b/src/main/java/wprover/NdgDialog.java @@ -10,6 +10,13 @@ import java.awt.event.*; import java.util.Vector; +/** + * NdgDialog is a custom dialog class that extends JBaseDialog and implements + * ActionListener, MouseMotionListener, MouseListener, ChangeListener, + * TableModelListener, and ListSelectionListener interfaces. It provides + * functionality to display and manage non-degenerate conditions in a graphical + * user interface. + */ public class NdgDialog extends JBaseDialog implements ActionListener, MouseMotionListener, MouseListener, ChangeListener, TableModelListener, ListSelectionListener { private DrawProcess dp; @@ -27,6 +34,13 @@ public class NdgDialog extends JBaseDialog implements ActionListener, MouseMotio private GExpert gxInstance; + /** + * Constructs a new NdgDialog with the specified GExpert, GTerm, and DrawProcess instances. + * + * @param gx the GExpert instance to associate with this NdgDialog + * @param gt the GTerm instance to associate with this NdgDialog + * @param dp the DrawProcess instance to associate with this NdgDialog + */ public NdgDialog(GExpert gx, GTerm gt, DrawProcess dp) { super(gx.getFrame(), gx.getLanguage("Nondegenerate Conditions")); gxInstance = gx; @@ -36,7 +50,6 @@ public NdgDialog(GExpert gx, GTerm gt, DrawProcess dp) { tt = new JTabbedPane(JTabbedPane.BOTTOM, JTabbedPane.WRAP_TAB_LAYOUT); - tt.addChangeListener(this); this.getConstructions(); @@ -51,7 +64,6 @@ public NdgDialog(GExpert gx, GTerm gt, DrawProcess dp) { tabel1.setDragEnabled(true); - tabel1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); tabel2.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); model1.addTableModelListener(this); @@ -61,15 +73,12 @@ public NdgDialog(GExpert gx, GTerm gt, DrawProcess dp) { tabel1.setSelectionModel(lselect1); lselect1.addListSelectionListener(this); -// super.getPreferredSize() -// tabel1.setBorder(BorderFactory.createTitledBorder("")); JScrollPane pane = new JScrollPane(tabel1, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER) { public Dimension getPreferredSize() { Dimension dm = tabel1.getPreferredSize(); dm.setSize(dm.getWidth(), dm.getHeight() + 30); return dm; } - }; JScrollPane pane2 = new JScrollPane(tabel2, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER) { public Dimension getPreferredSize() { @@ -77,12 +86,10 @@ public Dimension getPreferredSize() { dm.setSize(dm.getWidth(), dm.getHeight() + 30); return dm; } - }; JScrollPane pane3 = new JScrollPane(tabel3, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER) { public Dimension getPreferredSize() { Dimension dm = tabel3.getPreferredSize(); - dm.setSize(dm.getWidth(), dm.getHeight() + 30); return dm; } @@ -107,13 +114,13 @@ public Dimension getPreferredSize() { int x = gx.getX(); int y = gx.getY(); this.setLocation(x + w / 2 - WD / 2, y + h / 2 - HD / 2); - - } - - public void setSelectIndex(int t) { - tt.setSelectedIndex(t); } + /** + * Handles list selection events for the NdgDialog. + * + * @param e the list selection event + */ public void valueChanged(ListSelectionEvent e) { int n = tabel1.getSelectedRow(); Cons c = (Cons) model1.getValueAt(n, 0); @@ -121,9 +128,7 @@ public void valueChanged(ListSelectionEvent e) { gxInstance.getpprove().setSelectedConstruction(c); Object o = model1.getValueAt(n, 1); if (o != null && o instanceof CNdg) { - CNdg dd = (CNdg) o; - for (int i = 0; i < model2.getRowCount(); i++) { if (model2.getValueAt(i, 0) == dd.equ) { tabel2.getSelectionModel().setSelectionInterval(i, i); @@ -162,15 +167,30 @@ public void mouseEntered(MouseEvent e) { public void mouseExited(MouseEvent e) { } + /** + * Handles action events for the NdgDialog. + * + * @param e the action event + */ public void actionPerformed(ActionEvent e) { this.setVisible(false); } + /** + * Retrieves the constructions for the NdgDialog. + */ public void getConstructions() { } - - public void setValue(Vector v1, Vector v2, Vector v3, Vector v4) { // cndg, m1,m2 + /** + * Sets the values for the NdgDialog models based on the provided vectors. + * + * @param v1 the vector containing constructions + * @param v2 the vector containing non-degenerate conditions + * @param v3 the vector containing simplified non-degenerate conditions + * @param v4 the vector containing final non-degenerate conditions + */ + public void setValue(Vector v1, Vector v2, Vector v3, Vector v4) { model1.reset(); model2.reset(); model3.reset(); @@ -186,7 +206,6 @@ public void setValue(Vector v1, Vector v2, Vector v3, Vector v4) { // cndg, m1 model2.addElement(c); } - for (int i = 0; i < v4.size(); i++) { CNdg c = (CNdg) v4.get(i); model3.addElement(c); @@ -199,10 +218,15 @@ public void setValue(Vector v1, Vector v2, Vector v3, Vector v4) { // cndg, m1 model3.addElement(poly.getAllPrinted(getTMono(c))); } - spane.resetToPreferredSizes(); } + /** + * Retrieves the x-index of the specified point. + * + * @param n the index of the point + * @return the x-index of the point + */ public int dxindex(int n) { CPoint pt = dp.fd_point(n); if (pt == null) @@ -210,11 +234,23 @@ public int dxindex(int n) { return pt.x1.xindex; } + /** + * Retrieves the y-index of the specified point. + * + * @param n the index of the point + * @return the y-index of the point + */ public int dyindex(int n) { CPoint pt = dp.fd_point(n); return pt.y1.xindex; } + /** + * Retrieves the TMono representation of the specified non-degenerate condition. + * + * @param d the non-degenerate condition + * @return the TMono representation of the condition + */ public TMono getTMono(CNdg d) { if (d == null) return null; @@ -232,7 +268,6 @@ public TMono getTMono(CNdg d) { case Gib.NDG_PERP: return poly.perpendicular(dxindex(d.p[0]), dyindex(d.p[0]), dxindex(d.p[1]), dyindex(d.p[1]), dxindex(d.p[2]), dyindex(d.p[2]), dxindex(d.p[3]), dyindex(d.p[3])); - case Gib.NDG_CYCLIC: return poly.cyclic(dxindex(d.p[0]), dyindex(d.p[0]), dxindex(d.p[1]), dyindex(d.p[1]), dxindex(d.p[2]), dyindex(d.p[2]), dxindex(d.p[3]), dyindex(d.p[3])); @@ -245,6 +280,13 @@ public TMono getTMono(CNdg d) { return null; } + /** + * Finds the non-degenerate condition associated with the specified construction. + * + * @param c the construction + * @param v2 the vector containing non-degenerate conditions + * @return the non-degenerate condition associated with the construction, or null if not found + */ public CNdg fd_ndg(Cons c, Vector v2) { for (int i = 0; i < v2.size(); i++) { CNdg d = (CNdg) v2.get(i); @@ -254,6 +296,10 @@ public CNdg fd_ndg(Cons c, Vector v2) { return null; } + /** + * The ndgTableModel class is a custom table model that extends DefaultTableModel. + * It is used to manage the data displayed in the JTable for non-degenerate conditions. + */ class ndgTableModel extends DefaultTableModel { String c1 = gxInstance.getLanguage("Construction"); String c2 = gxInstance.getLanguage("Nondegenerate Condition"); @@ -314,7 +360,10 @@ public void setValueAt(Object value, int row, int col) { } } - + /** + * The ndgTableModel1 class is a custom table model that extends DefaultTableModel. + * It is used to manage the data displayed in the JTable for non-degenerate conditions. + */ class ndgTableModel1 extends DefaultTableModel { String c1 = null; diff --git a/src/main/java/wprover/NumCheckDialog.java b/src/main/java/wprover/NumCheckDialog.java index 35174d58..002765c6 100644 --- a/src/main/java/wprover/NumCheckDialog.java +++ b/src/main/java/wprover/NumCheckDialog.java @@ -7,6 +7,10 @@ import java.awt.event.*; import java.util.Vector; +/** + * NumCheckDialog is a dialog for performing numerical checks on geometric points. + * It allows the user to select points and check various geometric properties. + */ public class NumCheckDialog extends JBaseDialog implements DiagramUpdater, ItemListener, WindowListener { private JComboBox bx; @@ -24,6 +28,11 @@ public class NumCheckDialog extends JBaseDialog implements DiagramUpdater, ItemL public static String[] ST = {"Collinear", "Parallel", "Perpendicular", "Cyclic", "Equal Distance", "Equal Angle"}; public static int[] SN = {3, 4, 4, 4, 4, 6}; + /** + * Constructs a new NumCheckDialog with the specified GExpert instance. + * + * @param gx the GExpert instance to associate with this NumCheckDialog + */ public NumCheckDialog(GExpert gx) { super(gx.getFrame()); gxInstance = gx; @@ -33,9 +42,7 @@ public NumCheckDialog(GExpert gx) { icon1 = GExpert.createImageIcon("images/ptree/hook.gif"); icon2 = GExpert.createImageIcon("images/ptree/cross.gif"); - JPanel top = new JPanel(); - top.setLayout(new BoxLayout(top, BoxLayout.Y_AXIS)); JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT)); @@ -105,7 +112,9 @@ public void actionPerformed(ActionEvent e) { gxInstance.dp.addDiagramUpdaterListener(this); } - + /** + * Updates the diagram and the labels in the dialog. + */ public void UpdateDiagram() { for (int i = 0; i < labels.length; i++) { labels[i].setText(getStringFromPoint((CPoint) bxs[i].getSelectedItem())); @@ -117,6 +126,11 @@ public void UpdateDiagram() { } } + /** + * Adds the selected point to the first available JComboBox. + * + * @param p the point to add + */ public void addSelectPoint(CPoint p) { for (int i = 0; i < bxs.length; i++) { if (bxs[i].getSelectedIndex() < 0) { @@ -124,9 +138,13 @@ public void addSelectPoint(CPoint p) { return; } } - } + /** + * Handles item state change events. + * + * @param e the item event + */ public void itemStateChanged(ItemEvent e) { Object o = e.getSource(); if (o == bx) { @@ -142,6 +160,11 @@ public void itemStateChanged(ItemEvent e) { UpdateDiagram(); } + /** + * Sets the visibility status of the JComboBoxes and labels based on the selected index. + * + * @param n the selected index + */ public void setVisibleStatus(int n) { int num = 0; if (n == -1) @@ -158,8 +181,11 @@ public void setVisibleStatus(int n) { } } + /** + * Unselects all points in the JComboBoxes. + */ public void unSelectAllPoints() { - Vector v = gxInstance.dp.getPointList(); + Vector v = gxInstance.dp.getPointList(); for (int i = 0; i < bxs.length; i++) { } @@ -168,10 +194,21 @@ public void unSelectAllPoints() { } } + /** + * Retrieves the selected point from the specified JComboBox. + * + * @param n the index of the JComboBox + * @return the selected point + */ public CPoint getPt(int n) { return (CPoint) bxs[n].getSelectedItem(); } + /** + * Checks if all visible JComboBoxes have selected points. + * + * @return true if all visible JComboBoxes have selected points, false otherwise + */ public boolean check_filled() { for (int i = 0; i < bxs.length; i++) { if ((bxs[i].isVisible() && bxs[i].getSelectedIndex() == -1)) return false; @@ -179,6 +216,12 @@ public boolean check_filled() { return true; } + /** + * Retrieves the string representation of the specified point. + * + * @param p the point + * @return the string representation of the point + */ public String getStringFromPoint(CPoint p) { if (p == null) return " "; @@ -195,6 +238,12 @@ public void windowOpened(WindowEvent e) { public void windowClosing(WindowEvent e) { } + /** + * This method is called when the window is closed. + * It removes the current instance from the diagram updater listeners. + * + * @param e the window event + */ public void windowClosed(WindowEvent e) { gxInstance.dp.RemoveDiagramUpdaterListener(this); } @@ -212,8 +261,10 @@ public void windowActivated(WindowEvent e) { public void windowDeactivated(WindowEvent e) { } - - ///////////////////////////////////////////////////////////////////// + /** + * This method is called when the diagram is updated. + * It updates the diagram and the labels in the dialog. + */ class Panel_Button extends JPanel { public Panel_Button() { @@ -221,6 +272,10 @@ public Panel_Button() { } } + /** + * Abstract class representing a basic panel for numerical checks. + * It contains methods to set values, reset the panel, and update the diagram. + */ abstract class Panel_Basic extends JPanel { JLabel lex, ltex; String pstring; @@ -275,6 +330,10 @@ public String toString() { } } + /** + * Panel_Coll is a subclass of Panel_Basic that checks for collinearity of three points. + * It overrides the Cal_Value and getLex methods to provide specific functionality. + */ class Panel_Coll extends Panel_Basic { public Panel_Coll() { @@ -294,6 +353,10 @@ public boolean Cal_Value() { } + /** + * Panel_Para is a subclass of Panel_Basic that checks for parallelism of two lines. + * It overrides the Cal_Value and getLex methods to provide specific functionality. + */ class Panel_Para extends Panel_Basic { public Panel_Para() { super(ST[1]); @@ -311,6 +374,10 @@ public String getLex() { } } + /** + * Panel_Perp is a subclass of Panel_Basic that checks for perpendicularity of two lines. + * It overrides the Cal_Value and getLex methods to provide specific functionality. + */ class Panel_Perp extends Panel_Basic { public Panel_Perp() { super(ST[2]); @@ -328,6 +395,10 @@ public String getLex() { } } + /** + * Panel_Cyclic is a subclass of Panel_Basic that checks for cyclicity of four points. + * It overrides the Cal_Value and getLex methods to provide specific functionality. + */ class Panel_Cyclic extends Panel_Basic { public Panel_Cyclic() { super(gxInstance.getLanguage(ST[3])); @@ -345,6 +416,10 @@ public String getLex() { } } + /** + * Panel_EQDis is a subclass of Panel_Basic that checks for equal distances between two pairs of points. + * It overrides the Cal_Value and getLex methods to provide specific functionality. + */ class Panel_EQDis extends Panel_Basic { public Panel_EQDis() { super(ST[4]); @@ -362,6 +437,10 @@ public String getLex() { } } + /** + * Panel_EQAng is a subclass of Panel_Basic that checks for equal angles between two sets of points. + * It overrides the Cal_Value and getLex methods to provide specific functionality. + */ class Panel_EQAng extends Panel_Basic { public Panel_EQAng() { super(ST[5]); diff --git a/src/main/java/wprover/PPDialog.java b/src/main/java/wprover/PPDialog.java index b23badcb..f07f958a 100644 --- a/src/main/java/wprover/PPDialog.java +++ b/src/main/java/wprover/PPDialog.java @@ -11,7 +11,13 @@ import java.awt.*; import java.util.Vector; -public class PPDialog extends JBaseDialog implements ActionListener, MouseMotionListener, MouseListener, ChangeListener { +/** + * PPDialog is a class that extends JBaseDialog and implements ActionListener, + * MouseMotionListener, MouseListener, and ChangeListener interfaces. It is used + * to display a dialog for nondegenerate conditions in a geometric context. + */ +public class +PPDialog extends JBaseDialog implements ActionListener, MouseMotionListener, MouseListener, ChangeListener { private DrawProcess dp; private static int WD = 600; private static int HD = 400; @@ -19,9 +25,16 @@ public class PPDialog extends JBaseDialog implements ActionListener, MouseMotion private JList list1, list2, list22; private JTabbedPane tt; private DefaultListModel model1, model2, model22; - private static Color bcolor = new Color(249,249,255); + private static Color bcolor = new Color(249, 249, 255); + /** + * Constructs a new PPDialog with the specified GExpert, GTerm, and DrawProcess. + * + * @param gx the GExpert instance to associate with this dialog + * @param gt the GTerm instance to associate with this dialog + * @param dp the DrawProcess instance to associate with this dialog + */ public PPDialog(GExpert gx, GTerm gt, DrawProcess dp) { super(gx.getFrame(), "Nondegenerate Conditions"); // TODO. Internationalize. @@ -40,7 +53,7 @@ public PPDialog(GExpert gx, GTerm gt, DrawProcess dp) { list1.setBackground(bcolor); list2.setBackground(bcolor); list22.setBackground(bcolor); - + list22.setSelectionModel(list2.getSelectionModel()); TitledBorder t = BorderFactory.createTitledBorder("Nondegenerate Conditions"); @@ -51,14 +64,12 @@ public PPDialog(GExpert gx, GTerm gt, DrawProcess dp) { tb.setTitleColor(Color.gray); list22.setBorder(tb); - JSplitPane panel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, list2, list22); tt.addChangeListener(this); this.getConstructions(); this.getNDGs(); - JSplitPane panelx = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, list1, panel); panelx.setDividerLocation(200); this.getContentPane().add(new JScrollPane(panelx)); @@ -73,42 +84,89 @@ public PPDialog(GExpert gx, GTerm gt, DrawProcess dp) { panel.revalidate(); } - public void setSelectIndex(int t) { - tt.setSelectedIndex(t); - } - + /** + * Handles state change events for the tabbed pane. + * + * @param e the ChangeEvent triggered by the tabbed pane + */ public void stateChanged(ChangeEvent e) { PPDialog.this.setTitle(tt.getTitleAt(tt.getSelectedIndex())); } + /** + * Handles mouse dragged events. + * + * @param e the MouseEvent triggered by dragging the mouse + */ public void mouseDragged(MouseEvent e) { } + /** + * Handles mouse moved events. + * + * @param e the MouseEvent triggered by moving the mouse + */ public void mouseMoved(MouseEvent e) { } + /** + * Handles mouse clicked events. + * + * @param e the MouseEvent triggered by clicking the mouse + */ public void mouseClicked(MouseEvent e) { } + /** + * Handles mouse pressed events. + * + * @param e the MouseEvent triggered by pressing the mouse + */ public void mousePressed(MouseEvent e) { } + /** + * Handles mouse released events. + * + * @param e the MouseEvent triggered by releasing the mouse + */ public void mouseReleased(MouseEvent e) { } + /** + * Handles mouse entered events. + * + * @param e the MouseEvent triggered by entering a component + */ public void mouseEntered(MouseEvent e) { } + /** + * Handles mouse exited events. + * + * @param e the MouseEvent triggered by exiting a component + */ public void mouseExited(MouseEvent e) { } + /** + * Handles action events. + * + * @param e the ActionEvent triggered by an action + */ public void actionPerformed(ActionEvent e) { this.setVisible(false); } + /** + * Retrieves and processes the constructions for the dialog. + */ public void getConstructions() { } + /** + * Retrieves and processes the nondegenerate conditions (NDGs) for the dialog. + */ public void getNDGs() { if (gt == null) return; @@ -131,17 +189,15 @@ public void getNDGs() { for (int i = 0; i < v.size(); i++) { Cons c = (Cons) v.get(i); model2.addElement((i + 1) + ": " + c.toDString()); - - } + for (int i = 0; i < v.size(); i++) { Cons c = (Cons) v.get(i); -// TMono m = poly.mm_poly(c, dp); -// String s = (i + 1) + ": "; -// if (m != null) -// s += poly.printNPoly(m); -// model22.addElement(s); + // TMono m = poly.mm_poly(c, dp); + // String s = (i + 1) + ": "; + // if (m != null) + // s += poly.printNPoly(m); + // model22.addElement(s); } } - } \ No newline at end of file diff --git a/src/main/java/wprover/PanelAlgebraic.java b/src/main/java/wprover/PanelAlgebraic.java index 496e5800..de36c34c 100644 --- a/src/main/java/wprover/PanelAlgebraic.java +++ b/src/main/java/wprover/PanelAlgebraic.java @@ -13,6 +13,11 @@ import java.awt.event.ActionListener; import java.util.Vector; +/** + * PanelAlgebraic is an abstract class that extends JScrollPane and implements + * Runnable and ActionListener interfaces. It provides methods for handling + * algebraic operations and displaying results in a text pane. + */ public abstract class PanelAlgebraic extends JScrollPane implements Runnable, ActionListener { protected DrawProcess dp; protected GeoPoly poly = GeoPoly.getPoly(); @@ -25,26 +30,40 @@ public abstract class PanelAlgebraic extends JScrollPane implements Runnable, Ac protected TMono _mremainder = null; protected RunningDialog rund; + /** + * Retrieves the language string for the specified key. + * + * @param n the key index (not used) + * @param s the key for the language string + * @return the language string associated with the key + * @deprecated This method is deprecated. Use GExpert.getLanguage(s) directly. + */ @Deprecated public String getLanguage(int n, String s) { return GExpert.getLanguage(s); - - /* - if (lan == null) - return s; - - return lan.getString(n, s); - */ } + /** + * Checks if the panel is currently running. + * + * @return true if the panel is running, false otherwise + */ public boolean isRunning() { return running; } + /** + * Stops the panel from running. + */ public void stop() { running = false; } + /** + * Sets the GExpert instance and updates the language settings. + * + * @param gx the GExpert instance to set + */ public void setXInstance(GExpert gx) { if (gx != null) { this.gxInstance = gx; @@ -52,7 +71,12 @@ public void setXInstance(GExpert gx) { } } - + /** + * Constructs a new PanelAlgebraic with the specified DrawProcess and WuTextPane. + * + * @param dp the DrawProcess instance to associate with this panel + * @param tpane the WuTextPane instance to associate with this panel + */ public PanelAlgebraic(DrawProcess dp, WuTextPane tpane) { super(tpane); this.dp = dp; @@ -60,14 +84,25 @@ public PanelAlgebraic(DrawProcess dp, WuTextPane tpane) { tpane.addListnerToButton(this); } + /** + * Abstract method to stop the panel from running. + * Must be implemented by subclasses. + */ public abstract void stopRunning(); - + /** + * Clears all content from the text pane and stops the panel from running. + */ public void clearAll() { running = false; tpane.clearAll(); } + /** + * Adds a string to the text pane with a newline. + * + * @param s the string to add + */ protected void addString(String s) { try { StyledDocument doc = tpane.getStyledDocument(); @@ -75,9 +110,14 @@ protected void addString(String s) { } catch (BadLocationException ble) { System.err.println("Couldn't insert initial text into text pane."); } - } + /** + * Adds a string to the text pane with the specified style. + * + * @param s the string to add + * @param type the style type to apply + */ protected void addString(String s, String type) { try { StyledDocument doc = tpane.getStyledDocument(); @@ -85,9 +125,11 @@ protected void addString(String s, String type) { } catch (BadLocationException ble) { System.err.println("Couldn't insert initial text into text pane."); } - } + /** + * Adds a button to the text pane. + */ protected void addButton() { try { StyledDocument doc = tpane.getStyledDocument(); @@ -97,6 +139,11 @@ protected void addButton() { } } + /** + * Adds a bold string to the text pane. + * + * @param s the string to add + */ protected void addString1(String s) { try { StyledDocument doc = tpane.getStyledDocument(); @@ -106,6 +153,11 @@ protected void addString1(String s) { } } + /** + * Adds a header string to the text pane with newlines before and after. + * + * @param s the string to add + */ protected void addString2(String s) { try { StyledDocument doc = tpane.getStyledDocument(); @@ -115,6 +167,11 @@ protected void addString2(String s) { } } + /** + * Adds a header string to the text pane with a newline after. + * + * @param s the string to add + */ protected void addString2s(String s) { try { StyledDocument doc = tpane.getStyledDocument(); @@ -124,7 +181,9 @@ protected void addString2s(String s) { } } - + /** + * Adds the algebraic form of the points to the text pane. + */ protected void addAlgebraicForm() { addString2s(getLanguage(1101, "The Algebraic Form:")); Vector vp = dp.getPointList(); @@ -147,10 +206,13 @@ protected void addAlgebraicForm() { addString1("\n"); } - + /** + * Handles action events for the panel. + * + * @param e the action event + */ public void actionPerformed(ActionEvent e) { JTextArea a = new JTextArea(); -// a.setWrapStyleWord(true); a.setLineWrap(true); String s = GeoPoly.getInstance().getExpandedPrint(_mremainder); a.setText(s); @@ -163,81 +225,28 @@ public void actionPerformed(ActionEvent e) { dlg.setVisible(true); } + /** + * Scrolls the text pane to the end. + */ protected void scrollToEnd() { JScrollBar bar = this.getVerticalScrollBar(); bar.setValue(bar.getMaximum()); repaint(); } + /** + * Retrieves the TMono representation of the specified construction. + * + * @param c the construction + * @return the TMono representation of the construction + */ protected TMono getTMono(Cons c) { return dp.getTMono(c); } + /** + * Runs the panel's main process. + */ public void run() { } - - public TPoly get_ndgs(Vector vlist, int z) { - TPoly pp = null; - for (int i = 0; i < vlist.size(); i++) { - Cons c = (Cons) vlist.get(i); - if (c.type != Gib.C_POINT) { - TMono mx = dp.getTMono(c); - if (mx != null) { - mx = poly.n_ndg(mx, z++); - pp = poly.ppush(mx, pp); - } - } - } - return pp; - } - - public Vector get_ndgs(int param, Vector vlist) { - - Vector pp = new Vector(); - for (int i = 0; i < vlist.size(); i++) { - Cons c = (Cons) vlist.get(i); - if (c.type != Gib.C_POINT) { - TMono mx = get_ndg(param--, c.type, dp.getPoints(c)); - if (mx != null) - pp.add(0, mx); - } - } - return pp; - } - - public Vector get_ndgsx(int param, Vector vlist) { - - Vector pp = new Vector(); - for (int i = 0; i < vlist.size(); i++) { - TMono m = (TMono) vlist.get(i); - m = poly.n_ndg(m, param--); - poly.ppush(m, pp); - } - return pp; - } - - public TMono get_ndg(int z, int t, CPoint[] pp) { - switch (t) { - case Gib.C_I_LL: // AB // CD. - return poly.n_ndg(poly.parallel(pp[1], pp[2], pp[3], pp[4]), z); - case Gib.C_I_LP: - return poly.n_ndg(poly.parallel(pp[1], pp[2], pp[4], pp[5]), z); - case Gib.C_I_LT: - return poly.n_ndg(poly.perpendicular(pp[1], pp[2], pp[4], pp[5]), z); - case Gib.C_I_PP: - return poly.n_ndg(poly.parallel(pp[2], pp[3], pp[5], pp[6]), z); - case Gib.C_FOOT: - return poly.n_ndg(poly.isotropic(pp[2], pp[3]), z); - case Gib.C_I_LB: - return poly.n_ndg(poly.perpendicular(pp[0], pp[1], pp[2], pp[3]), z); - case Gib.C_SQUARE: - return poly.n_ndg(poly.isotropic(pp[0], pp[1]), z); - case Gib.C_O_C: - return poly.n_ndg(poly.isotropic(pp[1], pp[2]), z); - case Gib.C_CIRCUM: - return poly.n_ndg(poly.collinear(pp[1], pp[2], pp[3]), z); - - } - return null; - } } \ No newline at end of file diff --git a/src/main/java/wprover/PanelGB.java b/src/main/java/wprover/PanelGB.java index df852585..c81be81a 100644 --- a/src/main/java/wprover/PanelGB.java +++ b/src/main/java/wprover/PanelGB.java @@ -1,6 +1,5 @@ package wprover; -import gprover.CNdg; import gprover.Cons; import gprover.GTerm; import maths.PolyBasic; @@ -18,6 +17,12 @@ import java.io.FileOutputStream; import java.io.IOException; +/** + * PanelGB is a graphical panel for performing Groebner basis computations. + * It extends the PanelAlgebraic class and implements MouseListener for handling mouse events. + * This class provides methods to compute Groebner bases, handle user interactions, + * and save results in Maple format. + */ public class PanelGB extends PanelAlgebraic implements MouseListener { private Vector vndgs; @@ -25,6 +30,12 @@ public class PanelGB extends PanelAlgebraic implements MouseListener { private static long TIME = 1000000; private JPopupMenu menu; + /** + * Constructs a new PanelGB with the specified DrawProcess and WuTextPane. + * + * @param dp the DrawProcess instance to associate with this panel + * @param tpane the WuTextPane instance to associate with this panel + */ public PanelGB(DrawProcess dp, WuTextPane tpane) { super(dp, tpane); menu = new JPopupMenu(); @@ -38,17 +49,23 @@ public void actionPerformed(ActionEvent e) { tpane.addMouseListener(this); } - + /** + * Stops the running process and updates the status. + */ public void stopRunning() { running = false; PolyBasic.setbbStop(true); this.addString("\n"); this.addString("icon4", "icon4"); this.addString(GExpert.getLanguage("The Process Is Stopped By The User.")); - } - + /** + * Initiates the proving process with the given GTerm and DrawProcess. + * + * @param tm the GTerm instance representing the term to prove + * @param dp the DrawProcess instance to use for proving + */ public void prove(GTerm tm, DrawProcess dp) { if (running) return; @@ -62,6 +79,9 @@ public void prove(GTerm tm, DrawProcess dp) { startTimer(); } + /** + * Starts a timer to monitor the running process. + */ public void startTimer() { if (gxInstance != null) { Timer t = new Timer(1000, new ActionListener() { @@ -77,10 +97,15 @@ public void actionPerformed(ActionEvent e) { t.start(); } - } - + /** + * Divides the given polynomial by the terms in the specified TPoly. + * + * @param m1 the polynomial to divide + * @param p1 the TPoly containing the terms to divide by + * @return 0 if the division is successful, 1 if the process is interrupted + */ protected int div(TMono m1, TPoly p1) { if (poly.pzerop(m1)) return 0; @@ -109,7 +134,6 @@ protected int div(TMono m1, TPoly p1) { int k = 0; } long t1 = System.currentTimeMillis(); -// addDiv(--index, m1, m.x, t1 - time); time = t1; if (poly.pzerop(m1)) return 0; @@ -122,68 +146,20 @@ protected int div(TMono m1, TPoly p1) { return 1; } + /** + * Retrieves the TMono representation of the specified construction. + * + * @param c the construction + * @return the TMono representation of the construction + */ protected TMono getTMono(Cons c) { return dp.getTMono(c); } - public int addMM(TMono m, Vector v, int param) { - GeoPoly gp = GeoPoly.getPoly(); - - if (gp.plength(m) == 1) { - while (m != null && m.deg > 0 && m.x > 0) { - TMono m1 = gp.pth(m.x, 1, 1); - m1 = gp.n_ndg(m1, param--); - v.add(m1); - m = m.coef; - } - } else { - m = gp.n_ndg(m, param--); - v.add(m); - } - - return param; - - } - - private boolean is_ndg_set() { - return gt != null && gt.getNcons().size() > 0; - } - - public void getNDGS(Vector v3) { - int t = 3; - int param = -1; - GeoPoly gp = GeoPoly.getPoly(); - - if (t == 3) { - vndgs = gt.getNcons(); - } - - - if (t == 0 || t == 3) { // from FULL - for (int i = 0; i < vndgs.size(); i++) { - CNdg nd = (CNdg) vndgs.get(i); - TMono m = gp.mm_poly(nd, dp); - addString1(nd.toString() + "\n"); - if (m != null) { - param = addMM(m, v3, param); - - - } - } - } else if (t == 1) { // from DB - Vector v = dp.getNDGS(); - for (int i = 0; i < v.size(); i++) { - TMono m = (TMono) v.get(i); - if (m != null) { - param = addMM(m, v3, param); - } - } - } - } - - + /** + * Runs the main process for computing the Groebner basis. + */ public void run() { - if (gt == null) { running = false; if (rund != null) @@ -191,9 +167,6 @@ public void run() { return; } -// /if (is_ndg_set()) -// this.gbasis1(); -// else gbasis(); PolyBasic.setbbStop(false); @@ -202,148 +175,11 @@ public void run() { rund.stopTimer(); } - public void gbasis1() { - - String sc = gt.getConcText(); - Cons cc = gt.getConclusion(); - - TMono mc = getTMono(cc); - if (mc == null) { - running = false; - return; - } - - - addAlgebraicForm(); - addString2("The equational hypotheses:"); - - Vector vc = dp.getAllConstraint(); - int n = 1; - Vector pp = new Vector(); - - - for (int i = 0; i < vc.size(); i++) { - Constraint c = (Constraint) vc.get(i); - if (c.is_poly_genereate) { - c.PolyGenerate(); - TPoly p1 = Constraint.getPolyListAndSetNull(); - if (p1 != null) - addString1(n++ + ": " + c.toString() + "\n"); - while (p1 != null) { - TMono m = p1.getPoly(); - if (m != null) { - poly.ppush(m, pp); - addString(" " + poly.printSPoly(m)); - } - p1 = p1.next; - } - } - } - - - addString2("Nondegenerate Conditions"); - Vector v3 = new Vector(); - this.getNDGS(v3); - Vector p = v3; - printTP(p); - - - for (int i = 0; i < p.size(); i++) { - TMono m = (TMono) p.get(i); - poly.ppush(m, pp); - } - - if (prs) { - addString2("Poly set before gbasis"); - printTP(pp); - } - - int dx = p.size() + 2; - poly.upValueTM(pp, dx); - - int index = 1; - long t = System.currentTimeMillis(); - - boolean r1 = false; -// if (true) { -// sbasis(); -// return; -// } - - while (true) { - if (index == 2) { - int k = 0; - } - - if (!prs) { - addString2(index + ": Poly set before bb-reduce"); - printTP(pp); - } - r1 = true; - - - pp = poly.bb_reduce(pp, t); - // if (System.currentTimeMillis() - t > 10000) - // break; - - if (!prs) { - addString2(index++ + ": Poly set after bb-reduce"); - printTP(pp); - } -// } - if (gb_finished(pp)) - break; - // if (pp.size() > 30) - // break; - - Vector tp = poly.s_polys(pp); - if (tp.size() != 0) { - tp = poly.bb_reduce(tp, t); - if (!prs) { - addString2("S - Polynomials"); - printTP(tp); - } -// } - for (int i = 0; i < tp.size(); i++) - poly.ppush((TMono) tp.get(i), pp); - } else { - break; - } - if (!running) - return; - } - - - String s1 = poly.printSPoly(mc); - poly.upValueTM(mc, dx); - mc = poly.b_reduce(mc, pp); - poly.upValueTM(mc, -dx); - poly.upValueTM(pp, -dx); - String s2 = poly.printSPoly(mc); - - if (prs) { - addString2("Poly set after gbasis"); - printTP(pp); - } - - - addString2("The conclusion: "); - addString1(sc + "\n"); - - addString(s1); - addString2("The conclusion after reduce:"); - addString(s2); - - if (mc == null) { - addString("icon1", "icon1"); - addString1("The conclusion is true"); - } else { - addString("icon2", "icon2"); - addString1("The conclusion is false"); - } - running = false; - } - + /** + * Prints the terms in the specified vector to the text pane. + * + * @param v the vector containing the terms to print + */ public void printTP(Vector v) { for (int i = 0; i < v.size(); i++) { TMono m = (TMono) v.get(i); @@ -352,6 +188,12 @@ public void printTP(Vector v) { } } + /** + * Checks if the Groebner basis computation is finished. + * + * @param v the vector containing the terms to check + * @return true if the computation is finished, false otherwise + */ public boolean gb_finished(Vector v) { for (int i = 0; i < v.size(); i++) { TMono m = (TMono) v.get(i); @@ -361,10 +203,15 @@ public boolean gb_finished(Vector v) { return false; } + /** + * Tests the Groebner basis computation with the specified polynomial vector and index. + * + * @param pp the vector containing the polynomial terms + * @param dx the index value for the computation + */ public void test(Vector pp, int dx) { int size = pp.size(); - if (size < 2) return; int index = size - 3; @@ -372,7 +219,6 @@ public void test(Vector pp, int dx) { for (int i = size - 2; i < size; i++) vp.add(pp.get(i)); - for (int i = index; i >= 0; i--) { addString2(i + "GBASIS"); printTP(vp); @@ -384,14 +230,14 @@ public void test(Vector pp, int dx) { addString2(-1 + "GBASIS"); poly.upValueTM(vp, -dx); printTP(vp); - - } - + /** + * Computes the Groebner basis for the specified polynomial vector. + * + * @param pp the vector containing the polynomial terms + */ public void gbasis(Vector pp) { -// long t = System.currentTimeMillis(); - while (true) { pp = poly.bb_reduce(pp, 10000); if (!isRunning()) @@ -400,63 +246,30 @@ public void gbasis(Vector pp) { if (gb_finished(pp)) break; - Vector tp = poly.s_polys(pp); if (tp.size() != 0) { for (int i = 0; i < tp.size(); i++) poly.ppush((TMono) tp.get(i), pp); - } else { break; } } } - public void dbasis(Vector pp) { - - GeoPoly basic = GeoPoly.getPoly(); - - Vector v = new Vector(); - int size = pp.size(); - for (int i = 0; i < size - 1; i++) { - TMono m1 = (TMono) pp.get(i); - for (int j = i + 1; j < size; j++) { - TMono m2 = (TMono) pp.get(j); - v.clear(); - v.add(basic.p_copy(m1)); - v.add(basic.p_copy(m2)); - - basic.printVpoly(v); - while (true) { - v = poly.bb_reduce(v, -1); - - if (gb_finished(v)) - break; - - - Vector tp = poly.s_polys(v); - - if (v.size() >= 1) { - basic.printVpoly(v); - basic.printVpoly(tp); - } - tp = poly.bb_reduce(tp, -1); - - - if (tp.size() != 0) { - for (int k = 0; k < tp.size(); k++) - poly.ppush((TMono) tp.get(k), v); - } else { - break; - } - } - basic.printVpoly(v); - } - } - } - - + /** + * Computes a modified Groebner basis (SBasis) for the given polynomial vector and conclusion. + * + *

This method selects and removes polynomial terms from the vector based on the provided index, + * computes intermediate deltas and nondegenerate conditions, and applies a series of polynomial + * updates and reductions. It modifies the input vector with updated terms and returns the reduced + * conclusion polynomial.

+ * + * @param x the maximum index value controlling term selection and iterations + * @param v the vector of polynomial terms (TMono objects) to be processed and updated + * @param mc the conclusion polynomial term (TMono) to be reduced + * @return the reduced conclusion polynomial or {@code null} if the process is interrupted + */ public TMono sbasis(int x, Vector v, TMono mc) { Vector vg = new Vector(); @@ -601,28 +414,16 @@ public TMono sbasis(int x, Vector v, TMono mc) { return mc; } - public void printVectorExpanded(Vector vrs, int dx) { - GeoPoly basic = GeoPoly.getPoly(); - - basic.upValueTM(vrs, -dx); - for (int i = 0; i < vrs.size(); i++) { - TMono ma = (TMono) vrs.get(i); - String st = basic.getExpandedPrint(ma); - if (st.endsWith("*")) - st = st.substring(0, st.length() - 1); - else if (st.endsWith("-") || st.endsWith("+")) - st += "1"; - System.out.println(st); - } - basic.upValueTM(vrs, dx); - } - + /** + * Adds the non-degenerate conditions to the text pane. + * + * @param v the vector containing the non-degenerate conditions + */ public void addSVdd(Vector v) { GeoPoly basic = GeoPoly.getPoly(); addString2(GExpert.getLanguage("The Nondegenerate Conditions:")); for (int i = 0; i < v.size(); i++) { -// TDono d = (TDono) v.get(i); TMono m = (TMono) v.get(i); basic.coefgcd(m); TMono mf = basic.get_factor1(m); @@ -638,32 +439,13 @@ public void addSVdd(Vector v) { } String s = basic.printNPoly(ff, m); this.addString(s); - } } - - } - - public void printVDD(Vector v) { - GeoPoly basic = GeoPoly.getPoly(); - - for (int i = 0; i < v.size(); i++) { - - TDono d = (TDono) v.get(i); - basic.sprint(d.p1); - System.out.print("*( "); - basic.sprint(d.p2); - System.out.print(" )"); - if (d.c.value() > 0) - System.out.print(" + "); - basic.sprint(d.c); - System.out.print("\n"); - - - } - } + /** + * Computes the Groebner basis for the current set of constraints and updates the text pane. + */ public void gbasis() { GeoPoly basic = GeoPoly.getPoly(); String sc = gt.getConcText(); @@ -674,7 +456,6 @@ public void gbasis() { return; } - addAlgebraicForm(); addString2(GExpert.getLanguage("The equational hypotheses:")); @@ -682,7 +463,6 @@ public void gbasis() { int n = 1; Vector pp = new Vector(); - for (int i = 0; i < vc.size(); i++) { Constraint c = (Constraint) vc.get(i); if (c.is_poly_genereate) { @@ -706,8 +486,7 @@ public void gbasis() { String s1 = poly.printSPoly(mc); - addString2(GExpert.getLanguage("The Groebner basis:") /* + "GB = " */); -// addString2("GB = "); + addString2(GExpert.getLanguage("The Groebner basis:")); Vector v = dp.getPBMono(); int x = basic.getMaxX(v); @@ -742,8 +521,11 @@ public void gbasis() { running = false; } - - //////////////////////////////////////////////////////////// + /** + * Handles mouse click events to show the popup menu. + * + * @param e the mouse event + */ public void mouseClicked(MouseEvent e) { menu.show((JComponent) e.getSource(), e.getX(), e.getY()); } @@ -760,6 +542,12 @@ public void mouseEntered(MouseEvent e) { public void mouseExited(MouseEvent e) { } + /** + * Saves the current data in Maple format. + * Opens a file chooser dialog to select the save location. + * If the file exists, it will be overwritten. + * If the file does not exist, it will be created. + */ public void saveAsMaple() { JFileChooser filechooser1 = new JFileChooser(); String dr = GExpert.getUserDir(); @@ -785,10 +573,15 @@ public void saveAsMaple() { JOptionPane.showMessageDialog(this, ee.getMessage(), "Save Failed", JOptionPane.ERROR_MESSAGE); } - } } + /** + * Writes the current data in Maple format to the specified output stream. + * + * @param out the output stream to write the data to + * @throws IOException if an I/O error occurs + */ public void writeMaple(FileOutputStream out) throws IOException { GeoPoly basic = GeoPoly.getPoly(); Cons cc = gt.getConclusion(); @@ -813,7 +606,6 @@ public void writeMaple(FileOutputStream out) throws IOException { out.write((s2 + ", " + s1).getBytes()); } - Vector v = dp.getPBMono(); int x = basic.getMaxX(v); @@ -855,15 +647,13 @@ public void writeMaple(FileOutputStream out) throws IOException { } out.write("];".getBytes()); -// Part 2: All polynomials. -// out.write(("\n" + vg.size()).getBytes()); + // Part 2: All polynomials. for (int i = 0; i < vg.size(); i++) { TMono m = (TMono) vg.get(i); out.write("\n".getBytes()); - out.write(("P" + i + " := " + poly.getExpandedPrint(m) +" ;").getBytes()); + out.write(("P" + i + " := " + poly.getExpandedPrint(m) + " ;").getBytes()); } String st = poly.getExpandedPrint(mc); - out.write(("\n C := " + st +" ;").getBytes()); - + out.write(("\n C := " + st + " ;").getBytes()); } } \ No newline at end of file diff --git a/src/main/java/wprover/PanelProve.java b/src/main/java/wprover/PanelProve.java index 9c2d5043..73891961 100644 --- a/src/main/java/wprover/PanelProve.java +++ b/src/main/java/wprover/PanelProve.java @@ -28,6 +28,12 @@ import static org.graphper.api.Html.table; import static org.graphper.api.Html.td; +/** + * PanelProve is a class that represents a tabbed pane for displaying various + * proof-related panels in a graphical user interface (GUI). It includes panels + * for construction, GDD (General Deduction), area method, manual proof editor, + * and database. + */ public class PanelProve extends JTabbedPane implements ChangeListener { // private Font font_thm = new Font("Dialog", Font.BOLD, 12); diff --git a/src/main/java/wprover/PanelWu.java b/src/main/java/wprover/PanelWu.java index cab6d114..e796b7d6 100644 --- a/src/main/java/wprover/PanelWu.java +++ b/src/main/java/wprover/PanelWu.java @@ -11,24 +11,48 @@ import maths.TMono; import maths.TPoly; +/** + * PanelWu is a class that extends PanelAlgebraic and implements Runnable and + * MouseListener interfaces. It provides functionality for proving theorems + * using Wu's method and displaying the results in a text pane. + */ public class PanelWu extends PanelAlgebraic implements Runnable, MouseListener { private TMono mremainder; + /** + * Constructs a new PanelWu with the specified DrawProcess and WuTextPane. + * + * @param dp the DrawProcess instance to associate with this panel + * @param tpane the WuTextPane instance to associate with this panel + */ public PanelWu(DrawProcess dp, WuTextPane tpane) { super(dp, tpane); tpane.addMouseListener(this); } + /** + * Sets the language for the panel. + * + * @param lan the Language instance to set + */ public void setLanguage(Language lan) { this.lan = lan; } + /** + * Stops the running process if it is currently running. + */ public void stopRunning() { if (!running) return; } + /** + * Initiates the proving process with the given GTerm. + * + * @param tm the GTerm instance representing the term to prove + */ public void prove(GTerm tm) { if (running) return; @@ -40,6 +64,14 @@ public void prove(GTerm tm) { main.start(); } + /** + * Adds a division step to the text pane. + * + * @param index the index of the division step + * @param m1 the TMono instance representing the polynomial + * @param x the variable index + * @param t the time taken for the division step + */ protected void addDiv(int index, TMono m1, int x, long t) { index++; String s = "R_" + (index - 1) + " = prem(R_" + index + ", h_" + (index - 1) + ") = [" @@ -47,6 +79,13 @@ protected void addDiv(int index, TMono m1, int x, long t) { addString(s); } + /** + * Divides the given polynomial by the terms in the specified TPoly. + * + * @param m1 the polynomial to divide + * @param p1 the TPoly containing the terms to divide by + * @return 0 if the division is successful, 1 if the process is interrupted + */ protected int div(TMono m1, TPoly p1) { if (poly.pzerop(m1)) return 0; @@ -96,13 +135,21 @@ protected int div(TMono m1, TPoly p1) { return 1; } + /** + * Retrieves the TMono representation of the specified construction. + * + * @param c the construction + * @return the TMono representation of the construction + */ public TMono getTMono(Cons c) { TMono m = dp.getTMono(c); return m; } - + /** + * Runs the main process for computing the Groebner basis. + */ public void run() { if (gt == null) { running = false; @@ -141,7 +188,6 @@ public void run() { } } - addString2(GExpert.getLanguage("The Triangulized Hypotheses:")); TPoly p1 = dp.getPolyList(); int i = 0; @@ -150,7 +196,6 @@ public void run() { p1 = p1.next; } - addString2(GExpert.getLanguage("The conclusion:")); addString1(sc + "\n"); addString(poly.printSPoly(mc)); @@ -189,6 +234,11 @@ public void run() { running = false; } + /** + * Handles mouse click events to show the popup menu. + * + * @param e the mouse event + */ public void mouseClicked(MouseEvent e) { if (e.getClickCount() > 1) { if (mremainder != null) { diff --git a/src/main/java/wprover/Parser.java b/src/main/java/wprover/Parser.java index 7f63b508..905b475d 100644 --- a/src/main/java/wprover/Parser.java +++ b/src/main/java/wprover/Parser.java @@ -3,11 +3,8 @@ import maths.TMono; /** - * Created by IntelliJ IDEA. - * User: ye - * Date: 2008-8-30 - * Time: 10:10:17 - * To change this template use File | Settings | File Templates. + * Parser is a class that parses a mathematical expression represented as a string + * and converts it into a TMono object. */ public class Parser { private static GeoPoly poly = GeoPoly.getPoly(); @@ -18,6 +15,13 @@ public class Parser { int id; int param; + /** + * Constructs a new Parser with the specified name, function, and parameter. + * + * @param n the name of the parser + * @param f the function to parse + * @param x the parameter for the parser + */ public Parser(String n, String f, int x) { m1 = null; sname = n; @@ -26,6 +30,11 @@ public Parser(String n, String f, int x) { param = x; } + /** + * Parses the function string and converts it into a TMono object. + * + * @return the TMono object representing the parsed function + */ public TMono parse() { byte[] bf = sfunc.getBytes(); byte[] nm = sname.getBytes(); @@ -34,14 +43,33 @@ public TMono parse() { return m1; } + /** + * Checks if the given byte represents a numeric character. + * + * @param b the byte to check + * @return true if the byte is a numeric character, false otherwise + */ public boolean isNum(byte b) { return b >= '0' && b <= '9'; } + /** + * Checks if the given byte represents an alphabetic character. + * + * @param b the byte to check + * @return true if the byte is an alphabetic character, false otherwise + */ public boolean isAlpha(byte b) { - return b >= 'a' && b <= 'z' || b >= 'A' && b <= 'z'; + return b >= 'a' && b <= 'z' || b >= 'A' && b <= 'Z'; } + /** + * Parses a term from the function string and updates the TMono object. + * + * @param first indicates if this is the first term being parsed + * @param bf the byte array representing the function string + * @param nm the byte array representing the name string + */ public void parseterm(boolean first, byte[] bf, byte[] nm) { while (true) { if (id >= bf.length) @@ -70,6 +98,12 @@ public void parseterm(boolean first, byte[] bf, byte[] nm) { } } + /** + * Skips blank spaces in the function string. + * + * @param bf the byte array representing the function string + * @param nm the byte array representing the name string + */ public void parseBlank(byte[] bf, byte[] nm) { while (bf[id] == 32) { if (id >= bf.length) @@ -78,6 +112,13 @@ public void parseBlank(byte[] bf, byte[] nm) { } } + /** + * Parses a term from the function string and returns it as a TMono object. + * + * @param bf the byte array representing the function string + * @param nm the byte array representing the name string + * @return the TMono object representing the parsed term + */ public TMono getAterm(byte[] bf, byte[] nm) { parseBlank(bf, nm); @@ -112,5 +153,4 @@ public TMono getAterm(byte[] bf, byte[] nm) { else return poly.pth(0, value, 0); } - } diff --git a/src/main/java/wprover/RatioSelectDialog.java b/src/main/java/wprover/RatioSelectDialog.java index fe61c32b..e6a92b7e 100644 --- a/src/main/java/wprover/RatioSelectDialog.java +++ b/src/main/java/wprover/RatioSelectDialog.java @@ -10,11 +10,8 @@ import java.awt.event.ActionListener; /** - * Created by IntelliJ IDEA. - * User: ye - * Date: Nov 29, 2006 - * Time: 1:01:15 PM - * To change this template use File | Settings | File Templates. + * RatioSelectDialog is a dialog that allows the user to input two integers + * representing a ratio. It extends JBaseDialog and implements ActionListener. */ public class RatioSelectDialog extends JBaseDialog implements ActionListener { IntTextField field1, field2; @@ -22,6 +19,11 @@ public class RatioSelectDialog extends JBaseDialog implements ActionListener { boolean returnValue; + /** + * Constructs a new RatioSelectDialog with the specified GExpert instance. + * + * @param f the GExpert instance to associate with this dialog + */ public RatioSelectDialog(GExpert f) { super(f.getFrame(), true); this.setTitle(f.getLanguage("Set the ratio")); @@ -61,9 +63,13 @@ public RatioSelectDialog(GExpert f) { if (CMisc.isApplication()) this.setAlwaysOnTop(true); - } + /** + * Handles action events for the dialog buttons. + * + * @param e the ActionEvent triggered by the buttons + */ public void actionPerformed(ActionEvent e) { if (e.getSource() == button1) returnValue = true; @@ -71,16 +77,29 @@ public void actionPerformed(ActionEvent e) { this.setVisible(false); } + /** + * Gets the value from the first input field. + * + * @return the integer value from the first input field + */ public int getValue1() { String s = field1.getText(); return Integer.parseInt(s); } + /** + * Gets the value from the second input field. + * + * @return the integer value from the second input field + */ public int getValue2() { String s = field2.getText(); return Integer.parseInt(s); } + /** + * Centers the dialog window relative to its owner. + */ public void centerWindow() { Window wo = this.getOwner(); int x = wo.getX(); @@ -90,15 +109,34 @@ public void centerWindow() { this.setLocation(x + w / 2 - 200 / 2, y + h / 2 - 120 / 2); } + /** + * IntTextField is a custom JTextField that only accepts integer input. + */ class IntTextField extends JTextField { + /** + * Constructs a new IntTextField with the specified default value and size. + * + * @param defval the default integer value + * @param size the size of the text field + */ public IntTextField(int defval, int size) { super("" + defval, size); } + /** + * Creates the default model for the text field, which is an IntTextDocument. + * + * @return the default document model + */ protected Document createDefaultModel() { return new IntTextDocument(); } + /** + * Checks if the current text in the field is a valid integer. + * + * @return true if the text is a valid integer, false otherwise + */ public boolean isValid() { try { Integer.parseInt(getText()); @@ -110,6 +148,11 @@ public boolean isValid() { } } + /** + * Gets the integer value from the text field. + * + * @return the integer value, or 0 if the text is not a valid integer + */ public int getValue() { try { return Integer.parseInt(getText()); @@ -118,7 +161,18 @@ public int getValue() { } } + /** + * IntTextDocument is a custom PlainDocument that only allows integer input. + */ class IntTextDocument extends PlainDocument { + /** + * Inserts a string into the document, ensuring that it remains a valid integer. + * + * @param offs the offset at which to insert the string + * @param str the string to insert + * @param a the attribute set + * @throws BadLocationException if the insert position is invalid + */ public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { if (str == null) diff --git a/src/main/java/wprover/RectChooser.java b/src/main/java/wprover/RectChooser.java index 9f5e61af..95423c2c 100644 --- a/src/main/java/wprover/RectChooser.java +++ b/src/main/java/wprover/RectChooser.java @@ -9,11 +9,9 @@ import java.awt.event.*; /** - * Created by IntelliJ IDEA. - * User: ye - * Date: 2008-4-10 - * Time: 19:06:31 - * To change this template use File | Settings | File Templates. + * RectChooser is a class that extends JBaseDialog and implements various mouse + * and action listeners. It is used to create a dialog for selecting a rectangle + * area on a drawing panel. */ public class RectChooser extends JBaseDialog implements MouseListener, MouseMotionListener, MouseWheelListener, ActionListener { @@ -31,15 +29,20 @@ public class RectChooser extends JBaseDialog implements MouseListener, MouseMoti private JButton bok, bcancel; private boolean result = false; + /** + * Constructs a new RectChooser dialog with the specified GExpert instance. + * + * @param gx the GExpert instance to associate with this dialog + */ public RectChooser(GExpert gx) { super(gx.getFrame(), true); this.setTitle(gx.getLanguage("Please choose the client area")); this.gxInstance = gx; -// this.setUndecorated(true); + // this.setUndecorated(true); rx = ry = 0; zoom = 1.00; -// this.addWindowListener((new WindowDispose(this)); + // this.addWindowListener((new WindowDispose(this)); DPanel d = gx.d; width = d.getWidth(); height = d.getHeight(); @@ -95,7 +98,6 @@ public RectChooser(GExpert gx) { rx = (int) (rc.getX() + rc.getWidth() / 2); ry = (int) (rc.getY() + rc.getHeight() / 2); - updateField(); updateButton(); @@ -112,7 +114,6 @@ public RectChooser(GExpert gx) { if (hh > h1) hh = h1; - dm1.setSize(ww, hh + 35); this.setSize(dm1); @@ -120,7 +121,9 @@ public RectChooser(GExpert gx) { this.setVisible(true); } - + /** + * Enlarges the rectangle by a specified edge size. + */ public void enlargeRect() { int edge = 15; int x = (int) rc.getX() - edge; @@ -132,14 +135,29 @@ public void enlargeRect() { rc.setSize((int) rc.getWidth() + 2 * edge, (int) rc.getHeight() + 2 * edge); } + /** + * Returns the result of the dialog. + * + * @return true if the OK button was pressed, false otherwise + */ public boolean getReturnResult() { return result; } + /** + * Returns the selected rectangle. + * + * @return the selected Rectangle + */ public Rectangle getSelectedRectangle() { return rc; } + /** + * Handles action events for the OK and Cancel buttons. + * + * @param e the ActionEvent triggered by the buttons + */ public void actionPerformed(ActionEvent e) { if (e.getSource() == bok) { result = true; @@ -147,9 +165,11 @@ public void actionPerformed(ActionEvent e) { result = false; } this.setVisible(false); - } + /** + * Updates the text fields with the current rectangle coordinates and size. + */ public void updateField() { field1.setText(Integer.toString((int) rc.getX())); field2.setText(Integer.toString((int) rc.getY())); @@ -159,6 +179,9 @@ public void updateField() { fieldh.setText(Integer.toString((int) rc.getHeight())); } + /** + * Updates the state of the OK button based on the rectangle size and pressed state. + */ public void updateButton() { if (pressed) bok.setEnabled(false); @@ -167,9 +190,19 @@ else if (Math.abs(rc.getWidth()) < 10 || Math.abs(rc.getHeight()) < 10) else bok.setEnabled(true); } + /** + * Handles mouse clicked events. + * + * @param e the MouseEvent triggered by clicking the mouse + */ public void mouseClicked(MouseEvent e) { } + /** + * Handles mouse pressed events to start drawing the rectangle. + * + * @param e the MouseEvent triggered by pressing the mouse + */ public void mousePressed(MouseEvent e) { pressed = true; int x = e.getX(); @@ -189,6 +222,11 @@ public void mousePressed(MouseEvent e) { dpane.repaint(); } + /** + * Handles mouse released events to finalize the rectangle. + * + * @param e the MouseEvent triggered by releasing the mouse + */ public void mouseReleased(MouseEvent e) { pressed = false; updateButton(); @@ -201,18 +239,39 @@ public void mouseReleased(MouseEvent e) { dpane.repaint(); } + /** + * Handles mouse entered events. + * + * @param e the MouseEvent triggered by entering a component + */ public void mouseEntered(MouseEvent e) { } + /** + * Handles mouse exited events. + * + * @param e the MouseEvent triggered by exiting a component + */ public void mouseExited(MouseEvent e) { } + /** + * Handles mouse dragged events to update the rectangle's size. + * + * @param e the MouseEvent triggered by dragging the mouse + */ public void mouseDragged(MouseEvent e) { int x = e.getX(); int y = e.getY(); dragto(x, y); } + /** + * Updates the rectangle's size based on the dragged mouse coordinates. + * + * @param x the x-coordinate of the mouse + * @param y the y-coordinate of the mouse + */ public void dragto(int x, int y) { int x1 = (int) rc.getX(); int y1 = (int) rc.getY(); @@ -227,9 +286,19 @@ public void dragto(int x, int y) { dpane.repaint(); } + /** + * Handles mouse moved events. + * + * @param e the MouseEvent triggered by moving the mouse + */ public void mouseMoved(MouseEvent e) { } + /** + * Handles mouse wheel moved events to zoom in or out. + * + * @param e the MouseWheelEvent triggered by moving the mouse wheel + */ public void mouseWheelMoved(MouseWheelEvent e) { int n = e.getScrollAmount(); int r = e.getWheelRotation(); @@ -245,17 +314,31 @@ public void mouseWheelMoved(MouseWheelEvent e) { dpane.repaint(); } + /** + * Converts the x-coordinate based on the current zoom level. + * + * @param x the original x-coordinate + * @return the zoomed x-coordinate + */ public int getZoomX(int x) { x = x - rx; return (int) (x / zoom + rx); } + /** + * Converts the y-coordinate based on the current zoom level. + * + * @param y the original y-coordinate + * @return the zoomed y-coordinate + */ public int getZoomY(int y) { y = y - ry; return (int) (y / zoom + ry); } - + /** + * Custom JTextField class with fixed preferred and maximum sizes. + */ class TextField extends JTextField { public TextField() { super(); @@ -263,25 +346,32 @@ public TextField() { public Dimension getPreferredSize() { Dimension dm = super.getPreferredSize(); -// if (dm.getWidth() > 30) dm.setSize(40, dm.getHeight()); return dm; } public Dimension getMaximumSize() { Dimension dm = super.getMaximumSize(); -// if (dm.getWidth() > 30) dm.setSize(40, dm.getHeight()); return dm; } + /** + * Gets the integer value from the text field. + * + * @return the integer value + */ public int getValue() { String s = this.getText(); return Integer.parseInt(s); } - } + /** + * Handles key pressed events to move the rectangle or confirm the selection. + * + * @param e the KeyEvent triggered by pressing a key + */ public void keyPressed(KeyEvent e) { super.keyPressed(e); @@ -312,9 +402,11 @@ public void keyPressed(KeyEvent e) { rc.setLocation((int) x, (int) y); this.updateField(); this.repaint(); - } + /** + * Custom JPanel class for drawing the rectangle and handling mouse events. + */ class drawPane extends JPanel { public drawPane() { @@ -330,7 +422,6 @@ protected void paintComponent(Graphics g) { if (gxInstance != null) { gxInstance.dp.paintPoint(g); g2.setColor(Color.red); - // g2.setStroke(CMisc.NormalLineStroke); g2.setStroke(CMisc.DashedStroke1); if (Math.abs(rc.getWidth()) > 10 && Math.abs(rc.getHeight()) > 10) { g2.drawRect((int) rc.getX(), (int) rc.getY(), (int) rc.getWidth(), (int) rc.getHeight()); diff --git a/src/main/java/wprover/RectChooser1.java b/src/main/java/wprover/RectangleSelectionDialog.java similarity index 61% rename from src/main/java/wprover/RectChooser1.java rename to src/main/java/wprover/RectangleSelectionDialog.java index 168b5e9d..bc7b62b8 100644 --- a/src/main/java/wprover/RectChooser1.java +++ b/src/main/java/wprover/RectangleSelectionDialog.java @@ -1,219 +1,301 @@ -package wprover; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.*; -import java.awt.image.BufferedImage; - -/** - * Created by IntelliJ IDEA. - * User: ye - * Date: 2008-6-26 - * Time: 11:20:51 - * To change this template use File | Settings | File Templates. - */ - -// TODO. This class should be renamed. -public class RectChooser1 extends JBaseDialog implements MouseListener, MouseMotionListener, - ComponentListener, ActionListener, Runnable { - - private int x2, y2, x1, y1; - private GExpert gxInstance; - private JPanel contentPane; - private JComponent content; - private double dx, dy; - private boolean result = false; - -// private int nnn = 1; - - public boolean getResult() { - return result; - } - - public RectChooser1(GExpert gx) { - super(gx.getFrame(), GExpert.getLanguage("Choose a rectangle"), true); - JPanel ppp = new JPanel(); - ppp.setLayout(new BoxLayout(ppp, BoxLayout.Y_AXIS)); - - - gxInstance = gx; - content = gx.getContent(); - Point pt = content.getLocation(); - dx = pt.getX(); - dy = pt.getY(); - - contentPane = new JPanel() { - public Dimension getPreferredSize() { - return content.getSize(); - } - - - public void paintComponent(Graphics g) { - super.paintComponent(g); -// super.paintAll(); - //this.pai - Graphics2D g2 = (Graphics2D) g; -// g2.translate(-dx, -dy); - g2.drawImage(image, 0, 0, null); - -// gxInstance.getContentPane().paintComponents(g2); - - - g2.translate(-dx, -dy); - - g2.setStroke(CMisc.DashedStroke1); - - g2.setColor(Color.red); - g2.drawLine(x1, y1, x1, y2); - g2.drawLine(x1, y1, x2, y1); - g2.drawLine(x1, y2, x2, y2); - g2.drawLine(x2, y1, x2, y2); - - - } - }; - contentPane.addMouseListener(this); - contentPane.addMouseMotionListener(this); - ppp.add(contentPane); - - - JPanel bpane = new JPanel(); - bpane.setLayout(new BoxLayout(bpane, BoxLayout.X_AXIS)); - bpane.add(Box.createHorizontalGlue()); - JButton bok = new JButton(GExpert.getLanguage("OK")); - JButton bcancel = new JButton(GExpert.getLanguage("Cancel")); - bok.addActionListener(this); - bcancel.addActionListener(this); - bpane.add(bok); - bpane.add(bcancel); - ppp.add(bpane); - - this.getContentPane().add(ppp); - - - this.pack(); - x1 = y1 = x2 = y2 = 0; - } - - // - BufferedImage image; - - public void setVisible(boolean r) { - Dimension dm = content.getSize(); - image = gxInstance.getBufferedImage2(new Rectangle(0, 0, (int) dm.getWidth(), (int) dm.getHeight())); - - super.setVisible(r); - } - - public void mouseClicked(MouseEvent e) { - } - - public void mousePressed(MouseEvent e) { - x1 = (int) (e.getX() + dx); - y1 = (int) (e.getY() + dy); - x2 = x1; - y2 = y1; - this.repaint(); - } - - public Rectangle getRectangle() { - return new Rectangle(x1 - (int) dx, y1 - (int) dy, x2 - x1, y2 - y1); - } - - public void mouseReleased(MouseEvent e) { - } - - public void mouseEntered(MouseEvent e) { - } - - public void mouseExited(MouseEvent e) { - } - - public void mouseDragged(MouseEvent e) { - x2 = (int) (e.getX() + dx); - y2 = (int) (e.getY() + dy); -// this.validate(); - -// this.doLayout(); -// this.invalidate(); - this.repaint(); - } - - public void mouseMoved(MouseEvent e) { - } - - public void componentResized(ComponentEvent e) { - Point pt = content.getLocation(); - dx = pt.getX(); - dy = pt.getY(); - - } - - public void componentMoved(ComponentEvent e) { - } - - public void componentShown(ComponentEvent e) { - } - - public void componentHidden(ComponentEvent e) { - } - - public void translate(int n) { - x1 += n; - y1 += n; - x2 += n; - y2 += n; - } - - public void keyPressed(KeyEvent e) { - super.keyPressed(e); - - int key = e.getKeyCode(); - switch (key) { - case KeyEvent.VK_LEFT: - x1 -= 1; - x2 -= 1; - break; - case KeyEvent.VK_RIGHT: - x1 += 1; - x2 += 1; - break; - case KeyEvent.VK_UP: - y1 -= 1; - y2 -= 1; - break; - case KeyEvent.VK_DOWN: - y1 += 1; - y2 += 1; - break; - case KeyEvent.VK_ENTER: - result = true; - setVisible(false); - break; - default: - return; - - } - this.repaint(); - - } - - public void actionPerformed(ActionEvent e) { - String s = e.getActionCommand(); - if (s.equalsIgnoreCase("OK")) { - result = true; - } else { - result = false; - } - this.setVisible(false); - } - - - public void paint(Graphics g) { - super.paint(g); - } - - public void run() { - - } -} +package wprover; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; +import java.awt.image.BufferedImage; + + +/** + * RectangleSelectionDialog is a class that extends JBaseDialog and implements + * MouseListener, MouseMotionListener, ComponentListener, ActionListener, and Runnable. + * It is used to create a dialog for selecting a rectangle in a JPanel. + */ +public class RectangleSelectionDialog extends JBaseDialog implements MouseListener, MouseMotionListener, + ComponentListener, ActionListener, Runnable { + + private int x2, y2, x1, y1; + private GExpert gxInstance; + private JPanel contentPane; + private JComponent content; + private double dx, dy; + private boolean result = false; + + /** + * Returns the result of the dialog. + * + * @return true if the OK button was pressed, false otherwise + */ + public boolean getResult() { + return result; + } + + /** + * Constructs a new RectangleSelectionDialog with the specified GExpert instance. + * + * @param gx the GExpert instance to associate with this dialog + */ + public RectangleSelectionDialog(GExpert gx) { + super(gx.getFrame(), GExpert.getLanguage("Choose a rectangle"), true); + JPanel ppp = new JPanel(); + ppp.setLayout(new BoxLayout(ppp, BoxLayout.Y_AXIS)); + + + gxInstance = gx; + content = gx.getContent(); + Point pt = content.getLocation(); + dx = pt.getX(); + dy = pt.getY(); + + contentPane = new JPanel() { + public Dimension getPreferredSize() { + return content.getSize(); + } + + + public void paintComponent(Graphics g) { + super.paintComponent(g); +// super.paintAll(); + //this.pai + Graphics2D g2 = (Graphics2D) g; +// g2.translate(-dx, -dy); + g2.drawImage(image, 0, 0, null); + +// gxInstance.getContentPane().paintComponents(g2); + + + g2.translate(-dx, -dy); + + g2.setStroke(CMisc.DashedStroke1); + + g2.setColor(Color.red); + g2.drawLine(x1, y1, x1, y2); + g2.drawLine(x1, y1, x2, y1); + g2.drawLine(x1, y2, x2, y2); + g2.drawLine(x2, y1, x2, y2); + + + } + }; + contentPane.addMouseListener(this); + contentPane.addMouseMotionListener(this); + ppp.add(contentPane); + + + JPanel bpane = new JPanel(); + bpane.setLayout(new BoxLayout(bpane, BoxLayout.X_AXIS)); + bpane.add(Box.createHorizontalGlue()); + JButton bok = new JButton(GExpert.getLanguage("OK")); + JButton bcancel = new JButton(GExpert.getLanguage("Cancel")); + bok.addActionListener(this); + bcancel.addActionListener(this); + bpane.add(bok); + bpane.add(bcancel); + ppp.add(bpane); + + this.getContentPane().add(ppp); + + + this.pack(); + x1 = y1 = x2 = y2 = 0; + } + + BufferedImage image; + + /** + * Sets the visibility of the dialog and captures the current content as an image. + * + * @param r true to make the dialog visible, false to hide it + */ + public void setVisible(boolean r) { + Dimension dm = content.getSize(); + image = gxInstance.getBufferedImage2(new Rectangle(0, 0, (int) dm.getWidth(), (int) dm.getHeight())); + super.setVisible(r); + } + + /** + * Handles mouse clicked events. + * + * @param e the MouseEvent triggered by clicking the mouse + */ + public void mouseClicked(MouseEvent e) { + } + + /** + * Handles mouse pressed events to start drawing the rectangle. + * + * @param e the MouseEvent triggered by pressing the mouse + */ + public void mousePressed(MouseEvent e) { + x1 = (int) (e.getX() + dx); + y1 = (int) (e.getY() + dy); + x2 = x1; + y2 = y1; + this.repaint(); + } + + /** + * Returns the selected rectangle. + * + * @return the selected Rectangle + */ + public Rectangle getRectangle() { + return new Rectangle(x1 - (int) dx, y1 - (int) dy, x2 - x1, y2 - y1); + } + + /** + * Handles mouse released events. + * + * @param e the MouseEvent triggered by releasing the mouse + */ + public void mouseReleased(MouseEvent e) { + } + + /** + * Handles mouse entered events. + * + * @param e the MouseEvent triggered by entering a component + */ + public void mouseEntered(MouseEvent e) { + } + + /** + * Handles mouse exited events. + * + * @param e the MouseEvent triggered by exiting a component + */ + public void mouseExited(MouseEvent e) { + } + + /** + * Handles mouse dragged events to update the rectangle's size. + * + * @param e the MouseEvent triggered by dragging the mouse + */ + public void mouseDragged(MouseEvent e) { + x2 = (int) (e.getX() + dx); + y2 = (int) (e.getY() + dy); + this.repaint(); + } + + /** + * Handles mouse moved events. + * + * @param e the MouseEvent triggered by moving the mouse + */ + public void mouseMoved(MouseEvent e) { + } + + /** + * Handles component resized events to update the content location. + * + * @param e the ComponentEvent triggered by resizing the component + */ + public void componentResized(ComponentEvent e) { + Point pt = content.getLocation(); + dx = pt.getX(); + dy = pt.getY(); + } + + /** + * Handles component moved events. + * + * @param e the ComponentEvent triggered by moving the component + */ + public void componentMoved(ComponentEvent e) { + } + + /** + * Handles component shown events. + * + * @param e the ComponentEvent triggered by showing the component + */ + public void componentShown(ComponentEvent e) { + } + + /** + * Handles component hidden events. + * + * @param e the ComponentEvent triggered by hiding the component + */ + public void componentHidden(ComponentEvent e) { + } + + /** + * Translates the rectangle by a specified amount. + * + * @param n the amount to translate the rectangle + */ + public void translate(int n) { + x1 += n; + y1 += n; + x2 += n; + y2 += n; + } + + /** + * Handles key pressed events to move the rectangle or confirm the selection. + * + * @param e the KeyEvent triggered by pressing a key + */ + public void keyPressed(KeyEvent e) { + super.keyPressed(e); + + int key = e.getKeyCode(); + switch (key) { + case KeyEvent.VK_LEFT: + x1 -= 1; + x2 -= 1; + break; + case KeyEvent.VK_RIGHT: + x1 += 1; + x2 += 1; + break; + case KeyEvent.VK_UP: + y1 -= 1; + y2 -= 1; + break; + case KeyEvent.VK_DOWN: + y1 += 1; + y2 += 1; + break; + case KeyEvent.VK_ENTER: + result = true; + setVisible(false); + break; + default: + return; + } + this.repaint(); + } + + /** + * Handles action events for the OK and Cancel buttons. + * + * @param e the ActionEvent triggered by the buttons + */ + public void actionPerformed(ActionEvent e) { + String s = e.getActionCommand(); + if (s.equalsIgnoreCase("OK")) { + result = true; + } else { + result = false; + } + this.setVisible(false); + } + + /** + * Paints the component. + * + * @param g the Graphics object to protect + */ + public void paint(Graphics g) { + super.paint(g); + } + + /** + * Runs the dialog. + */ + public void run() { + } +} diff --git a/src/main/java/wprover/RightClickPopMenu.java b/src/main/java/wprover/RightClickPopMenu.java index f0077a54..d34ff819 100644 --- a/src/main/java/wprover/RightClickPopMenu.java +++ b/src/main/java/wprover/RightClickPopMenu.java @@ -5,24 +5,32 @@ import java.awt.*; import java.awt.event.*; +/** + * RightClickPopMenu is a class that extends JPopupMenu and implements ActionListener. + * It is used to create a context menu for right-click actions on graphical elements. + */ public class RightClickPopMenu extends JPopupMenu implements ActionListener { private GExpert gxInstance; private CClass cc; + JRadioButtonMenuItem t1, t2; + /** + * Constructs a new RightClickPopMenu with the specified CClass and GExpert instances. + * + * @param c the CClass instance to associate with this menu + * @param gx the GExpert instance to associate with this menu + */ public RightClickPopMenu(CClass c, GExpert gx) { this.gxInstance = gx; this.cc = c; this.setForeground(Color.white); - JMenuItem item = addAMenuItem(GExpert.getLanguage("Cancel Action"), true); item.setActionCommand("Cancel Action"); item.setMnemonic(KeyEvent.VK_ESCAPE); KeyStroke ctrlP = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); item.setAccelerator(ctrlP); -// item = addAMenuItem(getLanguage(10, "Move"), true); -// item.setActionCommand("Move"); addFreezeMenu(); this.addSeparator(); @@ -38,6 +46,11 @@ public RightClickPopMenu(CClass c, GExpert gx) { item.setActionCommand("Properties"); } + /** + * Adds specific menu items based on the type of the given CClass instance. + * + * @param c the CClass instance to determine the specific menu items + */ public void addSpecificMenu(CClass c) { if (c == null) return; @@ -94,6 +107,11 @@ public void addSpecificMenu(CClass c) { } } + /** + * Handles action events for the menu items. + * + * @param e the ActionEvent triggered by the menu items + */ public void actionPerformed(ActionEvent e) { String command = e.getActionCommand(); if (command.equals("Properties")) @@ -124,9 +142,7 @@ else if (command.equals("Trace")) { gxInstance.dp.addCalculationPX((CPoint) cc); } else if (command.equals("Y Coordinate")) { gxInstance.dp.addCalculationPY((CPoint) cc); - } else if (command.equals("Area")) { - if (cc instanceof Circle) gxInstance.dp.addCalculationCircle((Circle) cc, 0); else { @@ -139,20 +155,23 @@ else if (command.equals("Trace")) { gxInstance.dp.addCalculationPolygon((CPolygon) cc); } } - } else if (command.equals("Girth")) { gxInstance.dp.addCalculationCircle((Circle) cc, 1); - } else if (command.equals("Radius")) { gxInstance.dp.addCalculationCircle((Circle) cc, 2); } else if (command.equals("Slope")) { gxInstance.dp.addLineSlope((CLine) cc); } else if (command.equals("Unfreeze All Points")) gxInstance.dp.unfreezeAllPoints(); - - } + /** + * Adds a menu item with the specified label and enabled state. + * + * @param s the label of the menu item + * @param t the enabled state of the menu item + * @return the created JMenuItem + */ private JMenuItem addAMenuItem(String s, boolean t) { JMenuItem item = new JMenuItem(s); item.setEnabled(t); @@ -161,8 +180,11 @@ private JMenuItem addAMenuItem(String s, boolean t) { return item; } - JRadioButtonMenuItem t1, t2; - + /** + * Adds font size menu items for the specified CText instance. + * + * @param t the CText instance to add font size menu items for + */ private void addFontSizeMenuItem(CText t) { int f = t.getFontSize(); int[] fz = CMisc.getFontSizePool(); @@ -212,6 +234,9 @@ public void actionPerformed(ActionEvent e) { this.add(m); } + /** + * Adds a menu item to unfreeze all points if there are any frozen points. + */ private void addFreezeMenu() { if (gxInstance.dp.containFreezedPoint()) { JMenuItem item = new JMenuItem(GExpert.getLanguage("Unfreeze All Points")); @@ -222,6 +247,13 @@ private void addFreezeMenu() { } } + /** + * Adds a color menu item with the specified label, enabled state, and default color index. + * + * @param s the label of the color menu item + * @param t the enabled state of the color menu item + * @param d the default color index + */ private void addAColorMenuItem(String s, boolean t, int d) { JMenu item = new JMenu(s); item.setEnabled(t); @@ -251,6 +283,10 @@ private void addAColorMenuItem(String s, boolean t, int d) { } } + /** + * A custom JPanel class that represents a color panel. + * It sets the foreground and background color to the specified color. + */ class colorPanel extends JPanel { public colorPanel(Color c) { this.setForeground(c); diff --git a/src/main/java/wprover/RightTransformPopupMenu.java b/src/main/java/wprover/RightTransformPopupMenu.java index 4e4aeaac..51612ea1 100644 --- a/src/main/java/wprover/RightTransformPopupMenu.java +++ b/src/main/java/wprover/RightTransformPopupMenu.java @@ -8,11 +8,8 @@ import java.awt.*; /** - * Created by IntelliJ IDEA. - * User: ye - * Date: Mar 18, 2007 - * Time: 7:57:14 PM - * To change this template use File | Settings | File Templates. + * RightTransformPopupMenu is a class that extends JPopupMenu and implements ItemListener and ActionListener. + * It provides a context menu for transforming graphical objects in a drawing application. */ public class RightTransformPopupMenu extends JPopupMenu implements ItemListener, ActionListener { @@ -21,6 +18,11 @@ public class RightTransformPopupMenu extends JPopupMenu implements ItemListener, private JMenuItem m; private int xx, yy; + /** + * Constructs a new RightTransformPopupMenu with the specified DrawProcess instance. + * + * @param d the DrawProcess instance to associate with this menu + */ public RightTransformPopupMenu(DrawProcess d) { dp = d; @@ -49,6 +51,11 @@ public RightTransformPopupMenu(DrawProcess d) { this.add(m); } + /** + * Handles action events for the menu items. + * + * @param e the ActionEvent triggered by the menu items + */ public void actionPerformed(ActionEvent e) { if (e.getSource() == m) { dp.setTransformStatus(0); @@ -56,19 +63,29 @@ public void actionPerformed(ActionEvent e) { } } + /** + * Displays the popup menu at the specified location. + * + * @param invoker the component in which the popup menu is displayed + * @param x the x-coordinate of the popup menu's location + * @param y the y-coordinate of the popup menu's location + */ public void show(Component invoker, int x, int y) { super.show(invoker, x, y); xx = x; yy = y; } + /** + * Handles item state change events for the radio buttons. + * + * @param e the ItemEvent triggered by the radio buttons + */ public void itemStateChanged(ItemEvent e) { if (m1.isSelected()) { dp.setTransformStatus(1); - dp.setFirstPnt(xx, yy); - } else if (m2.isSelected()) dp.setTransformStatus(2); else diff --git a/src/main/java/wprover/RuleApplicationDialog.java b/src/main/java/wprover/RuleApplicationDialog.java index 7c7ca4fe..c9ab10c6 100644 --- a/src/main/java/wprover/RuleApplicationDialog.java +++ b/src/main/java/wprover/RuleApplicationDialog.java @@ -17,6 +17,11 @@ import static wprover.GExpert.getLanguage; +/** + * RuleApplicationDialog is a dialog that displays the application of rules in + * the GExpert system. It allows users to visualize and interact with rules and + * their conditions. + */ public class RuleApplicationDialog extends JBaseDialog implements ComponentListener, ActionListener, WindowListener { private GExpert gxInstance; @@ -37,6 +42,13 @@ public class RuleApplicationDialog extends JBaseDialog implements ComponentListe private JDialog ruleDialog; + /** + * Constructs a new RuleApplicationDialog with the specified GExpert, DPanel, and DrawTextProcess instances. + * + * @param gx the GExpert instance to associate with this dialog + * @param d the DPanel instance to associate with this dialog + * @param dp the DrawTextProcess instance to associate with this dialog + */ public RuleApplicationDialog(GExpert gx, DPanel d, DrawTextProcess dp) { super(gx.getFrame()); this.dpane = d; @@ -47,6 +59,12 @@ public RuleApplicationDialog(GExpert gx, DPanel d, DrawTextProcess dp) { init(); } + /** + * Constructs a new RuleApplicationDialog with the specified DPanel and DrawTextProcess instances. + * + * @param d the DPanel instance to associate with this dialog + * @param dp the DrawTextProcess instance to associate with this dialog + */ public RuleApplicationDialog(DPanel d, DrawTextProcess dp) { this.dpane = d; this.dpp = dp; @@ -54,15 +72,13 @@ public RuleApplicationDialog(DPanel d, DrawTextProcess dp) { init(); } - + /** + * Initializes the RuleApplicationDialog by setting up the panels, listeners, and window properties. + */ public void init() { -// if (gxInstance != null) -// gxInstance.addDependentDialog(this); - rpanel = new rulePanel(gxInstance); panel = new JSplitPane(JSplitPane.VERTICAL_SPLIT); - JPanel panel1 = new JPanel() { public Dimension getMaximumSize() { return super.getPreferredSize(); @@ -79,7 +95,6 @@ public Dimension getMaximumSize() { panel1.add(Box.createVerticalStrut(4)); panel1.add(rapanel); - spanel = new JScrollPane(rpanel) { public Dimension getPreferredSize() { return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE); @@ -102,9 +117,11 @@ public Dimension getPreferredSize() { } else { this.setSize(500, 500); } - } + /** + * Generates a MouseListener for handling mouse events on the dialog components. + */ public void generateListener() { lselected = null; @@ -145,8 +162,12 @@ public void mouseExited(MouseEvent e) { }; } + /** + * Starts flashing the specified object in the rule panel. + * + * @param o the object to flash + */ public void startFlashObject(Object o) { - Object f = hash.get(o.toString()); if (f instanceof JFlash) { JFlash f1 = (JFlash) f; @@ -155,6 +176,11 @@ public void startFlashObject(Object o) { rpanel.repaint(); } + /** + * Handles action events for the Align Center button. + * + * @param e the ActionEvent triggered by the button + */ public void actionPerformed(ActionEvent e) { if (buttona == e.getSource()) { rpanel.centerAllObject(); @@ -164,6 +190,13 @@ public void actionPerformed(ActionEvent e) { } } + /** + * Creates a JToggleButton with the specified icon and tooltip. + * + * @param name the name of the icon file + * @param tip the tooltip text + * @return the created JToggleButton + */ private JToggleButton createRPaneButton(String name, String tip) { JToggleButton b = new JToggleButton(GExpert.createImageIcon("images/rpane/" + name)); b.setToolTipText(tip); @@ -174,6 +207,11 @@ private JToggleButton createRPaneButton(String name, String tip) { return b; } + /** + * Loads the specified ElTerm rule into the dialog. + * + * @param el the ElTerm rule to load + */ public void LoadRule(ElTerm el) { this.setTitle(GExpert.getTranslationViaGettext("RULE {0}", el.etype + "")); hash.clear(); @@ -184,6 +222,11 @@ public void LoadRule(ElTerm el) { rpanel.scrollToCenter(); } + /** + * Loads the specified Cond rule into the dialog. + * + * @param c the Cond rule to load + */ public void LoadRule(Cond c) { this.setTitle(GExpert.getTranslationViaGettext("RULE {0}", c.getRule() + "")); hash.clear(); @@ -193,9 +236,13 @@ public void LoadRule(Cond c) { rpanel.scrollToCenter(); } + /** + * Handles component resized events to reset the panel sizes. + * + * @param e the ComponentEvent triggered by resizing the component + */ public void componentResized(ComponentEvent e) { panel.resetToPreferredSizes(); - } public void componentMoved(ComponentEvent e) { @@ -207,6 +254,11 @@ public void componentShown(ComponentEvent e) { public void componentHidden(ComponentEvent e) { } + /** + * ruleViewPanel is a custom JPanel that displays the rule view in the + * RuleApplicationDialog. It allows users to visualize and interact with + * rules and their conditions. + */ class ruleViewPanel extends JToolBar { private Vector vlist = new Vector(); @@ -264,6 +316,11 @@ public void loadRule(ElTerm el) { } } + /** + * ruleAppPanel is a custom JPanel that displays the rule application view + * in the RuleApplicationDialog. It allows users to visualize and interact + * with rules and their conditions. + */ class ruleAppPanel extends JToolBar { private Vector vlist = new Vector(); @@ -334,31 +391,17 @@ public void loadRule(ElTerm el) { } } - class JruleTreePanel extends JPanel { - private JEditorPane pane; - - public JruleTreePanel() { - pane = new JEditorPane(); - this.add(pane); - } - - public void loadRule(ElTerm el) { - URL url = GExpert.getResourceURL("rule/rule" + el.getEType() + ".html"); - try { - pane.setPage(url); - } catch (IOException ee) { - } - - } - - } - public void windowOpened(WindowEvent e) { } public void windowClosing(WindowEvent e) { } + /** + * Invoked when a window has been closed. If the rule dialog is open, it hides the rule dialog. + * + * @param e the WindowEvent that indicates the window has been closed + */ public void windowClosed(WindowEvent e) { if (ruleDialog != null) ruleDialog.setVisible(false); @@ -376,7 +419,11 @@ public void windowActivated(WindowEvent e) { public void windowDeactivated(WindowEvent e) { } - + /** + * rulePanel is a custom JPanel that displays geometric objects and allows + * interaction with them. It handles mouse events, scaling, and drawing of + * objects. + */ class rulePanel extends JPanel implements MouseListener, MouseMotionListener, ComponentListener { int xx, yy; @@ -920,6 +967,10 @@ protected void paintComponent(Graphics g) { } } + /** + * RuleLabel is a custom JLabel that represents a rule in the GExpert system. + * It allows users to click on the label to view more information about the rule. + */ class RuleLabel extends JLabel implements MouseListener { private int RULE; private int type; diff --git a/src/main/java/wprover/RuleDialog.java b/src/main/java/wprover/RuleDialog.java index 56b3f36a..4a18be8c 100644 --- a/src/main/java/wprover/RuleDialog.java +++ b/src/main/java/wprover/RuleDialog.java @@ -12,19 +12,26 @@ import java.util.EventObject; import java.util.Vector; - +/** + * RuleDialog is a class that extends JBaseDialog and implements ChangeListener, + * ActionListener, and MouseListener interfaces. It provides a dialog for displaying + * and managing rules related to the GDD method and the Full Angle method. + */ public class RuleDialog extends JBaseDialog implements ChangeListener, ActionListener, MouseListener { private GExpert gxInstance; private JTree tree, treef; private JTabbedPane pane; + /** + * Constructs a new RuleDialog with the specified GExpert instance. + * + * @param owner the GExpert instance to associate with this dialog + */ public RuleDialog(GExpert owner) { super(owner.getFrame()); gxInstance = owner; -// if (gxInstance != null) -// gxInstance.addDependentDialog(this); this.setTitle(GExpert.getLanguage("Rules for the GDD Method")); @@ -45,7 +52,7 @@ public RuleDialog(GExpert owner) { CheckBoxNodeRenderer renderer = new CheckBoxNodeRenderer(); tree.setCellRenderer(renderer); -// tree.setCellEditor(new CheckBoxNodeEditor(tree)); + // tree.setCellEditor(new CheckBoxNodeEditor(tree)); tree.setEditable(false); tree.addMouseListener(this); @@ -64,23 +71,40 @@ public RuleDialog(GExpert owner) { JScrollPane scrollPane1 = new JScrollPane(treef); pane.addTab(GExpert.getLanguage("Rules for the Full Angle Method"), scrollPane1); - this.getContentPane().add(pane, BorderLayout.CENTER); expandAll(); this.setSize(600, owner.getHeight()); } + /** + * Sets the selected tab in the JTabbedPane. + * + * @param n the index of the tab to select + */ public void setSelected(int n) { pane.setSelectedIndex(n); } + /** + * Called when the state of the JTabbedPane changes. + * + * @param e the ChangeEvent that triggered this method + */ public void stateChanged(ChangeEvent e) { if (e.getSource() == pane) { this.setTitle(pane.getTitleAt(pane.getSelectedIndex())); } } - + /** + * Creates a NamedVector with the specified name and a subset of the given vector. + * + * @param n the name of the NamedVector + * @param vlist the vector to create the subset from + * @param t1 the starting index of the subset + * @param t2 the ending index of the subset + * @return the created NamedVector + */ private Vector createNameVector(String n, Vector vlist, int t1, int t2) { CheckBoxNode[] list1 = new CheckBoxNode[t2 - t1 + 1]; createCheckBox(list1, vlist, t1, t2); @@ -88,6 +112,14 @@ private Vector createNameVector(String n, Vector vlist, int t1, int t2) { return v1; } + /** + * Creates an array of CheckBoxNode objects from a subset of the given vector. + * + * @param list the array to store the CheckBoxNode objects + * @param vlist the vector to create the subset from + * @param t1 the starting index of the subset + * @param t2 the ending index of the subset + */ private void createCheckBox(CheckBoxNode[] list, Vector vlist, int t1, int t2) { int index = 0; for (int i = t1; i < vlist.size() && i <= t2; i++) { @@ -98,6 +130,9 @@ private void createCheckBox(CheckBoxNode[] list, Vector vlist, int t1, int t2) { } } + /** + * Expands all rows in the JTree components. + */ private void expandAll() { int n = tree.getRowCount(); for (int i = n - 1; i >= 0; i--) @@ -107,6 +142,11 @@ private void expandAll() { treef.expandRow(i); } + /** + * Returns the selected GRule from the currently selected tab. + * + * @return the selected GRule, or null if no rule is selected + */ public GRule getSelectedRule() { DefaultMutableTreeNode nd = null; JTree tt = null; @@ -130,6 +170,11 @@ public GRule getSelectedRule() { return null; } + /** + * Handles mouse click events on the JTree components. + * + * @param e the MouseEvent that triggered this method + */ public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3) { DefaultMutableTreeNode nd = null; @@ -152,7 +197,6 @@ public void mouseClicked(MouseEvent e) { this.showRuleDialog(r); } } - } public void mousePressed(MouseEvent e) { @@ -167,6 +211,10 @@ public void mouseEntered(MouseEvent e) { public void mouseExited(MouseEvent e) { } + /** + * CheckBoxNodeRenderer is a class that implements TreeCellRenderer to render + * checkboxes in a JTree. + */ class CheckBoxNodeRenderer implements TreeCellRenderer { private JCheckBox leafRenderer = new JCheckBox(); private DefaultTreeCellRenderer nonLeafRenderer = new DefaultTreeCellRenderer(); @@ -240,75 +288,9 @@ public Component getTreeCellRendererComponent(JTree tree, Object value, } } - class CheckBoxNodeEditor extends AbstractCellEditor implements TreeCellEditor { - - CheckBoxNodeRenderer renderer = new CheckBoxNodeRenderer(); - - ChangeEvent changeEvent = null; - - JTree tree; - - public CheckBoxNodeEditor(JTree tree) { - this.tree = tree; -// renderer.leafRenderer.addChangeListener(); - renderer.leafRenderer.addChangeListener(new ChangeListener() { - public void stateChanged(ChangeEvent e) { - int n = 0; - if (renderer.leafNode != null) - renderer.leafNode.updateValue(renderer.leafRenderer.isSelected()); - } - - }); - } - - public Object getCellEditorValue() { - JCheckBox checkbox = renderer.getLeafRenderer(); - CheckBoxNode nd = renderer.getLeafNode(); - if (nd != null && checkbox != null) - nd.setSelected(checkbox.isSelected()); - return nd; - } - - public boolean isCellEditable(EventObject event) { - boolean returnValue = false; - if (event instanceof MouseEvent) { - MouseEvent mouseEvent = (MouseEvent) event; - TreePath path = tree.getPathForLocation(mouseEvent.getX(), - mouseEvent.getY()); - if (path != null) { - Object node = path.getLastPathComponent(); - if ((node != null) && (node instanceof DefaultMutableTreeNode)) { - DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) node; - Object userObject = treeNode.getUserObject(); - returnValue = ((treeNode.isLeaf()) && (userObject instanceof CheckBoxNode)); - } - } - } - return returnValue; - } - - public Component getTreeCellEditorComponent(JTree tree, Object value, - boolean selected, boolean expanded, boolean leaf, int row) { - - Component editor = renderer.getTreeCellRendererComponent(tree, value, - true, expanded, leaf, row, true); - - // editor always selected / focused - ItemListener itemListener = new ItemListener() { - public void itemStateChanged(ItemEvent itemEvent) { - if (stopCellEditing()) { - fireEditingStopped(); - } - } - }; - if (editor instanceof JCheckBox) { - ((JCheckBox) editor).addItemListener(itemListener); - } - - return editor; - } - } - + /** + * CheckBoxNode is a class that represents a node in the JTree with a checkbox. + */ class CheckBoxNode { private String text; @@ -354,6 +336,9 @@ public String toString() { } } + /** + * NamedVector is a class that extends Vector and adds a name attribute. + */ class NamedVector extends Vector { String name; @@ -400,6 +385,9 @@ public void actionPerformed(ActionEvent e) { } + /** + * Popup menu for displaying rule options. + */ class ppMenu extends JPopupMenu { private GRule rule; diff --git a/src/main/java/wprover/RuleList.java b/src/main/java/wprover/RuleList.java index 0aee2136..9e8e1f70 100644 --- a/src/main/java/wprover/RuleList.java +++ b/src/main/java/wprover/RuleList.java @@ -6,64 +6,81 @@ import java.util.Vector; /** - * Created by IntelliJ IDEA. - * User: ye - * Date: 2007-5-9 - * Time: 15:28:50 - * To change this template use File | Settings | File Templates. + * RuleList is a class that manages a list of rules for GDD and FULL types. + * It provides methods to load rules, retrieve rules by index, and manage rule values. */ public class RuleList { - // final private static boolean SAVEAGAIN = true; - private RuleList() { } - - - final public static Vector GDDLIST = new Vector(); final public static Vector FULLLIST = new Vector(); - final public static Vector getAllGDDRules() { + /** + * Retrieves all GDD rules. + * + * @return a Vector containing all GDD rules + */ + public static Vector getAllGDDRules() { Vector v = new Vector(); v.addAll(GDDLIST); return v; } - final public static Vector getAllFullRules() { + /** + * Retrieves all FULL rules. + * + * @return a Vector containing all FULL rules + */ + public static Vector getAllFullRules() { Vector v = new Vector(); v.addAll(FULLLIST); return v; } - final public static GRule getGrule(int n) { + /** + * Retrieves a GDD rule by its index. + * + * @param n the index of the GDD rule to retrieve + * @return the GDD rule at the specified index, or null if the index is out of bounds + */ + public static GRule getGrule(int n) { n--; if (n < 0 || n > GDDLIST.size()) return null; return (GRule) GDDLIST.get(n); } - final public static GRule getFrule(int n) { + /** + * Retrieves a FULL rule by its index. + * + * @param n the index of the FULL rule to retrieve + * @return the FULL rule at the specified index, or null if the index is out of bounds + */ + public static GRule getFrule(int n) { n--; if (n < 0 || n > FULLLIST.size()) return null; return (GRule) FULLLIST.get(n); } - - - final private static void loadRules(String[] src, Vector vs, int type) { - - + /** + * Loads rules from the specified source array into the given vector. + * + * @param src the source array containing the rules + * @param vs the vector to load the rules into + * @param type the type of rules to load + */ + private static void loadRules(String[] src, Vector vs, int type) { String s, s1, s2; s = s1 = s2 = null; int i = 0; int len = src.length; - String t = src[i]; //reader.readLine().trim(); + String t = src[i]; int id = 1; @@ -83,7 +100,6 @@ else if (s1 == null) s1 = t; else s2 = t; } - } if (i >= len - 1) break; @@ -92,17 +108,31 @@ else if (s1 == null) } } - final public static void loadRules() { - loadRules(Rules.GDD_English, GDDLIST, 0); - loadRules(Rules.FULL_English, FULLLIST, 1); + /** + * Loads all GDD and FULL rules. + */ + public static void loadRules() { + loadRules(Rules.GDD_English, GDDLIST, 0); + loadRules(Rules.FULL_English, FULLLIST, 1); } - final public static boolean getValue(int n) { + /** + * Retrieves the value of a rule by its index. + * + * @param n the index of the rule + * @return the value of the rule at the specified index + */ + public static boolean getValue(int n) { return Gib.RValue[n - 1]; } - final public static void setValue(int n, boolean v) { + /** + * Sets the value of a rule by its index. + * + * @param n the index of the rule + * @param v the value to set for the rule + */ + public static void setValue(int n, boolean v) { Gib.RValue[n - 1] = v; } - } diff --git a/src/main/java/wprover/RuleListDialog.java b/src/main/java/wprover/RuleListDialog.java index 8453c94b..888d7d83 100644 --- a/src/main/java/wprover/RuleListDialog.java +++ b/src/main/java/wprover/RuleListDialog.java @@ -10,6 +10,10 @@ import java.net.URL; import java.net.URLConnection; +/** + * RuleListDialog is a dialog that displays a list of rules and allows the user to interact with them. + * It extends JBaseDialog and provides functionality for loading and displaying rules. + */ public class RuleListDialog extends JBaseDialog { private GExpert gxInstance; @@ -18,37 +22,37 @@ public class RuleListDialog extends JBaseDialog { private ruleDpanel dpane; private JPanel split; + /** + * Constructs a new RuleListDialog with the specified GExpert instance. + * + * @param gx the GExpert instance to associate with this dialog + */ public RuleListDialog(GExpert gx) { super(gx.getFrame()); gxInstance = gx; init(); } + /** + * Constructs a new RuleListDialog with no associated GExpert instance. + */ public RuleListDialog() { gxInstance = null; init(); } - + /** + * Initializes the RuleListDialog by setting up the panels, listeners, and window properties. + */ public void init() { if (gxInstance != null && CMisc.isApplication()) this.setAlwaysOnTop(true); -// if (gxInstance != null) -// gxInstance.addDependentDialog(this); - - this.setTitle(GExpert.getLanguage("Rule")); this.setModal(false); scroll = new JScrollPane((rpane = new RuleViewPane(gxInstance))); -// { -// public Dimension getPreferredSize() { -// return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE); -// } -// })); - dpane = new ruleDpanel(); split = new JPanel(); @@ -61,6 +65,13 @@ public void init() { this.setLocation(gxInstance.getX(), gxInstance.getY() + gxInstance.getHeight() - 500); } + /** + * Loads a rule based on the type and index. + * + * @param t the type of the rule + * @param n the index of the rule + * @return true if the rule is loaded successfully, false otherwise + */ public boolean loadRule(int t, int n) { GRule r; if (t == 0) @@ -82,11 +93,19 @@ public boolean loadRule(int t, int n) { return rf; } + /** + * A custom JPanel that displays rule details and handles mouse events. + */ class ruleDpanel extends JPanel implements MouseListener { private JLabel label1, label2; private JEditorPane epane; private int rt1, rt2; + /** + * Returns the maximum size of this component. + * + * @return the maximum size of this component + */ public Dimension getMaximumSize() { Dimension dm = super.getMaximumSize(); Dimension dm2 = super.getPreferredSize(); @@ -94,6 +113,9 @@ public Dimension getMaximumSize() { return dm2; } + /** + * Constructs a new ruleDpanel. + */ public ruleDpanel() { this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); JPanel p = new JPanel(new FlowLayout(FlowLayout.LEADING)); @@ -110,16 +132,17 @@ public ruleDpanel() { this.add(epane); } + /** + * Sets the rule to be displayed in this panel. + * + * @param t the type of the rule + * @param r the rule to display + */ public void setRule(int t, GRule r) { rt1 = t; rt2 = r.type; String sh; - /* - if (t == 0) - sh = "RULE " + r.type;//+ " for Deductive Database Method"; - else sh = "RULE " + r.type;//+ " for Full Angle Method"; - */ sh = GExpert.getTranslationViaGettext("Rule {0}", r.type + ""); label1.setText(sh); @@ -132,6 +155,11 @@ public void setRule(int t, GRule r) { epane.setText(s); } + /** + * Handles mouse click events to open the rule's help page. + * + * @param e the mouse event + */ public void mouseClicked(MouseEvent e) { String dr = GExpert.getUserDir(); String sp = GExpert.getFileSeparator(); @@ -139,7 +167,6 @@ public void mouseClicked(MouseEvent e) { GExpert.openURL("file:///" + dr + sp + "help" + sp + "GDD" + sp + "r" + rt2 + ".html"); else GExpert.openURL("file:///" + dr + sp + "help" + sp + "FULL" + sp + "r" + rt2 + ".html"); - } public void mousePressed(MouseEvent e) { @@ -153,19 +180,30 @@ public void mouseEntered(MouseEvent e) { public void mouseExited(MouseEvent e) { } - } + /** + * A custom JPanel that displays and interacts with rules in a graphical format. + * Implements MouseListener, ComponentListener, and MouseMotionListener interfaces. + */ class RuleViewPane extends JPanel implements MouseListener, ComponentListener, MouseMotionListener { DrawTextProcess dx; int xx, yy; double scale = 1.0; protected Rectangle rc = new Rectangle(0, 0, 0, 0); + /** + * Returns the preferred size of this component. + * + * @return the preferred size of this component + */ public Dimension getPreferredSize() { return new Dimension((int) rc.getWidth() + 20, (int) rc.getHeight() + 20); } + /** + * Resets the size of the component based on the points bounds. + */ public void resetSize() { if (dx == null) return; Vector v1 = dx.pointlist; @@ -182,10 +220,18 @@ public void resetSize() { scrollToCenter(); } + /** + * Invoked when the component's size changes. + * + * @param e the component event + */ public void componentResized(ComponentEvent e) { resetSize(); } + /** + * Scrolls the view to the center of the component. + */ public void scrollToCenter() { Rectangle rc1 = scroll.getViewport().getBounds(); JScrollBar b1 = scroll.getHorizontalScrollBar(); @@ -203,6 +249,9 @@ public void componentShown(ComponentEvent e) { public void componentHidden(ComponentEvent e) { } + /** + * Centers all objects within the view. + */ public void centerAllObject() { Vector v1 = dx.pointlist; this.getPointsBounds(v1); @@ -211,6 +260,13 @@ public void centerAllObject() { yy = (int) ((this.getHeight() - rc.getHeight() * scale) / 2 - rc.getY() * scale); } + /** + * Loads a rule based on the type and index. + * + * @param t the type of the rule + * @param n the index of the rule + * @return true if the rule is loaded successfully, false otherwise + */ public boolean loadRule(int t, int n) { String s = n + ""; @@ -236,19 +292,11 @@ public boolean loadRule(int t, int n) { } - private void loadRemote(String sh) { - try { - URL ul = new URL(/*gxInstance.getDocumentBase()*/ CMisc.getHomeDirectory(), sh); - URLConnection urlc = ul.openConnection(); - urlc.connect(); - InputStream instream = urlc.getInputStream(); - DataInputStream in = new DataInputStream(instream); - dx.Load(in); - } - catch (IOException ee) { - } - } - + /** + * Constructs a new RuleViewPane with the specified GExpert instance. + * + * @param gx the GExpert instance + */ public RuleViewPane(GExpert gx) { gxInstance = gx; xx = yy = 0; @@ -273,6 +321,12 @@ public void mouseWheelMoved(MouseWheelEvent e) { //this.setBackground(Color.lightGray); } + /** + * Returns the bounds of the points in the given vector. + * + * @param v the vector of points + * @return the bounds of the points + */ public Rectangle getPointsBounds(Vector v) { if (v.size() == 0) return rc; CPoint p1 = (CPoint) v.get(0); @@ -296,6 +350,11 @@ else if (y0 < y1) return rc; } + /** + * Invoked when a mouse button is pressed on a component. + * + * @param e the mouse event + */ public void mouseDragged(MouseEvent e) { dx.DWMouseDrag((e.getX() - xx) / scale, (e.getY() - yy) / scale); dx.reCalculate(); @@ -303,6 +362,11 @@ public void mouseDragged(MouseEvent e) { this.repaint(); } + /** + * Invoked when the mouse cursor has been moved onto a component but no buttons have been pushed. + * + * @param e the mouse event + */ public void mouseMoved(MouseEvent e) { dx.DWMouseMove((e.getX() - xx) / scale, (e.getY() - yy) / scale); dx.reCalculate(); @@ -312,7 +376,11 @@ public void mouseMoved(MouseEvent e) { public void mouseClicked(MouseEvent e) { } - + /** + * Invoked when a mouse button has been pressed on a component. + * + * @param e the mouse event + */ public void mousePressed(MouseEvent e) { dx.DWButtonDown((e.getX() - xx) / scale, (e.getY() - yy) / scale); dx.reCalculate(); @@ -320,7 +388,11 @@ public void mousePressed(MouseEvent e) { this.repaint(); } - + /** + * Invoked when a mouse button has been released on a component. + * + * @param e the mouse event + */ public void mouseReleased(MouseEvent e) { dx.DWButtonUp((e.getX() - xx) / scale, (e.getY() - yy) / scale); dx.reCalculate(); @@ -328,15 +400,17 @@ public void mouseReleased(MouseEvent e) { this.repaint(); } - public void mouseEntered(MouseEvent e) { } - public void mouseExited(MouseEvent e) { } - + /** + * Paints this component. + * + * @param g the graphics context to use for painting + */ protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; diff --git a/src/main/java/wprover/RunningDialog.java b/src/main/java/wprover/RunningDialog.java index 8f948979..664d3439 100644 --- a/src/main/java/wprover/RunningDialog.java +++ b/src/main/java/wprover/RunningDialog.java @@ -9,11 +9,8 @@ import java.awt.*; /** - * Created by IntelliJ IDEA. - * User: ye - * Date: 2008-4-10 - * Time: 13:30:36 - * To change this template use File | Settings | File Templates. + * RunningDialog is a class that extends JPopupMenu and implements ActionListener. + * It provides a dialog to show the progress of a running process in a graphical user interface. */ public class RunningDialog extends JPopupMenu implements ActionListener { public static Timer timer = null; @@ -27,6 +24,12 @@ public class RunningDialog extends JPopupMenu implements ActionListener { private static Color color = new Color(206, 223, 242); + /** + * Constructs a new RunningDialog with the specified GExpert instance and message string. + * + * @param gx the GExpert instance to associate with this dialog + * @param s the message string to display in the dialog + */ public RunningDialog(GExpert gx, String s) { this.setBorder(BorderFactory.createCompoundBorder( new DropShadowBorder(), BorderFactory.createLineBorder(color, 10))); @@ -55,30 +58,59 @@ public Dimension getPreferredSize() { panel.add(Box.createHorizontalGlue()); panel.add(labelt); this.add(panel); - } + /** + * Called when the menu selection changes. + * + * @param isIncluded whether the menu is included in the selection + */ public void menuSelectionChanged(boolean isIncluded) { } + /** + * Sets the PanelGB instance associated with this dialog. + * + * @param gb the PanelGB instance to set + */ public void setPanelGB(PanelGB gb) { panegb = gb; } + /** + * Returns the preferred size of this component. + * + * @return the preferred size of this component + */ public Dimension getPreferredSize() { Dimension d = super.getPreferredSize(); d.setSize(300, d.getHeight()); return d; } + /** + * Sets the string to be shown in the dialog. + * + * @param s the string to set + */ public void setShownString(String s) { str = s; } + /** + * Starts the timer count by recording the current time. + */ public void startCount() { start_time = System.currentTimeMillis(); } + /** + * Starts the timer and displays the RunningDialog. + * + * @param gx the GExpert instance to associate with this dialog + * @param s the message string to display in the dialog + * @return the RunningDialog instance if the timer is not already running, null otherwise + */ public static RunningDialog startTimer(GExpert gx, String s) { if (timer != null && timer.isRunning()) return null; @@ -104,6 +136,9 @@ public static RunningDialog startTimer(GExpert gx, String s) { return r; } + /** + * Stops the timer and hides the RunningDialog. + */ public void stopTimer() { if (timer != null) timer.stop(); @@ -111,6 +146,11 @@ public void stopTimer() { this.setVisible(false); } + /** + * Handles action events for the timer and stop button. + * + * @param e the ActionEvent triggered by the timer or stop button + */ public void actionPerformed(ActionEvent e) { if (e.getSource() == timer) { counter++; diff --git a/src/main/java/wprover/SecondCounterDemo.java b/src/main/java/wprover/SecondCounterDemo.java index 462f00f5..be86106d 100644 --- a/src/main/java/wprover/SecondCounterDemo.java +++ b/src/main/java/wprover/SecondCounterDemo.java @@ -10,11 +10,9 @@ import java.text.DecimalFormat; /** - * Created by IntelliJ IDEA. - * User: ye - * Date: Nov 15, 2006 - * Time: 2:14:26 PM - * To change this template use File | Settings | File Templates. + * SecondCounterDemo is a class that extends JBaseDialog and provides a + * countdown timer with a graphical user interface. It displays the elapsed time + * in seconds and allows the user to stop the countdown. */ // FIXME. This is unused at the moment. public class SecondCounterDemo extends JBaseDialog { @@ -22,6 +20,12 @@ public class SecondCounterDemo extends JBaseDialog { boolean visible = false; Thread mainThread; + /** + * Constructs a new SecondCounterDemo with the specified GExpert instance and main thread. + * + * @param fr the GExpert instance to associate with this dialog + * @param main the main thread to be used by this dialog + */ public SecondCounterDemo(GExpert fr, Thread main) { super(fr.getFrame(), "Building fixpoint...."); mainThread = main; @@ -33,13 +37,20 @@ public SecondCounterDemo(GExpert fr, Thread main) { this.setAlwaysOnTop(true); this.requestFocus(); } - } + /** + * Sets the main thread for this dialog. + * + * @param m the main thread to set + */ public void setMainThread(Thread m) { mainThread = m; } + /** + * Starts the countdown timer and centers the dialog on the screen. + */ public void startCounting() { Window fr = this.getOwner(); if (fr != null) @@ -47,22 +58,24 @@ public void startCounting() { pane.startCounting(); } + /** + * Stops the countdown timer and hides the dialog. + */ public void stopCounting() { pane.stopCounting(); } - + /** + * CounterPanel is a custom JPanel that contains the countdown timer and stop button. + */ class CounterPanel extends JPanel { private SecondCounterRunnable sc = new SecondCounterRunnable(); - - private JButton stopB = new JButton("Stop"); + RenderingHints qualityHints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - RenderingHints qualityHints = new RenderingHints(RenderingHints. - KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); -// qualityHints.put(RenderingHints.key) - + /** + * Constructs a new CounterPanel and initializes its components. + */ public CounterPanel() { stopB.setEnabled(false); // begin with this disabled @@ -88,40 +101,52 @@ public void actionPerformed(ActionEvent e) { this.add(sc, BorderLayout.CENTER); } + /** + * Starts the countdown timer in a new thread. + */ public void startCounting() { - Thread counterThread = new Thread(sc, "Counter"); counterThread.start(); stopB.setEnabled(true); stopB.requestFocus(); } + /** + * Stops the countdown timer and hides the dialog. + */ public void stopCounting() { sc.stopClock(); SecondCounterDemo.this.setVisible(false); } + /** + * SecondCounterRunnable is a custom JComponent that implements Runnable to provide the countdown timer functionality. + */ class SecondCounterRunnable extends JComponent implements Runnable { private volatile boolean keepRunning; - private Font paintFont = new Font("SansSerif", Font.BOLD, 14); - private volatile String timeMsg = "never started"; - private volatile int arcLen = 0; private long normalSleepTime = 100; + /** + * Constructs a new SecondCounterRunnable. + */ public SecondCounterRunnable() { } + /** + * Runs the countdown timer. + */ public void run() { runClock(); } + /** + * Runs the countdown timer and updates the display. + */ public void runClock() { DecimalFormat fmt = new DecimalFormat("0.000"); - - int counter = 0; keepRunning = true; @@ -145,10 +170,18 @@ else if (counter > 30) { } } + /** + * Stops the countdown timer. + */ public void stopClock() { keepRunning = false; } + /** + * Paints the countdown timer. + * + * @param g the graphics context to use for painting + */ public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; // g2.setRenderingHints(qualityHints); @@ -166,6 +199,5 @@ public void paint(Graphics g) { g2.fillArc(2, 22, 96, 96, 90, -arcLen); } } - } } \ No newline at end of file diff --git a/src/main/java/wprover/SelectDialog.java b/src/main/java/wprover/SelectDialog.java index 96d9964b..003f45ab 100644 --- a/src/main/java/wprover/SelectDialog.java +++ b/src/main/java/wprover/SelectDialog.java @@ -8,11 +8,9 @@ import java.util.Vector; /** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2005-7-19 - * Time: 11:42:51 - * To change this template use File | Settings | File Templates. + * SelectDialog is a class that extends JBaseDialog and implements ActionListener, + * ListSelectionListener, MouseListener, MouseMotionListener, and KeyListener interfaces. + * It provides a dialog for selecting items from a list. */ public class SelectDialog extends JBaseDialog implements ActionListener, ListSelectionListener, MouseListener, MouseMotionListener, KeyListener { @@ -31,6 +29,12 @@ public class SelectDialog extends JBaseDialog implements private static Font listFont = new Font("Arial", Font.PLAIN, 12); + /** + * Constructs a new SelectDialog with the specified GExpert instance and list of items. + * + * @param owner the GExpert instance to associate with this dialog + * @param vlist the list of items to display in the dialog + */ public SelectDialog(GExpert owner, Vector vlist) { super(owner.getFrame(), "Select"); gxInstance = owner; @@ -45,8 +49,8 @@ public SelectDialog(GExpert owner, Vector vlist) { list.addMouseMotionListener(this); JScrollPane listScrollPane = new JScrollPane(list); list.setFont(listFont); -// list.addKeyListener(this); -// this.addKeyListener(this); + // list.addKeyListener(this); + // this.addKeyListener(this); cancle_button = new JButton(str); cancle_button.addActionListener(this); @@ -61,10 +65,20 @@ public SelectDialog(GExpert owner, Vector vlist) { addItem(vlist); } + /** + * Handles the mouse dragged event. + * + * @param e the MouseEvent triggered by dragging the mouse + */ public void mouseDragged(MouseEvent e) { } + /** + * Handles the mouse moved event. + * + * @param e the MouseEvent triggered by moving the mouse + */ public void mouseMoved(MouseEvent e) { Rectangle rc = list.getCellBounds(0, 0); if (rc == null) @@ -81,6 +95,11 @@ else if (n >= listModel.getSize()) list.setSelectedIndex(n); } + /** + * Adds items to the list model and selected list. + * + * @param v the vector of items to add + */ public void addItem(Vector v) { listModel.clear(); selectedlist.clear(); @@ -92,6 +111,11 @@ public void addItem(Vector v) { } } + /** + * Handles the list selection event. + * + * @param e the ListSelectionEvent triggered by selecting an item in the list + */ public void valueChanged(ListSelectionEvent e) { int n = list.getSelectedIndex(); int len = selectedlist.size(); @@ -99,6 +123,11 @@ public void valueChanged(ListSelectionEvent e) { gxInstance.dp.setObjectListForFlash((CClass) selectedlist.get(n)); } + /** + * Handles the action event for the cancel button. + * + * @param e the ActionEvent triggered by clicking the cancel button + */ public void actionPerformed(ActionEvent e) { if (e.getSource() == cancle_button) { selectedlist.clear(); @@ -107,23 +136,43 @@ public void actionPerformed(ActionEvent e) { } } + /** + * Returns the selected item. + * + * @return the selected item + */ public Object getSelected() { return selected; } + /** + * Handles the mouse clicked event. + * + * @param e the MouseEvent triggered by clicking the mouse + */ public void mouseClicked(MouseEvent e) { } + /** + * Displays the dialog at the specified location. + * + * @param x the x-coordinate of the location + * @param y the y-coordinate of the location + */ public void popSelect(int x, int y) { oldx = x; oldy = y; this.setLocation(oldx, oldy); this.setFocusable(true); this.setVisible(true); - } + /** + * Handles the mouse pressed event. + * + * @param e the MouseEvent triggered by pressing the mouse + */ public void mousePressed(MouseEvent e) { int index = list.getSelectedIndex(); if (index < 0 || index >= selectedlist.size()) @@ -132,22 +181,46 @@ public void mousePressed(MouseEvent e) { this.setVisible(false); } + /** + * Handles the mouse released event. + * + * @param e the MouseEvent triggered by releasing the mouse + */ public void mouseReleased(MouseEvent e) { - } + /** + * Handles the mouse entered event. + * + * @param e the MouseEvent triggered by entering the mouse + */ public void mouseEntered(MouseEvent e) { } + /** + * Handles the mouse exited event. + * + * @param e the MouseEvent triggered by exiting the mouse + */ public void mouseExited(MouseEvent e) { } + /** + * Handles the key typed event. + * + * @param e the KeyEvent triggered by typing a key + */ public void keyTyped(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ESCAPE) this.setVisible(false); } + /** + * Handles the key pressed event. + * + * @param e the KeyEvent triggered by pressing a key + */ public void keyPressed(KeyEvent e) { super.keyPressed(e); } diff --git a/src/main/java/wprover/SpecificAngleDialog.java b/src/main/java/wprover/SpecificAngleDialog.java index b5befa9f..a9981513 100644 --- a/src/main/java/wprover/SpecificAngleDialog.java +++ b/src/main/java/wprover/SpecificAngleDialog.java @@ -9,14 +9,11 @@ import java.util.Vector; /** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2005-11-3 - * Time: 10:05:14 - * To change this template use File | Settings | File Templates. + * SpecificAngleDialog is a class that extends JBaseDialog and implements ActionListener and ItemListener. + * It provides a dialog for selecting specific angles in a graphical application. */ public class SpecificAngleDialog extends JBaseDialog implements ActionListener, ItemListener { - JCheckBox cb1, cb2, cb3, cb4, cb5,cb6; // 30,45,60,75,120 + JCheckBox cb1, cb2, cb3, cb4, cb5, cb6; // 30,45,60,75,120 JButton bok, bca; int type; // 0: define, 1 alread define 2 setangle. @@ -24,6 +21,13 @@ public class SpecificAngleDialog extends JBaseDialog implements ActionListener, int rtype = 0; GExpert gxInstance; + /** + * Constructs a new SpecificAngleDialog with the specified GExpert instance, type, and vector of angles. + * + * @param owner the GExpert instance to associate with this dialog + * @param type the type of the dialog (0: define, 1: already defined, 2: set angle) + * @param v the vector of angles to be used in the dialog + */ public SpecificAngleDialog(GExpert owner, int type, Vector v) { super(owner.getFrame(), true); gxInstance = owner; @@ -49,7 +53,6 @@ public SpecificAngleDialog(GExpert owner, int type, Vector v) { cb5.addItemListener(this); cb6.addItemListener(this); - JPanel panel2 = new JPanel(); panel2.setLayout(new BoxLayout(panel2, BoxLayout.X_AXIS)); bok = new JButton(gxInstance.getLanguage(GExpert.getLanguage("OK"))); @@ -86,7 +89,7 @@ else if (value == 75) cb4.setEnabled(true); else if (value == 120) cb5.setEnabled(true); - else if(value == 0) + else if (value == 0) cb6.setEnabled(true); } bok.setEnabled(false); @@ -110,7 +113,7 @@ else if (value == 75) cb4.setEnabled(true); else if (value == 120) cb5.setEnabled(true); - else if(value == 0) + else if (value == 0) cb6.setEnabled(true); } } @@ -118,6 +121,11 @@ else if(value == 0) owner.centerDialog(this); } + /** + * Handles the action events for the OK and Cancel buttons. + * + * @param e the ActionEvent triggered by clicking a button + */ public void actionPerformed(ActionEvent e) { String command = e.getActionCommand(); Object obj = e.getSource(); @@ -129,13 +137,22 @@ public void actionPerformed(ActionEvent e) { rtype = 0; this.setVisible(false); } - } + /** + * Checks if the OK button was pressed. + * + * @return true if the OK button was pressed, false otherwise + */ public boolean isOkPressed() { return rtype == 1; } + /** + * Handles the item state change events for the checkboxes. + * + * @param e the ItemEvent triggered by selecting or deselecting a checkbox + */ public void itemStateChanged(ItemEvent e) { if (type == 0) return; if (e.getStateChange() == ItemEvent.SELECTED) { @@ -150,19 +167,16 @@ public void itemStateChanged(ItemEvent e) { cb3.setSelected(false); cb4.setSelected(false); cb5.setSelected(false); - } else if (obj == cb3) { cb1.setSelected(false); cb2.setSelected(false); cb4.setSelected(false); cb5.setSelected(false); - } else if (obj == cb4) { cb1.setSelected(false); cb2.setSelected(false); cb3.setSelected(false); cb5.setSelected(false); - } else if (obj == cb5) { cb2.setSelected(false); cb3.setSelected(false); @@ -172,7 +186,11 @@ public void itemStateChanged(ItemEvent e) { } } - + /** + * Returns the vector of selected specific angles. + * + * @return the vector of selected specific angles + */ public Vector getSpecificAngle() { Vector v = new Vector(); if (cb1.isSelected()) diff --git a/src/main/java/wprover/TextFrame.java b/src/main/java/wprover/TextFrame.java index 9d5cd9b5..92f5a36a 100644 --- a/src/main/java/wprover/TextFrame.java +++ b/src/main/java/wprover/TextFrame.java @@ -14,11 +14,10 @@ /** - * Created by IntelliJ IDEA. - * User: Administrator - * Date: 2005-2-27 - * Time: 21:05:35 - * To change this template use File | Settings | File Templates. + * TextFrame.java + * This class represents a dialog for editing text properties in a drawing application. + * It allows users to set font, size, style, and color for the text. + * The class also provides functionality for cut, copy, paste, delete, and select all operations. */ public class TextFrame extends JBaseDialog implements ItemListener, ActionListener, FocusListener, MouseListener { @@ -37,6 +36,11 @@ public class TextFrame extends JBaseDialog implements ItemListener, int x, y; + + /** + * Initializes the TextFrame with font, size, style, and color options. + * Sets up the layout and components for the text editing toolbar. + */ public void init() { Font tf = new Font("Dialog", Font.PLAIN, 12); @@ -54,16 +58,8 @@ public Dimension getPreferredSize() { GraphicsEnvironment gEnv = GraphicsEnvironment.getLocalGraphicsEnvironment(); String envfonts[] = gEnv.getAvailableFontFamilyNames(); - Font cfont = null; -// for (int i = 0; i < envfonts.length; i++) { -// if (envfonts[i].equalsIgnoreCase("Dialog")) { -// cfont = new Font("Dialog", Font.PLAIN, 16); -// break; -// } -// } - if (cfont == null) - cfont = new Font("Dialog", Font.PLAIN, 16); - + Font cfont = new Font("Dialog", Font.PLAIN, 16); + fontfamily = new Vector(); for (int i = 1; i < envfonts.length; i++) fontfamily.addElement(envfonts[i]); @@ -135,6 +131,11 @@ public Dimension getPreferredSize() { getContentPane().add(BorderLayout.SOUTH, tb); } + /** + * Sets the current font for the text pane and updates the font, size, and style selections. + * + * @param f the Font to set as the current font + */ public void setCurrentFont(Font f) { if (f == null) return; int size = f.getSize(); @@ -161,6 +162,13 @@ public void setCurrentFont(Font f) { } + /** + * Constructs a new TextFrame with the specified GExpert instance and coordinates. + * + * @param gx the GExpert instance to associate with this frame + * @param xt the x-coordinate for the frame + * @param yt the y-coordinate for the frame + */ public TextFrame(GExpert gx, double xt, double yt) { super(gx.getFrame()); this.gxInstance = gx; @@ -173,16 +181,16 @@ public TextFrame(GExpert gx, double xt, double yt) { this.init(); this.getContentPane().add(new JScrollPane(textpane)); text = null; - // setCurrentFont(gxInstance.getDefaultFont()); + // setCurrentFont(gxInstance.getDefaultFont()); this.setSize(550, 200); } - void setTextLocation(int x, int y) { - this.x = x; - this.y = y; - } - + /** + * Sets the text and font for the text pane based on the provided CText object. + * + * @param tx the CText object containing the text and font to set + */ void setText(CText tx) { if (tx != null) { text = tx; @@ -199,35 +207,30 @@ void setText(CText tx) { } } + /** + * Returns the preferred size of the TextFrame. + * + * @return the preferred Dimension of the TextFrame + */ public Dimension getPreferredSize() { Dimension dm = super.getPreferredSize(); dm.setSize(dm.getWidth(), 200); return dm; } - CText getText() { - - String s = (String) fonts.getSelectedItem(); - int size = ((Integer) sizes.getSelectedItem()).intValue(); - int type = styles.getSelectedIndex(); - Font f = new Font(s, type, size); - - if (text != null) { - text.setText(textpane.getText()); - text.setFont(f); - return text; - } else { - return null; - } - } - - String getString() { - return textpane.getText(); - } - + /** + * Handles item state change events for the combo boxes. + * + * @param e the ItemEvent triggered by selecting an item in a combo box + */ public void itemStateChanged(ItemEvent e) { } + /** + * Handles action events for the OK and Cancel buttons, and updates the text pane font and color. + * + * @param e the ActionEvent triggered by clicking a button + */ public void actionPerformed(ActionEvent e) { if (e.getSource() == bok) { String str = textpane.getText(); @@ -275,27 +278,11 @@ public void focusGained(FocusEvent e) { public void focusLost(FocusEvent e) { } - public void windowOpened(WindowEvent e) { - } - - public void windowClosing(WindowEvent e) { - } - - public void windowClosed(WindowEvent e) { - } - - public void windowIconified(WindowEvent e) { - } - - public void windowDeiconified(WindowEvent e) { - } - - public void windowActivated(WindowEvent e) { - } - - public void windowDeactivated(WindowEvent e) { - } - + /** + * Handles the mouse clicked event. + * + * @param e the MouseEvent triggered by clicking the mouse + */ public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3) { new TextPopupMenu(textpane.getSelectionStart() @@ -315,7 +302,16 @@ public void mouseEntered(MouseEvent e) { public void mouseExited(MouseEvent e) { } + /** + * TextPopupMenu is a class that extends JPopupMenu and implements ActionListener and ClipboardOwner. + * It provides a context menu for text editing operations such as Cut, Copy, Paste, Delete, and Select All. + */ class TextPopupMenu extends JPopupMenu implements ActionListener, ClipboardOwner { + /** + * Constructs a new TextPopupMenu with the specified selection state. + * + * @param selected whether the menu items should be enabled based on selection + */ public TextPopupMenu(boolean selected) { this.addMenuItem("Cut", selected); this.addMenuItem("Copy", selected); @@ -325,6 +321,12 @@ public TextPopupMenu(boolean selected) { this.addMenuItem("Select All", true); } + /** + * Adds a menu item to the popup menu. + * + * @param s the name of the menu item + * @param selected whether the menu item should be enabled + */ public void addMenuItem(String s, boolean selected) { JMenuItem item = new JMenuItem(s); item.addActionListener(TextPopupMenu.this); @@ -332,11 +334,21 @@ public void addMenuItem(String s, boolean selected) { this.add(item); } + /** + * Handles the loss of ownership of the clipboard. + * + * @param aClipboard the clipboard that this owner has lost ownership of + * @param aContents the contents which this owner had placed on the clipboard + */ public void lostOwnership(Clipboard aClipboard, Transferable aContents) { - //do nothing + // do nothing } - + /** + * Handles action events for the popup menu items. + * + * @param e the ActionEvent triggered by selecting a menu item + */ public void actionPerformed(ActionEvent e) { String s = e.getActionCommand(); if (s.equalsIgnoreCase("Cut")) { @@ -368,32 +380,31 @@ public void actionPerformed(ActionEvent e) { } } + /** + * Retrieves the contents of the system clipboard as a string. + * + * @return the clipboard contents as a string + */ public String getClipboardContents() { String result = ""; Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); - //odd: the Object param of getContents is not currently used Transferable contents = clipboard.getContents(TextPopupMenu.this); - Object oobs[] = clipboard.getAvailableDataFlavors(); boolean hasTransferableText = (contents != null) && contents.isDataFlavorSupported(DataFlavor.stringFlavor); if (hasTransferableText) { try { result = (String) contents.getTransferData(DataFlavor.stringFlavor); - } - catch (UnsupportedFlavorException ex) { - //highly unlikely since we are using a standard DataFlavor + } catch (UnsupportedFlavorException ex) { + // highly unlikely since we are using a standard DataFlavor System.out.println(ex); ex.printStackTrace(); - } - catch (IOException ex) { + } catch (IOException ex) { System.out.println(ex); ex.printStackTrace(); } } return result; } - } - } diff --git a/src/main/java/wprover/TextValueEditor.java b/src/main/java/wprover/TextValueEditor.java index 002646b7..bb4c4160 100644 --- a/src/main/java/wprover/TextValueEditor.java +++ b/src/main/java/wprover/TextValueEditor.java @@ -12,11 +12,9 @@ import java.util.Vector; /** - * Created by IntelliJ IDEA. - * User: ye - * Date: 2008-5-31 - * Time: 21:47:16 - * To change this template use File | Settings | File Templates. + * TextValueEditor is a dialog for editing mathematical expressions. + * It allows users to input and evaluate expressions using buttons and a text pane. + * The dialog also provides options to insert data points and functions into the expression. */ public class TextValueEditor extends JBaseDialog implements ActionListener, KeyListener { @@ -28,6 +26,12 @@ public class TextValueEditor extends JBaseDialog implements ActionListener, KeyL GExpert gxInstance; CText text = null; + /** + * Sets the text in the editor based on the provided CText object. + * Inserts the string from the CText into the styled document and updates the editor value. + * + * @param t the CText object containing the text to be set + */ public void setText(CText t) { text = t; //pane.setText(t.getString()); @@ -41,12 +45,17 @@ public void setText(CText t) { onValueUpdated(); } + /** + * Constructs a new TextValueEditor dialog with a specified GExpert context. + * Initializes the user interface components for editing mathematical expressions. + * + * @param gx the GExpert instance providing context for the dialog + */ public TextValueEditor(GExpert gx) { super(gx.getFrame(), GExpert.getLanguage("Calculation")); gxInstance = gx; - JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); @@ -186,13 +195,21 @@ public Dimension getPreferredSize() { } + /** + * Sets the text in the text pane and updates the value. + * + * @param s the text to set in the text pane + */ public void setText(String s) { pane.setText(s); this.onValueUpdated(); } + /** + * Updates the value displayed in the pane1 based on the text in the pane. + * Parses the text, calculates the value, and updates the pane1 with the result. + */ public void onValueUpdated() { - String s = pane.getText(); if (s == null || s.length() == 0) { pane1.setText(""); @@ -206,11 +223,16 @@ public void onValueUpdated() { doc.remove(0, doc.getLength()); doc.insertString(0, Double.toString(r), doc.getStyle("large")); } catch (Exception ee) { + // Handle exception } - } } + /** + * Handles action events for the buttons in the dialog. + * + * @param e the ActionEvent triggered by clicking a button + */ public void actionPerformed(ActionEvent e) { String command = e.getActionCommand(); if (command.equalsIgnoreCase("OK")) { @@ -248,7 +270,6 @@ public void actionPerformed(ActionEvent e) { } } catch (Exception ee) { ee.printStackTrace(); - } } else { if (command.equals("+") || command.equals("-") || command.equals("*") || command.equals("/")) @@ -259,20 +280,34 @@ public void actionPerformed(ActionEvent e) { doc.insertString(doc.getLength(), command, doc.getStyle("large1")); onValueUpdated(); } catch (Exception ee) { - + // Handle exception } - } } + /** + * Handles the key typed event. + * + * @param e the KeyEvent triggered by typing a key + */ public void keyTyped(KeyEvent e) { - + // No implementation needed } + /** + * Handles the key pressed event. + * + * @param e the KeyEvent triggered by pressing a key + */ public void keyPressed(KeyEvent e) { super.keyPressed(e); } + /** + * Handles the key released event and updates the value. + * + * @param e the KeyEvent triggered by releasing a key + */ public void keyReleased(KeyEvent e) { onValueUpdated(); } diff --git a/src/main/java/wprover/TransformConfirmDialog.java b/src/main/java/wprover/TransformConfirmDialog.java index cd09277c..54ca30a3 100644 --- a/src/main/java/wprover/TransformConfirmDialog.java +++ b/src/main/java/wprover/TransformConfirmDialog.java @@ -7,16 +7,21 @@ import java.awt.event.KeyEvent; /** - * Created by IntelliJ IDEA. - * User: ye - * Date: 2008-6-25 - * Time: 21:12:36 - * To change this template use File | Settings | File Templates. + * TransformConfirmDialog.java + * This class represents a confirmation dialog for transformations in the GExpert application. + * It extends JBaseDialog and implements ActionListener to handle button actions. */ public class TransformConfirmDialog extends JBaseDialog implements ActionListener { int result = -1; + /** + * Constructs a new TransformConfirmDialog with the specified frame and messages. + * + * @param f the parent frame for the dialog + * @param s1 the first message to display in the dialog + * @param s2 the second message to display in the dialog + */ public TransformConfirmDialog(Frame f, String s1, String s2) { super(f, "Confirm", true); @@ -70,6 +75,11 @@ else if (s.equalsIgnoreCase("N")) pack(); } + /** + * Handles action events for the buttons in the dialog. + * + * @param e the ActionEvent triggered by clicking a button + */ public void actionPerformed(ActionEvent e) { String s = e.getActionCommand(); if (s.equalsIgnoreCase("Yes")) @@ -79,16 +89,23 @@ else if (s.equalsIgnoreCase("No")) else result = 2; this.setVisible(false); - -// super.keyPressed(); } + /** + * Returns the result of the dialog. + * + * @return the result of the dialog (0 for Yes, 1 for No, 2 for Cancel) + */ public int getResult() { return result; } + /** + * Handles key pressed events for the dialog. + * + * @param e the KeyEvent triggered by pressing a key + */ public void keyPressed(KeyEvent e) { - int code = e.getKeyCode(); if (code == KeyEvent.VK_Y) { result = 0; @@ -102,6 +119,4 @@ public void keyPressed(KeyEvent e) { } super.keyPressed(e); } - - } diff --git a/src/main/java/wprover/TreeCellOpaqueRender.java b/src/main/java/wprover/TreeCellOpaqueRender.java index fcd2d2f5..31f15555 100644 --- a/src/main/java/wprover/TreeCellOpaqueRender.java +++ b/src/main/java/wprover/TreeCellOpaqueRender.java @@ -12,13 +12,11 @@ import java.util.Vector; /** - * Created by IntelliJ IDEA. - * User: yezheng - * Date: 2006-6-8 - * Time: 13:30:48 - * To change this template use File | Settings | File Templates. + * TreeCellOpaqueRender.java + * This class is a custom tree cell renderer and editor for a JTree component. + * It provides a way to display and edit tree nodes with custom rendering and editing capabilities. + * The class implements TreeCellRenderer and TreeCellEditor interfaces. */ - public class TreeCellOpaqueRender extends JPanel implements TreeCellRenderer, MouseListener { static Icon Icon_etri = GExpert.createImageIcon("images/dtree/etri.gif"); static Icon Icon_squa = GExpert.createImageIcon("images/dtree/squa.gif"); @@ -409,6 +407,12 @@ public Component getTreeCellRendererComponent(JTree tree, Object value, } } +/** + * TreeCellOPaqueEditor.java + * This class is a custom tree cell editor for a JTree component. + * It provides a way to edit tree nodes with custom rendering and editing capabilities. + * The class implements TreeCellEditor interface. + */ class TreeCellOPaqueEditor extends AbstractCellEditor implements TreeCellEditor { TreeCellOpaqueRender render; @@ -467,30 +471,12 @@ public void reset() { } -//class TreeCellOpaquePanel extends JPanel { -// JLabel label1, label2, label3; -// -// public TreeCellOpaquePanel() { -// this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); -// label1 = new JLabel(); -// label2 = new JLabel(); -// label3 = new JLabel(); -// this.add(label1); -// this.add(label2); -// this.add(label3); -// } -// -// public void setUserObject(Object obj) { -// massertion ass = (massertion) obj; -// ass.checkValid(); -// } -// -//} - +/** + * TreeCellAssertPanel.java + * This class is a custom panel for displaying assertions in a tree cell. + * It extends JPanel and implements MouseListener for handling mouse events. + */ class TreeCellAssertPanel extends JPanel implements MouseListener { -// private Color backgroundColor = (UIManager.getColor("Tree.selectionBackground")); -// -// private Color backgroundNoSelectionColor = UIManager.getColor("Tree.textBackground"); private static Color bcolor = new Color(204, 255, 204); private Vector vlist = new Vector(); @@ -721,8 +707,12 @@ public void addMouseListener(MouseListener l) { } +/** + * TreeCellOpaqueLabel.java + * This class is a custom label for displaying tree cell values. + * It extends JLabel and implements MouseListener for handling mouse events. + */ class TreeCellOpaqueLabel extends JLabel implements MouseListener { -// static Font font = (new Font("Dialog", Font.BOLD, 14)); protected boolean selected; protected boolean mousein; private Object userObject; @@ -795,31 +785,6 @@ public Object getUserObject() { return userObject; } - private void setLeafIcon(Icon newIcon) { - leafIcon = newIcon; - this.setIcon(leafIcon); - } - - private Icon getLeafIcon() { - return leafIcon; - } - - private void setTextSelectionColor(Color newColor) { - textSelectionColor = newColor; - } - - private Color getTextSelectionColor() { - return textSelectionColor; - } - - private void setTextNonSelectionColor(Color newColor) { - textNonSelectionColor = newColor; - } - - private Color getTextNonSelectionColor() { - return textNonSelectionColor; - } - private void setBackgroundSelectionColor(Color newColor) { backgroundSelectionColor = newColor; } @@ -828,22 +793,10 @@ private Color getBackgroundSelectionColor() { return backgroundSelectionColor; } - private void setBackgroundNonSelectionColor(Color newColor) { - backgroundNonSelectionColor = newColor; - } - - private Color getBackgroundNonSelectionColor() { - return backgroundNonSelectionColor; - } - private void setBorderSelectionColor(Color newColor) { borderSelectionColor = newColor; } - private Color getBorderSelectionColor() { - return borderSelectionColor; - } - public void setFont(Font font) { if (font instanceof FontUIResource) font = null; @@ -913,14 +866,6 @@ public void paint(Graphics g) { super.paint(g); } - private int getLabelStart() { - Icon currentI = getIcon(); - if (currentI != null && getText() != null) { - return currentI.getIconWidth() + Math.max(0, getIconTextGap() - 1); - } - return 0; - } - public void mouseClicked(MouseEvent e) { } diff --git a/src/main/java/wprover/UndoEditDialog.java b/src/main/java/wprover/UndoEditDialog.java index a4676980..ed4e22b4 100644 --- a/src/main/java/wprover/UndoEditDialog.java +++ b/src/main/java/wprover/UndoEditDialog.java @@ -6,15 +6,20 @@ import java.awt.event.WindowEvent; /** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2005-8-12 - * Time: 11:31:35 - * To change this template use File | Settings | File Templates. + * UndoEditDialog.java + * This class represents a dialog for displaying the undo edit history in a tree structure. + * It extends JBaseDialog and implements WindowListener to handle window events. */ public class UndoEditDialog extends JBaseDialog implements WindowListener { private ListTree treepanel; + /** + * Constructs a new UndoEditDialog with the specified GExpert owner. + * Sets the title, initializes the tree panel, sets the content pane, + * sets the size, centers the dialog, and adds a window listener. + * + * @param owner the GExpert instance that owns this dialog + */ public UndoEditDialog(GExpert owner) { super(owner.getFrame()); this.setTitle(owner.getLanguage("Construct History")); @@ -30,6 +35,9 @@ ListTree getTreePanel() { return treepanel; } + /** + * Displays the dialog and reloads the tree panel. + */ public void showDialog() { this.setVisible(true); treepanel.reload(); diff --git a/src/main/java/wprover/UndoStruct.java b/src/main/java/wprover/UndoStruct.java index dc3fa859..cd27e44d 100644 --- a/src/main/java/wprover/UndoStruct.java +++ b/src/main/java/wprover/UndoStruct.java @@ -9,11 +9,10 @@ import java.awt.*; /** - * Created by IntelliJ IDEA. - * User: Ye - * Date: 2005-8-11 - * Time: 9:34:44 - * To change this template use File | Settings | File Templates. + * UndoStruct is a class that represents an undo structure in a drawing application. + * It contains information about the current state of the drawing, including points, + * lines, circles, angles, constraints, and other objects. It also provides methods + * for saving and loading the state to/from a data stream. */ class UndoStruct { @@ -68,8 +67,6 @@ public UndoStruct(int type, int pc) { int plineCounter_b = 0; int pcircleCounter_b = 0; - - ////////////////////////////////////////////////////// TPoly polylist = null; TPoly pblist = null; @@ -83,17 +80,27 @@ public UndoStruct(int type, int pc) { Vector textlist = new Vector(); Vector tracklist = new Vector(); Vector otherlist = new Vector(); - //////////////////////////// Vector objectlist = new Vector(); // object related to this node. Vector childundolist = new Vector(); - ////////////////////////////////////////////// added 2006.7.8. Vector dlist = new Vector(); + /** + * Adds an object to the list of objects in the undo structure. + * + * @param obj the object to add to the list + */ public void addObject(Object obj) { dlist.add(obj); } + /** + * Returns a string representation of the undo structure. + * If the list of objects is empty, returns the message. + * Otherwise, returns a description of the action performed. + * + * @return a string representation of the undo structure + */ public String toString() { if (dlist.size() == 0) { return msg; @@ -117,6 +124,9 @@ public String toString() { } } + /** + * Clears all lists and resets the polygon and polyline lists to null. + */ public void clear() { polylist = pblist = null; pointlist.clear(); @@ -128,9 +138,13 @@ public void clear() { textlist.clear(); polygonlist.clear(); otherlist.clear(); - } + /** + * Draws all objects in the undo structure using the provided Graphics2D object. + * + * @param g2 the Graphics2D object to use for drawing + */ public void draw(Graphics2D g2) { drawlist(polygonlist, g2); drawlist(tracklist, g2); @@ -138,14 +152,17 @@ public void draw(Graphics2D g2) { drawlist(anglelist, g2); drawlist(linelist, g2); drawlist(circlelist, g2); - drawlist(pointlist, g2); - drawlist(textlist, g2); drawlist(otherlist, g2); - } + /** + * Retrieves the undo structure with the specified ID. + * + * @param id the ID of the undo structure to retrieve + * @return the undo structure with the specified ID, or null if not found + */ public UndoStruct getUndoStructByid(int id) { if (this.m_id == id) { return this; @@ -161,18 +178,12 @@ public UndoStruct getUndoStructByid(int id) { } } - public void setInFlashing(boolean inflash) { - setListInFlashing(objectlist, inflash); - } - - private void setListInFlashing(Vector v, boolean inflash) { - for (int i = 0; i < v.size(); i++) { - CClass cc = (CClass) v.get(i); - cc.setInFlashing(inflash); - - } - } - + /** + * Draws all objects in the provided list using the provided Graphics2D object. + * + * @param v the list of objects to draw + * @param g2 the Graphics2D object to use for drawing + */ private void drawlist(Vector v, Graphics2D g2) { for (int i = 0; i < v.size(); i++) { CClass c = (CClass) v.get(i); @@ -180,14 +191,23 @@ private void drawlist(Vector v, Graphics2D g2) { } } + /** + * Adds a related object to the list of related objects in the undo structure. + * + * @param cc the related object to add + */ public void addRelatedObject(CClass cc) { if (!objectlist.contains(cc)) { objectlist.add(cc); } } + /** + * Checks if the node is valued by comparing various counters. + * + * @return true if the node is valued, false otherwise + */ public boolean isNodeValued() { - // return pointlist.size() != 0 ; if (m_id - id_b != 0) return true; return pnameCounter - pnameCounter_b != 0 @@ -195,33 +215,11 @@ public boolean isNodeValued() { || plineCounter_b - plineCounter != 0; } - - public void merge(UndoStruct undo1, UndoStruct undo2) { - - action = -1; // combined. - msg = "cb"; - - id = undo1.id; - current_id = undo1.current_id; - paraCounter = undo1.paraCounter; - pnameCounter = undo1.pnameCounter; - plineCounter = undo1.plineCounter; - pcircleCounter = undo1.pcircleCounter; - - id_b = undo2.id_b; - paraCounter_b = undo2.paraCounter_b; - pnameCounter_b = undo2.pnameCounter_b; - plineCounter_b = undo2.plineCounter_b; - pcircleCounter_b = undo2.pcircleCounter_b; - - } - - public void addchild(UndoStruct u) { - if (!childundolist.contains(u)) { - childundolist.add(u); - } - } - + /** + * Adds all objects from the provided list to the list of related objects in the undo structure. + * + * @param v the list of objects to add + */ public void addObjectRelatedList(Vector v) { for (int i = 0; i < v.size(); i++) { Object obj = v.get(i); @@ -231,6 +229,12 @@ public void addObjectRelatedList(Vector v) { } } + /** + * Retrieves all objects related to the undo structure from the draw process. + * + * @param dp the draw process to retrieve objects from + * @return a list of all related objects + */ public Vector getAllObjects(DrawProcess dp) { Vector v = new Vector(); @@ -263,6 +267,13 @@ public Vector getAllObjects(DrawProcess dp) { return v; } + /** + * Saves a list of objects to a data output stream. + * + * @param out the DataOutputStream to write to + * @param v the list of objects to save + * @throws IOException if an I/O error occurs + */ public void SaveList(DataOutputStream out, Vector v) throws IOException { int n = v.size(); if (n > 999) { @@ -275,8 +286,15 @@ public void SaveList(DataOutputStream out, Vector v) throws IOException { } } - public Vector ReadList(DataInputStream in, DrawProcess dp) throws - IOException { + /** + * Reads a list of objects from a data input stream. + * + * @param in the DataInputStream to read from + * @param dp the DrawProcess to retrieve objects by ID + * @return a list of objects read from the input stream + * @throws IOException if an I/O error occurs + */ + public Vector ReadList(DataInputStream in, DrawProcess dp) throws IOException { int size = in.readInt(); Vector v = new Vector(); @@ -290,9 +308,13 @@ public Vector ReadList(DataInputStream in, DrawProcess dp) throws return v; } - + /** + * Saves the current state of the undo structure to a data output stream. + * + * @param out the DataOutputStream to write to + * @throws IOException if an I/O error occurs + */ public void Save(DataOutputStream out) throws IOException { - out.writeInt(m_id); out.writeInt(m_type); out.writeBoolean(done); @@ -317,11 +339,6 @@ public void Save(DataOutputStream out) throws IOException { } else out.writeInt(n); -// if (msg != null && n > 0) { -// byte[] b = msg.getBytes(); -// out.write(b); -// } - out.writeInt(id_b); out.writeInt(paraCounter_b); out.writeInt(pnameCounter_b); @@ -337,14 +354,19 @@ public void Save(DataOutputStream out) throws IOException { UndoStruct u = (UndoStruct) childundolist.get(i); u.Save(out); } - } } + /** + * Loads the state of the undo structure from a data input stream. + * + * @param in the DataInputStream to read from + * @param dp the DrawProcess to retrieve objects by ID + * @throws IOException if an I/O error occurs + */ public void Load(DataInputStream in, DrawProcess dp) throws IOException { if (CMisc.version_load_now >= 0.019) { m_id = in.readInt(); - } else { m_id = CMisc.id_count++; } diff --git a/src/main/java/wprover/VFontChooser.java b/src/main/java/wprover/VFontChooser.java index e70b801a..52bed984 100644 --- a/src/main/java/wprover/VFontChooser.java +++ b/src/main/java/wprover/VFontChooser.java @@ -46,14 +46,10 @@ import java.sql.SQLException; /** - * Created by IntelliJ IDEA. - * User: yezheng - * Date: 2006-6-28 - * Time: 22:01:58 - * To change this template use File | Settings | File Templates. + * VFontChooser is a class that extends JBaseDialog and provides a font chooser + * dialog for selecting fonts, sizes, and styles. It includes checkboxes for + * various font effects and a color picker. */ - - public class VFontChooser extends JBaseDialog { protected int Closed_Option = JOptionPane.CLOSED_OPTION; @@ -88,6 +84,12 @@ public class VFontChooser extends JBaseDialog { private GExpert gxInstance; + /** + * Constructs a VFontChooser dialog with the specified owner. + * Initializes the dialog components and sets up the layout. + * + * @param owner the GExpert instance that owns this dialog + */ private VFontChooser(GExpert owner) { super(owner.getFrame(), "Font Chooser", true); gxInstance = owner; @@ -228,12 +230,23 @@ public void actionPerformed(ActionEvent e) { } + /** + * Returns the language-specific string for the given key. + * + * @param s the key for the language string + * @return the language-specific string + */ String getLanguage(String s) { if (gxInstance != null) return gxInstance.getLanguage(s); return s; } + /** + * Sets the attributes for the font chooser based on the given AttributeSet. + * + * @param a the AttributeSet containing font attributes + */ private void setAttributes(AttributeSet a) { attributes = new SimpleAttributeSet(a); String name = StyleConstants.getFontFamily(a); @@ -250,29 +263,38 @@ private void setAttributes(AttributeSet a) { updatePreview(); } + /** + * Retrieves the current font attributes from the font chooser. + * + * @return the AttributeSet containing the current font attributes + */ private AttributeSet getAttributes() { if (attributes == null) return null; - StyleConstants.setFontFamily(attributes, fontNameInputList - .getSelected()); - StyleConstants.setFontSize(attributes, fontSizeInputList - .getSelectedInt()); + StyleConstants.setFontFamily(attributes, fontNameInputList.getSelected()); + StyleConstants.setFontSize(attributes, fontSizeInputList.getSelectedInt()); StyleConstants.setBold(attributes, boldCheckBox.isSelected()); StyleConstants.setItalic(attributes, italicCheckBox.isSelected()); StyleConstants.setUnderline(attributes, underlineCheckBox.isSelected()); - StyleConstants.setStrikeThrough(attributes, strikethroughCheckBox - .isSelected()); + StyleConstants.setStrikeThrough(attributes, strikethroughCheckBox.isSelected()); StyleConstants.setSubscript(attributes, subscriptCheckBox.isSelected()); - StyleConstants.setSuperscript(attributes, superscriptCheckBox - .isSelected()); + StyleConstants.setSuperscript(attributes, superscriptCheckBox.isSelected()); StyleConstants.setForeground(attributes, (Color) colorComboBox.getSelectedItem()); return attributes; } + /** + * Returns the option selected by the user in the font chooser dialog. + * + * @return the selected option + */ private int getOption() { return Closed_Option; } + /** + * Updates the font preview based on the current selections in the font chooser. + */ protected void updatePreview() { StringBuilder previewText = new StringBuilder(PREVIEW_TEXT); String name = fontNameInputList.getSelected(); @@ -285,7 +307,7 @@ protected void updatePreview() { attributes.put(FAMILY, name); attributes.put(SIZE, (float) size); - // Using HTML to force JLabel manage natively unsupported attributes + // Using HTML to force JLabel to manage natively unsupported attributes if (underlineCheckBox.isSelected() || strikethroughCheckBox.isSelected()) { previewText.insert(0, ""); previewText.append(""); @@ -302,7 +324,6 @@ protected void updatePreview() { previewText.insert(previewText.length() - 7, ""); } - if (boldCheckBox.isSelected()) attributes.put(WEIGHT, WEIGHT_BOLD); if (italicCheckBox.isSelected()) @@ -317,7 +338,6 @@ protected void updatePreview() { superscriptCheckBox.setEnabled(!subscriptCheckBox.isSelected()); subscriptCheckBox.setEnabled(!superscriptCheckBox.isSelected()); - Font fn = new Font(attributes); previewLabel.setText(previewText.toString()); @@ -328,9 +348,16 @@ protected void updatePreview() { previewLabel.repaint(); } - + /** + * Displays the font chooser dialog and returns the selected option. + * + * @param frame the parent frame + * @param f the initial font + * @param title the title of the dialog + * @param c the initial color + * @return the selected option + */ public static int showDialog(GExpert frame, Font f, String title, Color c) { - if (chooser == null) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); fontNames = ge.getAvailableFontFamilyNames(); @@ -344,8 +371,6 @@ public static int showDialog(GExpert frame, Font f, String title, Color c) { StyleConstants.setItalic(a, f.isItalic()); StyleConstants.setFontFamily(a, f.getFamily()); chooser.setAttributes(a); -// if (title != null) -// chooser.setTitle(title); int x = frame.getX() + frame.getWidth() / 2 - 350 / 2; int y = frame.getY() + frame.getHeight() / 2 - 450 / 2; chooser.setLocation(x, y); @@ -354,10 +379,23 @@ public static int showDialog(GExpert frame, Font f, String title, Color c) { return chooser.getOption(); } + /** + * Displays the font chooser dialog and returns the selected option. + * + * @param frame the parent frame + * @param f the initial font + * @param c the initial color + * @return the selected option + */ public static int showDialog(GExpert frame, Font f, Color c) { return showDialog(frame, f, "Font Chooser", c); } + /** + * Returns the selected font from the font chooser dialog. + * + * @return the selected font + */ public static Font getReturnFont() { SimpleAttributeSet a = (SimpleAttributeSet) chooser.getAttributes(); @@ -374,13 +412,14 @@ else if (it) else style = Font.PLAIN; - Font f = new Font(s1, style, size); - //a.getAttribute() return f; - } + /** + * InputList is a custom JPanel that contains a label, a text field, and a list. + * It allows the user to select an item from the list and displays it in the text field. + */ class InputList extends JPanel implements ListSelectionListener, ActionListener { protected JLabel label = new JLabel(); @@ -591,6 +630,10 @@ public AccessibleRole getAccessibleRole() { } } + /** + * FontLabel is a custom JLabel that displays a font preview. It sets the + * background, foreground, and border properties for the label. + */ class FontLabel extends JLabel { public FontLabel(String text) { super(text, JLabel.CENTER); @@ -602,6 +645,10 @@ public FontLabel(String text) { } } + /** + * ColorComboBox is a custom JComboBox that displays a list of colors. It uses a + * custom renderer to display the colors in the combo box. + */ class ColorComboBox extends JComboBox { public ColorComboBox() { diff --git a/src/main/java/wprover/VcellRender.java b/src/main/java/wprover/VcellRender.java index 4adf9156..28829958 100644 --- a/src/main/java/wprover/VcellRender.java +++ b/src/main/java/wprover/VcellRender.java @@ -17,11 +17,9 @@ import static wprover.GExpert.getLanguage; /** - * Created by IntelliJ IDEA. - * User: yezheng - * Date: 2006-5-23 - * Time: 13:50:22 - * To change this template use File | Settings | File Templates. + * VcellRender is a custom JPanel that serves as a base class for rendering + * tree cells in a JTree. It provides a custom painting mechanism and handles + * selection and background colors. */ class VcellRender extends JPanel { protected static Border eborder = BorderFactory.createEmptyBorder(1, 1, 1, 1); @@ -51,12 +49,21 @@ public void paintComponent(Graphics g) { super.paintComponent(g); } } - +/** + * BookCellRenderer is a custom cell renderer for a tree structure, allowing + * for the rendering of tree nodes with specific content and behavior. + */ class BookCellRenderer extends VcellRender implements TreeCellRenderer { Vector renderlist = new Vector(); Vector renderlist1 = new Vector(); + /** + * Constructs a BookCellRenderer with the specified number of labels. + * Initializes the renderer and adds labels to the render lists. + * + * @param n the number of labels to initialize + */ public BookCellRenderer(int n) { super(); for (int i = 1; i <= n; i++) { @@ -69,6 +76,11 @@ public BookCellRenderer(int n) { } } + /** + * Sets the font for all labels in the renderer. + * + * @param f the font to set for the labels + */ public void setCellFont(Font f) { for (int i = 0; i < renderlist.size(); i++) { ItemLabel lb = (ItemLabel) renderlist.get(i); @@ -81,22 +93,46 @@ public void setCellFont(Font f) { } } + /** + * Sets the user object and type for a label at the specified index in the primary list. + * + * @param index the index of the label to set + * @param t the type of the label + * @param obj the user object to associate with the label + */ public void setLabelObject(int index, int t, Object obj) { if (obj == null) return; - ItemLabel label = null; - label = (ItemLabel) renderlist.get(index); + ItemLabel label = (ItemLabel) renderlist.get(index); label.setUserObject(t, obj); this.add(label); } + /** + * Sets the user object and type for a label at the specified index in the secondary list. + * + * @param index the index of the label to set + * @param t the type of the label + * @param obj the user object to associate with the label + */ public void setLabelObject1(int index, int t, Object obj) { - ItemLabel label = null; - label = (ItemLabel) renderlist1.get(index); + ItemLabel label = (ItemLabel) renderlist1.get(index); label.setUserObject(t, obj); this.add(label); } + /** + * Returns the tree cell renderer component for the specified tree node. + * + * @param tree the JTree that is asking the renderer to render + * @param value the value of the cell to be rendered + * @param selected whether the cell is selected + * @param expanded whether the node is expanded + * @param leaf whether the node is a leaf node + * @param row the row index of the node + * @param hasFocus whether the node has focus + * @return the component for rendering the tree cell + */ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, @@ -174,7 +210,7 @@ public Component getTreeCellRendererComponent(JTree tree, Object value, if (n != 0) { setLabelObject1(k++, 0, " (" + getLanguage("by HYP") + ")"); } else if (c.getNo() == 0) { - setLabelObject1(k++, 0, " (" + getLanguage("in GIB") + ")"); + setLabelObject1(k++, 0, " (" + getLanguage("in GIB") + ")"); } } @@ -185,7 +221,6 @@ public Component getTreeCellRendererComponent(JTree tree, Object value, Rule ls = (Rule) userObject; setLabelObject(0, 7, ls); } else { - //cell = null; setLabelObject(0, 9999, userObject); } @@ -206,12 +241,21 @@ public Component getTreeCellRendererComponent(JTree tree, Object value, return returnValue; } - -} +} +/** + * BookCellEditor is a custom cell editor for a tree structure, allowing + * for the editing of tree nodes with specific rendering and behavior. + */ class BookCellEditor extends BasicCellEditor implements MouseListener { + /** + * Constructs a BookCellEditor with the specified number of labels. + * Initializes the editor and adds mouse listeners to all labels. + * + * @param n the number of labels to initialize + */ public BookCellEditor(int n) { init(n); @@ -228,6 +272,12 @@ public BookCellEditor(int n) { public void mouseClicked(MouseEvent e) { } + /** + * Handles the mouse pressed event. Deselects the previously selected label, + * selects the new label, and repaints the cell. + * + * @param e the MouseEvent that triggered this method + */ public void mousePressed(MouseEvent e) { if (selectLabel != null) { selectLabel.setSelected(false); @@ -248,7 +298,10 @@ public void mouseExited(MouseEvent e) { } - +/** + * BasicCellEditor is a custom cell editor for a tree structure, allowing + * for the editing of tree nodes with specific rendering and behavior. + */ class BasicCellEditor extends AbstractCellEditor implements TreeCellEditor { public static int cond_no = 0; @@ -258,12 +311,15 @@ class BasicCellEditor extends AbstractCellEditor implements TreeCellEditor { ItemLabel selectLabel = null; + /** + * Initializes the editor with the specified number of labels. + * + * @param n the number of labels to initialize + */ public void init(int n) { - for (int i = 1; i <= n; i++) { ItemLabel lb = new ItemLabel(false, false); lb.setRenderT(false); - renderlist.add(lb); } for (int i = 1; i <= n; i++) { @@ -275,6 +331,11 @@ public void init(int n) { cell.setBorder(new LineBorder(cell.backgroundSelectionColor.darker(), 1)); } + /** + * Sets the font for the editor labels. + * + * @param f the font to set for the labels + */ public void setEditorFont(Font f) { for (int i = 0; i < renderlist.size(); i++) { ItemLabel lb = (ItemLabel) renderlist.get(i); @@ -287,20 +348,37 @@ public void setEditorFont(Font f) { } } + /** + * Sets the user object and type for a label at the specified index. + * + * @param index the index of the label to set + * @param t the type of the label + * @param obj the user object to associate with the label + */ public void setLabelObject(int index, int t, Object obj) { - ItemLabel label = null; - label = (ItemLabel) renderlist.get(index); + ItemLabel label = (ItemLabel) renderlist.get(index); label.setUserObject(t, obj); cell.add(label); } + /** + * Sets the user object and type for a label at the specified index in the secondary list. + * + * @param index the index of the label to set + * @param t the type of the label + * @param obj the user object to associate with the label + */ public void setLabelObject1(int index, int t, Object obj) { - ItemLabel label = null; - label = (ItemLabel) renderlist1.get(index); + ItemLabel label = (ItemLabel) renderlist1.get(index); label.setUserObject(t, obj); cell.add(label); } + /** + * Adds a mouse listener to all labels. + * + * @param listener the mouse listener to add + */ public void addListenerToAllLabel(MouseListener listener) { for (int i = 0; i < renderlist.size(); i++) { ItemLabel label = (ItemLabel) renderlist.get(i); @@ -312,6 +390,17 @@ public void addListenerToAllLabel(MouseListener listener) { } } + /** + * Returns the tree cell editor component for the specified tree node. + * + * @param tree the JTree that is asking the editor to edit + * @param value the value of the cell to be edited + * @param isSelected whether the cell is selected + * @param expanded whether the node is expanded + * @param leaf whether the node is a leaf node + * @param row the row index of the node + * @return the component for editing the tree cell + */ public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, @@ -369,8 +458,6 @@ public Component getTreeCellEditorComponent(JTree tree, Object value, if (el.getEType() > 0) setLabelObject1(k++, 2, el); setLabelObject1(k++, 5, el); -// if (node.getParent() != null) -// setLabelObject1(k++, 0, " )"); } else if (userObject instanceof DTerm) { } else if (userObject instanceof Cond) { Cond c = (Cond) userObject; @@ -395,7 +482,6 @@ public Component getTreeCellEditorComponent(JTree tree, Object value, } } } else { - //cell = null; setLabelObject(0, 9999, userObject); } @@ -411,21 +497,30 @@ public Component getTreeCellEditorComponent(JTree tree, Object value, value, isSelected, expanded, leaf, row, true); } return returnValue; - } - + /** + * Cancels the cell editing process. + */ public void cancelCellEditing() { super.cancelCellEditing(); cond_no = 0; } + /** + * Returns the value contained in the editor. + * + * @return the value contained in the editor + */ public Object getCellEditorValue() { return null; } } - +/** + * ItemLabel is a custom JLabel that can display different types of content + * and handle mouse events. + */ class ItemLabel extends JLabel { public static ImageIcon icon = GExpert.createImageIcon("images/dtree/detail.gif"); private static ImageIcon icon_bc = GExpert.createImageIcon("images/dtree/because.gif"); @@ -444,19 +539,30 @@ class ItemLabel extends JLabel { boolean selected = false; + /** + * Returns the type of the item label. + * + * @return the type of the item label + */ public int getType() { return type; } - - public static int getItemLabelFontSize() { - return font.getSize(); - } - + /** + * Returns the user object associated with the item label. + * + * @return the user object associated with the item label + */ public Object getUserObject() { return userValue; } + /** + * Constructs an ItemLabel with the specified render and element flags. + * + * @param r whether the label should be rendered + * @param e whether the label is an element + */ public ItemLabel(boolean r, boolean e) { super(); isrender = r; @@ -497,11 +603,20 @@ public void mouseExited(MouseEvent e) { }); } - + /** + * Sets whether the label should be rendered. + * + * @param r true if the label should be rendered, false otherwise + */ public void setRenderT(boolean r) { this.isrender = r; } + /** + * Sets whether the label is selected. + * + * @param s true if the label is selected, false otherwise + */ public void setSelected(boolean s) { selected = s; if (iselm) { @@ -516,10 +631,21 @@ public void setSelected(boolean s) { this.repaint(); } + /** + * Returns whether the label is selected. + * + * @return true if the label is selected, false otherwise + */ public boolean isSelected() { return selected; } + /** + * Sets the user object and type for the label. + * + * @param type the type of the label + * @param obj the user object to associate with the label + */ public void setUserObject(int type, Object obj) { this.type = type; userValue = obj; @@ -564,6 +690,11 @@ public void setUserObject(int type, Object obj) { } } + /** + * Paints the component. + * + * @param g the Graphics object to protect + */ public void paint(Graphics g) { if (isrender) { } else { diff --git a/src/main/java/wprover/Version.java b/src/main/java/wprover/Version.java index 42600898..3bc74b97 100644 --- a/src/main/java/wprover/Version.java +++ b/src/main/java/wprover/Version.java @@ -1,35 +1,57 @@ package wprover; - +/** + * Version is a class that provides version information for the Geometry Expert project. + * It includes methods to retrieve the version number, project name, and release date. + */ public class Version { private static String sversion = "0.86"; private static String data = "2024-11-26"; private static String project = "Geometry Expert"; - private static float version = Float.parseFloat(sversion); - - public static final float getVersionf() { - return version; - } - - public static final String getVersion1() { - return sversion; - } +/** + * Returns the version as a string. + * + * @return the version string + */ +public static final String getVersion1() { + return sversion; +} - public static final String getNameAndVersion() { - return project + " " + sversion; - } +/** + * Returns the project name and version as a single string. + * + * @return the project name and version string + */ +public static final String getNameAndVersion() { + return project + " " + sversion; +} - public static final String getVersion() { - return " " + project + " "; - } +/** + * Returns the project name surrounded by spaces. + * + * @return the project name with surrounding spaces + */ +public static final String getVersion() { + return " " + project + " "; +} - public static final String getProject() { - return project; - } +/** + * Returns the project name. + * + * @return the project name + */ +public static final String getProject() { + return project; +} - public static final String getData() { - return data; - } +/** + * Returns the date as a string. + * + * @return the date string + */ +public static final String getData() { + return data; +} } diff --git a/src/main/java/wprover/WuTextPane.java b/src/main/java/wprover/WuTextPane.java index ac06f834..b06d9383 100644 --- a/src/main/java/wprover/WuTextPane.java +++ b/src/main/java/wprover/WuTextPane.java @@ -10,35 +10,53 @@ import java.awt.event.ActionListener; /** - * Created by IntelliJ IDEA. - * User: ye - * Date: 2007-5-25 - * Time: 17:37:54 - * To change this template use File | Settings | File Templates. + * WuTextPane is a class that extends JTextPane and implements ActionListener. + * It provides functionality for displaying styled text and handling button actions. */ public class WuTextPane extends JTextPane implements ActionListener { private JButton button; + /** + * Clears all text from the text pane. + */ public void clearAll() { this.setText(""); } + /** + * Constructs a WuTextPane, sets it to be non-editable, and adds styles to the document. + */ public WuTextPane() { this.setEditable(false); StyledDocument doc = getStyledDocument(); addStylesToDocument(doc); } + /** + * Sets the size of the text pane, ensuring the width is at least as wide as the parent component. + * + * @param d the new size of the text pane + */ public void setSize(Dimension d) { if (d.width < getParent().getSize().width) d.width = getParent().getSize().width; super.setSize(d); } + /** + * Indicates whether the viewport should track the width of the text pane. + * + * @return false, indicating the viewport should not track the width + */ public boolean getScrollableTracksViewportWidth() { return false; } + /** + * Adds various styles to the specified StyledDocument. + * + * @param doc the StyledDocument to which styles will be added + */ protected void addStylesToDocument(StyledDocument doc) { Font defont = CMisc.algebraFont; //SansSerif @@ -52,7 +70,6 @@ protected void addStylesToDocument(StyledDocument doc) { Style s = doc.addStyle("italic", regular); StyleConstants.setItalic(s, true); - s = doc.addStyle("bold", regular); StyleConstants.setBold(s, true); @@ -60,7 +77,6 @@ protected void addStylesToDocument(StyledDocument doc) { StyleConstants.setBold(s, true); StyleConstants.setForeground(s, new Color(0, 128, 0)); - int sm = defont.getSize(); s = doc.addStyle("small", regular); @@ -98,7 +114,6 @@ protected void addStylesToDocument(StyledDocument doc) { StyleConstants.setIcon(s, pigIcon); } - s = doc.addStyle("button", regular); button = new JButton(GExpert.getLanguage("View Remainder")); button.setCursor(Cursor.getDefaultCursor()); @@ -108,7 +123,11 @@ protected void addStylesToDocument(StyledDocument doc) { StyleConstants.setComponent(s, button); } - + /** + * Adds an ActionListener to the button. + * + * @param ls the ActionListener to be added + */ public void addListnerToButton(ActionListener ls) { if (ls == null) return; @@ -116,10 +135,10 @@ public void addListnerToButton(ActionListener ls) { button.addActionListener(ls); } - public void actionPerformed(ActionEvent e) { - - - } - - + /** + * Handles action events. Currently, this method does nothing. + * + * @param e the ActionEvent to be handled + */ + public void actionPerformed(ActionEvent e) {} } diff --git a/src/main/java/wprover/package-info.java b/src/main/java/wprover/package-info.java new file mode 100644 index 00000000..d1dba542 --- /dev/null +++ b/src/main/java/wprover/package-info.java @@ -0,0 +1,10 @@ +/** + * The wprover package provides core functionalities for geometric proving and constraint-based computations. + * This package is designed with a clear separation of concerns. It encapsulates the core proving logic, + * geometric drawing operations, and constraint verifications while isolating these functionalities from the + * main user interface management. Classes such as DrawBase demonstrate this design by offering methods for + * drawing geometric elements and handling interactions. + * Note: Although the focus of this package is on the prover functionalities, some classes may include minimal + * UI components solely to support interactive functionalities within the proving process. + */ +package wprover;